mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
renditions available methods
This commit is contained in:
parent
8c76aed11d
commit
0c60ff168d
@ -154,6 +154,12 @@ bootstrap(MyDemoApp, [
|
||||
|
||||
```
|
||||
|
||||
#### Renditions Service
|
||||
|
||||
* getRenditionsListByNodeId(nodeId: string)
|
||||
* createRendition(nodeId: string, encoding: string)
|
||||
* getRendition(nodeId: string, encoding: string)
|
||||
* isRenditionAvailable(nodeId: string, encoding: string)
|
||||
|
||||
## Build from sources
|
||||
|
||||
|
@ -28,6 +28,14 @@ describe('RenditionsService', () => {
|
||||
let service: any;
|
||||
|
||||
let fakeRedition = {
|
||||
'entry': {
|
||||
'id': 'pdf',
|
||||
'content': {'mimeType': 'application/pdf', 'mimeTypeName': 'Adobe PDF Document'},
|
||||
'status': 'NOT_CREATED'
|
||||
}
|
||||
};
|
||||
|
||||
let fakeReditionsList = {
|
||||
'list': {
|
||||
'pagination': {
|
||||
'count': 6,
|
||||
@ -95,12 +103,41 @@ describe('RenditionsService', () => {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
|
||||
it('Get redition list service should call the server with the ID passed', (done) => {
|
||||
service.getRenditionsListByNodeId('fake-node-id').subscribe((res) => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions');
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeReditionsList)
|
||||
});
|
||||
});
|
||||
|
||||
it('Get redition service should call the server with the ID passed', (done) => {
|
||||
service.getRendition('fake-node-id', 'pdf').subscribe((res) => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions/pdf');
|
||||
expect(res.entry.status).toBe('NOT_CREATED');
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeRedition)
|
||||
});
|
||||
});
|
||||
|
||||
it('isRenditionsAvailable service should call the server with the ID passed and return false if is not created', (done) => {
|
||||
service.isRenditionAvailable('fake-node-id', 'pdf').subscribe((res) => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().url).toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/fake-node-id/renditions/pdf');
|
||||
expect(res).toBe(false);
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
@ -131,7 +168,7 @@ describe('RenditionsService', () => {
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 403,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeRedition)
|
||||
responseText: 'error'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -31,19 +31,31 @@ export class RenditionsService {
|
||||
|
||||
}
|
||||
|
||||
isReditionsAvailable(nodeId: string, encoding: string) {
|
||||
this.apiService.getInstance().core.renditionsApi.getRenditions(nodeId).then((res) => {
|
||||
console.log('res' + res);
|
||||
isRenditionAvailable(nodeId: string, encoding: string) {
|
||||
return Observable.create((observer) => {
|
||||
this.getRendition(nodeId, encoding).subscribe((res) => {
|
||||
let isAvailable = true;
|
||||
if (res.entry.status === 'NOT_CREATED') {
|
||||
isAvailable = false;
|
||||
}
|
||||
observer.next(isAvailable);
|
||||
observer.complete();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getRendition(nodeId: string, encoding: string) {
|
||||
return Observable.fromPromise(this.apiService.getInstance().core.renditionsApi.getRendition(nodeId, encoding))
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
getRenditionsListByNodeId(nodeId: string) {
|
||||
return Observable.fromPromise(this.apiService.getInstance().core.renditionsApi.getRenditions(nodeId))
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
createRendition(nodeId: string, encoding: string) {
|
||||
return Observable.fromPromise(this.apiService.getInstance().core.renditionsApi.createRendition(nodeId, encoding))
|
||||
return Observable.fromPromise(this.apiService.getInstance().core.renditionsApi.createRendition(nodeId, {id: 'pdf'}))
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user