f571dcaa189d93252022333d2a7cd9babcf89586
[portal.git] / portal-FE-common / src / app / pages / application-catalog / application-catalog.component.ts
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 import { Component, OnInit } from '@angular/core';
39 import { GridsterConfig, GridsterItem } from 'angular-gridster2';
40 import { ApplicationCatalogService } from '../../shared/services/application-catalog/application-catalog.service';
41 import { IApplicationCatalog } from '../../shared/model/application-catalog.model';
42 import { IWidgetCatalog } from '../../shared/model/widget-catalog.model';
43 import { environment } from 'src/environments/environment';
44 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
45 import { CatalogModalComponent } from '../catalog-modal/catalog-modal.component';
46 import { ExternalRequestAccessService } from 'src/app/shared/services/external-request-access-service/external-request-access.service';
47 import { UsersService } from 'src/app/shared/services/users/users.service';
48
49 @Component({
50   selector: 'app-application-catalog',
51   templateUrl: './application-catalog.component.html',
52   styleUrls: ['./application-catalog.component.scss']
53 })
54 export class ApplicationCatalogComponent implements OnInit {
55   widgetCatalogData: IWidgetCatalog[];
56   appCatalogData: IApplicationCatalog[];
57   resultAccessValue: string;
58   orgUserId: string;
59   firstName: string;
60   lastName: string;
61   radioValue: any;
62   isUserSuperAdmin: boolean;
63
64   get options(): GridsterConfig {
65     return this.applicationCatalogService.options;
66   } get layout(): GridsterItem[] {
67     return this.applicationCatalogService.layout;
68   } constructor(private applicationCatalogService: ApplicationCatalogService, private externalRequestAccessService: ExternalRequestAccessService, private userService: UsersService, private modal: NgbModal) { }
69
70   ngOnInit() {
71     this.applicationCatalogService.clearCatalog();
72     this.radioValue = 'All';
73     this.callAppCatalogExecutor();
74   }
75
76   callAppCatalogExecutor() {
77     //Check whether Admin is Super Admin
78     this.checkAdminIsSuperAdmin();
79     //To fetch ML value
80     this.getExternalAccess();
81
82     //Call user profile service
83     this.getUserProfile();
84
85     //Call Application Catalog services
86     this.getAppCatalogService();
87   }
88
89   checkAdminIsSuperAdmin() {
90     this.applicationCatalogService.checkIfUserIsSuperAdmin().subscribe(data => {
91       this.isUserSuperAdmin = data;
92     }, error => {
93       console.log('checkAdminIsSuperAdmin Error Object' + error);
94     });
95   }
96
97   getAppCatalogService() {
98     //console.log("getAppCatalogServices called");
99     this.applicationCatalogService.getAppCatalog().subscribe(data => {
100       //console.log("Response data" + data);
101       this.appCatalogData = data;
102       for (let entry of this.appCatalogData) {
103         //console.log("Check the URL" + environment.api.appThumbnail);
104         var appCatalog = {
105           x: -1,
106           y: -1,
107           id: entry.id,
108           name: entry.name,
109           mlAppName: entry.mlAppName,
110           imageLink: environment.api.appThumbnail.replace(':appId', <string><any>entry.id),
111           restricted: entry.restricted,
112           select: entry.select,
113           access: entry.access,
114           pending: entry.pending,
115           mlproperty: this.resultAccessValue
116         };
117         this.applicationCatalogService.addItem(appCatalog);
118       }
119     }, error => {
120       console.log('getAppCatalogServices Error Object' + error);
121     });
122   };
123
124   storeSelection(appCatalogData: any) {
125     //console.log("Store selection called " + appCatalogData.name);
126     var pendingFlag: boolean = false;
127     if (appCatalogData.access)
128       pendingFlag = false;
129     else
130       pendingFlag = appCatalogData.pending;
131
132     var appData = {
133       appId: appCatalogData.id,
134       select: appCatalogData.select,
135       pending: pendingFlag
136     };
137     this.applicationCatalogService.updateManualAppSort(appData).subscribe(data => {
138       //console.log("Update App sort data" + data);
139     }, error => {
140       console.log('Update App sort error' + error);
141     });
142
143     this.applicationCatalogService.updateAppCatalog(appData).subscribe(data => {
144       //console.log("Update App Catalog data" + data);
145     }, error => {
146       console.log('Update App Catalog error' + error);
147     });
148   };
149   openAddRoleModal(item: any) {
150     //console.log("OpenModal check" + item.id);
151     if ((!item.restricted) && (item.mlproperty)) {
152       this.modal.open(CatalogModalComponent);
153     }
154   }
155
156   getExternalAccess() {
157     //console.log("getExternalAccess service called");
158     this.externalRequestAccessService.getExternalRequestAccessServiceInfo().subscribe(data => {
159       //console.log("Response data" + data);
160       if (data)
161         this.resultAccessValue = data.accessValue;
162     }, error => {
163       console.log('getExternalAccess Error object' + error);
164     });
165   }
166
167   getUserProfile() {
168     const userProfileObservable = this.userService.getUserProfile();
169     userProfileObservable.subscribe((userProfile: any) => {
170       //console.log('UserProfile is ' + userProfile);
171       if (userProfile) {
172         this.orgUserId = userProfile.orgUserId;
173         this.firstName = userProfile.firstName;
174         this.lastName = userProfile.lastName;
175       }
176     });
177
178   }
179 }