Util-services.ts 5.21 KB
Newer Older
1
import { Injectable } from '@angular/core';
rajkumar's avatar
rajkumar committed
2
import { HttpClient, HttpClientJsonpModule } from '@angular/common/http';
3
import { environment } from '../../environments/environment';
rajkumar's avatar
rajkumar committed
4
import { tap, startWith, map, debounceTime, catchError } from 'rxjs/operators';
rajkumar's avatar
rajkumar committed
5
import { throwError, Observable } from 'rxjs';
rajkumar's avatar
rajkumar committed
6
import { NonSubmissionResultDialogComponent } from '../non-submission-result-dialog/non-submission-result-dialog.component';
rajkumar's avatar
rajkumar committed
7

8 9 10 11



@Injectable({
rajkumar's avatar
rajkumar committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
  providedIn: 'root'
})
export class UtilService {
  constructor(private httpClient: HttpClient,
  ) { }

  getCountries(prefix) {
    var url = environment.webinAdminServiceUrl + "/country" + "?partialCountry=" + prefix;
    return this.httpClient.get<string[]>(url, { responseType: 'json' });
  }

  saveSubmissionAccount(payload, editMode) {
    if (editMode) {
      return this.httpClient.put(environment.webinAdminServiceUrl + '/' + 'submission-account', payload);
    } else {
      return this.httpClient.post(environment.webinAdminServiceUrl + '/' + 'submission-account', payload);
    }
  }

  getAccountDetails() {
    return this.httpClient.get(environment.webinAdminServiceUrl + '/' + 'submission-account');
  }

  deleteContact(contact) {
    return this.httpClient.delete(environment.webinAdminServiceUrl + '/' + 'submission-contact/' + contact["emailAddress"]);
  }

  saveNewContact(contact) {
    return this.httpClient.post(environment.webinAdminServiceUrl + '/' + 'submission-contact', contact);
  }

  sendResetPasswordRequest(resetPassReq) {
    return this.httpClient.post(environment.webinAdminServiceUrl + '/' + 'request-password-change', resetPassReq);
  }

  resetPassword(resetPassReq, token) {
    return this.httpClient.put(environment.webinAdminServiceUrl + '/' + 'change-password?token=' + token, resetPassReq);
  }

  getPubMed(prefix) {
    var url = environment.pupMedUrl + "?query=" + prefix + "&resultType=lite&cursorMark=*&format=json";
    return this.httpClient.get(url);
  }

  getPubMedById(id) {
    var url = environment.pupMedUrl + "?query=ext_id:" + id + "&resultType=lite&cursorMark=*&format=json";
    return this.httpClient.get(url);
  }

  getProjectDetails(projectId) {
    var url = environment.webinReportServiceUrl + "/projects/" + projectId;
    return this.httpClient.get(url);
  }

  getProjectXml(projectId) {
    var url = environment.webinReportServiceUrl + "/projects/xml/" + projectId;
    return this.httpClient.get(url, { responseType: 'text' })
  }

Rajkumar-D's avatar
Rajkumar-D committed
71 72 73 74 75
  getDacXml(dacId) {
    var url = environment.webinReportServiceUrl + "/dacs/xml/" + dacId;
    return this.httpClient.get(url, { responseType: 'text' })
  }

Rajkumar-D's avatar
Rajkumar-D committed
76 77 78 79 80 81 82 83 84 85
  getDacPolicyXml(policyId) {
    var url = environment.webinReportServiceUrl + "/policies/xml/" + policyId;
    return this.httpClient.get(url, { responseType: 'text' })
  }

  getDacDatasetXml(datasetId) {
    var url = environment.webinReportServiceUrl + "/datasets/xml/" + datasetId;
    return this.httpClient.get(url, { responseType: 'text' })
  }

rajkumar's avatar
rajkumar committed
86
  downloadExcelTemplate(checklistJson) {
Rajkumar-D's avatar
Rajkumar-D committed
87
    return this.httpClient.post(environment.webinRestUrl + '/tab/spreadsheet', checklistJson, { responseType: 'arraybuffer' });
rajkumar's avatar
rajkumar committed
88 89 90
  }

  downloadTsvTemplate(checklistJson) {
Rajkumar-D's avatar
Rajkumar-D committed
91
    return this.httpClient.post(environment.webinRestUrl + '/tab/tsv', checklistJson, { responseType: 'arraybuffer' });
rajkumar's avatar
rajkumar committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
  }

  getFileName(checklist, extension) {
    return checklist.checklistType + "_" + checklist.checklistFieldName.replace(" ", "-") + "_" + new Date().getTime() + extension;
  }

  getFileNameByTemplate(template, extension) {
    return template.replace(/\s/g, "-") + "_template_" + new Date().getTime() + extension;
  }

  getId() {
    return Math.floor(1000 + Math.random() * 9000);
  }

  showSubmissionResponse(component, popupComponent, observable, redirectPath?: string) {
    component.dialog.open(popupComponent, {
      width: '600px',
      data: { "observable": observable, "redirectPath": redirectPath }

    });
  }

  showHttpError(component, popupComponent, err, title) {
    console.error('** Webin submission service failed **', err);
    const message = 'Webin submission service failed. Please try again later. If the problem persists please contact the helpdesk.';
    component.dialog.open(popupComponent, {
      width: '600px',
      data: this.getMessage(true, title, message)
    });
  }

  showError(component, popupComponent, message, title) {
    component.dialog.open(popupComponent, {
      width: '600px',
      data: this.getMessage(true, title, message)
    });
  }

  showSuccess(component, popupComponent, message, title, redirectPath?: string) {
    component.dialog.open(popupComponent, {
      width: '600px',
      data: this.getMessage(false, title, message, redirectPath)
    });
  }
136

rajkumar's avatar
rajkumar committed
137 138 139
  getMessage(isError, title, message, redirectPath?: string) {
    return { "isError": isError, "title": title, "message": message, "redirectPath": redirectPath }
  }
140

rajkumar's avatar
rajkumar committed
141
  getTweet() {
142

rajkumar's avatar
rajkumar committed
143 144 145 146
    /* var url="https://api.twitter.com/1.1/search/tweets.json?q=enasequence&result_type=popular";
     var twitterToken="AAAAAAAAAAAAAAAAAAAAACHPOQAAAAAAK%2FQU%2BR0MB%2BcMXOiWrljWlX3%2BZ%2BU%3DFV9fOpABfT8s69ntGFAUNPwEf6fgcvNk3svOBfYXlKRsuEvUWd";
     var headers = new Headers();
     headers.append('Authorization', 'Bearer '+twitterToken);
rajkumar's avatar
rajkumar committed
147

rajkumar's avatar
rajkumar committed
148
   return this.httpClient.jsonp(url,'callback');*/
rajkumar's avatar
rajkumar committed
149

rajkumar's avatar
rajkumar committed
150
  }
rajkumar's avatar
rajkumar committed
151 152


153

rajkumar's avatar
rajkumar committed
154

rajkumar's avatar
rajkumar committed
155
}