Skip to content

Commit ff85422

Browse files
[DURACOM-155] Edit item / collection / community in sidebar menu
1 parent 48ea7df commit ff85422

7 files changed

Lines changed: 79 additions & 47 deletions

File tree

src/app/collection-page/collection-form/collection-form.component.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, OnInit } from '@angular/core';
1+
import { ChangeDetectorRef, Component, Input, OnChanges, OnInit, SimpleChange, SimpleChanges } from '@angular/core';
22

33
import { Observable } from 'rxjs';
44
import { TranslateService } from '@ngx-translate/core';
@@ -31,7 +31,7 @@ import { NONE_ENTITY_TYPE } from '../../core/shared/item-relationships/item-type
3131
styleUrls: ['../../shared/comcol/comcol-forms/comcol-form/comcol-form.component.scss'],
3232
templateUrl: '../../shared/comcol/comcol-forms/comcol-form/comcol-form.component.html'
3333
})
34-
export class CollectionFormComponent extends ComColFormComponent<Collection> implements OnInit {
34+
export class CollectionFormComponent extends ComColFormComponent<Collection> implements OnInit, OnChanges {
3535
/**
3636
* @type {Collection} A new collection when a collection is being created, an existing Input collection when a collection is being edited
3737
*/
@@ -61,12 +61,23 @@ export class CollectionFormComponent extends ComColFormComponent<Collection> imp
6161
protected dsoService: CommunityDataService,
6262
protected requestService: RequestService,
6363
protected objectCache: ObjectCacheService,
64-
protected entityTypeService: EntityTypeDataService) {
64+
protected entityTypeService: EntityTypeDataService,
65+
protected chd: ChangeDetectorRef) {
6566
super(formService, translate, notificationsService, authService, requestService, objectCache);
6667
}
6768

68-
ngOnInit() {
69+
/**
70+
* Detect changes to the dso and initialize the form,
71+
* if the dso changes, exists and it is not the first change
72+
*/
73+
ngOnChanges(changes: SimpleChanges) {
74+
const dsoChange: SimpleChange = changes.dso;
75+
if (this.dso && dsoChange && !dsoChange.isFirstChange()) {
76+
this.initializeForm();
77+
}
78+
}
6979

80+
initializeForm() {
7081
let currentRelationshipValue: MetadataValue[];
7182
if (this.dso && this.dso.metadata) {
7283
currentRelationshipValue = this.dso.metadata['dspace.entity.type'];
@@ -96,6 +107,7 @@ export class CollectionFormComponent extends ComColFormComponent<Collection> imp
96107
this.formModel = [...collectionFormModels, this.entityTypeSelection];
97108

98109
super.ngOnInit();
110+
this.chd.detectChanges();
99111
});
100112

101113
}

src/app/collection-page/edit-collection-page/collection-metadata/collection-metadata.component.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnInit } from '@angular/core';
22
import { ComcolMetadataComponent } from '../../../shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component';
33
import { Collection } from '../../../core/shared/collection.model';
44
import { CollectionDataService } from '../../../core/data/collection-data.service';
5-
import { ActivatedRoute, Router } from '@angular/router';
5+
import { ActivatedRoute, NavigationEnd, Router, Scroll } from '@angular/router';
66
import { ItemTemplateDataService } from '../../../core/data/item-template-data.service';
77
import { combineLatest as combineLatestObservable, Observable } from 'rxjs';
88
import { RemoteData } from '../../../core/data/remote-data';
@@ -23,7 +23,7 @@ import { hasValue } from '../../../shared/empty.util';
2323
selector: 'ds-collection-metadata',
2424
templateUrl: './collection-metadata.component.html',
2525
})
26-
export class CollectionMetadataComponent extends ComcolMetadataComponent<Collection> {
26+
export class CollectionMetadataComponent extends ComcolMetadataComponent<Collection> implements OnInit {
2727
protected frontendURL = '/collections/';
2828
protected type = Collection.type;
2929

@@ -44,9 +44,21 @@ export class CollectionMetadataComponent extends ComcolMetadataComponent<Collect
4444
super(collectionDataService, router, route, notificationsService, translate);
4545
}
4646

47+
/**
48+
* Cheking if the navigation is done and if so, initialize the collection's item template,
49+
* to ensure that the item template is always up to date.
50+
* Check when a NavigationEnd event (URL change) or a Scroll event followed by a NavigationEnd event (refresh event), occurs
51+
*/
4752
ngOnInit(): void {
48-
super.ngOnInit();
49-
this.initTemplateItem();
53+
this.router.events.subscribe((event) => {
54+
if (
55+
event instanceof NavigationEnd ||
56+
(event instanceof Scroll && event.routerEvent instanceof NavigationEnd)
57+
) {
58+
super.ngOnInit();
59+
this.initTemplateItem();
60+
}
61+
});
5062
}
5163

5264
/**

src/app/community-page/community-form/community-form.component.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input } from '@angular/core';
1+
import { Component, Input, OnChanges, SimpleChange, SimpleChanges } from '@angular/core';
22
import {
33
DynamicFormControlModel,
44
DynamicFormService,
@@ -23,7 +23,7 @@ import { environment } from '../../../environments/environment';
2323
styleUrls: ['../../shared/comcol/comcol-forms/comcol-form/comcol-form.component.scss'],
2424
templateUrl: '../../shared/comcol/comcol-forms/comcol-form/comcol-form.component.html'
2525
})
26-
export class CommunityFormComponent extends ComColFormComponent<Community> {
26+
export class CommunityFormComponent extends ComColFormComponent<Community> implements OnChanges {
2727
/**
2828
* @type {Community} A new community when a community is being created, an existing Input community when a community is being edited
2929
*/
@@ -81,4 +81,11 @@ export class CommunityFormComponent extends ComColFormComponent<Community> {
8181
protected objectCache: ObjectCacheService) {
8282
super(formService, translate, notificationsService, authService, requestService, objectCache);
8383
}
84+
85+
ngOnChanges(changes: SimpleChanges) {
86+
const dsoChange: SimpleChange = changes.dso;
87+
if (this.dso && dsoChange && !dsoChange.isFirstChange()) {
88+
super.ngOnInit();
89+
}
90+
}
8491
}

