The following are prerequisites to use question set editor
Softwares / Frameworks
Version
Angular
15.2.3
The Question Set Editor is tested against the above version of angular. Updating to latest versions needs further testing.
For more information on installing angular, see angular.io/cli. If you are unsure what version of Angular runs on your system, run “ng version” in a command prompt (terminal) window.
💠 Question Set Editor library for Sunbird platform
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 angular library but also as a web component aims to make it easy to share, discover, and reuse web components. It creates a framework agnostic way of composing and re-purposing code.
📑 Getting started with integration steps
The Question Set Editor can be integrated as a web component and also as an angular library in angular application projects.
Use as web components 🌏
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:
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 server.js file and run it using node server.js
Use as web component in the Angular app
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 viewChildthese 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. Forrunning it locally we need a proxy server. You can use the below steps for doing the proxy and run the services on localhost:3000
Create a proxy.conf.json in the root folder. Refer: proxy.conf.json
Update the packge.json
Create a latexService.js in the root folder. Refer: latexService.js
Create server.js in the root folder. Refer: server.js
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
Use as Angular library in Angular app
For getting started with a new Angular app, check out the Angular CLI.
For existing apps, follow the below-mentioned steps:
🏷️ Step 1: Install the packages
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.
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 here
🏷️ Step 2: create and copy required assests
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.
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:
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:
🏷️ Step 6: Send input to render QuestionSet Editor
Create a data.ts file which contains the questionSetEditorConfig Refer: data.ts
(Note: data.ts contains the mock config used in component to send it as input to questionset Editor. We need only questionSetEditorConfig.Use the mock config in your component to send input to questionset editor as editorConfig)
Update the host variable to which env your pointing. example if you are pointing sunbird dev instance update variable like below
const BASE_URL = 'https://dev.inquiry.sunbird.org/' //add the base url of your portal
const API_AUTH_TOKEN = 'XXXX' // Add the API_KEY of your inQuiry API's.
npm i express-http-proxy
npm i async
npm i mathjax-full
npm i svg2img
node server.js
npm run start
npm i @project-sunbird/sunbird-questionset-editor --save
npm i @project-sunbird/common-form-elements-full --save
npm i ng2-semantic-ui-v9 --save
npm i ngx-infinite-scroll --save
npm i lodash-es --save
npm i jquery.fancytree --save
npm i uuid --save
npm i @project-sunbird/client-services --save
npm i export-to-csv --save
npm i moment --save
npm i @project-sunbird/ckeditor-build-classic --save
npm i @project-sunbird/sunbird-quml-player-web-component --save
npm i ngx-bootstrap@^10.0.0 --save
npm i [email protected] --save
npm i jquery --save
npm i express-http-proxy --save
npm i mathjax-full --save
npm i svg2img --save
npm i font-awesome --save
npm i @project-sunbird/sb-styles
{
context: Object // Information about the telemetry and default settings for editor API requests
config: Object // default editor config such as sidebar menu list
}
Update the host variable to which env your pointing. example if you are pointing sunbird dev instance update variable like below
const BASE_URL = 'dev.sunbirded.org'
const API_AUTH_TOKEN = 'XXXX'
const USER_TOKEN= 'YYYY
export const questionSetEditorConfig = {
context: {
...
...
...
},
identifier: 'do_id', // identifier of questionset created in sunbird dev
...
...
};
nodemon server.js
npm run start
cd editor
npm install
npm run build-lib
npm run start
Update the host variable to which env your pointing. example if you are pointing sunbird dev instance update variable like below
const BASE_URL = 'dev.sunbirded.org'
const API_AUTH_TOKEN = 'XXXX'
const USER_TOKEN= 'YYYY'
export const questionSetEditorConfig = {
context: {
...
...
...
},
identifier: 'do_id', // identifier of questionset created in sunbird dev
...
...
};