mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
57
lib/process-services/attachment/attachment.module.ts
Normal file
57
lib/process-services/attachment/attachment.module.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
/*!
|
||||
* @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 { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { MaterialModule } from '../material.module';
|
||||
import { DataColumnModule, DataTableModule, DirectiveModule } from '@alfresco/core';
|
||||
|
||||
import { TaskAttachmentListComponent } from './task-attachment-list.component';
|
||||
import { ProcessAttachmentListComponent } from './process-attachment-list.component';
|
||||
import { CreateProcessAttachmentComponent } from './create-process-attachment.component';
|
||||
import { AttachmentComponent } from './create-task-attachment.component';
|
||||
import { ProcessUploadService } from '../task-list/services/process-upload.service';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
DataColumnModule,
|
||||
DataTableModule,
|
||||
MaterialModule,
|
||||
CommonModule,
|
||||
TranslateModule,
|
||||
DirectiveModule
|
||||
],
|
||||
providers: [
|
||||
ProcessUploadService
|
||||
],
|
||||
declarations: [
|
||||
TaskAttachmentListComponent,
|
||||
ProcessAttachmentListComponent,
|
||||
CreateProcessAttachmentComponent,
|
||||
CreateProcessAttachmentComponent,
|
||||
AttachmentComponent
|
||||
],
|
||||
exports: [
|
||||
TaskAttachmentListComponent,
|
||||
ProcessAttachmentListComponent,
|
||||
CreateProcessAttachmentComponent,
|
||||
CreateProcessAttachmentComponent,
|
||||
AttachmentComponent
|
||||
]
|
||||
})
|
||||
export class AttachmentModule {}
|
@@ -0,0 +1,5 @@
|
||||
.adf-create-attachment {
|
||||
display: inline-block;
|
||||
line-height: 0px;
|
||||
vertical-align: middle;
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
<button
|
||||
id="add_new_process_content_button"
|
||||
color="primary"
|
||||
mat-button
|
||||
mat-raised-button
|
||||
mat-icon-button
|
||||
class="adf-create-attachment"
|
||||
[adf-upload]="true"
|
||||
mode="['click']"
|
||||
[multiple]="true"
|
||||
(upload-files)="onFileUpload($event)">
|
||||
<mat-icon>add</mat-icon>
|
||||
</button>
|
@@ -0,0 +1,132 @@
|
||||
/*!
|
||||
* @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 { SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MaterialModule } from '../material.module';
|
||||
import { ProcessContentService } from '@alfresco/core';
|
||||
import { TranslationService } from '@alfresco/core';
|
||||
import { CreateProcessAttachmentComponent } from './create-process-attachment.component';
|
||||
|
||||
declare let jasmine: any;
|
||||
|
||||
describe('Activiti Process Create Attachment', () => {
|
||||
|
||||
let service: ProcessContentService;
|
||||
let component: CreateProcessAttachmentComponent;
|
||||
let fixture: ComponentFixture<CreateProcessAttachmentComponent>;
|
||||
let element: HTMLElement;
|
||||
|
||||
let file = new File([new Blob()], 'Test');
|
||||
let fileObj = { entry: null, file: file, relativeFolder: '/' };
|
||||
let customEvent = { detail: { files: [fileObj] } };
|
||||
|
||||
let fakeUploadResponse = {
|
||||
id: 9999,
|
||||
name: 'BANANA.jpeg',
|
||||
created: '2017-06-12T12:52:11.109Z',
|
||||
createdBy: { id: 2, firstName: 'fake-user', lastName: 'fake-user', email: 'fake-user' },
|
||||
relatedContent: false,
|
||||
contentAvailable: true,
|
||||
link: false,
|
||||
mimeType: 'image/jpeg',
|
||||
simpleType: 'image',
|
||||
previewStatus: 'queued',
|
||||
thumbnailStatus: 'queued'
|
||||
};
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
MaterialModule
|
||||
],
|
||||
declarations: [
|
||||
CreateProcessAttachmentComponent
|
||||
],
|
||||
providers: [
|
||||
{ provide: TranslationService },
|
||||
ProcessContentService
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CreateProcessAttachmentComponent);
|
||||
component = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(ProcessContentService);
|
||||
element = fixture.nativeElement;
|
||||
|
||||
component.processInstanceId = '9999';
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
it('should update the processInstanceId when it is changed', () => {
|
||||
component.processInstanceId = null;
|
||||
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({ 'processInstanceId': change });
|
||||
|
||||
expect(component.processInstanceId).toBe('123');
|
||||
});
|
||||
|
||||
it('should emit content created event when the file is uploaded', async(() => {
|
||||
component.success.subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).not.toBeNull();
|
||||
expect(res.id).toBe(9999);
|
||||
});
|
||||
|
||||
component.onFileUpload(customEvent);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeUploadResponse)
|
||||
});
|
||||
}));
|
||||
|
||||
it('should allow user to upload files via button', async(() => {
|
||||
let buttonUpload: HTMLElement = <HTMLElement> element.querySelector('#add_new_process_content_button');
|
||||
expect(buttonUpload).toBeDefined();
|
||||
expect(buttonUpload).not.toBeNull();
|
||||
|
||||
component.success.subscribe((res) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res).not.toBeNull();
|
||||
expect(res.id).toBe(9999);
|
||||
});
|
||||
|
||||
let dropEvent = new CustomEvent('upload-files', customEvent);
|
||||
buttonUpload.dispatchEvent(dropEvent);
|
||||
fixture.detectChanges();
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeUploadResponse)
|
||||
});
|
||||
}));
|
||||
|
||||
});
|
@@ -0,0 +1,63 @@
|
||||
/*!
|
||||
* @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 { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
|
||||
import { ProcessContentService } from '@alfresco/core';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-create-process-attachment',
|
||||
styleUrls: ['./create-process-attachment.component.css'],
|
||||
templateUrl: './create-process-attachment.component.html'
|
||||
})
|
||||
export class CreateProcessAttachmentComponent implements OnChanges {
|
||||
|
||||
@Input()
|
||||
processInstanceId: string;
|
||||
|
||||
@Output()
|
||||
error: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
@Output()
|
||||
success: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
constructor(private activitiContentService: ProcessContentService) {
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (changes['processInstanceId'] && changes['processInstanceId'].currentValue) {
|
||||
this.processInstanceId = changes['processInstanceId'].currentValue;
|
||||
}
|
||||
}
|
||||
|
||||
onFileUpload(event: any) {
|
||||
let filesList: File[] = event.detail.files.map(obj => obj.file);
|
||||
|
||||
for (let fileInfoObj of filesList) {
|
||||
let file: File = fileInfoObj;
|
||||
let opts = {
|
||||
isRelatedContent: true
|
||||
};
|
||||
this.activitiContentService.createProcessRelatedContent(this.processInstanceId, file, opts).subscribe(
|
||||
(res) => {
|
||||
this.success.emit(res);
|
||||
},
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
<button
|
||||
color="primary"
|
||||
mat-button
|
||||
mat-raised-button
|
||||
mat-icon-button
|
||||
class="adf-create-attachment"
|
||||
[adf-upload]="true"
|
||||
mode="['click']"
|
||||
[multiple]="true"
|
||||
(upload-files)="onFileUpload($event)">
|
||||
<mat-icon>add</mat-icon>
|
||||
</button>
|
@@ -0,0 +1,5 @@
|
||||
.adf-create-attachment {
|
||||
display: inline-block;
|
||||
line-height: 0px;
|
||||
vertical-align: middle;
|
||||
}
|
@@ -0,0 +1,91 @@
|
||||
/*!
|
||||
* @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 { SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MaterialModule } from '../material.module';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
|
||||
import { ProcessContentService } from '@alfresco/core';
|
||||
import { AttachmentComponent } from './create-task-attachment.component';
|
||||
|
||||
describe('Activiti Task Create Attachment', () => {
|
||||
|
||||
let service: ProcessContentService;
|
||||
let component: AttachmentComponent;
|
||||
let fixture: ComponentFixture<AttachmentComponent>;
|
||||
let createTaskRelatedContentSpy: jasmine.Spy;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
MaterialModule
|
||||
],
|
||||
declarations: [
|
||||
AttachmentComponent
|
||||
],
|
||||
providers: [
|
||||
ProcessContentService
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
fixture = TestBed.createComponent(AttachmentComponent);
|
||||
component = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(ProcessContentService);
|
||||
|
||||
createTaskRelatedContentSpy = spyOn(service, 'createTaskRelatedContent').and.returnValue(Observable.of(
|
||||
{
|
||||
status: true
|
||||
}));
|
||||
});
|
||||
|
||||
it('should not call createTaskRelatedContent service when taskId changed', () => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
expect(createTaskRelatedContentSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not call createTaskRelatedContent service when there is no file uploaded', () => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
let customEvent: any = {
|
||||
detail: {
|
||||
files: []
|
||||
}
|
||||
};
|
||||
component.onFileUpload(customEvent);
|
||||
expect(createTaskRelatedContentSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call createTaskRelatedContent service when there is a file uploaded', () => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
let file = new File([new Blob()], 'Test');
|
||||
let customEvent = {
|
||||
detail: {
|
||||
files: [
|
||||
file
|
||||
]
|
||||
}
|
||||
};
|
||||
component.onFileUpload(customEvent);
|
||||
expect(createTaskRelatedContentSpy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
@@ -0,0 +1,64 @@
|
||||
/*!
|
||||
* @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 { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
|
||||
import { ProcessContentService } from '@alfresco/core';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-create-task-attachment',
|
||||
styleUrls: ['./create-task-attachment.component.scss'],
|
||||
templateUrl: './create-task-attachment.component.html'
|
||||
})
|
||||
export class AttachmentComponent implements OnChanges {
|
||||
|
||||
@Input()
|
||||
taskId: string;
|
||||
|
||||
@Output()
|
||||
error: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
@Output()
|
||||
success: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
constructor(private activitiContentService: ProcessContentService) {
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (changes['taskId'] && changes['taskId'].currentValue) {
|
||||
this.taskId = changes['taskId'].currentValue;
|
||||
}
|
||||
}
|
||||
|
||||
onFileUpload(event: any) {
|
||||
let filesList: File[] = event.detail.files.map(obj => obj.file);
|
||||
|
||||
for (let fileInfoObj of filesList) {
|
||||
let file: File = fileInfoObj;
|
||||
let opts = {
|
||||
isRelatedContent: true
|
||||
};
|
||||
this.activitiContentService.createTaskRelatedContent(this.taskId, file, opts).subscribe(
|
||||
(res) => {
|
||||
this.success.emit(res);
|
||||
},
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
18
lib/process-services/attachment/index.ts
Normal file
18
lib/process-services/attachment/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
export * from './public-api';
|
@@ -0,0 +1,29 @@
|
||||
<adf-datatable [rows]="attachments" [actions]="true" [loading]="isLoading" (rowDblClick)="openContent($event)" (showRowActionsMenu)="onShowRowActionsMenu($event)"
|
||||
(executeRowAction)="onExecuteRowAction($event)">
|
||||
|
||||
<adf-empty-list *ngIf="isEmpty()">
|
||||
<div adf-empty-list-header class="adf-empty-list-header"> {{'ADF_PROCESS_LIST.PROCESS-ATTACHMENT.EMPTY.HEADER' | translate}} </div>
|
||||
<div adf-empty-list-body *ngIf="!isDisabled()">
|
||||
<div fxHide.lt-md="true" class="adf-empty-list-drag_drop">{{'ADF_PROCESS_LIST.PROCESS-ATTACHMENT.EMPTY.DRAG-AND-DROP.TITLE' | translate}}</div>
|
||||
<div fxHide.lt-md="true" class="adf-empty-list__any-files-here-to-add"> {{'ADF_PROCESS_LIST.PROCESS-ATTACHMENT.EMPTY.DRAG-AND-DROP.SUBTITLE' | translate}} </div>
|
||||
</div>
|
||||
<div adf-empty-list-footer *ngIf="!isDisabled()">
|
||||
<img class="adf-empty-list__empty_doc_lib" [src]="emptyListImageUrl">
|
||||
</div>
|
||||
</adf-empty-list>
|
||||
|
||||
<data-columns>
|
||||
<data-column key="icon" type="icon" srTitle="Thumbnail" [sortable]="false"></data-column>
|
||||
<data-column key="name" type="text" title="{{'ADF_PROCESS_LIST.PROPERTIES.NAME' | translate}}" class="full-width ellipsis-cell" [sortable]="true"></data-column>
|
||||
<data-column key="created" type="date" format="shortDate" title="{{'ADF_PROCESS_LIST.PROPERTIES.CREATED' | translate}}"></data-column>
|
||||
</data-columns>
|
||||
|
||||
<loading-content-template>
|
||||
<ng-template>
|
||||
<!--Add your custom loading template here-->
|
||||
<mat-progress-spinner class="adf-attachment-list-loading-margin" [color]="'primary'" [mode]="'indeterminate'">
|
||||
</mat-progress-spinner>
|
||||
</ng-template>
|
||||
</loading-content-template>
|
||||
|
||||
</adf-datatable>
|
@@ -0,0 +1,58 @@
|
||||
@import '~@angular/material/theming';
|
||||
|
||||
adf-datatable ::ng-deep th span {
|
||||
color: #232323;
|
||||
}
|
||||
|
||||
adf-datatable ::ng-deep .data-cell {
|
||||
cursor: pointer !important;
|
||||
}
|
||||
|
||||
.adf-attachment-list-loading-margin {
|
||||
margin-left: calc((100% - 100px) / 2);
|
||||
margin-right: calc((100% - 100px) / 2);
|
||||
}
|
||||
|
||||
.adf-empty-list-header {
|
||||
height: 32px;
|
||||
opacity: 0.26 !important;
|
||||
font-size: 24px;
|
||||
line-height: 1.33;
|
||||
letter-spacing: -1px;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
.adf-empty-list-drag_drop {
|
||||
min-height: 56px;
|
||||
opacity: 0.54;
|
||||
font-size: 56px;
|
||||
line-height: 1;
|
||||
letter-spacing: -2px;
|
||||
color: #000000;
|
||||
margin-top: 40px !important;
|
||||
word-break: break-all;
|
||||
white-space: pre-line;
|
||||
}
|
||||
|
||||
.adf-empty-list__any-files-here-to-add {
|
||||
min-height: 24px;
|
||||
opacity: 0.54;
|
||||
font-size: 16px;
|
||||
line-height: 1.5;
|
||||
letter-spacing: -0.4px;
|
||||
color: #000000;
|
||||
margin-top: 17px;
|
||||
word-break: break-all;
|
||||
white-space: pre-line;
|
||||
}
|
||||
|
||||
.adf-empty-list__empty_doc_lib {
|
||||
width: 565px;
|
||||
height: 161px;
|
||||
object-fit: contain;
|
||||
margin-top: 17px;
|
||||
|
||||
@media screen and ($mat-xsmall) {
|
||||
width: 250px;
|
||||
}
|
||||
}
|
@@ -0,0 +1,313 @@
|
||||
/*!
|
||||
* @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 { NgZone, SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MatProgressSpinnerModule } from '@angular/material';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { ProcessContentService } from '@alfresco/core';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
|
||||
import { ProcessAttachmentListComponent } from './process-attachment-list.component';
|
||||
|
||||
describe('ProcessAttachmentListComponent', () => {
|
||||
|
||||
let service: ProcessContentService;
|
||||
let component: ProcessAttachmentListComponent;
|
||||
let fixture: ComponentFixture<ProcessAttachmentListComponent>;
|
||||
let getProcessRelatedContentSpy: jasmine.Spy;
|
||||
let deleteContentSpy: jasmine.Spy;
|
||||
let getFileRawContentSpy: jasmine.Spy;
|
||||
let mockAttachment: any;
|
||||
|
||||
beforeEach(async(() => {
|
||||
let zone = new NgZone({enableLongStackTrace: false});
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
MatProgressSpinnerModule
|
||||
],
|
||||
declarations: [
|
||||
ProcessAttachmentListComponent
|
||||
],
|
||||
providers: [
|
||||
ProcessContentService,
|
||||
{ provide: NgZone, useValue: zone }
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
fixture = TestBed.createComponent(ProcessAttachmentListComponent);
|
||||
component = fixture.componentInstance;
|
||||
service = fixture.debugElement.injector.get(ProcessContentService);
|
||||
|
||||
const translateService: TranslateService = TestBed.get(TranslateService);
|
||||
spyOn(translateService, 'get').and.callFake((key) => {
|
||||
return Observable.of(key);
|
||||
});
|
||||
|
||||
mockAttachment = {
|
||||
'size': 2,
|
||||
'total': 2,
|
||||
'start': 0,
|
||||
'data': [{
|
||||
'id': 4001,
|
||||
'name': 'Invoice01.pdf',
|
||||
'created': '2017-05-12T12:50:05.522+0000',
|
||||
'createdBy': {
|
||||
'id': 1,
|
||||
'firstName': 'Apps',
|
||||
'lastName': 'Administrator',
|
||||
'email': 'admin@app.activiti.com',
|
||||
'company': 'Alfresco.com',
|
||||
'pictureId': 3003
|
||||
},
|
||||
'relatedContent': true,
|
||||
'contentAvailable': true,
|
||||
'link': false,
|
||||
'mimeType': 'application/pdf',
|
||||
'simpleType': 'pdf',
|
||||
'previewStatus': 'created',
|
||||
'thumbnailStatus': 'created'
|
||||
},
|
||||
{
|
||||
'id': 4002,
|
||||
'name': 'Invoice02.pdf',
|
||||
'created': '2017-05-12T12:50:05.522+0000',
|
||||
'createdBy': {
|
||||
'id': 1,
|
||||
'firstName': 'Apps',
|
||||
'lastName': 'Administrator',
|
||||
'email': 'admin@app.activiti.com',
|
||||
'company': 'Alfresco.com',
|
||||
'pictureId': 3003
|
||||
},
|
||||
'relatedContent': true,
|
||||
'contentAvailable': true,
|
||||
'link': false,
|
||||
'mimeType': 'application/pdf',
|
||||
'simpleType': 'pdf',
|
||||
'previewStatus': 'created',
|
||||
'thumbnailStatus': 'created'
|
||||
}]
|
||||
};
|
||||
|
||||
getProcessRelatedContentSpy = spyOn(service, 'getProcessRelatedContent').and.returnValue(Observable.of(mockAttachment));
|
||||
|
||||
deleteContentSpy = spyOn(service, 'deleteRelatedContent').and.returnValue(Observable.of({successCode: true}));
|
||||
|
||||
let blobObj = new Blob();
|
||||
getFileRawContentSpy = spyOn(service, 'getFileRawContent').and.returnValue(Observable.of(
|
||||
blobObj
|
||||
));
|
||||
});
|
||||
|
||||
it('should load attachments when processInstanceId specified', () => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({ 'processInstanceId': change });
|
||||
expect(getProcessRelatedContentSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should emit an error when an error occurs loading attachments', () => {
|
||||
let emitSpy = spyOn(component.error, 'emit');
|
||||
getProcessRelatedContentSpy.and.returnValue(Observable.throw({}));
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({ 'processInstanceId': change });
|
||||
expect(emitSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should emit a success event when the attachments are loaded', () => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.success.subscribe((attachments) => {
|
||||
expect(attachments[0].name).toEqual(mockAttachment.data[0].name);
|
||||
expect(attachments[0].id).toEqual(mockAttachment.data[0].id);
|
||||
});
|
||||
|
||||
component.ngOnChanges({'taskId': change});
|
||||
});
|
||||
|
||||
it('should not attach when no processInstanceId is specified', () => {
|
||||
fixture.detectChanges();
|
||||
expect(getProcessRelatedContentSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should display attachments when the process has attachments', async(() => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({ 'processInstanceId': change });
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.queryAll(By.css('adf-datatable tbody tr')).length).toBe(2);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should display all actions if attachements are not read only', () => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({ 'processInstanceId': change });
|
||||
|
||||
fixture.detectChanges();
|
||||
let actionButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="action_menu_0"]');
|
||||
actionButton.click();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
let actionMenu = fixture.debugElement.nativeElement.querySelectorAll('button.mat-menu-item').length;
|
||||
expect(fixture.debugElement.nativeElement.querySelector('[data-automation-id="View"]')).not.toBeNull();
|
||||
expect(fixture.debugElement.nativeElement.querySelector('[data-automation-id="Remove"]')).not.toBeNull();
|
||||
expect(actionMenu).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not display remove action if attachments are read only', () => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({ 'processInstanceId': change });
|
||||
component.disabled = true;
|
||||
|
||||
fixture.detectChanges();
|
||||
let actionButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="action_menu_0"]');
|
||||
actionButton.click();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
let actionMenu = fixture.debugElement.nativeElement.querySelectorAll('button.mat-menu-item').length;
|
||||
expect(fixture.debugElement.nativeElement.querySelector('[data-automation-id="View"]')).not.toBeNull();
|
||||
expect(fixture.debugElement.nativeElement.querySelector('[data-automation-id="Remove"]')).toBeNull();
|
||||
expect(actionMenu).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
it('should show the empty list component when the attachments list is empty', async(() => {
|
||||
getProcessRelatedContentSpy.and.returnValue(Observable.of({
|
||||
'size': 0,
|
||||
'total': 0,
|
||||
'start': 0,
|
||||
'data': []
|
||||
}));
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'processInstanceId': change});
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_PROCESS_LIST.PROCESS-ATTACHMENT.EMPTY.HEADER');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show the empty list drag and drop component when the process is not completed', async(() => {
|
||||
getProcessRelatedContentSpy.and.returnValue(Observable.of({
|
||||
'size': 0,
|
||||
'total': 0,
|
||||
'start': 0,
|
||||
'data': []
|
||||
}));
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'processInstanceId': change});
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.querySelector('adf-empty-list .adf-empty-list-drag_drop').innerText.trim())
|
||||
.toEqual('ADF_PROCESS_LIST.PROCESS-ATTACHMENT.EMPTY.DRAG-AND-DROP.TITLE');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not show the empty list drag and drop component when is disabled', async(() => {
|
||||
getProcessRelatedContentSpy.and.returnValue(Observable.of({
|
||||
'size': 0,
|
||||
'total': 0,
|
||||
'start': 0,
|
||||
'data': []
|
||||
}));
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'processInstanceId': change});
|
||||
component.disabled = true;
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.querySelector('adf-empty-list .adf-empty-list-drag_drop')).toBeNull();
|
||||
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_PROCESS_LIST.PROCESS-ATTACHMENT.EMPTY.HEADER');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show the empty list component when the attachments list is empty for completed process', async(() => {
|
||||
getProcessRelatedContentSpy.and.returnValue(Observable.of({
|
||||
'size': 0,
|
||||
'total': 0,
|
||||
'start': 0,
|
||||
'data': []
|
||||
}));
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'processInstanceId': change});
|
||||
component.disabled = true;
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim())
|
||||
.toEqual('ADF_PROCESS_LIST.PROCESS-ATTACHMENT.EMPTY.HEADER');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not show the empty list component when the attachments list is not empty for completed process', async(() => {
|
||||
getProcessRelatedContentSpy.and.returnValue(Observable.of(mockAttachment));
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'processInstanceId': change});
|
||||
component.disabled = true;
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]')).toBeNull();
|
||||
});
|
||||
}));
|
||||
|
||||
describe('change detection', () => {
|
||||
|
||||
let change = new SimpleChange('123', '456', true);
|
||||
let nullChange = new SimpleChange('123', null, true);
|
||||
|
||||
beforeEach(async(() => {
|
||||
component.processInstanceId = '123';
|
||||
fixture.whenStable().then(() => {
|
||||
getProcessRelatedContentSpy.calls.reset();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should fetch new attachments when processInstanceId changed', () => {
|
||||
component.ngOnChanges({ 'processInstanceId': change });
|
||||
expect(getProcessRelatedContentSpy).toHaveBeenCalledWith('456');
|
||||
});
|
||||
|
||||
it('should NOT fetch new attachments when empty changeset made', () => {
|
||||
component.ngOnChanges({});
|
||||
expect(getProcessRelatedContentSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should NOT fetch new attachments when processInstanceId changed to null', () => {
|
||||
component.ngOnChanges({ 'processInstanceId': nullChange });
|
||||
expect(getProcessRelatedContentSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Delete attachments', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
component.processInstanceId = '123';
|
||||
fixture.whenStable();
|
||||
}));
|
||||
|
||||
it('should display a dialog to the user when the Add button clicked', () => {
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
@@ -0,0 +1,196 @@
|
||||
/*!
|
||||
* @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 { ContentService, ThumbnailService } from '@alfresco/core';
|
||||
import { Component, EventEmitter, Input, NgZone, OnChanges, Output, SimpleChanges } from '@angular/core';
|
||||
import { ProcessContentService } from '@alfresco/core';
|
||||
|
||||
declare var require: any;
|
||||
|
||||
@Component({
|
||||
selector: 'adf-process-attachment-list',
|
||||
styleUrls: ['./process-attachment-list.component.scss'],
|
||||
templateUrl: './process-attachment-list.component.html'
|
||||
})
|
||||
export class ProcessAttachmentListComponent implements OnChanges {
|
||||
|
||||
@Input()
|
||||
processInstanceId: string;
|
||||
|
||||
@Input()
|
||||
disabled: boolean = false;
|
||||
|
||||
@Output()
|
||||
attachmentClick = new EventEmitter();
|
||||
|
||||
@Output()
|
||||
success = new EventEmitter();
|
||||
|
||||
@Output()
|
||||
error: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
@Input()
|
||||
emptyListImageUrl: string = require('../assets/images/empty_doc_lib.svg');
|
||||
|
||||
attachments: any[] = [];
|
||||
isLoading: boolean = true;
|
||||
|
||||
constructor(private activitiContentService: ProcessContentService,
|
||||
private contentService: ContentService,
|
||||
private thumbnailService: ThumbnailService,
|
||||
private ngZone: NgZone) {
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (changes['processInstanceId'] && changes['processInstanceId'].currentValue) {
|
||||
this.loadAttachmentsByProcessInstanceId(changes['processInstanceId'].currentValue);
|
||||
}
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.attachments = [];
|
||||
}
|
||||
|
||||
reload(): void {
|
||||
this.ngZone.run(() => {
|
||||
this.loadAttachmentsByProcessInstanceId(this.processInstanceId);
|
||||
});
|
||||
}
|
||||
|
||||
add(content: any): void {
|
||||
this.ngZone.run(() => {
|
||||
this.attachments.push({
|
||||
id: content.id,
|
||||
name: content.name,
|
||||
created: content.created,
|
||||
createdBy: content.createdBy.firstName + ' ' + content.createdBy.lastName,
|
||||
icon: this.thumbnailService.getMimeTypeIcon(content.mimeType)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private loadAttachmentsByProcessInstanceId(processInstanceId: string) {
|
||||
if (processInstanceId) {
|
||||
this.reset();
|
||||
this.isLoading = true;
|
||||
this.activitiContentService.getProcessRelatedContent(processInstanceId).subscribe(
|
||||
(res: any) => {
|
||||
res.data.forEach(content => {
|
||||
this.attachments.push({
|
||||
id: content.id,
|
||||
name: content.name,
|
||||
created: content.created,
|
||||
createdBy: content.createdBy.firstName + ' ' + content.createdBy.lastName,
|
||||
icon: this.thumbnailService.getMimeTypeIcon(content.mimeType)
|
||||
});
|
||||
});
|
||||
this.success.emit(this.attachments);
|
||||
this.isLoading = false;
|
||||
},
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
this.isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private deleteAttachmentById(contentId: number) {
|
||||
if (contentId) {
|
||||
this.activitiContentService.deleteRelatedContent(contentId).subscribe(
|
||||
(res: any) => {
|
||||
this.attachments = this.attachments.filter(content => {
|
||||
return content.id !== contentId;
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isEmpty(): boolean {
|
||||
return this.attachments && this.attachments.length === 0;
|
||||
}
|
||||
|
||||
onShowRowActionsMenu(event: any) {
|
||||
let viewAction = {
|
||||
title: 'ADF_PROCESS_LIST.MENU_ACTIONS.VIEW_CONTENT',
|
||||
name: 'view'
|
||||
};
|
||||
|
||||
let removeAction = {
|
||||
title: 'ADF_PROCESS_LIST.MENU_ACTIONS.REMOVE_CONTENT',
|
||||
name: 'remove'
|
||||
};
|
||||
|
||||
let downloadAction = {
|
||||
title: 'ADF_PROCESS_LIST.MENU_ACTIONS.DOWNLOAD_CONTENT',
|
||||
name: 'download'
|
||||
};
|
||||
|
||||
event.value.actions = [
|
||||
viewAction,
|
||||
downloadAction
|
||||
];
|
||||
|
||||
if (!this.disabled) {
|
||||
event.value.actions.splice(1, 0, removeAction);
|
||||
}
|
||||
}
|
||||
|
||||
onExecuteRowAction(event: any) {
|
||||
let args = event.value;
|
||||
let action = args.action;
|
||||
if (action.name === 'view') {
|
||||
this.emitDocumentContent(args.row.obj);
|
||||
} else if (action.name === 'remove') {
|
||||
this.deleteAttachmentById(args.row.obj.id);
|
||||
} else if (action.name === 'download') {
|
||||
this.downloadContent(args.row.obj);
|
||||
}
|
||||
}
|
||||
|
||||
openContent(event: any): void {
|
||||
let content = event.value.obj;
|
||||
this.emitDocumentContent(content);
|
||||
}
|
||||
|
||||
emitDocumentContent(content: any) {
|
||||
this.activitiContentService.getFileRawContent(content.id).subscribe(
|
||||
(blob: Blob) => {
|
||||
content.contentBlob = blob;
|
||||
this.attachmentClick.emit(content);
|
||||
},
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
downloadContent(content: any): void {
|
||||
this.activitiContentService.getFileRawContent(content.id).subscribe(
|
||||
(blob: Blob) => this.contentService.downloadBlob(blob, content.name),
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
isDisabled(): boolean {
|
||||
return this.disabled;
|
||||
}
|
||||
}
|
23
lib/process-services/attachment/public-api.ts
Normal file
23
lib/process-services/attachment/public-api.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
export * from './task-attachment-list.component';
|
||||
export * from './process-attachment-list.component';
|
||||
export * from './create-process-attachment.component';
|
||||
export * from './create-task-attachment.component';
|
||||
|
||||
export * from './attachment.module';
|
@@ -0,0 +1,25 @@
|
||||
<adf-datatable [rows]="attachments" [actions]="true" [loading]="isLoading" (rowDblClick)="openContent($event)" (showRowActionsMenu)="onShowRowActionsMenu($event)"
|
||||
(executeRowAction)="onExecuteRowAction($event)">
|
||||
<adf-empty-list *ngIf="isEmpty()">
|
||||
<div adf-empty-list-header class="adf-empty-list-header"> {{'ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER' | translate}} </div>
|
||||
<div adf-empty-list-body *ngIf="!isDisabled()">
|
||||
<div fxHide.lt-md="true" class="adf-empty-list-drag_drop">{{'ADF_TASK_LIST.ATTACHMENT.EMPTY.DRAG-AND-DROP.TITLE' | translate}}</div>
|
||||
<div fxHide.lt-md="true" class="adf-empty-list__any-files-here-to-add"> {{'ADF_TASK_LIST.ATTACHMENT.EMPTY.DRAG-AND-DROP.SUBTITLE' | translate}} </div>
|
||||
</div>
|
||||
<div adf-empty-list-footer *ngIf="!isDisabled()">
|
||||
<img class="adf-empty-list__empty_doc_lib" [src]="emptyListImageUrl">
|
||||
</div>
|
||||
</adf-empty-list>
|
||||
<data-columns>
|
||||
<data-column key="icon" type="icon" srTitle="ADF_TASK_LIST.PROPERTIES.THUMBNAIL" [sortable]="false"></data-column>
|
||||
<data-column key="name" type="text" title="ADF_TASK_LIST.PROPERTIES.NAME" class="full-width ellipsis-cell" [sortable]="true"></data-column>
|
||||
<data-column key="created" type="date" format="shortDate" title="ADF_TASK_LIST.PROPERTIES.CREATED"></data-column>
|
||||
</data-columns>
|
||||
<loading-content-template>
|
||||
<ng-template>
|
||||
<!--Add your custom loading template here-->
|
||||
<mat-progress-spinner class="adf-attachment-list-loading-margin" [color]="'primary'" [mode]="'indeterminate'">
|
||||
</mat-progress-spinner>
|
||||
</ng-template>
|
||||
</loading-content-template>
|
||||
</adf-datatable>
|
@@ -0,0 +1,63 @@
|
||||
@import '~@angular/material/theming';
|
||||
|
||||
adf-datatable ::ng-deep th span {
|
||||
color: #232323;
|
||||
}
|
||||
|
||||
adf-datatable ::ng-deep .data-cell {
|
||||
cursor: pointer !important;
|
||||
}
|
||||
|
||||
.adf-attachment-list-loading-margin {
|
||||
margin-left: calc((100% - 100px) / 2);
|
||||
margin-right: calc((100% - 100px) / 2);
|
||||
}
|
||||
|
||||
.adf-empty-list-header {
|
||||
height: 32px;
|
||||
opacity: 0.26;
|
||||
font-size: 24px;
|
||||
line-height: 1.33;
|
||||
letter-spacing: -1px;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
.adf-empty-list-drag_drop {
|
||||
min-height: 56px;
|
||||
opacity: 0.54;
|
||||
font-size: 56px;
|
||||
line-height: 1;
|
||||
letter-spacing: -2px;
|
||||
color: #000000;
|
||||
margin-top: 40px;
|
||||
word-break: break-all;
|
||||
white-space: pre-line;
|
||||
|
||||
@media screen and ($mat-xsmall) {
|
||||
font-size: 40px;
|
||||
}
|
||||
}
|
||||
|
||||
.adf-empty-list__any-files-here-to-add {
|
||||
min-height: 24px;
|
||||
opacity: 0.54;
|
||||
font-size: 16px;
|
||||
line-height: 1.5;
|
||||
letter-spacing: -0.4px;
|
||||
color: #000000;
|
||||
margin-top: 17px;
|
||||
word-break: break-all;
|
||||
white-space: pre-line;
|
||||
}
|
||||
|
||||
.adf-empty-list__empty_doc_lib {
|
||||
width: 565px;
|
||||
max-width: 100%;
|
||||
height: 161px;
|
||||
object-fit: contain;
|
||||
margin-top: 17px;
|
||||
|
||||
@media screen and ($mat-xsmall) {
|
||||
width: 250px;
|
||||
}
|
||||
}
|
@@ -0,0 +1,296 @@
|
||||
/*!
|
||||
* @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 { SimpleChange } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { MaterialModule } from '../material.module';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { TaskAttachmentListComponent } from './task-attachment-list.component';
|
||||
import { ProcessContentService } from '@alfresco/core';
|
||||
|
||||
describe('TaskAttachmentList', () => {
|
||||
|
||||
let component: TaskAttachmentListComponent;
|
||||
let fixture: ComponentFixture<TaskAttachmentListComponent>;
|
||||
let service: ProcessContentService;
|
||||
let getTaskRelatedContentSpy: jasmine.Spy;
|
||||
let deleteContentSpy: jasmine.Spy;
|
||||
let getFileRawContentSpy: jasmine.Spy;
|
||||
let mockAttachment: any;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
MaterialModule
|
||||
],
|
||||
declarations: [
|
||||
TaskAttachmentListComponent
|
||||
],
|
||||
providers: [
|
||||
ProcessContentService
|
||||
]
|
||||
}).compileComponents();
|
||||
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
fixture = TestBed.createComponent(TaskAttachmentListComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
service = TestBed.get(ProcessContentService);
|
||||
|
||||
mockAttachment = {
|
||||
size: 2,
|
||||
total: 2,
|
||||
start: 0,
|
||||
data: [
|
||||
{
|
||||
id: 8,
|
||||
name: 'fake.zip',
|
||||
created: 1494595697381,
|
||||
createdBy: {id: 2, firstName: 'user', lastName: 'user', email: 'user@user.com'},
|
||||
relatedContent: true,
|
||||
contentAvailable: true,
|
||||
link: false,
|
||||
mimeType: 'application/zip',
|
||||
simpleType: 'content',
|
||||
previewStatus: 'unsupported',
|
||||
thumbnailStatus: 'unsupported'
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
name: 'fake.jpg',
|
||||
created: 1494595655381,
|
||||
createdBy: {id: 2, firstName: 'user', lastName: 'user', email: 'user@user.com'},
|
||||
relatedContent: true,
|
||||
contentAvailable: true,
|
||||
link: false,
|
||||
mimeType: 'image/jpeg',
|
||||
simpleType: 'image',
|
||||
previewStatus: 'unsupported',
|
||||
thumbnailStatus: 'unsupported'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
getTaskRelatedContentSpy = spyOn(service, 'getTaskRelatedContent').and.returnValue(Observable.of(
|
||||
mockAttachment
|
||||
));
|
||||
|
||||
deleteContentSpy = spyOn(service, 'deleteRelatedContent').and.returnValue(Observable.of({successCode: true}));
|
||||
|
||||
let blobObj = new Blob();
|
||||
getFileRawContentSpy = spyOn(service, 'getFileRawContent').and.returnValue(Observable.of(
|
||||
blobObj
|
||||
));
|
||||
|
||||
});
|
||||
|
||||
it('should load attachments when taskId specified', () => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
expect(getTaskRelatedContentSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should emit an error when an error occurs loading attachments', () => {
|
||||
let emitSpy = spyOn(component.error, 'emit');
|
||||
getTaskRelatedContentSpy.and.returnValue(Observable.throw({}));
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
expect(emitSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should emit a success event when the attachments are loaded', () => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.success.subscribe((attachments) => {
|
||||
expect(attachments[0].name).toEqual(mockAttachment.data[0].name);
|
||||
expect(attachments[0].id).toEqual(mockAttachment.data[0].id);
|
||||
});
|
||||
|
||||
component.ngOnChanges({'taskId': change});
|
||||
});
|
||||
|
||||
it('should not attach when no taskId is specified', () => {
|
||||
fixture.detectChanges();
|
||||
expect(getTaskRelatedContentSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should display attachments when the task has attachments', async(() => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.debugElement.queryAll(By.css('adf-datatable tbody tr')).length).toBe(2);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should display all actions if attachements are not read only', () => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
fixture.detectChanges();
|
||||
|
||||
let actionButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="action_menu_0"]');
|
||||
actionButton.click();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
let actionMenu = fixture.debugElement.nativeElement.querySelectorAll('button.mat-menu-item').length;
|
||||
expect(fixture.debugElement.nativeElement.querySelector('[data-automation-id="View"]')).not.toBeNull();
|
||||
expect(fixture.debugElement.nativeElement.querySelector('[data-automation-id="Remove"]')).not.toBeNull();
|
||||
expect(actionMenu).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not display remove action if attachments are read only', () => {
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
component.disabled = true;
|
||||
fixture.detectChanges();
|
||||
|
||||
let actionButton = fixture.debugElement.nativeElement.querySelector('[data-automation-id="action_menu_0"]');
|
||||
actionButton.click();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
let actionMenu = fixture.debugElement.nativeElement.querySelectorAll('button.mat-menu-item').length;
|
||||
expect(fixture.debugElement.nativeElement.querySelector('[data-automation-id="View"]')).not.toBeNull();
|
||||
expect(fixture.debugElement.nativeElement.querySelector('[data-automation-id="Remove"]')).toBeNull();
|
||||
expect(actionMenu).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
it('should show the empty list component when the attachments list is empty', async(() => {
|
||||
getTaskRelatedContentSpy.and.returnValue(Observable.of({
|
||||
'size': 0,
|
||||
'total': 0,
|
||||
'start': 0,
|
||||
'data': []
|
||||
}));
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show the empty list drag and drop component when the task is not completed', async(() => {
|
||||
getTaskRelatedContentSpy.and.returnValue(Observable.of({
|
||||
'size': 0,
|
||||
'total': 0,
|
||||
'start': 0,
|
||||
'data': []
|
||||
}));
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.querySelector('adf-empty-list .adf-empty-list-drag_drop').innerText.trim()).toEqual('ADF_TASK_LIST.ATTACHMENT.EMPTY.DRAG-AND-DROP.TITLE');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not show the empty list drag and drop component when is disabled', async(() => {
|
||||
getTaskRelatedContentSpy.and.returnValue(Observable.of({
|
||||
'size': 0,
|
||||
'total': 0,
|
||||
'start': 0,
|
||||
'data': []
|
||||
}));
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
component.disabled = true;
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.querySelector('adf-empty-list .adf-empty-list-drag_drop')).toBeNull();
|
||||
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should show the empty list component when the attachments list is empty for completed task', async(() => {
|
||||
getTaskRelatedContentSpy.and.returnValue(Observable.of({
|
||||
'size': 0,
|
||||
'total': 0,
|
||||
'start': 0,
|
||||
'data': []
|
||||
}));
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
component.disabled = true;
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]').innerText.trim()).toEqual('ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not show the empty list component when the attachments list is not empty for completed task', async(() => {
|
||||
getTaskRelatedContentSpy.and.returnValue(Observable.of(mockAttachment));
|
||||
let change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({'taskId': change});
|
||||
component.disabled = true;
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(fixture.nativeElement.querySelector('div[adf-empty-list-header]')).toBeNull();
|
||||
});
|
||||
}));
|
||||
|
||||
describe('change detection', () => {
|
||||
|
||||
let change = new SimpleChange('123', '456', true);
|
||||
let nullChange = new SimpleChange('123', null, true);
|
||||
|
||||
beforeEach(async(() => {
|
||||
component.taskId = '123';
|
||||
fixture.whenStable().then(() => {
|
||||
getTaskRelatedContentSpy.calls.reset();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should fetch new attachments when taskId changed', () => {
|
||||
component.ngOnChanges({'taskId': change});
|
||||
expect(getTaskRelatedContentSpy).toHaveBeenCalledWith('456');
|
||||
});
|
||||
|
||||
it('should NOT fetch new attachments when empty changeset made', () => {
|
||||
component.ngOnChanges({});
|
||||
expect(getTaskRelatedContentSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should NOT fetch new attachments when taskId changed to null', () => {
|
||||
component.ngOnChanges({'taskId': nullChange});
|
||||
expect(getTaskRelatedContentSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Delete attachments', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
component.taskId = '123';
|
||||
fixture.whenStable();
|
||||
}));
|
||||
|
||||
it('should display a dialog to the user when the Add button clicked', () => {
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
@@ -0,0 +1,198 @@
|
||||
/*!
|
||||
* @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 { ContentService, ThumbnailService } from '@alfresco/core';
|
||||
import { Component, EventEmitter, Input, NgZone, OnChanges, Output, SimpleChanges } from '@angular/core';
|
||||
import { ProcessContentService } from '@alfresco/core';
|
||||
|
||||
declare var require: any;
|
||||
|
||||
@Component({
|
||||
selector: 'adf-task-attachment-list',
|
||||
styleUrls: ['./task-attachment-list.component.scss'],
|
||||
templateUrl: './task-attachment-list.component.html'
|
||||
})
|
||||
export class TaskAttachmentListComponent implements OnChanges {
|
||||
|
||||
@Input()
|
||||
taskId: string;
|
||||
|
||||
@Input()
|
||||
disabled: boolean = false;
|
||||
|
||||
@Output()
|
||||
attachmentClick = new EventEmitter();
|
||||
|
||||
@Output()
|
||||
success = new EventEmitter();
|
||||
|
||||
@Output()
|
||||
error: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
@Input()
|
||||
emptyListImageUrl: string = require('../assets/images/empty_doc_lib.svg');
|
||||
|
||||
attachments: any[] = [];
|
||||
isLoading: boolean = true;
|
||||
|
||||
constructor(private activitiContentService: ProcessContentService,
|
||||
private contentService: ContentService,
|
||||
private thumbnailService: ThumbnailService,
|
||||
private ngZone: NgZone) {
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (changes['taskId'] && changes['taskId'].currentValue) {
|
||||
this.loadAttachmentsByTaskId(changes['taskId'].currentValue);
|
||||
}
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
this.attachments = [];
|
||||
}
|
||||
|
||||
reload(): void {
|
||||
this.ngZone.run(() => {
|
||||
this.loadAttachmentsByTaskId(this.taskId);
|
||||
});
|
||||
}
|
||||
|
||||
add(content: any): void {
|
||||
this.ngZone.run(() => {
|
||||
this.attachments.push({
|
||||
id: content.id,
|
||||
name: content.name,
|
||||
created: content.created,
|
||||
createdBy: content.createdBy.firstName + ' ' + content.createdBy.lastName,
|
||||
icon: this.thumbnailService.getMimeTypeIcon(content.mimeType)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private loadAttachmentsByTaskId(taskId: string) {
|
||||
if (taskId) {
|
||||
this.isLoading = true;
|
||||
this.reset();
|
||||
this.activitiContentService.getTaskRelatedContent(taskId).subscribe(
|
||||
(res: any) => {
|
||||
let attachList = [];
|
||||
res.data.forEach(content => {
|
||||
attachList.push({
|
||||
id: content.id,
|
||||
name: content.name,
|
||||
created: content.created,
|
||||
createdBy: content.createdBy.firstName + ' ' + content.createdBy.lastName,
|
||||
icon: this.thumbnailService.getMimeTypeIcon(content.mimeType)
|
||||
});
|
||||
});
|
||||
this.attachments = attachList;
|
||||
this.success.emit(this.attachments);
|
||||
this.isLoading = false;
|
||||
},
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
this.isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private deleteAttachmentById(contentId: number) {
|
||||
if (contentId) {
|
||||
this.activitiContentService.deleteRelatedContent(contentId).subscribe(
|
||||
(res: any) => {
|
||||
this.attachments = this.attachments.filter(content => {
|
||||
return content.id !== contentId;
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isEmpty(): boolean {
|
||||
return this.attachments && this.attachments.length === 0;
|
||||
}
|
||||
|
||||
onShowRowActionsMenu(event: any) {
|
||||
let viewAction = {
|
||||
title: 'ADF_TASK_LIST.MENU_ACTIONS.VIEW_CONTENT',
|
||||
name: 'view'
|
||||
};
|
||||
|
||||
let removeAction = {
|
||||
title: 'ADF_TASK_LIST.MENU_ACTIONS.REMOVE_CONTENT',
|
||||
name: 'remove'
|
||||
};
|
||||
|
||||
let downloadAction = {
|
||||
title: 'ADF_TASK_LIST.MENU_ACTIONS.DOWNLOAD_CONTENT',
|
||||
name: 'download'
|
||||
};
|
||||
|
||||
event.value.actions = [
|
||||
viewAction,
|
||||
downloadAction
|
||||
];
|
||||
|
||||
if (!this.disabled) {
|
||||
event.value.actions.splice(1, 0, removeAction);
|
||||
}
|
||||
}
|
||||
|
||||
onExecuteRowAction(event: any) {
|
||||
let args = event.value;
|
||||
let action = args.action;
|
||||
if (action.name === 'view') {
|
||||
this.emitDocumentContent(args.row.obj);
|
||||
} else if (action.name === 'remove') {
|
||||
this.deleteAttachmentById(args.row.obj.id);
|
||||
} else if (action.name === 'download') {
|
||||
this.downloadContent(args.row.obj);
|
||||
}
|
||||
}
|
||||
|
||||
openContent(event: any): void {
|
||||
let content = event.value.obj;
|
||||
this.emitDocumentContent(content);
|
||||
}
|
||||
|
||||
emitDocumentContent(content: any) {
|
||||
this.activitiContentService.getFileRawContent(content.id).subscribe(
|
||||
(blob: Blob) => {
|
||||
content.contentBlob = blob;
|
||||
this.attachmentClick.emit(content);
|
||||
},
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
downloadContent(content: any): void {
|
||||
this.activitiContentService.getFileRawContent(content.id).subscribe(
|
||||
(blob: Blob) => this.contentService.downloadBlob(blob, content.name),
|
||||
(err) => {
|
||||
this.error.emit(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
isDisabled(): boolean {
|
||||
return this.disabled;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user