CST-12174 Ldn services are now retrieved with the remotadata object

This commit is contained in:
Mattia Vianelli
2023-10-11 15:35:28 +02:00
parent 9216073b5b
commit 8de0e76b72
7 changed files with 66 additions and 140 deletions

View File

@@ -24,12 +24,18 @@ 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<LdnService> implements FindAllData<LdnService>, DeleteData<LdnService> {
private findAllData: FindAllDataImpl<LdnService>; // Corrected the type
private deleteData: DeleteDataImpl<LdnService>; // Corrected the type
@Injectable()
@dataService(LDN_SERVICE)
export class LdnServicesService extends IdentifiableDataService<LdnService> implements FindAllData<LdnService>, DeleteData<LdnService>, PatchData<LdnService> {
private findAllData: FindAllDataImpl<LdnService>;
private deleteData: DeleteDataImpl<LdnService>;
private patchData: PatchDataImpl<LdnService>;
private comparator: ChangeAnalyzer<LdnService>;
constructor(
protected requestService: RequestService,
@@ -42,6 +48,20 @@ export class LdnServicesService extends IdentifiableDataService<LdnService> impl
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<RemoteData<LdnService>> {
throw new Error('Method not implemented.');
}
update(object: LdnService): Observable<RemoteData<LdnService>> {
throw new Error('Method not implemented.');
}
commitUpdates(method?: RestRequestMethod): void {
throw new Error('Method not implemented.');
}
createPatchFromCache(object: LdnService): Observable<Operation[]> {
throw new Error('Method not implemented.');
}
findAll(options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<LdnService>[]): Observable<RemoteData<PaginatedList<LdnService>>> {

View File

@@ -23,7 +23,7 @@
</tr>
</thead>
<tbody>
<tr *ngFor="let ldnService of servicesData">
<tr *ngFor="let ldnService of (ldnServicesRD$| async)?.payload?.page">
<td>{{ ldnService.name }}</td>
<td>{{ ldnService.description }}</td>
<td>

View File

@@ -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 {

View File

@@ -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');

View File

@@ -26,6 +26,9 @@ export class LdnService extends CacheableObject {
@autoserialize
url: string;
@autoserialize
enabled: boolean;
@autoserialize
ldnUrl: string;

View File

@@ -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<boolean> = new BehaviorSubject<boolean>(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<LdnService>) => {
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<LdnService>) => rd.hasSucceeded),
count(),
).subscribe((value) => {
this.notificationsService.success(this.translateService.get('process.bulk.delete.success', {count: value}));
this.isProcessingBehaviorSubject.next(false);
});
}
}

View File

@@ -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({