mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-573] support for toggling enabled state (#1912)
This commit is contained in:
committed by
Eugenio Romano
parent
4b5eb4bb29
commit
1ffc3cd080
@@ -287,12 +287,14 @@ platformBrowserDynamic().bootstrapModule(AppModule);
|
|||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `onSuccess` | The event is emitted when the file is uploaded |
|
| `onSuccess` | The event is emitted when the file is uploaded |
|
||||||
|
|
||||||
#### Propertoes
|
#### Properties
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
|
| `enabled` | *boolean* | true | Toggle component enabled state |
|
||||||
| `showNotificationBar` | *boolean* | true | Hide/show notification bar |
|
| `showNotificationBar` | *boolean* | true | Hide/show notification bar |
|
||||||
| `currentFolderPath` | *string* | '/Sites/swsdp/documentLibrary' | define the path where the files are uploaded |
|
| `rootFolderId` | *string* | '-root-' | The ID of the root folder node.
|
||||||
|
| `currentFolderPath` | *string* | '/' | define the path where the files are uploaded |
|
||||||
| `versioning` | *boolean* | false | Versioning false is the default uploader behaviour and it rename using an integer suffix if there is a name clash. Versioning true to indicate that a major version should be created |
|
| `versioning` | *boolean* | false | Versioning false is the default uploader behaviour and it rename using an integer suffix if there is a name clash. Versioning true to indicate that a major version should be created |
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
<div file-draggable id="UploadBorder" class="upload-border"
|
<div [file-draggable]="enabled" id="UploadBorder" class="upload-border"
|
||||||
(onFilesDropped)="onFilesDropped($event)"
|
(onFilesDropped)="onFilesDropped($event)"
|
||||||
(onFilesEntityDropped)="onFilesEntityDropped($event)"
|
(onFilesEntityDropped)="onFilesEntityDropped($event)"
|
||||||
(onFolderEntityDropped)="onFolderEntityDropped($event)"
|
(onFolderEntityDropped)="onFolderEntityDropped($event)"
|
||||||
|
@@ -20,6 +20,7 @@ import { EventEmitter, DebugElement } from '@angular/core';
|
|||||||
import { AlfrescoTranslationService, CoreModule, LogService, LogServiceMock, NotificationService } from 'ng2-alfresco-core';
|
import { AlfrescoTranslationService, CoreModule, LogService, LogServiceMock, NotificationService } from 'ng2-alfresco-core';
|
||||||
|
|
||||||
import { UploadDragAreaComponent } from './upload-drag-area.component';
|
import { UploadDragAreaComponent } from './upload-drag-area.component';
|
||||||
|
import { FileDraggableDirective } from '../directives/file-draggable.directive';
|
||||||
import { TranslationMock } from '../assets/translation.service.mock';
|
import { TranslationMock } from '../assets/translation.service.mock';
|
||||||
import { UploadService } from '../services/upload.service';
|
import { UploadService } from '../services/upload.service';
|
||||||
import { FileModel } from '../models/file.model';
|
import { FileModel } from '../models/file.model';
|
||||||
@@ -39,6 +40,7 @@ describe('UploadDragAreaComponent', () => {
|
|||||||
CoreModule.forRoot()
|
CoreModule.forRoot()
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
|
FileDraggableDirective,
|
||||||
UploadDragAreaComponent
|
UploadDragAreaComponent
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
|
@@ -20,8 +20,6 @@ import { AlfrescoTranslationService, LogService, NotificationService } from 'ng2
|
|||||||
import { UploadService } from '../services/upload.service';
|
import { UploadService } from '../services/upload.service';
|
||||||
import { FileModel } from '../models/file.model';
|
import { FileModel } from '../models/file.model';
|
||||||
|
|
||||||
declare let componentHandler: any;
|
|
||||||
|
|
||||||
const ERROR_FOLDER_ALREADY_EXIST = 409;
|
const ERROR_FOLDER_ALREADY_EXIST = 409;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -42,6 +40,9 @@ export class UploadDragAreaComponent {
|
|||||||
|
|
||||||
private static DEFAULT_ROOT_ID: string = '-root-';
|
private static DEFAULT_ROOT_ID: string = '-root-';
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
enabled: boolean = true;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
showNotificationBar: boolean = true;
|
showNotificationBar: boolean = true;
|
||||||
|
|
||||||
@@ -73,15 +74,16 @@ export class UploadDragAreaComponent {
|
|||||||
onUploadFiles(e: CustomEvent) {
|
onUploadFiles(e: CustomEvent) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
if (this.enabled) {
|
||||||
let files: File[] = e.detail.files;
|
let files: File[] = e.detail.files;
|
||||||
if (files && files.length > 0) {
|
if (files && files.length > 0) {
|
||||||
const fileModels = files.map(f => new FileModel(f, { newVersion: this.versioning }));
|
const fileModels = files.map(f => new FileModel(f, { newVersion: this.versioning }));
|
||||||
if (e.detail.data.obj.entry.isFolder) {
|
if (e.detail.data.obj.entry.isFolder) {
|
||||||
let id = e.detail.data.obj.entry.id;
|
let id = e.detail.data.obj.entry.id;
|
||||||
this.onFilesDropped(fileModels, id, '/');
|
this.onFilesDropped(fileModels, id, '/');
|
||||||
} else {
|
} else {
|
||||||
this.onFilesDropped(fileModels);
|
this.onFilesDropped(fileModels);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +94,7 @@ export class UploadDragAreaComponent {
|
|||||||
* @param {File[]} files - files dropped in the drag area.
|
* @param {File[]} files - files dropped in the drag area.
|
||||||
*/
|
*/
|
||||||
onFilesDropped(files: FileModel[], rootId?: string, directory?: string): void {
|
onFilesDropped(files: FileModel[], rootId?: string, directory?: string): void {
|
||||||
if (files.length) {
|
if (this.enabled && files.length) {
|
||||||
this.uploadService.addToQueue(...files);
|
this.uploadService.addToQueue(...files);
|
||||||
this.uploadService.uploadFilesInTheQueue(rootId || this.rootFolderId, directory || this.currentFolderPath, this.onSuccess);
|
this.uploadService.uploadFilesInTheQueue(rootId || this.rootFolderId, directory || this.currentFolderPath, this.onSuccess);
|
||||||
let latestFilesAdded = this.uploadService.getQueue();
|
let latestFilesAdded = this.uploadService.getQueue();
|
||||||
@@ -107,13 +109,15 @@ export class UploadDragAreaComponent {
|
|||||||
* @param item - FileEntity
|
* @param item - FileEntity
|
||||||
*/
|
*/
|
||||||
onFilesEntityDropped(item: any): void {
|
onFilesEntityDropped(item: any): void {
|
||||||
item.file((file: File) => {
|
if (this.enabled) {
|
||||||
const fileModel = new FileModel(file, { newVersion: this.versioning });
|
item.file((file: File) => {
|
||||||
this.uploadService.addToQueue(fileModel);
|
const fileModel = new FileModel(file, { newVersion: this.versioning });
|
||||||
let path = item.fullPath.replace(item.name, '');
|
this.uploadService.addToQueue(fileModel);
|
||||||
let filePath = this.currentFolderPath + path;
|
let path = item.fullPath.replace(item.name, '');
|
||||||
this.uploadService.uploadFilesInTheQueue(this.rootFolderId, filePath, this.onSuccess);
|
let filePath = this.currentFolderPath + path;
|
||||||
});
|
this.uploadService.uploadFilesInTheQueue(this.rootFolderId, filePath, this.onSuccess);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,7 +125,7 @@ export class UploadDragAreaComponent {
|
|||||||
* @param folder - name of the dropped folder
|
* @param folder - name of the dropped folder
|
||||||
*/
|
*/
|
||||||
onFolderEntityDropped(folder: any): void {
|
onFolderEntityDropped(folder: any): void {
|
||||||
if (folder.isDirectory) {
|
if (this.enabled && folder.isDirectory) {
|
||||||
let relativePath = folder.fullPath.replace(folder.name, '');
|
let relativePath = folder.fullPath.replace(folder.name, '');
|
||||||
relativePath = this.currentFolderPath + relativePath;
|
relativePath = this.currentFolderPath + relativePath;
|
||||||
|
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { ElementRef } from '@angular/core';
|
||||||
import { FileDraggableDirective } from '../directives/file-draggable.directive';
|
import { FileDraggableDirective } from '../directives/file-draggable.directive';
|
||||||
|
|
||||||
describe('FileDraggableDirective', () => {
|
describe('FileDraggableDirective', () => {
|
||||||
@@ -22,7 +23,22 @@ describe('FileDraggableDirective', () => {
|
|||||||
let component: FileDraggableDirective;
|
let component: FileDraggableDirective;
|
||||||
|
|
||||||
beforeEach( () => {
|
beforeEach( () => {
|
||||||
component = new FileDraggableDirective(null, null);
|
let el = new ElementRef(null);
|
||||||
|
component = new FileDraggableDirective(el, null);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should always be enabled by default', () => {
|
||||||
|
expect(component.enabled).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not allow drad and drop when disabled', () => {
|
||||||
|
component.enabled = false;
|
||||||
|
let event = new CustomEvent('custom-event');
|
||||||
|
spyOn(event, 'preventDefault').and.stub();
|
||||||
|
component.onDropFiles(event);
|
||||||
|
component.onDragEnter(event);
|
||||||
|
component.onDragLeave(event);
|
||||||
|
expect(event.preventDefault).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Directive, EventEmitter, Output, OnInit, OnDestroy, ElementRef, NgZone } from '@angular/core';
|
import { Directive, EventEmitter, Input, Output, OnInit, OnDestroy, ElementRef, NgZone } from '@angular/core';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [file-draggable]
|
* [file-draggable]
|
||||||
@@ -35,6 +35,9 @@ export class FileDraggableDirective implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
files: File [];
|
files: File [];
|
||||||
|
|
||||||
|
@Input('file-draggable')
|
||||||
|
enabled: boolean = true;
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
onFilesDropped: EventEmitter<any> = new EventEmitter();
|
onFilesDropped: EventEmitter<any> = new EventEmitter();
|
||||||
|
|
||||||
@@ -72,7 +75,7 @@ export class FileDraggableDirective implements OnInit, OnDestroy {
|
|||||||
* @param event DOM event.
|
* @param event DOM event.
|
||||||
*/
|
*/
|
||||||
onDropFiles(event: any): void {
|
onDropFiles(event: any): void {
|
||||||
if (!event.defaultPrevented) {
|
if (this.enabled && !event.defaultPrevented) {
|
||||||
this.preventDefault(event);
|
this.preventDefault(event);
|
||||||
|
|
||||||
let items = event.dataTransfer.items;
|
let items = event.dataTransfer.items;
|
||||||
@@ -120,7 +123,7 @@ export class FileDraggableDirective implements OnInit, OnDestroy {
|
|||||||
* @param {event} event - DOM event.
|
* @param {event} event - DOM event.
|
||||||
*/
|
*/
|
||||||
onDragEnter(event: Event): void {
|
onDragEnter(event: Event): void {
|
||||||
if (!event.defaultPrevented) {
|
if (this.enabled && !event.defaultPrevented) {
|
||||||
this.preventDefault(event);
|
this.preventDefault(event);
|
||||||
this.element.classList.add(this.cssClassName);
|
this.element.classList.add(this.cssClassName);
|
||||||
}
|
}
|
||||||
@@ -132,7 +135,7 @@ export class FileDraggableDirective implements OnInit, OnDestroy {
|
|||||||
* @param {event} event - DOM event.
|
* @param {event} event - DOM event.
|
||||||
*/
|
*/
|
||||||
onDragLeave(event: Event): void {
|
onDragLeave(event: Event): void {
|
||||||
if (!event.defaultPrevented) {
|
if (this.enabled && !event.defaultPrevented) {
|
||||||
this.preventDefault(event);
|
this.preventDefault(event);
|
||||||
this.element.classList.remove(this.cssClassName);
|
this.element.classList.remove(this.cssClassName);
|
||||||
}
|
}
|
||||||
@@ -144,7 +147,7 @@ export class FileDraggableDirective implements OnInit, OnDestroy {
|
|||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
onDragOver(event: Event): void {
|
onDragOver(event: Event): void {
|
||||||
if (!event.defaultPrevented) {
|
if (this.enabled && !event.defaultPrevented) {
|
||||||
this.preventDefault(event);
|
this.preventDefault(event);
|
||||||
this.element.classList.add(this.cssClassName);
|
this.element.classList.add(this.cssClassName);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user