Assign image keyname and pubkey at vnf level
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / ux / help / help-module / src / main / resources / help / help.service.ts
1 import * as angular from 'angularAMD';
2
3 const help = angular.module('app.help');
4
5 export interface VersionInfo {
6   label: string,
7   path: string,
8   date: string
9 }
10
11 export interface TocNode {
12   label: string; 
13   versions: {
14     [versionKey: string]: VersionInfo
15   };
16   nodes?: TocNodeCollection;
17 }
18
19 export type TocNodeCollection = { [tocNodeKey: string]: TocNode };
20
21
22 interface IEnv {
23   getBaseURL: (salType: 'AD_SAL' | 'MD_SAL') => string;
24 }
25
26 /** Represents a service used for the help application. */
27 export interface IHelpService {
28
29   /**
30    * Queries the table of contents for a specific version.
31    * @param version The version the table of contents shall be requested for.
32    * @returns A Promise containing the requested table of contents.
33    * 
34    */
35   getTableOfContents(version?: string): angular.IPromise<TocNodeCollection>;
36
37   /**
38    * Get a specitic document by its path.
39    * @param path The path of the document to get.
40    * @returns A Promise containing the requested document.
41    * 
42    */
43   getDocument(path: string): angular.IPromise<{ basePath: string, document: string }>;
44 }
45
46 class Helpservice implements IHelpService {
47
48   private tocNodeCollection: TocNodeCollection;
49   private documents: { [path: string]: { basePath: string, document: string } };
50
51         constructor(private $q: angular.IQService, private $http: angular.IHttpService, private env: IEnv) {
52     this.tocNodeCollection = null;
53     this.documents = {};
54   }
55  
56   public getTableOfContents(): angular.IPromise<TocNodeCollection> {
57     if (this.tocNodeCollection) {
58       return this.$q.resolve(this.tocNodeCollection);
59                 }
60
61                 return this.$http({
62       method: "GET",
63                         url: `${this.env.getBaseURL('MD_SAL')}/help/?meta`
64     }).then((result: angular.IHttpResponse<TocNodeCollection>) => {
65       if (result.status === 200) {
66                                 this.tocNodeCollection = result.data;
67                                 return result.data;
68       }
69     });
70   }
71
72   public getDocument(path: string): angular.IPromise<{basePath: string, document: string}> {
73     if (this.documents[path] != null) {
74       return this.$q.resolve(this.documents[path]);
75     }
76
77    return this.$http({
78       method: "GET",
79       url: `${this.env.getBaseURL('MD_SAL')}/help/${path}`
80     }).then((result: angular.IHttpResponse<string>) => {
81       if (result.status === 200) {
82         return this.documents[path] = {
83           basePath: result.config && result.config.url && result.config.url,
84           document: result.data
85         };
86       }
87     });
88
89   } 
90 }
91
92 help.service('helpService', ['$q', '$http', 'ENV',  Helpservice]);