Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import {Router} from '@angular/router';
- import {Http, Response, Headers, RequestOptions} from "@angular/http";
- import {Injectable} from '@angular/core';
- import {Observable} from "rxjs/Rx";
- import 'rxjs/add/operator/map';
- import {projects} from '../projects';
- import { Options } from 'selenium-webdriver/edge';
- import {FormControl, Validators} from '@angular/forms';
- import {NgForm} from '@angular/forms/src/directives/ng_form';
- @Component({
- selector: 'app-useradd',
- templateUrl: './useradd.component.html',
- styles: []
- })
- export class UseraddComponent implements OnInit {
- logo:string;
- custom:string;
- graph:string;
- sensors1:string;
- ohd:string;
- video:string;
- map:string;
- id:String;
- ut:String;
- companyID:String;
- data:any=null;
- dataclient:any=null;
- sysadmin:Boolean;
- dataCompanies:any=null;
- projectData;
- username:string;
- password:string;
- firstname:string;
- lastName:string;
- email:string;
- active:String;
- Company:String;
- MobilePhone:String;
- address:String;
- mailAlarms:Boolean=true;
- messageAlarms:Boolean;
- role:String;
- projects=[];
- selectProject={};
- controllers:any;
- client:any;
- companies:String;
- userRealm:String;
- project:any=[];
- constructor(private router:Router, private http:Http) {
- this.graph = 'assets/images/shortcuts/reports.png',
- this.video = 'assets/images/shortcuts/video-button.png',
- this.ohd = 'assets/images/shortcuts/reports.png',
- this.sensors1 = 'assets/images/shortcuts/reports.png',
- this.custom = 'assets/images/shortcuts/settings.png',
- this.map = 'assets/images/shortcuts/Map-Marker-Marker-Inside-Azure.png',
- this.logo = 'assets/images/amsLogo.png',
- this.projects.push({ id: '' });
- this.projectData = [];
- this.dash(),
- this.getCompanies(),
- //this.getClients(),
- this.getProjects()
- }
- webmaster:Boolean;
- websysadmin:Boolean;
- websys:Boolean;
- userType:String=null;
- public dash(){
- this.userType=localStorage.getItem("userType");
- if(this.userType=="webmaster"){
- this.webmaster=true;
- }
- if (this.userType=="webmaster" || this.userType=="sysadmin" || this.userType=="admin"){
- this.websysadmin=true;
- }
- if (this.userType=="webmaster" || this.userType=="sysadmin" ){
- this.websys=true;
- }
- }
- public pruebasubmit(){
- console.log(this.projects);
- console.log(this.project=[this.projects]);
- }
- public add() {
- this.projects.push({ id: '' });
- }
- public delete(index) {
- this.projects.splice(index, 1);
- }
- public createUser(e){
- // Mapping array projects
- let validation;
- let projects = [];
- this.projects.forEach((key) => {
- if(projects.includes(key.id)) {
- validation = false;
- } else {
- projects.push(key.id);
- validation = true;
- }
- });
- if(!validation) {
- alert('Please dont choose the same projects in the list');
- projects = [];
- return false;
- }
- var response =confirm("Wish you add This User?");
- if(response) {
- if(this.companies=="all") this.userRealm="client";
- else this.userRealm="customer"
- var token = localStorage.getItem('id');
- let headers = new Headers();
- headers.append('Content-Type', 'application/json');
- var request = { userType: this.role,
- userRealm: this.userRealm,
- fName: this.firstname,
- lName: this.lastName,
- isActive: this.active,
- clientId: this.Company,
- mPhone: this.MobilePhone,
- address: this.address,
- getAlarmOnEmail: this.mailAlarms,
- getAlarmOnPhone: this.messageAlarms,
- username: this.username,
- email: this.email,
- password: this.password,
- projectIds: projects,
- controllerIds: this.controllers,
- companyid: this.companies
- };
- var url = "http://35.182.172.115:3000/api/users?access_token=" + token;
- return this.http.post(url, request, {headers:headers})
- .map(res => res.json())
- .subscribe(res => {
- this.data = res;
- this.router.navigate(['users']);
- });
- } else {
- this.router.navigate(['useradd']);
- }
- }
- private getClients(){
- this.id = localStorage.getItem("id");
- this.ut = localStorage.getItem('userType');
- this.companyID=localStorage.getItem("clientID");
- let headers = new Headers({ 'Content-Type': 'application/json', 'access_token': this.id});
- let options=new RequestOptions({headers:headers});
- //this.Url='http://35.182.172.115:3000/api/projects';
- //return this.http.get(`${this.Url}/${this.data['companyId']}`, options)
- return this.http.get('http://35.182.172.115:3000/api/clients?access_token='+this.id)
- .map(res => res.json())
- .subscribe(data=>{
- this.dataclient=data;
- })
- }
- private getCompanies(){
- this.id=localStorage.getItem("id");
- this.ut=localStorage.getItem("userType");
- this.companyID=localStorage.getItem("clientID");
- let headers = new Headers({ 'Content-Type': 'application/json', 'access_token': this.id});
- let options=new RequestOptions({headers:headers});
- //this.Url='http://35.182.172.115:3000/api/projects';
- //return this.http.get(`${this.Url}/${this.data['companyId']}`, options)
- return this.http.get('http://35.182.172.115:3000/api/companies?access_token='+this.id)
- .map(res => res.json())
- .subscribe(data=>{
- this.dataCompanies=data;
- })
- }
- private getProjects(){
- this.id=localStorage.getItem("id");
- this.ut=localStorage.getItem("ut");
- this.companyID=localStorage.getItem("clientID");
- let headers = new Headers({ 'Content-Type': 'application/json', 'access_token': this.id});
- let options=new RequestOptions({headers:headers});
- //this.Url='http://35.182.172.115:3000/api/projects';
- //return this.http.get(`${this.Url}/${this.data['companyId']}`, options)
- return this.http.get('http://35.182.172.115:3000/api/projects?access_token='+ this.id)
- .map(res => res.json())
- .subscribe(data=>{
- console.log('data');
- console.log(data);
- this.projectData= data;
- })
- }
- ngOnInit() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement