Project

General

Profile

1
import {Component, OnInit} from '@angular/core';
2
import {DocumentClassification} from '../../../../../shared/models/document-classification.interface';
3
import {DocumentSubclassification} from '../../../../../shared/models/document-subclassification.interface';
4
import {DialogService, DynamicDialogConfig, DynamicDialogRef} from 'primeng/dynamicdialog';
5
import {FileViewerPopupComponent} from '../file-viewer-popup/file-viewer-popup.component';
6
import {InboxManagementService} from '../../../../../shared/services/inbox-management.service';
7
import {DocumentClassificationService} from '../../../../../shared/services/document-classification.service';
8
import {DocumentSubclassificationService} from '../../../../../shared/services/document-subclassification.service';
9
import {InboxBatch} from '../../../../../shared/models/inbox-batch.interface';
10
import {ReceivedFile} from '../../../../../shared/models/inbox-document.interface';
11
import { NotificationsHandlingService } from 'src/app/shared/services/notifications-handling/notifications-handling.service';
12
import { ReceivedFiles } from 'src/app/shared/models/receivedFiles.interface';
13

    
14
@Component({
15
  selector: 'app-edit-file-class-and-qeue-to-abby-for-recognition-dialog',
16
  templateUrl: './edit-file-class-and-qeue-to-abby-for-recognition-dialog.component.html',
17
  styleUrls: ['./edit-file-class-and-qeue-to-abby-for-recognition-dialog.component.scss']
18
})
19
export class EditFileClassAndQeueToAbbyForRecognitionDialogComponent implements OnInit {
20

    
21
  selectedClassification = null;
22
  selectedSubClassification = null;
23
  documents: ReceivedFiles[];
24
  subclassificationOptionsDepSelection: DocumentSubclassification[] = [];
25

    
26
  // TODO: Uncomment below when we have services
27
  classificationOptions: DocumentClassification[] = [];
28

    
29
  // TODO: Uncomment below when we have services
30
  subclassificationOptions: DocumentSubclassification[] = [];
31

    
32
  // TODO: Comment below when we have services
33
  private documentBatch: InboxBatch;
34

    
35
  constructor(public ref: DynamicDialogRef
36
    , public config: DynamicDialogConfig
37
    , private dialogService: DialogService
38
    , private inboxService: InboxManagementService
39
    , private documentClassificationsService: DocumentClassificationService
40
    , private documentSubclassificationService: DocumentSubclassificationService
41
    , private notificationService: NotificationsHandlingService) {
42

    
43
    this.config.width = '80vw';
44
    this.config.height = '60vh';
45
    this.config.header = this.config.data.title;
46
  }
47

    
48
  ngOnInit(): void {
49

    
50
    // TODO: call service to get classifications. when it is ready
51
    // TODO: call service to get subclassifications. when it is ready
52
    console.log('hey', this.config.data);
53
    // this.selectedClassification = this.classificationOptions[0].classificationName;
54
    this.documentBatch = this.config.data.document;
55
    this.documents = [this.documentBatch.receivedFile];
56
    this.documentClassificationsService.getAll().subscribe(classes => {
57

    
58
      this.classificationOptions = classes;
59
      this.documentSubclassificationService.getAll().subscribe(subclasses => {
60
        this.subclassificationOptions = subclasses;
61
        this.toBeNamed();
62
      });
63

    
64
    });
65

    
66
  }
67

    
68
  toBeNamed(): void {
69
    console.log(this.subclassificationOptions);
70
    this.subclassificationOptionsDepSelection = this.subclassificationOptions.filter((item) => {
71
      console.log(item);
72
      return item.documentClassification.classificationName === this.selectedClassification;
73
    });
74
  }
75

    
76
  showOrDownloadFile(document: any): void {
77
    this.dialogService.open(FileViewerPopupComponent, {data: document});
78
  }
79

    
80
  onClassificationSelect($event): void {
81
    this.subclassificationOptionsDepSelection = this.subclassificationOptions.filter((item) => {
82
      return item.documentClassification.classificationName === this.selectedClassification;
83
    });
84
  }
85

    
86
  onClassify(): void {
87
    // TODO: Update documents classification and sub-classification on click of classify
88

    
89
    const inboxBatch = this.documentBatch;
90
    (inboxBatch.receivedFile as ReceivedFile).abbyClassification  = this.selectedClassification;
91
    (inboxBatch.receivedFile as ReceivedFile).abbySubClassification = this.selectedSubClassification;
92
    this.inboxService.reclassify(inboxBatch).subscribe( result => {
93
      this.notificationService.showOnIgnoreFileSuccess();
94
    });
95
    this.ref.close();
96
  }
97

    
98
  closeDialog(): void {
99
    this.ref.close();
100
  }
101

    
102
}
103

    
(4-4/4)