diff --git a/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts b/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts index 43755adb3c..09670cc064 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-data/ldn-services-data.service.ts @@ -24,25 +24,45 @@ import { hasValue } from '../../../shared/empty.util'; 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 { ChangeAnalyzer } from '../../../core/data/change-analyzer'; +import { Operation } from 'fast-json-patch'; +import { RestRequestMethod } from 'src/app/core/data/rest-request-method'; -@Injectable() -@dataService(LDN_SERVICE) -export class LdnServicesService extends IdentifiableDataService implements FindAllData, DeleteData { - private findAllData: FindAllDataImpl; // Corrected the type - private deleteData: DeleteDataImpl; // Corrected the type + @Injectable() + @dataService(LDN_SERVICE) + export class LdnServicesService extends IdentifiableDataService implements FindAllData, DeleteData, PatchData { + private findAllData: FindAllDataImpl; + private deleteData: DeleteDataImpl; + private patchData: PatchDataImpl; + private comparator: ChangeAnalyzer; - constructor( - protected requestService: RequestService, - protected rdbService: RemoteDataBuildService, - protected objectCache: ObjectCacheService, - protected halService: HALEndpointService, - protected notificationsService: NotificationsService, - ) { - super('ldnservices', requestService, rdbService, objectCache, halService); + constructor( + protected requestService: RequestService, + protected rdbService: RemoteDataBuildService, + protected objectCache: ObjectCacheService, + protected halService: HALEndpointService, + protected notificationsService: NotificationsService, + ) { + super('ldnservices', requestService, rdbService, objectCache, halService); - 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.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.patchData = new PatchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.comparator, this.responseMsToLive, this.constructIdEndpoint); + } + + patch(object: LdnService, operations: Operation[]): Observable> { + throw new Error('Method not implemented.'); + } + update(object: LdnService): Observable> { + throw new Error('Method not implemented.'); + } + commitUpdates(method?: RestRequestMethod): void { + throw new Error('Method not implemented.'); + } + createPatchFromCache(object: LdnService): Observable { + throw new Error('Method not implemented.'); + } findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig[]): Observable>> { return this.findAllData.findAll(options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); diff --git a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html index e3795d6e96..4c9b3c3f04 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html +++ b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.html @@ -23,7 +23,7 @@ - + {{ ldnService.name }} {{ ldnService.description }} diff --git a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts index 9d19ad56c7..345f5182aa 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-directory/ldn-services-directory.component.ts @@ -12,6 +12,7 @@ import { PaginationService } from 'src/app/core/pagination/pagination.service'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { hasValue } from '../../../shared/empty.util'; import { HttpClient } from '@angular/common/http'; +import { getFirstCompletedRemoteData } from "../../../core/shared/operators"; @Component({ selector: 'ds-ldn-services-directory', templateUrl: './ldn-services-directory.component.html', @@ -33,8 +34,12 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy { isProcessingSub: Subscription; private modalRef: any; + + + constructor( protected processLdnService: LdnServicesService, + private ldnServicesService: LdnServicesService, protected paginationService: PaginationService, protected modalService: NgbModal, public ldnDirectoryService: LdnDirectoryService, @@ -44,9 +49,9 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy { } ngOnInit(): void { - /*this.ldnDirectoryService.listLdnServices();*/ - this.findAllServices(); + this.setLdnServices2(); this.setLdnServices(); + /*this.ldnDirectoryService.listLdnServices();*/ /*this.ldnServicesRD$.subscribe(data => { console.log('searchByLdnUrl()', data); });*/ @@ -62,10 +67,22 @@ export class LdnServicesOverviewComponent implements OnInit, OnDestroy { } setLdnServices() { + this.ldnServicesService.findAll().pipe(getFirstCompletedRemoteData()).subscribe((remoteData) => { + + if (remoteData.hasSucceeded) { + const ldnservices = remoteData.payload.page; + console.log(ldnservices); + } else { + console.error('Error fetching LDN services:', remoteData.errorMessage); + } + }); + } + + setLdnServices2() { this.ldnServicesRD$ = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe( - switchMap((config) => this.processLdnService.findAll(config, true, false)) + switchMap((config) => this.ldnServicesService.findAll(config, true, false)) + ); - console.log(); } ngOnDestroy(): void { diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts index 937fac255d..e5684e8c34 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-service.resource-type.ts @@ -6,4 +6,4 @@ */ import { ResourceType } from '../../../core/shared/resource-type'; -export const LDN_SERVICE = new ResourceType('ldnservices'); +export const LDN_SERVICE = new ResourceType('ldnservice'); diff --git a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts index bdb8bc5123..ec28193a93 100644 --- a/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts +++ b/src/app/admin/admin-ldn-services/ldn-services-model/ldn-services.model.ts @@ -26,6 +26,9 @@ export class LdnService extends CacheableObject { @autoserialize url: string; + @autoserialize + enabled: boolean; + @autoserialize ldnUrl: string; diff --git a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-service-bulk-delete.service.ts b/src/app/admin/admin-ldn-services/ldn-services-services/ldn-service-bulk-delete.service.ts deleted file mode 100644 index 6805cd7f93..0000000000 --- a/src/app/admin/admin-ldn-services/ldn-services-services/ldn-service-bulk-delete.service.ts +++ /dev/null @@ -1,117 +0,0 @@ -import { Injectable } from '@angular/core'; -import { BehaviorSubject, count, from } from 'rxjs'; -import { LdnServicesService } from '../ldn-services-data/ldn-services-data.service'; -import { NotificationsService } from '../../../shared/notifications/notifications.service'; -import { TranslateService } from '@ngx-translate/core'; -import { isNotEmpty } from '../../../shared/empty.util'; -import { concatMap, filter, tap } from 'rxjs/operators'; -import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; -import { RemoteData } from '../../../core/data/remote-data'; -import { LdnService } from '../ldn-services-model/ldn-services.model'; -@Injectable({ - providedIn: 'root' -}) -/** - * Service to facilitate removing ldn services in bulk. - */ -export class LdnServicesBulkDeleteService { - - /** - * Array to track the services to be deleted - */ - ldnServicesToDelete: string[] = []; - - /** - * Behavior subject to track whether the delete is processing - * @protected - */ - protected isProcessingBehaviorSubject: BehaviorSubject = new BehaviorSubject(false); - - constructor( - protected processLdnService: LdnServicesService, - protected notificationsService: NotificationsService, - protected translateService: TranslateService - ) { - } - - /** - * Add or remove a process id to/from the list - * If the id is already present it will be removed, otherwise it will be added. - * - * @param notifyServiceName - The process id to add or remove - */ - toggleDelete(notifyServiceName: string) { - if (this.isToBeDeleted(notifyServiceName)) { - this.ldnServicesToDelete.splice(this.ldnServicesToDelete.indexOf(notifyServiceName), 1); - } else { - this.ldnServicesToDelete.push(notifyServiceName); - } - } - - /** - * Checks if the provided service id is present in the to be deleted list - * @param notifyServiceName - */ - isToBeDeleted(notifyServiceName: string) { - return this.ldnServicesToDelete.includes(notifyServiceName); - } - - /** - * Clear the list of services to be deleted - */ - clearAllServices() { - this.ldnServicesToDelete.splice(0); - } - - /** - * Get the amount of processes selected for deletion - */ - getAmountOfSelectedServices() { - return this.ldnServicesToDelete.length; - } - - /** - * Returns a behavior subject to indicate whether the bulk delete is processing - */ - isProcessing$() { - return this.isProcessingBehaviorSubject; - } - - /** - * Returns whether there currently are values selected for deletion - */ - hasSelected(): boolean { - return isNotEmpty(this.ldnServicesToDelete); - } - - /** - * Delete all selected processes one by one - * When the deletion for a process fails, an error notification will be shown with the process id, - * but it will continue deleting the other processes. - * At the end it will show a notification stating the amount of successful deletes - * The successfully deleted processes will be removed from the list of selected values, the failed ones will be retained. - */ - deleteSelectedLdnServices() { - this.isProcessingBehaviorSubject.next(true); - - from([...this.ldnServicesToDelete]).pipe( - concatMap((notifyServiceName) => { - return this.processLdnService.delete(notifyServiceName).pipe( - getFirstCompletedRemoteData(), - tap((rd: RemoteData) => { - if (rd.hasFailed) { - this.notificationsService.error(this.translateService.get('process.bulk.delete.error.head'), this.translateService.get('process.bulk.delete.error.body', {processId: notifyServiceName})); - } else { - this.toggleDelete(notifyServiceName); - } - }) - ); - }), - filter((rd: RemoteData) => rd.hasSucceeded), - count(), - ).subscribe((value) => { - this.notificationsService.success(this.translateService.get('process.bulk.delete.success', {count: value})); - this.isProcessingBehaviorSubject.next(false); - }); - } -} diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index e1b1fc8811..1990bde77e 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -188,6 +188,7 @@ import { BulkAccessConditionOptions } from './config/models/bulk-access-conditio import { SuggestionTarget } from './suggestion-notifications/reciter-suggestions/models/suggestion-target.model'; import { SuggestionSource } from './suggestion-notifications/reciter-suggestions/models/suggestion-source.model'; import { LdnServicesService } from '../admin/admin-ldn-services/ldn-services-data/ldn-services-data.service'; +import { LdnService } from '../admin/admin-ldn-services/ldn-services-model/ldn-services.model'; /** * When not in production, endpoint responses can be mocked for testing purposes @@ -392,7 +393,9 @@ export const models = ItemRequest, BulkAccessConditionOptions, SuggestionTarget, - SuggestionSource + SuggestionSource, + LdnService + ]; @NgModule({