mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-1534] Automatic PDF rendering for unsupported types. (#2313)
* move viewer dialog to a separate folder * make dialog take full screen size * automatic PDF conversion * mime type icon in the title * [ADF-1530] correct plain text viewer resolving * separate lightweigh pdf view for the dialog
This commit is contained in:
committed by
Popovics András
parent
3ba93a6840
commit
1cf2db48ac
@@ -122,6 +122,7 @@ import { NodePermissionDirective } from './src/directives/node-permission.direct
|
||||
import { UploadDirective } from './src/directives/upload.directive';
|
||||
|
||||
import { FileSizePipe } from './src/pipes/file-size.pipe';
|
||||
import { MimeTypeIconPipe } from './src/pipes/mime-type-icon.pipe';
|
||||
import { HighlightPipe } from './src/pipes/text-highlight.pipe';
|
||||
import { TimeAgoPipe } from './src/pipes/time-ago.pipe';
|
||||
|
||||
@@ -193,7 +194,8 @@ export function providers() {
|
||||
SharedLinksApiService,
|
||||
SitesApiService,
|
||||
DiscoveryApiService,
|
||||
HighlightTransformService
|
||||
HighlightTransformService,
|
||||
MomentDateAdapter
|
||||
];
|
||||
}
|
||||
|
||||
@@ -212,6 +214,15 @@ export function obsoleteMdlDirectives() {
|
||||
];
|
||||
}
|
||||
|
||||
export function pipes() {
|
||||
return [
|
||||
FileSizePipe,
|
||||
HighlightPipe,
|
||||
TimeAgoPipe,
|
||||
MimeTypeIconPipe
|
||||
];
|
||||
}
|
||||
|
||||
export function createTranslateLoader(http: Http, logService: LogService) {
|
||||
return new AlfrescoTranslateLoader(http, logService);
|
||||
}
|
||||
@@ -240,6 +251,7 @@ export function createTranslateLoader(http: Http, logService: LogService) {
|
||||
],
|
||||
declarations: [
|
||||
...obsoleteMdlDirectives(),
|
||||
...pipes(),
|
||||
UploadDirective,
|
||||
NodePermissionDirective,
|
||||
HighlightDirective,
|
||||
@@ -251,16 +263,12 @@ export function createTranslateLoader(http: Http, logService: LogService) {
|
||||
InfoDrawerTitleDirective,
|
||||
InfoDrawerButtonsDirective,
|
||||
InfoDrawerContentDirective,
|
||||
FileSizePipe,
|
||||
HighlightPipe,
|
||||
TimeAgoPipe,
|
||||
CreateFolderDialogComponent,
|
||||
DownloadZipDialogComponent
|
||||
],
|
||||
providers: [
|
||||
...providers(),
|
||||
...deprecatedProviders(),
|
||||
MomentDateAdapter,
|
||||
{
|
||||
provide: TRANSLATION_PROVIDER,
|
||||
multi: true,
|
||||
@@ -284,14 +292,12 @@ export function createTranslateLoader(http: Http, logService: LogService) {
|
||||
PaginationModule,
|
||||
ToolbarModule,
|
||||
...obsoleteMdlDirectives(),
|
||||
...pipes(),
|
||||
UploadDirective,
|
||||
NodePermissionDirective,
|
||||
HighlightDirective,
|
||||
DataColumnComponent,
|
||||
DataColumnListComponent,
|
||||
FileSizePipe,
|
||||
HighlightPipe,
|
||||
TimeAgoPipe,
|
||||
CreateFolderDialogComponent,
|
||||
DownloadZipDialogComponent,
|
||||
InfoDrawerComponent,
|
||||
|
@@ -0,0 +1,31 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { ThumbnailService } from '../services/thumbnail.service';
|
||||
|
||||
@Pipe({
|
||||
name: 'adfMimeTypeIcon'
|
||||
})
|
||||
export class MimeTypeIconPipe implements PipeTransform {
|
||||
|
||||
constructor(private thumbnailService: ThumbnailService) { }
|
||||
|
||||
transform(text: string): string {
|
||||
return this.thumbnailService.getMimeTypeIcon(text);
|
||||
}
|
||||
}
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AlfrescoApi } from 'alfresco-js-api';
|
||||
import { AlfrescoApi, ContentApi, NodesApi, RenditionsApi } from 'alfresco-js-api';
|
||||
import * as alfrescoApi from 'alfresco-js-api';
|
||||
import { AppConfigService } from './app-config.service';
|
||||
import { StorageService } from './storage.service';
|
||||
@@ -26,10 +26,22 @@ export class AlfrescoApiService {
|
||||
|
||||
private alfrescoApi: AlfrescoApi;
|
||||
|
||||
public getInstance(): AlfrescoApi {
|
||||
getInstance(): AlfrescoApi {
|
||||
return this.alfrescoApi;
|
||||
}
|
||||
|
||||
get contentApi(): ContentApi {
|
||||
return this.getInstance().content;
|
||||
}
|
||||
|
||||
get nodesApi(): NodesApi {
|
||||
return this.getInstance().nodes;
|
||||
}
|
||||
|
||||
get renditionsApi(): RenditionsApi {
|
||||
return this.getInstance().core.renditionsApi;
|
||||
}
|
||||
|
||||
constructor(private appConfig: AppConfigService,
|
||||
private storage: StorageService) {
|
||||
|
||||
|
@@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RenditionEntry, RenditionPaging } from 'alfresco-js-api';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { LogService } from './log.service';
|
||||
|
||||
/**
|
||||
* RenditionsService
|
||||
@@ -28,52 +28,57 @@ import { LogService } from './log.service';
|
||||
@Injectable()
|
||||
export class RenditionsService {
|
||||
|
||||
constructor(private apiService: AlfrescoApiService,
|
||||
private logService: LogService) {
|
||||
|
||||
constructor(private apiService: AlfrescoApiService) {
|
||||
}
|
||||
|
||||
isRenditionAvailable(nodeId: string, encoding: string) {
|
||||
isRenditionAvailable(nodeId: string, encoding: string): Observable<boolean> {
|
||||
return Observable.create((observer) => {
|
||||
this.getRendition(nodeId, encoding).subscribe((res) => {
|
||||
let isAvailable = true;
|
||||
if (res.entry.status === 'NOT_CREATED') {
|
||||
isAvailable = false;
|
||||
this.getRendition(nodeId, encoding).subscribe(
|
||||
(res) => {
|
||||
let isAvailable = true;
|
||||
if (res.entry.status.toString() === 'NOT_CREATED') {
|
||||
isAvailable = false;
|
||||
}
|
||||
observer.next(isAvailable);
|
||||
observer.complete();
|
||||
},
|
||||
() => {
|
||||
observer.next(false);
|
||||
observer.complete();
|
||||
}
|
||||
observer.next(isAvailable);
|
||||
observer.complete();
|
||||
}, () => {
|
||||
observer.next(false);
|
||||
observer.complete();
|
||||
});
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
isConversionPossible(nodeId: string, encoding: string) {
|
||||
isConversionPossible(nodeId: string, encoding: string): Observable<boolean> {
|
||||
return Observable.create((observer) => {
|
||||
this.getRendition(nodeId, encoding).subscribe(() => {
|
||||
observer.next(true);
|
||||
observer.complete();
|
||||
}, () => {
|
||||
observer.next(false);
|
||||
observer.complete();
|
||||
});
|
||||
this.getRendition(nodeId, encoding).subscribe(
|
||||
() => {
|
||||
observer.next(true);
|
||||
observer.complete();
|
||||
},
|
||||
() => {
|
||||
observer.next(false);
|
||||
observer.complete();
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
getRendition(nodeId: string, encoding: string) {
|
||||
return Observable.fromPromise(this.apiService.getInstance().core.renditionsApi.getRendition(nodeId, encoding))
|
||||
.catch(err => this.handleError(err));
|
||||
getRenditionUrl(nodeId: string, encoding: string): string {
|
||||
return this.apiService.contentApi.getRenditionUrl(nodeId, 'pdf');
|
||||
}
|
||||
|
||||
getRenditionsListByNodeId(nodeId: string) {
|
||||
return Observable.fromPromise(this.apiService.getInstance().core.renditionsApi.getRenditions(nodeId))
|
||||
.catch(err => this.handleError(err));
|
||||
getRendition(nodeId: string, encoding: string): Observable<RenditionEntry> {
|
||||
return Observable.fromPromise(this.apiService.renditionsApi.getRendition(nodeId, encoding));
|
||||
}
|
||||
|
||||
createRendition(nodeId: string, encoding: string) {
|
||||
return Observable.fromPromise(this.apiService.getInstance().core.renditionsApi.createRendition(nodeId, {id: encoding}))
|
||||
.catch(err => this.handleError(err));
|
||||
getRenditionsListByNodeId(nodeId: string): Observable<RenditionPaging> {
|
||||
return Observable.fromPromise(this.apiService.renditionsApi.getRenditions(nodeId));
|
||||
}
|
||||
|
||||
createRendition(nodeId: string, encoding: string): Observable<{}> {
|
||||
return Observable.fromPromise(this.apiService.renditionsApi.createRendition(nodeId, {id: encoding}));
|
||||
}
|
||||
|
||||
convert(nodeId: string, encoding: string, pollingInterval: number = 1000) {
|
||||
@@ -85,12 +90,7 @@ export class RenditionsService {
|
||||
return Observable.interval(interval)
|
||||
.switchMap(() => this.getRendition(nodeId, encoding))
|
||||
.takeWhile((data) => {
|
||||
return (data.entry.status !== 'CREATED');
|
||||
return (data.entry.status.toString() !== 'CREATED');
|
||||
});
|
||||
}
|
||||
|
||||
private handleError(error: any): Observable<any> {
|
||||
this.logService.error(error);
|
||||
return Observable.throw(error || 'Server error');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user