blob: 62b1613e0c1c17e2b5ab2343fcfd27d122627970 [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import {Component, OnDestroy, OnInit} from "@angular/core";
import {select, Store} from "@ngrx/store";
import {Subscription} from "rxjs";
import {filter, take} from "rxjs/operators";
import {IAPIProcessTask} from "../../../../core/api/process";
import {
addCommentAction,
claimTaskAction,
currentActivityIds,
deleteCommentAction,
fetchStatementDetailsAction,
processDiagramSelector,
processNameSelector,
processVersionSelector,
queryParamsIdSelector,
statementCommentsSelector,
statementSelector
} from "../../../../store";
import {statementDetailsButtonSelector} from "../../selectors";
import {processHistoryDataSelector} from "../../selectors/process-details.selectors";
@Component({
selector: "app-statement-details",
templateUrl: "./statement-details.component.html",
styleUrls: ["./statement-details.component.scss"]
})
export class StatementDetailsComponent implements OnInit, OnDestroy {
public statementId$ = this.store.pipe(select(queryParamsIdSelector));
public buttons$ = this.store.pipe(select(statementDetailsButtonSelector));
public comments$ = this.store.pipe(select(statementCommentsSelector));
public statement$ = this.store.pipe(select(statementSelector));
public processName$ = this.store.pipe(select(processNameSelector));
public processVersion$ = this.store.pipe(select(processVersionSelector));
public processHistoryData$ = this.store.pipe(select(processHistoryDataSelector));
public processDiagram$ = this.store.pipe(select(processDiagramSelector));
public processCurrentActivityIds$ = this.store.pipe(select(currentActivityIds));
private subscription: Subscription;
public constructor(private readonly store: Store) {
}
public ngOnInit(): void {
this.subscription = this.statementId$
.pipe(filter((statementId) => statementId != null))
.subscribe((statementId) => this.store.dispatch(fetchStatementDetailsAction({statementId})));
}
public ngOnDestroy(): void {
if (this.subscription != null) {
this.subscription.unsubscribe();
this.subscription = null;
}
}
public editTask(task: IAPIProcessTask, options?: any) {
this.store.dispatch(claimTaskAction({
statementId: task?.statementId,
taskId: task?.taskId,
options
}));
}
public async addComment(text: string) {
const statementId = await this.statementId$.pipe(take(1)).toPromise();
this.store.dispatch(addCommentAction({statementId, text}));
}
public async deleteComment(commentId: number) {
const statementId = await this.statementId$.pipe(take(1)).toPromise();
this.store.dispatch(deleteCommentAction({statementId, commentId}));
}
}