blob: 8c589c3c0a2561a504a2d6575d497b4351ef3531 [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,
historySelector,
processDiagramSelector,
processNameSelector,
processVersionSelector,
queryParamsIdSelector,
statementLoadingSelector,
statementSelector,
statementTasksSelector,
statementTitleSelector,
userRolesSelector
} from "../../../../store";
@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 statement$ = this.store.pipe(select(statementSelector));
public title$ = this.store.pipe(select(statementTitleSelector));
public processName$ = this.store.pipe(select(processNameSelector));
public processVersion$ = this.store.pipe(select(processVersionSelector));
public processHistory$ = this.store.pipe(select(historySelector));
public processDiagram$ = this.store.pipe(select(processDiagramSelector));
public processCurrentActivityIds$ = this.store.pipe(select(currentActivityIds));
public userRoles$ = this.store.pipe(select(userRolesSelector));
public tasks$ = this.store.pipe(select(statementTasksSelector));
public loading$ = this.store.pipe(select(statementLoadingSelector));
private subscription: Subscription;
public constructor(public 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}));
}
}