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.
 
 
 
 
 

64 lines
1.7 KiB

/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
*/
import { ChangeDetectionStrategy, 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
} from '@app/shared/internal';
@Component({
selector: 'sqx-history',
styleUrls: ['./history.component.scss'],
templateUrl: './history.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class HistoryComponent {
private readonly channel = this.calculateChannel();
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
) {
}
private calculateChannel(): string {
let channel = this.route.snapshot.data['channel'];
if (channel) {
const params = allParams(this.route);
for (const key in params) {
if (params.hasOwnProperty(key)) {
const value = params[key];
channel = channel.replace(`{${key}}`, value);
}
}
}
return channel;
}
}