Portal Non-Gui application onboarding changes
[portal.git] / portal-FE-common / src / app / pages / dashboard-widget-catalog / dashboard-widget-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 { WidgetCatalogService } from '../../shared/services/widget-catalog/widget-catalog.service';
41 import { IWidgetCatalog } from '../../shared/model/widget-catalog.model';
42 import { Observable } from 'rxjs';
43 import { inflateRaw } from 'zlib';
44 import { UsersService } from 'src/app/shared/services/users/users.service';
45
46 @Component({
47   selector: 'app-dashboard-widget-catalog',
48   templateUrl: './dashboard-widget-catalog.component.html',
49   styleUrls: ['./dashboard-widget-catalog.component.scss']
50 })
51 export class DashboardWidgetCatalogComponent implements OnInit {
52
53  
54   widgetCatalogData: IWidgetCatalog[];
55   isCommonError: boolean = false;
56   isApiRunning: boolean = true;
57   userName: string;
58
59
60   get options(): GridsterConfig {
61     return this.widgetCatalogService.options;
62   } get layout(): GridsterItem[] {
63     return this.widgetCatalogService.layout;
64   } constructor(private widgetCatalogService: WidgetCatalogService, private userService: UsersService) {
65
66   }
67
68   ngOnInit() {
69     const widgetCatalogObservable = this.widgetCatalogService.getWidgetCatalog();
70     this.widgetCatalogService.layout = [];
71     this.getUserWidgets(this.userName);
72   }
73
74
75   getUserWidgets(loginName: string) {
76     const widgetCatalogUserObservable = this.userService.getUserProfile();
77     widgetCatalogUserObservable.subscribe((userProfile: any) => {
78       //console.log('UserProfile is ' + userProfile);
79       if (userProfile) {
80         const widgetCatalogObservable = this.widgetCatalogService.getUserWidgets(userProfile.orgUserId);
81         widgetCatalogObservable.subscribe(data => {
82           //console.log("What is coming from backend" + JSON.parse(data));
83           this.widgetCatalogData = data;
84           console.log(this.widgetCatalogData);
85                   if(this.widgetCatalogData != null){
86                           for (let entry of this.widgetCatalogData) {
87             if (entry[1] == 'Events' || entry[1] == 'News' || entry[1] == 'Resources') {
88               if(entry[4] === 'S' || entry[4] === null)
89               {
90               var appCatalog = {
91                 id: entry[0],
92                 name: entry[1],
93                 headerName: entry[2],
94                 //select: (entry[4] === 'S' || entry[4] === null) ? true : false
95               };
96               this.widgetCatalogService.addItem(appCatalog);
97             }
98             }
99           }
100                   }
101         });
102       }
103     });
104
105   }
106
107   getUserProfile(): Observable<any> {
108     const widgetCatalogObservable = this.userService.getUserProfile();
109     return widgetCatalogObservable;
110   }
111
112   storeSelection(widgetCatalogData: any) {
113     console.log("Store selection called " + widgetCatalogData.select);
114     if (widgetCatalogData && widgetCatalogData.select) {
115       var appData = {
116         widgetId: widgetCatalogData.id,
117         select: widgetCatalogData.select,
118         pending:false
119       };
120       this.widgetCatalogService.updateWidgetCatalog(appData).subscribe(data => {
121         //console.log("Update App sort data" + data);
122       }, error => {
123         console.log('updateWidgetCatalog error' + error);
124       });
125     }
126
127   }
128 }