From af47aad1fccc10b4be1d1a6178ce4549b049ca22 Mon Sep 17 00:00:00 2001 From: "Mohd. Shariq" Date: Fri, 22 Jul 2022 12:51:17 +0530 Subject: [PATCH 01/10] working on plugin data view Signed-off-by: Mohd. Shariq --- .../config-children.component.css | 1 + .../config-children.component.html | 12 +- .../config-children.component.ts | 14 +- .../plugin-data.service.spec.ts | 16 ++ .../plugin-dev-data/plugin-data.service.ts | 33 ++++ .../plugin-dev-data.component.css | 12 ++ .../plugin-dev-data.component.html | 71 +++++++++ .../plugin-dev-data.component.spec.ts | 25 +++ .../plugin-dev-data.component.ts | 145 ++++++++++++++++++ .../north-task-modal.component.html | 3 +- src/app/shared.module.ts | 3 + 11 files changed, 328 insertions(+), 7 deletions(-) create mode 100644 src/app/components/core/configuration-manager/plugin-dev-data/plugin-data.service.spec.ts create mode 100644 src/app/components/core/configuration-manager/plugin-dev-data/plugin-data.service.ts create mode 100644 src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.css create mode 100644 src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.html create mode 100644 src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.spec.ts create mode 100644 src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.ts diff --git a/src/app/components/core/configuration-manager/config-children/config-children.component.css b/src/app/components/core/configuration-manager/config-children/config-children.component.css index 785b172a6..7569147bb 100644 --- a/src/app/components/core/configuration-manager/config-children/config-children.component.css +++ b/src/app/components/core/configuration-manager/config-children/config-children.component.css @@ -21,6 +21,7 @@ border-top-right-radius: 0 !important; position: relative; padding: 1rem; + overflow: visible; } .tabs { diff --git a/src/app/components/core/configuration-manager/config-children/config-children.component.html b/src/app/components/core/configuration-manager/config-children/config-children.component.html index e6d47b972..01d9e52b1 100644 --- a/src/app/components/core/configuration-manager/config-children/config-children.component.html +++ b/src/app/components/core/configuration-manager/config-children/config-children.component.html @@ -13,10 +13,17 @@
+ +
  • +
    + Developer +
    +
  • -

    +

    @@ -30,5 +37,8 @@

    [categoryConfigurationData]="securityConfiguration" [useChildrenProxy]="useCategoryChildrenProxy" formId="security"> + + +

    diff --git a/src/app/components/core/configuration-manager/config-children/config-children.component.ts b/src/app/components/core/configuration-manager/config-children/config-children.component.ts index 7d83e89a7..57646b8b0 100644 --- a/src/app/components/core/configuration-manager/config-children/config-children.component.ts +++ b/src/app/components/core/configuration-manager/config-children/config-children.component.ts @@ -1,6 +1,8 @@ import { Component, Input } from '@angular/core'; import { ConfigurationService } from '../../../../services'; +import { DeveloperFeaturesService } from '../../../../services/developer-features.service'; + @Component({ selector: 'app-config-children', @@ -9,16 +11,18 @@ import { ConfigurationService } from '../../../../services'; }) export class ConfigChildrenComponent { seletedTab = ''; - useCategoryChildrenProxy = 'true' - categoryKey = '' + useCategoryChildrenProxy = 'true'; + categoryKey = ''; advanceConfiguration: any; securityConfiguration: any; - categoryChildren = [] - @Input() category + categoryChildren = []; + @Input() category; + @Input() plugin; constructor( - private configService: ConfigurationService + private configService: ConfigurationService, + public developerFeaturesService: DeveloperFeaturesService, ) { } ngOnInit() { diff --git a/src/app/components/core/configuration-manager/plugin-dev-data/plugin-data.service.spec.ts b/src/app/components/core/configuration-manager/plugin-dev-data/plugin-data.service.spec.ts new file mode 100644 index 000000000..5443363de --- /dev/null +++ b/src/app/components/core/configuration-manager/plugin-dev-data/plugin-data.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { PluginDataService } from './plugin-data.service'; + +describe('PluginDataService', () => { + let service: PluginDataService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(PluginDataService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/components/core/configuration-manager/plugin-dev-data/plugin-data.service.ts b/src/app/components/core/configuration-manager/plugin-dev-data/plugin-data.service.ts new file mode 100644 index 000000000..f5ae9d6d9 --- /dev/null +++ b/src/app/components/core/configuration-manager/plugin-dev-data/plugin-data.service.ts @@ -0,0 +1,33 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { throwError } from 'rxjs'; +import { catchError, map } from 'rxjs/operators'; + +import { environment } from '../../../../../environments/environment'; + +@Injectable({ + providedIn: 'root' +}) +export class PluginDataService { + private SERVICE_URL = environment.BASE_URL + 'service'; + constructor(private http: HttpClient) { } + + public getData(serviceName: string, pluginName: string) { + return this.http.get(`${this.SERVICE_URL}/${encodeURIComponent(serviceName)}/plugin/${encodeURIComponent(pluginName)}/data`).pipe( + map(response => response), + catchError(error => throwError(error))); + } + + public importData(serviceName: string, pluginName: string, payload: any) { + return this.http.post(`${this.SERVICE_URL}/${encodeURIComponent(serviceName)}/plugin/${encodeURIComponent(pluginName)}/data`, payload).pipe( + map(response => response), + catchError(error => throwError(error))); + } + + public deleteData(serviceName: string, pluginName: string) { + return this.http.delete(`${this.SERVICE_URL}/${encodeURIComponent(serviceName)}/plugin/${encodeURIComponent(pluginName)}/data`).pipe( + map(response => response), + catchError(error => throwError(error))); + } + +} diff --git a/src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.css b/src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.css new file mode 100644 index 000000000..17202862c --- /dev/null +++ b/src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.css @@ -0,0 +1,12 @@ +.context-menu { + border: none; +} + +.dropdown-content { + width: 80% !important; +} + +.is-disable{ + pointer-events: none; + opacity: .65; + } diff --git a/src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.html b/src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.html new file mode 100644 index 000000000..478c9d9cb --- /dev/null +++ b/src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.html @@ -0,0 +1,71 @@ +
    +
    +
    +
    {{pluginData | json}}
    +
    + +
    +
    + + + + + +
    + + +
    +
    diff --git a/src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.spec.ts b/src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.spec.ts new file mode 100644 index 000000000..6f38a784f --- /dev/null +++ b/src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PluginDevDataComponent } from './plugin-dev-data.component'; + +describe('PluginDevDataComponent', () => { + let component: PluginDevDataComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ PluginDevDataComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(PluginDevDataComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.ts b/src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.ts new file mode 100644 index 000000000..147f98af0 --- /dev/null +++ b/src/app/components/core/configuration-manager/plugin-dev-data/plugin-dev-data.component.ts @@ -0,0 +1,145 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { DialogService } from '../../../common/confirmation-dialog/dialog.service'; +import { AlertService, ProgressBarService } from '../../../../services'; +import { PluginDataService } from './plugin-data.service'; + +@Component({ + selector: 'app-plugin-dev-data', + templateUrl: './plugin-dev-data.component.html', + styleUrls: ['./plugin-dev-data.component.css'] +}) +export class PluginDevDataComponent implements OnInit { + @Input() serviceName; + @Input() pluginName; + public pluginData; + public isJsonExtension = true; + public selectedTheme = 'default'; + + constructor( + public pluginDataService: PluginDataService, + private alertService: AlertService, + private dialogService: DialogService, + public ngProgress: ProgressBarService) { } + + ngOnInit(): void { + console.log('serviceName', this.serviceName); + console.log('pluginName', this.pluginName); + this.getData(); + } + + getData() { + /** request started */ + this.ngProgress.start(); + this.pluginDataService.getData(this.serviceName, this.pluginName) + .subscribe( + (res: any) => { + console.log('data', res.data); + this.pluginData = res.data; + /** request completed */ + this.ngProgress.done(); + }, + error => { + /** request completed but error */ + this.ngProgress.done(); + if (error.status === 0) { + console.log('service down ', error); + } else { + this.alertService.error(error.statusText); + } + }); + } + + openModal(id: string) { + this.dialogService.open(id); + } + + closeModal(id: string) { + this.dialogService.close(id); + } + + onPluginDataFileChange(event: any) { + this.pluginData = ''; + if (event.target.files.length !== 0) { + const fileName = event.target.files[0].name; + const ext = fileName.substr(fileName.lastIndexOf('.') + 1); + if (ext !== 'json') { + this.isJsonExtension = false; + return; + } + this.isJsonExtension = true; + if (event.target.files.length > 0) { + const file = event.target.files[0]; + const fileReader = new FileReader(); + fileReader.readAsText(file); + fileReader.onload = () => { + this.pluginData = fileReader.result; + }; + } + } + } + + + exportPluginData(pluginData: any) { + const str = JSON.stringify(pluginData); + const bytes = new TextEncoder().encode(str); + const blob = new Blob([bytes], { + type: "application/json;charset=utf-8" + }); + const url = window.URL.createObjectURL(blob); + // create a custom anchor tag + const a = document.createElement('a'); + a.href = url; + a.download = `${this.serviceName}_${this.pluginName}_data`; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + } + + importPluginData() { + const payload = { data: JSON.parse(JSON.stringify(this.pluginData)) }; + console.log('plugin data', payload); + /** request started */ + this.ngProgress.start(); + this.pluginDataService.importData(this.serviceName, this.pluginName, payload) + .subscribe( + (data: any) => { + this.pluginData = data.result; + this.alertService.success(data.result); + /** request completed */ + this.ngProgress.done(); + this.closeModal('import-plugin-data-dialog') + }, + error => { + /** request completed but error */ + this.ngProgress.done(); + if (error.status === 0) { + console.log('service down ', error); + } else { + this.alertService.error(error.statusText); + } + }); + } + + deleteData() { + /** request started */ + this.ngProgress.start(); + this.pluginDataService.deleteData(this.serviceName, this.pluginName) + .subscribe( + (data: any) => { + console.log('data', data); + this.alertService.success(data.result); + /** request completed */ + this.ngProgress.done(); + }, + error => { + /** request completed but error */ + this.ngProgress.done(); + if (error.status === 0) { + console.log('service down ', error); + } else { + this.alertService.error(error.statusText); + } + }); + } + +} diff --git a/src/app/components/core/north/north-task-modal/north-task-modal.component.html b/src/app/components/core/north/north-task-modal/north-task-modal.component.html index 0886bd126..cadc74b14 100644 --- a/src/app/components/core/north/north-task-modal/north-task-modal.component.html +++ b/src/app/components/core/north/north-task-modal/north-task-modal.component.html @@ -18,7 +18,8 @@
    -
    diff --git a/src/app/components/core/configuration-manager/plugin-persist-data/plugin-persist-data.component.ts b/src/app/components/core/configuration-manager/plugin-persist-data/plugin-persist-data.component.ts index 6de13d1a1..4bbd341b4 100644 --- a/src/app/components/core/configuration-manager/plugin-persist-data/plugin-persist-data.component.ts +++ b/src/app/components/core/configuration-manager/plugin-persist-data/plugin-persist-data.component.ts @@ -15,6 +15,7 @@ export class PluginPersistDataComponent implements OnInit { public pluginData = ''; public pluginDataToImport = ''; public isJsonExtension; + public jsonParseError = false; // TODO: FOGL-6693 public plugins = [] // add plugins for testing public selectedPlugin = ''; @@ -84,7 +85,6 @@ export class PluginPersistDataComponent implements OnInit { fileReader.readAsText(file); fileReader.onload = () => { this.pluginDataToImport = JSON.parse(JSON.stringify(fileReader.result)); - console.log('file', this.pluginData); }; } } @@ -108,27 +108,33 @@ export class PluginPersistDataComponent implements OnInit { } importPluginData() { - const payload = { data: JSON.parse(this.pluginDataToImport) }; - /** request started */ - this.ngProgress.start(); - this.pluginDataService.importData(this.serviceName, this.pluginName, payload) - .subscribe( - (data: any) => { - this.alertService.success(data.result); - /** request completed */ - this.ngProgress.done(); - this.closeModal('import-plugin-data-dialog'); - this.getData(this.pluginName); - }, - error => { - /** request completed but error */ - this.ngProgress.done(); - if (error.status === 0) { - console.log('service down ', error); - } else { - this.alertService.error(error.statusText); - } - }); + try { + const jsonValue = JSON.parse(this.pluginDataToImport); + const payload = { data: jsonValue }; + this.jsonParseError = false; + /** request started */ + this.ngProgress.start(); + this.pluginDataService.importData(this.serviceName, this.pluginName, payload) + .subscribe( + (data: any) => { + this.alertService.success(data.result); + /** request completed */ + this.ngProgress.done(); + this.closeModal('import-plugin-data-dialog'); + this.getData(this.pluginName); + }, + error => { + /** request completed but error */ + this.ngProgress.done(); + if (error.status === 0) { + console.log('service down ', error); + } else { + this.alertService.error(error.statusText); + } + }); + } catch (ex) { + this.jsonParseError = true; + } } deleteData() { @@ -159,6 +165,7 @@ export class PluginPersistDataComponent implements OnInit { this.fileInput.nativeElement.value = ""; this.pluginDataToImport = ''; this.isJsonExtension = false; + this.jsonParseError = false; } } } From 96e47036c09038b9d3a687fb7609bcdf00e92681 Mon Sep 17 00:00:00 2001 From: "Mohd. Shariq" Date: Tue, 26 Jul 2022 18:16:53 +0530 Subject: [PATCH 09/10] fixed file name issue in file control Signed-off-by: Mohd. Shariq --- .../plugin-persist-data/plugin-persist-data.component.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/components/core/configuration-manager/plugin-persist-data/plugin-persist-data.component.ts b/src/app/components/core/configuration-manager/plugin-persist-data/plugin-persist-data.component.ts index 4bbd341b4..2e63b03ab 100644 --- a/src/app/components/core/configuration-manager/plugin-persist-data/plugin-persist-data.component.ts +++ b/src/app/components/core/configuration-manager/plugin-persist-data/plugin-persist-data.component.ts @@ -148,6 +148,7 @@ export class PluginPersistDataComponent implements OnInit { this.ngProgress.done(); this.closeModal('delete-plugin-data-confirmation-dialog'); this.getData(this.pluginName); + this.resetFileControl(); }, error => { /** request completed but error */ From 7e6736e9523db363c90585de5678ee0e0ca33654 Mon Sep 17 00:00:00 2001 From: "Mohd. Shariq" Date: Tue, 26 Jul 2022 18:38:03 +0530 Subject: [PATCH 10/10] fixed hover issue on dropdown Signed-off-by: Mohd. Shariq --- .../plugin-persist-data/plugin-persist-data.component.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/components/core/configuration-manager/plugin-persist-data/plugin-persist-data.component.css b/src/app/components/core/configuration-manager/plugin-persist-data/plugin-persist-data.component.css index 77b5af68a..4599b3397 100644 --- a/src/app/components/core/configuration-manager/plugin-persist-data/plugin-persist-data.component.css +++ b/src/app/components/core/configuration-manager/plugin-persist-data/plugin-persist-data.component.css @@ -18,3 +18,7 @@ pre { white-space: pre-wrap; } + + .dropdown-menu { + padding-left: 25px !important; + }