mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-10 03:23:07 +00:00
Added more comments
This commit is contained in:
@@ -15,22 +15,68 @@ import { HALEndpointService } from '../../core/shared/hal-endpoint.service';
|
||||
import { Collection } from '../../core/shared/collection.model';
|
||||
import { SubmissionObject } from '../../core/submission/models/submission-object.model';
|
||||
|
||||
/**
|
||||
* This component represents the submission form.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'ds-submission-submit-form',
|
||||
styleUrls: ['./submission-form.component.scss'],
|
||||
templateUrl: './submission-form.component.html',
|
||||
})
|
||||
export class SubmissionFormComponent implements OnChanges, OnDestroy {
|
||||
|
||||
/**
|
||||
* The collection id this submission belonging to
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() collectionId: string;
|
||||
|
||||
/**
|
||||
* The list of submission's sections
|
||||
* @type {WorkspaceitemSectionsObject}
|
||||
*/
|
||||
@Input() sections: WorkspaceitemSectionsObject;
|
||||
|
||||
/**
|
||||
* The submission self url
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() selfUrl: string;
|
||||
|
||||
/**
|
||||
* The configuration object that define this submission
|
||||
* @type {SubmissionDefinitionsModel}
|
||||
*/
|
||||
@Input() submissionDefinition: SubmissionDefinitionsModel;
|
||||
|
||||
/**
|
||||
* The submission id
|
||||
* @type {string}
|
||||
*/
|
||||
@Input() submissionId: string;
|
||||
|
||||
/**
|
||||
* The configuration id that define this submission
|
||||
* @type {string}
|
||||
*/
|
||||
public definitionId: string;
|
||||
public test = true;
|
||||
|
||||
/**
|
||||
* A boolean representing if a submission form is pending
|
||||
* @type {Observable<boolean>}
|
||||
*/
|
||||
public loading: Observable<boolean> = observableOf(true);
|
||||
public submissionSections: Observable<any>;
|
||||
|
||||
/**
|
||||
* Observable of the list of submission's sections
|
||||
* @type {Observable<WorkspaceitemSectionsObject>}
|
||||
*/
|
||||
public submissionSections: Observable<WorkspaceitemSectionsObject>;
|
||||
|
||||
/**
|
||||
* The uploader configuration options
|
||||
* @type {UploaderOptions}
|
||||
*/
|
||||
public uploadFilesOptions: UploaderOptions = {
|
||||
url: '',
|
||||
authToken: null,
|
||||
@@ -38,9 +84,26 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy {
|
||||
itemAlias: null
|
||||
};
|
||||
|
||||
/**
|
||||
* A boolean representing if component is active
|
||||
* @type {boolean}
|
||||
*/
|
||||
protected isActive: boolean;
|
||||
|
||||
/**
|
||||
* Array to track all subscriptions and unsubscribe them onDestroy
|
||||
* @type {Array}
|
||||
*/
|
||||
protected subs: Subscription[] = [];
|
||||
|
||||
/**
|
||||
* Initialize instance variables
|
||||
*
|
||||
* @param {AuthService} authService
|
||||
* @param {ChangeDetectorRef} changeDetectorRef
|
||||
* @param {HALEndpointService} halService
|
||||
* @param {SubmissionService} submissionService
|
||||
*/
|
||||
constructor(
|
||||
private authService: AuthService,
|
||||
private changeDetectorRef: ChangeDetectorRef,
|
||||
@@ -49,9 +112,14 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy {
|
||||
this.isActive = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all instance variables and retrieve form configuration
|
||||
*/
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (this.collectionId && this.submissionId) {
|
||||
this.isActive = true;
|
||||
|
||||
// retrieve submission's section list
|
||||
this.submissionSections = this.submissionService.getSubmissionObject(this.submissionId).pipe(
|
||||
filter(() => this.isActive),
|
||||
map((submission: SubmissionObjectEntry) => submission.isLoading),
|
||||
@@ -65,12 +133,14 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy {
|
||||
}
|
||||
}));
|
||||
|
||||
// check if is submission loading
|
||||
this.loading = this.submissionService.getSubmissionObject(this.submissionId).pipe(
|
||||
filter(() => this.isActive),
|
||||
map((submission: SubmissionObjectEntry) => submission.isLoading),
|
||||
map((isLoading: boolean) => isLoading),
|
||||
distinctUntilChanged());
|
||||
|
||||
// init submission state
|
||||
this.subs.push(
|
||||
this.halService.getEndpoint('workspaceitems').pipe(
|
||||
filter((href: string) => isNotEmpty(href)),
|
||||
@@ -89,10 +159,16 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy {
|
||||
this.changeDetectorRef.detectChanges();
|
||||
})
|
||||
);
|
||||
|
||||
// start auto save
|
||||
this.submissionService.startAutoSave(this.submissionId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe from all subscriptions, destroy instance variables
|
||||
* and reset submission state
|
||||
*/
|
||||
ngOnDestroy() {
|
||||
this.isActive = false;
|
||||
this.submissionService.stopAutoSave();
|
||||
@@ -102,6 +178,13 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy {
|
||||
.forEach((subscription) => subscription.unsubscribe());
|
||||
}
|
||||
|
||||
/**
|
||||
* On collection change reset submission state in case of it has a different
|
||||
* submission definition
|
||||
*
|
||||
* @param submissionObject
|
||||
* new submission object
|
||||
*/
|
||||
onCollectionChange(submissionObject: SubmissionObject) {
|
||||
this.collectionId = (submissionObject.collection as Collection).id;
|
||||
if (this.definitionId !== (submissionObject.submissionDefinition as SubmissionDefinitionsModel).name) {
|
||||
@@ -119,10 +202,16 @@ export class SubmissionFormComponent implements OnChanges, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if submission form is loading
|
||||
*/
|
||||
isLoading(): Observable<boolean> {
|
||||
return this.loading;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if submission form is loading
|
||||
*/
|
||||
protected getSectionsList(): Observable<any> {
|
||||
return this.submissionService.getSubmissionSections(this.submissionId).pipe(
|
||||
filter((sections: SectionDataObject[]) => isNotEmpty(sections)),
|
||||
|
Reference in New Issue
Block a user