[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,41 @@
/*!
* @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 { CoreModule } from '@alfresco/adf-core';
import { ExtensionsModule } from '@alfresco/adf-extensions';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { GenericErrorModule } from '@alfresco/aca-shared';
import { LocationLinkComponent } from './location-link/location-link.component';
import { ToggleSharedComponent } from './toggle-shared/toggle-shared.component';
import { LanguagePickerComponent } from './language-picker/language-picker.component';
import { LogoutComponent } from './logout/logout.component';
@NgModule({
imports: [CommonModule, CoreModule.forChild(), ExtensionsModule, GenericErrorModule],
declarations: [LocationLinkComponent, ToggleSharedComponent, LanguagePickerComponent, LogoutComponent],
exports: [ExtensionsModule, LocationLinkComponent, GenericErrorModule, ToggleSharedComponent, LanguagePickerComponent, LogoutComponent]
})
export class AppCommonModule {}

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 { Component } from '@angular/core';
@Component({
selector: 'aca-language-picker',
template: `
<button mat-menu-item [matMenuTriggerFor]="langMenu">
<mat-icon>language</mat-icon>
{{ 'APP.LANGUAGE' | translate }}
</button>
<mat-menu #langMenu="matMenu">
<adf-language-menu></adf-language-menu>
</mat-menu>
`
})
export class LanguagePickerComponent {}

View File

@@ -0,0 +1,184 @@
/*!
* @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, ChangeDetectionStrategy, OnInit, ViewEncapsulation, HostListener } from '@angular/core';
import { PathInfo, MinimalNodeEntity } from '@alfresco/js-api';
import { Observable, BehaviorSubject, of } from 'rxjs';
import { Store } from '@ngrx/store';
import { AppStore, NavigateToParentFolder } from '@alfresco/aca-shared/store';
import { ContentApiService } from '@alfresco/aca-shared';
import { TranslationService } from '@alfresco/adf-core';
@Component({
selector: 'aca-location-link',
template: `
<a
href=""
[title]="nodeLocation$ | async"
(click)="goToLocation()"
class="adf-datatable-cell-value"
[innerHTML]="displayText | async | translate"
>
</a>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
host: {
class: 'aca-location-link adf-location-cell adf-datatable-content-cell'
}
})
export class LocationLinkComponent implements OnInit {
private _path: PathInfo;
nodeLocation$ = new BehaviorSubject(this.translationService.instant('APP.BROWSE.SEARCH.UNKNOWN_LOCATION'));
displayText: Observable<string>;
@Input()
context: any;
@Input()
showLocation = false;
@HostListener('mouseenter')
onMouseEnter() {
this.getTooltip(this._path);
}
constructor(private store: Store<AppStore>, private contentApi: ContentApiService, private translationService: TranslationService) {}
goToLocation() {
if (this.context) {
const node: MinimalNodeEntity = this.context.row.node;
this.store.dispatch(new NavigateToParentFolder(node));
}
}
ngOnInit() {
if (this.context) {
const node: MinimalNodeEntity = this.context.row.node;
if (node && node.entry && node.entry.path) {
const path = node.entry.path;
if (path && path.name && path.elements) {
if (this.showLocation) {
this.displayText = of(path.name.substring(1).replace(/\//g, ' &#8250; '));
} else {
this.displayText = this.getDisplayText(path);
}
this._path = path;
} else {
this.displayText = of('APP.BROWSE.SEARCH.UNKNOWN_LOCATION');
}
}
}
}
// todo: review once 5.2.3 is out
private getDisplayText(path: PathInfo): Observable<string> {
const elements = path.elements.map((e) => e.name);
// for admin users
if (elements.length === 1 && elements[0] === 'Company Home') {
return of('APP.BROWSE.PERSONAL.TITLE');
}
// for non-admin users
if (elements.length === 3 && elements[0] === 'Company Home' && elements[1] === 'User Homes') {
return of('APP.BROWSE.PERSONAL.TITLE');
}
const result = elements[elements.length - 1];
if (result === 'documentLibrary') {
const fragment = path.elements[path.elements.length - 2];
return new Observable<string>((observer) => {
this.contentApi.getNodeInfo(fragment.id).subscribe(
(node) => {
observer.next(node.properties['cm:title'] || node.name || fragment.name);
observer.complete();
},
() => {
observer.next(fragment.name);
observer.complete();
}
);
});
}
return of(result);
}
// todo: review once 5.2.3 is out
private getTooltip(path: PathInfo) {
if (!path) {
return;
}
let result: string = null;
const elements = path.elements.map((e) => Object.assign({}, e));
const personalFiles = this.translationService.instant('APP.BROWSE.PERSONAL.TITLE');
const fileLibraries = this.translationService.instant('APP.BROWSE.LIBRARIES.TITLE');
if (elements[0].name === 'Company Home') {
elements[0].name = personalFiles;
if (elements.length > 2) {
if (elements[1].name === 'Sites') {
const fragment = elements[2];
this.contentApi.getNodeInfo(fragment.id).subscribe(
(node) => {
elements.splice(0, 2);
elements[0].name = node.properties['cm:title'] || node.name || fragment.name;
elements.splice(1, 1);
elements.unshift({ id: null, name: fileLibraries });
result = elements.map((e) => e.name).join('/');
this.nodeLocation$.next(result);
},
() => {
elements.splice(0, 2);
elements.unshift({ id: null, name: fileLibraries });
elements.splice(2, 1);
result = elements.map((e) => e.name).join('/');
this.nodeLocation$.next(result);
}
);
}
if (elements[1].name === 'User Homes') {
elements.splice(0, 3);
elements.unshift({ id: null, name: personalFiles });
}
}
}
result = elements.map((e) => e.name).join('/');
this.nodeLocation$.next(result);
}
}

View File

@@ -0,0 +1,62 @@
/*!
* @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 { TestBed, ComponentFixture } from '@angular/core/testing';
import { AppTestingModule } from '../../../testing/app-testing.module';
import { LogoutComponent } from './logout.component';
import { Store } from '@ngrx/store';
import { SetSelectedNodesAction } from '@alfresco/aca-shared/store';
describe('LogoutComponent', () => {
let fixture: ComponentFixture<LogoutComponent>;
let component: LogoutComponent;
let store;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule],
declarations: [LogoutComponent],
providers: [
{
provide: Store,
useValue: {
dispatch: jasmine.createSpy('dispatch')
}
}
]
});
store = TestBed.inject(Store);
fixture = TestBed.createComponent(LogoutComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should reset selected nodes from store', () => {
component.onLogoutEvent();
expect(store.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([]));
});
});

View File

@@ -0,0 +1,45 @@
/*!
* @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 } from '@angular/core';
import { Store } from '@ngrx/store';
import { AppStore, SetSelectedNodesAction } from '@alfresco/aca-shared/store';
@Component({
selector: 'aca-logout',
template: `
<button mat-menu-item (click)="onLogoutEvent()" adf-logout>
<mat-icon>exit_to_app</mat-icon>
<span>{{ 'APP.SIGN_OUT' | translate }}</span>
</button>
`
})
export class LogoutComponent {
constructor(private store: Store<AppStore>) {}
onLogoutEvent() {
this.store.dispatch(new SetSelectedNodesAction([]));
}
}

View File

@@ -0,0 +1,27 @@
<ng-container *ngIf="selection$ | async as selection">
<ng-container *ngIf="!data.iconButton">
<button mat-menu-item data-automation-id="share-action-button" (click)="editSharedNode(selection, '.adf-context-menu-source')">
<mat-icon>link</mat-icon>
<ng-container *ngIf="isShared(selection); else not_shared">
<span>{{ 'APP.ACTIONS.SHARE_EDIT' | translate }}</span>
</ng-container>
</button>
</ng-container>
<ng-container *ngIf="data.iconButton">
<button
mat-icon-button
data-automation-id="share-action-button"
(click)="editSharedNode(selection, '#share-action-button')"
[attr.aria-label]="getLabel(selection) | translate"
[attr.title]="getLabel(selection) | translate"
id="share-action-button"
>
<mat-icon>link</mat-icon>
</button>
</ng-container>
</ng-container>
<ng-template #not_shared>
<span>{{ 'APP.ACTIONS.SHARE' | translate }}</span>
</ng-template>

View File

@@ -0,0 +1,90 @@
/*!
* @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 { ToggleSharedComponent } from './toggle-shared.component';
import { of } from 'rxjs';
describe('ToggleSharedComponent', () => {
let component;
let entry;
const storeMock: any = {
select: () => of({ first: { entry } }),
dispatch: jasmine.createSpy('dispatch')
};
beforeEach(() => {
entry = {
properties: {
'qshare:sharedId': null
}
};
component = new ToggleSharedComponent(storeMock);
});
it('should get Store selection entry on initialization', (done) => {
component.ngOnInit();
component.selection$.subscribe((selection) => {
expect(selection.first.entry).toEqual(entry);
done();
});
});
it('should return false when entry is not shared', () => {
component.ngOnInit();
expect(component.isShared({ first: { entry } })).toBe(false);
});
it('should return true when entry is shared', () => {
entry.properties['qshare:sharedId'] = 'some-id';
component.ngOnInit();
expect(component.isShared({ first: { entry } })).toBe(true);
});
it('should dispatch `SHARE_NODE` action on share', () => {
component.ngOnInit();
component.editSharedNode({ first: { entry } });
expect(storeMock.dispatch).toHaveBeenCalled();
});
it('should get action label for unshared file', () => {
component.ngOnInit();
const label = component.getLabel({ first: { entry } });
expect(label).toBe('APP.ACTIONS.SHARE');
});
it('should get action label for shared file', () => {
entry.properties['qshare:sharedId'] = 'some-id';
component.ngOnInit();
const label = component.getLabel({ first: { entry } });
expect(label).toBe('APP.ACTIONS.SHARE_EDIT');
});
});

View File

@@ -0,0 +1,70 @@
/*!
* @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, OnInit, Input } from '@angular/core';
import { Observable } from 'rxjs';
import { Store } from '@ngrx/store';
import { SelectionState } from '@alfresco/adf-extensions';
import { AppStore, ShareNodeAction, getAppSelection } from '@alfresco/aca-shared/store';
@Component({
selector: 'app-toggle-shared',
templateUrl: './toggle-shared.component.html'
})
export class ToggleSharedComponent implements OnInit {
@Input()
data: {
iconButton?: string;
};
selection$: Observable<SelectionState>;
constructor(private store: Store<AppStore>) {}
ngOnInit() {
this.selection$ = this.store.select(getAppSelection);
}
isShared(selection: SelectionState) {
// workaround for shared files
if (selection.first && selection.first.entry && (selection.first.entry as any).sharedByUser) {
return true;
}
return selection.first && selection.first.entry && selection.first.entry.properties && !!selection.first.entry.properties['qshare:sharedId'];
}
editSharedNode(selection: SelectionState, focusedElementOnCloseSelector: string) {
this.store.dispatch(
new ShareNodeAction(selection.first, {
focusedElementOnCloseSelector
})
);
}
getLabel(selection: SelectionState): string {
return this.isShared(selection) ? 'APP.ACTIONS.SHARE_EDIT' : 'APP.ACTIONS.SHARE';
}
}