mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
@@ -106,6 +106,14 @@
|
|||||||
{{ favorite.hasFavorites() ? 'star' :'star_border' }}
|
{{ favorite.hasFavorites() ? 'star' :'star_border' }}
|
||||||
</mat-icon>
|
</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
|
<button mat-icon-button
|
||||||
|
[disabled]="!documentList.selection.length"
|
||||||
|
[baseShareUrl]="baseShareUrl"
|
||||||
|
[adf-share]="documentList.selection[0]">
|
||||||
|
<mat-icon>
|
||||||
|
share
|
||||||
|
</mat-icon>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button fxFlex="1 0 auto" mat-icon-button [matMenuTriggerFor]="themePicker">
|
<button fxFlex="1 0 auto" mat-icon-button [matMenuTriggerFor]="themePicker">
|
||||||
|
@@ -30,7 +30,7 @@ import {
|
|||||||
SiteEntry
|
SiteEntry
|
||||||
} from 'alfresco-js-api';
|
} from 'alfresco-js-api';
|
||||||
import {
|
import {
|
||||||
AuthenticationService, ContentService, TranslationService,
|
AuthenticationService, AppConfigService, ContentService, TranslationService,
|
||||||
FileUploadEvent, FolderCreatedEvent, LogService, NotificationService,
|
FileUploadEvent, FolderCreatedEvent, LogService, NotificationService,
|
||||||
UploadService, DataColumn, DataRow, UserPreferencesService,
|
UploadService, DataColumn, DataRow, UserPreferencesService,
|
||||||
PaginationComponent, FormValues, DisplayMode, UserPreferenceValues
|
PaginationComponent, FormValues, DisplayMode, UserPreferenceValues
|
||||||
@@ -59,6 +59,8 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
showVersions = false;
|
showVersions = false;
|
||||||
displayMode = DisplayMode.List;
|
displayMode = DisplayMode.List;
|
||||||
|
|
||||||
|
baseShareUrl = this.appConfig.get<string>('ecmHost') + '/preview/s/';
|
||||||
|
|
||||||
toolbarColor = 'default';
|
toolbarColor = 'default';
|
||||||
|
|
||||||
selectionModes = [
|
selectionModes = [
|
||||||
@@ -158,6 +160,7 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
private logService: LogService,
|
private logService: LogService,
|
||||||
private preference: UserPreferencesService,
|
private preference: UserPreferencesService,
|
||||||
@Optional() private route: ActivatedRoute,
|
@Optional() private route: ActivatedRoute,
|
||||||
|
private appConfig: AppConfigService,
|
||||||
public authenticationService: AuthenticationService) {
|
public authenticationService: AuthenticationService) {
|
||||||
this.preference.select(UserPreferenceValues.SupportedPageSizes)
|
this.preference.select(UserPreferenceValues.SupportedPageSizes)
|
||||||
.subscribe((pages) => {
|
.subscribe((pages) => {
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
@import './app/components/app-layout/app-layout.component.scss';
|
@import './app/components/app-layout/app-layout.component.scss';
|
||||||
|
|
||||||
@import '~@alfresco/adf-content-services/theming';
|
@import '~@alfresco/adf-content-services/theming';
|
||||||
@import '~@alfresco/adf-process-services/theming';
|
|
||||||
@import '~@alfresco/adf-insights/theming';
|
@import '~@alfresco/adf-insights/theming';
|
||||||
@import '~@alfresco/adf-core/theming';
|
@import '~@alfresco/adf-core/theming';
|
||||||
|
|
||||||
@@ -18,7 +17,6 @@ $theme: mat-light-theme($primary, $accent, $warn);
|
|||||||
@include adf-app-layout-theme($theme);
|
@include adf-app-layout-theme($theme);
|
||||||
|
|
||||||
@include adf-content-services-theme($theme);
|
@include adf-content-services-theme($theme);
|
||||||
@include adf-process-services-theme($theme);
|
|
||||||
@include adf-insights-theme($theme);
|
@include adf-insights-theme($theme);
|
||||||
@include adf-core-theme($theme);
|
@include adf-core-theme($theme);
|
||||||
|
|
||||||
|
@@ -45,7 +45,6 @@
|
|||||||
"no-bitwise": true,
|
"no-bitwise": true,
|
||||||
"no-console": [
|
"no-console": [
|
||||||
true,
|
true,
|
||||||
"log",
|
|
||||||
"debug",
|
"debug",
|
||||||
"info",
|
"info",
|
||||||
"time",
|
"time",
|
||||||
|
@@ -42,6 +42,7 @@ for more information about installing and using the source code.
|
|||||||
| [Folder create directive](folder-create.directive.md) | Allows folders to be created. | [Source](../../lib/content-services/folder-directive/folder-create.directive.ts) |
|
| [Folder create directive](folder-create.directive.md) | Allows folders to be created. | [Source](../../lib/content-services/folder-directive/folder-create.directive.ts) |
|
||||||
| [Folder edit directive](folder-edit.directive.md) | Allows folders to be edited. | [Source](../../lib/content-services/folder-directive/folder-edit.directive.ts) |
|
| [Folder edit directive](folder-edit.directive.md) | Allows folders to be edited. | [Source](../../lib/content-services/folder-directive/folder-edit.directive.ts) |
|
||||||
| [File draggable directive](file-draggable.directive.md) | Provide drag-and-drop features for an element such as a `div`. | [Source](../../lib/content-services/upload/directives/file-draggable.directive.ts) |
|
| [File draggable directive](file-draggable.directive.md) | Provide drag-and-drop features for an element such as a `div`. | [Source](../../lib/content-services/upload/directives/file-draggable.directive.ts) |
|
||||||
|
| [Share Directive](share.directive.md) | Proide a pop up that generat a public linlk to share a file | [Source](../../lib/content-services/upload/directives/share.directive.ts) |
|
||||||
|
|
||||||
## Models
|
## Models
|
||||||
|
|
||||||
|
49
docs/content-services/share.directive.md
Normal file
49
docs/content-services/share.directive.md
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
---
|
||||||
|
Added: v2.3.0
|
||||||
|
Status: Active
|
||||||
|
---
|
||||||
|
# Node Public file Share Directive
|
||||||
|
|
||||||
|
Create and manage public shared links for files
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
This dialog will generate a link that will be formed as "baseShareUrl + sharedId".
|
||||||
|
For example if you set the input parameter [baseShareUrl]="http://localhos:8080/myrouteForShareFile/",
|
||||||
|
the directive will ask to the Content service to generate a sharedId for the file. This will end up with a url link like :
|
||||||
|
|
||||||
|
http://localhos:8080/myrouteForShareFile/NEW_GENERATED_SHAREID
|
||||||
|
|
||||||
|
After you will need to implement in your app a logic that throught the router get the NEW_GENERATED_SHAREID and pass it to the ***adf-viewer***
|
||||||
|
|
||||||
|
```html
|
||||||
|
<adf-viewer
|
||||||
|
[sharedLinkId]="NEW_GENERATED_SHAREID"
|
||||||
|
[allowGoBack]="false">
|
||||||
|
</adf-viewer>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Basic Usage
|
||||||
|
|
||||||
|
```html
|
||||||
|
<adf-toolbar>
|
||||||
|
<button mat-icon-button
|
||||||
|
[baseShareUrl]="http://localhos:8080/myrouteForShareFile/"
|
||||||
|
[adf-share]="documentList.selection[0]">
|
||||||
|
<mat-icon>share</mat-icon>
|
||||||
|
</button>
|
||||||
|
</adf-toolbar>
|
||||||
|
|
||||||
|
<adf-document-list #documentList ...>
|
||||||
|
...
|
||||||
|
</adf-document-list>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Properties
|
||||||
|
|
||||||
|
| Name | Type | Default value | Description |
|
||||||
|
| ---- | ---- | ------------- | ----------- |
|
||||||
|
| node | `MinimalNodeEntity` | | Nodes to share. |
|
||||||
|
| baseShareUrl | `string` | | baseShareUrl to add as prefix to the generated link |
|
||||||
|
|
||||||
|
|
BIN
docs/docassets/images/share-directive.png
Normal file
BIN
docs/docassets/images/share-directive.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 64 KiB |
@@ -32,10 +32,10 @@ import { SitesDropdownModule } from './site-dropdown/sites-dropdown.module';
|
|||||||
import { BreadcrumbModule } from './breadcrumb/breadcrumb.module';
|
import { BreadcrumbModule } from './breadcrumb/breadcrumb.module';
|
||||||
import { VersionManagerModule } from './version-manager/version-manager.module';
|
import { VersionManagerModule } from './version-manager/version-manager.module';
|
||||||
import { ContentNodeSelectorModule } from './content-node-selector/content-node-selector.module';
|
import { ContentNodeSelectorModule } from './content-node-selector/content-node-selector.module';
|
||||||
|
import { ContentDirectiveModule } from './directives/content-directive.module';
|
||||||
import { DialogModule } from './dialogs/dialog.module';
|
import { DialogModule } from './dialogs/dialog.module';
|
||||||
import { FolderDirectiveModule } from './folder-directive/folder-directive.module';
|
import { FolderDirectiveModule } from './folder-directive/folder-directive.module';
|
||||||
import { ContentMetadataModule } from './content-metadata/content-metadata.module';
|
import { ContentMetadataModule } from './content-metadata/content-metadata.module';
|
||||||
import { NodeDownloadDirective } from './directives/node-download.directive';
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -56,10 +56,8 @@ import { NodeDownloadDirective } from './directives/node-download.directive';
|
|||||||
ContentNodeSelectorModule,
|
ContentNodeSelectorModule,
|
||||||
ContentMetadataModule,
|
ContentMetadataModule,
|
||||||
DialogModule,
|
DialogModule,
|
||||||
FolderDirectiveModule
|
FolderDirectiveModule,
|
||||||
],
|
ContentDirectiveModule
|
||||||
declarations: [
|
|
||||||
NodeDownloadDirective
|
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
@@ -86,7 +84,7 @@ import { NodeDownloadDirective } from './directives/node-download.directive';
|
|||||||
ContentMetadataModule,
|
ContentMetadataModule,
|
||||||
DialogModule,
|
DialogModule,
|
||||||
FolderDirectiveModule,
|
FolderDirectiveModule,
|
||||||
NodeDownloadDirective
|
ContentDirectiveModule
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class ContentModule {
|
export class ContentModule {
|
||||||
|
@@ -21,6 +21,7 @@ import { MaterialModule } from '../material.module';
|
|||||||
|
|
||||||
import { DownloadZipDialogComponent } from './download-zip.dialog';
|
import { DownloadZipDialogComponent } from './download-zip.dialog';
|
||||||
import { FolderDialogComponent } from './folder.dialog';
|
import { FolderDialogComponent } from './folder.dialog';
|
||||||
|
import { ShareDialogComponent } from './share.dialog';
|
||||||
|
|
||||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
@@ -36,7 +37,8 @@ import { NodesApiService, NotificationService, TranslationService } from '@alfre
|
|||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
DownloadZipDialogComponent,
|
DownloadZipDialogComponent,
|
||||||
FolderDialogComponent
|
FolderDialogComponent,
|
||||||
|
ShareDialogComponent
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
NodesApiService,
|
NodesApiService,
|
||||||
@@ -45,11 +47,13 @@ import { NodesApiService, NotificationService, TranslationService } from '@alfre
|
|||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
DownloadZipDialogComponent,
|
DownloadZipDialogComponent,
|
||||||
FolderDialogComponent
|
FolderDialogComponent,
|
||||||
|
ShareDialogComponent
|
||||||
],
|
],
|
||||||
entryComponents: [
|
entryComponents: [
|
||||||
DownloadZipDialogComponent,
|
DownloadZipDialogComponent,
|
||||||
FolderDialogComponent
|
FolderDialogComponent,
|
||||||
|
ShareDialogComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class DialogModule {}
|
export class DialogModule {}
|
||||||
|
@@ -17,3 +17,4 @@
|
|||||||
|
|
||||||
export * from './download-zip.dialog';
|
export * from './download-zip.dialog';
|
||||||
export * from './folder.dialog';
|
export * from './folder.dialog';
|
||||||
|
export * from './share.dialog';
|
||||||
|
32
lib/content-services/dialogs/share.dialog.html
Normal file
32
lib/content-services/dialogs/share.dialog.html
Normal file
@@ -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>
|
14
lib/content-services/dialogs/share.dialog.scss
Normal file
14
lib/content-services/dialogs/share.dialog.scss
Normal file
@@ -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;
|
||||||
|
}
|
109
lib/content-services/dialogs/share.dialog.spec.ts
Normal file
109
lib/content-services/dialogs/share.dialog.spec.ts
Normal file
@@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
97
lib/content-services/dialogs/share.dialog.ts
Normal file
97
lib/content-services/dialogs/share.dialog.ts
Normal file
@@ -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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
40
lib/content-services/directives/content-directive.module.ts
Normal file
40
lib/content-services/directives/content-directive.module.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*!
|
||||||
|
* @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 { CommonModule } from '@angular/common';
|
||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { MaterialModule } from '../material.module';
|
||||||
|
|
||||||
|
import { NodeDownloadDirective } from './node-download.directive';
|
||||||
|
import { NodeSharedDirective } from './node-share.directive';
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
MaterialModule
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
NodeDownloadDirective,
|
||||||
|
NodeSharedDirective
|
||||||
|
],
|
||||||
|
exports: [
|
||||||
|
NodeDownloadDirective,
|
||||||
|
NodeSharedDirective
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class ContentDirectiveModule {
|
||||||
|
}
|
18
lib/content-services/directives/index.ts
Normal file
18
lib/content-services/directives/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';
|
118
lib/content-services/directives/node-share.directive.spec.ts
Normal file
118
lib/content-services/directives/node-share.directive.spec.ts
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
/*!
|
||||||
|
* @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, DebugElement } from '@angular/core';
|
||||||
|
import { fakeAsync, async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { NodeSharedDirective } from './node-share.directive';
|
||||||
|
import { DialogModule } from '../dialogs/dialog.module';
|
||||||
|
import { MatDialog } from '@angular/material';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
template: `
|
||||||
|
<div [adf-share]="node">
|
||||||
|
</div>`
|
||||||
|
})
|
||||||
|
class TestComponent {
|
||||||
|
node = null;
|
||||||
|
|
||||||
|
done = jasmine.createSpy('done');
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('NodeSharedDirective', () => {
|
||||||
|
let fixture: ComponentFixture<TestComponent>;
|
||||||
|
let element: DebugElement;
|
||||||
|
let component: TestComponent;
|
||||||
|
let dialog: MatDialog;
|
||||||
|
let dialogSpy;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
DialogModule
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
TestComponent,
|
||||||
|
NodeSharedDirective
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.compileComponents()
|
||||||
|
.then(() => {
|
||||||
|
fixture = TestBed.createComponent(TestComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
dialog = TestBed.get(MatDialog);
|
||||||
|
element = fixture.debugElement.query(By.directive(NodeSharedDirective));
|
||||||
|
dialogSpy = spyOn(dialog, 'open');
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('Share', () => {
|
||||||
|
|
||||||
|
it('should not share when selection has no nodes', () => {
|
||||||
|
component.node = null;
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
element.triggerEventHandler('click', null);
|
||||||
|
|
||||||
|
expect(dialogSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not share when the selection node is a folder', () => {
|
||||||
|
component.node = {
|
||||||
|
entry: {
|
||||||
|
isFolder: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
element.triggerEventHandler('click', null);
|
||||||
|
|
||||||
|
expect(dialogSpy).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should share when the selection node is a file', () => {
|
||||||
|
component.node = {
|
||||||
|
entry: {
|
||||||
|
isFolder: false,
|
||||||
|
isFile: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
element.triggerEventHandler('click', null);
|
||||||
|
|
||||||
|
expect(dialogSpy).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should disable the button if no node is selected', fakeAsync(() => {
|
||||||
|
component.node = null;
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(element.nativeElement.disabled).toEqual(true);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should enable the button if nodes is selected and is a file', fakeAsync(() => {
|
||||||
|
component.node = { entry: { id: '1', name: 'name1' isFolder: false, isFile: true } };
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(element.nativeElement.disabled).toEqual(false);
|
||||||
|
}));
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
74
lib/content-services/directives/node-share.directive.ts
Normal file
74
lib/content-services/directives/node-share.directive.ts
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
/*!
|
||||||
|
* @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, ElementRef, OnChanges } from '@angular/core';
|
||||||
|
import { MatDialog } from '@angular/material';
|
||||||
|
import { MinimalNodeEntity } from 'alfresco-js-api';
|
||||||
|
|
||||||
|
import { ShareDialogComponent } from '../dialogs/share.dialog';
|
||||||
|
|
||||||
|
@Directive({
|
||||||
|
selector: '[adf-share]'
|
||||||
|
})
|
||||||
|
export class NodeSharedDirective implements OnChanges {
|
||||||
|
|
||||||
|
/** Node to share. */
|
||||||
|
// tslint:disable-next-line:no-input-rename
|
||||||
|
@Input('adf-share')
|
||||||
|
node: MinimalNodeEntity;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
baseShareUrl: string;
|
||||||
|
|
||||||
|
@HostListener('click')
|
||||||
|
onClick() {
|
||||||
|
this.shareNode(this.node);
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(private dialog: MatDialog,
|
||||||
|
private elementRef: ElementRef) {
|
||||||
|
}
|
||||||
|
|
||||||
|
shareNode(node: MinimalNodeEntity) {
|
||||||
|
if (node.entry && node.entry.isFile) {
|
||||||
|
this.setDisableAttribute(true);
|
||||||
|
this.dialog.open(ShareDialogComponent, {
|
||||||
|
width: '600px',
|
||||||
|
disableClose: true,
|
||||||
|
data: {
|
||||||
|
node: node,
|
||||||
|
baseShareUrl: this.baseShareUrl
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.setDisableAttribute(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnChanges() {
|
||||||
|
if (!this.node || this.node.entry.isFolder) {
|
||||||
|
this.setDisableAttribute(true);
|
||||||
|
} else {
|
||||||
|
this.setDisableAttribute(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private setDisableAttribute(disable: boolean) {
|
||||||
|
this.elementRef.nativeElement.disabled = disable;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
19
lib/content-services/directives/public-api.ts
Normal file
19
lib/content-services/directives/public-api.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/*!
|
||||||
|
* @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 './node-download.directive';
|
||||||
|
export * from './node-share.directive';
|
@@ -194,5 +194,17 @@
|
|||||||
"MODIFIER": "Modifier",
|
"MODIFIER": "Modifier",
|
||||||
"MODIFIED_DATE": "Modified Date"
|
"MODIFIED_DATE": "Modified Date"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"SHARE": {
|
||||||
|
"TITLE": "Share",
|
||||||
|
"PUBLIC-LINK": "Public link",
|
||||||
|
"UNSHARED": "File not shared",
|
||||||
|
"DESCRIPTION": "This is a link to your file",
|
||||||
|
"ALERT": "Anyone with this link can acces to it",
|
||||||
|
"ACTIONS": {
|
||||||
|
"SHARE": "SHARE",
|
||||||
|
"CLOSE": "CLOSE",
|
||||||
|
"COPY-LINK": "COPY LINK"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,8 +30,9 @@ export * from './content-node-selector/content-node-selector.module';
|
|||||||
export * from './dialogs/dialog.module';
|
export * from './dialogs/dialog.module';
|
||||||
export * from './folder-directive/folder-directive.module';
|
export * from './folder-directive/folder-directive.module';
|
||||||
export * from './content-metadata/content-metadata.module';
|
export * from './content-metadata/content-metadata.module';
|
||||||
export { NodeDownloadDirective } from './directives/node-download.directive';
|
export * from './directives/content-directive.module';
|
||||||
|
|
||||||
|
export * from './directives';
|
||||||
export * from './social';
|
export * from './social';
|
||||||
export * from './tag';
|
export * from './tag';
|
||||||
export * from './webscript';
|
export * from './webscript';
|
||||||
|
@@ -30,7 +30,8 @@ import {
|
|||||||
MatProgressSpinnerModule,
|
MatProgressSpinnerModule,
|
||||||
MatRippleModule,
|
MatRippleModule,
|
||||||
MatExpansionModule,
|
MatExpansionModule,
|
||||||
MatSelectModule
|
MatSelectModule,
|
||||||
|
MatSlideToggleModule
|
||||||
} from '@angular/material';
|
} from '@angular/material';
|
||||||
|
|
||||||
export function modules() {
|
export function modules() {
|
||||||
@@ -48,7 +49,8 @@ export function modules() {
|
|||||||
MatMenuModule,
|
MatMenuModule,
|
||||||
MatOptionModule,
|
MatOptionModule,
|
||||||
MatExpansionModule,
|
MatExpansionModule,
|
||||||
MatSelectModule
|
MatSelectModule,
|
||||||
|
MatSlideToggleModule
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { NodePaging } from 'alfresco-js-api';
|
import { NodePaging, SharedLinkEntry } from 'alfresco-js-api';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { AlfrescoApiService } from './alfresco-api.service';
|
import { AlfrescoApiService } from './alfresco-api.service';
|
||||||
import { UserPreferencesService } from './user-preferences.service';
|
import { UserPreferencesService } from './user-preferences.service';
|
||||||
@@ -25,9 +25,9 @@ import 'rxjs/add/observable/fromPromise';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class SharedLinksApiService {
|
export class SharedLinksApiService {
|
||||||
|
|
||||||
constructor(
|
constructor(private apiService: AlfrescoApiService,
|
||||||
private apiService: AlfrescoApiService,
|
private preferences: UserPreferencesService) {
|
||||||
private preferences: UserPreferencesService) {}
|
}
|
||||||
|
|
||||||
private get sharedLinksApi() {
|
private get sharedLinksApi() {
|
||||||
return this.apiService.getInstance().core.sharedlinksApi;
|
return this.apiService.getInstance().core.sharedlinksApi;
|
||||||
@@ -42,7 +42,7 @@ export class SharedLinksApiService {
|
|||||||
const defaultOptions = {
|
const defaultOptions = {
|
||||||
maxItems: this.preferences.paginationSize,
|
maxItems: this.preferences.paginationSize,
|
||||||
skipCount: 0,
|
skipCount: 0,
|
||||||
include: [ 'properties', 'allowableOperations' ]
|
include: ['properties', 'allowableOperations']
|
||||||
};
|
};
|
||||||
const queryOptions = Object.assign({}, defaultOptions, options);
|
const queryOptions = Object.assign({}, defaultOptions, options);
|
||||||
const promise = sharedLinksApi
|
const promise = sharedLinksApi
|
||||||
@@ -53,6 +53,35 @@ export class SharedLinksApiService {
|
|||||||
.catch(handleError);
|
.catch(handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a shared links available to the current user.
|
||||||
|
* @param nodeId
|
||||||
|
* @param options Options supported by JSAPI
|
||||||
|
*/
|
||||||
|
createSharedLinks(nodeId: string, options: any = {}): Observable<SharedLinkEntry> {
|
||||||
|
const { sharedLinksApi, handleError } = this;
|
||||||
|
|
||||||
|
const promise = sharedLinksApi.addSharedLink({ nodeId: nodeId });
|
||||||
|
|
||||||
|
return Observable
|
||||||
|
.fromPromise(promise)
|
||||||
|
.catch(handleError);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete shared links
|
||||||
|
* @param sharedId to delete
|
||||||
|
*/
|
||||||
|
deleteSharedLink(sharedId: string): Observable<SharedLinkEntry> {
|
||||||
|
const { sharedLinksApi, handleError } = this;
|
||||||
|
|
||||||
|
const promise = sharedLinksApi.deleteSharedLink(sharedId);
|
||||||
|
|
||||||
|
return Observable
|
||||||
|
.fromPromise(promise)
|
||||||
|
.catch(handleError);
|
||||||
|
}
|
||||||
|
|
||||||
private handleError(error: any): Observable<any> {
|
private handleError(error: any): Observable<any> {
|
||||||
return Observable.of(error);
|
return Observable.of(error);
|
||||||
}
|
}
|
||||||
|
@@ -11,8 +11,7 @@
|
|||||||
],
|
],
|
||||||
"ban": [
|
"ban": [
|
||||||
true,
|
true,
|
||||||
"eval",
|
"eval"
|
||||||
"fdescribe"
|
|
||||||
],
|
],
|
||||||
"class-name": true,
|
"class-name": true,
|
||||||
"comment-format": [
|
"comment-format": [
|
||||||
|
Reference in New Issue
Block a user