[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,72 @@
<aca-page-layout>
<aca-page-layout-header>
<adf-breadcrumb root="APP.BROWSE.FAVORITES.TITLE"> </adf-breadcrumb>
<adf-toolbar class="adf-toolbar--inline">
<ng-container *ngFor="let entry of actions; trackBy: trackByActionId">
<aca-toolbar-action [actionRef]="entry"></aca-toolbar-action>
</ng-container>
</adf-toolbar>
</aca-page-layout-header>
<aca-page-layout-content>
<div class="main-content">
<adf-document-list
#documentList
acaDocumentList
acaContextActions
[display]="documentDisplayMode$ | async"
currentFolderId="-favorites-"
selectionMode="multiple"
[navigate]="false"
[sorting]="['modifiedAt', 'desc']"
sortingMode="client"
[imageResolver]="imageResolver"
(node-dblclick)="handleNodeClick($event)"
(name-click)="handleNodeClick($event)"
>
<adf-custom-empty-content-template>
<adf-empty-content icon="star_rate" [title]="'APP.BROWSE.FAVORITES.EMPTY_STATE.TITLE'" subtitle="APP.BROWSE.FAVORITES.EMPTY_STATE.TEXT">
</adf-empty-content>
</adf-custom-empty-content-template>
<data-columns>
<ng-container *ngFor="let column of columns; trackBy: trackByColumnId">
<ng-container *ngIf="column.template && !(column.desktopOnly && isSmallScreen)">
<data-column
[key]="column.key"
[title]="column.title"
[type]="column.type"
[format]="column.format"
[class]="column.class"
[sortable]="column.sortable"
>
<ng-template let-context>
<adf-dynamic-column [id]="column.template" [context]="context"> </adf-dynamic-column>
</ng-template>
</data-column>
</ng-container>
<ng-container *ngIf="!column.template && !(column.desktopOnly && isSmallScreen)">
<data-column
[key]="column.key"
[title]="column.title"
[type]="column.type"
[format]="column.format"
[class]="column.class"
[sortable]="column.sortable"
>
</data-column>
</ng-container>
</ng-container>
</data-columns>
</adf-document-list>
<adf-pagination acaPagination [target]="documentList"> </adf-pagination>
</div>
<div class="sidebar" *ngIf="infoDrawerOpened$ | async">
<aca-info-drawer [node]="selection.last"></aca-info-drawer>
</div>
</aca-page-layout-content>
</aca-page-layout>

View File

@@ -0,0 +1,136 @@
/*!
* @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 { NO_ERRORS_SCHEMA } from '@angular/core';
import { Router } from '@angular/router';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { DataTableComponent, AppConfigModule } from '@alfresco/adf-core';
import { CustomResourcesService, DocumentListComponent, NodeFavoriteDirective } from '@alfresco/adf-content-services';
import { of } from 'rxjs';
import { FavoritesComponent } from './favorites.component';
import { AppTestingModule } from '../../testing/app-testing.module';
import { ContentApiService } from '@alfresco/aca-shared';
describe('FavoritesComponent', () => {
let fixture: ComponentFixture<FavoritesComponent>;
let component: FavoritesComponent;
let contentApi: ContentApiService;
let router: Router;
let node;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, AppConfigModule],
declarations: [DataTableComponent, NodeFavoriteDirective, DocumentListComponent, FavoritesComponent],
providers: [
{
provide: Router,
useValue: {
url: 'favorites',
navigate: () => {}
}
}
],
schemas: [NO_ERRORS_SCHEMA]
});
const page: any = {
list: {
entries: [{ entry: { id: 1, target: { file: {} } } }, { entry: { id: 2, target: { folder: {} } } }],
pagination: { data: 'data' }
}
};
node = {
id: 'folder-node',
isFolder: true,
isFile: false,
path: {
elements: []
}
};
fixture = TestBed.createComponent(FavoritesComponent);
component = fixture.componentInstance;
const customResourcesService = TestBed.inject(CustomResourcesService);
spyOn(customResourcesService, 'loadFavorites').and.returnValue(of(page));
contentApi = TestBed.inject(ContentApiService);
router = TestBed.inject(Router);
});
describe('Node navigation', () => {
beforeEach(() => {
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
spyOn(router, 'navigate').and.stub();
fixture.detectChanges();
});
it('navigates to `/libraries` if node path has `Sites`', () => {
node.path.elements = [{ name: 'Sites' }];
component.navigate(node);
expect(router.navigate).toHaveBeenCalledWith(['/libraries', 'folder-node']);
});
it('navigates to `/personal-files` if node path has no `Sites`', () => {
node.path.elements = [{ name: 'something else' }];
component.navigate(node);
expect(router.navigate).toHaveBeenCalledWith(['/personal-files', 'folder-node']);
});
it('does not navigate when node is not folder', () => {
node.isFolder = false;
component.navigate(node);
expect(router.navigate).not.toHaveBeenCalled();
});
});
it('should navigate if node is folder', () => {
const nodeEntity: any = { entry: { isFolder: true } };
spyOn(component, 'navigate').and.stub();
fixture.detectChanges();
component.onNodeDoubleClick(nodeEntity);
expect(component.navigate).toHaveBeenCalledWith(nodeEntity.entry);
});
it('should call showPreview if node is file', () => {
const nodeEntity: any = { entry: { isFile: true } };
spyOn(component, 'showPreview').and.stub();
fixture.detectChanges();
component.onNodeDoubleClick(nodeEntity);
expect(component.showPreview).toHaveBeenCalledWith(nodeEntity, {
location: 'favorites'
});
});
});

View File

@@ -0,0 +1,106 @@
/*!
* @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 { AppExtensionService, ContentApiService } from '@alfresco/aca-shared';
import { AppStore } from '@alfresco/aca-shared/store';
import { UploadService } from '@alfresco/adf-core';
import { MinimalNodeEntity, MinimalNodeEntryEntity, PathElementEntity, PathInfo } from '@alfresco/js-api';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { debounceTime, map } from 'rxjs/operators';
import { ContentManagementService } from '../../services/content-management.service';
import { PageComponent } from '../page.component';
import { DocumentListPresetRef } from '@alfresco/adf-extensions';
@Component({
templateUrl: './favorites.component.html'
})
export class FavoritesComponent extends PageComponent implements OnInit {
isSmallScreen = false;
columns: DocumentListPresetRef[] = [];
constructor(
private router: Router,
store: Store<AppStore>,
extensions: AppExtensionService,
private contentApi: ContentApiService,
content: ContentManagementService,
private uploadService: UploadService,
private breakpointObserver: BreakpointObserver
) {
super(store, extensions, content);
}
ngOnInit() {
super.ngOnInit();
this.subscriptions = this.subscriptions.concat([
this.uploadService.fileUploadComplete.pipe(debounceTime(300)).subscribe((_) => this.reload()),
this.uploadService.fileUploadDeleted.pipe(debounceTime(300)).subscribe((_) => this.reload()),
this.breakpointObserver.observe([Breakpoints.HandsetPortrait, Breakpoints.HandsetLandscape]).subscribe((result) => {
this.isSmallScreen = result.matches;
})
]);
this.columns = this.extensions.documentListPresets.favorites;
}
navigate(favorite: MinimalNodeEntryEntity) {
const { isFolder, id } = favorite;
// TODO: rework as it will fail on non-English setups
const isSitePath = (path: PathInfo): boolean => path && path.elements && path.elements.some(({ name }: PathElementEntity) => name === 'Sites');
if (isFolder) {
this.contentApi
.getNode(id)
.pipe(map((node) => node.entry))
.subscribe(({ path }: MinimalNodeEntryEntity) => {
const routeUrl = isSitePath(path) ? '/libraries' : '/personal-files';
this.router.navigate([routeUrl, id]);
});
}
}
onNodeDoubleClick(node: MinimalNodeEntity) {
if (node && node.entry) {
if (node.entry.isFolder) {
this.navigate(node.entry);
}
if (node.entry.isFile) {
this.showPreview(node, { location: this.router.url });
}
}
}
handleNodeClick(event: Event) {
this.onNodeDoubleClick((event as CustomEvent).detail?.node);
}
}