src/app/item-page/edit-item-page/item-status/item-status.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ export class ItemStatusComponent implements OnInit {
8282
ngOnInit(): void {
8383
this.itemRD$ = this.route.parent.data.pipe(map((data) => data.dso));
8484
this.itemRD$.pipe(
85-
first(),
8685
map((data: RemoteData<Item>) => data.payload)
8786
).subscribe((item: Item) => {
8887
this.statusData = Object.assign({

src/app/shared/comcol/comcol-forms/comcol-form/comcol-form.component.ts

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -127,39 +127,41 @@ export class ComColFormComponent<T extends Collection | Community> implements On
127127
}
128128

129129
ngOnInit(): void {
130-
this.formModel.forEach(
131-
(fieldModel: DynamicInputModel) => {
132-
fieldModel.value = this.dso.firstMetadataValue(fieldModel.name);
133-
}
134-
);
135-
this.formGroup = this.formService.createFormGroup(this.formModel);
130+
if (hasValue(this.formModel)) {
131+
this.formModel.forEach(
132+
(fieldModel: DynamicInputModel) => {
133+
fieldModel.value = this.dso.firstMetadataValue(fieldModel.name);
134+
}
135+
);
136+
this.formGroup = this.formService.createFormGroup(this.formModel);
136137

137-
this.updateFieldTranslations();
138-
this.translate.onLangChange
139-
.subscribe(() => {
140-
this.updateFieldTranslations();
141-
});
138+
this.updateFieldTranslations();
139+
this.translate.onLangChange
140+
.subscribe(() => {
141+
this.updateFieldTranslations();
142+
});
142143

143-
if (hasValue(this.dso.id)) {
144-
this.subs.push(
145-
observableCombineLatest([
146-
this.dsoService.getLogoEndpoint(this.dso.id),
147-
this.dso.logo
148-
]).subscribe(([href, logoRD]: [string, RemoteData<Bitstream>]) => {
149-
this.uploadFilesOptions.url = href;
150-
this.uploadFilesOptions.authToken = this.authService.buildAuthHeader();
151-
// If the object already contains a logo, send out a PUT request instead of POST for setting a new logo
152-
if (hasValue(logoRD.payload)) {
153-
this.uploadFilesOptions.method = RestRequestMethod.PUT;
154-
}
155-
this.initializedUploaderOptions.next(true);
156-
})
157-
);
158-
} else {
159-
// Set a placeholder URL to not break the uploader component. This will be replaced once the object is created.
160-
this.uploadFilesOptions.url = 'placeholder';
161-
this.uploadFilesOptions.authToken = this.authService.buildAuthHeader();
162-
this.initializedUploaderOptions.next(true);
144+
if (hasValue(this.dso.id)) {
145+
this.subs.push(
146+
observableCombineLatest([
147+
this.dsoService.getLogoEndpoint(this.dso.id),
148+
this.dso.logo
149+
]).subscribe(([href, logoRD]: [string, RemoteData<Bitstream>]) => {
150+
this.uploadFilesOptions.url = href;
151+
this.uploadFilesOptions.authToken = this.authService.buildAuthHeader();
152+
// If the object already contains a logo, send out a PUT request instead of POST for setting a new logo
153+
if (hasValue(logoRD.payload)) {
154+
this.uploadFilesOptions.method = RestRequestMethod.PUT;
155+
}
156+
this.initializedUploaderOptions.next(true);
157+
})
158+
);
159+
} else {
160+
// Set a placeholder URL to not break the uploader component. This will be replaced once the object is created.
161+
this.uploadFilesOptions.url = 'placeholder';
162+
this.uploadFilesOptions.authToken = this.authService.buildAuthHeader();
163+
this.initializedUploaderOptions.next(true);
164+
}
163165
}
164166
}
165167

src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DSpaceObject } from '../../../../../core/shared/dspace-object.model';
33
import { Observable } from 'rxjs';
44
import { RemoteData } from '../../../../../core/data/remote-data';
55
import { ActivatedRoute, Router } from '@angular/router';
6-
import { first, map, take } from 'rxjs/operators';
6+
import { map, take } from 'rxjs/operators';
77
import { getFirstCompletedRemoteData, getFirstSucceededRemoteData } from '../../../../../core/shared/operators';
88
import { hasValue, isEmpty } from '../../../../empty.util';
99
import { ResourceType } from '../../../../../core/shared/resource-type';
@@ -42,7 +42,7 @@ export class ComcolMetadataComponent<TDomain extends Community | Collection> imp
4242
}
4343

4444
ngOnInit(): void {
45-
this.dsoRD$ = this.route.parent.data.pipe(first(), map((data) => data.dso));
45+
this.dsoRD$ = this.route.parent.data.pipe(map((data) => data.dso));
4646
}
4747

4848
/**

src/app/shared/comcol/comcol-forms/edit-comcol-page/edit-comcol-page.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, OnInit } from '@angular/core';
22

33
import { Observable } from 'rxjs';
4-
import { first, map } from 'rxjs/operators';
4+
import { map } from 'rxjs/operators';
55

66
import { ActivatedRoute, Router } from '@angular/router';
77
import { RemoteData } from '../../../../core/data/remote-data';
@@ -53,7 +53,7 @@ export class EditComColPageComponent<TDomain extends DSpaceObject> implements On
5353
this.pages = this.route.routeConfig.children
5454
.map((child: any) => child.path)
5555
.filter((path: string) => isNotEmpty(path)); // ignore reroutes
56-
this.dsoRD$ = this.route.data.pipe(first(), map((data) => data.dso));
56+
this.dsoRD$ = this.route.data.pipe(map((data) => data.dso));
5757
}
5858

5959
/**

0 commit comments

Comments
 (0)