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.
 
 
 
 
 

76 lines
2.1 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { merge, Observable, timer } from 'rxjs';
import { delay } from 'rxjs/operators';
import {
allParams,
AppsState,
HistoryChannelUpdated,
HistoryEventDto,
HistoryService,
MessageBus,
switchSafe,
Version
} from '@app/shared';
import { ContentVersionSelected } from './../messages';
@Component({
selector: 'sqx-history',
styleUrls: ['./content-history-page.component.scss'],
templateUrl: './content-history-page.component.html'
})
export class ContentHistoryPageComponent {
public get channel(): string {
let channelPath = this.route.snapshot.data.channel;
if (channelPath) {
const params = allParams(this.route);
for (const key in params) {
if (params.hasOwnProperty(key)) {
const value = params[key];
channelPath = channelPath.replace(`{${key}}`, value);
}
}
}
return channelPath;
}
public events: Observable<ReadonlyArray<HistoryEventDto>> =
merge(
timer(0, 10000),
this.messageBus.of(HistoryChannelUpdated).pipe(delay(1000))
).pipe(
switchSafe(() => this.historyService.getHistory(this.appsState.appName, this.channel)));
constructor(
private readonly appsState: AppsState,
private readonly historyService: HistoryService,
private readonly messageBus: MessageBus,
private readonly route: ActivatedRoute
) {
}
public loadVersion(version: number) {
this.messageBus.emit(new ContentVersionSelected(new Version(version.toString()), false));
}
public compareVersion(version: number) {
this.messageBus.emit(new ContentVersionSelected(new Version(version.toString()), true));
}
public trackByEvent(index: number, event: HistoryEventDto) {
return event.eventId;
}
}