Newer
Older
import { Component, OnInit } from '@angular/core';
import { AuditMetadata } from '../models/audit-metadata';
import { NewAuditOptionsComponent } from '../new-audit-options/new-audit-options.component';
import { DARSState } from '../store/state';
import { Store } from '@ngrx/store';
import { GlobalState } from '@app/core/state';
import * as selectors from '../store/selectors';
import { Observable } from 'rxjs';
import * as darsActions from '../store/actions';
import { Audit } from '../models/audit/audit';

Scott Berg
committed
import { DarsApiService } from '../services/api.service';
import { Alert } from '@app/core/models/alert';
@Component({
selector: 'cse-dars-view',
templateUrl: './dars-view.component.html',
styleUrls: ['./dars-view.component.scss'],
})
export class DARSViewComponent implements OnInit {
public metadataStatus$: Observable<DARSState['metadata']['status']>;
public programMetadata$: Observable<AuditMetadata[]>;
public whatIfMetadata$: Observable<AuditMetadata[]>;
public visibleAuditStatus$: Observable<DARSState['visibleAudit']['status']>;

Scott Berg
committed
public audit$: Observable<Audit | null>;

Scott Berg
committed
constructor(
private store: Store<GlobalState>,
public dialog: MatDialog,
private api: DarsApiService,
) {}
public ngOnInit() {
this.store.dispatch(new darsActions.StartLoadingMetadata());
this.metadataStatus$ = this.store.select(selectors.metadataStatus);
this.programMetadata$ = this.store.select(selectors.programMetadata);
this.whatIfMetadata$ = this.store.select(selectors.whatIfMetadata);
this.visibleAuditStatus$ = this.store.select(selectors.visibleAuditStatus);

Scott Berg
committed
// this.audit$ = this.store.select(selectors.visibleAudit);
this.audit$ = this.api.getAudit(3);
this.alerts$ = this.store.select(selectors.alerts);
}
public onDismissAlert(key: string) {
this.store.dispatch(new darsActions.DismissAlert({ key }));
public openNewAuditOptionsDialog(selectedAuditType) {
this.dialog.open(NewAuditOptionsComponent, {
data: { selectedAuditType: selectedAuditType },
});
public openAudit(metadata: AuditMetadata) {

Scott Berg
committed
this.store.dispatch(new darsActions.StartLoadingAudit(metadata));
public closeAudit() {
this.store.dispatch(new darsActions.CloseAudit());
public openNewTab() {
window.open(window.location.href, '_blank', 'noopener noreferrer');
}