mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
70834: Metadata schema component refactoring and caching issue fix #2
This commit is contained in:
@@ -4,7 +4,7 @@ import { Observable, combineLatest as observableCombineLatest } from 'rxjs';
|
|||||||
import { RemoteData } from '../../../core/data/remote-data';
|
import { RemoteData } from '../../../core/data/remote-data';
|
||||||
import { PaginatedList } from '../../../core/data/paginated-list';
|
import { PaginatedList } from '../../../core/data/paginated-list';
|
||||||
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
|
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
|
||||||
import { map, take } from 'rxjs/operators';
|
import { filter, map, switchMap, take } from 'rxjs/operators';
|
||||||
import { hasValue } from '../../../shared/empty.util';
|
import { hasValue } from '../../../shared/empty.util';
|
||||||
import { RestResponse } from '../../../core/cache/response.models';
|
import { RestResponse } from '../../../core/cache/response.models';
|
||||||
import { zip } from 'rxjs/internal/observable/zip';
|
import { zip } from 'rxjs/internal/observable/zip';
|
||||||
@@ -13,6 +13,7 @@ import { Route, Router } from '@angular/router';
|
|||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { MetadataSchema } from '../../../core/metadata/metadata-schema.model';
|
import { MetadataSchema } from '../../../core/metadata/metadata-schema.model';
|
||||||
import { toFindListOptions } from '../../../shared/pagination/pagination.utils';
|
import { toFindListOptions } from '../../../shared/pagination/pagination.utils';
|
||||||
|
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-metadata-registry',
|
selector: 'ds-metadata-registry',
|
||||||
@@ -38,6 +39,11 @@ export class MetadataRegistryComponent {
|
|||||||
pageSize: 25
|
pageSize: 25
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the list of MetadataSchemas needs an update
|
||||||
|
*/
|
||||||
|
needsUpdate$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(true);
|
||||||
|
|
||||||
constructor(private registryService: RegistryService,
|
constructor(private registryService: RegistryService,
|
||||||
private notificationsService: NotificationsService,
|
private notificationsService: NotificationsService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
@@ -51,14 +57,17 @@ export class MetadataRegistryComponent {
|
|||||||
*/
|
*/
|
||||||
onPageChange(event) {
|
onPageChange(event) {
|
||||||
this.config.currentPage = event;
|
this.config.currentPage = event;
|
||||||
this.updateSchemas();
|
this.forceUpdateSchemas();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the list of schemas by fetching it from the rest api or cache
|
* Update the list of schemas by fetching it from the rest api or cache
|
||||||
*/
|
*/
|
||||||
private updateSchemas() {
|
private updateSchemas() {
|
||||||
this.metadataSchemas = this.registryService.getMetadataSchemas(toFindListOptions(this.config));
|
this.metadataSchemas = this.needsUpdate$.pipe(
|
||||||
|
filter((update) => update === true),
|
||||||
|
switchMap(() => this.registryService.getMetadataSchemas(toFindListOptions(this.config)))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -66,8 +75,7 @@ export class MetadataRegistryComponent {
|
|||||||
* a new REST call
|
* a new REST call
|
||||||
*/
|
*/
|
||||||
public forceUpdateSchemas() {
|
public forceUpdateSchemas() {
|
||||||
this.registryService.clearMetadataSchemaRequests().subscribe();
|
this.needsUpdate$.next(true);
|
||||||
this.updateSchemas();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,6 +134,7 @@ export class MetadataRegistryComponent {
|
|||||||
* Delete all the selected metadata schemas
|
* Delete all the selected metadata schemas
|
||||||
*/
|
*/
|
||||||
deleteSchemas() {
|
deleteSchemas() {
|
||||||
|
this.registryService.clearMetadataSchemaRequests().subscribe();
|
||||||
this.registryService.getSelectedMetadataSchemas().pipe(take(1)).subscribe(
|
this.registryService.getSelectedMetadataSchemas().pipe(take(1)).subscribe(
|
||||||
(schemas) => {
|
(schemas) => {
|
||||||
const tasks$ = [];
|
const tasks$ = [];
|
||||||
|
@@ -128,6 +128,7 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
|
|||||||
* Emit the updated/created schema using the EventEmitter submitForm
|
* Emit the updated/created schema using the EventEmitter submitForm
|
||||||
*/
|
*/
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
|
this.registryService.clearMetadataSchemaRequests().subscribe();
|
||||||
this.registryService.getActiveMetadataSchema().pipe(take(1)).subscribe(
|
this.registryService.getActiveMetadataSchema().pipe(take(1)).subscribe(
|
||||||
(schema) => {
|
(schema) => {
|
||||||
const values = {
|
const values = {
|
||||||
@@ -148,6 +149,7 @@ export class MetadataSchemaFormComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.clearFields();
|
this.clearFields();
|
||||||
|
this.registryService.cancelEditMetadataSchema();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -153,6 +153,7 @@ export class MetadataFieldFormComponent implements OnInit, OnDestroy {
|
|||||||
* Emit the updated/created field using the EventEmitter submitForm
|
* Emit the updated/created field using the EventEmitter submitForm
|
||||||
*/
|
*/
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
|
this.registryService.clearMetadataFieldRequests().subscribe();
|
||||||
this.registryService.getActiveMetadataField().pipe(take(1)).subscribe(
|
this.registryService.getActiveMetadataField().pipe(take(1)).subscribe(
|
||||||
(field) => {
|
(field) => {
|
||||||
const values = {
|
const values = {
|
||||||
|
@@ -50,7 +50,7 @@ export class MetadataSchemaComponent implements OnInit {
|
|||||||
/**
|
/**
|
||||||
* Whether or not the list of MetadataFields needs an update
|
* Whether or not the list of MetadataFields needs an update
|
||||||
*/
|
*/
|
||||||
needsUpdate: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(true);
|
needsUpdate$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(true);
|
||||||
|
|
||||||
constructor(private registryService: RegistryService,
|
constructor(private registryService: RegistryService,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
@@ -81,17 +81,16 @@ export class MetadataSchemaComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
onPageChange(event) {
|
onPageChange(event) {
|
||||||
this.config.currentPage = event;
|
this.config.currentPage = event;
|
||||||
this.needsUpdate.next(true);
|
this.forceUpdateFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the list of fields by fetching it from the rest api or cache
|
* Update the list of fields by fetching it from the rest api or cache
|
||||||
*/
|
*/
|
||||||
private updateFields() {
|
private updateFields() {
|
||||||
this.metadataFields$ = combineLatest(this.metadataSchema$, this.needsUpdate).pipe(
|
this.metadataFields$ = combineLatest(this.metadataSchema$, this.needsUpdate$).pipe(
|
||||||
switchMap(([schema, update]: [MetadataSchema, boolean]) => {
|
switchMap(([schema, update]: [MetadataSchema, boolean]) => {
|
||||||
if (update) {
|
if (update) {
|
||||||
console.log('reloaded list');
|
|
||||||
return this.registryService.getMetadataFieldsBySchema(schema, toFindListOptions(this.config));
|
return this.registryService.getMetadataFieldsBySchema(schema, toFindListOptions(this.config));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -103,7 +102,7 @@ export class MetadataSchemaComponent implements OnInit {
|
|||||||
* a new REST call
|
* a new REST call
|
||||||
*/
|
*/
|
||||||
public forceUpdateFields() {
|
public forceUpdateFields() {
|
||||||
this.registryService.clearMetadataFieldRequests().subscribe(() => this.needsUpdate.next(true));
|
this.needsUpdate$.next(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,6 +161,7 @@ export class MetadataSchemaComponent implements OnInit {
|
|||||||
* Delete all the selected metadata fields
|
* Delete all the selected metadata fields
|
||||||
*/
|
*/
|
||||||
deleteFields() {
|
deleteFields() {
|
||||||
|
this.registryService.clearMetadataFieldRequests().subscribe();
|
||||||
this.registryService.getSelectedMetadataFields().pipe(take(1)).subscribe(
|
this.registryService.getSelectedMetadataFields().pipe(take(1)).subscribe(
|
||||||
(fields) => {
|
(fields) => {
|
||||||
const tasks$ = [];
|
const tasks$ = [];
|
||||||
|
@@ -42,6 +42,14 @@ export class MetadataSchemaDataService extends DataService<MetadataSchema> {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create or Update a MetadataSchema
|
||||||
|
* If the MetadataSchema contains an id, it is assumed the schema already exists and is updated instead
|
||||||
|
* Since creating or updating is nearly identical, the only real difference is the request (and slight difference in endpoint):
|
||||||
|
* - On creation, a CreateMetadataSchemaRequest is used
|
||||||
|
* - On update, a UpdateMetadataSchemaRequest is used
|
||||||
|
* @param schema The MetadataSchema to create or update
|
||||||
|
*/
|
||||||
createOrUpdateMetadataSchema(schema: MetadataSchema): Observable<RestResponse> {
|
createOrUpdateMetadataSchema(schema: MetadataSchema): Observable<RestResponse> {
|
||||||
const isUpdate = hasValue(schema.id);
|
const isUpdate = hasValue(schema.id);
|
||||||
const requestId = this.requestService.generateRequestId();
|
const requestId = this.requestService.generateRequestId();
|
||||||
@@ -89,6 +97,10 @@ export class MetadataSchemaDataService extends DataService<MetadataSchema> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear all metadata schema requests
|
||||||
|
* Used for refreshing lists after adding/updating/removing a metadata schema in the registry
|
||||||
|
*/
|
||||||
clearRequests(): Observable<string> {
|
clearRequests(): Observable<string> {
|
||||||
return this.getBrowseEndpoint().pipe(
|
return this.getBrowseEndpoint().pipe(
|
||||||
tap((href: string) => this.requestService.removeByHrefSubstring(href))
|
tap((href: string) => this.requestService.removeByHrefSubstring(href))
|
||||||
|
Reference in New Issue
Block a user