Guest User

Untitled

a guest
Jun 6th, 2017
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  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 chatService:ChatService,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. }
  87. if(bio != ''){
  88. bio = this.user.bio;
  89. }
  90. if(birthday != null){
  91. birthday = this.user.birthday;
  92. }
  93.  
  94. picture = this.user.picture;
  95.  
  96. this.user.password = this.Password;
  97. let monStatus={
  98. status: this.user.status,
  99. pseudo: this.user.pseudo
  100. }
  101. this.chatService.emit('newStatus', monStatus);
  102.  
  103. console.log(email);
  104. console.log(pseudo);
  105.  
  106. //this.profilService.modifyUser(this.user);
  107.  
  108. this.profilService.modifyUser(this.user).then(userModified=>{
  109. console.log("profil component : "+userModified.pseudo);
  110. this.user = userModified;
  111. });
  112.  
  113. }
  114.  
  115. ngOnInit() {
  116.  
  117. this.user = {
  118. _id: '',
  119. pseudo: '',
  120. email: '',
  121. password: '',
  122. picture:'',
  123. bio:'',
  124. birthday: new Date(''),
  125. status:'',
  126. exist:true
  127. }
  128.  
  129. this.route.params.subscribe(params => {
  130. this.pseudoTest = params['userPseudo'];
  131.  
  132. this.profilService.getContactUser(this.pseudoTest).then(contactFind=>{
  133. console.log("contact-list component : "+contactFind.pseudo);
  134. this.user = contactFind;
  135. this.user.picture = contactFind.picture;
  136. });
  137. });
  138. }
  139.  
  140. ngOnDestroy() {
  141. if(this.connection){
  142. this.connection.unsubscribe();
  143. }
  144. }
  145. }
Add Comment
Please, Sign In to add comment