[AAE-11496] Move 'content-plugin' to projects folder as 'aca-content' (#2817)

* [AAE-11496] Move content-plugin to projects

* Fix unit test
This commit is contained in:
Bartosz Sekuła
2022-12-20 18:15:34 +01:00
committed by GitHub
parent c87662900e
commit e570ef8da0
263 changed files with 291 additions and 58 deletions

View File

@@ -0,0 +1,134 @@
<mat-card *ngIf="node">
<mat-card-content *ngIf="!edit">
<div class="mat-form-field mat-form-field-type-mat-input mat-form-field-can-float mat-form-field-should-float adf-full-width">
<div class="mat-form-field-wrapper">
<div class="mat-form-field-flex">
<div class="mat-form-field-infix">
<span class="mat-form-field-label-wrapper">
<span class="mat-form-field-label">
{{ 'LIBRARY.DIALOG.FORM.NAME' | translate }}
</span>
</span>
<span class="mat-input-element">
{{ form.controls.title.value }}
</span>
</div>
</div>
</div>
</div>
<div class="mat-form-field mat-primary mat-form-field-type-mat-input mat-form-field-can-float mat-form-field-should-float adf-full-width">
<div class="mat-form-field-wrapper">
<div class="mat-form-field-flex">
<div class="mat-form-field-infix">
<span class="mat-form-field-label-wrapper">
<span class="mat-form-field-label">
{{ 'LIBRARY.DIALOG.FORM.SITE_ID' | translate }}
</span>
</span>
<span class="mat-input-element">
{{ form.controls.id.value }}
</span>
</div>
</div>
</div>
</div>
<div class="mat-form-field mat-primary mat-form-field-type-mat-input mat-form-field-can-float mat-form-field-should-float adf-full-width">
<div class="mat-form-field-wrapper">
<div class="mat-form-field-flex">
<div class="mat-form-field-infix">
<span class="mat-form-field-label-wrapper">
<span class="mat-form-field-label">
{{ 'LIBRARY.DIALOG.FORM.VISIBILITY' | translate }}
</span>
</span>
<span class="mat-input-element">
{{ getVisibilityLabel(form.controls.visibility.value) | translate }}
</span>
</div>
</div>
</div>
</div>
<div class="mat-form-field mat-primary mat-form-field-type-mat-input mat-form-field-can-float mat-form-field-should-float adf-full-width">
<div class="mat-form-field-wrapper">
<div class="mat-form-field-flex">
<div class="mat-form-field-infix">
<span class="mat-form-field-label-wrapper">
<span class="mat-form-field-label">
{{ 'LIBRARY.DIALOG.FORM.DESCRIPTION' | translate }}
</span>
</span>
<span class="mat-input-element">
{{ form.controls.description?.value }}
</span>
</div>
</div>
</div>
</div>
</mat-card-content>
<mat-card-actions align="end" *ngIf="!edit && canUpdateLibrary">
<button mat-button color="primary" (click)="toggleEdit()">
{{ 'LIBRARY.DIALOG.EDIT' | translate }}
</button>
</mat-card-actions>
<mat-card-content *ngIf="edit">
<form [formGroup]="form" autocomplete="off">
<mat-form-field class="adf-full-width">
<input
matInput
cdkFocusInitial
required
placeholder="{{ 'LIBRARY.DIALOG.FORM.NAME' | translate }}"
formControlName="title"
[errorStateMatcher]="matcher"
/>
<mat-hint *ngIf="libraryTitleExists">{{ 'LIBRARY.HINTS.SITE_TITLE_EXISTS' | translate }}</mat-hint>
<mat-error>
{{ 'LIBRARY.ERRORS.TITLE_TOO_LONG' | translate }}
</mat-error>
</mat-form-field>
<mat-form-field class="adf-full-width">
<input matInput placeholder="{{ 'LIBRARY.DIALOG.FORM.SITE_ID' | translate }}" formControlName="id" />
</mat-form-field>
<mat-form-field class="adf-full-width">
<mat-select placeholder="{{ 'LIBRARY.DIALOG.FORM.VISIBILITY' | translate }}" formControlName="visibility">
<mat-option [value]="type.value" *ngFor="let type of libraryType">
{{ type.label | translate }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field class="adf-full-width">
<textarea
matInput
placeholder="{{ 'LIBRARY.DIALOG.FORM.DESCRIPTION' | translate }}"
rows="3"
formControlName="description"
[errorStateMatcher]="matcher"
></textarea>
<mat-error>
{{ 'LIBRARY.ERRORS.DESCRIPTION_TOO_LONG' | translate }}
</mat-error>
</mat-form-field>
</form>
</mat-card-content>
<mat-card-actions align="end" *ngIf="edit && canUpdateLibrary">
<button mat-button (click)="cancel()">
{{ 'LIBRARY.DIALOG.CANCEL' | translate }}
</button>
<button mat-button color="primary" [disabled]="form.invalid || form.pristine" (click)="update()">
{{ 'LIBRARY.DIALOG.UPDATE' | translate }}
</button>
</mat-card-actions>
</mat-card>

View File

@@ -0,0 +1,296 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { LibraryMetadataFormComponent } from './library-metadata-form.component';
import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
import { Store } from '@ngrx/store';
import { UpdateLibraryAction } from '@alfresco/aca-shared/store';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Site, SitePaging } from '@alfresco/js-api';
describe('LibraryMetadataFormComponent', () => {
let fixture: ComponentFixture<LibraryMetadataFormComponent>;
let component: LibraryMetadataFormComponent;
let store: Store<any>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule],
declarations: [LibraryMetadataFormComponent],
providers: [
{
provide: Store,
useValue: {
dispatch: jasmine.createSpy('dispatch')
}
}
],
schemas: [NO_ERRORS_SCHEMA]
});
store = TestBed.inject(Store);
fixture = TestBed.createComponent(LibraryMetadataFormComponent);
component = fixture.componentInstance;
});
it('should initialize form with node data', () => {
const siteEntryModel = {
title: 'libraryTitle',
description: 'description',
visibility: 'PRIVATE'
};
component.node = {
entry: {
id: 'libraryId',
...siteEntryModel
} as Site
};
fixture.detectChanges();
expect(component.form.value).toEqual(siteEntryModel);
});
it('should update form data when node data changes', () => {
const siteEntryModel = {
title: 'libraryTitle',
description: 'description',
visibility: 'PRIVATE'
};
const newSiteEntryModel = {
title: 'libraryTitle2',
description: 'description2',
visibility: 'PUBLIC'
};
component.node = {
entry: {
id: 'libraryId',
...siteEntryModel
} as Site
};
fixture.detectChanges();
expect(component.form.value).toEqual(siteEntryModel);
component.node = {
entry: {
id: 'libraryId',
...newSiteEntryModel
} as Site
};
component.ngOnChanges();
expect(component.form.value).toEqual(newSiteEntryModel);
});
it('should update library node if form is valid', () => {
const siteEntryModel = {
title: 'libraryTitle',
description: 'description',
visibility: 'PRIVATE'
};
component.node = {
entry: {
id: 'libraryId',
role: 'SiteManager',
...siteEntryModel
} as Site
};
fixture.detectChanges();
component.update();
expect(store.dispatch).toHaveBeenCalledWith(new UpdateLibraryAction(siteEntryModel));
});
it('should not update library node if it has no permission', () => {
const siteEntryModel = {
title: 'libraryTitle',
description: 'description',
visibility: 'PRIVATE'
};
component.node = {
entry: {
id: 'libraryId',
role: 'Consumer',
...siteEntryModel
} as Site
};
fixture.detectChanges();
component.update();
expect(store.dispatch).not.toHaveBeenCalledWith(new UpdateLibraryAction(siteEntryModel));
});
it('should not update library node if form is invalid', () => {
const siteEntryModel = {
title: 'libraryTitle',
description: 'description',
visibility: 'PRIVATE'
};
component.node = {
entry: {
id: 'libraryId',
role: 'SiteManager',
...siteEntryModel
} as Site
};
fixture.detectChanges();
component.form.controls['title'].setErrors({ maxlength: true });
component.update();
expect(store.dispatch).not.toHaveBeenCalledWith(new UpdateLibraryAction(siteEntryModel));
});
it('should toggle edit mode', () => {
component.edit = false;
component.toggleEdit();
expect(component.edit).toBe(true);
component.toggleEdit();
expect(component.edit).toBe(false);
});
it('should cancel from changes', () => {
const siteEntryModel = {
title: 'libraryTitle',
description: 'description',
visibility: 'PRIVATE'
};
component.node = {
entry: {
id: 'libraryId',
...siteEntryModel
} as Site
};
fixture.detectChanges();
expect(component.form.value).toEqual(siteEntryModel);
component.form.controls.title.setValue('libraryTitle-edit');
expect(component.form.value.title).toBe('libraryTitle-edit');
component.cancel();
expect(component.form.value).toEqual(siteEntryModel);
});
it('should warn if library name input is used by another library', fakeAsync(() => {
const title = 'some-title';
spyOn(component['queriesApi'], 'findSites').and.returnValue(
Promise.resolve({
list: { entries: [{ entry: { title } }] }
} as SitePaging)
);
const siteEntryModel = {
title: 'libraryTitle',
description: 'description',
visibility: 'PRIVATE'
};
component.node = {
entry: {
id: 'libraryId',
...siteEntryModel
} as Site
};
fixture.detectChanges();
component.form.controls.title.setValue(title);
fixture.detectChanges();
tick(500);
expect(component.libraryTitleExists).toBe(true);
}));
it('should not warn if library name input is the same with library node data', fakeAsync(() => {
spyOn(component['queriesApi'], 'findSites').and.returnValue(
Promise.resolve({
list: { entries: [{ entry: { title: 'libraryTitle' } }] }
} as SitePaging)
);
const siteEntryModel = {
title: 'libraryTitle',
description: 'description',
visibility: 'PRIVATE'
};
component.node = {
entry: {
id: 'libraryId',
...siteEntryModel
} as Site
};
fixture.detectChanges();
component.form.controls.title.setValue('libraryTitle');
fixture.detectChanges();
tick(500);
expect(component.libraryTitleExists).toBe(false);
}));
it('should not warn if library name is unique', fakeAsync(() => {
spyOn(component['queriesApi'], 'findSites').and.returnValue(
Promise.resolve({
list: { entries: [] }
} as SitePaging)
);
const siteEntryModel = {
title: 'libraryTitle',
description: 'description',
visibility: 'PRIVATE'
};
component.node = {
entry: {
id: 'libraryId',
...siteEntryModel
} as Site
};
fixture.detectChanges();
component.form.controls.title.setValue('some-name');
fixture.detectChanges();
tick(500);
expect(component.libraryTitleExists).toBe(false);
}));
});

