mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
[ADF-2563] Improve versioning functionality (#3335)
* change input with textarea * update file version use now the update content API * provide way to test read only mode version list * fix test * test fix
This commit is contained in:
parent
9772b2308a
commit
9e3a4aa49f
@ -9,7 +9,8 @@
|
||||
"ADF_VERSION_MANAGER": {
|
||||
"ALLOW_DELETE": "Allow delete",
|
||||
"SHOW_COMMENTS" : "Show comments on versions",
|
||||
"ALLOW_DOWNLOAD" :"Enable version download"
|
||||
"ALLOW_DOWNLOAD" :"Enable version download",
|
||||
"READ_ONLY" : "Read only"
|
||||
}
|
||||
},
|
||||
"title": "Welcome",
|
||||
|
@ -1,7 +1,18 @@
|
||||
<header mat-dialog-title>{{'VERSION.DIALOG.TITLE' | translate}}</header>
|
||||
<section mat-dialog-content>
|
||||
|
||||
<section>
|
||||
<mat-slide-toggle color="primary" [(ngModel)]="readOnly">
|
||||
{{'APP.ADF_VERSION_MANAGER.READ_ONLY' | translate}}
|
||||
</mat-slide-toggle>
|
||||
</section>
|
||||
|
||||
<section mat-dialog-content *ngIf="!readOnly">
|
||||
<adf-version-manager [node]="contentEntry" [allowDownload]="allowDownload" [showComments]="showComments" (uploadError)="uploadError($event)"></adf-version-manager>
|
||||
</section>
|
||||
<section mat-dialog-content *ngIf="readOnly">
|
||||
<adf-version-list [node]="contentEntry" [showActions]="false" ></adf-version-list>
|
||||
</section>
|
||||
|
||||
<footer mat-dialog-actions fxLayout="row" fxLayoutAlign="end center">
|
||||
<button mat-button (click)="close()">{{'VERSION.DIALOG.CLOSE' | translate}}</button>
|
||||
</footer>
|
||||
|
@ -30,6 +30,7 @@ export class VersionManagerDialogAdapterComponent {
|
||||
|
||||
showComments = true;
|
||||
allowDownload = true;
|
||||
readOnly = false;
|
||||
|
||||
constructor(@Inject(MAT_DIALOG_DATA) data: any,
|
||||
private snackBar: MatSnackBar,
|
||||
|
@ -31,6 +31,13 @@ Displays the version history of a node in a Version Manager component.
|
||||
This component is used by the Version Manager component to
|
||||
load and displays the version history of a node.
|
||||
|
||||
If you want show readonly version list you set this component with showActions false:
|
||||
|
||||
```html
|
||||
<adf-version-list [node]="myNode" [showActions]="false" ></adf-version-list>
|
||||
```
|
||||
|
||||
|
||||
## See also
|
||||
|
||||
- [Version manager component](version-manager.component.md)
|
||||
|
@ -59,8 +59,6 @@ describe('UploadBase', () => {
|
||||
fixture = TestBed.createComponent(UploadTestComponent);
|
||||
uploadService = TestBed.get(UploadService);
|
||||
|
||||
spyOn(FileModel.prototype, 'generateId').and.returnValue('test');
|
||||
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
@ -137,7 +137,7 @@ export abstract class UploadBase {
|
||||
*
|
||||
* @param file
|
||||
*/
|
||||
protected createFileModel(file: File, parentId: string, path: string): FileModel {
|
||||
protected createFileModel(file: File, parentId: string, path: string, id?: string): FileModel {
|
||||
return new FileModel(file, {
|
||||
comment: this.comment,
|
||||
majorVersion: this.majorVersion,
|
||||
@ -145,7 +145,7 @@ export abstract class UploadBase {
|
||||
parentId: parentId,
|
||||
path: path,
|
||||
nodeType: this.nodeType
|
||||
});
|
||||
}, id);
|
||||
}
|
||||
|
||||
protected isFileSizeAllowed(file: FileModel) {
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { PermissionsEnum } from '@alfresco/adf-core';
|
||||
import { Component, forwardRef, Input, OnChanges, SimpleChanges, ViewEncapsulation, OnInit } from '@angular/core';
|
||||
import { Component, forwardRef, Input, OnChanges, ViewEncapsulation, OnInit } from '@angular/core';
|
||||
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||
import { UploadButtonComponent } from './upload-button.component';
|
||||
import { FileModel, EXTENDIBLE_COMPONENT } from '@alfresco/adf-core';
|
||||
@ -36,20 +36,8 @@ export class UploadVersionButtonComponent extends UploadButtonComponent implemen
|
||||
@Input()
|
||||
node: MinimalNodeEntryEntity;
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
super.ngOnChanges(changes);
|
||||
|
||||
if (changes['acceptedFilesType']) {
|
||||
const message = this.translationService.instant('FILE_UPLOAD.VERSION.MESSAGES.NO_ACCEPTED_FILE_TYPES');
|
||||
this.logService.error(message);
|
||||
}
|
||||
this.acceptedFilesType = '.' + this.node.name.split('.').pop();
|
||||
}
|
||||
|
||||
protected createFileModel(file: File): FileModel {
|
||||
const fileModel = super.createFileModel(file, this.rootFolderId, (file.webkitRelativePath || '').replace(/\/[^\/]*$/, ''));
|
||||
|
||||
fileModel.options.newVersionBaseName = this.node.name;
|
||||
const fileModel = super.createFileModel(file, this.rootFolderId, (file.webkitRelativePath || '').replace(/\/[^\/]*$/, ''), this.node.id);
|
||||
|
||||
if (!this.isFileAcceptable(fileModel)) {
|
||||
const message = this.translationService.instant('FILE_UPLOAD.VERSION.MESSAGES.INCOMPATIBLE_VERSION');
|
||||
|
@ -10,8 +10,8 @@
|
||||
</mat-radio-button>
|
||||
</mat-radio-group>
|
||||
<mat-form-field class="adf-new-version-max-width">
|
||||
<input matInput [(ngModel)]="comment"
|
||||
placeholder="{{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.COMMENT' | translate }}">
|
||||
<textarea matInput [(ngModel)]="comment" class="adf-new-version-text-area"
|
||||
placeholder="{{ 'ADF_VERSION_LIST.ACTIONS.UPLOAD.COMMENT' | translate }}"></textarea>
|
||||
</mat-form-field>
|
||||
|
||||
</div>
|
||||
|
@ -20,3 +20,8 @@
|
||||
width: 100%;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.adf-new-version-text-area {
|
||||
resize: none !important;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@ export interface FileUploadOptions {
|
||||
comment?: string;
|
||||
newVersion?: boolean;
|
||||
majorVersion?: boolean;
|
||||
newVersionBaseName?: string;
|
||||
parentId?: string;
|
||||
path?: string;
|
||||
nodeType?: string;
|
||||
@ -43,20 +42,19 @@ export enum FileUploadStatus {
|
||||
}
|
||||
|
||||
export class FileModel {
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
readonly size: number;
|
||||
readonly file: File;
|
||||
|
||||
id: string;
|
||||
status: FileUploadStatus = FileUploadStatus.Pending;
|
||||
progress: FileUploadProgress;
|
||||
options: FileUploadOptions;
|
||||
data: any;
|
||||
|
||||
constructor(file: File, options?: FileUploadOptions) {
|
||||
constructor(file: File, options?: FileUploadOptions, id?: string) {
|
||||
this.file = file;
|
||||
|
||||
this.id = this.generateId();
|
||||
this.id = id;
|
||||
this.name = file.name;
|
||||
this.size = file.size;
|
||||
this.data = null;
|
||||
@ -72,13 +70,6 @@ export class FileModel {
|
||||
}, options);
|
||||
}
|
||||
|
||||
generateId(): string {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
get extension(): string {
|
||||
return this.name.slice((Math.max(0, this.name.lastIndexOf('.')) || Infinity) + 1);
|
||||
}
|
||||
|
@ -161,18 +161,16 @@ describe('UploadService', () => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().params.has('majorVersion')).toBe(false);
|
||||
});
|
||||
|
||||
it('If newVersionBaseName is set, name should be a param', () => {
|
||||
it('If newVersion is set, name should be a param', () => {
|
||||
let emitter = new EventEmitter();
|
||||
|
||||
const filesFake = new FileModel(<File> { name: 'fake-name', size: 10 }, {
|
||||
newVersion: true,
|
||||
newVersionBaseName: 'name-under-test'
|
||||
newVersion: true
|
||||
});
|
||||
service.addToQueue(filesFake);
|
||||
service.uploadFilesInTheQueue(emitter);
|
||||
|
||||
expect(jasmine.Ajax.requests.mostRecent().params.has('name')).toBe(true);
|
||||
expect(jasmine.Ajax.requests.mostRecent().params.get('name')).toBe('name-under-test');
|
||||
});
|
||||
|
||||
it('should use custom root folder ID given to the service', (done) => {
|
||||
|
@ -52,9 +52,8 @@ export class UploadService {
|
||||
fileUploadDeleted: Subject<FileUploadDeleteEvent> = new Subject<FileUploadDeleteEvent>();
|
||||
fileDeleted: Subject<string> = new Subject<string>();
|
||||
|
||||
constructor(
|
||||
protected apiService: AlfrescoApiService,
|
||||
appConfigService: AppConfigService) {
|
||||
constructor(protected apiService: AlfrescoApiService,
|
||||
appConfigService: AppConfigService) {
|
||||
this.excludedFileList = <String[]> appConfigService.get('files.excluded');
|
||||
}
|
||||
|
||||
@ -164,25 +163,32 @@ export class UploadService {
|
||||
opts.overwrite = true;
|
||||
opts.majorVersion = file.options.majorVersion;
|
||||
opts.comment = file.options.comment;
|
||||
opts.name = file.name;
|
||||
} else {
|
||||
opts.autoRename = true;
|
||||
}
|
||||
|
||||
if (file.options.newVersionBaseName) {
|
||||
opts.name = file.options.newVersionBaseName;
|
||||
}
|
||||
|
||||
if (file.options.nodeType) {
|
||||
opts.nodeType = file.options.nodeType;
|
||||
}
|
||||
|
||||
return this.apiService.getInstance().upload.uploadFile(
|
||||
file.file,
|
||||
file.options.path,
|
||||
file.options.parentId,
|
||||
null,
|
||||
opts
|
||||
);
|
||||
if (file.id) {
|
||||
return this.apiService.getInstance().upload.updateFile(
|
||||
file.file,
|
||||
file.options.path,
|
||||
file.id,
|
||||
file.file,
|
||||
opts
|
||||
);
|
||||
} else {
|
||||
return this.apiService.getInstance().upload.uploadFile(
|
||||
file.file,
|
||||
file.options.path,
|
||||
file.options.parentId,
|
||||
null,
|
||||
opts
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private beginUpload(file: FileModel, /* @deprecated */emitter: EventEmitter<any>): any {
|
||||
|
Loading…
x
Reference in New Issue
Block a user