mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-3176] file content reload fixed (#3501)
* file content reload fixed * refactoring & layout fix * resolve indentation problems * missing semicolon
This commit is contained in:
@@ -15,12 +15,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, Input, OnChanges, OnInit, SimpleChanges, ViewEncapsulation } from '@angular/core';
|
import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewEncapsulation } from '@angular/core';
|
||||||
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import { CardViewItem, NodesApiService, LogService, CardViewUpdateService, AlfrescoApiService } from '@alfresco/adf-core';
|
import { CardViewItem, NodesApiService, LogService, CardViewUpdateService, AlfrescoApiService } from '@alfresco/adf-core';
|
||||||
import { ContentMetadataService } from '../../services/content-metadata.service';
|
import { ContentMetadataService } from '../../services/content-metadata.service';
|
||||||
import { CardViewGroup } from '../../interfaces/content-metadata.interfaces';
|
import { CardViewGroup } from '../../interfaces/content-metadata.interfaces';
|
||||||
|
import { Subscription } from 'rxjs/Subscription';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-content-metadata',
|
selector: 'adf-content-metadata',
|
||||||
@@ -29,7 +30,7 @@ import { CardViewGroup } from '../../interfaces/content-metadata.interfaces';
|
|||||||
host: { 'class': 'adf-content-metadata' },
|
host: { 'class': 'adf-content-metadata' },
|
||||||
encapsulation: ViewEncapsulation.None
|
encapsulation: ViewEncapsulation.None
|
||||||
})
|
})
|
||||||
export class ContentMetadataComponent implements OnChanges, OnInit {
|
export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
|
||||||
/** (required) The node entity to fetch metadata about */
|
/** (required) The node entity to fetch metadata about */
|
||||||
@Input()
|
@Input()
|
||||||
node: MinimalNodeEntryEntity;
|
node: MinimalNodeEntryEntity;
|
||||||
@@ -59,6 +60,7 @@ export class ContentMetadataComponent implements OnChanges, OnInit {
|
|||||||
componentInited: boolean = false;
|
componentInited: boolean = false;
|
||||||
basicProperties$: Observable<CardViewItem[]>;
|
basicProperties$: Observable<CardViewItem[]>;
|
||||||
groupedProperties$: Observable<CardViewGroup[]>;
|
groupedProperties$: Observable<CardViewGroup[]>;
|
||||||
|
disposableNodeUpdate: Subscription;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private contentMetadataService: ContentMetadataService,
|
private contentMetadataService: ContentMetadataService,
|
||||||
@@ -69,7 +71,7 @@ export class ContentMetadataComponent implements OnChanges, OnInit {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.cardViewUpdateService.itemUpdated$.switchMap(this.saveNode.bind(this)).subscribe(
|
this.disposableNodeUpdate = this.cardViewUpdateService.itemUpdated$.switchMap(this.saveNode.bind(this)).subscribe(
|
||||||
updatedNode => {
|
updatedNode => {
|
||||||
Object.assign(this.node, updatedNode);
|
Object.assign(this.node, updatedNode);
|
||||||
this.alfrescoApiService.nodeUpdated.next(this.node);
|
this.alfrescoApiService.nodeUpdated.next(this.node);
|
||||||
@@ -93,4 +95,9 @@ export class ContentMetadataComponent implements OnChanges, OnInit {
|
|||||||
private saveNode({ changed: nodeBody }): Observable<MinimalNodeEntryEntity> {
|
private saveNode({ changed: nodeBody }): Observable<MinimalNodeEntryEntity> {
|
||||||
return this.nodesApiService.updateNode(this.node.id, nodeBody);
|
return this.nodesApiService.updateNode(this.node.id, nodeBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.disposableNodeUpdate.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -122,16 +122,7 @@
|
|||||||
</adf-toolbar>
|
</adf-toolbar>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<ng-container *ngIf="isLoading">
|
<div fxLayout="row" fxFlex="1 1 auto">
|
||||||
<div class="adf-viewer__loading-screen" fxFlex="1 1 auto">
|
|
||||||
<h2>{{ 'ADF_VIEWER.LOADING' | translate }}</h2>
|
|
||||||
<div>
|
|
||||||
<mat-spinner></mat-spinner>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</ng-container>
|
|
||||||
|
|
||||||
<div *ngIf="!isLoading" fxLayout="row" fxFlex="1 1 auto">
|
|
||||||
|
|
||||||
<ng-container *ngIf="allowSidebar && showSidebar">
|
<ng-container *ngIf="allowSidebar && showSidebar">
|
||||||
<div class="adf-viewer__sidebar" [ngClass]="getSideBarStyle()" fxFlexOrder="{{sidebarPosition === 'left'? 1 : 4 }}">
|
<div class="adf-viewer__sidebar" [ngClass]="getSideBarStyle()" fxFlexOrder="{{sidebarPosition === 'left'? 1 : 4 }}">
|
||||||
@@ -142,7 +133,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<div class="adf-viewer-main" fxFlexOrder="{{sidebarPosition !== 'left'? 1 : 4}}" fxFlex="1 1 auto">
|
<div *ngIf="isLoading" class="adf-viewer-main" fxFlexOrder="{{sidebarPosition !== 'left'? 1 : 4}}" fxFlex="1 1 auto">
|
||||||
|
<div class="adf-viewer-layout-content adf-viewer__fullscreen-container">
|
||||||
|
<div class="adf-viewer-content-container">
|
||||||
|
<ng-container *ngIf="isLoading">
|
||||||
|
<div class="adf-viewer__loading-screen" fxFlex="1 1 auto">
|
||||||
|
<h2>{{ 'ADF_VIEWER.LOADING' | translate }}</h2>
|
||||||
|
<div>
|
||||||
|
<mat-spinner></mat-spinner>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div *ngIf="!isLoading" class="adf-viewer-main" fxFlexOrder="{{sidebarPosition !== 'left'? 1 : 4}}" fxFlex="1 1 auto">
|
||||||
<div class="adf-viewer-layout-content adf-viewer__fullscreen-container">
|
<div class="adf-viewer-layout-content adf-viewer__fullscreen-container">
|
||||||
<div class="adf-viewer-content-container" [ngSwitch]="viewerType">
|
<div class="adf-viewer-content-container" [ngSwitch]="viewerType">
|
||||||
<ng-container *ngSwitchCase="'pdf'">
|
<ng-container *ngSwitchCase="'pdf'">
|
||||||
|
@@ -209,7 +209,6 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
@Output()
|
@Output()
|
||||||
navigateNext = new EventEmitter();
|
navigateNext = new EventEmitter();
|
||||||
|
|
||||||
showPdfThumbnails: boolean = false;
|
|
||||||
viewerType = 'unknown';
|
viewerType = 'unknown';
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
node: MinimalNodeEntryEntity;
|
node: MinimalNodeEntryEntity;
|
||||||
@@ -265,7 +264,10 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
private onNodeUpdated(node: MinimalNodeEntryEntity) {
|
private onNodeUpdated(node: MinimalNodeEntryEntity) {
|
||||||
if (node && node.id === this.nodeId) {
|
if (node && node.id === this.nodeId) {
|
||||||
this.generateCacheBusterNumber();
|
this.generateCacheBusterNumber();
|
||||||
this.setUpNodeFile(node);
|
this.isLoading = true;
|
||||||
|
this.setUpNodeFile(node).then(() => {
|
||||||
|
this.isLoading = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,15 +276,20 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
if (!this.isSourceDefined()) {
|
if (!this.isSourceDefined()) {
|
||||||
throw new Error('A content source attribute value is missing.');
|
throw new Error('A content source attribute value is missing.');
|
||||||
}
|
}
|
||||||
|
this.isLoading = true;
|
||||||
|
|
||||||
if (this.blobFile) {
|
if (this.blobFile) {
|
||||||
this.setUpBlobData();
|
this.setUpBlobData();
|
||||||
|
this.isLoading = false;
|
||||||
} else if (this.urlFile) {
|
} else if (this.urlFile) {
|
||||||
this.setUpUrlFile();
|
this.setUpUrlFile();
|
||||||
|
this.isLoading = false;
|
||||||
} else if (this.nodeId) {
|
} else if (this.nodeId) {
|
||||||
this.isLoading = true;
|
|
||||||
this.apiService.nodesApi.getNodeInfo(this.nodeId).then(
|
this.apiService.nodesApi.getNodeInfo(this.nodeId).then(
|
||||||
(data: MinimalNodeEntryEntity) => {
|
(data: MinimalNodeEntryEntity) => {
|
||||||
this.setUpNodeFile(data);
|
this.setUpNodeFile(data).then(() => {
|
||||||
|
this.isLoading = false;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
@@ -290,10 +297,10 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else if (this.sharedLinkId) {
|
} else if (this.sharedLinkId) {
|
||||||
this.isLoading = true;
|
|
||||||
|
|
||||||
this.apiService.sharedLinksApi.getSharedLink(this.sharedLinkId).then(details => {
|
this.apiService.sharedLinksApi.getSharedLink(this.sharedLinkId).then(details => {
|
||||||
this.setUpSharedLinkFile(details);
|
this.setUpSharedLinkFile(details);
|
||||||
|
this.isLoading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -301,7 +308,6 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
|
|
||||||
private setUpBlobData() {
|
private setUpBlobData() {
|
||||||
this.displayName = this.getDisplayName('Unknown');
|
this.displayName = this.getDisplayName('Unknown');
|
||||||
this.isLoading = true;
|
|
||||||
this.mimeType = this.blobFile.type;
|
this.mimeType = this.blobFile.type;
|
||||||
this.viewerType = this.getViewerTypeByMimeType(this.mimeType);
|
this.viewerType = this.getViewerTypeByMimeType(this.mimeType);
|
||||||
|
|
||||||
@@ -309,12 +315,10 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
// TODO: wrap blob into the data url and allow downloading
|
// TODO: wrap blob into the data url and allow downloading
|
||||||
|
|
||||||
this.extensionChange.emit(this.mimeType);
|
this.extensionChange.emit(this.mimeType);
|
||||||
this.isLoading = false;
|
|
||||||
this.scrollTop();
|
this.scrollTop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private setUpUrlFile() {
|
private setUpUrlFile() {
|
||||||
this.isLoading = true;
|
|
||||||
let filenameFromUrl = this.getFilenameFromUrl(this.urlFile);
|
let filenameFromUrl = this.getFilenameFromUrl(this.urlFile);
|
||||||
this.displayName = this.getDisplayName(filenameFromUrl);
|
this.displayName = this.getDisplayName(filenameFromUrl);
|
||||||
this.extension = this.getFileExtension(filenameFromUrl);
|
this.extension = this.getFileExtension(filenameFromUrl);
|
||||||
@@ -329,11 +333,12 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.extensionChange.emit(this.extension);
|
this.extensionChange.emit(this.extension);
|
||||||
this.isLoading = false;
|
|
||||||
this.scrollTop();
|
this.scrollTop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private setUpNodeFile(data: MinimalNodeEntryEntity) {
|
private async setUpNodeFile(data: MinimalNodeEntryEntity) {
|
||||||
|
let setupNode;
|
||||||
|
|
||||||
if (data.content) {
|
if (data.content) {
|
||||||
this.mimeType = data.content.mimeType;
|
this.mimeType = data.content.mimeType;
|
||||||
}
|
}
|
||||||
@@ -354,14 +359,14 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.viewerType === 'unknown') {
|
if (this.viewerType === 'unknown') {
|
||||||
this.displayNodeRendition(data.id);
|
setupNode = this.displayNodeRendition(data.id);
|
||||||
} else {
|
|
||||||
this.isLoading = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.extensionChange.emit(this.extension);
|
this.extensionChange.emit(this.extension);
|
||||||
this.sidebarTemplateContext.node = data;
|
this.sidebarTemplateContext.node = data;
|
||||||
this.scrollTop();
|
this.scrollTop();
|
||||||
|
|
||||||
|
return setupNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private setUpSharedLinkFile(details: any) {
|
private setUpSharedLinkFile(details: any) {
|
||||||
@@ -380,11 +385,9 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
|
|
||||||
if (this.viewerType === 'unknown') {
|
if (this.viewerType === 'unknown') {
|
||||||
this.displaySharedLinkRendition(this.sharedLinkId);
|
this.displaySharedLinkRendition(this.sharedLinkId);
|
||||||
} else {
|
|
||||||
this.isLoading = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.extensionChange.emit(this.extension);
|
this.extensionChange.emit(this.extension);
|
||||||
this.isLoading = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleSidebar() {
|
toggleSidebar() {
|
||||||
@@ -606,8 +609,6 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async displayNodeRendition(nodeId: string) {
|
private async displayNodeRendition(nodeId: string) {
|
||||||
this.isLoading = true;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const rendition = await this.resolveRendition(nodeId, 'pdf');
|
const rendition = await this.resolveRendition(nodeId, 'pdf');
|
||||||
if (rendition) {
|
if (rendition) {
|
||||||
@@ -624,13 +625,9 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logService.error(err);
|
this.logService.error(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isLoading = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async displaySharedLinkRendition(sharedId: string) {
|
private async displaySharedLinkRendition(sharedId: string) {
|
||||||
this.isLoading = true;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const rendition = await this.apiService.renditionsApi.getSharedLinkRendition(sharedId, 'pdf');
|
const rendition = await this.apiService.renditionsApi.getSharedLinkRendition(sharedId, 'pdf');
|
||||||
if (rendition.entry.status.toString() === 'CREATED') {
|
if (rendition.entry.status.toString() === 'CREATED') {
|
||||||
@@ -649,8 +646,6 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
this.logService.error(error);
|
this.logService.error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isLoading = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async resolveRendition(nodeId: string, renditionId: string): Promise<RenditionEntry> {
|
private async resolveRendition(nodeId: string, renditionId: string): Promise<RenditionEntry> {
|
||||||
@@ -662,42 +657,37 @@ export class ViewerComponent implements OnChanges, OnInit, OnDestroy {
|
|||||||
if (!rendition) {
|
if (!rendition) {
|
||||||
renditionId = 'imgpreview';
|
renditionId = 'imgpreview';
|
||||||
rendition = supported.list.entries.find(obj => obj.entry.id.toLowerCase() === renditionId);
|
rendition = supported.list.entries.find(obj => obj.entry.id.toLowerCase() === renditionId);
|
||||||
|
}
|
||||||
|
|
||||||
if (!rendition) {
|
if (rendition) {
|
||||||
return null;
|
const status = rendition.entry.status.toString();
|
||||||
|
|
||||||
|
if (status === 'NOT_CREATED') {
|
||||||
|
try {
|
||||||
|
await this.apiService.renditionsApi.createRendition(nodeId, { id: renditionId });
|
||||||
|
rendition = await this.waitRendition(nodeId, renditionId, 0);
|
||||||
|
} catch (err) {
|
||||||
|
this.logService.error(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const status = rendition.entry.status.toString();
|
return rendition;
|
||||||
|
|
||||||
if (status === 'CREATED') {
|
|
||||||
return rendition;
|
|
||||||
} else if (status === 'NOT_CREATED') {
|
|
||||||
try {
|
|
||||||
await this.apiService.renditionsApi.createRendition(nodeId, { id: renditionId });
|
|
||||||
return await this.waitRendition(nodeId, renditionId, 0);
|
|
||||||
} catch (err) {
|
|
||||||
this.logService.error(err);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async waitRendition(nodeId: string, renditionId: string, retries: number): Promise<RenditionEntry> {
|
private async waitRendition(nodeId: string, renditionId: string, retries: number): Promise<RenditionEntry> {
|
||||||
const rendition = await this.apiService.renditionsApi.getRendition(nodeId, renditionId);
|
const rendition = await this.apiService.renditionsApi.getRendition(nodeId, renditionId);
|
||||||
|
|
||||||
if (retries > this.maxRetries) {
|
if (this.maxRetries < retries) {
|
||||||
return null;
|
const status = rendition.entry.status.toString();
|
||||||
}
|
|
||||||
|
|
||||||
const status = rendition.entry.status.toString();
|
if (status === 'CREATED') {
|
||||||
|
return rendition;
|
||||||
if (status === 'CREATED') {
|
} else {
|
||||||
return rendition;
|
retries += 1;
|
||||||
} else {
|
await this.wait(1000);
|
||||||
retries += 1;
|
return await this.waitRendition(nodeId, renditionId, retries);
|
||||||
await this.wait(1000);
|
}
|
||||||
return await this.waitRendition(nodeId, renditionId, retries);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user