| /******************************************************************************** |
| * 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, OnInit} from "@angular/core"; |
| import {select, Store} from "@ngrx/store"; |
| import {take} from "rxjs/operators"; |
| import {IPageHeaderAction} from "../../../../shared"; |
| import { |
| addNewStatementAction, |
| INewStatementForm, |
| newStatementErrorSelector, |
| newStatementFormSelector, |
| newStatementLoadingSelector, |
| statementTypesSelector |
| } from "../../../../store"; |
| |
| @Component({ |
| selector: "app-new-statement", |
| templateUrl: "./new-statement.component.html", |
| styleUrls: ["./new-statement.component.scss"] |
| }) |
| export class NewStatementComponent implements OnInit { |
| |
| public readonly pageHeaderActions: IPageHeaderAction[] = [ |
| { |
| name: "core.actions.backToDashboard", |
| icon: "arrow_back", |
| routerLink: "/" |
| } |
| ]; |
| |
| public typeOptions$ = this.store.pipe(select(statementTypesSelector)); |
| |
| public form$ = this.store.pipe( |
| select(newStatementFormSelector) |
| ); |
| |
| public isLoading$ = this.store.pipe(select(newStatementLoadingSelector)); |
| |
| public error$ = this.store.pipe(select(newStatementErrorSelector)); |
| |
| public form: INewStatementForm; |
| |
| public constructor(private readonly store: Store) { |
| |
| } |
| |
| public async ngOnInit() { |
| const isLoading = await this.isLoading$.pipe(take(1)).toPromise(); |
| const error = await this.error$.pipe(take(1)).toPromise(); |
| |
| if (isLoading || error != null) { |
| this.form = await this.form$.pipe(take(1)).toPromise(); |
| } |
| } |
| |
| public submit(form: INewStatementForm) { |
| this.store.dispatch(addNewStatementAction({form})); |
| } |
| |
| } |