View File

@@ -0,0 +1,156 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, Input, OnInit, OnChanges, OnDestroy } from '@angular/core';
import { UntypedFormGroup, UntypedFormControl, Validators, FormGroupDirective, NgForm } from '@angular/forms';
import { QueriesApi, SiteEntry, SitePaging } from '@alfresco/js-api';
import { Store } from '@ngrx/store';
import { AppStore, UpdateLibraryAction } from '@alfresco/aca-shared/store';
import { debounceTime, mergeMap, takeUntil } from 'rxjs/operators';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { Observable, from, Subject } from 'rxjs';
import { ErrorStateMatcher } from '@angular/material/core';
export class InstantErrorStateMatcher implements ErrorStateMatcher {
isErrorState(control: UntypedFormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const isSubmitted = form && form.submitted;
return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted));
}
}
@Component({
selector: 'app-library-metadata-form',
templateUrl: './library-metadata-form.component.html'
})
export class LibraryMetadataFormComponent implements OnInit, OnChanges, OnDestroy {
_queriesApi: QueriesApi;
get queriesApi(): QueriesApi {
this._queriesApi = this._queriesApi ?? new QueriesApi(this.alfrescoApiService.getInstance());
return this._queriesApi;
}
@Input()
node: SiteEntry;
edit: boolean;
libraryTitleExists = false;
libraryType = [
{ value: 'PUBLIC', label: 'LIBRARY.VISIBILITY.PUBLIC' },
{ value: 'PRIVATE', label: 'LIBRARY.VISIBILITY.PRIVATE' },
{ value: 'MODERATED', label: 'LIBRARY.VISIBILITY.MODERATED' }
];
form: UntypedFormGroup = new UntypedFormGroup({
id: new UntypedFormControl({ value: '', disabled: true }),
title: new UntypedFormControl({ value: '' }, [Validators.required, Validators.maxLength(256)]),
description: new UntypedFormControl({ value: '' }, [Validators.maxLength(512)]),
visibility: new UntypedFormControl(this.libraryType[0].value)
});
matcher = new InstantErrorStateMatcher();
onDestroy$: Subject<boolean> = new Subject<boolean>();
constructor(private alfrescoApiService: AlfrescoApiService, protected store: Store<AppStore>) {}
get canUpdateLibrary() {
return this.node && this.node.entry && this.node.entry.role === 'SiteManager';
}
getVisibilityLabel(value: string) {
return this.libraryType.find((type) => type.value === value).label;
}
toggleEdit() {
this.edit = !this.edit;
}
cancel() {
this.updateForm(this.node);
this.toggleEdit();
}
ngOnInit() {
this.updateForm(this.node);
this.form.controls['title'].valueChanges
.pipe(
debounceTime(300),
mergeMap((title) => this.findLibraryByTitle(title)),
takeUntil(this.onDestroy$)
)
.subscribe((result) => {
const { entries } = result.list;
if (entries.length) {
if (this.form.controls.title.value === this.node.entry.title) {
this.libraryTitleExists = false;
} else {
this.libraryTitleExists = this.form.controls.title.value === entries[0].entry.title;
}
} else {
this.libraryTitleExists = false;
}
});
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
ngOnChanges() {
this.updateForm(this.node);
}
update() {
if (this.canUpdateLibrary && this.form.valid) {
this.store.dispatch(new UpdateLibraryAction(this.form.value));
}
}
private updateForm(node: SiteEntry) {
const { entry } = node;
this.form.setValue({
id: entry.id,
title: entry.title,
description: entry.description || '',
visibility: entry.visibility
});
}
private findLibraryByTitle(libraryTitle: string): Observable<SitePaging | { list: { entries: any[] } }> {
return from(
this.queriesApi
.findSites(libraryTitle, {
maxItems: 1,
fields: ['title']
})
.catch(() => ({ list: { entries: [] } }))
);
}
}

View File

@@ -0,0 +1,37 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, Input } from '@angular/core';
import { SiteEntry } from '@alfresco/js-api';
@Component({
selector: 'app-library-metadata-tab',
template: '<app-library-metadata-form [node]="node"></app-library-metadata-form>',
host: { class: 'app-metadata-tab' }
})
export class LibraryMetadataTabComponent {
@Input()
node: SiteEntry;
}