[ADF-ADF-2528] share directive (#3102)

* share file directive

* share link phase 2

* share dialog

* share dialog test

* more documentation

* add more meaningfully specification

* Add  description in the dialog
This commit is contained in:
Eugenio Romano
2018-03-20 22:32:56 +00:00
committed by GitHub
parent 71b85588cf
commit 2761626f55
24 changed files with 660 additions and 35 deletions
@@ -21,6 +21,7 @@ import { MaterialModule } from '../material.module';
import { DownloadZipDialogComponent } from './download-zip.dialog';
import { FolderDialogComponent } from './folder.dialog';
import { ShareDialogComponent } from './share.dialog';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { TranslateModule } from '@ngx-translate/core';
@@ -36,7 +37,8 @@ import { NodesApiService, NotificationService, TranslationService } from '@alfre
],
declarations: [
DownloadZipDialogComponent,
FolderDialogComponent
FolderDialogComponent,
ShareDialogComponent
],
providers: [
NodesApiService,
@@ -45,11 +47,13 @@ import { NodesApiService, NotificationService, TranslationService } from '@alfre
],
exports: [
DownloadZipDialogComponent,
FolderDialogComponent
FolderDialogComponent,
ShareDialogComponent
],
entryComponents: [
DownloadZipDialogComponent,
FolderDialogComponent
FolderDialogComponent,
ShareDialogComponent
]
})
export class DialogModule {}
@@ -17,3 +17,4 @@
export * from './download-zip.dialog';
export * from './folder.dialog';
export * from './share.dialog';
@@ -0,0 +1,32 @@
<h1 mat-dialog-title id="adf-share-title" >{{ 'SHARE.TITLE' | translate }} {{fileName}}</h1>
<mat-dialog-content>
<span class="spacer"></span>
<mat-slide-toggle [checked]="isFileShared" [disabled]="isDisabled" (change)="onSlideShareChange($event)">
{{ 'SHARE.ACTIONS.SHARE' | translate }}
</mat-slide-toggle>
<span class="spacer"></span>
.
<h2 *ngIf="isFileShared">{{ 'SHARE.DESCRIPTION' | translate }}</h2>
<div *ngIf="isFileShared">{{ 'SHARE.ALERT' | translate }}</div>
<form *ngIf="isFileShared">
<mat-form-field class="full-width">
<input class="adf-share-link" matInput placeholder="{{ 'SHARE.PUBLIC-LINK' | translate }}" [value]="baseShareUrl + sharedId">
<mat-icon matPrefix>link</mat-icon>
</mat-form-field>
</form>
<h2 *ngIf="!isFileShared">{{ 'SHARE.UNSHARED' | translate }}</h2>
</mat-dialog-content>
<mat-dialog-actions>
<button mat-button color="primary" (click)="cancelShare()">
{{ 'SHARE.ACTIONS.CLOSE' | translate }}
</button>
</mat-dialog-actions>
@@ -0,0 +1,14 @@
.spacer { flex: 1 1 auto; }
.adf-share-dialog .mat-dialog-actions .mat-button-wrapper {
text-transform: uppercase;
}
.full-width {
width: 100%;
}
.adf-share-link {
margin-left: 10px;
font-size: 18px !important;
}
@@ -0,0 +1,109 @@
/*!
* @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 { async, TestBed } from '@angular/core/testing';
import { ComponentFixture } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
import { Observable } from 'rxjs/Observable';
import { ShareDialogComponent } from './share.dialog';
describe('ShareDialogComponent', () => {
let fixture: ComponentFixture<ShareDialogComponent>;
let component: ShareDialogComponent;
let dialogRef;
let data: any = {
node: { entry: { properties: { 'qshare:sharedId': 'example-link' }, name: 'example-name' } }
baseShareUrl: 'baseShareUrl-example'
};
beforeEach(async(() => {
dialogRef = {
close: jasmine.createSpy('close')
};
TestBed.configureTestingModule({
imports: [
FormsModule,
ReactiveFormsModule,
BrowserDynamicTestingModule
],
declarations: [
ShareDialogComponent
],
providers: [
{ provide: MatDialogRef, useValue: dialogRef },
{
provide: MAT_DIALOG_DATA,
useValue: data
}
]
});
TestBed.overrideModule(BrowserDynamicTestingModule, {
set: { entryComponents: [ShareDialogComponent] }
});
TestBed.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ShareDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should init the dialog with the file name and baseShareUrl', () => {
expect(component.fileName).toBe('example-name');
expect(component.baseShareUrl).toBe('baseShareUrl-example');
});
describe('public link creation', () => {
it('should not create the public link if it alredy present in the node', () => {
let spyCreate = spyOn(component, 'createSharedLinks').and.returnValue(Observable.of(''));
component.ngOnInit();
expect(spyCreate).not.toHaveBeenCalled();
});
it('should not create the public link if it alredy present in the node', () => {
component.data = {
node: { entry: { name: 'example-name' } }
baseShareUrl: 'baseShareUrl-example'
};
let spyCreate = spyOn(component, 'createSharedLinks').and.returnValue(Observable.of(''));
data = {
node: { entry: { name: 'example-name' } }
baseShareUrl: 'baseShareUrl-example'
};
component.ngOnInit();
expect(spyCreate).toHaveBeenCalled();
});
});
});
@@ -0,0 +1,97 @@
/*!
* @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 } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
import { SharedLinksApiService } from '@alfresco/adf-core';
import { SharedLinkEntry } from 'alfresco-js-api';
@Component({
selector: 'adf-share-dialog',
templateUrl: './share.dialog.html',
styleUrls: ['./share.dialog.scss'],
host: { 'class': 'adf-share-dialog' },
encapsulation: ViewEncapsulation.None
})
export class ShareDialogComponent implements OnInit {
sharedId: string;
fileName: string;
baseShareUrl: string;
isFileShared: boolean = false;
isDisabled: boolean = false;
constructor(private sharedLinksApiService: SharedLinksApiService,
private dialogRef: MatDialogRef<ShareDialogComponent>,
@Inject(MAT_DIALOG_DATA)
public data: any) {
}
ngOnInit() {
if (this.data.node && this.data.node.entry) {
this.fileName = this.data.node.entry.name;
this.baseShareUrl = this.data.baseShareUrl;
if (this.data.node.entry.properties && this.data.node.entry.properties['qshare:sharedId']) {
this.sharedId = this.data.node.entry.properties['qshare:sharedId'];
this.isFileShared = true;
} else {
this.createSharedLinks(this.data.node.entry.id);
}
}
}
cancelShare() {
this.dialogRef.close(false);
}
onSlideShareChange(event: any) {
this.isDisabled = true;
if (event.checked) {
this.createSharedLinks(this.data.node.entry.id);
} else {
this.deleteSharedLink(this.sharedId);
}
}
createSharedLinks(nodeId: string) {
this.sharedLinksApiService.createSharedLinks(nodeId).subscribe((sharedLink: SharedLinkEntry) => {
if (sharedLink.entry) {
this.sharedId = sharedLink.entry.id;
this.isFileShared = true;
this.isDisabled = false;
}
},
() => {
this.isFileShared = false;
this.isDisabled = false;
});
}
deleteSharedLink(sharedId: string) {
this.sharedLinksApiService.deleteSharedLink(sharedId).subscribe(() => {
this.isFileShared = false;
this.isDisabled = false;
},
() => {
this.isFileShared = true;
this.isDisabled = false;
});
}
}