Added portal-FE-os components
[portal.git] / portal-FE-common / src / app / shared / services / widget-catalog / widget-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 { IWidgetCatalog } from '../../model/widget-catalog.model';
40 import { Observable, from } from 'rxjs';
41 import { GridsterConfig, GridsterItem, CompactType, DisplayGrid, GridType } from 'angular-gridster2';
42 import { environment } from 'src/environments/environment';
43 import { HttpClient, HttpHeaders } from '@angular/common/http';
44
45
46
47 @Injectable({
48   providedIn: 'root'
49 })
50 export class WidgetCatalogService {
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: 2,
63     defaultItemRows: 2,
64     setGridSize: false,
65     fixedColWidth: 250,
66     fixedRowHeight: 250,
67     gridType: GridType.ScrollVertical,
68     swap: true,
69     dynamicColumns: true,
70     displayGrid: DisplayGrid.None,
71
72
73     draggable: {
74       enabled: true
75     },
76     pushItems: true,
77     resizable: {
78       enabled: true
79     }
80   };
81   public layout: GridsterItem[] = [];
82   constructor(private api: HttpClient) { }
83   addItem(widgetData: any): void {
84     this.layout.push(widgetData);
85   }
86   widgetCatalogData: IWidgetCatalog[] = [{
87     widgetId: '1',
88     widgetName: 'TestData1',
89     widgetStatus: 'TestStatus1',
90     imageLink: 'week_1.png',
91     select: true
92   },
93   {
94     widgetId: '2',
95     widgetName: 'TestData1',
96     widgetStatus: 'TestStatus1',
97     imageLink: 'week_1.png',
98     select: true
99   },
100   {
101     widgetId: '3',
102     widgetName: 'TestData1',
103     widgetStatus: 'TestStatus1',
104     imageLink: 'week_1.png',
105     select: true
106   },
107   {
108     widgetId: '4',
109     widgetName: 'TestData1',
110     widgetStatus: 'TestStatus1',
111     imageLink: 'week_1.png',
112     select: true
113   },
114   {
115     widgetId: '5',
116     widgetName: 'TestData1',
117     widgetStatus: 'TestStatus1',
118     imageLink: 'week_1.png',
119     select: true
120   },
121   {
122     widgetId: '6',
123     widgetName: 'TestData1',
124     widgetStatus: 'TestStatus1',
125     imageLink: 'week_1.png',
126     select: true
127   },
128   {
129     widgetId: '7',
130     widgetName: 'TestData1',
131     widgetStatus: 'TestStatus1',
132     imageLink: 'week_1.png',
133     select: true
134   },
135   {
136     widgetId: '8',
137     widgetName: 'TestData1',
138     widgetStatus: 'TestStatus1',
139     imageLink: 'week_1.png',
140     select: true
141   }];
142
143
144   public getWidgetCatalog(): any {
145     const widgetCatalogObservable = new Observable(observer => {
146       setTimeout(() => {
147         observer.next(this.widgetCatalogData);
148       }, 1000);
149     });
150
151     return widgetCatalogObservable;
152   }
153   getUserWidgets(loginName: string): Observable<any> {
154     return this.api.get(environment.api.widgetCommon + '/widgetCatalog' + '/' + loginName);
155   }
156   getManagedWidgets(): Observable<any> {
157     return this.api.get(environment.api.widgetCommon + '/widgetCatalog');
158   }
159   getUploadFlag(): Observable<any> {
160     return this.api.get(environment.api.widgetCommon + '/uploadFlag');
161   }
162   // createWidget(newWidget: any, widgetNameparam: string): Observable<any> {
163   //   return this.api.post(environment.api.widgetCommon + '/widgetCatalog', newWidget, widgetNameparam);
164   // }
165
166   // updateWidgetWithFile(newWidget: any, widgetNameparam: string, widgetIdParam: string): Observable<any> {
167   //   return this.api.post(environment.api.widgetCommon + '/widgetCatalog/' + widgetIdParam, newWidget, widgetNameparam);
168   // }
169
170   updateWidget(newWidget: any, widgetIdParam: string): Observable<any> {
171     return this.api.put(environment.api.widgetCommon + '/widgetCatalog/' + widgetIdParam, newWidget);
172   }
173   updateWidgetCatalog(appData: any): Observable<any> {
174     const headers = new HttpHeaders().set('X-Widgets-Type','all');
175     return this.api.put(environment.api.widgetCatalogSelection, appData,{headers});
176   }
177 }