Project

General

Profile

1
import { JournalEntry } from './../../../../shared/models/journal-entry.interface';
2
import { Component, Input, OnInit } from '@angular/core';
3
import { DialogService } from 'primeng/dynamicdialog';
4
import { JournalPreviewDialogComponent } from './journal-entries-verification-dialogs/journal-preview-dialog/journal-preview-dialog.component';
5
import { JournalEditDialogComponent } from './journal-entries-verification-dialogs/journal-edit-dialog/journal-edit-dialog.component';
6
import {JournalViewDialogComponent} from "./journal-entries-verification-dialogs/journal-view-dialog/journal-view-dialog.component";
7

    
8
@Component({
9
  selector: 'app-journal-entries-verification',
10
  templateUrl: './journal-entries-verification.component.html',
11
  styleUrls: ['./journal-entries-verification.component.scss']
12
})
13
export class JournalEntriesVerificationComponent implements OnInit {
14

    
15
  @Input() set journalEntries(journalEntries: JournalEntry[]) {
16

    
17
    // This setter may be called on page setup without arguments.
18
    if (!journalEntries) {
19
      return;
20
    }
21

    
22
    this._journalEntries = journalEntries;
23

    
24
    // Now we have to pick a unique JournalEntry per recordId, for it to hold the 'edit' & 'post' buttons.
25
    let recordToEntryMap = new Map<number, number>();
26

    
27
    for (let entry of journalEntries) {
28
      // If this recordId has already been processed, proceed to the next one.
29
      if (recordToEntryMap.has(entry.recordId)) {
30
        continue;
31
      }
32

    
33
      // Otherwise, create it and keep track of its entry.
34
      recordToEntryMap.set(entry.recordId, entry.id);
35
    }
36

    
37
    // Now that we are finished, keep only the entryIds we found. We have no use for their respective recordIds.
38
    recordToEntryMap.forEach((value, key) => this.buttonHoldingEntriesIDsArray.push(value));
39
  }
40

    
41
  _journalEntries: JournalEntry[] = [];
42
  buttonHoldingEntriesIDsArray: number[] = [];   // An array bearing the IDs of all entries for which the 'edit' & 'post' buttons should be displayed.
43

    
44
  first: number = 0;
45
  rows: number = 4;
46
  loading = false;
47

    
48
  constructor(private dialogService: DialogService) { }
49

    
50
  ngOnInit(): void {
51
  }
52

    
53
  onPagination(event) {
54
    // Since the requested InvoiceProcess comes along with all of its JournalEntries, we simply have to slice the 'journalEntries' input to match each requested page.
55
    // The slicing is requested by the template (see html table's 'value' attribute).
56
    this.first = event.first;
57
  }
58

    
59
  // tslint:disable-next-line:typedef
60
  previewJournalEntry(journalEntry: JournalEntry, rowIndex: number) {
61
    this.dialogService.open(JournalPreviewDialogComponent, { data: { journalsList: this._journalEntries, index: rowIndex, title: 'Previewing of Journal Entries' } });
62
  }
63

    
64
  editJournalEntry(journalEntry: JournalEntry) {
65
    // TODO: perhaps add argument for iframe??
66
    this.dialogService.open(JournalEditDialogComponent, { data: { journalEntry, title: 'Edit of Journal Entries' } });
67
  }
68

    
69
  viewJournalEntry(journalEntry: JournalEntry) {
70
    this.dialogService.open(JournalViewDialogComponent, { data: { journalEntry, title: 'View of Journal Entries' } });
71
  }
72

    
73
  postJournalEntry(journalEntry: JournalEntry) {
74
    // TODO:
75
  }
76
}
(4-4/4)