[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,9 @@
<ng-container *ngIf="sharedLinkId">
<adf-viewer [allowPrint]="false" [allowDownload]="false" [allowFullScreen]="false" [sharedLinkId]="sharedLinkId" [allowGoBack]="false">
<adf-viewer-toolbar-actions>
<ng-container *ngFor="let action of viewerToolbarActions; trackBy: trackByActionId">
<aca-toolbar-action [actionRef]="action"></aca-toolbar-action>
</ng-container>
</adf-viewer-toolbar-actions>
</adf-viewer>
</ng-container>

View File

@@ -0,0 +1,8 @@
.app-shared-link-view {
width: 100%;
height: 100%;
.adf-viewer-toolbar .adf-toolbar-divider {
display: none;
}
}

View File

@@ -0,0 +1,134 @@
/*!
* @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 { SharedLinkViewComponent } from './shared-link-view.component';
import { TestBed, ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
import { Store } from '@ngrx/store';
import { AppTestingModule } from '../../testing/app-testing.module';
import { ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { SetSelectedNodesAction } from '@alfresco/aca-shared/store';
import { AppExtensionService } from '@alfresco/aca-shared';
describe('SharedLinkViewComponent', () => {
let component: SharedLinkViewComponent;
let fixture: ComponentFixture<SharedLinkViewComponent>;
let appExtensionService: AppExtensionService;
let spyGetSharedLink;
const storeMock = {
dispatch: jasmine.createSpy('dispatch'),
select: () => of({})
};
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule],
declarations: [SharedLinkViewComponent],
providers: [
AppExtensionService,
{ provide: Store, useValue: storeMock },
{
provide: ActivatedRoute,
useValue: {
snapshot: { data: { preferencePrefix: 'prefix' } },
params: of({ id: '123' })
}
}
],
schemas: [NO_ERRORS_SCHEMA]
});
fixture = TestBed.createComponent(SharedLinkViewComponent);
component = fixture.componentInstance;
appExtensionService = TestBed.inject(AppExtensionService);
appExtensionService.selection = {
isEmpty: true,
count: 0,
libraries: null,
nodes: null
};
spyGetSharedLink = spyOn(component['sharedLinksApi'], 'getSharedLink');
storeMock.dispatch.calls.reset();
});
afterEach(() => {
spyGetSharedLink.calls.reset();
});
it('should update store selection', fakeAsync(() => {
spyGetSharedLink.and.returnValue(Promise.resolve({ entry: { id: 'shared-id' } }));
fixture.detectChanges();
tick();
expect(storeMock.dispatch).toHaveBeenCalledWith(new SetSelectedNodesAction([{ entry: { id: 'shared-id' } } as any]));
}));
it('should not update store on error', fakeAsync(() => {
spyGetSharedLink.and.returnValue(Promise.reject('error'));
fixture.detectChanges();
tick();
expect(storeMock.dispatch).not.toHaveBeenCalled();
}));
it('should not update actions reference if selection is empty', fakeAsync(() => {
spyGetSharedLink.and.returnValue(Promise.resolve({ entry: { id: 'shared-id' } }));
fixture.detectChanges();
tick();
expect(component.viewerToolbarActions).toEqual([]);
}));
it('should update actions reference if selection is not empty', fakeAsync(() => {
appExtensionService.selection = {
isEmpty: false,
count: 1,
libraries: null,
nodes: null
};
spyOn(appExtensionService, 'getSharedLinkViewerToolbarActions').and.callThrough();
spyGetSharedLink.and.returnValue(Promise.resolve({ entry: { id: 'shared-id' } }));
fixture.detectChanges();
tick();
expect(appExtensionService.getSharedLinkViewerToolbarActions).toHaveBeenCalled();
}));
it('should fetch link id from the active route', fakeAsync(() => {
spyGetSharedLink.and.returnValue(Promise.resolve({ entry: { id: 'shared-id' } }));
fixture.detectChanges();
tick();
expect(component.sharedLinkId).toBe('123');
}));
});

View File

@@ -0,0 +1,89 @@
/*!
* @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 { AppStore, SetSelectedNodesAction } from '@alfresco/aca-shared/store';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { ContentActionRef } from '@alfresco/adf-extensions';
import { SharedLinkEntry, SharedlinksApi } from '@alfresco/js-api';
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Store } from '@ngrx/store';
import { forkJoin, from, of, Subject } from 'rxjs';
import { catchError, mergeMap, takeUntil } from 'rxjs/operators';
import { AppExtensionService } from '@alfresco/aca-shared';
@Component({
selector: 'app-shared-link-view',
templateUrl: './shared-link-view.component.html',
styleUrls: ['shared-link-view.component.scss'],
encapsulation: ViewEncapsulation.None,
host: { class: 'app-shared-link-view' }
})
export class SharedLinkViewComponent implements OnInit, OnDestroy {
private onDestroy$: Subject<boolean> = new Subject<boolean>();
private sharedLinksApi: SharedlinksApi;
sharedLinkId: string = null;
viewerToolbarActions: Array<ContentActionRef> = [];
constructor(
private route: ActivatedRoute,
private store: Store<AppStore>,
private extensions: AppExtensionService,
private alfrescoApiService: AlfrescoApiService
) {
this.sharedLinksApi = new SharedlinksApi(this.alfrescoApiService.getInstance());
}
ngOnInit() {
this.route.params
.pipe(
mergeMap((params) =>
forkJoin([from(this.sharedLinksApi.getSharedLink(params.id)), of(params.id)]).pipe(catchError(() => of([null, params.id])))
)
)
.subscribe(([sharedEntry, sharedId]: [SharedLinkEntry, string]) => {
if (sharedEntry) {
this.store.dispatch(new SetSelectedNodesAction([sharedEntry as any]));
}
this.sharedLinkId = sharedId;
});
this.extensions
.getSharedLinkViewerToolbarActions()
.pipe(takeUntil(this.onDestroy$))
.subscribe((actions) => {
this.viewerToolbarActions = actions;
});
}
ngOnDestroy() {
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
trackByActionId(_: number, action: ContentActionRef) {
return action.id;
}
}

View File

@@ -0,0 +1,61 @@
/*!
* @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 { NgModule } from '@angular/core';
import { SharedLinkViewComponent } from './shared-link-view.component';
import { CommonModule } from '@angular/common';
import { CoreModule } from '@alfresco/adf-core';
import { RouterModule, Routes } from '@angular/router';
import { DirectivesModule } from '../../directives/directives.module';
import { AppCommonModule } from '../common/common.module';
import { AppToolbarModule } from '../toolbar/toolbar.module';
import { AppInfoDrawerModule } from '../info-drawer/info.drawer.module';
import { CoreExtensionsModule } from '../../extensions/core.extensions.module';
const routes: Routes = [
{
path: '',
component: SharedLinkViewComponent,
data: {
title: 'APP.PREVIEW.TITLE'
}
}
];
@NgModule({
imports: [
CommonModule,
CoreModule.forChild(),
RouterModule.forChild(routes),
DirectivesModule,
AppCommonModule,
AppToolbarModule,
CoreExtensionsModule.forChild(),
AppInfoDrawerModule
],
declarations: [SharedLinkViewComponent],
exports: [SharedLinkViewComponent]
})
export class AppSharedLinkViewModule {}