UNPKG

@tekdi/sunbird-quml-player

Version:

The QuML player library components are powered by Angular. This player is primarily designed to be used on Sunbird consumption platforms (mobile app, web portal, offline desktop app) to drive reusability and maintainability, hence reducing the redundant d

96 lines (91 loc) 4.12 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createService = void 0; const schematics_1 = require("@angular-devkit/schematics"); const workspace_1 = require("@schematics/angular/utility/workspace"); const messages = require("../messages"); function createService(options) { return (host, context) => __awaiter(this, void 0, void 0, function* () { const workspace = yield (0, workspace_1.getWorkspace)(host); const projectName = options.project || workspace.extensions.defaultProject; const project = workspace.projects.get(projectName); if (!project) { throw new schematics_1.SchematicsException(messages.noProject(projectName)); } return createQUMLImplementationService(workspace, project, host, context); }); } exports.createService = createService; function createQUMLImplementationService(workspace, project, host, context) { const path = `${project.sourceRoot}/app/question-cursor-implementation.service.ts`; if (!host.exists(path)) { context.logger.info("Creating question cursor implementation service..."); host.create(path, getQuestionCursorImplementationService()); } return () => host; } function getQuestionCursorImplementationService() { return ` import { HttpClient } from '@angular/common/http'; import { Injectable } from "@angular/core"; import { Question, QuestionCursor } from '@project-sunbird/sunbird-quml-player'; import { Observable, of, throwError } from 'rxjs'; import { map, mergeMap } from 'rxjs/operators'; @Injectable({ providedIn: 'root' }) export class QuestionCursorImplementationService implements QuestionCursor { listUrl: string | undefined; // Define this url to call list api in server constructor(private http: HttpClient) { } getQuestions(identifiers: string[], parentId?: string): Observable<Question> { const option: any = { url: this.listUrl, data: { request: { search: { identifier: identifiers } } } }; return this.post(option).pipe(map((data) => data.result)); } getQuestion(identifier: string): Observable<Question> { const option: any = { url: this.listUrl, data: { request: { search: { identifier: [identifier] } } } }; return this.post(option).pipe(map((data) => data.result)); } getQuestionSet(identifier: string): Observable<any> { return of({}) } private post(requestParam: any): Observable<any> { const httpOptions = { headers: { 'Content-Type': 'application/json' } }; return this.http.post(requestParam.url, requestParam.data, httpOptions).pipe( mergeMap((data: any) => { if (data.responseCode !== 'OK') { return throwError(() => data); } return of(data); })); } getAllQuestionSet(identifiers: string[]): Observable<any> { return of({}); } }`; } //# sourceMappingURL=create-service.js.map