summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/shared/services/doc.service.ts
blob: 4cbb4cf185b38ae5347e3b2c315ca63819171578 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Injectable } from '@angular/core';

import { BehaviorSubject, Subscription } from 'rxjs';
import { filter, first, map } from 'rxjs/operators';

import { CephReleaseNamePipe } from '../pipes/ceph-release-name.pipe';
import { SummaryService } from './summary.service';

@Injectable({
  providedIn: 'root'
})
export class DocService {
  private releaseDataSource = new BehaviorSubject<string>(null);
  releaseData$ = this.releaseDataSource.asObservable();

  constructor(
    private summaryservice: SummaryService,
    private cephReleaseNamePipe: CephReleaseNamePipe
  ) {
    this.summaryservice.subscribeOnce((summary) => {
      const releaseName = this.cephReleaseNamePipe.transform(summary.version);
      this.releaseDataSource.next(releaseName);
    });
  }

  urlGenerator(section: string, release = 'master'): string {
    const docVersion = release === 'master' ? 'latest' : release;
    const domain = `https://docs.ceph.com/en/${docVersion}/`;
    const domainCeph = `https://ceph.io/`;

    const sections = {
      iscsi: `${domain}mgr/dashboard/#enabling-iscsi-management`,
      prometheus: `${domain}mgr/dashboard/#enabling-prometheus-alerting`,
      'nfs-ganesha': `${domain}mgr/dashboard/#configuring-nfs-ganesha-in-the-dashboard`,
      'rgw-nfs': `${domain}radosgw/nfs`,
      rgw: `${domain}mgr/dashboard/#enabling-the-object-gateway-management-frontend`,
      dashboard: `${domain}mgr/dashboard`,
      grafana: `${domain}mgr/dashboard/#enabling-the-embedding-of-grafana-dashboards`,
      orch: `${domain}mgr/orchestrator`,
      pgs: `${domainCeph}pgcalc`,
      help: `${domainCeph}help/`,
      security: `${domainCeph}security/`,
      trademarks: `${domainCeph}legal-page/trademarks/`,
      'dashboard-landing-page-status': `${domain}mgr/dashboard/#dashboard-landing-page-status`,
      'dashboard-landing-page-performance': `${domain}mgr/dashboard/#dashboard-landing-page-performance`,
      'dashboard-landing-page-capacity': `${domain}mgr/dashboard/#dashboard-landing-page-capacity`
    };

    return sections[section];
  }

  subscribeOnce(
    section: string,
    next: (release: string) => void,
    error?: (error: any) => void
  ): Subscription {
    return this.releaseData$
      .pipe(
        filter((value) => !!value),
        map((release) => this.urlGenerator(section, release)),
        first()
      )
      .subscribe(next, error);
  }
}