Installation
Last updated
Was this helpful?
Last updated
Was this helpful?
The following are prerequisites to use question set editor
Angular
15.2.3
Question Set Editor library components is powered by angular. This editor is primarily designed to be used in the sunbirdEd portal and web portal to drive reusability, maintainability hence reducing the redundant development effort significantly. And it can be integrated with any platform irrespective of the platforms and the frontend frameworks. It is exported not only as an but also as a aims to make it easy to share, discover, and reuse web components. It creates a framework agnostic way of composing and re-purposing code.
The Question Set Editor can be integrated as a web component and also as an angular library in angular application projects.
Question Set Editor Library can also be used as a web component which means if your project does not use a JavaScript framework but prefers platform-based HTML, CSS, and JavaScript, you may wish to use Question Set Editor Library in this way. Simply follow the below-mentioned steps to use it in plain JavaScript project:
Insert as below:
Copy all the files from , the library requires these files internally to work well.
Define an html element where you want to display the editor and set an id
to it. For example
Note - You can give any id
of your choice but the same id should be used to append the questionsetEditorElement.
Create a custom HTML element: lib-questionset-editor
Get sample questionsetEditorConfig from here: and pass data using editor-config
Note: Attribute should be in string type
Listen for the output events: editorEmitter
as:
Append this element to the existing element
▶️ Refer demo
Note: Question Set Editor requires a back-end service for making the API calls. For running the Question Set Editor you need a server where inQuiry services are up and running.
For testing purpose we are using a node.js server where the API's proxy and editor are running on localhost
. For running the editor and services from localhost
please refer the file and run it using node server.js
Run command
Add these entries in an angular JSON file inside assets, scripts, and styles like below
Integrating lib-questionset-editor
web component in the angular component
Create a viewChild in HTML template of the angular component like
Refer to the viewChild
in the ts file of the component and create the Questionset Editor using the document.createElement
, then attach the editor config and listen to the editor events like below and since we are rendering using viewChild
these steps should be under the ngAfterViewInit
hook of the angular component.
For running different question set in the editor, set the do_id of Question Set in data.ts
file as:
You're done! Question Set Editor web component integration in angular application is completed.
Note: Question Set Editor requires a back-end service to make the API calls. For running it locally we need a proxy server. You can use the below steps for doing the proxy and run the services on localhost:3000
Update the packge.json
For running the server.js file few packges are to be installed. Please install the below packages.
Now we are ready to run the application.
Open one terminal in your application's root folder and run the server as below and let it keep on running.
Open another terminal on root folder and start your application
For existing apps, follow the below-mentioned steps:
The following commands will add sunbird-questionset-editor
library to your package.json file along with its dependencies.
Don't forget to install the below peer dependencies of the library in your application. that need to be installed in order to use the library in your angular project.
After installing the above dependencies, now we have to copy the required assets from the given folder to the assets folder of your angular application. It contains styles and plugins.
Now open the angular.json
file and add the following under architect.build.assets
for default project
Create a question-cursor-implementation.service.ts
in a project and which will implement the QuestionCursor
and EditorCursor
abstract class.
QuestionCursor
and EditorCursor
is an abstract class, exported from the library, which needs to be implemented. Basically it has some methods which should make an API request over HTTP
Let's create the question-cursor-implementation
service by running the following command:
Now open app.module.ts
file and import like this:
Include QuestionsetEditorLibraryModule
in your app module:
Once your library is imported, you can use its main component, lib-questionset-editor
in your Angular application.
Add the tag to the app.component.html
like so:
app.component.ts
app.component.html
QuestionSet Editor
Can be used to render Editor
lib-questionset-editor
<lib-questionset-editor [editorConfig]="editorConfig"></lib-questionset-editor>
editorConfig
editorEmitter
editorConfig: Object - [Required
]
editorEmitter() - It emits event for each action performed in the editor.
From the root directory - go to server.js
file
Note: You will need actual API_AUTH_TOKEN
and USER_TOKEN
If you are pointing to sunbird dev (dev.sunbirded.org
), create a Question Set in sunbird dev, set the do_id of Question Set in data.ts
file
Run npm run build-lib
to build the library. The build artifacts will be stored in the dist/ directory.
Before running the application, we have to start the node server to proxy the APIs by running the following command:
Once that is done, Use the following CLI command to run your application locally
Go to the root directory
Install dependencies
Build the library
It will create a /dist/questionset-editor-library
folder at the root directory and also copy all the required assets.
A sample angular application is included as part of this repo
In another terminal tab -
From the root directory - Start the server
The demo app will launch at http://localhost:4200
From the root directory - go to server.js
file
Note: You will need actual API_AUTH_TOKEN
and USER_TOKEN
If you are pointing to sunbird dev (dev.sunbirded.org
), create a Question Set in sunbird dev and set the do_id of Question Set in data.ts
file
Run Node server to proxy the APIs (Open one more terminal in root folder and run the server.js ) as:
Note: Click to see the mock - and send the input config as a string
Create a proxy.conf.json in the root folder. Refer:
Create a latexService.js in the root folder. Refer:
Create server.js in the root folder. Refer:
For getting started with a new Angular app, check out the .
Note: As QuestionSet library is build with angular version 15, we are using "bootstrap": "^4.6.2" and ngx-bootstrap@^10.0.0 which are the compatible versions. For more reference Check compatibility document for ng-bootstrap
Copy the assets from:
Create a latexService.js in the root folder. Refer:
Create a proxy.conf.json in the root folder. Refer:
Create server.js in the root folder. Refer:
For more information refer .
Create a data.ts file which contains the questionSetEditorConfig
Refer:
(Note: data.ts
contains the mock config used in component to send it as input to questionset Editor. We need only .Use the mock config in your component to send input to questionset editor as editorConfig
)
For more information refer this documentation:
To see your application in the browser, go to .
Clone the Repo with the desired release branch: