Skip to content

Commit 1cb962b

Browse files
committed
feat: use the metadata with correct language
feat: provide a language support for community pages
1 parent d74e672 commit 1cb962b

28 files changed

Lines changed: 395 additions & 187 deletions

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
AsyncPipe,
33
NgClass,
4+
NgForOf,
45
NgIf,
56
} from '@angular/common';
67
import {
@@ -12,6 +13,7 @@ import {
1213
SimpleChange,
1314
SimpleChanges,
1415
} from '@angular/core';
16+
import { FormsModule } from '@angular/forms';
1517
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
1618
import {
1719
DynamicFormControlModel,
@@ -66,7 +68,9 @@ import {
6668
ComcolPageLogoComponent,
6769
NgIf,
6870
NgClass,
71+
NgForOf,
6972
VarDirective,
73+
FormsModule,
7074
],
7175
})
7276
export class CollectionFormComponent extends ComColFormComponent<Collection> implements OnInit, OnChanges {
@@ -101,11 +105,14 @@ export class CollectionFormComponent extends ComColFormComponent<Collection> imp
101105
protected objectCache: ObjectCacheService,
102106
protected entityTypeService: EntityTypeDataService,
103107
protected chd: ChangeDetectorRef,
104-
protected modalService: NgbModal) {
105-
super(formService, translate, notificationsService, authService, requestService, objectCache, modalService);
108+
protected modalService: NgbModal,
109+
protected cdr: ChangeDetectorRef) {
110+
super(formService, translate, notificationsService, authService, requestService, objectCache, modalService, cdr);
106111
}
107112

108113
ngOnInit(): void {
114+
this.initializeLanguage();
115+
109116
if (hasNoValue(this.formModel) && isNotNull(this.dso)) {
110117
this.initializeForm();
111118
}
@@ -148,11 +155,23 @@ export class CollectionFormComponent extends ComColFormComponent<Collection> imp
148155
}
149156
});
150157

151-
this.formModel = entityTypes.length === 0 ? collectionFormModels : [...collectionFormModels, this.entityTypeSelection];
158+
this.formModels.set(
159+
this.defaultLanguageCode,
160+
this.getCollectionFormModels(entityTypes, collectionFormModels(this.defaultLanguageCode, true)),
161+
);
162+
this.languages.forEach(lang => {
163+
this.formModels.set(
164+
lang.code,
165+
this.getCollectionFormModels(entityTypes, collectionFormModels(lang.code, false)),
166+
);
167+
});
152168

153169
super.ngOnInit();
154170
this.chd.detectChanges();
155171
});
172+
}
156173

174+
private getCollectionFormModels(entityTypes: ItemType[], dynamicCollectionFormModels: DynamicFormControlModel[]): DynamicFormControlModel[] {
175+
return entityTypes.length === 0 ? dynamicCollectionFormModels : [...dynamicCollectionFormModels, this.entityTypeSelection];
157176
}
158177
}

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

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,43 @@ export const collectionFormEntityTypeSelectionConfig: DynamicSelectModelConfig<s
1717
* The dynamic form fields used for creating/editing a collection
1818
* @type {(DynamicInputModel | DynamicTextAreaModel)[]}
1919
*/
20-
export const collectionFormModels: DynamicFormControlModel[] = [
21-
new DynamicInputModel({
22-
id: 'title',
23-
name: 'dc.title',
24-
required: true,
25-
validators: {
26-
required: null,
27-
},
28-
errorMessages: {
29-
required: 'Please enter a name for this title',
30-
},
31-
}),
32-
new DynamicTextAreaModel({
33-
id: 'description',
34-
name: 'dc.description',
35-
spellCheck: environment.form.spellCheck,
36-
}),
37-
new DynamicTextAreaModel({
38-
id: 'abstract',
39-
name: 'dc.description.abstract',
40-
spellCheck: environment.form.spellCheck,
41-
}),
42-
new DynamicTextAreaModel({
43-
id: 'rights',
44-
name: 'dc.rights',
45-
spellCheck: environment.form.spellCheck,
46-
}),
47-
new DynamicTextAreaModel({
48-
id: 'tableofcontents',
49-
name: 'dc.description.tableofcontents',
50-
spellCheck: environment.form.spellCheck,
51-
}),
52-
new DynamicTextAreaModel({
53-
id: 'license',
54-
name: 'dc.rights.license',
55-
spellCheck: environment.form.spellCheck,
56-
}),
57-
];
20+
export const collectionFormModels = (lang: string, isDefaultLanguage: boolean): DynamicFormControlModel[] => {
21+
return [
22+
new DynamicInputModel({
23+
id: `title-${lang}`,
24+
name: 'dc.title',
25+
required: isDefaultLanguage,
26+
validators: {
27+
required: null,
28+
},
29+
errorMessages: {
30+
required: 'Please enter a name for this title',
31+
},
32+
}),
33+
new DynamicTextAreaModel({
34+
id: `description-${lang}`,
35+
name: 'dc.description',
36+
spellCheck: environment.form.spellCheck,
37+
}),
38+
new DynamicTextAreaModel({
39+
id: `abstract-${lang}`,
40+
name: 'dc.description.abstract',
41+
spellCheck: environment.form.spellCheck,
42+
}),
43+
new DynamicTextAreaModel({
44+
id: `rights-${lang}`,
45+
name: 'dc.rights',
46+
spellCheck: environment.form.spellCheck,
47+
}),
48+
new DynamicTextAreaModel({
49+
id: `tableofcontents-${lang}`,
50+
name: 'dc.description.tableofcontents',
51+
spellCheck: environment.form.spellCheck,
52+
}),
53+
new DynamicTextAreaModel({
54+
id: `license-${lang}`,
55+
name: 'dc.rights.license',
56+
spellCheck: environment.form.spellCheck,
57+
}),
58+
];
59+
};

