2 * ============LICENSE_START=======================================================
4 * ================================================================================
6 *=================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
27 import { Component, ViewChild, ElementRef, OnInit } from "@angular/core";
28 import { RestApiService } from "src/app/core/services/rest-api.service";
29 import { AdminService } from "src/app/core/services/admin.service";
30 import { DataService } from "src/app/core/models/data-service.model";
31 import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
34 import { ToastrNotificationService } from "src/app/shared/components/toastr-notification/toastr-notification.service";
37 import { NgxSpinnerService } from "ngx-spinner";
39 import { AlertComponent } from "src/app/shared/components/alert/alert.component";
40 import { map, mergeMap } from "rxjs/operators";
41 import { forkJoin, from } from "rxjs";
44 import { ModalComponent } from "src/app/shared/modules/modal/modal.component";
45 import { ModalContentData } from "src/app/shared/modules/modal/modal.data";
46 import { DeModalComponent } from "src/app/views/data-exposure/de-modal/de-modal.component";
49 selector: "app-data-exposure",
50 templateUrl: "./data-exposure.component.html",
51 styleUrls: ["./data-exposure.component.css"]
53 export class DataExposureComponent implements OnInit {
54 datas: Array<DataService> = [];
55 t_temp: Array<DataService> = [];
56 columns: Array<any> = []; // column of table
58 @ViewChild("searchText") searchText: ElementRef;
60 private restApiService: RestApiService,
61 private modalService: NgbModal,
62 private notificationService: ToastrNotificationService,
63 private spinner: NgxSpinnerService,
64 private adminService: AdminService
67 this.adminService.setTitle("SIDEBAR.DATAEXPOSURE");
72 let t_data: Array<DataService> = [];
74 const get_ds = this.restApiService.getAllDataService().pipe(
75 mergeMap(dss => from(dss)),
81 forkJoin(get_ds).subscribe(data => {
82 this.columns = this.initColumn();
84 this.t_temp = [...this.datas];
85 this.updateFilter(this.searchText.nativeElement.value);
93 let t_columns: Array<any> = [];
103 headerName: "DESCRIPTION",
123 updateFilter(searchValue: string) {
124 const val = searchValue.toLowerCase();
127 const temp = this.t_temp.filter(data => {
128 return data.id.toLowerCase().indexOf(val) !== -1 || !val;
135 btnTableAction(passValueArr: Array<any>) {
136 let action = passValueArr[0];
137 let id = passValueArr[1];
141 this.openModal("edit", id);
144 const modalRef = this.modalService.open(AlertComponent, {
149 modalRef.componentInstance.message = "ARE_YOU_SURE_DELETE";
150 modalRef.componentInstance.passEntry.subscribe(recevicedEntry => {
151 this.restApiService.deleteDataService(id).subscribe(
155 this.notificationService.success("SUCCESSFULLY_DELETED");
159 this.notificationService.error(err);
168 openModal(mode: string = "", id: number | string) {
169 const modalRef = this.modalService.open(ModalComponent, {
177 let newDS: DataService;
178 let componentNew = new ModalContentData(DeModalComponent, newDS);
180 modalRef.componentInstance.title = "NEW_DATASERVICE";
181 modalRef.componentInstance.notice = "";
182 modalRef.componentInstance.mode = "new";
183 modalRef.componentInstance.component = componentNew;
185 modalRef.componentInstance.passEntry.subscribe((data: DataService) => {
186 newDS = Object.assign({}, data);
187 this.restApiService.addDataService(newDS).subscribe(
191 this.notificationService.success("SUCCESSFULLY_CREARED");
195 this.notificationService.error(err);
202 let index: number = this.datas.findIndex(data => data.id === id);
203 let editDS: DataService = this.datas[index];
204 let componentEdit = new ModalContentData(DeModalComponent, editDS);
206 modalRef.componentInstance.title = editDS.id;
207 modalRef.componentInstance.notice = "";
208 modalRef.componentInstance.mode = "edit";
209 modalRef.componentInstance.component = componentEdit;
211 modalRef.componentInstance.passEntry.subscribe((data: DataService) => {
212 editDS = Object.assign({}, data);
213 this.restApiService.updateDataService(editDS).subscribe(
217 this.notificationService.success("SUCCESSFULLY_UPDATED");
221 this.notificationService.error(err);