mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
CST-12174 Implemented data-service for the api calls
This commit is contained in:
@@ -6,6 +6,7 @@ import { SharedModule } from '../../shared/shared.module';
|
|||||||
import { LdnServiceNewComponent } from './ldn-service-new/ldn-service-new.component';
|
import { LdnServiceNewComponent } from './ldn-service-new/ldn-service-new.component';
|
||||||
import { LdnServiceFormComponent } from './ldn-service-form/ldn-service-form.component';
|
import { LdnServiceFormComponent } from './ldn-service-form/ldn-service-form.component';
|
||||||
import { LdnServiceFormEditComponent } from './ldn-service-form-edit/ldn-service-form-edit.component';
|
import { LdnServiceFormEditComponent } from './ldn-service-form-edit/ldn-service-form-edit.component';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ import { LdnServiceFormEditComponent } from './ldn-service-form-edit/ldn-service
|
|||||||
CommonModule,
|
CommonModule,
|
||||||
SharedModule,
|
SharedModule,
|
||||||
AdminLdnServicesRoutingModule,
|
AdminLdnServicesRoutingModule,
|
||||||
|
FormsModule
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
LdnServicesOverviewComponent,
|
LdnServicesOverviewComponent,
|
||||||
|
@@ -112,7 +112,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<div class="col-sm-1">
|
<div class="col-sm-1">
|
||||||
<button (click)="removeInboundPattern(i)" class="btn btn-outline-dark trash-button ml-2">
|
<button type="button" (click)="removeInboundPattern(i)" class="btn btn-outline-dark trash-button ml-2">
|
||||||
<i class="fas fa-trash"></i>
|
<i class="fas fa-trash"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -176,7 +176,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-1">
|
<div class="col-sm-1">
|
||||||
<button (click)="removeOutboundPattern(i)" class="btn btn-outline-dark trash-button ml-2">
|
<button type="button" (click)="removeOutboundPattern(i)" class="btn btn-outline-dark trash-button ml-2">
|
||||||
<i class="fas fa-trash"></i>
|
<i class="fas fa-trash"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -215,7 +215,7 @@
|
|||||||
{{ 'service.overview.delete.body' | translate }}
|
{{ 'service.overview.delete.body' | translate }}
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-4">
|
<div class="mt-4">
|
||||||
<button (click)="this.createService()"
|
<button (click)="this.patchService()"
|
||||||
class="btn btn-primary mr-2 custom-btn">{{ 'service.detail.update' | translate }}</button>
|
class="btn btn-primary mr-2 custom-btn">{{ 'service.detail.update' | translate }}</button>
|
||||||
<button (click)="closeModal()" class="btn btn-danger"
|
<button (click)="closeModal()" class="btn btn-danger"
|
||||||
id="delete-confirm">{{ 'service.detail.return' | translate }}
|
id="delete-confirm">{{ 'service.detail.return' | translate }}
|
||||||
|
@@ -1,396 +1,381 @@
|
|||||||
import { ChangeDetectorRef, Component, Input, TemplateRef, ViewChild } from '@angular/core';
|
import { ChangeDetectorRef, Component, Input, OnInit, TemplateRef, ViewChild } from '@angular/core';
|
||||||
import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
import { LDN_SERVICE } from '../ldn-services-model/ldn-service.resource-type';
|
import { LDN_SERVICE } from '../ldn-services-model/ldn-service.resource-type';
|
||||||
import { Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { HttpClient } from '@angular/common/http';
|
|
||||||
import { LdnDirectoryService } from '../ldn-services-services/ldn-directory.service';
|
import { LdnDirectoryService } from '../ldn-services-services/ldn-directory.service';
|
||||||
import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service';
|
import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service';
|
||||||
import { LdnServiceConstraint } from '../ldn-services-model/ldn-service-constraint.model';
|
|
||||||
import { notifyPatterns } from '../ldn-services-patterns/ldn-service-coar-patterns';
|
import { notifyPatterns } from '../ldn-services-patterns/ldn-service-coar-patterns';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
|
||||||
import { animate, state, style, transition, trigger } from '@angular/animations';
|
import { animate, state, style, transition, trigger } from '@angular/animations';
|
||||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { LdnService } from '../ldn-services-model/ldn-services.model';
|
||||||
|
import { RemoteData } from 'src/app/core/data/remote-data';
|
||||||
|
import { Operation } from 'fast-json-patch';
|
||||||
|
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-ldn-service-form-edit',
|
selector: 'ds-ldn-service-form-edit',
|
||||||
templateUrl: './ldn-service-form-edit.component.html',
|
templateUrl: './ldn-service-form-edit.component.html',
|
||||||
styleUrls: ['./ldn-service-form-edit.component.scss'],
|
styleUrls: ['./ldn-service-form-edit.component.scss'],
|
||||||
animations: [
|
animations: [
|
||||||
trigger('toggleAnimation', [
|
trigger('toggleAnimation', [
|
||||||
state('true', style({})),
|
state('true', style({})),
|
||||||
state('false', style({})),
|
state('false', style({})),
|
||||||
transition('true <=> false', animate('300ms ease-in')),
|
transition('true <=> false', animate('300ms ease-in')),
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class LdnServiceFormEditComponent {
|
export class LdnServiceFormEditComponent implements OnInit {
|
||||||
formModel: FormGroup;
|
formModel: FormGroup;
|
||||||
@ViewChild('confirmModal', {static: true}) confirmModal: TemplateRef<any>;
|
@ViewChild('confirmModal', {static: true}) confirmModal: TemplateRef<any>;
|
||||||
|
|
||||||
showItemFilterDropdown = false;
|
public inboundPatterns: object[] = notifyPatterns;
|
||||||
|
public outboundPatterns: object[] = notifyPatterns;
|
||||||
|
public itemFilterList: any[];
|
||||||
|
@Input() public name: string;
|
||||||
|
@Input() public description: string;
|
||||||
|
@Input() public url: string;
|
||||||
|
@Input() public ldnUrl: string;
|
||||||
|
@Input() public inboundPattern: string;
|
||||||
|
@Input() public outboundPattern: string;
|
||||||
|
@Input() public constraint: string;
|
||||||
|
@Input() public automatic: boolean;
|
||||||
|
@Input() public headerKey: string;
|
||||||
|
private originalInboundPatterns: any[] = [];
|
||||||
|
private originalOutboundPatterns: any[] = [];
|
||||||
|
private modalRef: any;
|
||||||
|
private service: LdnService;
|
||||||
|
protected serviceId: string;
|
||||||
|
|
||||||
private originalInboundPatterns: any[] = [];
|
constructor(
|
||||||
private originalOutboundPatterns: any[] = [];
|
protected ldnServicesService: LdnServicesService,
|
||||||
public inboundPatterns: object[] = notifyPatterns;
|
private ldnDirectoryService: LdnDirectoryService,
|
||||||
public outboundPatterns: object[] = notifyPatterns;
|
private formBuilder: FormBuilder,
|
||||||
public itemFilterList: LdnServiceConstraint[];
|
private router: Router,
|
||||||
private modalRef: any;
|
private route: ActivatedRoute,
|
||||||
|
private cdRef: ChangeDetectorRef,
|
||||||
|
protected modalService: NgbModal,
|
||||||
|
private notificationService: NotificationsService,
|
||||||
|
private translateService: TranslateService,
|
||||||
|
) {
|
||||||
|
|
||||||
@Input() public name: string;
|
this.formModel = this.formBuilder.group({
|
||||||
@Input() public description: string;
|
id: [''],
|
||||||
@Input() public url: string;
|
name: ['', Validators.required],
|
||||||
@Input() public ldnUrl: string;
|
description: ['', Validators.required],
|
||||||
@Input() public inboundPattern: string;
|
url: ['', Validators.required],
|
||||||
@Input() public outboundPattern: string;
|
ldnUrl: ['', Validators.required],
|
||||||
@Input() public constraint: string;
|
inboundPattern: [''],
|
||||||
@Input() public automatic: boolean;
|
outboundPattern: [''],
|
||||||
|
constraintPattern: [''],
|
||||||
|
enabled: [''],
|
||||||
|
notifyServiceInboundPatterns: this.formBuilder.array([this.createInboundPatternFormGroup()]),
|
||||||
|
notifyServiceOutboundPatterns: this.formBuilder.array([this.createOutboundPatternFormGroup()]),
|
||||||
|
type: LDN_SERVICE.value,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Input() public headerKey: string;
|
ngOnInit(): void {
|
||||||
private serviceId: string;
|
this.route.params.subscribe((params) => {
|
||||||
|
this.serviceId = params.serviceId;
|
||||||
|
if (this.serviceId) {
|
||||||
|
this.fetchServiceData(this.serviceId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.ldnDirectoryService.getItemFilters().subscribe((itemFilters) => {
|
||||||
|
this.itemFilterList = itemFilters._embedded.itemfilters.map((filter: { id: string; }) => ({
|
||||||
|
name: filter.id
|
||||||
|
}));
|
||||||
|
this.cdRef.detectChanges();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
constructor(
|
fetchServiceData(serviceId: string): void {
|
||||||
private ldnServicesService: LdnServicesService,
|
this.ldnServicesService.findById(serviceId).pipe(
|
||||||
private ldnDirectoryService: LdnDirectoryService,
|
getFirstCompletedRemoteData()
|
||||||
private formBuilder: FormBuilder,
|
).subscribe(
|
||||||
private http: HttpClient,
|
(data: RemoteData<LdnService>) => {
|
||||||
private router: Router,
|
if (data.hasSucceeded) {
|
||||||
private route: ActivatedRoute,
|
this.service = data.payload;
|
||||||
private cdRef: ChangeDetectorRef,
|
|
||||||
protected modalService: NgbModal,
|
|
||||||
private notificationService: NotificationsService,
|
|
||||||
private translateService: TranslateService,
|
|
||||||
|
|
||||||
) {
|
console.log(this.service);
|
||||||
|
|
||||||
this.formModel = this.formBuilder.group({
|
this.formModel.patchValue({
|
||||||
id: [''],
|
id: this.service.id,
|
||||||
name: ['', Validators.required],
|
name: this.service.name,
|
||||||
description: ['', Validators.required],
|
description: this.service.description,
|
||||||
url: ['', Validators.required],
|
url: this.service.url,
|
||||||
ldnUrl: ['', Validators.required],
|
ldnUrl: this.service.ldnUrl,
|
||||||
inboundPattern: [''],
|
type: this.service.type,
|
||||||
outboundPattern: [''],
|
enabled: this.service.enabled
|
||||||
constraintPattern: [''],
|
});
|
||||||
enabled: [''],
|
|
||||||
notifyServiceInboundPatterns: this.formBuilder.array([this.createInboundPatternFormGroup()]),
|
|
||||||
notifyServiceOutboundPatterns: this.formBuilder.array([this.createOutboundPatternFormGroup()]),
|
|
||||||
type: LDN_SERVICE.value,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
const inboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
||||||
this.route.params.subscribe((params) => {
|
inboundPatternsArray.clear();
|
||||||
this.serviceId = params.serviceId;
|
|
||||||
if (this.serviceId) {
|
this.service.notifyServiceInboundPatterns.forEach((pattern: any) => {
|
||||||
this.fetchServiceData(this.serviceId);
|
const patternFormGroup = this.initializeInboundPatternFormGroup();
|
||||||
}
|
patternFormGroup.patchValue(pattern);
|
||||||
});
|
inboundPatternsArray.push(patternFormGroup);
|
||||||
this.ldnDirectoryService.getItemFilters().subscribe((itemFilters) => {
|
|
||||||
this.itemFilterList = itemFilters._embedded.itemfilters.map((filter: { id: string; }) => ({
|
|
||||||
name: filter.id
|
|
||||||
}));
|
|
||||||
this.cdRef.detectChanges();
|
this.cdRef.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
const outboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
|
||||||
}
|
outboundPatternsArray.clear();
|
||||||
|
|
||||||
private getOriginalPattern(formArrayName: string, patternId: number): any {
|
this.service.notifyServiceOutboundPatterns.forEach((pattern: any) => {
|
||||||
let originalPatterns: any[] = [];
|
const patternFormGroup = this.initializeOutboundPatternFormGroup();
|
||||||
|
patternFormGroup.patchValue(pattern);
|
||||||
|
outboundPatternsArray.push(patternFormGroup);
|
||||||
|
|
||||||
if (formArrayName === 'notifyServiceInboundPatterns') {
|
this.cdRef.detectChanges();
|
||||||
originalPatterns = this.originalInboundPatterns;
|
});
|
||||||
} else if (formArrayName === 'notifyServiceOutboundPatterns') {
|
this.originalInboundPatterns = [...this.service.notifyServiceInboundPatterns];
|
||||||
originalPatterns = this.originalOutboundPatterns;
|
this.originalOutboundPatterns = [...this.service.notifyServiceOutboundPatterns];
|
||||||
|
} else {
|
||||||
|
console.error('Error fetching service data:', data.errorMessage);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
console.error('Error fetching service data:', error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return originalPatterns.find((pattern) => pattern.id === patternId);
|
generatePatchOperations(): any[] {
|
||||||
|
const patchOperations: any[] = [];
|
||||||
|
|
||||||
|
this.createReplaceOperation(patchOperations, 'name', '/name');
|
||||||
|
this.createReplaceOperation(patchOperations, 'description', '/description');
|
||||||
|
this.createReplaceOperation(patchOperations, 'ldnUrl', '/ldnurl');
|
||||||
|
this.createReplaceOperation(patchOperations, 'url', '/url');
|
||||||
|
|
||||||
|
this.handlePatterns(patchOperations, 'notifyServiceInboundPatterns');
|
||||||
|
|
||||||
|
this.handlePatterns(patchOperations, 'notifyServiceOutboundPatterns');
|
||||||
|
|
||||||
|
return patchOperations;
|
||||||
|
}
|
||||||
|
|
||||||
|
submitForm() {
|
||||||
|
this.openConfirmModal(this.confirmModal);
|
||||||
|
}
|
||||||
|
|
||||||
|
addInboundPattern() {
|
||||||
|
const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
||||||
|
notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
removeInboundPattern(index: number): void {
|
||||||
|
const patternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
||||||
|
const patternGroup = patternsArray.at(index) as FormGroup;
|
||||||
|
const patternValue = patternGroup.value;
|
||||||
|
|
||||||
|
if (index < 0 || index >= patternsArray.length || patternValue.isNew) {
|
||||||
|
patternsArray.removeAt(index);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private patternsAreEqual(patternA: any, patternB: any): boolean {
|
const patchOperation: Operation = {
|
||||||
return (
|
op: 'remove',
|
||||||
patternA.pattern === patternB.pattern &&
|
path: `notifyServiceInboundPatterns[${index}]`
|
||||||
patternA.constraint === patternB.constraint &&
|
};
|
||||||
patternA.automatic === patternB.automatic
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchServiceData(serviceId: string): void {
|
this.ldnServicesService.patch(this.service, [patchOperation]).pipe(
|
||||||
const apiUrl = `http://localhost:8080/server/api/ldn/ldnservices/${serviceId}`;
|
getFirstCompletedRemoteData()
|
||||||
|
).subscribe(
|
||||||
this.http.get(apiUrl).subscribe(
|
(data: RemoteData<LdnService>) => {
|
||||||
(data: any) => {
|
if (data.hasSucceeded) {
|
||||||
console.log(data);
|
this.notificationService.success(this.translateService.get('ldn-service.notification.remove-inbound-pattern.success.title'),
|
||||||
|
this.translateService.get('ldn-service.notification.remove-inbound-pattern.success.content'));
|
||||||
this.formModel.patchValue({
|
} else {
|
||||||
id: data.id,
|
this.notificationService.error(this.translateService.get('ldn-service.notification.remove-inbound-pattern.error.title'),
|
||||||
name: data.name,
|
this.translateService.get('ldn-service.notification.remove-inbound-pattern.error.content'));
|
||||||
description: data.description,
|
}
|
||||||
url: data.url,
|
patternsArray.removeAt(index);
|
||||||
ldnUrl: data.ldnUrl,
|
this.cdRef.detectChanges();
|
||||||
type: data.type,
|
},
|
||||||
enabled: data.enabled
|
(error) => {
|
||||||
});
|
console.error('Error removing pattern:', error);
|
||||||
|
|
||||||
const inboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
|
||||||
inboundPatternsArray.clear(); // Clear existing rows
|
|
||||||
|
|
||||||
data.notifyServiceInboundPatterns.forEach((pattern: any) => {
|
|
||||||
console.log(pattern);
|
|
||||||
const patternFormGroup = this.initializeInboundPatternFormGroup();
|
|
||||||
console.log();
|
|
||||||
patternFormGroup.patchValue(pattern);
|
|
||||||
inboundPatternsArray.push(patternFormGroup);
|
|
||||||
this.cdRef.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
const outboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
|
|
||||||
outboundPatternsArray.clear();
|
|
||||||
|
|
||||||
data.notifyServiceOutboundPatterns.forEach((pattern: any) => {
|
|
||||||
const patternFormGroup = this.initializeOutboundPatternFormGroup();
|
|
||||||
patternFormGroup.patchValue(pattern);
|
|
||||||
outboundPatternsArray.push(patternFormGroup);
|
|
||||||
|
|
||||||
this.cdRef.detectChanges();
|
|
||||||
});
|
|
||||||
this.originalInboundPatterns = [...data.notifyServiceInboundPatterns];
|
|
||||||
|
|
||||||
this.originalOutboundPatterns = [...data.notifyServiceOutboundPatterns];
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
console.error('Error fetching service data:', error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
generatePatchOperations(): any[] {
|
|
||||||
const patchOperations: any[] = [];
|
|
||||||
|
|
||||||
this.addReplaceOperation(patchOperations, 'name', '/name');
|
|
||||||
this.addReplaceOperation(patchOperations, 'description', '/description');
|
|
||||||
this.addReplaceOperation(patchOperations, 'ldnUrl', '/ldnurl');
|
|
||||||
this.addReplaceOperation(patchOperations, 'url', '/url');
|
|
||||||
|
|
||||||
this.handlePatterns(patchOperations, 'notifyServiceInboundPatterns');
|
|
||||||
|
|
||||||
this.handlePatterns(patchOperations, 'notifyServiceOutboundPatterns');
|
|
||||||
|
|
||||||
return patchOperations;
|
|
||||||
}
|
|
||||||
|
|
||||||
private addReplaceOperation(patchOperations: any[], formControlName: string, path: string): void {
|
|
||||||
if (this.formModel.get(formControlName).dirty) {
|
|
||||||
patchOperations.push({
|
|
||||||
op: 'replace',
|
|
||||||
path,
|
|
||||||
value: this.formModel.get(formControlName).value,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
addOutboundPattern() {
|
||||||
|
const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
|
||||||
|
notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
removeOutboundPattern(index: number): void {
|
||||||
|
const patternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
|
||||||
|
const patternGroup = patternsArray.at(index) as FormGroup;
|
||||||
|
const patternValue = patternGroup.value;
|
||||||
|
|
||||||
|
if (index < 0 || index >= patternsArray.length || patternValue.isNew) {
|
||||||
|
patternsArray.removeAt(index);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private handlePatterns(patchOperations: any[], formArrayName: string): void {
|
const patchOperation: Operation = {
|
||||||
const patternsArray = this.formModel.get(formArrayName) as FormArray;
|
op: 'remove',
|
||||||
|
path: `notifyServiceOutboundPatterns[${index}]`
|
||||||
|
};
|
||||||
|
|
||||||
if (patternsArray.dirty) {
|
this.ldnServicesService.patch(this.service, [patchOperation]).pipe(
|
||||||
for (let i = 0; i < patternsArray.length; i++) {
|
getFirstCompletedRemoteData()
|
||||||
const patternGroup = patternsArray.at(i) as FormGroup;
|
).subscribe(
|
||||||
const patternValue = patternGroup.value;
|
(data: RemoteData<LdnService>) => {
|
||||||
|
if (data.hasSucceeded) {
|
||||||
if (patternValue.isNew) {
|
this.notificationService.success(this.translateService.get('ldn-service.notification.remove-outbound-pattern.success.title'),
|
||||||
console.log(this.getOriginalPatternsForFormArray(formArrayName));
|
this.translateService.get('ldn-service.notification.remove-outbound-pattern.success.content'));
|
||||||
console.log(patternGroup);
|
} else {
|
||||||
delete patternValue.isNew;
|
this.notificationService.error(this.translateService.get('ldn-service.notification.remove-outbound-pattern.error.title'),
|
||||||
const addOperation = {
|
this.translateService.get('ldn-service.notification.remove-outbound-pattern.error.content'));
|
||||||
op: 'add',
|
}
|
||||||
path: `${formArrayName}/-`,
|
patternsArray.removeAt(index);
|
||||||
value: patternValue,
|
this.cdRef.detectChanges();
|
||||||
};
|
},
|
||||||
patchOperations.push(addOperation);
|
(error) => {
|
||||||
} else if (patternGroup.dirty) {
|
console.error('Error removing pattern:', error);
|
||||||
const replaceOperation = {
|
|
||||||
op: 'replace',
|
|
||||||
path: `${formArrayName}[${i}]`,
|
|
||||||
value: patternValue,
|
|
||||||
};
|
|
||||||
patchOperations.push(replaceOperation);
|
|
||||||
console.log(patternValue.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private getOriginalPatternsForFormArray(formArrayName: string): any[] {
|
|
||||||
if (formArrayName === 'notifyServiceInboundPatterns') {
|
|
||||||
return this.originalInboundPatterns;
|
|
||||||
} else if (formArrayName === 'notifyServiceOutboundPatterns') {
|
|
||||||
return this.originalOutboundPatterns;
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
submitForm() {
|
|
||||||
this.openConfirmModal(this.confirmModal);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
addInboundPattern() {
|
|
||||||
const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
|
||||||
notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup());
|
|
||||||
}
|
|
||||||
|
|
||||||
removeInboundPattern(index: number) {
|
|
||||||
const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
|
||||||
if (index >= 0 && index < notifyServiceInboundPatternsArray.length) {
|
|
||||||
const serviceId = this.formModel.get('id').value;
|
|
||||||
|
|
||||||
const patchOperation = [
|
|
||||||
{
|
|
||||||
op: 'remove',
|
|
||||||
path: `notifyServiceInboundPatterns[${index}]`
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
const apiUrl = `http://localhost:8080/server/api/ldn/ldnservices/${serviceId}`;
|
|
||||||
|
|
||||||
this.http.patch(apiUrl, patchOperation).subscribe(
|
|
||||||
(response) => {
|
|
||||||
console.log('Pattern removed successfully:', response);
|
|
||||||
|
|
||||||
notifyServiceInboundPatternsArray.removeAt(index);
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
console.error('Error removing pattern:', error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
addOutboundPattern() {
|
|
||||||
const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
|
|
||||||
notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup());
|
|
||||||
}
|
|
||||||
|
|
||||||
removeOutboundPattern(index: number) {
|
|
||||||
const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
|
|
||||||
if (index >= 0 && index < notifyServiceOutboundPatternsArray.length) {
|
|
||||||
const serviceId = this.formModel.get('id').value;
|
|
||||||
|
|
||||||
|
|
||||||
const patchOperation = [
|
|
||||||
{
|
|
||||||
op: 'remove',
|
|
||||||
path: `notifyServiceOutboundPatterns[${index}]`
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
const apiUrl = `http://localhost:8080/server/api/ldn/ldnservices/${serviceId}`;
|
|
||||||
|
|
||||||
this.http.patch(apiUrl, patchOperation).subscribe(
|
|
||||||
(response) => {
|
|
||||||
console.log('Pattern removed successfully:', response);
|
|
||||||
|
|
||||||
notifyServiceOutboundPatternsArray.removeAt(index);
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
console.error('Error removing pattern:', error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private sendBack() {
|
|
||||||
this.router.navigateByUrl('admin/ldn/services');
|
|
||||||
}
|
|
||||||
|
|
||||||
private createOutboundPatternFormGroup(): FormGroup {
|
|
||||||
return this.formBuilder.group({
|
|
||||||
pattern: '',
|
|
||||||
constraint: '',
|
|
||||||
isNew: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private createInboundPatternFormGroup(): FormGroup {
|
|
||||||
return this.formBuilder.group({
|
|
||||||
pattern: '',
|
|
||||||
constraint: '',
|
|
||||||
automatic: '',
|
|
||||||
isNew: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private initializeOutboundPatternFormGroup(): FormGroup {
|
|
||||||
return this.formBuilder.group({
|
|
||||||
pattern: '',
|
|
||||||
constraint: '',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private initializeInboundPatternFormGroup(): FormGroup {
|
|
||||||
return this.formBuilder.group({
|
|
||||||
pattern: '',
|
|
||||||
constraint: '',
|
|
||||||
automatic: '',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleAutomatic(i: number) {
|
|
||||||
const automaticControl = this.formModel.get(`notifyServiceInboundPatterns.${i}.automatic`);
|
|
||||||
if (automaticControl) {
|
|
||||||
automaticControl.setValue(!automaticControl.value);
|
|
||||||
}
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
toggleAutomatic(i: number) {
|
||||||
|
const automaticControl = this.formModel.get(`notifyServiceInboundPatterns.${i}.automatic`);
|
||||||
|
if (automaticControl) {
|
||||||
|
automaticControl.setValue(!automaticControl.value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
toggleEnabled() {
|
toggleEnabled() {
|
||||||
const newStatus = !this.formModel.get('enabled').value;
|
const newStatus = !this.formModel.get('enabled').value;
|
||||||
const serviceId = this.formModel.get('id').value;
|
const serviceId = this.formModel.get('id').value;
|
||||||
const status = this.formModel.get('enabled').value;
|
|
||||||
|
|
||||||
const apiUrl = `http://localhost:8080/server/api/ldn/ldnservices/${serviceId}`;
|
const patchOperation: Operation = {
|
||||||
const patchOperation = {
|
|
||||||
op: 'replace',
|
op: 'replace',
|
||||||
path: '/enabled',
|
path: '/enabled',
|
||||||
value: newStatus,
|
value: newStatus,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.http.patch(apiUrl, [patchOperation]).subscribe(
|
this.ldnServicesService.patch(this.service, [patchOperation]).pipe(
|
||||||
() => {
|
getFirstCompletedRemoteData()
|
||||||
console.log('Status updated successfully.');
|
).subscribe(
|
||||||
this.formModel.get('enabled').setValue(newStatus);
|
() => {
|
||||||
console.log(this.formModel.get('enabled'));
|
console.log('Status updated successfully.');
|
||||||
this.cdRef.detectChanges();
|
this.formModel.get('enabled').setValue(newStatus);
|
||||||
},
|
this.cdRef.detectChanges();
|
||||||
(error) => {
|
},
|
||||||
console.error('Error updating status:', error);
|
(error) => {
|
||||||
}
|
console.error('Error updating status:', error);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
closeModal() {
|
closeModal() {
|
||||||
this.modalRef.close();
|
this.modalRef.close();
|
||||||
this.cdRef.detectChanges();
|
this.cdRef.detectChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
openConfirmModal(content) {
|
openConfirmModal(content) {
|
||||||
this.modalRef = this.modalService.open(content);
|
this.modalRef = this.modalService.open(content);
|
||||||
}
|
}
|
||||||
createService(){
|
|
||||||
const apiUrl = `http://localhost:8080/server/api/ldn/ldnservices/${this.serviceId}`;
|
patchService() {
|
||||||
const patchOperations = this.generatePatchOperations();
|
const patchOperations = this.generatePatchOperations();
|
||||||
this.http.patch(apiUrl, patchOperations).subscribe(
|
|
||||||
(response) => {
|
this.ldnServicesService.patch(this.service, patchOperations).subscribe(
|
||||||
console.log('Service updated successfully:', response);
|
(response) => {
|
||||||
this.sendBack();
|
console.log('Service updated successfully:', response);
|
||||||
this.closeModal();
|
this.closeModal();
|
||||||
this.notificationService.success(this.translateService.get('admin.registries.services-formats.modify.success.head'),
|
this.sendBack();
|
||||||
this.translateService.get('admin.registries.services-formats.modify.success.content'));
|
this.notificationService.success(this.translateService.get('admin.registries.services-formats.modify.success.head'),
|
||||||
},
|
this.translateService.get('admin.registries.services-formats.modify.success.content'));
|
||||||
(error) => {
|
},
|
||||||
this.notificationService.error(this.translateService.get('admin.registries.services-formats.modify.failure.head'),
|
(error) => {
|
||||||
|
this.notificationService.error(this.translateService.get('admin.registries.services-formats.modify.failure.head'),
|
||||||
this.translateService.get('admin.registries.services-formats.modify.failure.content'));
|
this.translateService.get('admin.registries.services-formats.modify.failure.content'));
|
||||||
console.error('Error updating service:', error);
|
console.error('Error updating service:', error);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private createReplaceOperation(patchOperations: any[], formControlName: string, path: string): void {
|
||||||
|
if (this.formModel.get(formControlName).dirty) {
|
||||||
|
patchOperations.push({
|
||||||
|
op: 'replace',
|
||||||
|
path,
|
||||||
|
value: this.formModel.get(formControlName).value,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private handlePatterns(patchOperations: any[], formArrayName: string): void {
|
||||||
|
const patternsArray = this.formModel.get(formArrayName) as FormArray;
|
||||||
|
|
||||||
|
for (let i = 0; i < patternsArray.length; i++) {
|
||||||
|
const patternGroup = patternsArray.at(i) as FormGroup;
|
||||||
|
const patternValue = patternGroup.value;
|
||||||
|
|
||||||
|
if (patternGroup.dirty) {
|
||||||
|
if (patternValue.isNew) {
|
||||||
|
delete patternValue.isNew;
|
||||||
|
const addOperation = {
|
||||||
|
op: 'add',
|
||||||
|
path: `${formArrayName}/-`,
|
||||||
|
value: patternValue,
|
||||||
|
};
|
||||||
|
patchOperations.push(addOperation);
|
||||||
|
} else {
|
||||||
|
const replaceOperation = {
|
||||||
|
op: 'replace',
|
||||||
|
path: `${formArrayName}[${i}]`,
|
||||||
|
value: patternValue,
|
||||||
|
};
|
||||||
|
patchOperations.push(replaceOperation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private sendBack() {
|
||||||
|
this.router.navigateByUrl('admin/ldn/services');
|
||||||
|
}
|
||||||
|
|
||||||
|
private createOutboundPatternFormGroup(): FormGroup {
|
||||||
|
return this.formBuilder.group({
|
||||||
|
pattern: '',
|
||||||
|
constraint: '',
|
||||||
|
isNew: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private createInboundPatternFormGroup(): FormGroup {
|
||||||
|
return this.formBuilder.group({
|
||||||
|
pattern: '',
|
||||||
|
constraint: '',
|
||||||
|
automatic: false,
|
||||||
|
isNew: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private initializeOutboundPatternFormGroup(): FormGroup {
|
||||||
|
return this.formBuilder.group({
|
||||||
|
pattern: '',
|
||||||
|
constraint: '',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private initializeInboundPatternFormGroup(): FormGroup {
|
||||||
|
return this.formBuilder.group({
|
||||||
|
pattern: '',
|
||||||
|
constraint: '',
|
||||||
|
automatic: '',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<form (ngSubmit)="submitForm()" [formGroup]="formModel">
|
<form (ngSubmit)="onSubmit()" [formGroup]="formModel">
|
||||||
|
|
||||||
<!-- In the name section -->
|
<!-- In the name section -->
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
|
@@ -1,172 +1,203 @@
|
|||||||
import { Component, Input, OnInit } from '@angular/core';
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||||
import { FormBuilder, FormGroup, Validators, FormArray } from '@angular/forms';
|
import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
import { HttpClient } from '@angular/common/http';
|
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service';
|
import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service';
|
||||||
import { LdnServiceConstraint } from '../ldn-services-model/ldn-service-constraint.model';
|
|
||||||
import { notifyPatterns } from '../ldn-services-patterns/ldn-service-coar-patterns';
|
import { notifyPatterns } from '../ldn-services-patterns/ldn-service-coar-patterns';
|
||||||
import { LdnDirectoryService } from '../ldn-services-services/ldn-directory.service';
|
import { LdnDirectoryService } from '../ldn-services-services/ldn-directory.service';
|
||||||
import { LDN_SERVICE } from '../ldn-services-model/ldn-service.resource-type';
|
import { LDN_SERVICE } from '../ldn-services-model/ldn-service.resource-type';
|
||||||
import { animate, state, style, transition, trigger } from '@angular/animations';
|
import { animate, state, style, transition, trigger } from '@angular/animations';
|
||||||
|
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
|
||||||
|
import { RemoteData } from '../../../core/data/remote-data';
|
||||||
|
import { LdnService } from '../ldn-services-model/ldn-services.model';
|
||||||
|
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-ldn-service-form',
|
selector: 'ds-ldn-service-form',
|
||||||
templateUrl: './ldn-service-form.component.html',
|
templateUrl: './ldn-service-form.component.html',
|
||||||
styleUrls: ['./ldn-service-form.component.scss'],
|
styleUrls: ['./ldn-service-form.component.scss'],
|
||||||
animations: [
|
animations: [
|
||||||
trigger('toggleAnimation', [
|
trigger('toggleAnimation', [
|
||||||
state('true', style({})), // Define animation states (empty style)
|
state('true', style({})),
|
||||||
state('false', style({})),
|
state('false', style({})),
|
||||||
transition('true <=> false', animate('300ms ease-in')), // Define animation transition with duration
|
transition('true <=> false', animate('300ms ease-in')),
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class LdnServiceFormComponent implements OnInit {
|
export class LdnServiceFormComponent implements OnInit {
|
||||||
formModel: FormGroup;
|
formModel: FormGroup;
|
||||||
|
|
||||||
|
|
||||||
|
public inboundPatterns: object[] = notifyPatterns;
|
||||||
|
public outboundPatterns: object[] = notifyPatterns;
|
||||||
|
public itemFilterList: any[];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//showItemFilterDropdown = false;
|
@Input() public name: string;
|
||||||
|
@Input() public description: string;
|
||||||
|
@Input() public url: string;
|
||||||
|
@Input() public ldnUrl: string;
|
||||||
|
@Input() public inboundPattern: string;
|
||||||
|
@Input() public outboundPattern: string;
|
||||||
|
@Input() public constraint: string;
|
||||||
|
@Input() public automatic: boolean;
|
||||||
|
|
||||||
public inboundPatterns: object[] = notifyPatterns;
|
@Input() public headerKey: string;
|
||||||
public outboundPatterns: object[] = notifyPatterns;
|
@Output() submitForm: EventEmitter<any> = new EventEmitter();
|
||||||
public itemFilterList: LdnServiceConstraint[];
|
@Output() cancelForm: EventEmitter<any> = new EventEmitter();
|
||||||
//additionalOutboundPatterns: FormGroup[] = [];
|
|
||||||
//additionalInboundPatterns: FormGroup[] = [];
|
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private ldnServicesService: LdnServicesService,
|
||||||
|
private ldnDirectoryService: LdnDirectoryService,
|
||||||
|
private formBuilder: FormBuilder,
|
||||||
|
private router: Router,
|
||||||
|
private notificationsService: NotificationsService,
|
||||||
|
private translateService: TranslateService
|
||||||
|
) {
|
||||||
|
|
||||||
//@Input() public status: boolean;
|
this.formModel = this.formBuilder.group({
|
||||||
@Input() public name: string;
|
enabled: true,
|
||||||
@Input() public description: string;
|
id: [''],
|
||||||
@Input() public url: string;
|
name: ['', Validators.required],
|
||||||
@Input() public ldnUrl: string;
|
description: [''],
|
||||||
@Input() public inboundPattern: string;
|
url: ['', Validators.required],
|
||||||
@Input() public outboundPattern: string;
|
ldnUrl: ['', Validators.required],
|
||||||
@Input() public constraint: string;
|
inboundPattern: [''],
|
||||||
@Input() public automatic: boolean;
|
outboundPattern: [''],
|
||||||
|
constraintPattern: [''],
|
||||||
|
notifyServiceInboundPatterns: this.formBuilder.array([this.createInboundPatternFormGroup()]),
|
||||||
|
notifyServiceOutboundPatterns: this.formBuilder.array([this.createOutboundPatternFormGroup()]),
|
||||||
|
type: LDN_SERVICE.value,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Input() public headerKey: string;
|
ngOnInit(): void {
|
||||||
|
this.ldnDirectoryService.getItemFilters().subscribe((itemFilters) => {
|
||||||
|
console.log(itemFilters);
|
||||||
|
this.itemFilterList = itemFilters._embedded.itemfilters.map((filter: { id: string; }) => ({
|
||||||
|
name: filter.id
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
}
|
||||||
get notifyServiceInboundPatternsFormArray(): FormArray {
|
|
||||||
return this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
constructor(
|
/*createLdnService(values: any) {
|
||||||
private ldnServicesService: LdnServicesService,
|
this.formModel.get('name').markAsTouched();
|
||||||
private ldnDirectoryService: LdnDirectoryService,
|
this.formModel.get('url').markAsTouched();
|
||||||
private formBuilder: FormBuilder,
|
this.formModel.get('ldnUrl').markAsTouched();
|
||||||
private http: HttpClient,
|
|
||||||
private router: Router
|
|
||||||
) {
|
|
||||||
|
|
||||||
this.formModel = this.formBuilder.group({
|
const ldnServiceData = this.ldnServicesService.create(this.formModel.value);
|
||||||
enabled: true,
|
|
||||||
id: [''],
|
ldnServiceData.subscribe((ldnNewService) => {
|
||||||
name: ['', Validators.required],
|
console.log(ldnNewService);
|
||||||
description: [''],
|
const name = ldnNewService.payload.name;
|
||||||
url: ['', Validators.required],
|
const url = ldnNewService.payload.url;
|
||||||
ldnUrl: ['', Validators.required],
|
const ldnUrl = ldnNewService.payload.ldnUrl;
|
||||||
inboundPattern: [''],
|
|
||||||
outboundPattern: [''],
|
if (!name || !url || !ldnUrl) {
|
||||||
constraintPattern: [''],
|
return;
|
||||||
notifyServiceInboundPatterns: this.formBuilder.array([this.createInboundPatternFormGroup()]),
|
}
|
||||||
notifyServiceOutboundPatterns: this.formBuilder.array([this.createOutboundPatternFormGroup()]),
|
|
||||||
type: LDN_SERVICE.value,
|
ldnServiceData.pipe(
|
||||||
});
|
getFirstCompletedRemoteData()
|
||||||
|
).subscribe((rd: RemoteData<LdnService>) => {
|
||||||
|
if (rd.hasSucceeded) {
|
||||||
|
this.notificationsService.success(this.translateService.get('notification.created.success'));
|
||||||
|
this.submitForm.emit(values);
|
||||||
|
} else {
|
||||||
|
this.notificationsService.error(this.translateService.get('notification.created.failure', ));
|
||||||
|
this.cancelForm.emit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}*/
|
||||||
|
|
||||||
|
onSubmit() {
|
||||||
|
this.formModel.get('name').markAsTouched();
|
||||||
|
this.formModel.get('url').markAsTouched();
|
||||||
|
this.formModel.get('ldnUrl').markAsTouched();
|
||||||
|
|
||||||
|
const name = this.formModel.get('name').value;
|
||||||
|
const url = this.formModel.get('url').value;
|
||||||
|
const ldnUrl = this.formModel.get('ldnUrl').value;
|
||||||
|
|
||||||
|
if (!name || !url || !ldnUrl) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
const values = this.formModel.value;
|
||||||
this.ldnDirectoryService.getItemFilters().subscribe((itemFilters) => {
|
|
||||||
console.log(itemFilters);
|
|
||||||
this.itemFilterList = itemFilters._embedded.itemfilters.map((filter: { id: string; }) => ({
|
|
||||||
name: filter.id
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
const ldnServiceData = this.ldnServicesService.create(values);
|
||||||
|
|
||||||
|
ldnServiceData.pipe(
|
||||||
|
getFirstCompletedRemoteData()
|
||||||
|
).subscribe((ldnNewService) => {
|
||||||
|
console.log(ldnNewService);
|
||||||
|
});
|
||||||
|
|
||||||
|
ldnServiceData.pipe(
|
||||||
|
getFirstCompletedRemoteData()
|
||||||
|
).subscribe((rd: RemoteData<LdnService>) => {
|
||||||
|
if (rd.hasSucceeded) {
|
||||||
|
this.notificationsService.success(this.translateService.get('notification.created.success'));
|
||||||
|
this.submitForm.emit();
|
||||||
|
this.sendBack();
|
||||||
|
} else {
|
||||||
|
this.notificationsService.error(this.translateService.get('notification.created.failure'));
|
||||||
|
this.cancelForm.emit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
addInboundPattern() {
|
||||||
|
const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
||||||
|
notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
removeInboundPattern(index: number) {
|
||||||
|
const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
||||||
|
notifyServiceInboundPatternsArray.removeAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
addOutboundPattern() {
|
||||||
|
const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
|
||||||
|
notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
removeOutboundPattern(index: number) {
|
||||||
|
const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
|
||||||
|
notifyServiceOutboundPatternsArray.removeAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleAutomatic(i: number) {
|
||||||
|
const automaticControl = this.formModel.get(`notifyServiceInboundPatterns.${i}.automatic`);
|
||||||
|
if (automaticControl) {
|
||||||
|
automaticControl.setValue(!automaticControl.value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
submitForm() {
|
private sendBack() {
|
||||||
this.formModel.get('name').markAsTouched();
|
this.router.navigateByUrl('admin/ldn/services');
|
||||||
this.formModel.get('url').markAsTouched();
|
}
|
||||||
this.formModel.get('ldnUrl').markAsTouched();
|
|
||||||
|
|
||||||
const name = this.formModel.get('name').value;
|
private createOutboundPatternFormGroup(): FormGroup {
|
||||||
const url = this.formModel.get('url').value;
|
return this.formBuilder.group({
|
||||||
const ldnUrl = this.formModel.get('ldnUrl').value;
|
pattern: [''],
|
||||||
|
constraint: [''],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!name || !url || !ldnUrl) {
|
private createInboundPatternFormGroup(): FormGroup {
|
||||||
return;
|
return this.formBuilder.group({
|
||||||
}
|
pattern: [''],
|
||||||
|
constraint: [''],
|
||||||
this.formModel.removeControl('inboundPattern');
|
automatic: false
|
||||||
this.formModel.removeControl('outboundPattern');
|
});
|
||||||
this.formModel.removeControl('constraintPattern');
|
}
|
||||||
console.log('JSON Data:', this.formModel.value);
|
|
||||||
|
|
||||||
const apiUrl = 'http://localhost:8080/server/api/ldn/ldnservices';
|
|
||||||
|
|
||||||
this.http.post(apiUrl, this.formModel.value).subscribe(
|
|
||||||
(response) => {
|
|
||||||
console.log('Service created successfully:', response);
|
|
||||||
this.formModel.reset();
|
|
||||||
this.sendBack();
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
console.error('Error creating service:', error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private sendBack() {
|
|
||||||
this.router.navigateByUrl('admin/ldn/services');
|
|
||||||
}
|
|
||||||
|
|
||||||
addInboundPattern() {
|
|
||||||
const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
|
||||||
notifyServiceInboundPatternsArray.push(this.createInboundPatternFormGroup());
|
|
||||||
}
|
|
||||||
|
|
||||||
removeInboundPattern(index: number) {
|
|
||||||
const notifyServiceInboundPatternsArray = this.formModel.get('notifyServiceInboundPatterns') as FormArray;
|
|
||||||
notifyServiceInboundPatternsArray.removeAt(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
addOutboundPattern() {
|
|
||||||
const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
|
|
||||||
notifyServiceOutboundPatternsArray.push(this.createOutboundPatternFormGroup());
|
|
||||||
}
|
|
||||||
|
|
||||||
removeOutboundPattern(index: number) {
|
|
||||||
const notifyServiceOutboundPatternsArray = this.formModel.get('notifyServiceOutboundPatterns') as FormArray;
|
|
||||||
notifyServiceOutboundPatternsArray.removeAt(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
private createOutboundPatternFormGroup(): FormGroup {
|
|
||||||
return this.formBuilder.group({
|
|
||||||
pattern: [''],
|
|
||||||
constraint: [''],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private createInboundPatternFormGroup(): FormGroup {
|
|
||||||
return this.formBuilder.group({
|
|
||||||
pattern: [''],
|
|
||||||
constraint: [''],
|
|
||||||
automatic: false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleAutomatic(i: number) {
|
|
||||||
const automaticControl = this.formModel.get(`notifyServiceInboundPatterns.${i}.automatic`);
|
|
||||||
if (automaticControl) {
|
|
||||||
automaticControl.setValue(!automaticControl.value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { dataService } from '../../../core/data/base/data-service.decorator';
|
import { dataService } from '../../../core/data/base/data-service.decorator';
|
||||||
import { LDN_SERVICE } from '../ldn-services-model/ldn-service.resource-type';
|
import { LDN_SERVICE } from '../ldn-services-model/ldn-service.resource-type';
|
||||||
import { IdentifiableDataService } from '../../../core/data/base/identifiable-data.service';
|
import { IdentifiableDataService } from '../../../core/data/base/identifiable-data.service';
|
||||||
@@ -19,50 +19,63 @@ import { map, take } from 'rxjs/operators';
|
|||||||
import { URLCombiner } from '../../../core/url-combiner/url-combiner';
|
import { URLCombiner } from '../../../core/url-combiner/url-combiner';
|
||||||
import { MultipartPostRequest } from '../../../core/data/request.models';
|
import { MultipartPostRequest } from '../../../core/data/request.models';
|
||||||
import { RestRequest } from '../../../core/data/rest-request.model';
|
import { RestRequest } from '../../../core/data/rest-request.model';
|
||||||
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
|
|
||||||
import { hasValue } from '../../../shared/empty.util';
|
|
||||||
|
|
||||||
import { LdnService } from '../ldn-services-model/ldn-services.model';
|
import { LdnService } from '../ldn-services-model/ldn-services.model';
|
||||||
import { LdnServiceConstraint } from '../ldn-services-model/ldn-service-constraint.model';
|
|
||||||
import { PatchData, PatchDataImpl } from '../../../core/data/base/patch-data';
|
import { PatchData, PatchDataImpl } from '../../../core/data/base/patch-data';
|
||||||
import { ChangeAnalyzer } from '../../../core/data/change-analyzer';
|
import { ChangeAnalyzer } from '../../../core/data/change-analyzer';
|
||||||
import { Operation } from 'fast-json-patch';
|
import { Operation } from 'fast-json-patch';
|
||||||
import { RestRequestMethod } from 'src/app/core/data/rest-request-method';
|
import { RestRequestMethod } from 'src/app/core/data/rest-request-method';
|
||||||
|
import { CreateData, CreateDataImpl } from '../../../core/data/base/create-data';
|
||||||
|
import { ldnServiceConstrain } from '../ldn-services-model/ldn-service.constrain.model';
|
||||||
|
import { getFirstCompletedRemoteData } from 'src/app/core/shared/operators';
|
||||||
|
import { hasValue } from 'src/app/shared/empty.util';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@dataService(LDN_SERVICE)
|
@dataService(LDN_SERVICE)
|
||||||
export class LdnServicesService extends IdentifiableDataService<LdnService> implements FindAllData<LdnService>, DeleteData<LdnService>, PatchData<LdnService> {
|
export class LdnServicesService extends IdentifiableDataService<LdnService> implements FindAllData<LdnService>, DeleteData<LdnService>, PatchData<LdnService>, CreateData<LdnService> {
|
||||||
private findAllData: FindAllDataImpl<LdnService>;
|
createData: CreateDataImpl<LdnService>;
|
||||||
private deleteData: DeleteDataImpl<LdnService>;
|
private findAllData: FindAllDataImpl<LdnService>;
|
||||||
private patchData: PatchDataImpl<LdnService>;
|
private deleteData: DeleteDataImpl<LdnService>;
|
||||||
private comparator: ChangeAnalyzer<LdnService>;
|
private patchData: PatchDataImpl<LdnService>;
|
||||||
|
private comparator: ChangeAnalyzer<LdnService>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected requestService: RequestService,
|
protected requestService: RequestService,
|
||||||
protected rdbService: RemoteDataBuildService,
|
protected rdbService: RemoteDataBuildService,
|
||||||
protected objectCache: ObjectCacheService,
|
protected objectCache: ObjectCacheService,
|
||||||
protected halService: HALEndpointService,
|
protected halService: HALEndpointService,
|
||||||
protected notificationsService: NotificationsService,
|
protected notificationsService: NotificationsService,
|
||||||
) {
|
) {
|
||||||
super('ldnservices', requestService, rdbService, objectCache, halService);
|
super('ldnservices', requestService, rdbService, objectCache, halService);
|
||||||
|
|
||||||
this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
|
this.findAllData = new FindAllDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
|
||||||
this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint);
|
this.deleteData = new DeleteDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive, this.constructIdEndpoint);
|
||||||
this.patchData = new PatchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.comparator, this.responseMsToLive, this.constructIdEndpoint);
|
this.patchData = new PatchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.comparator, this.responseMsToLive, this.constructIdEndpoint);
|
||||||
}
|
this.createData = new CreateDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, notificationsService, this.responseMsToLive);
|
||||||
|
}
|
||||||
|
|
||||||
patch(object: LdnService, operations: Operation[]): Observable<RemoteData<LdnService>> {
|
|
||||||
throw new Error('Method not implemented.');
|
create(object: LdnService): Observable<RemoteData<LdnService>> {
|
||||||
}
|
return this.createData.create(object);
|
||||||
update(object: LdnService): Observable<RemoteData<LdnService>> {
|
}
|
||||||
throw new Error('Method not implemented.');
|
|
||||||
}
|
patch(object: LdnService, operations: Operation[]): Observable<RemoteData<LdnService>> {
|
||||||
commitUpdates(method?: RestRequestMethod): void {
|
return this.patchData.patch(object, operations);
|
||||||
throw new Error('Method not implemented.');
|
}
|
||||||
}
|
|
||||||
createPatchFromCache(object: LdnService): Observable<Operation[]> {
|
update(object: LdnService): Observable<RemoteData<LdnService>> {
|
||||||
throw new Error('Method not implemented.');
|
return this.patchData.update(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commitUpdates(method?: RestRequestMethod): void {
|
||||||
|
return this.patchData.commitUpdates(method);
|
||||||
|
}
|
||||||
|
|
||||||
|
createPatchFromCache(object: LdnService): Observable<Operation[]> {
|
||||||
|
return this.patchData.createPatchFromCache(object);
|
||||||
|
}
|
||||||
|
|
||||||
findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<LdnService>[]): Observable<RemoteData<PaginatedList<LdnService>>> {
|
findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<LdnService>[]): Observable<RemoteData<PaginatedList<LdnService>>> {
|
||||||
return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
|
||||||
@@ -76,21 +89,22 @@ import { RestRequestMethod } from 'src/app/core/data/rest-request-method';
|
|||||||
return this.deleteData.deleteByHref(href, copyVirtualMetadata);
|
return this.deleteData.deleteByHref(href, copyVirtualMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
public invoke(serviceName: string, parameters: LdnServiceConstraint[], files: File[]): Observable<RemoteData<LdnService>> {
|
public invoke(serviceName: string, serviceId: string, parameters: ldnServiceConstrain[], files: File[]): Observable<RemoteData<LdnService>> {
|
||||||
const requestId = this.requestService.generateRequestId();
|
const requestId = this.requestService.generateRequestId();
|
||||||
this.getBrowseEndpoint().pipe(
|
this.getBrowseEndpoint().pipe(
|
||||||
take(1),
|
take(1),
|
||||||
map((endpoint: string) => new URLCombiner(endpoint, serviceName, 'processes').toString()),
|
map((endpoint: string) => new URLCombiner(endpoint, serviceName, 'processes', serviceId).toString()),
|
||||||
map((endpoint: string) => {
|
map((endpoint: string) => {
|
||||||
const body = this.getInvocationFormData(parameters, files);
|
const body = this.getInvocationFormData(parameters, files);
|
||||||
return new MultipartPostRequest(requestId, endpoint, body);
|
return new MultipartPostRequest(requestId, endpoint, body);
|
||||||
})
|
})
|
||||||
).subscribe((request: RestRequest) => this.requestService.send(request));
|
).subscribe((request: RestRequest) => this.requestService.send(request));
|
||||||
|
|
||||||
return this.rdbService.buildFromRequestUUID<LdnService>(requestId);
|
return this.rdbService.buildFromRequestUUID<LdnService>(requestId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getInvocationFormData(constrain: LdnServiceConstraint[], files: File[]): FormData {
|
|
||||||
|
private getInvocationFormData(constrain: ldnServiceConstrain[], files: File[]): FormData {
|
||||||
const form: FormData = new FormData();
|
const form: FormData = new FormData();
|
||||||
form.set('properties', JSON.stringify(constrain));
|
form.set('properties', JSON.stringify(constrain));
|
||||||
files.forEach((file: File) => {
|
files.forEach((file: File) => {
|
||||||
|
@@ -23,12 +23,12 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr *ngFor="let ldnService of (ldnServicesRD$| async)?.payload?.page">
|
<tr *ngFor="let ldnService of (ldnServicesRD$ | async)?.payload?.page">
|
||||||
<td>{{ ldnService.name }}</td>
|
<td>{{ ldnService.name }}</td>
|
||||||
<td>{{ ldnService.description }}</td>
|
<td>{{ ldnService.description }}</td>
|
||||||
<td>
|
<td>
|
||||||
<span [ngClass]="{ 'status-enabled': ldnService.enabled, 'status-disabled': !ldnService.enabled }"
|
<span [ngClass]="{ 'status-enabled': ldnService.enabled, 'status-disabled': !ldnService.enabled }"
|
||||||
class="status-indicator" (click)="toggleStatus(ldnService)"
|
class="status-indicator" (click)="toggleStatus(ldnService, ldnServicesService)"
|
||||||
[title]="ldnService.enabled ? ('ldn-service.overview.table.clickToDisable' | translate) : ('ldn-service.overview.table.clickToEnable' | translate)">
|
[title]="ldnService.enabled ? ('ldn-service.overview.table.clickToDisable' | translate) : ('ldn-service.overview.table.clickToEnable' | translate)">
|
||||||
{{ ldnService.enabled ? ('ldn-service.overview.table.enabled' | translate) : ('ldn-service.overview.table.disabled' | translate) }}
|
{{ ldnService.enabled ? ('ldn-service.overview.table.enabled' | translate) : ('ldn-service.overview.table.disabled' | translate) }}
|
||||||
</span>
|
</span>
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
<div class="mt-4">
|
<div class="mt-4">
|
||||||
<button (click)="closeModal()"
|
<button (click)="closeModal()"
|
||||||
class="btn btn-primary mr-2">{{ 'service.detail.delete.cancel' | translate }}</button>
|
class="btn btn-primary mr-2">{{ 'service.detail.delete.cancel' | translate }}</button>
|
||||||
<button (click)="deleteSelected()" class="btn btn-danger"
|
<button (click)="deleteSelected(this.selectedServiceId.toString(), ldnServicesService)" class="btn btn-danger"
|
||||||
id="delete-confirm">{{ 'service.overview.delete' | translate }}
|
id="delete-confirm">{{ 'service.overview.delete' | translate }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import { ChangeDetectorRef, Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
|
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit, TemplateRef, ViewChild } from '@angular/core';
|
||||||
import { LdnDirectoryService } from '../ldn-services-services/ldn-directory.service';
|
|
||||||
import { Observable, Subscription } from 'rxjs';
|
import { Observable, Subscription } from 'rxjs';
|
||||||
import { RemoteData } from '../../../core/data/remote-data';
|
import { RemoteData } from '../../../core/data/remote-data';
|
||||||
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
import { PaginatedList } from '../../../core/data/paginated-list.model';
|
||||||
@@ -11,170 +10,122 @@ import { LdnServicesService } from 'src/app/admin/admin-ldn-services/ldn-service
|
|||||||
import { PaginationService } from 'src/app/core/pagination/pagination.service';
|
import { PaginationService } from 'src/app/core/pagination/pagination.service';
|
||||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { hasValue } from '../../../shared/empty.util';
|
import { hasValue } from '../../../shared/empty.util';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { Operation } from 'fast-json-patch';
|
||||||
import { getFirstCompletedRemoteData } from "../../../core/shared/operators";
|
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
|
||||||
|
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-ldn-services-directory',
|
selector: 'ds-ldn-services-directory',
|
||||||
templateUrl: './ldn-services-directory.component.html',
|
templateUrl: './ldn-services-directory.component.html',
|
||||||
styleUrls: ['./ldn-services-directory.component.scss'],
|
styleUrls: ['./ldn-services-directory.component.scss'],
|
||||||
|
changeDetection: ChangeDetectionStrategy.Default
|
||||||
})
|
})
|
||||||
export class LdnServicesOverviewComponent implements OnInit, OnDestroy {
|
export class LdnServicesOverviewComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
selectedServiceId: number | null = null;
|
selectedServiceId: string | number | null = null;
|
||||||
servicesData: any[] = [];
|
servicesData: any[] = [];
|
||||||
@ViewChild('deleteModal', {static: true}) deleteModal: TemplateRef<any>;
|
@ViewChild('deleteModal', {static: true}) deleteModal: TemplateRef<any>;
|
||||||
ldnServicesRD$: Observable<RemoteData<PaginatedList<LdnService>>>;
|
ldnServicesRD$: Observable<RemoteData<PaginatedList<LdnService>>>;
|
||||||
config: FindListOptions = Object.assign(new FindListOptions(), {
|
config: FindListOptions = Object.assign(new FindListOptions(), {
|
||||||
elementsPerPage: 20
|
elementsPerPage: 20
|
||||||
|
});
|
||||||
|
pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
|
||||||
|
id: 'po',
|
||||||
|
pageSize: 20
|
||||||
|
});
|
||||||
|
isProcessingSub: Subscription;
|
||||||
|
private modalRef: any;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
protected ldnServicesService: LdnServicesService,
|
||||||
|
protected paginationService: PaginationService,
|
||||||
|
protected modalService: NgbModal,
|
||||||
|
private cdRef: ChangeDetectorRef,
|
||||||
|
private notificationService: NotificationsService,
|
||||||
|
private translateService: TranslateService,
|
||||||
|
private router: Router,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
this.setLdnServices();
|
||||||
|
}
|
||||||
|
|
||||||
|
setLdnServices() {
|
||||||
|
this.ldnServicesRD$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe(
|
||||||
|
switchMap((config) => this.ldnServicesService.findAll(config, true, false).pipe(
|
||||||
|
getFirstCompletedRemoteData()
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
this.ldnServicesRD$.subscribe((rd: RemoteData<PaginatedList<LdnService>>) => {
|
||||||
|
console.log(rd);
|
||||||
|
if (rd.hasSucceeded) {
|
||||||
|
this.notificationService.success(this.translateService.get('notification.loaded.success'));
|
||||||
|
} else {
|
||||||
|
this.notificationService.error(this.translateService.get('notification.loaded.failure'));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
|
}
|
||||||
id: 'po',
|
|
||||||
pageSize: 20
|
|
||||||
});
|
|
||||||
isProcessingSub: Subscription;
|
|
||||||
private modalRef: any;
|
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.paginationService.clearPagination(this.pageConfig.id);
|
||||||
|
if (hasValue(this.isProcessingSub)) {
|
||||||
constructor(
|
this.isProcessingSub.unsubscribe();
|
||||||
protected processLdnService: LdnServicesService,
|
|
||||||
private ldnServicesService: LdnServicesService,
|
|
||||||
protected paginationService: PaginationService,
|
|
||||||
protected modalService: NgbModal,
|
|
||||||
public ldnDirectoryService: LdnDirectoryService,
|
|
||||||
private http: HttpClient,
|
|
||||||
private cdRef: ChangeDetectorRef
|
|
||||||
) {
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
openDeleteModal(content) {
|
||||||
this.setLdnServices2();
|
this.modalRef = this.modalService.open(content);
|
||||||
this.setLdnServices();
|
}
|
||||||
/*this.ldnDirectoryService.listLdnServices();*/
|
|
||||||
/*this.ldnServicesRD$.subscribe(data => {
|
|
||||||
console.log('searchByLdnUrl()', data);
|
|
||||||
});*/
|
|
||||||
|
|
||||||
/*this.ldnServicesRD$.pipe(
|
closeModal() {
|
||||||
tap(data => {
|
this.modalRef.close();
|
||||||
console.log('ldnServicesRD$ data:', data);
|
this.cdRef.detectChanges();
|
||||||
})
|
}
|
||||||
).subscribe(() => {
|
|
||||||
this.searchByLdnUrl();
|
|
||||||
});*/
|
|
||||||
|
|
||||||
}
|
selectServiceToDelete(serviceId: number) {
|
||||||
|
this.selectedServiceId = serviceId;
|
||||||
|
this.openDeleteModal(this.deleteModal);
|
||||||
|
}
|
||||||
|
|
||||||
setLdnServices() {
|
deleteSelected(serviceId: string, ldnServicesService: LdnServicesService): void {
|
||||||
this.ldnServicesService.findAll().pipe(getFirstCompletedRemoteData()).subscribe((remoteData) => {
|
if (this.selectedServiceId !== null) {
|
||||||
|
ldnServicesService.delete(serviceId).pipe(getFirstCompletedRemoteData()).subscribe((rd: RemoteData<LdnService>) => {
|
||||||
if (remoteData.hasSucceeded) {
|
if (rd.hasSucceeded) {
|
||||||
const ldnservices = remoteData.payload.page;
|
this.servicesData = this.servicesData.filter(service => service.id !== serviceId);
|
||||||
console.log(ldnservices);
|
this.cdRef.detectChanges();
|
||||||
} else {
|
this.closeModal();
|
||||||
console.error('Error fetching LDN services:', remoteData.errorMessage);
|
this.notificationService.success(this.translateService.get('notification.created.success'));
|
||||||
}
|
} else {
|
||||||
});
|
this.notificationService.error(this.translateService.get('notification.created.failure'));
|
||||||
}
|
this.cdRef.detectChanges();
|
||||||
|
|
||||||
setLdnServices2() {
|
|
||||||
this.ldnServicesRD$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe(
|
|
||||||
switchMap((config) => this.ldnServicesService.findAll(config, true, false))
|
|
||||||
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
|
||||||
this.paginationService.clearPagination(this.pageConfig.id);
|
|
||||||
if (hasValue(this.isProcessingSub)) {
|
|
||||||
this.isProcessingSub.unsubscribe();
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
openDeleteModal(content) {
|
|
||||||
this.modalRef = this.modalService.open(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
closeModal() {
|
|
||||||
this.modalRef.close();
|
|
||||||
this.cdRef.detectChanges();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
findAllServices(): void {
|
toggleStatus(ldnService: any, ldnServicesService: LdnServicesService): void {
|
||||||
this.retrieveAll().subscribe(
|
const newStatus = !ldnService.enabled;
|
||||||
(response) => {
|
let status = ldnService.enabled;
|
||||||
this.servicesData = response._embedded.ldnservices;
|
const patchOperation: Operation = {
|
||||||
console.log('ServicesData =', this.servicesData);
|
op: 'replace',
|
||||||
this.cdRef.detectChanges();
|
path: '/enabled',
|
||||||
},
|
value: newStatus,
|
||||||
(error) => {
|
};
|
||||||
console.error('Error:', error);
|
ldnServicesService.patch(ldnService, [patchOperation]).pipe(getFirstCompletedRemoteData()).subscribe(
|
||||||
}
|
() => {
|
||||||
);
|
if (status !== newStatus) {
|
||||||
}
|
this.notificationService.success(this.translateService.get('ldn-enable-service.notification.success.title'),
|
||||||
|
this.translateService.get('ldn-enable-service.notification.success.content'));
|
||||||
retrieveAll(): Observable<any> {
|
} else {
|
||||||
const url = 'http://localhost:8080/server/api/ldn/ldnservices';
|
this.notificationService.error(this.translateService.get('ldn-enable-service.notification.error.title'),
|
||||||
return this.http.get(url);
|
this.translateService.get('ldn-enable-service.notification.error.content'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
deleteSelected() {
|
|
||||||
if (this.selectedServiceId !== null) {
|
|
||||||
const deleteUrl = `http://localhost:8080/server/api/ldn/ldnservices/${this.selectedServiceId}`;
|
|
||||||
this.http.delete(deleteUrl).subscribe(
|
|
||||||
() => {
|
|
||||||
this.closeModal();
|
|
||||||
this.findAllServices();
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
console.error('Error deleting service:', error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
|
}
|
||||||
selectServiceToDelete(serviceId: number) {
|
|
||||||
this.selectedServiceId = serviceId;
|
|
||||||
this.openDeleteModal(this.deleteModal);
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleStatus(ldnService: any): void {
|
|
||||||
const newStatus = !ldnService.enabled;
|
|
||||||
|
|
||||||
const apiUrl = `http://localhost:8080/server/api/ldn/ldnservices/${ldnService.id}`;
|
|
||||||
const patchOperation = {
|
|
||||||
op: 'replace',
|
|
||||||
path: '/enabled',
|
|
||||||
value: newStatus,
|
|
||||||
};
|
|
||||||
|
|
||||||
this.http.patch(apiUrl, [patchOperation]).subscribe(
|
|
||||||
() => {
|
|
||||||
console.log('Status updated successfully.');
|
|
||||||
ldnService.enabled = newStatus;
|
|
||||||
this.cdRef.detectChanges();
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
console.error('Error updating status:', error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchServiceData(serviceId: string): void {
|
|
||||||
const apiUrl = `http://localhost:8080/server/api/ldn/ldnservices/${serviceId}`;
|
|
||||||
|
|
||||||
this.http.get(apiUrl).subscribe(
|
|
||||||
(data: any) => {
|
|
||||||
console.log(data);
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
console.error('Error fetching service data:', error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
|
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
@@ -1,26 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* A cosntrain that can be used when running a service
|
|
||||||
*/
|
|
||||||
export class LdnServiceConstraint {
|
|
||||||
/**
|
|
||||||
* The name of the constrain
|
|
||||||
*/
|
|
||||||
name: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The value of the constrain
|
|
||||||
*/
|
|
||||||
value: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const EndorsmentConstrain = [
|
|
||||||
{
|
|
||||||
name: 'Type 1 Item',
|
|
||||||
value: 'Type1'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Type 2 Item',
|
|
||||||
value: 'Type2'
|
|
||||||
},
|
|
||||||
];
|
|
@@ -0,0 +1,13 @@
|
|||||||
|
import { autoserialize } from 'cerialize';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* notify service patterns
|
||||||
|
*/
|
||||||
|
export class NotifyServicePattern {
|
||||||
|
@autoserialize
|
||||||
|
pattern: string;
|
||||||
|
@autoserialize
|
||||||
|
constraint: string;
|
||||||
|
@autoserialize
|
||||||
|
automatic: string;
|
||||||
|
}
|
@@ -0,0 +1,3 @@
|
|||||||
|
export class ldnServiceConstrain {
|
||||||
|
void: any;
|
||||||
|
}
|
@@ -7,3 +7,4 @@
|
|||||||
import { ResourceType } from '../../../core/shared/resource-type';
|
import { ResourceType } from '../../../core/shared/resource-type';
|
||||||
|
|
||||||
export const LDN_SERVICE = new ResourceType('ldnservice');
|
export const LDN_SERVICE = new ResourceType('ldnservice');
|
||||||
|
export const LDN_SERVICE_CONSTRAINT = new ResourceType('ldnservice');
|
||||||
|
@@ -1,12 +1,16 @@
|
|||||||
import { ResourceType } from '../../../core/shared/resource-type';
|
import { ResourceType } from '../../../core/shared/resource-type';
|
||||||
import { CacheableObject } from '../../../core/cache/cacheable-object.model';
|
import { CacheableObject } from '../../../core/cache/cacheable-object.model';
|
||||||
import { autoserialize, deserialize } from 'cerialize';
|
import { autoserialize, deserialize, deserializeAs, inheritSerialization } from 'cerialize';
|
||||||
import { LDN_SERVICE } from './ldn-service.resource-type';
|
import { LDN_SERVICE } from './ldn-service.resource-type';
|
||||||
import { excludeFromEquals } from '../../../core/utilities/equals.decorators';
|
import { excludeFromEquals } from '../../../core/utilities/equals.decorators';
|
||||||
import { typedObject } from '../../../core/cache/builders/build-decorators';
|
import { typedObject } from '../../../core/cache/builders/build-decorators';
|
||||||
|
import { NotifyServicePattern } from './ldn-service-patterns.model';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@typedObject
|
@typedObject
|
||||||
|
@inheritSerialization(CacheableObject)
|
||||||
export class LdnService extends CacheableObject {
|
export class LdnService extends CacheableObject {
|
||||||
static type = LDN_SERVICE;
|
static type = LDN_SERVICE;
|
||||||
|
|
||||||
@@ -15,7 +19,10 @@ export class LdnService extends CacheableObject {
|
|||||||
type: ResourceType;
|
type: ResourceType;
|
||||||
|
|
||||||
@autoserialize
|
@autoserialize
|
||||||
id?: number;
|
id: number;
|
||||||
|
|
||||||
|
@deserializeAs('id')
|
||||||
|
uuid: string;
|
||||||
|
|
||||||
@autoserialize
|
@autoserialize
|
||||||
name: string;
|
name: string;
|
||||||
@@ -49,13 +56,3 @@ export class LdnService extends CacheableObject {
|
|||||||
return this._links.self.href;
|
return this._links.self.href;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class NotifyServicePattern {
|
|
||||||
@autoserialize
|
|
||||||
pattern: string;
|
|
||||||
@autoserialize
|
|
||||||
constraint?: string;
|
|
||||||
@autoserialize
|
|
||||||
automatic?: boolean;
|
|
||||||
}
|
|
||||||
|
@@ -4,6 +4,8 @@ import { getAdminModuleRoute } from '../app-routing-paths';
|
|||||||
export const REGISTRIES_MODULE_PATH = 'registries';
|
export const REGISTRIES_MODULE_PATH = 'registries';
|
||||||
export const NOTIFICATIONS_MODULE_PATH = 'notifications';
|
export const NOTIFICATIONS_MODULE_PATH = 'notifications';
|
||||||
|
|
||||||
|
export const LDN_PATH = 'ldn';
|
||||||
|
|
||||||
export function getRegistriesModuleRoute() {
|
export function getRegistriesModuleRoute() {
|
||||||
return new URLCombiner(getAdminModuleRoute(), REGISTRIES_MODULE_PATH).toString();
|
return new URLCombiner(getAdminModuleRoute(), REGISTRIES_MODULE_PATH).toString();
|
||||||
}
|
}
|
||||||
@@ -12,4 +14,8 @@ export function getNotificationsModuleRoute() {
|
|||||||
return new URLCombiner(getAdminModuleRoute(), NOTIFICATIONS_MODULE_PATH).toString();
|
return new URLCombiner(getAdminModuleRoute(), NOTIFICATIONS_MODULE_PATH).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
export const LDN_PATH = 'ldn';
|
export function getLdnServicesModuleRoute() {
|
||||||
|
return new URLCombiner(getAdminModuleRoute(), LDN_PATH).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user