Skip to content

Commit

Permalink
[ACA-2216] Shared link preview - use extension actions (#964)
Browse files Browse the repository at this point in the history
* isSharedFileViewer evaluator

* navigation evaluators tests

* update docs

* fallback for SharedLink entry

* shared link view use extensions

* rules for link shared view actions

* dedicated extension definition for shared link action toolbar

* resolve selection and actions

* update tests

* remove un used imports

* nest shared link viewer toolbar actions in to viewer structure
  • Loading branch information
pionnegru authored and DenysVuika committed Feb 24, 2019
1 parent 88ca0cb commit 525ba7e
Show file tree
Hide file tree
Showing 12 changed files with 582 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/extending/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ for example mixing `core.every` and `core.not`.
| app.navigation.isNotSearchResults | Current page is not the **Search Results**. |
| app.navigation.isSharedPreview | Current page is preview **Shared Files** |
| app.navigation.isFavoritesPreview | Current page is preview **Favorites** |
| app.navigation.isSharedFileViewer | Current page is shared file preview page |

**Tip:** See the [Registration](/extending/registration) section for more details
on how to register your own entries to be re-used at runtime.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
<ng-container *ngIf="sharedLinkId">
<adf-viewer [sharedLinkId]="sharedLinkId" [allowGoBack]="false"> </adf-viewer>
<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>
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,47 @@
*/

import { SharedLinkViewComponent } from './shared-link-view.component';
import { TestBed, ComponentFixture } from '@angular/core/testing';
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 { AlfrescoApiService } from '@alfresco/adf-core';
import { SetSelectedNodesAction } from '../../store/actions';
import { AppExtensionService } from '../../extensions/extension.service';

describe('SharedLinkViewComponent', () => {
let component: SharedLinkViewComponent;
let fixture: ComponentFixture<SharedLinkViewComponent>;
let alfrescoApiService: AlfrescoApiService;
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: AlfrescoApiService,
useValue: {
sharedLinksApi: {
getSharedLink: () => {}
}
}
},
{
provide: ActivatedRoute,
useValue: {
Expand All @@ -52,11 +78,79 @@ describe('SharedLinkViewComponent', () => {

fixture = TestBed.createComponent(SharedLinkViewComponent);
component = fixture.componentInstance;
alfrescoApiService = TestBed.get(AlfrescoApiService);
appExtensionService = TestBed.get(AppExtensionService);

fixture.detectChanges();
spyGetSharedLink = spyOn(
alfrescoApiService.sharedLinksApi,
'getSharedLink'
);

storeMock.dispatch.calls.reset();
});

it('should fetch link id from the active route', () => {
expect(component.sharedLinkId).toBe('123');
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([<any>{ entry: { id: 'shared-id' } }])
);
}));

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(() => {
spyOn(storeMock, 'select').and.returnValue(of({ isEmpty: true }));

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(() => {
spyOn(storeMock, 'select').and.returnValue(of({ isEmpty: false }));
spyOn(appExtensionService, 'getSharedLinkViewerToolbarActions');
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');
}));
});
45 changes: 42 additions & 3 deletions src/app/components/shared-link-view/shared-link-view.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { Component, ViewEncapsulation, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ContentActionRef } from '@alfresco/adf-extensions';
import { AppExtensionService } from '../../extensions/extension.service';
import { Store } from '@ngrx/store';
import { AppStore } from '../../store/states/app.state';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { SharedLinkEntry } from '@alfresco/js-api';
import { SetSelectedNodesAction } from '../../store/actions';
import { flatMap, catchError } from 'rxjs/operators';
import { forkJoin, of, from } from 'rxjs';
import { appSelection } from '../../store/selectors/app.selectors';

@Component({
selector: 'app-shared-link-view',
Expand All @@ -10,12 +20,41 @@ import { ActivatedRoute } from '@angular/router';
})
export class SharedLinkViewComponent implements OnInit {
sharedLinkId: string = null;
viewerToolbarActions: Array<ContentActionRef> = [];

constructor(private route: ActivatedRoute) {}
constructor(
private route: ActivatedRoute,
private store: Store<AppStore>,
private extensions: AppExtensionService,
private alfrescoApiService: AlfrescoApiService
) {}

ngOnInit() {
this.route.params.subscribe(params => {
this.sharedLinkId = params.id;
this.route.params
.pipe(
flatMap(params =>
forkJoin(
from(
this.alfrescoApiService.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([<any>sharedEntry]));
}
this.sharedLinkId = sharedId;
});

this.store.select(appSelection).subscribe(selection => {
if (!selection.isEmpty)
this.viewerToolbarActions = this.extensions.getSharedLinkViewerToolbarActions();
});
}

trackByActionId(index: number, action: ContentActionRef) {
return action.id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ 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 = [
{
Expand All @@ -51,6 +52,7 @@ const routes: Routes = [
DirectivesModule,
AppCommonModule,
AppToolbarModule,
CoreExtensionsModule.forChild(),
AppInfoDrawerModule
],
declarations: [SharedLinkViewComponent],
Expand Down
1 change: 1 addition & 0 deletions src/app/extensions/core.extensions.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export class CoreExtensionsModule {
'app.navigation.isPreview': nav.isPreview,
'app.navigation.isSharedPreview': nav.isSharedPreview,
'app.navigation.isFavoritesPreview': nav.isFavoritesPreview,
'app.navigation.isSharedFileViewer': nav.isSharedFileViewer,

'repository.isQuickShareEnabled': repository.hasQuickShareEnabled
});
Expand Down
Loading

0 comments on commit 525ba7e

Please sign in to comment.