1 import * as angular from 'angularAMD';
3 const help = angular.module('app.help');
5 export interface VersionInfo {
11 export interface TocNode {
14 [versionKey: string]: VersionInfo
16 nodes?: TocNodeCollection;
19 export type TocNodeCollection = { [tocNodeKey: string]: TocNode };
23 getBaseURL: (salType: 'AD_SAL' | 'MD_SAL') => string;
26 /** Represents a service used for the help application. */
27 export interface IHelpService {
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.
35 getTableOfContents(version?: string): angular.IPromise<TocNodeCollection>;
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.
43 getDocument(path: string): angular.IPromise<{ basePath: string, document: string }>;
46 class Helpservice implements IHelpService {
48 private tocNodeCollection: TocNodeCollection;
49 private documents: { [path: string]: { basePath: string, document: string } };
51 constructor(private $q: angular.IQService, private $http: angular.IHttpService, private env: IEnv) {
52 this.tocNodeCollection = null;
56 public getTableOfContents(): angular.IPromise<TocNodeCollection> {
57 if (this.tocNodeCollection) {
58 return this.$q.resolve(this.tocNodeCollection);
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;
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]);
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,
92 help.service('helpService', ['$q', '$http', 'ENV', Helpservice]);