mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
* [AAE-6242] Create upload new version dialog to handle the upload of the new file version * [AAE-6242] Create version manager service to open version manager dialog * [AAE-6242] Export service and dialog * [AAE-6242] add adf-upload button to the show the upload new file button * [AAE-6242] open upload new version dialog * [AAE-6242] Removed console log * [AAE-8798] display update option name to newVersion * [AAE-8799] Emit version manager data when new file version is uploaded * [AAE-8799] When a new file version is uploaded open new version dialog and update current file version with the new file version * [AAE-8799] Rename UploadNewVersionDialogComponent to VersionManagerDialogComponent and UploadNewVersionDialogData to VersionManagerDialogData * [AAE-8799] Use default root folder id * [AAE-8799] Add #uploadSingleFile ViewChild in order get the input reference * [AAE-8799] Trigger adf-upload-button by clicking on the button in order to open the file chooser and upload a new file version * [AAE-8799] Version manager dialog emits file upload error * [AAE-8799] Format version manager dialog code * [AAE-8799] Reject upload and permission errors * [AAE-8799] Catch upload new version errors * [AAE-8799] Update allowable operation type * [AAE-8799] Rename VersionManagerDialogComponent into NewVersionUploaderDialogComponent and VersionManagerService into NewVersionUploaderService, create specific folder for new version uploader component and service * Restore previous UploadButtonComponent version * [AAE-8799] Use [adf-upload] directive to upload new file version * [AAE-8799] Add mock file for new version uploader unit tests * [AAE-8799] Override mat dialog configuration * [AAE-8799] Add unit test related to event emitted from Dialog * [AAE-8799] Create model to handle New Version Uploader data * [AAE-8799] Return data on dialog close * [AAE-8799] Add showVersionsOnly property to dialog to show only file version list * [AAE-8799] Add dialogAction to emit dialog actions * [AAE-8799] Return observable instead of promise * [AAE-8799] Update new file version type * [AAE-8799] Subscribe dialog because return an Observable * [AAE-8799] Add license header * [AAE-8799] Add i18n new version uploader translations * [AAE-8799] If data.title is not provided, add a default title * [AAE-8799] Change panelClass for manage versions visualizations, add dialog styles * [AAE-8799] Add upload new version dialog unit test * [AAE-8799] Add upload new version dialog unit test related to manage versions section * [AAE-8799] Add onUploadNewFileVersion unit tests * [AAE-8799] Test new dialog panelClass * [AAE-8799] Create a method to set dialog title, if title isn't provided from parent component, a default title is set * [AAE-8799] Add doc to new-version-uploader-dilog component and service * [AAE-8799] Add new-version-uploader.dialog.service documentation
87 lines
3.9 KiB
TypeScript
87 lines
3.9 KiB
TypeScript
/*!
|
|
* @license
|
|
* Copyright 2019 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 { Injectable } from '@angular/core';
|
|
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
|
|
import { AlfrescoApiService, ContentService } from '@alfresco/adf-core';
|
|
|
|
import { NewVersionUploaderDialogComponent } from './new-version-uploader.dialog';
|
|
import { VersionPaging, VersionsApi } from '@alfresco/js-api';
|
|
import { NewVersionUploaderData, NewVersionUploaderDialogData } from './models';
|
|
import { Observable } from 'rxjs';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class NewVersionUploaderService {
|
|
|
|
_versionsApi: VersionsApi;
|
|
get versionsApi(): VersionsApi {
|
|
this._versionsApi = this._versionsApi ?? new VersionsApi(this.apiService.getInstance());
|
|
return this._versionsApi;
|
|
}
|
|
|
|
constructor(
|
|
private contentService: ContentService,
|
|
private apiService: AlfrescoApiService,
|
|
private dialog: MatDialog
|
|
) { }
|
|
|
|
/**
|
|
* Open a dialog NewVersionUploaderDialogComponent to display:
|
|
* - a side by side comparison between the current target node (type, name, icon) and the new file that should update it's version
|
|
* - the new version's minor/major changes and the optional comment of a node and the ability to upload a new file version
|
|
* - if data.showVersionsOnly is set to true, displays the version history of a node, with the ability to restore, delete and view version of the current node
|
|
* @param data data to pass to MatDialog
|
|
* @param config allow to override default MatDialogConfig
|
|
* @returns an Observable represents the triggered dialog action or an error in case of an error condition
|
|
*/
|
|
openUploadNewVersionDialog(data: NewVersionUploaderDialogData, config?: MatDialogConfig) {
|
|
const { file, node, showVersionsOnly } = data;
|
|
const showComments = true;
|
|
const allowDownload = true;
|
|
|
|
return new Observable((observer) => {
|
|
if (this.contentService.hasAllowableOperations(node, 'update')) {
|
|
this.versionsApi.listVersionHistory(node.id).then((versionPaging: VersionPaging) => {
|
|
const dialogRef = this.dialog.open(NewVersionUploaderDialogComponent, {
|
|
data: { file, node, currentVersion: versionPaging.list.entries[0].entry, showComments, allowDownload, showVersionsOnly },
|
|
panelClass: this.composePanelClass(showVersionsOnly),
|
|
width: '630px',
|
|
...(config && Object.keys(config).length > 0 && config)
|
|
});
|
|
dialogRef.componentInstance.dialogAction.asObservable()
|
|
.subscribe((newVersionUploaderData: NewVersionUploaderData) => {
|
|
observer.next(newVersionUploaderData);
|
|
});
|
|
dialogRef.componentInstance.uploadError.asObservable().subscribe(error => {
|
|
observer.error(error);
|
|
});
|
|
});
|
|
} else {
|
|
observer.error({ value: 'OPERATION.ERROR.PERMISSION' });
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
private composePanelClass(showVersionsOnly: boolean): string | string[] {
|
|
const dialogCssClass = 'adf-new-version-uploader-dialog';
|
|
return [dialogCssClass, `${dialogCssClass}-${showVersionsOnly ? 'list' : 'upload'}`];
|
|
}
|
|
}
|