mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-1889] fix preview of the APS content (#2663)
* fix preview of the APS content * test fixes * viewer integration enhancements * code fixes * test fixes
This commit is contained in:
committed by
Eugenio Romano
parent
2d6861e96f
commit
8a52d6fed5
@@ -153,12 +153,12 @@ The response is going to be `null` if the delete was successful.
|
|||||||
|
|
||||||
See `getProcessRelatedContent` and `getTaskRelatedContent` for how to get to the `contentId`.
|
See `getProcessRelatedContent` and `getTaskRelatedContent` for how to get to the `contentId`.
|
||||||
|
|
||||||
#### getContentThumbnailUrl(contentId: number): Observable<any>
|
#### getContentThumbnail(contentId: number): Observable<Blob>
|
||||||
Get the thumbnail URL for related content (currently does not return this):
|
Get the thumbnail URL for related content (currently does not return this):
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const contentId = 6008;
|
const contentId = 6008;
|
||||||
this.contentService.getContentThumbnailUrl(contentId).subscribe(
|
this.contentService.getContentThumbnail(contentId).subscribe(
|
||||||
res => {
|
res => {
|
||||||
console.log('Response: ', res);
|
console.log('Response: ', res);
|
||||||
}, error => {
|
}, error => {
|
||||||
|
@@ -162,7 +162,7 @@ describe('ContentWidgetComponent', () => {
|
|||||||
|
|
||||||
it('should load the thumbnail preview of a pdf', (done) => {
|
it('should load the thumbnail preview of a pdf', (done) => {
|
||||||
let blob = createFakePdfBlob();
|
let blob = createFakePdfBlob();
|
||||||
spyOn(processContentService, 'getContentThumbnailUrl').and.returnValue(Observable.of(blob));
|
spyOn(processContentService, 'getContentThumbnail').and.returnValue(Observable.of(blob));
|
||||||
|
|
||||||
component.thumbnailLoaded.subscribe((res) => {
|
component.thumbnailLoaded.subscribe((res) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -244,6 +244,7 @@ describe('ContentWidgetComponent', () => {
|
|||||||
|
|
||||||
it('should open the viewer when the view button is clicked', (done) => {
|
it('should open the viewer when the view button is clicked', (done) => {
|
||||||
let blob = createFakePdfBlob();
|
let blob = createFakePdfBlob();
|
||||||
|
spyOn(processContentService, 'getContentPreview').and.returnValue(Observable.of(blob));
|
||||||
spyOn(processContentService, 'getFileRawContent').and.returnValue(Observable.of(blob));
|
spyOn(processContentService, 'getFileRawContent').and.returnValue(Observable.of(blob));
|
||||||
|
|
||||||
component.content = new ContentLinkModel({
|
component.content = new ContentLinkModel({
|
||||||
|
@@ -85,7 +85,7 @@ export class ContentWidgetComponent implements OnChanges {
|
|||||||
if (this.content.isTypeImage()) {
|
if (this.content.isTypeImage()) {
|
||||||
observable = this.processContentService.getFileRawContent(content.id);
|
observable = this.processContentService.getFileRawContent(content.id);
|
||||||
} else {
|
} else {
|
||||||
observable = this.processContentService.getContentThumbnailUrl(content.id);
|
observable = this.processContentService.getContentThumbnail(content.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (observable) {
|
if (observable) {
|
||||||
@@ -104,7 +104,11 @@ export class ContentWidgetComponent implements OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
openViewer(content: ContentLinkModel): void {
|
openViewer(content: ContentLinkModel): void {
|
||||||
this.processContentService.getFileRawContent(content.id).subscribe(
|
let fetch = this.processContentService.getContentPreview(content.id);
|
||||||
|
if (content.isTypeImage() || content.isTypePdf()) {
|
||||||
|
fetch = this.processContentService.getFileRawContent(content.id);
|
||||||
|
}
|
||||||
|
fetch.subscribe(
|
||||||
(blob: Blob) => {
|
(blob: Blob) => {
|
||||||
content.contentBlob = blob;
|
content.contentBlob = blob;
|
||||||
this.contentClick.emit(content);
|
this.contentClick.emit(content);
|
||||||
|
@@ -18,6 +18,8 @@
|
|||||||
import { DebugElement } from '@angular/core';
|
import { DebugElement } from '@angular/core';
|
||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { Observable } from 'rxjs/Rx';
|
||||||
|
|
||||||
import { EcmModelService } from '../../../services/ecm-model.service';
|
import { EcmModelService } from '../../../services/ecm-model.service';
|
||||||
import { FormService } from '../../../services/form.service';
|
import { FormService } from '../../../services/form.service';
|
||||||
import { ProcessContentService } from '../../../services/process-content.service';
|
import { ProcessContentService } from '../../../services/process-content.service';
|
||||||
@@ -60,6 +62,8 @@ declare let jasmine: any;
|
|||||||
|
|
||||||
describe('UploadWidgetComponent', () => {
|
describe('UploadWidgetComponent', () => {
|
||||||
|
|
||||||
|
let contentService: ProcessContentService;
|
||||||
|
|
||||||
let filePngFake = new File(['fakePng'], 'file-fake.png', {type: 'image/png'});
|
let filePngFake = new File(['fakePng'], 'file-fake.png', {type: 'image/png'});
|
||||||
let filJpgFake = new File(['fakeJpg'], 'file-fake.jpg', {type: 'image/jpg'});
|
let filJpgFake = new File(['fakeJpg'], 'file-fake.jpg', {type: 'image/jpg'});
|
||||||
|
|
||||||
@@ -81,6 +85,7 @@ describe('UploadWidgetComponent', () => {
|
|||||||
uploadWidgetComponent = fixture.componentInstance;
|
uploadWidgetComponent = fixture.componentInstance;
|
||||||
element = fixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
debugElement = fixture.debugElement;
|
debugElement = fixture.debugElement;
|
||||||
|
contentService = TestBed.get(ProcessContentService);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -393,6 +398,9 @@ describe('UploadWidgetComponent', () => {
|
|||||||
|
|
||||||
it('should emit form content clicked event on icon click', (done) => {
|
it('should emit form content clicked event on icon click', (done) => {
|
||||||
|
|
||||||
|
spyOn(contentService, 'getContentPreview').and.returnValue(Observable.of(new Blob()));
|
||||||
|
spyOn(contentService, 'getFileRawContent').and.returnValue(Observable.of(new Blob()));
|
||||||
|
|
||||||
formServiceInstance.formContentClicked.subscribe((content: any) => {
|
formServiceInstance.formContentClicked.subscribe((content: any) => {
|
||||||
expect(content.name).toBe(fakeJpgAnswer.name);
|
expect(content.name).toBe(fakeJpgAnswer.name);
|
||||||
expect(content.id).toBe(fakeJpgAnswer.id);
|
expect(content.id).toBe(fakeJpgAnswer.id);
|
||||||
@@ -409,11 +417,6 @@ describe('UploadWidgetComponent', () => {
|
|||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
let fileJpegIcon = debugElement.query(By.css('#file-1156-icon'));
|
let fileJpegIcon = debugElement.query(By.css('#file-1156-icon'));
|
||||||
fileJpegIcon.nativeElement.dispatchEvent(new MouseEvent('click'));
|
fileJpegIcon.nativeElement.dispatchEvent(new MouseEvent('click'));
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
|
||||||
status: 200,
|
|
||||||
contentType: 'json',
|
|
||||||
responseText: new Blob()
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -129,14 +129,19 @@ export class UploadWidgetComponent extends WidgetComponent implements OnInit {
|
|||||||
return this.thumbnailService.getMimeTypeIcon(mimeType);
|
return this.thumbnailService.getMimeTypeIcon(mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
fileClicked(file: ContentLinkModel): void {
|
fileClicked(obj: any): void {
|
||||||
this.processContentService.getFileRawContent(file.id).subscribe(
|
const file = new ContentLinkModel(obj);
|
||||||
|
let fetch = this.processContentService.getContentPreview(file.id);
|
||||||
|
if (file.isTypeImage() || file.isTypePdf()) {
|
||||||
|
fetch = this.processContentService.getFileRawContent(file.id);
|
||||||
|
}
|
||||||
|
fetch.subscribe(
|
||||||
(blob: Blob) => {
|
(blob: Blob) => {
|
||||||
file.contentBlob = blob;
|
file.contentBlob = blob;
|
||||||
this.formService.formContentClicked.next(file);
|
this.formService.formContentClicked.next(file);
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
this.logService.error('Unable to send evento for file ' + file.name);
|
this.logService.error('Unable to send event for file ' + file.name);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -179,8 +179,8 @@ describe('ProcessContentService', () => {
|
|||||||
it('should return a Blob as thumbnail', (done) => {
|
it('should return a Blob as thumbnail', (done) => {
|
||||||
let contentId: number = 999;
|
let contentId: number = 999;
|
||||||
let blob = createFakeBlob();
|
let blob = createFakeBlob();
|
||||||
spyOn(service, 'getContentThumbnailUrl').and.returnValue(Observable.of(blob));
|
spyOn(service, 'getContentThumbnail').and.returnValue(Observable.of(blob));
|
||||||
service.getContentThumbnailUrl(contentId).subscribe(result => {
|
service.getContentThumbnail(contentId).subscribe(result => {
|
||||||
expect(result).toEqual(jasmine.any(Blob));
|
expect(result).toEqual(jasmine.any(Blob));
|
||||||
expect(result.size).toEqual(48);
|
expect(result.size).toEqual(48);
|
||||||
expect(result.type).toEqual('image/png');
|
expect(result.type).toEqual('image/png');
|
||||||
|
@@ -46,12 +46,35 @@ export class ProcessContentService {
|
|||||||
return Observable.fromPromise(this.contentApi.getRawContent(contentId)).catch(err => this.handleError(err));
|
return Observable.fromPromise(this.contentApi.getRawContent(contentId)).catch(err => this.handleError(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getContentPreview(contentId: number): Observable<Blob> {
|
||||||
|
return new Observable(observer => {
|
||||||
|
this.contentApi.getContentPreview(contentId).then(
|
||||||
|
(result) => {
|
||||||
|
observer.next(result);
|
||||||
|
observer.complete();
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
this.contentApi.getRawContent(contentId).then(
|
||||||
|
(data) => {
|
||||||
|
observer.next(data);
|
||||||
|
observer.complete();
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
observer.error(err);
|
||||||
|
observer.complete();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getFileRawContentUrl(contentId: number): string {
|
getFileRawContentUrl(contentId: number): string {
|
||||||
return this.contentApi.getRawContentUrl(contentId);
|
return this.contentApi.getRawContentUrl(contentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
getContentThumbnailUrl(contentId: number): Observable<any> {
|
getContentThumbnail(contentId: number): Observable<Blob> {
|
||||||
return Observable.fromPromise(this.contentApi.getContentThumbnailUrl(contentId)).catch(err => this.handleError(err));
|
return Observable.fromPromise(this.contentApi.getContentThumbnail(contentId)).catch(err => this.handleError(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
getTaskRelatedContent(taskId: string): Observable<any> {
|
getTaskRelatedContent(taskId: string): Observable<any> {
|
||||||
|
Reference in New Issue
Block a user