Added service 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 { CoreService } from '../core/core.service';
43 import { environment } from 'src/environments/environment';
44 import { HttpClient, HttpHeaders } from '@angular/common/http';
45
46
47
48 @Injectable({
49   providedIn: 'root'
50 })
51 export class WidgetCatalogService {
52   public options: GridsterConfig = {
53     minCols: 6,
54     maxCols: 6,
55     minRows: 7,
56     //maxRows: 4,
57     maxItemCols: 50,
58     minItemCols: 1,
59     maxItemRows: 50,
60     minItemRows: 1,
61     maxItemArea: 2500,
62     minItemArea: 1,
63     defaultItemCols: 2,
64     defaultItemRows: 2,
65     setGridSize: false,
66     fixedColWidth: 250,
67     fixedRowHeight: 250,
68     gridType: GridType.ScrollVertical,
69     swap: true,
70     dynamicColumns: true,
71     displayGrid: DisplayGrid.None,
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   addItem(widgetData: any): void {
85     this.layout.push(widgetData);
86   }
87   widgetCatalogData: IWidgetCatalog[] = [{
88     widgetId: '1',
89     widgetName: 'TestData1',
90     widgetStatus: 'TestStatus1',
91     imageLink: 'week_1.png',
92     select: true
93   },
94   {
95     widgetId: '2',
96     widgetName: 'TestData1',
97     widgetStatus: 'TestStatus1',
98     imageLink: 'week_1.png',
99     select: true
100   },
101   {
102     widgetId: '3',
103     widgetName: 'TestData1',
104     widgetStatus: 'TestStatus1',
105     imageLink: 'week_1.png',
106     select: true
107   },
108   {
109     widgetId: '4',
110     widgetName: 'TestData1',
111     widgetStatus: 'TestStatus1',
112     imageLink: 'week_1.png',
113     select: true
114   },
115   {
116     widgetId: '5',
117     widgetName: 'TestData1',
118     widgetStatus: 'TestStatus1',
119     imageLink: 'week_1.png',
120     select: true
121   },
122   {
123     widgetId: '6',
124     widgetName: 'TestData1',
125     widgetStatus: 'TestStatus1',
126     imageLink: 'week_1.png',
127     select: true
128   },
129   {
130     widgetId: '7',
131     widgetName: 'TestData1',
132     widgetStatus: 'TestStatus1',
133     imageLink: 'week_1.png',
134     select: true
135   },
136   {
137     widgetId: '8',
138     widgetName: 'TestData1',
139     widgetStatus: 'TestStatus1',
140     imageLink: 'week_1.png',
141     select: true
142   }];
143
144
145   public getWidgetCatalog(): any {
146     const widgetCatalogObservable = new Observable(observer => {
147       setTimeout(() => {
148         observer.next(this.widgetCatalogData);
149       }, 1000);
150     });
151
152     return widgetCatalogObservable;
153   }
154   getUserWidgets(loginName: string): Observable<any> {
155     return this.api.get(environment.api.widgetCommon + '/widgetCatalog' + '/' + loginName);
156   }
157   getManagedWidgets(): Observable<any> {
158     return this.api.get(environment.api.widgetCommon + '/widgetCatalog');
159   }
160   getUploadFlag(): Observable<any> {
161     return this.api.get(environment.api.widgetCommon + '/uploadFlag');
162   }
163   // createWidget(newWidget: any, widgetNameparam: string): Observable<any> {
164   //   return this.api.post(environment.api.widgetCommon + '/widgetCatalog', newWidget, widgetNameparam);
165   // }
166
167   // updateWidgetWithFile(newWidget: any, widgetNameparam: string, widgetIdParam: string): Observable<any> {
168   //   return this.api.post(environment.api.widgetCommon + '/widgetCatalog/' + widgetIdParam, newWidget, widgetNameparam);
169   // }
170
171   updateWidget(newWidget: any, widgetIdParam: string): Observable<any> {
172     return this.api.put(environment.api.widgetCommon + '/widgetCatalog/' + widgetIdParam, newWidget);
173   }
174   updateWidgetCatalog(appData: any): Observable<any> {
175     const headers = new HttpHeaders().set('X-Widgets-Type','all');
176     return this.api.put(environment.api.widgetCatalogSelection, appData,{headers});
177   }
178 }