read-submission.component.ts 4.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
import { Component, OnInit } from '@angular/core';
import { ReportType } from '../report-type.enum';
import { WebinReportService } from '../webin-report.service';
import { ChecklistComponent } from '../checklist/checklist.component';
import { UtilService } from '../util/Util-services'
import { retry, mergeMap } from 'rxjs/operators';
import { MatStepper, MatDialog } from '@angular/material';
import { WebinRestService } from '../webin-rest.service';
import { Observable } from 'rxjs';
import { HttpErrorResponse } from '@angular/common/http';
import { PopupMessageComponent } from '../popup-message/popup-message.component';
rajkumar's avatar
rajkumar committed
12
import { WebinAuthenticationService } from '../webin-authentication.service';
rajkumar's avatar
rajkumar committed
13
import { SubmissionResultDialogComponent } from '../submission-result-dialog/submission-result-dialog.component';
14 15 16 17 18 19 20

@Component({
  selector: 'app-read-submission',
  templateUrl: './read-submission.component.html',
  styleUrls: ['./read-submission.component.css']
})
export class ReadSubmissionComponent implements OnInit {
rajkumar's avatar
rajkumar committed
21 22
  panelOpenState: boolean = false;
  reportType = ReportType.studies;
23
  selectedStudy: string;
rajkumar's avatar
rajkumar committed
24 25 26
  readFileDetails = {};
  selectedFieldsArray = [];
  mandatoryFields = {};
27 28
  selectedFieldType: string;
  selectedFieldName: string;
rajkumar's avatar
rajkumar committed
29
  fieldType = {};
Rajkumar-D's avatar
Rajkumar-D committed
30 31
  centerName: String;

32 33 34 35
  constructor(private _webinReportService: WebinReportService,
    private util: UtilService,
    private _webinRestService: WebinRestService,
    public dialog: MatDialog,
rajkumar's avatar
rajkumar committed
36
    private _webinAuthenticationService: WebinAuthenticationService
rajkumar's avatar
rajkumar committed
37
  ) { }
38 39 40 41 42

  ngOnInit() {
    this.getReadFileDetails();
  }

Rajkumar-D's avatar
Rajkumar-D committed
43 44
  getSelectedStudy(studyAlias: object, stepper: MatStepper) {
    this.selectedStudy = studyAlias["alias"];
45 46 47
    stepper.next();
  }

rajkumar's avatar
rajkumar committed
48
  getReadFileDetails() {
49 50
    this._webinReportService.getReadFiletypeAndFields().
      pipe(retry(3)).
rajkumar's avatar
rajkumar committed
51 52 53
      subscribe(data => {
        this.readFileDetails = data;
      });
54 55
  }

rajkumar's avatar
rajkumar committed
56 57 58 59
  selectFileType(fieldType, name) {
    this.selectedFieldsArray = [];
    this.selectedFieldType = fieldType;
    this.selectedFieldName = name
60
    this.readFileDetails["fieldTypes"].forEach(fieldType => {
rajkumar's avatar
rajkumar committed
61 62 63
      if (fieldType.name === this.selectedFieldName) {
        fieldType.fields.forEach(field => {
          if (field.mandatory) {
64 65 66
            this.selectedFieldsArray.push(field);
          }
        })
rajkumar's avatar
rajkumar committed
67

68 69 70 71
      }
    });
  }

rajkumar's avatar
rajkumar committed
72 73 74
  selectedField(event, field) {
    if (event.checked) {
      if (this.selectedFieldsArray.indexOf(field) === -1) {
75 76
        this.selectedFieldsArray.push(field);
      }
rajkumar's avatar
rajkumar committed
77
    } else {
78 79 80 81
      this.selectedFieldsArray.splice(this.selectedFieldsArray.indexOf(field), 1);
    }
  }

rajkumar's avatar
rajkumar committed
82 83 84 85 86 87 88
  downloadReadTsvTemplate() {
    let selObj = { "fields": this.selectedFieldsArray, "displayUnits": false }
    selObj["checklistType"] = "FileType";
    selObj["checklistFieldName"] = "Read submission file type";
    selObj["checklistFieldValue"] = this.selectedFieldType;
    selObj["displayChecklistRow"] = "true";
    this.util.downloadTsvTemplate(selObj).
89
      subscribe((data) => {
rajkumar's avatar
rajkumar committed
90 91 92 93 94
        let blob = new Blob([data], { type: "text/plain;charset=utf-8'" });
        saveAs(blob, this.util.getFileNameByTemplate(this.selectedFieldName, ".tsv"));
      }, (error) => {
        console.log('Error', error);
      });
95 96
  }

rajkumar's avatar
rajkumar committed
97 98
  downloadReadExcelTemplate() {
    let selObj = { "fields": this.selectedFieldsArray, "displayUnits": false }
99 100 101 102 103
    selObj["checklistType"] = "FileType";
    selObj["checklistFieldName"] = "Read submission file type";
    selObj["checklistFieldValue"] = this.selectedFieldType;
    selObj["displayChecklistRow"] = "true";
    this.util.downloadExcelTemplate(selObj).
rajkumar's avatar
rajkumar committed
104 105 106 107 108
      subscribe((data) => {
        let blob = new Blob([data], { type: "text/plain;charset=utf-8'" });
        saveAs(blob, this.util.getFileNameByTemplate(this.selectedFieldName, ".xlsx"));
      }, (error) => {
        console.log('Error', error);
109
      });
rajkumar's avatar
rajkumar committed
110 111
  }

112 113


rajkumar's avatar
rajkumar committed
114 115 116
  buildSelectedChecklistRequestObject(callback) {
    let selectedChecklistObject = {};
    selectedChecklistObject["fields"] = this.selectedFieldsArray;
117 118
  }

rajkumar's avatar
rajkumar committed
119
  uploadFile(form) {
120 121 122 123 124 125 126 127 128 129 130 131
    const formData: FormData = new FormData();
    const observable: Observable<string> =
      this._webinRestService.submitXml(
        null,
        null,
        null,
        null,
        null,
        form.spreadSheet,
        null,
        null,
        null,
Rajkumar-D's avatar
Rajkumar-D committed
132 133
        null,
        this.centerName);
rajkumar's avatar
rajkumar committed
134 135
    let redirectPath = "/read-submission";
    this.util.showSubmissionResponse(this, SubmissionResultDialogComponent, observable, redirectPath)
136 137
  }

rajkumar's avatar
rajkumar committed
138 139
  isEga(): boolean {
    return this._webinAuthenticationService.ega;
140 141
  }

rajkumar's avatar
rajkumar committed
142 143 144 145 146 147
  /*** This method is to hide ega fields */
  displayEgaField(field): boolean {
    let showField = true;
    if (field["is_ega_field"]) {
      if (field["is_ega_field"] != this.isEga()) {
        showField = false;
rajkumar's avatar
rajkumar committed
148 149
      }
    }
rajkumar's avatar
rajkumar committed
150
    return showField;
rajkumar's avatar
rajkumar committed
151
  }
Rajkumar-D's avatar
Rajkumar-D committed
152 153 154 155

  isBroker(): boolean {
    return this._webinAuthenticationService.isBroker();
  }
rajkumar's avatar
rajkumar committed
156
}