-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperfil.page.ts
155 lines (147 loc) · 4.71 KB
/
perfil.page.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { Component, OnInit } from '@angular/core'; //se importan todas las librerias necesarias para el codigo
import { Router } from '@angular/router';
import { AuthService } from '../services/auth.service';
import { datos_usuario } from '../shared/user_interface';
@Component({
selector: 'app-perfil',
templateUrl: './perfil.page.html',
styleUrls: ['./perfil.page.scss'],
})
export class PerfilPage implements OnInit { // inicia el codigo para el funcionamiento de la pagina
gen: string ="masculino";
public cerrar_nombre:string="Cerrar sesion"; // se definen algunas variables
public modifi_nombre:string="Modificar datos";
public isDisabled: boolean=true;
public isDis :boolean=false;
public place_check:boolean=false;
public n_place_check:boolean=false;
public place_nombre:string;
public place_apellido:string;
public place_anio:string;
public place_dia:string;
public place_mes:string;
public place_mes_Str:string;
public chequeador:string="checked";
constructor(private authSvc:AuthService, private router:Router) { }
ngOnInit() {
}
ionViewWillEnter(){
this.inicializar(); // se llama la funcion inicializar
}
inicializar(){
if(this.authSvc.datos$ != undefined){
this.reestablacer_datos(); // se llama la funcion reestablcer datos
}
this.isDisabled=true; // si no se cumple la condicion esto ocurrira
this.isDis=false;
this.cerrar_nombre="Cerrar sesion";
this.modifi_nombre="Modificar datos";
}
reestablacer_datos(){ // esta funcion es usada para cambiar los datos si el usario ya esta dentro de su perfil
this.place_nombre= this.authSvc.datos$.nombre;
this.place_apellido=this.authSvc.datos$.apellido;
this.place_anio= this.authSvc.datos$.anio;
this.place_mes= this.authSvc.datos$.mes;
this.place_dia= this.authSvc.datos$.dia;
if(this.authSvc.datos$.genero=="masculino"){//se definen nuevamente las opciones
this.gen="masculino";
this.place_check=true;
this.n_place_check=false;
}else{
this.gen="femenino";
this.place_check=false;
this.n_place_check=true;
}
switch(this.place_mes) {
case "01": {
this.place_mes_Str="Enero" //se definen nuevamente las opciones
break;
}
case "02": {
this.place_mes_Str="Febrero"
break;
}
case "03": {
this.place_mes_Str="Marzo"
break;
}
case "04": {
this.place_mes_Str="Abril"
break;
}
case "05": {
this.place_mes_Str="Mayo"
break;
}
case "06": {
this.place_mes_Str="Junio"
break;
}
case "07": {
this.place_mes_Str="Julio"
break;
}
case "08": {
this.place_mes_Str="Agosto"
break;
}
case "09": {
this.place_mes_Str="Septiembre"
break;
}
case "10": {
this.place_mes_Str="Octubre"
break;
}
case "11": {
this.place_mes_Str="Noviembre"
break;
}
case "12": {
this.place_mes_Str="Diciembre"
break;
}
default: {
this.place_mes_Str="Oliwis"
break;
}
}
}
Modificar_datos(){ //esta funcion ocurre si se presiona el boton (Buscar en los comentarios del HTML), se actualizan los nuevos datos escogidos
if(this.isDisabled==true){
this.modifi_nombre= "Cancelar";
this.cerrar_nombre= "Guardar";
}else{
this.modifi_nombre= "Modificar datos";
this.cerrar_nombre= "Cerrar sesion";
}
this.isDisabled = !this.isDisabled;
this.isDis= !this.isDis;
}
male_boton(){ // se definen funciones
this.gen = "masculino";
};
female_boton(){ // se definen funciones
this.gen = "femenino";
}
Cerrar_sesion(nombre, apellido, anio,mes,dia){ // esta funcion cierra la sesion del ususariom haciendo uso se las funciones presentes en el autservice
var name = nombre.value;
var Sname = apellido.value;
if(this.cerrar_nombre== "Guardar"){
if(name == ""){
name = this.authSvc.datos$.nombre;
}
if(Sname == ""){
Sname = this.authSvc.datos$.apellido;
}
console.log("Los datos subidos seran ",name,Sname,anio.value,mes.value,dia.value, this.gen) // se guardan los datos nuevos y se envian a la base da datos en firebase
this.authSvc.modificar_datos(this.authSvc.usuario$,name,Sname,anio.value,mes.value,dia.value, this.gen)
this.authSvc.actualizar_datos();
console.log(this.authSvc.datos$)
this.inicializar();
}else{
this.authSvc.logout(); // usa la funcion logout para salir y volver a la aplicacion por defecto
this.router.navigate(['/cuenta']);
}
}
}