Skip to content
Snippets Groups Projects
header.component.ts 1.56 KiB
Newer Older
import { Component } from '@angular/core';
import { Store } from '@ngrx/store';
import { DegreePlannerState } from '@app/degree-planner/store/state';
import { MatDialog, MatSnackBar } from '@angular/material';
import { PromptDialogComponent } from '@app/shared/dialogs/prompt-dialog/prompt-dialog.component';
import { CreatePlan } from '@app/degree-planner/store/actions/plan.actions';
import { AddAcademicYearRequest } from '@app/degree-planner/store/actions/addAcademicYear.actions';
pnogal's avatar
pnogal committed

@Component({
  selector: 'cse-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.scss'],
pnogal's avatar
pnogal committed
})
export class HeaderComponent {
  constructor(
    private store: Store<DegreePlannerState>,
    private dialog: MatDialog,
    private snackBar: MatSnackBar,
  ) {}
pnogal's avatar
pnogal committed

  public printPlan() {
    window.print();
  }
pnogal's avatar
pnogal committed

  public downloadPdf() {
pnogal's avatar
pnogal committed
    // FIXME and open in new window
    this.snackBar.open('Not supported yet');
  }
pnogal's avatar
pnogal committed

  public addPlan() {
    this.dialog
      .open(PromptDialogComponent, {
        data: {
          title: 'Add degree plan',
          confirmText: 'Save',
          inputName: 'i.e. Psychology',
        },
      })
      .afterClosed()
      .subscribe((result: { confirmed: boolean; value: string }) => {
        const { confirmed, value } = result;
        if (confirmed) {
          const action = new CreatePlan({ name: value, primary: false });
          this.store.dispatch(action);
        }
      });
  }

  public addYear() {
    this.store.dispatch(new AddAcademicYearRequest());
    this.snackBar.open('New academic year has been created');
  }
pnogal's avatar
pnogal committed
}