SHARE
TWEET

Untitled

a guest Jun 5th, 2017 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Created by Thierry on 28/05/2017.
  3.  */
  4. import { Component, OnInit,OnDestroy } from '@angular/core';
  5. import { RegisterService } from '../../services/register/register.service';
  6. import { ChatService }  from '../../services/chat/chat.service';
  7. import { ProfilService }  from '../../services/profil/profil.service';
  8. import { User } from '../../../User';
  9. import { ActivatedRoute } from '@angular/router';
  10. //import { DateModel } from 'ng2-datepicker-bootstrap';
  11. import 'rxjs/add/operator/toPromise';
  12. //import {DatePickerModule} from 'ng2-datepicker-bootstrap';
  13.  
  14. @Component({
  15.     moduleId: module.id,
  16.     selector: 'profil',
  17.     templateUrl: 'profil.component.html',
  18.     providers: [ProfilService,ChatService]
  19. })
  20.  
  21. export class ProfilComponent implements OnInit, OnDestroy {
  22.     //initialisation de notre classe/modele User/ts
  23.     user : User;
  24.     email : string;
  25.     pseudo : string;
  26.     pseudoTest : string;
  27.     birthday:Date;
  28.     status:string;
  29.     Password: string;
  30.     oldPassword: string;
  31.     ConfirmPassword: string;
  32.     bio:string;
  33.     namePicture = '';
  34.     connection;
  35.     isNewUser : boolean;
  36.  
  37.     constructor(private profilService:ProfilService, private registerService:RegisterService, private route:ActivatedRoute){
  38.         this.ngOnInit();
  39.     }
  40.  
  41.     isNew(pseudo){
  42.         pseudo = this.user.pseudo;
  43.         console.log("this.isNewUser dans register component: " + this.isNewUser);
  44.         if(/*pseudo != null &&this.isNewUser != true*/ this.isNewUser == undefined /*|| this.isNewUser == false*/) {
  45.             this.registerService.isNew(pseudo).then(isNewUs => {
  46.                 //console.log("dans register component" + isNewUs);
  47.                 if (isNewUs) {
  48.                     this.isNewUser =isNewUs;
  49.                     return false;
  50.                 } else {
  51.                     this.isNewUser =isNewUs;
  52.                     return true;
  53.                 }
  54.             });
  55.         }else {
  56.             if(this.isNewUser){
  57.                 return false;
  58.             }else if(this.isNewUser == false){
  59.                 return true;
  60.             }
  61.         }
  62.     }
  63.  
  64.     changeStatus(status){
  65.  
  66.         this.status = status;
  67.         status = this.user.status;
  68.  
  69.     }
  70.  
  71.     modifyUser(email,pseudo,Password,bio,picture,birthday){
  72.  
  73.         if(email != ''){
  74.             email = this.user.email;
  75.         }
  76.         if(pseudo != ''){
  77.             pseudo = this.user.pseudo;
  78.         }
  79.         /*
  80.         if(password != ''){
  81.             password = this.user.password;
  82.         }*/
  83.         if(this.status != ''){
  84.             this.user.status = this.status;
  85.         }
  86.         if(bio != ''){
  87.             bio = this.user.bio;
  88.         }
  89.         if(birthday != null){
  90.             birthday = this.user.birthday;
  91.         }
  92.  
  93.         picture = this.user.picture;
  94.  
  95.         this.user.password = this.Password;
  96.  
  97.  
  98.         console.log(email);
  99.         console.log(pseudo);
  100.  
  101.         //this.profilService.modifyUser(this.user);
  102.  
  103.         this.profilService.modifyUser(this.user).then(userModified=>{
  104.             console.log("profil component : "+userModified.pseudo);
  105.             this.user = userModified;
  106.         });
  107.  
  108.     }
  109.  
  110.     ngOnInit() {
  111.  
  112.         this.user = {
  113.             _id: '',
  114.             pseudo: '',
  115.             email: '',
  116.             password: '',
  117.             picture:'',
  118.             bio:'',
  119.             birthday: new Date(''),
  120.             status:'',
  121.             exist:true
  122.         }
  123.  
  124.         this.route.params.subscribe(params => {
  125.             this.pseudoTest = params['userPseudo'];
  126.  
  127.             this.profilService.getContactUser(this.pseudoTest).then(contactFind=>{
  128.                 console.log("contact-list component : "+contactFind.pseudo);
  129.                 this.user = contactFind;
  130.                 this.user.picture = contactFind.picture;
  131.             });
  132.         });
  133.     }
  134.  
  135.     ngOnDestroy() {
  136.         if(this.connection){
  137.             this.connection.unsubscribe();
  138.         }
  139.     }
  140. }
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