common changes for application-onboarding, application-catalog
[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                 if(entry.applicationType != "3"){
105         var appCatalog = {
106           x: -1,
107           y: -1,
108           id: entry.id,
109           name: entry.name,
110           mlAppName: entry.mlAppName,
111           imageLink: environment.api.appThumbnail.replace(':appId', <string><any>entry.id),
112           applicationType: entry.applicationType,
113           select: entry.select,
114           access: entry.access,
115           pending: entry.pending,
116           mlproperty: this.resultAccessValue
117         };
118         this.applicationCatalogService.addItem(appCatalog);
119       }
120           }
121     }, error => {
122       console.log('getAppCatalogServices Error Object' + error);
123     });
124   };
125
126   storeSelection(appCatalogData: any) {
127     //console.log("Store selection called " + appCatalogData.name);
128     var pendingFlag: boolean = false;
129     if (appCatalogData.access)
130       pendingFlag = false;
131     else
132       pendingFlag = appCatalogData.pending;
133
134     var appData = {
135       appId: appCatalogData.id,
136       select: appCatalogData.select,
137       pending: pendingFlag
138     };
139     this.applicationCatalogService.updateManualAppSort(appData).subscribe(data => {
140       //console.log("Update App sort data" + data);
141     }, error => {
142       console.log('Update App sort error' + error);
143     });
144
145     this.applicationCatalogService.updateAppCatalog(appData).subscribe(data => {
146       //console.log("Update App Catalog data" + data);
147     }, error => {
148       console.log('Update App Catalog error' + error);
149     });
150   };
151   openAddRoleModal(item: any) {
152     //console.log("OpenModal check" + item.id);
153     if ((item.applicationType == "1") && (item.mlproperty)) {
154       this.modal.open(CatalogModalComponent);
155     }
156   }
157
158   getExternalAccess() {
159     //console.log("getExternalAccess service called");
160     this.externalRequestAccessService.getExternalRequestAccessServiceInfo().subscribe(data => {
161       //console.log("Response data" + data);
162       if (data)
163         this.resultAccessValue = data.accessValue;
164     }, error => {
165       console.log('getExternalAccess Error object' + error);
166     });
167   }
168
169   getUserProfile() {
170     const userProfileObservable = this.userService.getUserProfile();
171     userProfileObservable.subscribe((userProfile: any) => {
172       //console.log('UserProfile is ' + userProfile);
173       if (userProfile) {
174         this.orgUserId = userProfile.orgUserId;
175         this.firstName = userProfile.firstName;
176         this.lastName = userProfile.lastName;
177       }
178     });
179
180   }
181 }