From 6fbda1919ca49dd1f5a5baee14ce80f55afa14a9 Mon Sep 17 00:00:00 2001 From: Maurizio Vitale Date: Tue, 28 Nov 2017 22:00:05 +0000 Subject: [PATCH] [ADF-1711] Task Attachment list - fix custom template (#2748) * fix custom template * rollback change process attachment --- .../process-attachments.component.html | 8 +-- .../task-attachments.component.html | 13 ++-- .../task-attachment-list.component.html | 21 ++++--- .../task-attachment-list.component.spec.ts | 59 +++++++++++++------ .../task-attachment-list.component.ts | 28 +++++---- 5 files changed, 79 insertions(+), 50 deletions(-) diff --git a/demo-shell/src/app/components/process-service/process-attachments.component.html b/demo-shell/src/app/components/process-service/process-attachments.component.html index 5ed63d02ec..61670f6fcd 100644 --- a/demo-shell/src/app/components/process-service/process-attachments.component.html +++ b/demo-shell/src/app/components/process-service/process-attachments.component.html @@ -6,10 +6,10 @@ [disabled]="isCompletedProcess()"> + *ngIf="processInstanceId" + [disabled]="isCompletedProcess()" + [processInstanceId]="processInstanceId" + (attachmentClick)="onAttachmentClick($event)"> diff --git a/demo-shell/src/app/components/process-service/task-attachments.component.html b/demo-shell/src/app/components/process-service/task-attachments.component.html index 5295cd14fc..00d569b4fd 100644 --- a/demo-shell/src/app/components/process-service/task-attachments.component.html +++ b/demo-shell/src/app/components/process-service/task-attachments.component.html @@ -5,12 +5,11 @@ [parentId]="taskId"> -
-
{{'ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER' - | translate}} + [disabled]="isCompletedTask()" + [taskId]="taskId" + (attachmentClick)="onAttachmentClick($event)"> + +
{{'ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER' | translate}}
@@ -20,7 +19,7 @@ {{'ADF_TASK_LIST.ATTACHMENT.EMPTY.DRAG-AND-DROP.SUBTITLE' | translate}}
-
+ diff --git a/lib/process-services/attachment/task-attachment-list.component.html b/lib/process-services/attachment/task-attachment-list.component.html index 1ef1247b1f..587f961353 100644 --- a/lib/process-services/attachment/task-attachment-list.component.html +++ b/lib/process-services/attachment/task-attachment-list.component.html @@ -4,15 +4,18 @@ (rowDblClick)="openContent($event)" (showRowActionsMenu)="onShowRowActionsMenu($event)" (executeRowAction)="onExecuteRowAction($event)"> - - -
- {{'ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER' | translate}} -
-
- -
-
+ + + + + +
+ {{'ADF_TASK_LIST.ATTACHMENT.EMPTY.HEADER' | translate}} +
+
+
+
+
diff --git a/lib/process-services/attachment/task-attachment-list.component.spec.ts b/lib/process-services/attachment/task-attachment-list.component.spec.ts index f0b4b4f0e5..9c957d22c5 100644 --- a/lib/process-services/attachment/task-attachment-list.component.spec.ts +++ b/lib/process-services/attachment/task-attachment-list.component.spec.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { SimpleChange } from '@angular/core'; +import { SimpleChange, Component } from '@angular/core'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { MaterialModule } from '../material.module'; @@ -168,23 +168,6 @@ describe('TaskAttachmentList', () => { }); })); - it('should not show the custom empty message when has custom template', 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.hasCustomTemplate = true; - - fixture.whenStable().then(() => { - fixture.detectChanges(); - expect(fixture.nativeElement.querySelector('.adf-custom-empty-template')).not.toBeNull(); - }); - })); - it('should display all actions if attachments are not read only', () => { let change = new SimpleChange(null, '123', true); component.ngOnChanges({ 'taskId': change }); @@ -314,3 +297,43 @@ describe('TaskAttachmentList', () => { }); }); + +@Component({ + template: ` + + +
Custom header
+
+
+ ` +}) +class CustomEmptyTemplateComponent { +} + +describe('Custom CustomEmptyTemplateComponent', () => { + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ + TaskAttachmentListComponent, + CustomEmptyTemplateComponent + ], + imports: [ + MaterialModule + ] + }).compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CustomEmptyTemplateComponent); + fixture.detectChanges(); + }); + + it('should render the custom template', () => { + fixture.detectChanges(); + let title: any = fixture.debugElement.queryAll(By.css('[adf-empty-list-header]')); + expect(title.length).toBe(1); + expect(title[0].nativeElement.innerText).toBe('Custom header'); + }); +}); diff --git a/lib/process-services/attachment/task-attachment-list.component.ts b/lib/process-services/attachment/task-attachment-list.component.ts index 8f5693ed7c..5426af6625 100644 --- a/lib/process-services/attachment/task-attachment-list.component.ts +++ b/lib/process-services/attachment/task-attachment-list.component.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import { ContentService, ThumbnailService } from '@alfresco/adf-core'; -import { AfterViewInit, Component, ElementRef, EventEmitter, Input, NgZone, OnChanges, Output, SimpleChanges, ViewChild, ViewEncapsulation } from '@angular/core'; +import { ContentService, ThumbnailService, EmptyListComponent } from '@alfresco/adf-core'; +import { AfterContentInit, ContentChild, Component, ElementRef, EventEmitter, Input, NgZone, OnChanges, Output, SimpleChanges, ViewChild, ViewEncapsulation } from '@angular/core'; import { ProcessContentService, UploadService } from '@alfresco/adf-core'; import { TaskUploadService } from '../task-list/services/task-upload.service'; @@ -29,7 +29,10 @@ import { TaskUploadService } from '../task-list/services/task-upload.service'; { provide: UploadService, useClass: TaskUploadService } ] }) -export class TaskAttachmentListComponent implements OnChanges, AfterViewInit { +export class TaskAttachmentListComponent implements OnChanges, AfterContentInit { + + @ContentChild(EmptyListComponent) + emptyTemplate: EmptyListComponent; @Input() taskId: string; @@ -51,6 +54,8 @@ export class TaskAttachmentListComponent implements OnChanges, AfterViewInit { @ViewChild('customEmptyListTemplate') customTemplateRef: ElementRef; + curret: any; + attachments: any[] = []; isLoading: boolean = false; @@ -66,17 +71,20 @@ export class TaskAttachmentListComponent implements OnChanges, AfterViewInit { } } - ngAfterViewInit() { - if (this.customTemplateRef && this.customTemplateRef.nativeElement && - this.customTemplateRef.nativeElement.children && this.customTemplateRef.nativeElement.children.length > 0) { - this.hasCustomTemplate = true; - } + ngAfterContentInit() { + if (this.emptyTemplate) { + this.hasCustomTemplate = true; + } } reset(): void { this.attachments = []; } + hasCutomEmptyTemplate() { + return !!this.emptyTemplate; + } + reload(): void { this.ngZone.run(() => { this.loadAttachmentsByTaskId(this.taskId); @@ -140,10 +148,6 @@ export class TaskAttachmentListComponent implements OnChanges, AfterViewInit { return this.attachments && this.attachments.length === 0; } - isCustomTemplateDefined(): boolean { - return this.hasCustomTemplate; - } - onShowRowActionsMenu(event: any) { let viewAction = { title: 'ADF_TASK_LIST.MENU_ACTIONS.VIEW_CONTENT',