Headless CMS and Content Managment Hub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

63 lines
1.7 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { Component, Input, OnChanges } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import {
AppsState,
AssetDto,
HistoryEventDto,
HistoryService
} from '@app/shared/internal';
interface AssetEvent { event: HistoryEventDto; fileVersion: number; canDownload: boolean; }
@Component({
selector: 'sqx-asset-history',
styleUrls: ['./asset-history.component.scss'],
templateUrl: './asset-history.component.html'
})
export class AssetHistoryComponent implements OnChanges {
@Input()
public asset: AssetDto;
public assetEvents: Observable<ReadonlyArray<AssetEvent>>;
constructor(
private readonly appsState: AppsState,
private readonly historyService: HistoryService
) {
}
public ngOnChanges() {
const channel = `assets.${this.asset.id}`;
this.assetEvents =
this.historyService.getHistory(this.appsState.appName, channel).pipe(
map(events => {
let fileVersion = -1;
return events.map(event => {
const canDownload =
event.eventType === 'AssetUpdatedEventV2' ||
event.eventType === 'AssetCreatedEventV2';
if (canDownload) {
fileVersion++;
}
return { event, fileVersion, canDownload };
});
}));
}
public trackByEvent(index: number, assetEvent: AssetEvent) {
return assetEvent.event.eventId;
}
}