global.ts 8.32 KB
import { CsvService } from "angular2-json2csv";
import { Injectable, Inject } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Http, Response } from '@angular/http';
@Injectable()
export class GlobalService {
  userUrl: string = "";
  resourceBaseUrl: string = ""; 
  hostURL: string = "";
  LocalURL: string = "";
  LiveURL: string = "";
  LiveAPIURL: string = "";
  QAAPIURL: string = "";  
  UserId: number = 0;
  UserType: number = 0;
  UserTypeName: string ="";
  AccountType: number = 0;
  loggedInUser: any;
  DisplayName: string = "";
  NoRecords: string;
  ValidationMsg: string;
  AccountNumber: string;
  LicenseId: number;
  AccLicId: number = 0;
  LoginId:string="";
  ProtocolType:string="";
  aiaIdleTime:number=0;
  aiaIdleTimeOut:number=0;
  aiaPingInterval:number=0;
  SessionId:number=0;
  isSiteUser:boolean=false;
  isAdmin:boolean=false;
  LicenseTypeId:number=0;
  RemoveColumns: Array<string> = ["Serial_No", "LicenseId","RowNum"]
  error;
  public href: string = "";
  constructor(private csvService: CsvService, private http: Http) { 
    if(window.location.host=="localhost:4200")
      {
         // for 'ng serve --open' command
         //**** for localhost:4200 *****//
         var date = new Date();
         var newsessionid = date.getTime();//timestamp is the number of milliseconds that have passed since January 1, 1970
         localStorage.setItem('loggedInUserDetails', JSON.stringify(
          {
            "Id": 1, "FirstName": "Maribel", "LastName": "sfsfsfsfsfsfs", "EmailId": "ravi.vishwakarma@ebix.com", "LoginId": "superadmin", "Password": "ebix@2016","aiaIdleTime": 300,"aiaIdleTimeOut": 30,"aiaPingInterval": 10,"SessionId":newsessionid,"isSiteUser":false,"isAdmin":true, "SecurityQuestionId": 1, "SecurityAnswer": "boxer", "CreatorId": 1, "CreationDate": "2009-03-02T00:00:00", "DeactivationDate": null, "ModifierId": 1, "ModifiedDate": "2017-01-24T02:03:19", "UserType": "Super Admin", "UserTypeId": 1, "IsActive": true, "IsCorrectPassword": false, "IncorrectLoginAttemptCount": 0, "IsBlocked": false, "LicenseId": 0, "EditionId": 0, "LoginFailureCauseId": 0, "Modules": [{ "slug": "da-view-list", "name": "Dissectible Anatomy", "id": 1 }, { "slug": "tile-view-list", "name": "Atlas Anatomy", "id": 2 }, { "slug": "3d-anatomy-list", "name": "3D Anatomy", "id": 3 }, { "slug": "clinical-illustrations", "name": "Clinical Illustrations", "id": 4 }, { "slug": "clinical-animations", "name": "Clinical Animations", "id": 5 }, { "slug": "Link/encyclopedia", "name": "Encyclopedia", "id": 6 }, { "slug": "curriculum-builder", "name": "Curriculum Builder", "id": 7 }, { "slug": "anatomy-test", "name": "Anatomy Test", "id": 8 }, { "slug": "Link/IP-10", "name": "IP 10", "id": 9 }, { "slug": "lab-exercises", "name": "Lab Exercises", "id": 10 }, { "slug": "Link/indepth-reports", "name": "In-Depth Reports", "id": 11 }, { "slug": "Link/complementary-and-alternate-medicine", "name": "CAM", "id": 12 }, { "slug": "ADAM-images", "name": "A.D.A.M. Images", "id": 13 }, { "slug": "Link/bodyguide", "name": "Body Guide", "id": 14 }, { "slug": "Link/health-navigator", "name": "Symptom Navigator", "id": 15 }, { "slug": "Link/wellness-tools", "name": "The Wellness Tools", "id": 16 }, { "slug": "Link/aod", "name": "A.D.A.M. OnDemand", "id": 1017 }], "LicenseInfo": { "Id": 0, "AccountNumber": "AIAS000319" }, "LicenseSubscriptions": null, "IsSubscriptionExpired": false, "SubscriptionExpirationDate": null, "TermsAndConditionsTitle": null, "TermsAndConditionsText": null
          }));
      }
     
        this.loggedInUser = JSON.parse(localStorage.getItem("loggedInUserDetails"));
        if (this.loggedInUser != null) {
          this.UserId = this.loggedInUser.Id;
          this.UserType = this.loggedInUser.UserTypeId;
          this.UserTypeName = this.loggedInUser.UserType;
          this.DisplayName = this.loggedInUser.FirstName + " " + this.loggedInUser.LastName;
          this.LoginId=this.loggedInUser.LoginId;
          this.aiaIdleTime=this.loggedInUser.aiaIdleTime;
          this.aiaIdleTimeOut=this.loggedInUser.aiaIdleTimeOut;
          this.aiaPingInterval=this.loggedInUser.aiaPingInterval;
          this.SessionId=this.loggedInUser.SessionId;
          this.isSiteUser=this.loggedInUser.isSiteUser;
          this.isAdmin=this.loggedInUser.LicenseId==0?true:false;

          if (this.loggedInUser.LicenseInfo != null) {
            this.LicenseTypeId=this.loggedInUser.LicenseInfo.LicenseTypeId;
          }

        }
    
    this.NoRecords = 'No Record Found.';
   
    this.hostURL = "http://localhost/API/Adminapi/"; 
    this.LiveAPIURL = "http://interactiveanatomy.com/API/Adminapi/";
    this.QAAPIURL = "http://qa.beta.interactiveanatomy.com/API/Adminapi/";    
    this.LocalURL = "http://localhost:4200";
   
     // get protocol type
       this.ProtocolType = window.location.protocol+"//";

     if(window.location.host=="localhost:4200")
      {
        // for 'ng serve --open' command
         //**** for localhost:4200 *****//
        this.resourceBaseUrl = this.hostURL;
      }
      else
      {
          // get hosted url on uat and prod  server
        this.resourceBaseUrl = window.location.origin+"/API/Adminapi/";
      
      }

    if (this.resourceBaseUrl == this.ProtocolType+"localhost/API/Adminapi/") {       

      if (this.UserTypeName == "Client Admin" || this.UserTypeName == "District Admin") {
        this.AccountNumber = this.loggedInUser.LicenseInfo.AccountNumber.trim();
      }
      if (this.loggedInUser.LicenseInfo == null) {
        this.AccLicId = 0;
        this.AccountNumber = '';

      }
      else {
        this.AccLicId = this.loggedInUser.LicenseInfo.Id;
        this.AccountNumber = this.loggedInUser.LicenseInfo.AccountNumber.trim();
      }

    }
    // Live
    if ((this.resourceBaseUrl == this.ProtocolType+"interactiveanatomy.com/API/Adminapi/")
         ||(this.resourceBaseUrl == this.ProtocolType+"www.interactiveanatomy.com/API/Adminapi/"))
       {
          this.LiveURL = this.ProtocolType+"interactiveanatomy.com";
          if (this.UserTypeName == "Client Admin" || this.UserTypeName == "District Admin") {
            this.AccountNumber = this.loggedInUser.LicenseInfo.AccountNumber.trim();
            this.AccLicId = this.loggedInUser.LicenseInfo.Id;
          }
          if (this.loggedInUser.LicenseInfo == null) {
            this.AccLicId = 0;
            this.AccountNumber = '';

          }
          else {
            this.AccLicId = this.loggedInUser.LicenseInfo.Id;
            this.AccountNumber = this.loggedInUser.LicenseInfo.AccountNumber.trim();
          }
     }
    
    // QA
    if ((this.resourceBaseUrl == this.ProtocolType+"qa.beta.interactiveanatomy.com/API/Adminapi/")
        || (this.resourceBaseUrl == this.ProtocolType+"www.qa.beta.interactiveanatomy.com/API/Adminapi/")) 
     {
        this.LiveURL = this.ProtocolType+"qa.beta.interactiveanatomy.com";
        if (this.UserTypeName == "Client Admin" || this.UserTypeName == "District Admin") {
          this.AccountNumber = this.loggedInUser.LicenseInfo.AccountNumber.trim();
          this.AccLicId = this.loggedInUser.LicenseInfo.Id;
        }
        if (this.loggedInUser.LicenseInfo == null) {
          this.AccLicId = 0;
          this.AccountNumber = '';

        }
        else {
          this.AccLicId = this.loggedInUser.LicenseInfo.Id;
          this.AccountNumber = this.loggedInUser.LicenseInfo.AccountNumber.trim();;
        }
     }
   
    
  }
  compareTwoDates(todate: string, fromdate: string) {

    if (fromdate ==null ||fromdate =='Invalid Date') {
      this.ValidationMsg = 'From date is Invalid.'
	  if(fromdate ==null)
		{
		  this.ValidationMsg = 'From date is Required.'
		}  
    }
    else if (todate ==null ||todate =='Invalid Date') {
		 this.ValidationMsg = 'To date is Invalid.'
		if(todate ==null)
		{
		  this.ValidationMsg = 'To date is Required.'
		}    
    }
    else if (Date.parse(todate) < Date.parse(fromdate)) {
      this.ValidationMsg = "'To date' must be greater than or equal to 'From date'."
    }
    else {
      this.ValidationMsg = '';
    }
  }

  ExportToCSV(data: any, FileName: string) {
    this.csvService.download(data, FileName);
  }
  // Read Json File for Menu
  public getJSON() {
   
    let apiUrl = './assets/data/Menu.json';
    return this.http.get(apiUrl)
      .map((response: Response) => {        
        const data = response.json();
        return data;
      });
  }  

}