SHARE
TWEET

Untitled

a guest Apr 20th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2. import {Router} from '@angular/router';
  3. import {Http, Response, Headers, RequestOptions} from "@angular/http";
  4. import {Injectable} from '@angular/core';
  5. import {Observable} from "rxjs/Rx";
  6. import 'rxjs/add/operator/map';
  7. import {projects} from '../projects';
  8. import { Options } from 'selenium-webdriver/edge';
  9. import {FormControl, Validators} from '@angular/forms';
  10. import {NgForm} from '@angular/forms/src/directives/ng_form';
  11.  
  12. @Component({
  13.   selector: 'app-useradd',
  14.   templateUrl: './useradd.component.html',
  15.   styles: []
  16. })
  17. export class UseraddComponent implements OnInit {
  18.  
  19.    logo:string;
  20. custom:string;
  21. graph:string;
  22. sensors1:string;
  23. ohd:string;
  24. video:string;
  25. map:string;
  26. id:String;
  27. ut:String;
  28. companyID:String;
  29. data:any=null;
  30. dataclient:any=null;
  31. sysadmin:Boolean;
  32. dataCompanies:any=null;
  33. projectData;
  34.  
  35.  
  36. username:string;
  37. password:string;
  38. firstname:string;
  39. lastName:string;
  40. email:string;
  41. active:String;
  42. Company:String;
  43. MobilePhone:String;
  44. address:String;
  45. mailAlarms:Boolean=true;
  46. messageAlarms:Boolean;
  47. role:String;
  48. projects=[];
  49. selectProject={};
  50. controllers:any;
  51. client:any;
  52. companies:String;
  53. userRealm:String;
  54. project:any=[];
  55.  
  56.   constructor(private router:Router, private http:Http) {
  57.   this.graph = 'assets/images/shortcuts/reports.png',
  58.   this.video = 'assets/images/shortcuts/video-button.png',
  59.   this.ohd = 'assets/images/shortcuts/reports.png',
  60.   this.sensors1 = 'assets/images/shortcuts/reports.png',
  61.   this.custom = 'assets/images/shortcuts/settings.png',
  62.   this.map = 'assets/images/shortcuts/Map-Marker-Marker-Inside-Azure.png',
  63.   this.logo =   'assets/images/amsLogo.png',
  64.   this.projects.push({ id: '' });
  65.   this.projectData = [];
  66.   this.dash(),
  67.   this.getCompanies(),
  68.   //this.getClients(),
  69.   this.getProjects()
  70.  
  71. }
  72. webmaster:Boolean;
  73.   websysadmin:Boolean;
  74.   websys:Boolean;
  75.   userType:String=null;
  76.    
  77.  
  78.  
  79.   public dash(){
  80.   this.userType=localStorage.getItem("userType");
  81.  
  82.   if(this.userType=="webmaster"){
  83.   this.webmaster=true;
  84.   }
  85.   if (this.userType=="webmaster" || this.userType=="sysadmin" || this.userType=="admin"){
  86.     this.websysadmin=true;
  87.   }
  88.   if (this.userType=="webmaster" || this.userType=="sysadmin" ){
  89.       this.websys=true;
  90.     }
  91.   }
  92.  
  93. public pruebasubmit(){
  94.  
  95.  
  96.   console.log(this.projects);
  97.   console.log(this.project=[this.projects]);
  98. }
  99.  
  100. public add() {
  101.   this.projects.push({ id: '' });
  102. }
  103.  
  104. public delete(index) {
  105.   this.projects.splice(index, 1);
  106. }
  107.  
  108.  
  109. public createUser(e){
  110.   //  Mapping array projects
  111.   let validation;
  112.   let projects = [];
  113.  
  114.   this.projects.forEach((key) => {
  115.     if(projects.includes(key.id)) {
  116.       validation = false;
  117.      } else {
  118.        projects.push(key.id);
  119.        validation = true;
  120.      }
  121.   });
  122.  
  123.   if(!validation) {
  124.     alert('Please dont choose the same projects in the list');
  125.     projects = [];
  126.     return false;
  127.   }
  128.  
  129.   var response =confirm("Wish you add This User?");
  130.   if(response) {
  131.     if(this.companies=="all") this.userRealm="client";
  132.     else this.userRealm="customer"
  133.  
  134.     var token = localStorage.getItem('id');
  135.     let headers = new Headers();
  136.     headers.append('Content-Type', 'application/json');
  137.     var request = { userType: this.role,
  138.                     userRealm: this.userRealm,
  139.                     fName: this.firstname,
  140.                     lName: this.lastName,
  141.                     isActive: this.active,
  142.                     clientId: this.Company,
  143.                     mPhone: this.MobilePhone,
  144.                     address: this.address,
  145.                     getAlarmOnEmail: this.mailAlarms,
  146.                     getAlarmOnPhone: this.messageAlarms,
  147.                     username: this.username,
  148.                     email: this.email,
  149.                     password: this.password,
  150.                     projectIds: projects,
  151.                     controllerIds: this.controllers,
  152.                     companyid: this.companies
  153.                   };
  154.  
  155.   var url = "http://35.182.172.115:3000/api/users?access_token=" + token;
  156.    
  157.   return this.http.post(url, request, {headers:headers})
  158.     .map(res => res.json())
  159.     .subscribe(res => {
  160.       this.data = res;
  161.       this.router.navigate(['users']);
  162.     });
  163.    } else {
  164.      this.router.navigate(['useradd']);
  165.    }
  166. }
  167.  
  168.  
  169. private getClients(){
  170.   this.id = localStorage.getItem("id");
  171.   this.ut = localStorage.getItem('userType');
  172.  
  173.  
  174.   this.companyID=localStorage.getItem("clientID");
  175.   let headers = new Headers({ 'Content-Type': 'application/json', 'access_token': this.id});
  176.       let options=new RequestOptions({headers:headers});
  177.  
  178.  
  179.   //this.Url='http://35.182.172.115:3000/api/projects';
  180.   //return this.http.get(`${this.Url}/${this.data['companyId']}`, options)
  181.   return this.http.get('http://35.182.172.115:3000/api/clients?access_token='+this.id)
  182.   .map(res => res.json())
  183.     .subscribe(data=>{
  184.       this.dataclient=data;
  185.      
  186.      
  187.  
  188.     })
  189. }
  190. private getCompanies(){
  191.   this.id=localStorage.getItem("id");
  192.   this.ut=localStorage.getItem("userType");
  193.  
  194.   this.companyID=localStorage.getItem("clientID");
  195.   let headers = new Headers({ 'Content-Type': 'application/json', 'access_token': this.id});
  196.       let options=new RequestOptions({headers:headers});
  197.  
  198.  
  199.   //this.Url='http://35.182.172.115:3000/api/projects';
  200.   //return this.http.get(`${this.Url}/${this.data['companyId']}`, options)
  201.   return this.http.get('http://35.182.172.115:3000/api/companies?access_token='+this.id)
  202.   .map(res => res.json())
  203.     .subscribe(data=>{
  204.       this.dataCompanies=data;
  205.      
  206.      
  207.  
  208.     })
  209.   }
  210.  
  211.   private getProjects(){
  212.     this.id=localStorage.getItem("id");
  213.     this.ut=localStorage.getItem("ut");
  214.     this.companyID=localStorage.getItem("clientID");
  215.     let headers = new Headers({ 'Content-Type': 'application/json', 'access_token': this.id});
  216.         let options=new RequestOptions({headers:headers});
  217.    
  218.    
  219.     //this.Url='http://35.182.172.115:3000/api/projects';
  220.     //return this.http.get(`${this.Url}/${this.data['companyId']}`, options)
  221.     return this.http.get('http://35.182.172.115:3000/api/projects?access_token='+ this.id)
  222.     .map(res => res.json())
  223.       .subscribe(data=>{
  224.         console.log('data');
  225.         console.log(data);
  226.         this.projectData= data;  
  227.       })
  228.     }
  229.   ngOnInit() {
  230.   }
  231.  
  232. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top