Added portal-FE-os components
[portal.git] / portal-FE-common / src / app / shared / services / application-catalog / application-catalog.service.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 { Injectable } from '@angular/core';
39 import { GridsterConfig, GridsterItem, DisplayGrid, GridType } from 'angular-gridster2';
40 import { Observable } from 'rxjs';
41 import { IApplicationCatalog } from '../../model/application-catalog.model';
42 import { environment } from 'src/environments/environment';
43 import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
44
45 @Injectable({
46   providedIn: 'root'
47 })
48 export class ApplicationCatalogService {
49   public options: GridsterConfig = {
50     minCols: 6,
51     maxCols: 6,
52     minRows: 7,
53     //maxRows: 4,
54     maxItemCols: 50,
55     minItemCols: 1,
56     maxItemRows: 50,
57     minItemRows: 1,
58     maxItemArea: 2500,
59     minItemArea: 1,
60     defaultItemCols: 1,
61     defaultItemRows: 1,
62     setGridSize: false,
63     fixedColWidth: 250,
64     fixedRowHeight: 250,
65     gridType: GridType.ScrollVertical,
66     swap: true,
67     dynamicColumns: true,
68     displayGrid: DisplayGrid.None,
69     itemChangeCallback: this.itemChange,
70
71
72     draggable: {
73       enabled: true
74     },
75     pushItems: true,
76     resizable: {
77       enabled: true
78     }
79   };
80   public layout: GridsterItem[] = [];
81   constructor(private api: HttpClient) { }
82
83   addItem(appData: any): void {
84     this.layout.push(appData);
85   }
86   getAppCatalog(): Observable<any> {
87     return this.api.get(environment.api.appCatalog);
88   }
89   updateAppCatalog(appData: any): Observable<any> {
90     return this.api.put(environment.api.appCatalog, appData);
91   }
92   updateManualAppSort(appData: any): Observable<any> {
93     return this.api.put(environment.api.UpdateUserAppsSortManual, appData);
94   }
95   getuserAppRolesCatalog(appName: string): Observable<any> {
96     return this.api.get(environment.api.appCatalogRoles);
97   }
98   getAppsFullList(): Observable<any> {
99     return this.api.get(environment.api.appsFullList);
100   }
101   getUserAppsSortTypePreference(): Observable<any> {
102     const headers = new HttpHeaders().set('Content-Type','text/plain;charset=utf-8');
103     return this.api.get(environment.api.userAppsSortTypePreference,{headers,responseType:'text'});
104   }
105   getAppsOrderBySortPref(appSortPrefData: any): Observable<any> {
106     let httpParam = new  HttpParams().set('mparams', appSortPrefData);
107     return this.api.get(environment.api.userAppsOrderBySortPref, {params: httpParam});
108   }
109   saveAppsSortTypePreference(userPrefData: any): Observable<any> {
110     return this.api.put(environment.api.saveUserAppsSortingPreference, userPrefData);
111   }
112   itemChange(item, itemComponent) {
113     //console.info('itemChanged', item, itemComponent);
114     if(this.layout)
115     {
116     //console.log("check the layout value "+this.layout.values);
117     }
118   }
119   checkIfUserIsSuperAdmin(): Observable<any> {
120     let checkIfUserIsSuperAdminURL = environment.api.checkIfUserIsSuperAdmin;
121     return this.api.get(checkIfUserIsSuperAdminURL);
122   }
123   clearCatalog(): void {
124     this.layout =[];
125   }
126
127 }