[ACA-92] Context Menu - share settings action (#699)

* context menu share settings action

* update cspell with 'qshare'

* share/edit share in viewer

* force change detection on children

* cleanup module declarations

* detection only for preview page

* assert properties

* cast to boolean
This commit is contained in:
Cilibiu Bogdan 2018-10-10 20:31:13 +03:00 committed by Denys Vuika
parent 8d28838de4
commit f44b3629e9
11 changed files with 262 additions and 30 deletions

View File

@ -34,6 +34,7 @@
"SOLR",
"unshare",
"qshare",
"validators",
"guid",
"polyfill",

View File

@ -54,6 +54,7 @@ import { DirectivesModule } from './directives/directives.module';
import { ContextMenuModule } from './components/context-menu/context-menu.module';
import { ExtensionsModule } from '@alfresco/adf-extensions';
import { AppToolbarModule } from './components/toolbar/toolbar.module';
import { AppSharedModule } from './components/shared/shared.module';
import { AppCreateMenuModule } from './components/create-menu/create-menu.module';
import { AppSidenavModule } from './components/sidenav/sidenav.module';
import { AppPermissionsModule } from './components/permissions/permissions.module';
@ -90,6 +91,7 @@ import { AppHeaderModule } from './components/header/header.module';
ContextMenuModule,
AppInfoDrawerModule,
AppToolbarModule,
AppSharedModule,
AppSidenavModule,
AppCreateMenuModule,
AppPermissionsModule,

View File

@ -0,0 +1,42 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2018 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 { CommonModule } from '@angular/common';
import { CoreModule } from '@alfresco/adf-core';
import { ContentNodeShareModule } from '@alfresco/adf-content-services';
import { ExtensionsModule } from '@alfresco/adf-extensions';
import { ToggleSharedModule } from './toggle-shared/toggle-shared.module';
@NgModule({
imports: [
CommonModule,
CoreModule.forChild(),
ExtensionsModule,
ContentNodeShareModule,
ToggleSharedModule
]
})
export class AppSharedModule {}

View File

@ -0,0 +1,12 @@
<ng-container *ngIf="selection$ | async as selection">
<button mat-menu-item data-automation-id="share-action-button" (click)="editSharedNode(selection)">
<mat-icon>share</mat-icon>
<ng-container *ngIf="isShared(selection); else not_shared">
<span>{{ 'APP.ACTIONS.CONTEXT_EDIT_SHARE' | translate }}</span>
</ng-container>
</button>
</ng-container>
<ng-template #not_shared>
<span>{{ 'APP.ACTIONS.SHARE' | translate }}</span>
</ng-template>

View File

@ -0,0 +1,75 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2018 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 = {
select: () => of({ first: { entry } }),
dispatch: jasmine.createSpy('dispatch')
};
beforeEach(() => {
entry = {
properties: {
'qshare:sharedId': null
}
};
component = new ToggleSharedComponent(<any>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();
});
});

View File

@ -0,0 +1,58 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2018 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 } from '@angular/core';
import { Observable } from 'rxjs';
import { Store } from '@ngrx/store';
import { AppStore } from '../../../store/states/app.state';
import { appSelection } from '../../../store/selectors/app.selectors';
import { SelectionState } from '@alfresco/adf-extensions';
import { ShareNodeAction } from '../../../store/actions';
@Component({
selector: 'app-toggle-shared',
templateUrl: './toggle-shared.component.html'
})
export class ToggleSharedComponent implements OnInit {
selection$: Observable<SelectionState>;
constructor(private store: Store<AppStore>) {}
ngOnInit() {
this.selection$ = this.store.select(appSelection);
}
isShared(selection) {
return (
selection.first.entry &&
selection.first.entry.properties &&
!!selection.first.entry.properties['qshare:sharedId']
);
}
editSharedNode(selection) {
this.store.dispatch(new ShareNodeAction(selection.first));
}
}

View File

@ -0,0 +1,48 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2018 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 { CommonModule } from '@angular/common';
import { CoreModule } from '@alfresco/adf-core';
import { ContentNodeShareModule } from '@alfresco/adf-content-services';
import { ExtensionsModule } from '@alfresco/adf-extensions';
import { ToggleSharedComponent } from './toggle-shared.component';
export function components() {
return [ToggleSharedComponent];
}
@NgModule({
imports: [
CommonModule,
CoreModule.forChild(),
ExtensionsModule,
ContentNodeShareModule
],
declarations: components(),
exports: components(),
entryComponents: components()
})
export class ToggleSharedModule {}

