Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Thierry on 28/05/2017.
- */
- import { Component, OnInit,OnDestroy } from '@angular/core';
- import { RegisterService } from '../../services/register/register.service';
- import { ChatService } from '../../services/chat/chat.service';
- import { ProfilService } from '../../services/profil/profil.service';
- import { User } from '../../../User';
- import { ActivatedRoute } from '@angular/router';
- //import { DateModel } from 'ng2-datepicker-bootstrap';
- import 'rxjs/add/operator/toPromise';
- //import {DatePickerModule} from 'ng2-datepicker-bootstrap';
- @Component({
- moduleId: module.id,
- selector: 'profil',
- templateUrl: 'profil.component.html',
- providers: [ProfilService,ChatService]
- })
- export class ProfilComponent implements OnInit, OnDestroy {
- //initialisation de notre classe/modele User/ts
- user : User;
- email : string;
- pseudo : string;
- pseudoTest : string;
- birthday:Date;
- status:string;
- Password: string;
- oldPassword: string;
- ConfirmPassword: string;
- bio:string;
- namePicture = '';
- connection;
- isNewUser : boolean;
- constructor(private profilService:ProfilService, private registerService:RegisterService, private chatService:ChatService,private route:ActivatedRoute){
- this.ngOnInit();
- }
- isNew(pseudo){
- pseudo = this.user.pseudo;
- console.log("this.isNewUser dans register component: " + this.isNewUser);
- if(/*pseudo != null &&this.isNewUser != true*/ this.isNewUser == undefined /*|| this.isNewUser == false*/) {
- this.registerService.isNew(pseudo).then(isNewUs => {
- //console.log("dans register component" + isNewUs);
- if (isNewUs) {
- this.isNewUser =isNewUs;
- return false;
- } else {
- this.isNewUser =isNewUs;
- return true;
- }
- });
- }else {
- if(this.isNewUser){
- return false;
- }else if(this.isNewUser == false){
- return true;
- }
- }
- }
- changeStatus(status){
- this.status = status;
- status = this.user.status;
- }
- modifyUser(email,pseudo,Password,bio,picture,birthday){
- if(email != ''){
- email = this.user.email;
- }
- if(pseudo != ''){
- pseudo = this.user.pseudo;
- }
- /*
- if(password != ''){
- password = this.user.password;
- }*/
- if(this.status != ''){
- this.user.status = this.status;
- }
- if(bio != ''){
- bio = this.user.bio;
- }
- if(birthday != null){
- birthday = this.user.birthday;
- }
- picture = this.user.picture;
- this.user.password = this.Password;
- let monStatus={
- status: this.user.status,
- pseudo: this.user.pseudo
- }
- this.chatService.emit('newStatus', monStatus);
- console.log(email);
- console.log(pseudo);
- //this.profilService.modifyUser(this.user);
- this.profilService.modifyUser(this.user).then(userModified=>{
- console.log("profil component : "+userModified.pseudo);
- this.user = userModified;
- });
- }
- ngOnInit() {
- this.user = {
- _id: '',
- pseudo: '',
- email: '',
- password: '',
- picture:'',
- bio:'',
- birthday: new Date(''),
- status:'',
- exist:true
- }
- this.route.params.subscribe(params => {
- this.pseudoTest = params['userPseudo'];
- this.profilService.getContactUser(this.pseudoTest).then(contactFind=>{
- console.log("contact-list component : "+contactFind.pseudo);
- this.user = contactFind;
- this.user.picture = contactFind.picture;
- });
- });
- }
- ngOnDestroy() {
- if(this.connection){
- this.connection.unsubscribe();
- }
- }
- }
Add Comment
Please, Sign In to add comment