Picture of Lars Halkjær
Adding a database field to articles, block and components in Authoring Tool
by Lars Halkjær - Tuesday, 26 March 2019, 10:55 AM
 

I have been trying to add an ID-field (called "itemId") to replace the database generated "_id" as the "_id" for Articles, Blocks and Components in the framework json-files.

The main reason for this is, that when you have made translation CSV-files for a course, it is a pain that the IDs change, every time you copy or import a course.
But it also makes it possible to use IDs from a course manuscript, which makes it easier to connect items in the course code to the manuscript.

In "plugins/content/[article|block|component]/model.schema" I have inserted this in the "properties" section:

"itemId": {
    "type": "string",
    "required": true,
    "default": "",
    "inputType": "Text",
    "validators": ["required"]
}

And also in the "plugins/content/component/componentType.schema" file.

In "ContentPlugin.prototype.create" I insert a default ID, that could be changed by the user in the AT.

I have also added the field to "BlockModel.whitelistAttributes" and "ComponentModel.whitelistAttributes" to allow it to be saved.

The "OutputPlugin.prototype.writeCourseJSON" is of course also modified, to use the "itemId" instead of the database "_id" field for JSON "_id" field.

This works quite a long way, but when I try to install a new AT server, using the modified code (from a fork of the AT repo), the standard components will not install (extensions installs ok).

I get this error, when I try to upload a component in the AT (it is the same error during AT install - but without the stack trace):

ValidationError: itemId: Path `itemId` is required.
ValidationError: componenttype validation failed: itemId: Path `itemId` is required.
  at new ValidationError (/root/adapt_authoring/node_modules/mongoose/lib/error/validation.js:30:11)
  at model.Document.invalidate (/root/adapt_authoring/node_modules/mongoose/lib/document.js:2080:32)
  at p.doValidate.skipSchemaValidators (/root/adapt_authoring/node_modules/mongoose/lib/document.js:1943:17)
  at /root/adapt_authoring/node_modules/mongoose/lib/schematype.js:929:9
  at process._tickCallback (internal/process/next_tick.js:61:11)

I can see that it is connected to my "itemId" field - but how?

Picture of Tom Taylor
Re: Adding a database field to articles, block and components in Authoring Tool
by Tom Taylor - Tuesday, 26 March 2019, 1:40 PM
 

Hi Lars,

Side-note: this is actually a feature that's being worked on by the core dev team, and something that will be released in the future. See this GitHub issue for more info.

The first thing is to understand the distinction between components and componenttypes

  • Componenttypes define the plugin data itself (i.e. name, version, what attributes it exposes etc.)
  • Components defines an instance of a componenttype (i.e. a piece of content in a course), and is concerned with the actual content (i.e. title, instruction text etc.)

Removing the itemId from the componenttype.schema should solve the problem.

Picture of Lars Halkjær
Re: Adding a database field to articles, block and components in Authoring Tool
by Lars Halkjær - Wednesday, 27 March 2019, 12:13 PM
 

Hi Tom,

Thank you for the answer.

I tried removing itemId from componenttype.schema and it kind of solved the problem, but also created a new one...

I do not get the error when installing, but the itemId is now nowhere to be seen.
I wanted it to be in the article, block and component data, and in ContentPlugin.prototype.create
I add a default value.
It should then appear in the scaffold views, and allow the user to set custom IDs.

But it does not appear in the database components table, and it dow not show up in the scaffold views.

I suspect it has something to do with me not understanding what all the various schema files are used for.

I have added:

"itemId": {
  "type": "string",
  "required": true,
  "default": "",
  "inputType": "Text",
  "validators": ["required"]
}

To:

  • BlockModel.whitelistAttributes and ComponentModel.whitelistAttributes
  • plugins/content/contentobject/model.schema
  • plugins/content/article/model.schema
  • plugins/content/block/model.schema
  • plugins/content/component/model.schema
Picture of Lars Halkjær
Re: Adding a database field to articles, block and components in Authoring Tool
by Lars Halkjær - Monday, 8 April 2019, 3:47 PM
 

Is there any documentation of the use/purpose of the variuos schema-files?

Picture of Marissa Preciado
Re: Adding a database field to articles, block and components in Authoring Tool
by Marissa Preciado - Wednesday, 11 September 2019, 9:34 PM
 

Hi, I know this is an old thread, but did you ever get this to work?

Thank you.

Picture of Lars Halkjær
Re: Adding a database field to articles, block and components in Authoring Tool
by Lars Halkjær - Wednesday, 11 September 2019, 11:12 PM
 

No unfortunately not. I ran out of time on the project.