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