mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-3530, ADF-3598] Sharing files (#3828)
* share node * lint fix * createSharedLinks parameter * remove es6 async * use fakeAsync * removed trailing comma * e2e update dialog title locator * Expires label localization * docs update
This commit is contained in:
committed by
Eugenio Romano
parent
b34ca87657
commit
42f4bee2b4
@@ -0,0 +1,50 @@
|
||||
<div class="adf-share-link__dialog-content">
|
||||
<h1 data-automation-id="adf-share-dialog-title"
|
||||
class="adf-share-link__title">
|
||||
{{ 'SHARE.DIALOG-TITLE' | translate }} {{ fileName }}
|
||||
</h1>
|
||||
|
||||
<mat-dialog-content>
|
||||
<p class="adf-share-link__info">{{ 'SHARE.DESCRIPTION' | translate }}</p>
|
||||
|
||||
<div class="adf-share-link--row">
|
||||
<h1 class="adf-share-link__label">{{ 'SHARE.TITLE' | translate }}</h1>
|
||||
|
||||
<mat-slide-toggle
|
||||
color="primary"
|
||||
id="adf-share-toggle"
|
||||
[checked]="isFileShared"
|
||||
[disabled]="!canUpdate || isDisabled"
|
||||
(change)="onSlideShareChange($event)">
|
||||
</mat-slide-toggle>
|
||||
</div>
|
||||
|
||||
<form [formGroup]="form">
|
||||
<mat-form-field class="full-width">
|
||||
<input #sharedLinkInput
|
||||
data-automation-id="adf-share-link"
|
||||
class="adf-share-link__input"
|
||||
matInput
|
||||
cdkFocusInitial
|
||||
placeholder="{{ 'SHARE.PUBLIC-LINK' | translate }}"
|
||||
formControlName="sharedUrl">
|
||||
<mat-icon class="input-action" matSuffix
|
||||
[clipboard-notification]="'SHARE.CLIPBOARD-MESSAGE' | translate"
|
||||
[adf-clipboard]="sharedLinkInput">
|
||||
link
|
||||
</mat-icon>
|
||||
</mat-form-field>
|
||||
|
||||
<h1 class="adf-share-link__label">{{ 'SHARE.EXPIRES' | translate }}</h1>
|
||||
<mat-form-field class="full-width">
|
||||
<mat-datetimepicker-toggle [for]="datetimePicker" matSuffix></mat-datetimepicker-toggle>
|
||||
<mat-datetimepicker #datetimePicker type="datetime" openOnFocus="true" timeInterval="1"></mat-datetimepicker>
|
||||
<input class="adf-share-link__input"
|
||||
matInput
|
||||
[min]="minDate"
|
||||
formControlName="time"
|
||||
[matDatetimepicker]="datetimePicker">
|
||||
</mat-form-field>
|
||||
</form>
|
||||
</mat-dialog-content>
|
||||
</div>
|
@@ -0,0 +1,65 @@
|
||||
@mixin adf-share-link-typography {
|
||||
letter-spacing: -0.4px;
|
||||
line-height: 2;
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
font-stretch: normal;
|
||||
font-size: 16px;
|
||||
opacity: 0.87;
|
||||
}
|
||||
|
||||
.adf-share-link-dialog {
|
||||
|
||||
.adf-share-link {
|
||||
&__dialog-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
&__label {
|
||||
@include adf-share-link-typography;
|
||||
flex: 1 1 auto;
|
||||
}
|
||||
|
||||
&__title {
|
||||
@include adf-share-link-typography;
|
||||
}
|
||||
|
||||
&__info {
|
||||
@include adf-share-link-typography;
|
||||
opacity: 0.54;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
&--row {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
&__input {
|
||||
opacity: 0.54;
|
||||
}
|
||||
}
|
||||
|
||||
.input-action {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.full-width {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.mat-form-field-infix {
|
||||
border-top: unset;
|
||||
}
|
||||
|
||||
.mat-dialog-actions {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.mat-form-field-flex {
|
||||
align-items: center;
|
||||
}
|
||||
}
|
@@ -0,0 +1,242 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { TestBed, fakeAsync } from '@angular/core/testing';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material';
|
||||
import { of } from 'rxjs';
|
||||
import { setupTestBed, CoreModule, SharedLinksApiService, NodesApiService } from '@alfresco/adf-core';
|
||||
import { ContentNodeShareModule } from './content-node-share.module';
|
||||
import { ShareDialogComponent } from './content-node-share.dialog';
|
||||
import moment from 'moment-es6';
|
||||
|
||||
describe('ShareDialogComponent', () => {
|
||||
let node;
|
||||
let matDialog: MatDialog;
|
||||
let sharedLinksApiService: SharedLinksApiService;
|
||||
let nodesApiService: NodesApiService;
|
||||
let fixture;
|
||||
let component;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
NoopAnimationsModule,
|
||||
CoreModule.forRoot(),
|
||||
ContentNodeShareModule
|
||||
],
|
||||
providers: [
|
||||
NodesApiService,
|
||||
SharedLinksApiService,
|
||||
{ provide: MatDialogRef, useValue: {} },
|
||||
{ provide: MAT_DIALOG_DATA, useValue: {} }
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ShareDialogComponent);
|
||||
matDialog = TestBed.get(MatDialog);
|
||||
sharedLinksApiService = TestBed.get(SharedLinksApiService);
|
||||
nodesApiService = TestBed.get(NodesApiService);
|
||||
component = fixture.componentInstance;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
node = {
|
||||
entry: {
|
||||
id: 'nodeId',
|
||||
allowableOperations: ['update'],
|
||||
isFile: true,
|
||||
properties: {}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it(`should toggle share action when property 'sharedId' does not exists`, () => {
|
||||
spyOn(sharedLinksApiService, 'createSharedLinks').and.returnValue(of({
|
||||
entry: { id: 'sharedId', sharedId: 'sharedId' }
|
||||
}));
|
||||
|
||||
component.data = {
|
||||
node,
|
||||
baseShareUrl: 'some-url/'
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(sharedLinksApiService.createSharedLinks).toHaveBeenCalled();
|
||||
expect(fixture.nativeElement.querySelector('input[formcontrolname="sharedUrl"]').value).toBe('some-url/sharedId');
|
||||
expect(fixture.nativeElement.querySelector('.mat-slide-toggle').classList).toContain('mat-checked');
|
||||
});
|
||||
|
||||
it(`should not toggle share action when file has 'sharedId' property`, () => {
|
||||
spyOn(sharedLinksApiService, 'createSharedLinks');
|
||||
|
||||
node.entry.properties['qshare:sharedId'] = 'sharedId';
|
||||
|
||||
component.data = {
|
||||
node,
|
||||
baseShareUrl: 'some-url/'
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(sharedLinksApiService.createSharedLinks).not.toHaveBeenCalled();
|
||||
expect(fixture.nativeElement.querySelector('input[formcontrolname="sharedUrl"]').value).toBe('some-url/sharedId');
|
||||
expect(fixture.nativeElement.querySelector('.mat-slide-toggle').classList).toContain('mat-checked');
|
||||
});
|
||||
|
||||
it(`should copy shared link automatically and notify`, () => {
|
||||
jasmine.clock().uninstall();
|
||||
jasmine.clock().install();
|
||||
|
||||
spyOn(document, 'execCommand');
|
||||
|
||||
node.entry.properties['qshare:sharedId'] = 'sharedId';
|
||||
component.data = {
|
||||
node,
|
||||
baseShareUrl: 'some-url/'
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
jasmine.clock().tick(100);
|
||||
|
||||
expect(document.execCommand).toHaveBeenCalledWith('copy');
|
||||
expect(document.body.querySelector('snack-bar-container span').innerHTML)
|
||||
.toBe('SHARE.CLIPBOARD-MESSAGE');
|
||||
|
||||
jasmine.clock().uninstall();
|
||||
});
|
||||
|
||||
it(`should copy shared link and notify on button event`, () => {
|
||||
node.entry.properties['qshare:sharedId'] = 'sharedId';
|
||||
spyOn(document, 'execCommand').and.callThrough();
|
||||
|
||||
component.data = {
|
||||
node,
|
||||
baseShareUrl: 'some-url/'
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.nativeElement.querySelector('.input-action')
|
||||
.dispatchEvent(new MouseEvent('click'));
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(document.execCommand).toHaveBeenCalledWith('copy');
|
||||
expect(document.body.querySelector('snack-bar-container span').innerHTML)
|
||||
.toBe('SHARE.CLIPBOARD-MESSAGE');
|
||||
});
|
||||
|
||||
it('should open a confirmation dialog when unshare button is triggered', () => {
|
||||
spyOn(matDialog, 'open').and.returnValue({ beforeClose: () => of(false) });
|
||||
spyOn(sharedLinksApiService, 'deleteSharedLink');
|
||||
node.entry.properties['qshare:sharedId'] = 'sharedId';
|
||||
|
||||
component.data = {
|
||||
node,
|
||||
baseShareUrl: 'some-url/'
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.nativeElement.querySelector('.mat-slide-toggle label')
|
||||
.dispatchEvent(new MouseEvent('click'));
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(matDialog.open).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should unshare file when confirmation dialog returns true', fakeAsync(() => {
|
||||
spyOn(matDialog, 'open').and.returnValue({ beforeClose: () => of(true) });
|
||||
spyOn(sharedLinksApiService, 'deleteSharedLink');
|
||||
node.entry.properties['qshare:sharedId'] = 'sharedId';
|
||||
|
||||
component.data = {
|
||||
node,
|
||||
baseShareUrl: 'some-url/'
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.nativeElement.querySelector('.mat-slide-toggle label')
|
||||
.dispatchEvent(new MouseEvent('click'));
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(sharedLinksApiService.deleteSharedLink).toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should not unshare file when confirmation dialog returns false', fakeAsync(() => {
|
||||
spyOn(matDialog, 'open').and.returnValue({ beforeClose: () => of(false) });
|
||||
spyOn(sharedLinksApiService, 'deleteSharedLink');
|
||||
node.entry.properties['qshare:sharedId'] = 'sharedId';
|
||||
|
||||
component.data = {
|
||||
node,
|
||||
baseShareUrl: 'some-url/'
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.nativeElement.querySelector('.mat-slide-toggle label')
|
||||
.dispatchEvent(new MouseEvent('click'));
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(sharedLinksApiService.deleteSharedLink).not.toHaveBeenCalled();
|
||||
}));
|
||||
|
||||
it('should not allow unshare when node has no update permission', () => {
|
||||
node.entry.properties['qshare:sharedId'] = 'sharedId';
|
||||
node.entry.allowableOperations = [];
|
||||
|
||||
component.data = {
|
||||
node,
|
||||
baseShareUrl: 'some-url/'
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(fixture.nativeElement.querySelector('.mat-slide-toggle').classList).toContain('mat-disabled');
|
||||
expect(fixture.nativeElement.querySelector('input[formcontrolname="time"]').disabled).toBe(true);
|
||||
expect(fixture.nativeElement.querySelector('mat-datetimepicker-toggle button').disabled).toBe(true);
|
||||
});
|
||||
|
||||
it('should not update shared node expiryDate property when value changes', () => {
|
||||
const date = moment();
|
||||
|
||||
node.entry.properties['qshare:sharedId'] = 'sharedId';
|
||||
spyOn(nodesApiService, 'updateNode');
|
||||
fixture.componentInstance.form.controls['time'].setValue(null);
|
||||
component.data = {
|
||||
node,
|
||||
baseShareUrl: 'some-url/'
|
||||
};
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.componentInstance.form.controls['time'].setValue(date);
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(nodesApiService.updateNode).toHaveBeenCalled();
|
||||
});
|
||||
});
|
@@ -0,0 +1,226 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
Component,
|
||||
Inject,
|
||||
OnInit,
|
||||
ViewEncapsulation,
|
||||
ViewChild,
|
||||
ElementRef,
|
||||
OnDestroy
|
||||
} from '@angular/core';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef, MatDialog } from '@angular/material';
|
||||
import { FormGroup, FormControl } from '@angular/forms';
|
||||
import { Subscription, Observable } from 'rxjs';
|
||||
import { tap, skip } from 'rxjs/operators';
|
||||
import {
|
||||
TranslationService,
|
||||
SharedLinksApiService,
|
||||
ClipboardService,
|
||||
NodesApiService,
|
||||
ContentService
|
||||
} from '@alfresco/adf-core';
|
||||
import { SharedLinkEntry, MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||
import { ConfirmDialogComponent } from '../dialogs/confirm.dialog';
|
||||
import moment from 'moment-es6';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-share-dialog',
|
||||
templateUrl: './content-node-share.dialog.html',
|
||||
styleUrls: ['./content-node-share.dialog.scss'],
|
||||
host: { 'class': 'adf-share-dialog' },
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class ShareDialogComponent implements OnInit, OnDestroy {
|
||||
private subscriptions: Subscription[] = [];
|
||||
|
||||
minDate = moment().toDate();
|
||||
sharedId: string;
|
||||
fileName: string;
|
||||
baseShareUrl: string;
|
||||
isFileShared: boolean = false;
|
||||
isDisabled: boolean = false;
|
||||
form: FormGroup = new FormGroup({
|
||||
'sharedUrl': new FormControl(''),
|
||||
'time': new FormControl({value: '', disabled: false})
|
||||
});
|
||||
|
||||
@ViewChild('sharedLinkInput') sharedLinkInput: ElementRef;
|
||||
|
||||
constructor(
|
||||
private sharedLinksApiService: SharedLinksApiService,
|
||||
private dialogRef: MatDialogRef<ShareDialogComponent>,
|
||||
private dialog: MatDialog,
|
||||
private nodesApiService: NodesApiService,
|
||||
private clipboardService: ClipboardService,
|
||||
private contentService: ContentService,
|
||||
private translation: TranslationService,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
if (!this.canUpdate) {
|
||||
this.form.controls['time'].disable();
|
||||
}
|
||||
|
||||
this.subscriptions.push(
|
||||
this.form.valueChanges
|
||||
.pipe(
|
||||
skip(1),
|
||||
tap((updates) => {
|
||||
this.updateNode(updates);
|
||||
})
|
||||
)
|
||||
.subscribe((updates) => this.updateEntryExpiryDate(updates))
|
||||
);
|
||||
|
||||
if (this.data.node && this.data.node.entry) {
|
||||
this.fileName = this.data.node.entry.name;
|
||||
this.baseShareUrl = this.data.baseShareUrl;
|
||||
const properties = this.data.node.entry.properties;
|
||||
|
||||
if (properties && !properties['qshare:sharedId']) {
|
||||
|
||||
this.createSharedLinks(this.data.node.entry.id);
|
||||
} else {
|
||||
this.sharedId = properties['qshare:sharedId'];
|
||||
this.isFileShared = true;
|
||||
|
||||
this.updateForm();
|
||||
this.copyToClipboard();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subscriptions.forEach((subscription) => subscription.unsubscribe);
|
||||
}
|
||||
|
||||
removeShare() {
|
||||
this.deleteSharedLink(this.sharedId);
|
||||
}
|
||||
|
||||
onSlideShareChange(event: any) {
|
||||
if (event.checked) {
|
||||
this.createSharedLinks(this.data.node.entry.id);
|
||||
} else {
|
||||
this.openConfirmationDialog();
|
||||
}
|
||||
}
|
||||
|
||||
get canUpdate() {
|
||||
return this.contentService.hasPermission(this.data.node.entry, 'update');
|
||||
}
|
||||
|
||||
private openConfirmationDialog() {
|
||||
this.isFileShared = false;
|
||||
|
||||
this.dialog
|
||||
.open(ConfirmDialogComponent, {
|
||||
data: {
|
||||
title: 'SHARE.CONFIRMATION.DIALOG-TITLE',
|
||||
message: 'SHARE.CONFIRMATION.MESSAGE',
|
||||
yesLabel: 'SHARE.CONFIRMATION.REMOVE',
|
||||
noLabel: 'SHARE.CONFIRMATION.CANCEL'
|
||||
},
|
||||
minWidth: '250px',
|
||||
closeOnNavigation: true
|
||||
})
|
||||
.beforeClose().subscribe(deleteSharedLink => {
|
||||
if (deleteSharedLink) {
|
||||
this.deleteSharedLink(this.sharedId);
|
||||
} else {
|
||||
this.isFileShared = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private createSharedLinks(nodeId: string) {
|
||||
this.isDisabled = true;
|
||||
|
||||
this.sharedLinksApiService.createSharedLinks(nodeId)
|
||||
.subscribe((sharedLink: SharedLinkEntry) => {
|
||||
|
||||
if (sharedLink.entry) {
|
||||
this.sharedId = sharedLink.entry.id;
|
||||
this.data.node.entry.properties['qshare:sharedId'] = this.sharedId;
|
||||
this.isDisabled = false;
|
||||
this.isFileShared = true;
|
||||
|
||||
this.updateForm();
|
||||
this.copyToClipboard();
|
||||
|
||||
}
|
||||
},
|
||||
() => {
|
||||
this.isDisabled = false;
|
||||
this.isFileShared = false;
|
||||
});
|
||||
}
|
||||
|
||||
private deleteSharedLink(sharedId: string) {
|
||||
this.isDisabled = true;
|
||||
|
||||
this.sharedLinksApiService.deleteSharedLink(sharedId).subscribe(() => {
|
||||
this.data.node.entry.properties['qshare:sharedId'] = null;
|
||||
this.data.node.entry.properties['qshare:expiryDate'] = null;
|
||||
this.dialogRef.close(false);
|
||||
},
|
||||
() => {
|
||||
this.isDisabled = false;
|
||||
this.isFileShared = false;
|
||||
});
|
||||
}
|
||||
|
||||
private copyToClipboard() {
|
||||
setTimeout(() => this.clipboardService.copyToClipboard(
|
||||
this.sharedLinkInput.nativeElement,
|
||||
this.translation.instant('SHARE.CLIPBOARD-MESSAGE')
|
||||
), 0);
|
||||
}
|
||||
|
||||
private updateForm() {
|
||||
const { entry } = this.data.node;
|
||||
const expiryDate = entry.properties['qshare:expiryDate'];
|
||||
|
||||
this.form.setValue({
|
||||
'sharedUrl': `${this.baseShareUrl}${this.sharedId}`,
|
||||
'time': expiryDate ? moment(expiryDate) : null
|
||||
});
|
||||
}
|
||||
|
||||
private updateNode(updates): Observable<MinimalNodeEntryEntity> {
|
||||
return this.nodesApiService.updateNode(
|
||||
this.data.node.entry.id,
|
||||
{
|
||||
properties: {
|
||||
'qshare:expiryDate': updates.time ? updates.time.toDate() : null
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private updateEntryExpiryDate(updates) {
|
||||
const { properties } = this.data.node.entry;
|
||||
|
||||
properties['qshare:expiryDate'] = updates.time
|
||||
? updates.time.toDate()
|
||||
: null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,154 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { ComponentFixture } from '@angular/core/testing';
|
||||
import { Component } from '@angular/core';
|
||||
import { DOCUMENT } from '@angular/platform-browser';
|
||||
import { ContentTestingModule } from '../testing/content.testing.module';
|
||||
import { setupTestBed, CoreModule, SharedLinksApiService } from '@alfresco/adf-core';
|
||||
import { ContentNodeShareModule } from './content-node-share.module';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-node-share-test-component',
|
||||
template: `
|
||||
<button
|
||||
[disabled]="!shareRef.isFile"
|
||||
#shareRef="adfShare"
|
||||
[baseShareUrl]="baseShareUrl"
|
||||
[adf-share]="documentList.selection[0]"
|
||||
[title]="shareRef.isShared ? 'Shared' : 'Not Shared'">
|
||||
</button>
|
||||
`
|
||||
})
|
||||
class NodeShareTestComponent {
|
||||
baseShareUrl = 'some-url/';
|
||||
documentList = {
|
||||
selection: []
|
||||
};
|
||||
}
|
||||
|
||||
describe('NodeSharedDirective', () => {
|
||||
let fixture: ComponentFixture<NodeShareTestComponent>;
|
||||
let component: NodeShareTestComponent;
|
||||
let document: any;
|
||||
let shareButtonElement;
|
||||
let selection;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
NoopAnimationsModule,
|
||||
CoreModule.forRoot(),
|
||||
ContentTestingModule,
|
||||
ContentNodeShareModule
|
||||
],
|
||||
declarations: [
|
||||
NodeShareTestComponent
|
||||
],
|
||||
providers: [
|
||||
SharedLinksApiService
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(NodeShareTestComponent);
|
||||
document = TestBed.get(DOCUMENT);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
shareButtonElement = fixture.debugElement.query(By.css('button')).nativeElement;
|
||||
selection = {
|
||||
entry: {
|
||||
isFile: true,
|
||||
properties: {}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should have share button disabled when selection is empty', async() => {
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(shareButtonElement.disabled).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should have button enabled when selection is not empty', () => {
|
||||
component.documentList.selection = [selection];
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(shareButtonElement.disabled).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it('should have button disabled when selection is not a file', () => {
|
||||
selection.entry.isFile = false;
|
||||
component.documentList.selection = [selection];
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(shareButtonElement.disabled).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should indicate if file is not shared', () => {
|
||||
component.documentList.selection = [selection];
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(shareButtonElement.title).toBe('Not Shared');
|
||||
});
|
||||
});
|
||||
|
||||
it('should indicate if file is already shared', () => {
|
||||
selection.entry.properties['qshare:sharedId'] = 'someId';
|
||||
component.documentList.selection = [selection];
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(shareButtonElement.title).toBe('Shared');
|
||||
});
|
||||
});
|
||||
|
||||
it('should open share dialog on click event', () => {
|
||||
selection.entry.properties['qshare:sharedId'] = 'someId';
|
||||
component.documentList.selection = [selection];
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
|
||||
shareButtonElement.click();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(document.querySelector('.adf-share-link-dialog')).not.toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,71 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Directive, Input, HostListener, OnChanges, NgZone } from '@angular/core';
|
||||
import { MatDialog } from '@angular/material';
|
||||
import { MinimalNodeEntity } from 'alfresco-js-api';
|
||||
|
||||
import { ShareDialogComponent } from './content-node-share.dialog';
|
||||
|
||||
@Directive({
|
||||
selector: '[adf-share]',
|
||||
exportAs: 'adfShare'
|
||||
})
|
||||
export class NodeSharedDirective implements OnChanges {
|
||||
|
||||
isFile: boolean = false;
|
||||
isShared: boolean = false;
|
||||
|
||||
/** Node to share. */
|
||||
// tslint:disable-next-line:no-input-rename
|
||||
@Input('adf-share')
|
||||
node: MinimalNodeEntity;
|
||||
|
||||
@Input()
|
||||
baseShareUrl: string;
|
||||
|
||||
@HostListener('click')
|
||||
onClick() {
|
||||
if (this.node) {
|
||||
this.shareNode(this.node);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(private dialog: MatDialog, private zone: NgZone) {}
|
||||
|
||||
shareNode(node: MinimalNodeEntity) {
|
||||
if (node && node.entry && node.entry.isFile) {
|
||||
this.dialog.open(ShareDialogComponent, {
|
||||
width: '600px',
|
||||
panelClass: 'adf-share-link-dialog',
|
||||
data: {
|
||||
node: node,
|
||||
baseShareUrl: this.baseShareUrl
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges() {
|
||||
this.zone.onStable.subscribe(() => {
|
||||
if (this.node) {
|
||||
this.isFile = this.node.entry.isFile;
|
||||
this.isShared = this.node.entry.properties['qshare:sharedId'];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { NgModule, ModuleWithProviders } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { CoreModule } from '@alfresco/adf-core';
|
||||
import { MaterialModule } from '../material.module';
|
||||
import { ShareDialogComponent } from './content-node-share.dialog';
|
||||
import { NodeSharedDirective } from './content-node-share.directive';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CoreModule.forChild(),
|
||||
CommonModule,
|
||||
MaterialModule
|
||||
],
|
||||
declarations: [
|
||||
ShareDialogComponent,
|
||||
NodeSharedDirective
|
||||
],
|
||||
exports: [
|
||||
ShareDialogComponent,
|
||||
NodeSharedDirective
|
||||
],
|
||||
entryComponents: [
|
||||
ShareDialogComponent
|
||||
]
|
||||
})
|
||||
export class ContentNodeShareModule {
|
||||
static forRoot(): ModuleWithProviders {
|
||||
return {
|
||||
ngModule: ContentNodeShareModule
|
||||
};
|
||||
}
|
||||
|
||||
static forChild(): ModuleWithProviders {
|
||||
return {
|
||||
ngModule: ContentNodeShareModule
|
||||
};
|
||||
}
|
||||
}
|
18
lib/content-services/content-node-share/index.ts
Normal file
18
lib/content-services/content-node-share/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './public-api';
|
21
lib/content-services/content-node-share/public-api.ts
Normal file
21
lib/content-services/content-node-share/public-api.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export * from './content-node-share.dialog';
|
||||
export * from './content-node-share.directive';
|
||||
|
||||
export * from './content-node-share.module';
|
Reference in New Issue
Block a user