[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,40 @@
/*!
* @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 { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { CustomNameColumnComponent } from './name-column/name-column.component';
import { LockedByModule } from '@alfresco/aca-shared';
import { ContentModule } from '@alfresco/adf-content-services';
import { MaterialModule } from '../../material.module';
import { CoreModule } from '@alfresco/adf-core';
import { ThumbnailColumnComponent } from './thumbnail-column/thumbnail-column.component';
@NgModule({
imports: [BrowserModule, CoreModule.forChild(), ContentModule.forChild(), MaterialModule, LockedByModule],
declarations: [CustomNameColumnComponent, ThumbnailColumnComponent],
exports: [CustomNameColumnComponent, ThumbnailColumnComponent]
})
export class DocumentListCustomComponentsModule {}

View File

@@ -0,0 +1,24 @@
<div
class="aca-custom-name-column"
[ngClass]="{
'aca-name-column-container': isFile && isFileWriteLocked
}"
>
<span
role="link"
[attr.aria-label]="
(isFile ? 'CUSTOM_NAME_COLUMN.ACCESSIBILITY.FILE_LINK_ARIA_LABEL' : 'CUSTOM_NAME_COLUMN.ACCESSIBILITY.FOLDER_LINK_ARIA_LABEL')
| translate: { name: displayText$ | async }
"
class="adf-datatable-cell-value"
title="{{ node | adfNodeNameTooltip }}"
(click)="onLinkClick($event)"
(keyup.enter)="onLinkClick($event)"
>
{{ displayText$ | async }}
</span>
<ng-container *ngIf="isFile && isFileWriteLocked">
<aca-locked-by [node]="context.row.node"></aca-locked-by>
</ng-container>
</div>

View File

@@ -0,0 +1,19 @@
.aca-custom-name-column {
display: block;
align-items: center;
.aca-name-column-container {
aca-locked-by {
display: flex;
align-items: center;
color: rgba(0, 0, 0, 0.54);
max-width: 100%;
padding: 0 10px;
.locked_by--name {
overflow: hidden;
text-overflow: ellipsis;
}
}
}
}

View File

@@ -0,0 +1,124 @@
/*!
* @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 { CustomNameColumnComponent } from './name-column.component';
import { DocumentListCustomComponentsModule } from '../document-list-custom-components.module';
import { Actions } from '@ngrx/effects';
import { StoreModule } from '@ngrx/store';
import { TestBed } from '@angular/core/testing';
import { CoreModule } from '@alfresco/adf-core';
import { TranslateModule } from '@ngx-translate/core';
describe('CustomNameColumnComponent', () => {
let fixture;
let component;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot(),
CoreModule.forRoot(),
DocumentListCustomComponentsModule,
StoreModule.forRoot({ app: () => {} }, { initialState: {} })
],
providers: [Actions]
});
fixture = TestBed.createComponent(CustomNameColumnComponent);
component = fixture.componentInstance;
});
it('should not render lock element if file is not locked', () => {
component.context = {
row: {
node: {
entry: {
isFile: true,
id: 'nodeId'
}
},
getValue: (key: string) => key
}
};
fixture.detectChanges();
expect(fixture.debugElement.nativeElement.querySelector('aca-locked-by')).toBe(null);
});
it('should not render lock element if node is not a file', () => {
component.context = {
row: {
node: {
entry: {
isFile: false,
id: 'nodeId'
}
},
getValue: (key: string) => key
}
};
fixture.detectChanges();
expect(fixture.debugElement.nativeElement.querySelector('aca-locked-by')).toBe(null);
});
it('should render lock element if file is locked', () => {
component.context = {
row: {
node: {
entry: {
isFile: true,
id: 'nodeId',
properties: { 'cm:lockType': 'WRITE_LOCK' }
}
},
getValue: (key: string) => key
}
};
fixture.detectChanges();
expect(fixture.debugElement.nativeElement.querySelector('aca-locked-by')).not.toBe(null);
});
it('should call parent component onClick method', () => {
const event = new MouseEvent('click');
spyOn(component, 'onClick');
component.onLinkClick(event);
expect(component.onClick).toHaveBeenCalled();
});
it('should prevent event propagation', () => {
const event = new MouseEvent('click');
spyOn(event, 'stopPropagation');
component.onLinkClick(event);
expect(event.stopPropagation).toHaveBeenCalled();
});
});

View File

@@ -0,0 +1,99 @@
/*!
* @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 { NameColumnComponent } from '@alfresco/adf-content-services';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { Actions, ofType } from '@ngrx/effects';
import { Subject } from 'rxjs';
import { filter, takeUntil } from 'rxjs/operators';
import { NodeActionTypes } from '@alfresco/aca-shared/store';
import { isLocked } from '@alfresco/aca-shared';
@Component({
selector: 'aca-custom-name-column',
templateUrl: './name-column.component.html',
styleUrls: ['./name-column.component.scss'],
encapsulation: ViewEncapsulation.None,
host: {
class: 'adf-datatable-content-cell adf-datatable-link adf-name-column aca-custom-name-column'
}
})
export class CustomNameColumnComponent extends NameColumnComponent implements OnInit, OnDestroy {
private onDestroy$$ = new Subject<boolean>();
constructor(element: ElementRef, private cd: ChangeDetectorRef, private actions$: Actions, private apiService: AlfrescoApiService) {
super(element, apiService);
}
ngOnInit() {
this.updateValue();
this.apiService.nodeUpdated.pipe(takeUntil(this.onDestroy$$)).subscribe((node: any) => {
const row = this.context.row;
if (row) {
const { entry } = row.node;
const currentId = entry.nodeId || entry.id;
const updatedId = node.nodeId || node.id;
if (currentId === updatedId) {
entry.name = node.name;
row.node = { entry };
this.updateValue();
}
}
});
this.actions$
.pipe(
ofType<any>(NodeActionTypes.EditOffline),
filter((val) => this.node.entry.id === val.payload.entry.id),
takeUntil(this.onDestroy$$)
)
.subscribe(() => {
this.cd.detectChanges();
});
}
onLinkClick(event: Event) {
event.stopPropagation();
this.onClick();
}
ngOnDestroy() {
super.ngOnDestroy();
this.onDestroy$$.next(true);
this.onDestroy$$.complete();
}
get isFile(): boolean {
return this.node && this.node.entry && !this.node.entry.isFolder;
}
get isFileWriteLocked(): boolean {
return isLocked(this.node);
}
}

View File

@@ -0,0 +1,7 @@
<mat-icon class="adf-datatable-selected" *ngIf="context.row.isSelected" svgIcon="selected"></mat-icon>
<img *ngIf="!context.row.isSelected"
class="adf-datatable-center-img-ie"
src="{{ getThumbnail(context) }}"
[alt]="getToolTip(context)"
[matTooltip]="getToolTip(context)">

View File

@@ -0,0 +1,48 @@
/*!
* @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, ViewEncapsulation } from '@angular/core';
import { TranslationService } from '@alfresco/adf-core';
@Component({
selector: 'aca-custom-thumbnail-column',
templateUrl: './thumbnail-column.component.html',
encapsulation: ViewEncapsulation.None
})
export class ThumbnailColumnComponent {
@Input()
context: any;
constructor(private translation: TranslationService) {}
getThumbnail({ data, row, col }): string {
return data.getValue(row, col);
}
getToolTip({ row }): string {
const user = row.node?.entry?.properties && row.node.entry.properties['cm:lockOwner'] && row.node.entry.properties['cm:lockOwner'].displayName;
return user ? `${this.translation.instant('APP.LOCKED_BY')} ${user}` : '';
}
}