Advertisement
Guest User

Untitled

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