mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-662] fix readonly button for upload and added event for show file in viewer (#2215)
This commit is contained in:
@@ -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>
|
||||
|
@@ -18,6 +18,7 @@
|
||||
&-upload-widget__icon {
|
||||
padding: 6px;
|
||||
float: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
&-adf-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()
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -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);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user