mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Integration beetwen Viewer and Activiti Content (#1765)
* Provide a FormService event when you click on the uploaded content * Add a formContentClick event to the Form component * Provide a way to pass Blob to viewer * Provide a way to use the viewer using a Blob - Fix the pdf viewer - Fix the image viewer - Fix the media viewer * Update the viewer documentation * Use the ContentService provided by the core * Fix and improve unit test * Add unit test blob viewer
This commit is contained in:
parent
8132f79e97
commit
fde08bb573
@ -37,7 +37,7 @@
|
|||||||
[sort]="taskFilter.filter.sort"
|
[sort]="taskFilter.filter.sort"
|
||||||
[data]="dataTasks"
|
[data]="dataTasks"
|
||||||
[landingTaskId]="currentTaskId"
|
[landingTaskId]="currentTaskId"
|
||||||
(rowClick)="onTaskRowClick($event)"
|
(rowClick)="onTaskRowClick($event)"
|
||||||
(onSuccess)="onSuccessTaskList($event)"
|
(onSuccess)="onSuccessTaskList($event)"
|
||||||
(row-click)="onRowClick($event)"
|
(row-click)="onRowClick($event)"
|
||||||
(row-dblclick)="onRowDblClick($event)"
|
(row-dblclick)="onRowDblClick($event)"
|
||||||
@ -55,6 +55,7 @@
|
|||||||
<activiti-task-details #activitidetails
|
<activiti-task-details #activitidetails
|
||||||
[taskId]="currentTaskId"
|
[taskId]="currentTaskId"
|
||||||
(formCompleted)="onFormCompleted($event)"
|
(formCompleted)="onFormCompleted($event)"
|
||||||
|
(formContentClicked)="onFormContentClick($event)"
|
||||||
(taskCreated)="onTaskCreated($event)">
|
(taskCreated)="onTaskCreated($event)">
|
||||||
</activiti-task-details>
|
</activiti-task-details>
|
||||||
</div>
|
</div>
|
||||||
@ -142,3 +143,11 @@
|
|||||||
|
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div *ngIf="fileShowed">
|
||||||
|
<alfresco-viewer [(showViewer)]="fileShowed"
|
||||||
|
[blobFile]="content"
|
||||||
|
[displayName]="contentName"
|
||||||
|
[overlayMode]="true">
|
||||||
|
</alfresco-viewer>
|
||||||
|
</div>
|
||||||
|
@ -78,6 +78,11 @@ export class ActivitiDemoComponent implements AfterViewInit {
|
|||||||
@Input()
|
@Input()
|
||||||
appId: number = null;
|
appId: number = null;
|
||||||
|
|
||||||
|
fileShowed: boolean = false;
|
||||||
|
|
||||||
|
content: Blob;
|
||||||
|
contentName: string;
|
||||||
|
|
||||||
layoutType: string;
|
layoutType: string;
|
||||||
currentTaskId: string;
|
currentTaskId: string;
|
||||||
currentProcessInstanceId: string;
|
currentProcessInstanceId: string;
|
||||||
@ -92,6 +97,8 @@ export class ActivitiDemoComponent implements AfterViewInit {
|
|||||||
processFilter: FilterProcessRepresentationModel;
|
processFilter: FilterProcessRepresentationModel;
|
||||||
|
|
||||||
sub: Subscription;
|
sub: Subscription;
|
||||||
|
blobFile: any;
|
||||||
|
flag: boolean = true;
|
||||||
|
|
||||||
dataTasks: ObjectDataTableAdapter;
|
dataTasks: ObjectDataTableAdapter;
|
||||||
dataProcesses: ObjectDataTableAdapter;
|
dataProcesses: ObjectDataTableAdapter;
|
||||||
@ -113,6 +120,7 @@ export class ActivitiDemoComponent implements AfterViewInit {
|
|||||||
);
|
);
|
||||||
this.dataProcesses.setSorting(new DataSorting('started', 'desc'));
|
this.dataProcesses.setSorting(new DataSorting('started', 'desc'));
|
||||||
|
|
||||||
|
|
||||||
// Uncomment this line to replace all 'text' field editors with custom component
|
// Uncomment this line to replace all 'text' field editors with custom component
|
||||||
// formRenderingService.setComponentTypeResolver('text', () => CustomEditorComponent, true);
|
// formRenderingService.setComponentTypeResolver('text', () => CustomEditorComponent, true);
|
||||||
|
|
||||||
@ -126,6 +134,7 @@ export class ActivitiDemoComponent implements AfterViewInit {
|
|||||||
formService.formFieldValueChanged.subscribe((e: FormFieldEvent) => {
|
formService.formFieldValueChanged.subscribe((e: FormFieldEvent) => {
|
||||||
console.log(`Field value changed. Form: ${e.form.id}, Field: ${e.field.id}, Value: ${e.field.value}`);
|
console.log(`Field value changed. Form: ${e.form.id}, Field: ${e.field.id}, Value: ${e.field.value}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -242,6 +251,12 @@ export class ActivitiDemoComponent implements AfterViewInit {
|
|||||||
this.currentTaskId = null;
|
this.currentTaskId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onFormContentClick(content: any) {
|
||||||
|
this.fileShowed = true;
|
||||||
|
this.content = content.contentBlob;
|
||||||
|
this.contentName = content.name;
|
||||||
|
}
|
||||||
|
|
||||||
onTaskCreated(data: any) {
|
onTaskCreated(data: any) {
|
||||||
this.currentTaskId = data.parentTaskId;
|
this.currentTaskId = data.parentTaskId;
|
||||||
this.activititasklist.reload();
|
this.activititasklist.reload();
|
||||||
|
@ -94,8 +94,15 @@ export class ActivitiContent implements OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
openViewer(content: ContentLinkModel): void {
|
openViewer(content: ContentLinkModel): void {
|
||||||
this.contentClick.emit(content);
|
this.formService.getFileRawContent(content.id).subscribe(
|
||||||
this.logService.info('Content clicked' + content.id);
|
(blob: Blob) => {
|
||||||
|
content.contentBlob = blob;
|
||||||
|
this.contentClick.emit(content);
|
||||||
|
this.logService.info('Content clicked' + content.id);
|
||||||
|
this.formService.formContentClicked.next(content);
|
||||||
|
},
|
||||||
|
error => this.logService.error(error)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,6 +21,7 @@ import { EcmModelService } from './../services/ecm-model.service';
|
|||||||
import { FormService } from './../services/form.service';
|
import { FormService } from './../services/form.service';
|
||||||
import { NodeService } from './../services/node.service';
|
import { NodeService } from './../services/node.service';
|
||||||
import { FormModel, FormOutcomeModel, FormValues, FormFieldModel, FormOutcomeEvent } from './widgets/core/index';
|
import { FormModel, FormOutcomeModel, FormValues, FormFieldModel, FormOutcomeEvent } from './widgets/core/index';
|
||||||
|
import { ContentLinkModel } from './widgets/core/content-link.model';
|
||||||
import { FormEvent, FormErrorEvent } from './../events/index';
|
import { FormEvent, FormErrorEvent } from './../events/index';
|
||||||
|
|
||||||
import { WidgetVisibilityService } from './../services/widget-visibility.service';
|
import { WidgetVisibilityService } from './../services/widget-visibility.service';
|
||||||
@ -134,6 +135,9 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
|||||||
@Output()
|
@Output()
|
||||||
formCompleted: EventEmitter<FormModel> = new EventEmitter<FormModel>();
|
formCompleted: EventEmitter<FormModel> = new EventEmitter<FormModel>();
|
||||||
|
|
||||||
|
@Output()
|
||||||
|
formContentClicked: EventEmitter<ContentLinkModel> = new EventEmitter<ContentLinkModel>();
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
formLoaded: EventEmitter<FormModel> = new EventEmitter<FormModel>();
|
formLoaded: EventEmitter<FormModel> = new EventEmitter<FormModel>();
|
||||||
|
|
||||||
@ -202,6 +206,10 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
this.formService.formContentClicked.subscribe((content: ContentLinkModel) => {
|
||||||
|
this.formContentClicked.emit(content);
|
||||||
|
});
|
||||||
|
|
||||||
if (this.nodeId) {
|
if (this.nodeId) {
|
||||||
this.loadFormForEcmNode();
|
this.loadFormForEcmNode();
|
||||||
} else {
|
} else {
|
||||||
|
@ -29,6 +29,7 @@ export class ContentLinkModel {
|
|||||||
simpleType: string;
|
simpleType: string;
|
||||||
thumbnailUrl: string;
|
thumbnailUrl: string;
|
||||||
contentRawUrl: string;
|
contentRawUrl: string;
|
||||||
|
contentBlob: Blob;
|
||||||
thumbnailStatus: string;
|
thumbnailStatus: string;
|
||||||
|
|
||||||
constructor(obj?: any) {
|
constructor(obj?: any) {
|
||||||
|
@ -24,6 +24,7 @@ import { EcmModelService } from './ecm-model.service';
|
|||||||
import { GroupModel } from './../components/widgets/core/group.model';
|
import { GroupModel } from './../components/widgets/core/group.model';
|
||||||
import { GroupUserModel } from './../components/widgets/core/group-user.model';
|
import { GroupUserModel } from './../components/widgets/core/group-user.model';
|
||||||
import { FormEvent, FormErrorEvent, FormFieldEvent } from './../events/index';
|
import { FormEvent, FormErrorEvent, FormFieldEvent } from './../events/index';
|
||||||
|
import { ContentLinkModel } from './../components/widgets/core/content-link.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FormService {
|
export class FormService {
|
||||||
@ -37,6 +38,7 @@ export class FormService {
|
|||||||
taskCompletedError: Subject<FormErrorEvent> = new Subject<FormErrorEvent>();
|
taskCompletedError: Subject<FormErrorEvent> = new Subject<FormErrorEvent>();
|
||||||
taskSaved: Subject<FormEvent> = new Subject<FormEvent>();
|
taskSaved: Subject<FormEvent> = new Subject<FormEvent>();
|
||||||
taskSavedError: Subject<FormErrorEvent> = new Subject<FormErrorEvent>();
|
taskSavedError: Subject<FormErrorEvent> = new Subject<FormErrorEvent>();
|
||||||
|
formContentClicked: Subject<ContentLinkModel> = new Subject<ContentLinkModel>();
|
||||||
|
|
||||||
constructor(private ecmModelService: EcmModelService,
|
constructor(private ecmModelService: EcmModelService,
|
||||||
private apiService: AlfrescoApiService,
|
private apiService: AlfrescoApiService,
|
||||||
|
@ -53,6 +53,7 @@
|
|||||||
[readOnly]="readOnlyForm"
|
[readOnly]="readOnlyForm"
|
||||||
(formSaved)='onFormSaved($event)'
|
(formSaved)='onFormSaved($event)'
|
||||||
(formCompleted)='onFormCompleted($event)'
|
(formCompleted)='onFormCompleted($event)'
|
||||||
|
(formContentClicked)='onFormContentClick($event)'
|
||||||
(formLoaded)='onFormLoaded($event)'
|
(formLoaded)='onFormLoaded($event)'
|
||||||
(onError)='onFormError($event)'
|
(onError)='onFormError($event)'
|
||||||
(executeOutcome)='onFormExecuteOutcome($event)'>
|
(executeOutcome)='onFormExecuteOutcome($event)'>
|
||||||
|
@ -20,7 +20,7 @@ import { AlfrescoTranslationService, LogService } from 'ng2-alfresco-core';
|
|||||||
import { ActivitiTaskListService } from './../services/activiti-tasklist.service';
|
import { ActivitiTaskListService } from './../services/activiti-tasklist.service';
|
||||||
import { TaskDetailsModel } from '../models/task-details.model';
|
import { TaskDetailsModel } from '../models/task-details.model';
|
||||||
import { User } from '../models/user.model';
|
import { User } from '../models/user.model';
|
||||||
import { FormService, FormModel, FormOutcomeEvent } from 'ng2-activiti-form';
|
import { FormService, FormModel, FormOutcomeEvent, ContentLinkModel } from 'ng2-activiti-form';
|
||||||
import { TaskQueryRequestRepresentationModel } from '../models/filter.model';
|
import { TaskQueryRequestRepresentationModel } from '../models/filter.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -87,6 +87,9 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
|
|||||||
@Output()
|
@Output()
|
||||||
formCompleted: EventEmitter<FormModel> = new EventEmitter<FormModel>();
|
formCompleted: EventEmitter<FormModel> = new EventEmitter<FormModel>();
|
||||||
|
|
||||||
|
@Output()
|
||||||
|
formContentClicked: EventEmitter<ContentLinkModel> = new EventEmitter<ContentLinkModel>();
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
formLoaded: EventEmitter<FormModel> = new EventEmitter<FormModel>();
|
formLoaded: EventEmitter<FormModel> = new EventEmitter<FormModel>();
|
||||||
|
|
||||||
@ -228,6 +231,10 @@ export class ActivitiTaskDetails implements OnInit, OnChanges {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onFormContentClick(content: ContentLinkModel) {
|
||||||
|
this.formContentClicked.emit(content);
|
||||||
|
}
|
||||||
|
|
||||||
onFormSaved(form: FormModel) {
|
onFormSaved(form: FormModel) {
|
||||||
this.formSaved.emit(form);
|
this.formSaved.emit(form);
|
||||||
}
|
}
|
||||||
|
@ -210,10 +210,12 @@ platformBrowserDynamic().bootstrapModule(AppModule);
|
|||||||
Attribute | Options | Default | Description | Mandatory
|
Attribute | Options | Default | Description | Mandatory
|
||||||
--- | --- | --- | --- | ---
|
--- | --- | --- | --- | ---
|
||||||
`fileNodeId` | *string* | | node Id of the file to load the file |
|
`fileNodeId` | *string* | | node Id of the file to load the file |
|
||||||
`urlFile` | *string* | | If you want laod an external file that not comes from the ECM you can use this Url where to load the file |
|
`urlFile` | *string* | | If you want load an external file that not comes from the ECM you can use this Url where to load the file |
|
||||||
|
`urlBlob` | *Blob* | | If you want load a Blob File |
|
||||||
`overlayMode` | *boolean* | `false` | if true Show the Viewer full page over the present content otherwise will fit the parent div |
|
`overlayMode` | *boolean* | `false` | if true Show the Viewer full page over the present content otherwise will fit the parent div |
|
||||||
`showViewer` | *boolean* | `true` | Hide or show the viewer |
|
`showViewer` | *boolean* | `true` | Hide or show the viewer |
|
||||||
`showToolbar` | *boolean* | `true` | Hide or show the toolbars |
|
`showToolbar` | *boolean* | `true` | Hide or show the toolbars |
|
||||||
|
`displayName` | *string* | | You can specify the name of the file|
|
||||||
|
|
||||||
#### Supported file formats
|
#### Supported file formats
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
<div class="viewer-image-content">
|
<div class="viewer-image-content">
|
||||||
<div class="viewer-image-row">
|
<div class="viewer-image-row">
|
||||||
<div class="viewer-image-cell">
|
<div class="viewer-image-cell">
|
||||||
<img id="viewer-image" src="{{urlFile}}" alt="{{nameFile}}" class="center-element viewer-image"/>
|
<img id="viewer-image" [src]="urlFile" [alt]="nameFile" class="center-element viewer-image"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -17,21 +17,28 @@
|
|||||||
|
|
||||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||||
import { ImgViewerComponent } from './imgViewer.component';
|
import { ImgViewerComponent } from './imgViewer.component';
|
||||||
import { DebugElement } from '@angular/core';
|
import { DebugElement, SimpleChange } from '@angular/core';
|
||||||
import {
|
import {
|
||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
CoreModule
|
CoreModule,
|
||||||
|
ContentService
|
||||||
} from 'ng2-alfresco-core';
|
} from 'ng2-alfresco-core';
|
||||||
|
|
||||||
describe('Test ng2-alfresco-viewer Img viewer component ', () => {
|
describe('Test ng2-alfresco-viewer Img viewer component ', () => {
|
||||||
|
|
||||||
let component: ImgViewerComponent;
|
let component: ImgViewerComponent;
|
||||||
|
let service: ContentService;
|
||||||
let fixture: ComponentFixture<ImgViewerComponent>;
|
let fixture: ComponentFixture<ImgViewerComponent>;
|
||||||
let debug: DebugElement;
|
let debug: DebugElement;
|
||||||
let element: HTMLElement;
|
let element: HTMLElement;
|
||||||
|
|
||||||
|
function createFakeBlob() {
|
||||||
|
let data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
|
||||||
|
return new Blob([data], {type: 'image/png'});
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
@ -44,6 +51,7 @@ describe('Test ng2-alfresco-viewer Img viewer component ', () => {
|
|||||||
AlfrescoApiService
|
AlfrescoApiService
|
||||||
]
|
]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
service = TestBed.get(ContentService);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -55,17 +63,18 @@ describe('Test ng2-alfresco-viewer Img viewer component ', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('If no url is passed should thrown an error', () => {
|
it('If no url or blob are passed should thrown an error', () => {
|
||||||
|
let change = new SimpleChange(null, null);
|
||||||
expect(() => {
|
expect(() => {
|
||||||
component.ngOnChanges(null);
|
component.ngOnChanges({ 'blobFile': change });
|
||||||
}).toThrow(new Error('Attribute urlFile is required'));
|
}).toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('If url is passed should not thrown an error', () => {
|
it('If url is passed should not thrown an error', () => {
|
||||||
component.urlFile = 'fake-url';
|
component.urlFile = 'fake-url';
|
||||||
expect(() => {
|
expect(() => {
|
||||||
component.ngOnChanges(null);
|
component.ngOnChanges(null);
|
||||||
}).not.toThrow(new Error('Attribute urlFile is required'));
|
}).not.toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('The file Name should be present in the alt attribute', () => {
|
it('The file Name should be present in the alt attribute', () => {
|
||||||
@ -73,4 +82,15 @@ describe('Test ng2-alfresco-viewer Img viewer component ', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(element.querySelector('#viewer-image').getAttribute('alt')).toEqual('fake-name');
|
expect(element.querySelector('#viewer-image').getAttribute('alt')).toEqual('fake-name');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('If blob is passed should not thrown an error', () => {
|
||||||
|
let blob = createFakeBlob();
|
||||||
|
|
||||||
|
spyOn(service, 'createTrustedUrl').and.returnValue('fake-blob-url');
|
||||||
|
let change = new SimpleChange(null, blob);
|
||||||
|
expect(() => {
|
||||||
|
component.ngOnChanges({ 'blobFile': change });
|
||||||
|
}).not.toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||||
|
expect(component.urlFile).toEqual('fake-blob-url');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -15,7 +15,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
|
||||||
|
import { ContentService } from 'ng2-alfresco-core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
@ -23,17 +24,27 @@ import { Component, Input } from '@angular/core';
|
|||||||
templateUrl: './imgViewer.component.html',
|
templateUrl: './imgViewer.component.html',
|
||||||
styleUrls: ['./imgViewer.component.css']
|
styleUrls: ['./imgViewer.component.css']
|
||||||
})
|
})
|
||||||
export class ImgViewerComponent {
|
export class ImgViewerComponent implements OnChanges {
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
urlFile: string;
|
urlFile: string;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
blobFile: any;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
nameFile: string;
|
nameFile: string;
|
||||||
|
|
||||||
ngOnChanges(changes) {
|
constructor(private contentService: ContentService) {}
|
||||||
if (!this.urlFile) {
|
|
||||||
throw new Error('Attribute urlFile is required');
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
|
let blobFile = changes['blobFile'];
|
||||||
|
if (blobFile && blobFile.currentValue) {
|
||||||
|
this.urlFile = this.contentService.createTrustedUrl(this.blobFile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!this.urlFile && !this.blobFile) {
|
||||||
|
throw new Error('Attribute urlFile or blobFile is required');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
|
|
||||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||||
import { MediaPlayerComponent } from './mediaPlayer.component';
|
import { MediaPlayerComponent } from './mediaPlayer.component';
|
||||||
import { DebugElement } from '@angular/core';
|
import { DebugElement, SimpleChange } from '@angular/core';
|
||||||
|
import { ContentService } from 'ng2-alfresco-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
@ -28,10 +30,16 @@ import {
|
|||||||
describe('Test ng2-alfresco-viewer Media player component ', () => {
|
describe('Test ng2-alfresco-viewer Media player component ', () => {
|
||||||
|
|
||||||
let component: MediaPlayerComponent;
|
let component: MediaPlayerComponent;
|
||||||
|
let service: ContentService;
|
||||||
let fixture: ComponentFixture<MediaPlayerComponent>;
|
let fixture: ComponentFixture<MediaPlayerComponent>;
|
||||||
let debug: DebugElement;
|
let debug: DebugElement;
|
||||||
let element: HTMLElement;
|
let element: HTMLElement;
|
||||||
|
|
||||||
|
function createFakeBlob() {
|
||||||
|
let data = atob('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==');
|
||||||
|
return new Blob([data], {type: 'image/png'});
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
@ -44,6 +52,7 @@ describe('Test ng2-alfresco-viewer Media player component ', () => {
|
|||||||
AlfrescoApiService
|
AlfrescoApiService
|
||||||
]
|
]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
service = TestBed.get(ContentService);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -55,23 +64,35 @@ describe('Test ng2-alfresco-viewer Media player component ', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('If no url is passed should thrown an error', () => {
|
it('If no url or no blob are passed should thrown an error', () => {
|
||||||
|
let change = new SimpleChange(null, null);
|
||||||
expect(() => {
|
expect(() => {
|
||||||
component.ngOnChanges(null);
|
component.ngOnChanges({ 'blobFile': change });
|
||||||
}).toThrow(new Error('Attribute urlFile is required'));
|
}).toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('If url is passed should not thrown an error', () => {
|
it('If url is passed should not thrown an error', () => {
|
||||||
component.urlFile = 'fake-url';
|
component.urlFile = 'fake-url';
|
||||||
expect(() => {
|
expect(() => {
|
||||||
component.ngOnChanges(null);
|
component.ngOnChanges(null);
|
||||||
}).not.toThrow(new Error('Attribute urlFile is required'));
|
}).not.toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('If url is passed should not thrown an error', () => {
|
it('If url is passed should not thrown an error', () => {
|
||||||
component.urlFile = 'fake-url';
|
component.urlFile = 'fake-url';
|
||||||
expect(() => {
|
expect(() => {
|
||||||
component.ngOnChanges(null);
|
component.ngOnChanges(null);
|
||||||
}).not.toThrow(new Error('Attribute urlFile is required'));
|
}).not.toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('If blob is passed should not thrown an error', () => {
|
||||||
|
let blob = createFakeBlob();
|
||||||
|
|
||||||
|
spyOn(service, 'createTrustedUrl').and.returnValue('fake-blob-url');
|
||||||
|
let change = new SimpleChange(null, blob);
|
||||||
|
expect(() => {
|
||||||
|
component.ngOnChanges({ 'blobFile': change });
|
||||||
|
}).not.toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||||
|
expect(component.urlFile).toEqual('fake-blob-url');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -15,7 +15,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, Input } from '@angular/core';
|
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
|
||||||
|
import { ContentService } from 'ng2-alfresco-core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
@ -23,21 +24,31 @@ import { Component, Input } from '@angular/core';
|
|||||||
templateUrl: './mediaPlayer.component.html',
|
templateUrl: './mediaPlayer.component.html',
|
||||||
styleUrls: ['./mediaPlayer.component.css']
|
styleUrls: ['./mediaPlayer.component.css']
|
||||||
})
|
})
|
||||||
export class MediaPlayerComponent {
|
export class MediaPlayerComponent implements OnChanges {
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
urlFile: string;
|
urlFile: string;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
blobFile: Blob;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
mimeType: string;
|
mimeType: string;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
nameFile: string;
|
nameFile: string;
|
||||||
|
|
||||||
ngOnChanges(changes) {
|
constructor(private contentService: ContentService ) {}
|
||||||
if (!this.urlFile) {
|
|
||||||
throw new Error('Attribute urlFile is required');
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
|
let blobFile = changes['blobFile'];
|
||||||
|
if (blobFile && blobFile.currentValue) {
|
||||||
|
this.urlFile = this.contentService.createTrustedUrl(this.blobFile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.urlFile && !this.blobFile) {
|
||||||
|
throw new Error('Attribute urlFile or blobFile is required');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,24 @@ describe('Test ng2-alfresco-viewer PdfViewer component', () => {
|
|||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
function createFakeBlob(): Blob {
|
||||||
|
let pdfData = atob(
|
||||||
|
'JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwog' +
|
||||||
|
'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' +
|
||||||
|
'TWVkaWFCb3ggWyAwIDAgMjAwIDIwMCBdCiAgL0NvdW50IDEKICAvS2lkcyBbIDMgMCBSIF0K' +
|
||||||
|
'Pj4KZW5kb2JqCgozIDAgb2JqCjw8CiAgL1R5cGUgL1BhZ2UKICAvUGFyZW50IDIgMCBSCiAg' +
|
||||||
|
'L1Jlc291cmNlcyA8PAogICAgL0ZvbnQgPDwKICAgICAgL0YxIDQgMCBSIAogICAgPj4KICA+' +
|
||||||
|
'PgogIC9Db250ZW50cyA1IDAgUgo+PgplbmRvYmoKCjQgMCBvYmoKPDwKICAvVHlwZSAvRm9u' +
|
||||||
|
'dAogIC9TdWJ0eXBlIC9UeXBlMQogIC9CYXNlRm9udCAvVGltZXMtUm9tYW4KPj4KZW5kb2Jq' +
|
||||||
|
'Cgo1IDAgb2JqICAlIHBhZ2UgY29udGVudAo8PAogIC9MZW5ndGggNDQKPj4Kc3RyZWFtCkJU' +
|
||||||
|
'CjcwIDUwIFRECi9GMSAxMiBUZgooSGVsbG8sIHdvcmxkISkgVGoKRVQKZW5kc3RyZWFtCmVu' +
|
||||||
|
'ZG9iagoKeHJlZgowIDYKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMDEwIDAwMDAwIG4g' +
|
||||||
|
'CjAwMDAwMDAwNzkgMDAwMDAgbiAKMDAwMDAwMDE3MyAwMDAwMCBuIAowMDAwMDAwMzAxIDAw' +
|
||||||
|
'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' +
|
||||||
|
'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G');
|
||||||
|
return new Blob([pdfData], {type: 'application/pdf'});
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(PdfViewerComponent);
|
fixture = TestBed.createComponent(PdfViewerComponent);
|
||||||
|
|
||||||
@ -57,21 +75,71 @@ describe('Test ng2-alfresco-viewer PdfViewer component', () => {
|
|||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
|
||||||
component.showToolbar = true;
|
component.showToolbar = true;
|
||||||
component.urlFile = 'base/src/assets/fake-test-file.pdf';
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('View', () => {
|
describe('View with url file', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
component.urlFile = 'base/src/assets/fake-test-file.pdf';
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
it('If urlfile is not present should not be thrown any error ', () => {
|
it('If urlfile is not present should thrown an error ', () => {
|
||||||
component.urlFile = undefined;
|
component.urlFile = undefined;
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(() => {
|
expect(() => {
|
||||||
component.ngOnChanges(null);
|
component.ngOnChanges(null);
|
||||||
}).toThrow();
|
}).toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Canvas should be present', () => {
|
||||||
|
expect(element.querySelector('#viewer-viewerPdf')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#viewer-pdf-container')).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Loader should be present', () => {
|
||||||
|
expect(element.querySelector('#loader-container')).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Next an Previous Buttons should be present', () => {
|
||||||
|
expect(element.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Input Page elements should be present', () => {
|
||||||
|
expect(element.querySelector('#viewer-pagenumber-input')).toBeDefined();
|
||||||
|
expect(element.querySelector('#viewer-total-pages')).toBeDefined();
|
||||||
|
|
||||||
|
expect(element.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Toolbar should be hide if showToolbar is false', () => {
|
||||||
|
component.showToolbar = false;
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
expect(element.querySelector('#viewer-toolbar-command')).toBeNull();
|
||||||
|
expect(element.querySelector('#viewer-toolbar-pagination')).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('View with blob file', () => {
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
component.urlFile = undefined;
|
||||||
|
component.blobFile = createFakeBlob();
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('If blobFile is not present should thrown an error ', () => {
|
||||||
|
component.blobFile = undefined;
|
||||||
|
expect(() => {
|
||||||
|
component.ngOnChanges(null);
|
||||||
|
}).toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Canvas should be present', () => {
|
it('Canvas should be present', () => {
|
||||||
@ -109,6 +177,8 @@ describe('Test ng2-alfresco-viewer PdfViewer component', () => {
|
|||||||
describe('User interaction', () => {
|
describe('User interaction', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
component.urlFile = 'base/src/assets/fake-test-file.pdf';
|
||||||
|
fixture.detectChanges();
|
||||||
component.inputPage('1');
|
component.inputPage('1');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -244,6 +314,10 @@ describe('Test ng2-alfresco-viewer PdfViewer component', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Resize interaction', () => {
|
describe('Resize interaction', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
component.urlFile = 'base/src/assets/fake-test-file.pdf';
|
||||||
|
component.inputPage('1');
|
||||||
|
});
|
||||||
it('resize event should trigger setScaleUpdatePages', (done) => {
|
it('resize event should trigger setScaleUpdatePages', (done) => {
|
||||||
component.ngOnChanges(null).then(() => {
|
component.ngOnChanges(null).then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@ -256,6 +330,10 @@ describe('Test ng2-alfresco-viewer PdfViewer component', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('scroll interaction', () => {
|
describe('scroll interaction', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
component.urlFile = 'base/src/assets/fake-test-file.pdf';
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
it('scroll page should return the current page', (done) => {
|
it('scroll page should return the current page', (done) => {
|
||||||
component.ngOnChanges(null).then(() => {
|
component.ngOnChanges(null).then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
@ -33,6 +33,9 @@ export class PdfViewerComponent {
|
|||||||
@Input()
|
@Input()
|
||||||
urlFile: string;
|
urlFile: string;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
blobFile: Blob;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
nameFile: string;
|
nameFile: string;
|
||||||
|
|
||||||
@ -58,40 +61,52 @@ export class PdfViewerComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes) {
|
ngOnChanges(changes) {
|
||||||
if (!this.urlFile) {
|
if (!this.urlFile && !this.blobFile) {
|
||||||
throw new Error('Attribute urlFile is required');
|
throw new Error('Attribute urlFile or blobFile is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.urlFile) {
|
if (this.urlFile) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let loadingTask = this.getPDFJS().getDocument(this.urlFile);
|
this.executePdf(this.urlFile, resolve, reject);
|
||||||
|
});
|
||||||
loadingTask.onProgress = (progressData) => {
|
} else {
|
||||||
let level = progressData.loaded / progressData.total;
|
return new Promise((resolve, reject) => {
|
||||||
this.laodingPercent = Math.round(level * 100);
|
let reader = new FileReader();
|
||||||
|
reader.onload = () => {
|
||||||
|
this.executePdf(reader.result, resolve, reject);
|
||||||
};
|
};
|
||||||
|
reader.readAsArrayBuffer(this.blobFile);
|
||||||
loadingTask.then((pdfDocument) => {
|
|
||||||
this.currentPdfDocument = pdfDocument;
|
|
||||||
this.totalPages = pdfDocument.numPages;
|
|
||||||
this.page = 1;
|
|
||||||
this.displayPage = 1;
|
|
||||||
this.initPDFViewer(this.currentPdfDocument);
|
|
||||||
|
|
||||||
this.currentPdfDocument.getPage(1).then(() => {
|
|
||||||
this.scalePage('auto');
|
|
||||||
resolve();
|
|
||||||
}, (error) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
|
|
||||||
}, (error) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
executePdf(src, resolve, reject) {
|
||||||
|
let loadingTask = this.getPDFJS().getDocument(src);
|
||||||
|
|
||||||
|
loadingTask.onProgress = (progressData) => {
|
||||||
|
let level = progressData.loaded / progressData.total;
|
||||||
|
this.laodingPercent = Math.round(level * 100);
|
||||||
|
};
|
||||||
|
|
||||||
|
loadingTask.then((pdfDocument) => {
|
||||||
|
this.currentPdfDocument = pdfDocument;
|
||||||
|
this.totalPages = pdfDocument.numPages;
|
||||||
|
this.page = 1;
|
||||||
|
this.displayPage = 1;
|
||||||
|
this.initPDFViewer(this.currentPdfDocument);
|
||||||
|
|
||||||
|
this.currentPdfDocument.getPage(1).then(() => {
|
||||||
|
this.scalePage('auto');
|
||||||
|
resolve();
|
||||||
|
}, (error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
}, (error) => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the PDFJS global object (exist to facilitate the mock of PDFJS in the test)
|
* return the PDFJS global object (exist to facilitate the mock of PDFJS in the test)
|
||||||
*
|
*
|
||||||
|
@ -41,14 +41,14 @@
|
|||||||
|
|
||||||
<!-- Start View Switch-->
|
<!-- Start View Switch-->
|
||||||
<div *ngIf="isPdf()">
|
<div *ngIf="isPdf()">
|
||||||
<pdf-viewer [showToolbar]="showToolbar" [urlFile]="urlFileContent"
|
<pdf-viewer [showToolbar]="showToolbar" [blobFile]="blobFile" [urlFile]="urlFileContent"
|
||||||
[nameFile]="displayName"></pdf-viewer>
|
[nameFile]="displayName"></pdf-viewer>
|
||||||
</div>
|
</div>
|
||||||
<div class="center-element" *ngIf="isImage()">
|
<div class="center-element" *ngIf="isImage()">
|
||||||
<img-viewer [urlFile]="urlFileContent" [nameFile]="displayName"></img-viewer>
|
<img-viewer [urlFile]="urlFileContent" [nameFile]="displayName" [blobFile]="blobFile"></img-viewer>
|
||||||
</div>
|
</div>
|
||||||
<div class="center-element" *ngIf="isMedia()">
|
<div class="center-element" *ngIf="isMedia()">
|
||||||
<media-player [urlFile]="urlFileContent" [mimeType]="mimeType"
|
<media-player [urlFile]="urlFileContent" [mimeType]="mimeType" [blobFile]="blobFile"
|
||||||
[nameFile]="displayName"></media-player>
|
[nameFile]="displayName"></media-player>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -31,6 +31,9 @@ export class ViewerComponent {
|
|||||||
@Input()
|
@Input()
|
||||||
urlFile: string = '';
|
urlFile: string = '';
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
blobFile: Blob;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
fileNodeId: string = null;
|
fileNodeId: string = null;
|
||||||
|
|
||||||
@ -43,6 +46,9 @@ export class ViewerComponent {
|
|||||||
@Input()
|
@Input()
|
||||||
showToolbar: boolean = true;
|
showToolbar: boolean = true;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
displayName: string;
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
showViewerChange: EventEmitter<boolean> = new EventEmitter<boolean>();
|
showViewerChange: EventEmitter<boolean> = new EventEmitter<boolean>();
|
||||||
|
|
||||||
@ -55,7 +61,6 @@ export class ViewerComponent {
|
|||||||
|
|
||||||
urlFileContent: string;
|
urlFileContent: string;
|
||||||
otherMenu: any;
|
otherMenu: any;
|
||||||
displayName: string;
|
|
||||||
extension: string;
|
extension: string;
|
||||||
mimeType: string;
|
mimeType: string;
|
||||||
loaded: boolean = false;
|
loaded: boolean = false;
|
||||||
@ -70,12 +75,16 @@ export class ViewerComponent {
|
|||||||
if (this.showViewer) {
|
if (this.showViewer) {
|
||||||
this.hideOtherHeaderBar();
|
this.hideOtherHeaderBar();
|
||||||
this.blockOtherScrollBar();
|
this.blockOtherScrollBar();
|
||||||
if (!this.urlFile && !this.fileNodeId) {
|
if (!this.urlFile && !this.blobFile && !this.fileNodeId) {
|
||||||
throw new Error('Attribute urlFile or fileNodeId is required');
|
throw new Error('Attribute urlFile or fileNodeId or blobFile is required');
|
||||||
}
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let alfrescoApi = this.apiService.getInstance();
|
let alfrescoApi = this.apiService.getInstance();
|
||||||
if (this.urlFile) {
|
if (this.blobFile) {
|
||||||
|
this.mimeType = this.blobFile.type;
|
||||||
|
this.extensionChange.emit(this.mimeType);
|
||||||
|
resolve();
|
||||||
|
} else if (this.urlFile) {
|
||||||
let filenameFromUrl = this.getFilenameFromUrl(this.urlFile);
|
let filenameFromUrl = this.getFilenameFromUrl(this.urlFile);
|
||||||
this.displayName = filenameFromUrl ? filenameFromUrl : '';
|
this.displayName = filenameFromUrl ? filenameFromUrl : '';
|
||||||
this.extension = this.getFileExtension(filenameFromUrl);
|
this.extension = this.getFileExtension(filenameFromUrl);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user