[ADF-662] fix readonly button for upload and added event for show file in viewer (#2215)

This commit is contained in:
Vito
2017-08-14 14:15:29 -07:00
committed by Denys Vuika
parent f7d7b7143c
commit db5427d61a
4 changed files with 50 additions and 2 deletions

View File

@@ -6,9 +6,13 @@
<div>
<md-list *ngIf="hasFile">
<md-list-item class="adf-upload-files-row" *ngFor="let file of field.value">
<img md-list-icon class="adf-upload-widget__icon" [src]="getIcon(file.mimeType)" [alt]="mimeTypeIcon"/>
<img md-list-icon class="adf-upload-widget__icon"
[id]="'file-'+file.id+'-icon'"
[src]="getIcon(file.mimeType)"
[alt]="mimeTypeIcon"
(click)="fileClicked(file)"/>
<span md-line id="{{'file-'+file.id}}" class="adf-file">{{decode(file.name)}}</span>
<button md-icon-button [id]="'file-'+file.id+'-remove'" (click)="reset(file);" (keyup.enter)="reset(file);">
<button *ngIf="!field.readOnly" md-icon-button [id]="'file-'+file.id+'-remove'" (click)="reset(file);" (keyup.enter)="reset(file);">
<md-icon class="md-24">highlight_off</md-icon>
</button>
</md-list-item>
@@ -24,4 +28,5 @@
(change)="onFileChanged($event)">
</div>
<error-widget [error]="field.validationSummary" ></error-widget>
</div>

View File

@@ -18,6 +18,7 @@
&-upload-widget__icon {
padding: 6px;
float: left;
cursor: pointer;
}
&-adf-file {

View File

@@ -112,6 +112,7 @@ describe('UploadWidgetComponent', () => {
let element: HTMLInputElement;
let debugElement: DebugElement;
let inputElement: HTMLInputElement;
let formServiceInstance: FormService;
beforeEach(async(() => {
TestBed.configureTestingModule({
@@ -140,6 +141,7 @@ describe('UploadWidgetComponent', () => {
type: FormFieldTypes.UPLOAD,
readOnly: false
});
formServiceInstance = TestBed.get(FormService);
jasmine.Ajax.install();
});
@@ -249,6 +251,33 @@ describe('UploadWidgetComponent', () => {
});
}));
it('should emit form content clicked event on icon click', (done) => {
formServiceInstance.formContentClicked.subscribe((content: any) => {
expect(content.name).toBe(fakeJpgAnswer.name);
expect(content.id).toBe(fakeJpgAnswer.id);
expect(content.contentBlob).not.toBeNull();
done();
});
uploadWidgetComponent.field.params.multiple = true;
uploadWidgetComponent.field.value = [];
uploadWidgetComponent.field.value.push(fakeJpgAnswer);
uploadWidgetComponent.field.value.push(fakePngAnswer);
fixture.detectChanges();
fixture.whenStable().then(() => {
let fileJpegIcon = debugElement.query(By.css('#file-1156-icon'));
fileJpegIcon.nativeElement.dispatchEvent(new MouseEvent('click'));
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: new Blob()
});
});
});
});
});

View File

@@ -21,6 +21,7 @@ import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { LogService, ThumbnailService } from 'ng2-alfresco-core';
import { Observable } from 'rxjs/Rx';
import { FormService } from '../../../services/form.service';
import { ContentLinkModel } from '../core/content-link.model';
import { baseHost, WidgetComponent } from './../widget.component';
@Component({
@@ -117,4 +118,16 @@ export class UploadWidgetComponent extends WidgetComponent implements OnInit {
return this.thumbnailService.getMimeTypeIcon(mimeType);
}
fileClicked(file: ContentLinkModel): void {
this.formService.getFileRawContent(file.id).subscribe(
(blob: Blob) => {
file.contentBlob = blob;
this.formService.formContentClicked.next(file);
},
(error) => {
this.logService.error('Unable to send evento for file ' + file.name);
}
);
}
}