From b815034ef8716b93eee2bffcb75adf7468a0f3e9 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Fri, 2 Jun 2017 14:05:55 +0100 Subject: [PATCH] [ADF-571] upload feature rework (#1922) * upload feature rework lots of improvements for upload dialog and underlying services * readme update - readme cleanup - remove some old comments from code - update readme with new events for Upload Service * restore prerequisites section in readme --- .../src/services/alfresco-content.service.ts | 17 ++++++++++++ .../src/components/upload-button.component.ts | 18 +++++++++++++ .../src/events/folder-created.event.ts | 27 ------------------- .../src/models/file.model.ts | 4 --- 4 files changed, 35 insertions(+), 31 deletions(-) delete mode 100644 ng2-components/ng2-alfresco-upload/src/events/folder-created.event.ts diff --git a/ng2-components/ng2-alfresco-core/src/services/alfresco-content.service.ts b/ng2-components/ng2-alfresco-core/src/services/alfresco-content.service.ts index 774e9fb107..62197e47e4 100644 --- a/ng2-components/ng2-alfresco-core/src/services/alfresco-content.service.ts +++ b/ng2-components/ng2-alfresco-core/src/services/alfresco-content.service.ts @@ -88,6 +88,23 @@ export class AlfrescoContentService { .catch(err => this.handleError(err)); } + /** + * Create a folder + * @param name - the folder name + */ + createFolder(relativePath: string, name: string, parentId?: string): Observable { + return Observable.fromPromise(this.apiService.getInstance().nodes.createFolder(name, relativePath, parentId)) + .do(data => { + this.folderCreated.next({ + relativePath: relativePath, + name: name, + parentId: parentId, + node: data + }); + }) + .catch(err => this.handleError(err)); + } + private handleError(error: any) { this.logService.error(error); return Observable.throw(error || 'Server error'); diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts index 5091ce1d80..8f6d4538ef 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts @@ -190,6 +190,7 @@ export class UploadButtonComponent implements OnInit, OnChanges { error => this.onError.emit(error) ); } + return 'Error'; } // TODO: move to AlfrescoContentService @@ -210,6 +211,23 @@ export class UploadButtonComponent implements OnInit, OnChanges { return Observable.throw(error || 'Server error'); } + getFolderNode(nodeId: string): Observable { + let opts: any = { + includeSource: true, + include: ['allowableOperations'] + }; + + return Observable.fromPromise(this.apiService.getInstance().nodes.getNodeInfo(nodeId, opts)) + .catch(err => this.handleError(err)); + } + + private handleError(error: Response) { + // in a real world app, we may send the error to some remote logging infrastructure + // instead of just logging it to the console + this.logService.error(error); + return Observable.throw(error || 'Server error'); + } + private hasCreatePermission(node: any): boolean { if (node && node.allowableOperations) { return node.allowableOperations.find(permision => permision === 'create') ? true : false; diff --git a/ng2-components/ng2-alfresco-upload/src/events/folder-created.event.ts b/ng2-components/ng2-alfresco-upload/src/events/folder-created.event.ts deleted file mode 100644 index 8051498adf..0000000000 --- a/ng2-components/ng2-alfresco-upload/src/events/folder-created.event.ts +++ /dev/null @@ -1,27 +0,0 @@ -/*! - * @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 { MinimalNodeEntity } from 'alfresco-js-api'; - -export interface FolderCreatedEvent { - - name: string; - relativePath?: string; - parentId?: string; - node?: MinimalNodeEntity; - -} diff --git a/ng2-components/ng2-alfresco-upload/src/models/file.model.ts b/ng2-components/ng2-alfresco-upload/src/models/file.model.ts index ac1c6f600e..5edfe8fc3c 100644 --- a/ng2-components/ng2-alfresco-upload/src/models/file.model.ts +++ b/ng2-components/ng2-alfresco-upload/src/models/file.model.ts @@ -72,7 +72,3 @@ export class FileModel { }); } } - -export interface FileUploadOptions { - newVersion?: boolean; -}