src/app/collection-page/collection-page.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
</ds-comcol-page-handle>
2424
<!-- Introductory text -->
2525
<ds-comcol-page-content
26-
[content]="collection.introductoryText"
26+
[content]="collection.introductoryText(translateService.currentLang)"
2727
[hasInnerHtml]="true">
2828
</ds-comcol-page-content>
2929
<!-- News -->
3030
<ds-comcol-page-content
31-
[content]="collection.sidebarText"
31+
[content]="collection.sidebarText(translateService.currentLang)"
3232
[hasInnerHtml]="true"
3333
[title]="'collection.page.news'">
3434
</ds-comcol-page-content>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import {
1212
Router,
1313
RouterOutlet,
1414
} from '@angular/router';
15-
import { TranslateModule } from '@ngx-translate/core';
15+
import {
16+
TranslateModule,
17+
TranslateService,
18+
} from '@ngx-translate/core';
1619
import { Observable } from 'rxjs';
1720
import {
1821
filter,
@@ -103,6 +106,7 @@ export class CollectionPageComponent implements OnInit {
103106
protected authService: AuthService,
104107
protected authorizationDataService: AuthorizationDataService,
105108
public dsoNameService: DSONameService,
109+
public translateService: TranslateService,
106110
) {
107111
}
108112

src/app/community-list-page/community-list/community-list.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@
4646
</div>
4747
<ds-truncatable [id]="node.id">
4848
<div class="text-muted" cdkTreeNodePadding>
49-
<div class="d-flex" *ngIf="node.payload.shortDescription">
49+
<div class="d-flex" *ngIf="node.payload.shortDescription(translateService.currentLang) as shorDescription">
5050
<span aria-hidden="true" class="btn btn-default invisible">
5151
<span class="fa fa-chevron-right"></span>
5252
</span>
5353
<ds-truncatable-part [id]="node.id" [minLines]="3">
54-
<span>{{node.payload.shortDescription}}</span>
54+
<span>{{shorDescription}}</span>
5555
</ds-truncatable-part>
5656
</div>
5757
</div>
@@ -77,12 +77,12 @@ <h6 class="align-middle my-auto">
7777
</div>
7878
<ds-truncatable [id]="node.id">
7979
<div class="text-muted" cdkTreeNodePadding>
80-
<div class="d-flex" *ngIf="node.payload.shortDescription">
80+
<div class="d-flex" *ngIf="node.payload.shortDescription(translateService.currentLang)">
8181
<span aria-hidden="true" class="btn btn-default invisible">
8282
<span class="fa fa-chevron-right"></span>
8383
</span>
8484
<ds-truncatable-part [id]="node.id" [minLines]="3">
85-
<span>{{node.payload.shortDescription}}</span>
85+
<span>{{node.payload.shortDescription(translateService.currentLang)}}</span>
8686
</ds-truncatable-part>
8787
</div>
8888
</div>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import {
1313
OnInit,
1414
} from '@angular/core';
1515
import { RouterLink } from '@angular/router';
16-
import { TranslateModule } from '@ngx-translate/core';
16+
import {
17+
TranslateModule,
18+
TranslateService,
19+
} from '@ngx-translate/core';
1720
import { take } from 'rxjs/operators';
1821

1922
import { DSONameService } from '../../core/breadcrumbs/dso-name.service';
@@ -59,6 +62,7 @@ export class CommunityListComponent implements OnInit, OnDestroy {
5962
constructor(
6063
protected communityListService: CommunityListService,
6164
public dsoNameService: DSONameService,
65+
public translateService: TranslateService,
6266
) {
6367
this.paginationConfig = new FindListOptions();
6468
this.paginationConfig.elementsPerPage = 2;

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

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
import {
22
AsyncPipe,
33
NgClass,
4+
NgForOf,
45
NgIf,
56
} from '@angular/common';
67
import {
8+
ChangeDetectorRef,
79
Component,
810
Input,
911
OnChanges,
12+
OnInit,
1013
SimpleChange,
1114
SimpleChanges,
1215
} from '@angular/core';
16+
import { FormsModule } from '@angular/forms';
1317
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
14-
import {
15-
DynamicFormControlModel,
16-
DynamicFormService,
17-
DynamicInputModel,
18-
DynamicTextAreaModel,
19-
} from '@ng-dynamic-forms/core';
18+
import { DynamicFormService } from '@ng-dynamic-forms/core';
2019
import {
2120
TranslateModule,
2221
TranslateService,
2322
} from '@ngx-translate/core';
2423

25-
import { environment } from '../../../environments/environment';
2624
import { AuthService } from '../../core/auth/auth.service';
2725
import { ObjectCacheService } from '../../core/cache/object-cache.service';
2826
import { CommunityDataService } from '../../core/data/community-data.service';
@@ -34,6 +32,7 @@ import { FormComponent } from '../../shared/form/form.component';
3432
import { NotificationsService } from '../../shared/notifications/notifications.service';
3533
import { UploaderComponent } from '../../shared/upload/uploader/uploader.component';
3634
import { VarDirective } from '../../shared/utils/var.directive';
35+
import { communityFormModels } from './community-form.models';
3736

3837
/**
3938
* Form used for creating and editing communities
@@ -51,10 +50,12 @@ import { VarDirective } from '../../shared/utils/var.directive';
5150
ComcolPageLogoComponent,
5251
NgIf,
5352
NgClass,
53+
NgForOf,
5454
VarDirective,
55+
FormsModule,
5556
],
5657
})
57-
export class CommunityFormComponent extends ComColFormComponent<Community> implements OnChanges {
58+
export class CommunityFormComponent extends ComColFormComponent<Community> implements OnInit, OnChanges {
5859
/**
5960
* @type {Community} A new community when a community is being created, an existing Input community when a community is being edited
6061
*/
@@ -65,53 +66,27 @@ export class CommunityFormComponent extends ComColFormComponent<Community> imple
6566
*/
6667
type = Community.type;
6768

68-
/**
69-
* The dynamic form fields used for creating/editing a community
70-
* @type {(DynamicInputModel | DynamicTextAreaModel)[]}
71-
*/
72-
formModel: DynamicFormControlModel[] = [
73-
new DynamicInputModel({
74-
id: 'title',
75-
name: 'dc.title',
76-
required: true,
77-
validators: {
78-
required: null,
79-
},
80-
errorMessages: {
81-
required: 'Please enter a name for this title',
82-
},
83-
}),
84-
new DynamicTextAreaModel({
85-
id: 'description',
86-
name: 'dc.description',
87-
spellCheck: environment.form.spellCheck,
88-
}),
89-
new DynamicTextAreaModel({
90-
id: 'abstract',
91-
name: 'dc.description.abstract',
92-
spellCheck: environment.form.spellCheck,
93-
}),
94-
new DynamicTextAreaModel({
95-
id: 'rights',
96-
name: 'dc.rights',
97-
spellCheck: environment.form.spellCheck,
98-
}),
99-
new DynamicTextAreaModel({
100-
id: 'tableofcontents',
101-
name: 'dc.description.tableofcontents',
102-
spellCheck: environment.form.spellCheck,
103-
}),
104-
];
105-
10669
public constructor(protected formService: DynamicFormService,
10770
protected translate: TranslateService,
10871
protected notificationsService: NotificationsService,
10972
protected authService: AuthService,
11073
protected dsoService: CommunityDataService,
11174
protected requestService: RequestService,
11275
protected objectCache: ObjectCacheService,
113-
protected modalService: NgbModal) {
114-
super(formService, translate, notificationsService, authService, requestService, objectCache, modalService);
76+
protected modalService: NgbModal,
77+
protected cdr: ChangeDetectorRef) {
78+
super(formService, translate, notificationsService, authService, requestService, objectCache, modalService, cdr);
79+
}
80+
81+
ngOnInit() {
82+
this.initializeLanguage();
83+
84+
this.formModels.set(this.defaultLanguageCode, communityFormModels(this.defaultLanguageCode, true));
85+
this.languages.forEach(lang => {
86+
this.formModels.set(lang.code, communityFormModels(lang.code, false));
87+
});
88+
89+
super.ngOnInit();
11590
}
11691

11792
ngOnChanges(changes: SimpleChanges) {

0 commit comments

Comments
 (0)