[CST-5270] Implemented new refresh button & code refactoring

This commit is contained in:
Rezart Vata
2022-04-26 17:52:28 +02:00
parent d390920cca
commit cb84bc758e
10 changed files with 66 additions and 14 deletions

View File

@@ -1,14 +1,18 @@
import { JsonPatchOperationPathCombiner } from './../../../core/json-patch/builder/json-patch-operation-path-combiner';
import { JsonPatchOperationsBuilder } from './../../../core/json-patch/builder/json-patch-operations-builder';
import { WorkspaceitemSectionSherpaPoliciesObject } from './../../../core/submission/models/workspaceitem-section-sherpa-policies.model';
import { SectionSherpaPoliciesService } from './section-sherpa-policies.service';
import { Component, Inject, ViewChildren, QueryList } from '@angular/core';
import { Observable, of } from 'rxjs';
import { Observable, of, Subscription } from 'rxjs';
import { renderSectionFor } from '../sections-decorator';
import { SectionsType } from '../sections-type';
import { SectionDataObject } from '../models/section-data.model';
import { SectionsService } from '../sections.service';
import { SectionModelComponent } from '../models/section.model';
import { SubmissionService } from '../../submission.service';
import { hasValue } from '../../../shared/empty.util';
/**
* This component represents a section for managing item's access conditions.
@@ -29,6 +33,17 @@ export class SubmissionSectionSherpaPoliciesComponent extends SectionModelCompon
*/
public sherpaPoliciesData: WorkspaceitemSectionSherpaPoliciesObject;
/**
* The [[JsonPatchOperationPathCombiner]] object
* @type {JsonPatchOperationPathCombiner}
*/
protected pathCombiner: JsonPatchOperationPathCombiner;
/**
* Array to track all subscriptions and unsubscribe them onDestroy
* @type {Array}
*/
protected subs: Subscription[] = [];
/**
* Initialize instance variables
@@ -36,11 +51,15 @@ export class SubmissionSectionSherpaPoliciesComponent extends SectionModelCompon
* @param {SectionsService} sectionService
* @param {SectionDataObject} injectedSectionData
* @param {SectionSherpaPoliciesService} sectionSherpaPoliciesService
* @param {JsonPatchOperationsBuilder} operationsBuilder
* @param {SubmissionService} submissionService
* @param {string} injectedSubmissionId
*/
constructor(
protected sectionService: SectionsService,
private sectionSherpaPoliciesService: SectionSherpaPoliciesService,
protected operationsBuilder: JsonPatchOperationsBuilder,
private submissionService: SubmissionService,
@Inject('sectionDataProvider') public injectedSectionData: SectionDataObject,
@Inject('submissionIdProvider') public injectedSubmissionId: string) {
super(undefined, injectedSectionData, injectedSubmissionId);
@@ -49,11 +68,15 @@ export class SubmissionSectionSherpaPoliciesComponent extends SectionModelCompon
/**
* Unsubscribe from all subscriptions
*/
// tslint:disable-next-line:no-empty
onSectionDestroy() {
this.subs
.filter((subscription) => hasValue(subscription))
.forEach((subscription) => subscription.unsubscribe());
}
/**
* Expand all primary accordions
*/
ngAfterViewInit() {
this.acc.forEach(accordion => {
accordion.expandAll();
@@ -65,9 +88,12 @@ export class SubmissionSectionSherpaPoliciesComponent extends SectionModelCompon
* Initialize all instance variables and retrieve collection default access conditions
*/
protected onSectionInit(): void {
this.sectionSherpaPoliciesService.getSherpaPoliciesData(this.submissionId, this.sectionData.id).subscribe((sherpaPolicies: WorkspaceitemSectionSherpaPoliciesObject) => {
this.sherpaPoliciesData = sherpaPolicies;
});
this.pathCombiner = new JsonPatchOperationPathCombiner('sections', this.sectionData.id);
this.subs.push(
this.sectionSherpaPoliciesService.getSherpaPoliciesData(this.submissionId, this.sectionData.id).subscribe((sherpaPolicies: WorkspaceitemSectionSherpaPoliciesObject) => {
this.sherpaPoliciesData = sherpaPolicies;
})
);
}
/**
@@ -80,4 +106,12 @@ export class SubmissionSectionSherpaPoliciesComponent extends SectionModelCompon
return of(true);
}
/**
* Refresh sherpa information
*/
refresh() {
this.operationsBuilder.remove(this.pathCombiner.getPath('retrievalTime'));
this.submissionService.dispatchSaveSection(this.submissionId, this.sectionData.id);
}
}