[AAE-11496] Make aca-shared buildable (#2916)

This commit is contained in:
Bartosz Sekuła
2023-01-24 20:36:26 +01:00
committed by GitHub
parent 113b5a89e7
commit 87c1c2b5df
18 changed files with 124 additions and 41 deletions

View File

@@ -44,7 +44,7 @@ import {
LibraryStatusColumnComponent,
TrashcanNameColumnComponent
} from '@alfresco/adf-content-services';
import { ExtensionsDataLoaderGuard, RouterExtensionService, SharedModule } from '@alfresco/aca-shared';
import { DocumentBasePageService, ExtensionsDataLoaderGuard, RouterExtensionService, SharedModule } from '@alfresco/aca-shared';
import * as rules from '@alfresco/aca-shared/rules';
import { FilesComponent } from './components/files/files.component';
@@ -181,6 +181,7 @@ registerLocaleData(localeSv);
providers: [
{ provide: AppConfigService, useClass: DebugAppConfigService },
{ provide: ContentVersionService, useClass: ContentUrlService },
{ provide: DocumentBasePageService, useExisting: ContentVersionService },
{
provide: TRANSLATION_PROVIDER,
multi: true,

View File

@@ -25,8 +25,7 @@
import { Component, OnInit, ViewEncapsulation, OnDestroy } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { PageComponent } from '../page.component';
import { AppExtensionService, ContentApiService } from '@alfresco/aca-shared';
import { AppExtensionService, ContentApiService, PageComponent } from '@alfresco/aca-shared';
import { AppStore, NavigateToPreviousPage, SetSelectedNodesAction } from '@alfresco/aca-shared/store';
import { Store } from '@ngrx/store';
import { ContentManagementService } from '../../services/content-management.service';

View File

@@ -28,9 +28,8 @@ import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import { Store } from '@ngrx/store';
import { SiteEntry, FavoritePaging, Pagination } from '@alfresco/js-api';
import { ContentManagementService } from '../../services/content-management.service';
import { AppExtensionService, AppHookService, ContentApiService } from '@alfresco/aca-shared';
import { AppExtensionService, AppHookService, ContentApiService, PageComponent } from '@alfresco/aca-shared';
import { NavigateLibraryAction } from '@alfresco/aca-shared/store';
import { PageComponent } from '../page.component';
import { UserPreferencesService } from '@alfresco/adf-core';
import { DocumentListPresetRef } from '@alfresco/adf-extensions';

View File

@@ -23,7 +23,7 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { AppExtensionService, ContentApiService } from '@alfresco/aca-shared';
import { AppExtensionService, ContentApiService, PageComponent } 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';
@@ -33,7 +33,6 @@ 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({

View File

@@ -30,8 +30,7 @@ import { Store } from '@ngrx/store';
import { MinimalNodeEntity, MinimalNodeEntryEntity, PathElement, PathElementEntity } from '@alfresco/js-api';
import { ContentManagementService } from '../../services/content-management.service';
import { NodeActionsService } from '../../services/node-actions.service';
import { PageComponent } from '../page.component';
import { AppExtensionService, ContentApiService } from '@alfresco/aca-shared';
import { AppExtensionService, ContentApiService, PageComponent } from '@alfresco/aca-shared';
import { SetCurrentFolderAction, isAdmin, AppStore, UploadFileVersionAction, showLoaderSelector } from '@alfresco/aca-shared/store';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { debounceTime, takeUntil } from 'rxjs/operators';

View File

@@ -29,8 +29,7 @@ import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { Component, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';
import { ContentManagementService } from '../../services/content-management.service';
import { PageComponent } from '../page.component';
import { AppExtensionService, AppHookService } from '@alfresco/aca-shared';
import { AppExtensionService, AppHookService, PageComponent } from '@alfresco/aca-shared';
import { DocumentListPresetRef } from '@alfresco/adf-extensions';
@Component({

View File

@@ -1,268 +0,0 @@
/*!
* @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 { PageComponent } from './page.component';
import { ReloadDocumentListAction, SetSelectedNodesAction, AppState, AppStore, ViewNodeAction } from '@alfresco/aca-shared/store';
import { AppExtensionService } from '@alfresco/aca-shared';
import { MinimalNodeEntity, NodePaging } from '@alfresco/js-api';
import { ContentManagementService } from '../services/content-management.service';
import { EffectsModule } from '@ngrx/effects';
import { ViewerEffects } from '../store/effects';
import { Store } from '@ngrx/store';
import { AppTestingModule } from '../testing/app-testing.module';
import { Component } from '@angular/core';
import { DocumentListComponent } from '@alfresco/adf-content-services';
import { MockStore, provideMockStore } from '@ngrx/store/testing';
@Component({
selector: 'aca-test',
template: ''
})
class TestComponent extends PageComponent {
node: any;
constructor(store: Store<AppStore>, extensions: AppExtensionService, content: ContentManagementService) {
super(store, extensions, content);
}
}
describe('PageComponent', () => {
let component: TestComponent;
let store: Store<AppState>;
let fixture: ComponentFixture<TestComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, EffectsModule.forRoot([ViewerEffects])],
declarations: [TestComponent],
providers: [ContentManagementService, AppExtensionService]
});
store = TestBed.inject(Store);
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
});
afterEach(() => {
fixture.destroy();
});
describe('getParentNodeId()', () => {
it('returns parent node id when node is set', () => {
component.node = { id: 'node-id' };
expect(component.getParentNodeId()).toBe('node-id');
});
it('returns null when node is not set', () => {
component.node = null;
expect(component.getParentNodeId()).toBe(null);
});
});
describe('Reload', () => {
const locationHref = location.href;
afterEach(() => {
window.history.pushState({}, null, locationHref);
});
it('should not reload if url contains viewer outlet', () => {
window.history.pushState({}, null, `${locationHref}#test(viewer:view)`);
spyOn(store, 'dispatch');
component.reload();
expect(store.dispatch).not.toHaveBeenCalled();
});
it('should reload if url does not contain viewer outlet', () => {
spyOn(store, 'dispatch');
component.reload();
expect(store.dispatch).toHaveBeenCalledWith(new ReloadDocumentListAction());
});
it('should set selection after reload if node is passed', () => {
const node = {
entry: {
id: 'node-id'
}
} as MinimalNodeEntity;
spyOn(store, 'dispatch');
component.reload(node);
expect(store.dispatch['calls'].mostRecent().args[0]).toEqual(new SetSelectedNodesAction([node]));
});
it('should clear results onAllFilterCleared event', () => {
component.documentList = {
node: {
list: {
pagination: {},
entries: [{ entry: { id: 'new-node-id' } }]
}
} as NodePaging
} as DocumentListComponent;
spyOn(store, 'dispatch');
component.onAllFilterCleared();
expect(component.documentList.node).toBe(null);
expect(store.dispatch['calls'].mostRecent().args[0]).toEqual(new ReloadDocumentListAction());
});
it('should call onAllFilterCleared event if page is viewer outlet', () => {
window.history.pushState({}, null, `${locationHref}#test(viewer:view)`);
const nodePaging = {
list: {
pagination: {},
entries: [{ entry: { id: 'new-node-id' } }]
}
} as NodePaging;
component.documentList = { node: nodePaging } as DocumentListComponent;
spyOn(store, 'dispatch');
component.onAllFilterCleared();
expect(component.documentList.node).toEqual(nodePaging);
expect(store.dispatch).not.toHaveBeenCalled();
});
it('should call ViewNodeAction on showPreview for selected node', () => {
spyOn(store, 'dispatch');
const node = {
entry: {
id: 'node-id'
}
} as MinimalNodeEntity;
component.showPreview(node);
expect(store.dispatch).toHaveBeenCalledWith(new ViewNodeAction(node.entry.id));
});
it('should call ViewNodeAction on showPreview for `app:filelink` node type', () => {
spyOn(store, 'dispatch');
const linkNode = {
entry: {
id: 'node-id',
nodeType: 'app:filelink',
properties: {
'cm:destination': 'original-node-id'
}
}
} as MinimalNodeEntity;
component.showPreview(linkNode);
const id = linkNode.entry.properties['cm:destination'];
expect(store.dispatch).toHaveBeenCalledWith(new ViewNodeAction(id));
});
});
});
describe('Info Drawer state', () => {
let component: TestComponent;
let fixture: ComponentFixture<TestComponent>;
let store: MockStore<{ app: Partial<AppState> }>;
let appState: Partial<AppState> = {};
beforeEach(() => {
appState = {
selection: {
count: 2,
isEmpty: false,
libraries: [],
nodes: []
},
navigation: {},
infoDrawerOpened: false
};
TestBed.configureTestingModule({
imports: [AppTestingModule, EffectsModule.forRoot([ViewerEffects])],
declarations: [TestComponent],
providers: [
ContentManagementService,
AppExtensionService,
provideMockStore({
initialState: { app: appState }
})
]
});
store = TestBed.inject(MockStore);
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
});
afterEach(() => {
fixture.destroy();
});
const locationHref = location.href;
afterEach(() => {
window.history.pushState({}, null, locationHref);
});
it('should open info drawer on action event', (done) => {
window.history.pushState({}, null, `${locationHref}#test`);
fixture.detectChanges();
fixture.whenStable().then(() => {
component.infoDrawerOpened$.subscribe((state) => {
expect(state).toBe(true);
done();
});
});
store.setState({
app: {
...appState,
infoDrawerOpened: true
}
});
});
it('should not open info drawer if viewer outlet is active', (done) => {
window.history.pushState({}, null, `${locationHref}#test(viewer:view)`);
fixture.detectChanges();
fixture.whenStable().then(() => {
component.infoDrawerOpened$.subscribe((state) => {
expect(state).toBe(false);
done();
});
});
store.setState({
app: {
...appState,
infoDrawerOpened: true
}
});
});
});

View File

@@ -1,193 +0,0 @@
/*!
* @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 { DocumentListComponent, ShareDataRow } from '@alfresco/adf-content-services';
import { ShowHeaderMode } from '@alfresco/adf-core';
import { ContentActionRef, DocumentListPresetRef, SelectionState } from '@alfresco/adf-extensions';
import { OnDestroy, OnInit, OnChanges, ViewChild, SimpleChanges, Directive } from '@angular/core';
import { Store } from '@ngrx/store';
import { MinimalNodeEntity, MinimalNodeEntryEntity, NodePaging } from '@alfresco/js-api';
import { Observable, Subject, Subscription } from 'rxjs';
import { takeUntil, map } from 'rxjs/operators';
import { ContentManagementService } from '../services/content-management.service';
import {
AppStore,
ReloadDocumentListAction,
getCurrentFolder,
getAppSelection,
getDocumentDisplayMode,
isInfoDrawerOpened,
getSharedUrl,
ViewNodeAction,
ViewNodeExtras,
SetSelectedNodesAction
} from '@alfresco/aca-shared/store';
import { isLocked, isLibrary, AppExtensionService } from '@alfresco/aca-shared';
/* eslint-disable @angular-eslint/directive-class-suffix */
@Directive()
export abstract class PageComponent implements OnInit, OnDestroy, OnChanges {
onDestroy$: Subject<boolean> = new Subject<boolean>();
@ViewChild(DocumentListComponent)
documentList: DocumentListComponent;
title = 'Page';
infoDrawerOpened$: Observable<boolean>;
node: MinimalNodeEntryEntity;
selection: SelectionState;
documentDisplayMode$: Observable<string>;
sharedPreviewUrl$: Observable<string>;
actions: Array<ContentActionRef> = [];
viewerToolbarActions: Array<ContentActionRef> = [];
canUpdateNode = false;
canUpload = false;
nodeResult: NodePaging;
showHeader = ShowHeaderMode.Data;
filterSorting = 'name-asc';
protected subscriptions: Subscription[] = [];
protected constructor(protected store: Store<AppStore>, protected extensions: AppExtensionService, protected content: ContentManagementService) {}
ngOnInit() {
this.sharedPreviewUrl$ = this.store.select(getSharedUrl);
this.infoDrawerOpened$ = this.store.select(isInfoDrawerOpened).pipe(map((infoDrawerState) => !this.isOutletPreviewUrl() && infoDrawerState));
this.documentDisplayMode$ = this.store.select(getDocumentDisplayMode);
this.store
.select(getAppSelection)
.pipe(takeUntil(this.onDestroy$))
.subscribe((selection) => {
this.selection = selection;
this.canUpdateNode = this.selection.count === 1 && this.content.canUpdateNode(selection.first);
});
this.extensions
.getAllowedToolbarActions()
.pipe(takeUntil(this.onDestroy$))
.subscribe((actions) => {
this.actions = actions;
});
this.extensions
.getViewerToolbarActions()
.pipe(takeUntil(this.onDestroy$))
.subscribe((actions) => {
this.viewerToolbarActions = actions;
});
this.store
.select(getCurrentFolder)
.pipe(takeUntil(this.onDestroy$))
.subscribe((node) => {
this.canUpload = node && this.content.canUploadContent(node);
});
}
ngOnChanges(changes: SimpleChanges) {
if (changes.nodeResult && changes.nodeResult.currentValue) {
this.nodeResult = changes.nodeResult.currentValue;
}
}
ngOnDestroy() {
this.subscriptions.forEach((subscription) => subscription.unsubscribe());
this.subscriptions = [];
this.onDestroy$.next(true);
this.onDestroy$.complete();
this.store.dispatch(new SetSelectedNodesAction([]));
}
showPreview(node: MinimalNodeEntity, extras?: ViewNodeExtras) {
if (node && node.entry) {
let id: string;
if (node.entry.nodeType === 'app:filelink') {
id = node.entry.properties['cm:destination'];
} else {
id = (node as any).entry.nodeId || (node as any).entry.guid || node.entry.id;
}
this.store.dispatch(new ViewNodeAction(id, extras));
}
}
getParentNodeId(): string {
return this.node ? this.node.id : null;
}
imageResolver(row: ShareDataRow): string | null {
if (isLocked(row.node)) {
return 'assets/images/baseline-lock-24px.svg';
}
if (isLibrary(row.node)) {
return 'assets/images/baseline-library_books-24px.svg';
}
return null;
}
reload(selectedNode?: MinimalNodeEntity): void {
if (this.isOutletPreviewUrl()) {
return;
}
this.store.dispatch(new ReloadDocumentListAction());
if (selectedNode) {
this.store.dispatch(new SetSelectedNodesAction([selectedNode]));
}
}
trackByActionId(_: number, action: ContentActionRef) {
return action.id;
}
trackById(_: number, obj: { id: string }) {
return obj.id;
}
trackByColumnId(_: number, obj: DocumentListPresetRef): string {
return obj.id;
}
private isOutletPreviewUrl(): boolean {
return location.href.includes('viewer:view');
}
onSortingChanged(event) {
this.filterSorting = event.detail.key + '-' + event.detail.direction;
}
onAllFilterCleared() {
if (!this.isOutletPreviewUrl()) {
this.documentList.node = null;
this.store.dispatch(new ReloadDocumentListAction());
}
}
}

View File

@@ -30,8 +30,7 @@ import { debounceTime, map, takeUntil } from 'rxjs/operators';
import { UserPreferencesService, ObjectUtils, UploadService, NodesApiService } from '@alfresco/adf-core';
import { Store } from '@ngrx/store';
import { AppStore, ClosePreviewAction, ViewerActionTypes, SetSelectedNodesAction } from '@alfresco/aca-shared/store';
import { PageComponent } from '../page.component';
import { AppExtensionService, AppHookService, ContentApiService } from '@alfresco/aca-shared';
import { AppExtensionService, AppHookService, ContentApiService, PageComponent } from '@alfresco/aca-shared';
import { ContentManagementService } from '../../services/content-management.service';
import { ContentActionRef, ViewerExtensionRef } from '@alfresco/adf-extensions';
import { SearchRequest } from '@alfresco/js-api';

View File

@@ -27,13 +27,12 @@ import { Component, OnInit } from '@angular/core';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { MinimalNodeEntity } from '@alfresco/js-api';
import { ContentManagementService } from '../../services/content-management.service';
import { PageComponent } from '../page.component';
import { Store } from '@ngrx/store';
import { AppStore } from '@alfresco/aca-shared/store';
import { UploadService } from '@alfresco/adf-core';
import { debounceTime } from 'rxjs/operators';
import { Router } from '@angular/router';
import { AppExtensionService } from '@alfresco/aca-shared';
import { AppExtensionService, PageComponent } from '@alfresco/aca-shared';
import { DocumentListPresetRef } from '@alfresco/adf-extensions';
@Component({

View File

@@ -30,9 +30,8 @@ import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { Store } from '@ngrx/store';
import { ContentManagementService } from '../../../services/content-management.service';
import { PageComponent } from '../../page.component';
import { SearchLibrariesQueryBuilderService } from './search-libraries-query-builder.service';
import { AppExtensionService, AppHookService } from '@alfresco/aca-shared';
import { AppExtensionService, AppHookService, PageComponent } from '@alfresco/aca-shared';
import { DocumentListPresetRef } from '@alfresco/adf-extensions';
@Component({

View File

@@ -27,7 +27,6 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { MinimalNodeEntity, Pagination, ResultSetPaging } from '@alfresco/js-api';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { SearchQueryBuilderService } from '@alfresco/adf-content-services';
import { PageComponent } from '../../page.component';
import { Store } from '@ngrx/store';
import {
AppStore,
@@ -42,7 +41,7 @@ import {
import { ContentManagementService } from '../../../services/content-management.service';
import { TranslationService } from '@alfresco/adf-core';
import { combineLatest, Observable } from 'rxjs';
import { AppExtensionService } from '@alfresco/aca-shared';
import { AppExtensionService, PageComponent } from '@alfresco/aca-shared';
import { SearchSortingDefinition } from '@alfresco/adf-content-services/lib/search/models/search-sorting-definition.interface';
import { takeUntil } from 'rxjs/operators';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';

View File

@@ -26,13 +26,12 @@
import { Component, OnInit } from '@angular/core';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { ContentManagementService } from '../../services/content-management.service';
import { PageComponent } from '../page.component';
import { Store } from '@ngrx/store';
import { debounceTime } from 'rxjs/operators';
import { UploadService } from '@alfresco/adf-core';
import { Router } from '@angular/router';
import { MinimalNodeEntity } from '@alfresco/js-api';
import { AppExtensionService, AppHookService } from '@alfresco/aca-shared';
import { AppExtensionService, AppHookService, PageComponent } from '@alfresco/aca-shared';
import { DocumentListPresetRef } from '@alfresco/adf-extensions';
@Component({

View File

@@ -30,8 +30,7 @@ import { Component, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs';
import { ContentManagementService } from '../../services/content-management.service';
import { PageComponent } from '../page.component';
import { AppExtensionService } from '@alfresco/aca-shared';
import { AppExtensionService, PageComponent } from '@alfresco/aca-shared';
@Component({
templateUrl: './trashcan.component.html'