From 306728414314039a352719e96818726414cccd23 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 17 Jun 2024 08:10:14 -0500 Subject: [PATCH 1/3] #265 - Link to service --- .../df-script-details.component.html | 5 + .../df-script-details.component.ts | 2 + .../df-link-service.component.html | 79 +++++++++++ .../df-link-service.component.scss | 20 +++ .../df-link-service.component.spec.ts | 21 +++ .../df-link-service.component.ts | 123 ++++++++++++++++++ 6 files changed, 250 insertions(+) create mode 100644 src/app/shared/components/df-link-service/df-link-service.component.html create mode 100644 src/app/shared/components/df-link-service/df-link-service.component.scss create mode 100644 src/app/shared/components/df-link-service/df-link-service.component.spec.ts create mode 100644 src/app/shared/components/df-link-service/df-link-service.component.ts diff --git a/src/app/adf-event-scripts/df-script-details/df-script-details.component.html b/src/app/adf-event-scripts/df-script-details/df-script-details.component.html index a7ba0424..4c9fa82a 100644 --- a/src/app/adf-event-scripts/df-script-details/df-script-details.component.html +++ b/src/app/adf-event-scripts/df-script-details/df-script-details.component.html @@ -106,6 +106,11 @@ class="dynamic-width" >{{ 'Allow Event Modification' | transloco }} + + + + + Link to Service + + + + Select Service + + + {{ service.label }} + + + + + Repository: + + + + Branch/Tag: + + + + Path + + +
+ + +
+
+
+ diff --git a/src/app/shared/components/df-link-service/df-link-service.component.scss b/src/app/shared/components/df-link-service/df-link-service.component.scss new file mode 100644 index 00000000..628c9f18 --- /dev/null +++ b/src/app/shared/components/df-link-service/df-link-service.component.scss @@ -0,0 +1,20 @@ + + +.lnik-service-accordion { + padding: 16px 0; +} + +.mat-column-actions { + max-width: 10%; +} +.mat-column-private { + max-width: 10%; +} +.mat-mdc-cell { + padding: 8px; +} + +.form-field-gap { + margin-top: 10px; + margin-bottom: 10px; +} \ No newline at end of file diff --git a/src/app/shared/components/df-link-service/df-link-service.component.spec.ts b/src/app/shared/components/df-link-service/df-link-service.component.spec.ts new file mode 100644 index 00000000..08a8aecf --- /dev/null +++ b/src/app/shared/components/df-link-service/df-link-service.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { DfLinkServiceComponent } from './df-link-service.component'; + +describe('DfLinkServiceComponent', () => { + let component: DfLinkServiceComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [DfLinkServiceComponent] + }); + fixture = TestBed.createComponent(DfLinkServiceComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/shared/components/df-link-service/df-link-service.component.ts b/src/app/shared/components/df-link-service/df-link-service.component.ts new file mode 100644 index 00000000..2c9caf9d --- /dev/null +++ b/src/app/shared/components/df-link-service/df-link-service.component.ts @@ -0,0 +1,123 @@ +import { Component, Inject, OnInit, Input } from '@angular/core'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatButtonModule } from '@angular/material/button'; +import { MatTableModule } from '@angular/material/table'; +import { MatInputModule } from '@angular/material/input'; +import { MatSelectModule } from '@angular/material/select'; +import { MatOptionModule } from '@angular/material/core'; +import { MatSlideToggleModule } from '@angular/material/slide-toggle'; +import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; +import { MatExpansionModule } from '@angular/material/expansion'; +import { TranslocoPipe } from '@ngneat/transloco'; +import { DfThemeService } from 'src/app/shared/services/df-theme.service'; +import { AsyncPipe, CommonModule } from '@angular/common'; +import { UntilDestroy } from '@ngneat/until-destroy'; +import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms'; +import { DfBaseCrudService } from '../../services/df-base-crud.service'; +import { + BASE_SERVICE_TOKEN, + CACHE_SERVICE_TOKEN, + EVENT_SCRIPT_SERVICE_TOKEN, +} from 'src/app/shared/constants/tokens'; +import { switchMap } from 'rxjs'; +import { readAsText } from '../../utilities/file'; +import { Service, ServiceType } from '../../types/service'; + +@UntilDestroy({ checkProperties: true }) +@Component({ + selector: 'df-link-service', + templateUrl: './df-link-service.component.html', + styleUrls: ['./df-link-service.component.scss'], + standalone: true, + imports: [ + MatFormFieldModule, + MatButtonModule, + MatTableModule, + MatInputModule, + MatSelectModule, + MatSlideToggleModule, + FontAwesomeModule, + MatExpansionModule, + TranslocoPipe, + AsyncPipe, + MatOptionModule, + ReactiveFormsModule, + CommonModule, + ], + providers: [DfBaseCrudService], +}) +export class DfLinkServiceComponent implements OnInit { + @Input() cache: string; + @Input({ required: true }) storageServiceId: FormControl; + @Input({ required: true }) storagePath: FormControl; + @Input({ required: true }) content: FormControl; + + roleForm: FormGroup; + storageServices: Array = []; + + constructor( + private themeService: DfThemeService, + @Inject(CACHE_SERVICE_TOKEN) private cacheService: DfBaseCrudService, + @Inject(BASE_SERVICE_TOKEN) private baseService: DfBaseCrudService, + @Inject(EVENT_SCRIPT_SERVICE_TOKEN) private crudService: DfBaseCrudService + ) { + this.roleForm = new FormGroup({ + serviceList: new FormControl(''), + repoInput: new FormControl(''), + branchInput: new FormControl(''), + pathInput: new FormControl(''), + }); + this.baseService + .getAll<{ + serviceTypes: Array; + services: Array; + }>({ + additionalParams: [ + { + key: 'group', + value: 'source control,file', + }, + ], + }) + .subscribe(res => { + this.storageServices = res.services; + }); + } + isDarkMode = this.themeService.darkMode$; + ngOnInit() { + this.updateDataSource(); + } + updateDataSource() { + // + } + onViewLatest() { + const formValues = this.roleForm.getRawValue(); + const service = formValues.serviceList ?? ''; + const repo = formValues.repoInput ?? ''; + const branch = formValues.branchInput ?? ''; + const path = formValues.pathInput ?? ''; + + const filePath = `${service}/_repo/${repo}?branch=${branch}&content=1&path=${path}`; + + if (filePath.endsWith('.json')) { + this.baseService + .downloadJson(filePath) + .subscribe(text => this.content.setValue(text)); + return; + } else { + this.baseService + .downloadFile(filePath) + .pipe(switchMap(res => readAsText(res as Blob))) + .subscribe(text => this.content.setValue(text)); + } + } + + onDeleteCache() { + if (!this.cache) return; + this.cacheService + .delete(`_event/${this.cache}`, { + snackbarSuccess: 'scripts.deleteCacheSuccessMsg', + }) + .subscribe(); + } +} From 350ff4b666da60be9a714ce9b728e666d3aa8e7e Mon Sep 17 00:00:00 2001 From: root Date: Mon, 17 Jun 2024 08:10:51 -0500 Subject: [PATCH 2/3] cleanup --- .../components/df-link-service/df-link-service.component.scss | 4 +--- .../df-link-service/df-link-service.component.spec.ts | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/app/shared/components/df-link-service/df-link-service.component.scss b/src/app/shared/components/df-link-service/df-link-service.component.scss index 628c9f18..088a1f3a 100644 --- a/src/app/shared/components/df-link-service/df-link-service.component.scss +++ b/src/app/shared/components/df-link-service/df-link-service.component.scss @@ -1,5 +1,3 @@ - - .lnik-service-accordion { padding: 16px 0; } @@ -17,4 +15,4 @@ .form-field-gap { margin-top: 10px; margin-bottom: 10px; -} \ No newline at end of file +} diff --git a/src/app/shared/components/df-link-service/df-link-service.component.spec.ts b/src/app/shared/components/df-link-service/df-link-service.component.spec.ts index 08a8aecf..40797ac2 100644 --- a/src/app/shared/components/df-link-service/df-link-service.component.spec.ts +++ b/src/app/shared/components/df-link-service/df-link-service.component.spec.ts @@ -8,7 +8,7 @@ describe('DfLinkServiceComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ - declarations: [DfLinkServiceComponent] + declarations: [DfLinkServiceComponent], }); fixture = TestBed.createComponent(DfLinkServiceComponent); component = fixture.componentInstance; From b15a39bdc745544bb2517376e3ed48a7dd402542 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 17 Jun 2024 08:11:02 -0500 Subject: [PATCH 3/3] cleanup --- .../df-link-service.component.spec.ts | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 src/app/shared/components/df-link-service/df-link-service.component.spec.ts diff --git a/src/app/shared/components/df-link-service/df-link-service.component.spec.ts b/src/app/shared/components/df-link-service/df-link-service.component.spec.ts deleted file mode 100644 index 40797ac2..00000000 --- a/src/app/shared/components/df-link-service/df-link-service.component.spec.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { DfLinkServiceComponent } from './df-link-service.component'; - -describe('DfLinkServiceComponent', () => { - let component: DfLinkServiceComponent; - let fixture: ComponentFixture; - - beforeEach(() => { - TestBed.configureTestingModule({ - declarations: [DfLinkServiceComponent], - }); - fixture = TestBed.createComponent(DfLinkServiceComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -});