From 1666c8692aa03056140b879f43283397549e0b79 Mon Sep 17 00:00:00 2001 From: pcg-kk Date: Thu, 23 May 2024 21:51:48 +0200 Subject: [PATCH] fix: move translateService.currentLang assignment to the component fix: order of elements fix: changes after code review feat: fix e2e feat: next test fix feat: first test fix feat: fix unit feat: use the metadata with correct language feat: provide a language support for community pages --- cypress/e2e/collection-create.cy.ts | 4 +- cypress/e2e/community-create.cy.ts | 4 +- .../collection-form.component.ts | 25 ++- .../collection-form/collection-form.models.ts | 78 ++++---- .../collection-page.component.html | 8 +- .../collection-page.component.ts | 14 +- .../community-list.component.html | 8 +- .../community-list.component.ts | 17 +- .../community-form.component.ts | 71 +++---- .../community-form/community-form.models.ts | 48 +++++ .../community-page.component.html | 8 +- .../community-page.component.ts | 14 +- src/app/core/breadcrumbs/dso-name.service.ts | 4 + src/app/core/shared/collection.model.ts | 20 +- src/app/core/shared/community.model.ts | 16 +- .../comcol-form/comcol-form.component.html | 63 ++++++- .../comcol-form/comcol-form.component.scss | 7 + .../comcol-form/comcol-form.component.spec.ts | 64 ++++--- .../comcol-form/comcol-form.component.ts | 176 +++++++++++++----- .../shared/mocks/translate.service.mock.ts | 12 ++ .../collection-grid-element.component.html | 2 +- .../collection-grid-element.component.ts | 15 +- .../community-grid-element.component.html | 2 +- .../community-grid-element.component.ts | 15 +- ...-search-result-grid-element.component.html | 2 +- ...on-search-result-grid-element.component.ts | 14 +- ...-search-result-grid-element.component.html | 2 +- ...ty-search-result-grid-element.component.ts | 15 +- .../collection-list-element.component.html | 4 +- .../collection-list-element.component.spec.ts | 3 + .../collection-list-element.component.ts | 20 +- .../community-list-element.component.html | 4 +- .../community-list-element.component.spec.ts | 3 + .../community-list-element.component.ts | 10 + ...-search-result-list-element.component.html | 2 +- ...arch-result-list-element.component.spec.ts | 3 + ...on-search-result-list-element.component.ts | 23 +++ ...-search-result-list-element.component.html | 2 +- ...arch-result-list-element.component.spec.ts | 3 + ...ty-search-result-list-element.component.ts | 24 +++ src/assets/i18n/en.json5 | 4 + src/assets/i18n/pl.json5 | 2 + 42 files changed, 608 insertions(+), 227 deletions(-) create mode 100644 src/app/community-page/community-form/community-form.models.ts diff --git a/cypress/e2e/collection-create.cy.ts b/cypress/e2e/collection-create.cy.ts index 29f7dd5cacb..423464233f8 100644 --- a/cypress/e2e/collection-create.cy.ts +++ b/cypress/e2e/collection-create.cy.ts @@ -5,9 +5,9 @@ beforeEach(() => { it('should show loading component while saving', () => { const title = 'Test Collection Title'; - cy.get('#title').type(title); + cy.get('#title-en').type(title); - cy.get('button[type="submit"]').click(); + cy.get('button[type="button"].btn-primary').click(); cy.get('ds-loading').should('be.visible'); }); diff --git a/cypress/e2e/community-create.cy.ts b/cypress/e2e/community-create.cy.ts index 96bc003ba2a..205f270db14 100644 --- a/cypress/e2e/community-create.cy.ts +++ b/cypress/e2e/community-create.cy.ts @@ -5,9 +5,9 @@ beforeEach(() => { it('should show loading component while saving', () => { const title = 'Test Community Title'; - cy.get('#title').type(title); + cy.get('#title-en').type(title); - cy.get('button[type="submit"]').click(); + cy.get('button[type="button"].btn-primary').click(); cy.get('ds-loading').should('be.visible'); }); diff --git a/src/app/collection-page/collection-form/collection-form.component.ts b/src/app/collection-page/collection-form/collection-form.component.ts index 0758435db88..9338d744b37 100644 --- a/src/app/collection-page/collection-form/collection-form.component.ts +++ b/src/app/collection-page/collection-form/collection-form.component.ts @@ -1,6 +1,7 @@ import { AsyncPipe, NgClass, + NgForOf, NgIf, } from '@angular/common'; import { @@ -12,6 +13,7 @@ import { SimpleChange, SimpleChanges, } from '@angular/core'; +import { FormsModule } from '@angular/forms'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { DynamicFormControlModel, @@ -66,7 +68,9 @@ import { ComcolPageLogoComponent, NgIf, NgClass, + NgForOf, VarDirective, + FormsModule, ], }) export class CollectionFormComponent extends ComColFormComponent implements OnInit, OnChanges { @@ -101,11 +105,14 @@ export class CollectionFormComponent extends ComColFormComponent imp protected objectCache: ObjectCacheService, protected entityTypeService: EntityTypeDataService, protected chd: ChangeDetectorRef, - protected modalService: NgbModal) { - super(formService, translate, notificationsService, authService, requestService, objectCache, modalService); + protected modalService: NgbModal, + protected cdr: ChangeDetectorRef) { + super(formService, translate, notificationsService, authService, requestService, objectCache, modalService, cdr); } ngOnInit(): void { + this.initializeLanguage(); + if (hasNoValue(this.formModel) && isNotNull(this.dso)) { this.initializeForm(); } @@ -148,11 +155,23 @@ export class CollectionFormComponent extends ComColFormComponent imp } }); - this.formModel = entityTypes.length === 0 ? collectionFormModels : [...collectionFormModels, this.entityTypeSelection]; + this.formModels.set( + this.defaultLanguageCode, + this.getCollectionFormModels(entityTypes, collectionFormModels(this.defaultLanguageCode, true)), + ); + this.languages.forEach(lang => { + this.formModels.set( + lang.code, + this.getCollectionFormModels(entityTypes, collectionFormModels(lang.code, false)), + ); + }); super.ngOnInit(); this.chd.detectChanges(); }); + } + private getCollectionFormModels(entityTypes: ItemType[], dynamicCollectionFormModels: DynamicFormControlModel[]): DynamicFormControlModel[] { + return entityTypes.length === 0 ? dynamicCollectionFormModels : [...dynamicCollectionFormModels, this.entityTypeSelection]; } } diff --git a/src/app/collection-page/collection-form/collection-form.models.ts b/src/app/collection-page/collection-form/collection-form.models.ts index 22998af674e..f0c35270ebb 100644 --- a/src/app/collection-page/collection-form/collection-form.models.ts +++ b/src/app/collection-page/collection-form/collection-form.models.ts @@ -17,41 +17,43 @@ export const collectionFormEntityTypeSelectionConfig: DynamicSelectModelConfig { + return [ + new DynamicInputModel({ + id: `title-${lang}`, + name: 'dc.title', + required: isDefaultLanguage, + validators: { + required: null, + }, + errorMessages: { + required: 'Please enter a name for this title', + }, + }), + new DynamicTextAreaModel({ + id: `description-${lang}`, + name: 'dc.description', + spellCheck: environment.form.spellCheck, + }), + new DynamicTextAreaModel({ + id: `abstract-${lang}`, + name: 'dc.description.abstract', + spellCheck: environment.form.spellCheck, + }), + new DynamicTextAreaModel({ + id: `rights-${lang}`, + name: 'dc.rights', + spellCheck: environment.form.spellCheck, + }), + new DynamicTextAreaModel({ + id: `tableofcontents-${lang}`, + name: 'dc.description.tableofcontents', + spellCheck: environment.form.spellCheck, + }), + new DynamicTextAreaModel({ + id: `license-${lang}`, + name: 'dc.rights.license', + spellCheck: environment.form.spellCheck, + }), + ]; +}; diff --git a/src/app/collection-page/collection-page.component.html b/src/app/collection-page/collection-page.component.html index 4a3e28c6aad..1679ef54ae8 100644 --- a/src/app/collection-page/collection-page.component.html +++ b/src/app/collection-page/collection-page.component.html @@ -23,12 +23,12 @@ @@ -44,10 +44,10 @@ -