mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACA-4325] - disable upload button on upload new file version begin (#7017)
* [ACA-4325] - disable upload button on upload version begin * Update upload-base.spec.ts * disable upload button only on version upload component * PR changes * change to started Co-authored-by: Eugenio Romano <eromano@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,96 @@
|
|||||||
|
/*!
|
||||||
|
* @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 { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||||
|
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { VersionUploadComponent } from 'content-services';
|
||||||
|
import { ContentService, setupTestBed, UploadService } from '@alfresco/adf-core';
|
||||||
|
import { ContentTestingModule } from '../testing/content.testing.module';
|
||||||
|
import { Node } from '@alfresco/js-api';
|
||||||
|
|
||||||
|
describe('VersionUploadComponent', () => {
|
||||||
|
let component: VersionUploadComponent;
|
||||||
|
let fixture: ComponentFixture<VersionUploadComponent>;
|
||||||
|
let uploadService: UploadService;
|
||||||
|
let contentService: ContentService;
|
||||||
|
|
||||||
|
const node: Node = new Node({
|
||||||
|
id: '1234',
|
||||||
|
name: 'TEST-NODE',
|
||||||
|
isFile: true,
|
||||||
|
nodeType: 'FAKE',
|
||||||
|
isFolder: false,
|
||||||
|
modifiedAt: new Date(),
|
||||||
|
modifiedByUser: null,
|
||||||
|
createdAt: new Date(),
|
||||||
|
createdByUser: null,
|
||||||
|
content: {
|
||||||
|
mimeType: 'text/html',
|
||||||
|
mimeTypeName: 'HTML',
|
||||||
|
sizeInBytes: 13
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setupTestBed({
|
||||||
|
imports: [
|
||||||
|
TranslateModule.forRoot(),
|
||||||
|
ContentTestingModule
|
||||||
|
],
|
||||||
|
providers: [UploadService],
|
||||||
|
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(VersionUploadComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
uploadService = TestBed.inject(UploadService);
|
||||||
|
contentService = TestBed.inject(ContentService);
|
||||||
|
spyOn(contentService, 'hasAllowableOperations').and.returnValue(true);
|
||||||
|
component.node = node;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should disabled upload button on upload starts', fakeAsync(() => {
|
||||||
|
component.uploadStarted.subscribe(() => {
|
||||||
|
expect(component.disabled).toEqual(true);
|
||||||
|
});
|
||||||
|
uploadService.fileUploadStarting.next();
|
||||||
|
tick(500);
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should enable upload button on error', (done) => {
|
||||||
|
spyOn(component, 'canUpload').and.returnValue(true);
|
||||||
|
component.error.subscribe(() => {
|
||||||
|
expect(component.disabled).toEqual(false);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
component.onError(true);
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should enable upload button on success', (done) => {
|
||||||
|
spyOn(component, 'canUpload').and.returnValue(true);
|
||||||
|
component.success.subscribe(() => {
|
||||||
|
expect(component.disabled).toEqual(false);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
component.onSuccess(true);
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@@ -15,9 +15,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, Input, ViewEncapsulation, Output, EventEmitter } from '@angular/core';
|
import { Component, Input, ViewEncapsulation, Output, EventEmitter, OnInit, OnDestroy } from '@angular/core';
|
||||||
import { Node } from '@alfresco/js-api';
|
import { Node } from '@alfresco/js-api';
|
||||||
import { ContentService } from '@alfresco/adf-core';
|
import { ContentService, FileUploadEvent, UploadService } from '@alfresco/adf-core';
|
||||||
|
import { Subject } from 'rxjs';
|
||||||
|
import { takeUntil } from 'rxjs/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-version-upload',
|
selector: 'adf-version-upload',
|
||||||
@@ -26,11 +28,13 @@ import { ContentService } from '@alfresco/adf-core';
|
|||||||
encapsulation: ViewEncapsulation.None,
|
encapsulation: ViewEncapsulation.None,
|
||||||
host: { 'class': 'adf-version-upload' }
|
host: { 'class': 'adf-version-upload' }
|
||||||
})
|
})
|
||||||
export class VersionUploadComponent {
|
export class VersionUploadComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
semanticVersion: string = 'minor';
|
semanticVersion: string = 'minor';
|
||||||
comment: string;
|
comment: string;
|
||||||
uploadVersion: boolean = false;
|
uploadVersion: boolean = false;
|
||||||
|
disabled: boolean = false;
|
||||||
|
onDestroy$ = new Subject();
|
||||||
|
|
||||||
/** The target node. */
|
/** The target node. */
|
||||||
@Input()
|
@Input()
|
||||||
@@ -68,11 +72,24 @@ export class VersionUploadComponent {
|
|||||||
@Output()
|
@Output()
|
||||||
commentChanged = new EventEmitter<string>();
|
commentChanged = new EventEmitter<string>();
|
||||||
|
|
||||||
constructor(private contentService: ContentService) {
|
/** Emitted when the upload starts */
|
||||||
|
@Output()
|
||||||
|
uploadStarted = new EventEmitter<FileUploadEvent>();
|
||||||
|
|
||||||
|
constructor(private contentService: ContentService, private uploadService: UploadService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.uploadService.fileUploadStarting
|
||||||
|
.pipe(takeUntil(this.onDestroy$))
|
||||||
|
.subscribe((event: FileUploadEvent) => {
|
||||||
|
this.disabled = true;
|
||||||
|
this.uploadStarted.emit(event);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
canUpload(): boolean {
|
canUpload(): boolean {
|
||||||
return this.contentService.hasAllowableOperations(this.node, 'update');
|
return this.contentService.hasAllowableOperations(this.node, 'update') && !this.disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
isMajorVersion(): boolean {
|
isMajorVersion(): boolean {
|
||||||
@@ -80,6 +97,7 @@ export class VersionUploadComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cancelUpload() {
|
cancelUpload() {
|
||||||
|
this.disabled = false;
|
||||||
this.cancel.emit();
|
this.cancel.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,11 +110,18 @@ export class VersionUploadComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onSuccess(event: any) {
|
onSuccess(event: any) {
|
||||||
|
this.disabled = false;
|
||||||
this.success.emit(event);
|
this.success.emit(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
onError(event: any) {
|
onError(event: any) {
|
||||||
|
this.disabled = false;
|
||||||
this.error.emit(event);
|
this.error.emit(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.onDestroy$.next();
|
||||||
|
this.onDestroy$.complete();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user