View File

@ -27,7 +27,9 @@ import {
Component,
ViewEncapsulation,
ChangeDetectionStrategy,
Input
Input,
DoCheck,
ChangeDetectorRef
} from '@angular/core';
import { ContentActionRef } from '@alfresco/adf-extensions';
@ -38,7 +40,7 @@ import { ContentActionRef } from '@alfresco/adf-extensions';
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'aca-toolbar-action' }
})
export class ToolbarActionComponent {
export class ToolbarActionComponent implements DoCheck {
@Input()
type = 'icon-button';
@ -47,4 +49,14 @@ export class ToolbarActionComponent {
@Input()
actionRef: ContentActionRef;
constructor(private cd: ChangeDetectorRef) {}
// todo: review after ADF 2.6
// preview component : change detection workaround for children without input
ngDoCheck() {
if (this.actionRef.id.includes('app.viewer')) {
this.cd.markForCheck();
}
}
}

View File

@ -33,6 +33,7 @@ import * as nav from './evaluators/navigation.evaluators';
import { AppExtensionService } from './extension.service';
import { ToggleInfoDrawerComponent } from '../components/toolbar/toggle-info-drawer/toggle-info-drawer.component';
import { ToggleFavoriteComponent } from '../components/toolbar/toggle-favorite/toggle-favorite.component';
import { ToggleSharedComponent } from '../components/shared/toggle-shared/toggle-shared.component';
import { MetadataTabComponent } from '../components/info-drawer/metadata-tab/metadata-tab.component';
import { CommentsTabComponent } from '../components/info-drawer/comments-tab/comments-tab.component';
import { VersionsTabComponent } from '../components/info-drawer/versions-tab/versions-tab.component';
@ -75,7 +76,8 @@ export class CoreExtensionsModule {
'app.components.tabs.comments': CommentsTabComponent,
'app.components.tabs.versions': VersionsTabComponent,
'app.toolbar.toggleInfoDrawer': ToggleInfoDrawerComponent,
'app.toolbar.toggleFavorite': ToggleFavoriteComponent
'app.toolbar.toggleFavorite': ToggleFavoriteComponent,
'app.shared-link.toggleSharedLink': ToggleSharedComponent
});
extensions.setAuthGuards({

View File

@ -420,28 +420,13 @@
},
{
"id": "app.toolbar.share",
"type": "custom",
"order": 600,
"title": "APP.ACTIONS.SHARE",
"icon": "share",
"actions": {
"click": "SHARE_NODE"
},
"component": "app.shared-link.toggleSharedLink",
"rules": {
"visible": "app.selection.file.canShare"
}
},
{
"id": "app.toolbar.unshare",
"order": 700,
"title": "APP.ACTIONS.UNSHARE",
"icon": "stop_screen_share",
"actions": {
"click": "UNSHARE_NODES"
},
"rules": {
"visible": "app.selection.canUnshare"
}
},
{
"id": "app.toolbar.delete",
"order": 800,
@ -532,12 +517,9 @@
},
{
"id": "app.context.menu.share",
"title": "APP.ACTIONS.SHARE",
"type": "custom",
"order": 400,
"icon": "share",
"actions": {
"click": "SHARE_NODE"
},
"component": "app.shared-link.toggleSharedLink",
"rules": {
"visible": "app.selection.file.canShare"
}
@ -749,12 +731,9 @@
},
{
"id": "app.viewer.share",
"type": "custom",
"order": 300,
"title": "APP.ACTIONS.SHARE",
"icon": "share",
"actions": {
"click": "SHARE_NODE"
},
"component": "app.shared-link.toggleSharedLink",
"rules": {
"visible": "app.selection.file.canShare"
}

View File

@ -131,6 +131,7 @@
"VERSIONS": "Manage Versions",
"TOGGLE-SIDENAV": "Toggle side navigation bar",
"SHARE": "Share",
"CONTEXT_EDIT_SHARE": "Shared link settings",
"PRINT": "Print",
"FULLSCREEN": "Activate full-screen mode"
},