Fix mod ui build issues
[dcaegen2/platform.git] / mod2 / ui / src / app / services / breadcrumb.service.ts
1 /* 
2  *  # ============LICENSE_START=======================================================
3  *  # Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
4  *  # ================================================================================
5  *  # Licensed under the Apache License, Version 2.0 (the "License");
6  *  # you may not use this file except in compliance with the License.
7  *  # You may obtain a copy of the License at
8  *  #
9  *  #      http://www.apache.org/licenses/LICENSE-2.0
10  *  #
11  *  # Unless required by applicable law or agreed to in writing, software
12  *  # distributed under the License is distributed on an "AS IS" BASIS,
13  *  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  # See the License for the specific language governing permissions and
15  *  # limitations under the License.
16  *  # ============LICENSE_END=========================================================
17  */
18
19 import { Injectable } from '@angular/core';
20 import { Observable, of, Subject, BehaviorSubject } from 'rxjs';
21
22 @Injectable({
23   providedIn: 'root'
24 })
25
26 export class BreadcrumbService {
27
28     breadcrumbs: any[] = [];
29
30     breadcrumbs$: Subject<any[]> = new BehaviorSubject([]);
31     
32     constructor() {
33         this.setBreadcrumbs('', "reset");
34     }
35
36     setBreadcrumbs(component: string, action: string) {
37         if (action == "reset") {
38             this.breadcrumbs = [];
39             this.breadcrumbs.push({ page: 'Home', link: '/home' });
40         }
41
42         //  If the breadcrumb item is clicked, remove evwrything to the right of the clicked item
43         if (action == "crumbClicked") {
44             const pos = this.breadcrumbs.map(function(crumb) { return crumb.page }).indexOf(component);
45             for (1; this.breadcrumbs.length -1 -pos; 1) {
46                 this.breadcrumbs.pop()
47             }
48         } else {    // Add the component that was selected
49             if (component == 'Microservices') {
50                 this.breadcrumbs.push({ page: 'Microservices', link: '/base-microservices' });
51             } else if (component == 'MS Instances') {
52                 this.breadcrumbs.push({ page: 'MS Instances', link: '/ms-instances' });
53             } else if (component == 'Blueprints') {
54                 this.breadcrumbs.push({ page: 'Blueprints', link: '/blueprints' });
55             } else if (component == 'Component Specs') {
56                 this.breadcrumbs.push({ page: 'Component Specs', link: '/CompSpecs' });
57             } else if (component == 'User Management') {
58                 this.breadcrumbs.push({ page: 'User Management', link: '/users' });
59             } else if (component == 'Onboarding Tools') {
60                 this.breadcrumbs.push({ page: 'Onboarding Tools', link: '/OnboardingTools' });
61             } else if (component == 'Spec Validator') {
62                 this.breadcrumbs.push({ page: 'Spec Validator', link: '/spec-validator' });
63             }
64         }
65         this.notifySubscriber()
66     }
67
68     
69     notifySubscriber() {
70         this.breadcrumbs$.next(this.breadcrumbs);
71     }
72 }
73