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 8d731f07..3e4795a1 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 @@ -108,6 +108,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..088a1f3a --- /dev/null +++ b/src/app/shared/components/df-link-service/df-link-service.component.scss @@ -0,0 +1,18 @@ +.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; +} 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(); + } +}