| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578 |
- import { Component, ViewChild, AfterViewInit } from '@angular/core';
- import { MatPaginator } from '@angular/material/paginator';
- import { MatTableDataSource } from '@angular/material/table';
- import { Router } from '@angular/router';
- import { MatDialog } from '@angular/material/dialog';
- import { MatSnackBar } from '@angular/material/snack-bar';
- import { MCOMAUService } from 'src/app/services/mco/mcomau/mcomau.service';
- import { AlertaComponent } from '../../resources/dialogos/alerta/alerta.component';
- import { CambiarContrasenaComponent } from '../../resources/dialogos/cambiar-contrasena/cambiar-contrasena.component';
- import { MCOMAUINFOComponent } from './mcomau-info/mcomau-info.component';
- import { ResponseData } from 'src/app/interfaces/response-data';
- import { MCOMAUInterface } from 'src/app/interfaces/mco/mcomau/mcomau-interface';
- import { IAMService } from 'src/app/services/iam/iam.service';
- import { MCOMUNService } from 'src/app/services/mco/mcomun/mcomun.service';
- import { MCOMPVService } from 'src/app/services/mco/mcompv/mcompv.service';
- import { USERInterface } from 'src/app/interfaces/user-interface';
- import { ENCService } from 'src/app/services/enc/enc.service';
- import { LoginGuard } from 'src/app/auth/login.guard';
- import { MCOMAPService } from 'src/app/services/mco/mcomap/mcomap.service';
- import { ValidationsService } from 'src/app/services/validations.service';
- import { lastValueFrom } from 'rxjs';
- @Component({
- selector: 'app-mcomau',
- templateUrl: './mcomau.component.html',
- styleUrls: ['./mcomau.component.css'],
- })
- export class MCOMAUComponent implements AfterViewInit {
- usuarios: any = [];
- loading: Boolean = true;
- data_empty = false;
- filtro_usuarios: number = 0;
- filtro: any = [
- {
- tipo: 1,
- filtro: 'Todos',
- },
- {
- tipo: 2,
- filtro: 'Activos',
- },
- {
- tipo: 3,
- filtro: 'Inactivos',
- },
- {
- tipo: 4,
- filtro: 'Eliminados',
- },
- ];
- usuario_session: USERInterface = JSON.parse(
- localStorage.getItem('TIMUSERENC')!
- );
- usuarios_todos: any;
- displayedColumns: string[] = [
- 'no_empleado',
- 'nombre',
- 'correo',
- 'rfc',
- 'unidadNegocio',
- 'status',
- 'accion',
- ];
- dataSource: MatTableDataSource<MCOMAUInterface> =
- new MatTableDataSource<MCOMAUInterface>(this.usuarios);
- unidades_negocio: any = [];
- usuarios_menos: any = [];
- politicas: any = [];
- perfiles: any = [];
- isFilter: boolean = false;
- boton_register_disabled: boolean = false;
- @ViewChild(MatPaginator) paginator!: MatPaginator;
- constructor(
- private router: Router,
- public dialog: MatDialog,
- private _mcomauService: MCOMAUService,
- private _encService: ENCService,
- private _iamService: IAMService,
- private _mcomunService: MCOMUNService,
- private _mcomapService: MCOMAPService,
- private _mcompvService: MCOMPVService,
- private _validationService: ValidationsService
- ) {}
- async ngAfterViewInit() {
- this.dataSource.paginator = this.paginator;
- this.dataSource.filterPredicate = function (data, filter: string): boolean {
- let nombre_completo = `${data.NOMBRE} ${data.APELLIDO_PATERNO} ${data.APELLIDO_MATERNO}`;
- return (
- nombre_completo.toString().toLowerCase().includes(filter) ||
- data.IDUSUARIO.toLowerCase().includes(filter) ||
- data.EMAIL.toLowerCase().includes(filter) ||
- data.RFCUSUARIO.toLowerCase().includes(filter)
- );
- };
- await this.obtener();
- }
- async obtener() {
- let usuario = this._mcomauService.obtener().toPromise();
- await usuario.then(
- (res: any) => {
- if (res.status == 'Token is Expired') {
- this._iamService.logout();
- this._validationService.openSnackBar('Sesión expirada. Vuelva a iniciar sesión');
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (res.status == 'IP change') {
- localStorage.removeItem('jwt');
- localStorage.removeItem('jwt');
- this._validationService.openSnackBar('La IP fue cambiada');
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (!res.status && res.response.length > 0) {
- this.dataSource.data = res.response;
- this.usuarios_todos = res.response;
- } else {
- this._validationService.openSnackBar(
- res.response.length > 0 ? res.msg : 'No hay datos para mostrar'
- );
- this.data_empty = true;
- }
- this.loading = false;
- },
- (error: any) => {
- if (!error.ok) {
- this._validationService.openSnackBar('Ocurrió un error inesperado');
- }
- if (error.error.msg != undefined) {
- this._validationService.openSnackBar(error.error.msg);
- }
- if (error.status == 408) {
- this._validationService.openSnackBar('Conexion lenta');
- }
- }
- );
- }
- eliminar(item: MCOMAUInterface) {
- let datos = {
- numero_empleado: item.IDUSUARIO,
- numero_empleado_modifica: this._encService.desencriptar(
- this.usuario_session.IDUSUARIO
- ),
- };
- this._mcomauService.eliminar(datos).subscribe(
- (res) => {
- if (res.status == 'Token is Expired') {
- this._iamService.logout();
- this._validationService.openSnackBar(
- 'Sesión expirada. Vuelva a iniciar sesión'
- );
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (res.status == 'IP change') {
- localStorage.removeItem('jwt');
- localStorage.removeItem('jwt');
- this._validationService.openSnackBar('La IP fue cambiada');
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (!res.error) {
- this.obtener();
- this._validationService.openSnackBar('¡Eliminación Exitosa!');
- } else {
- this._validationService.openSnackBar(res.msg);
- }
- },
- (error) => {
- if (!error.ok) {
- this._validationService.openSnackBar('Ocurrió un error inesperado');
- }
- if (error.error.msg != undefined) {
- this._validationService.openSnackBar(error.error.msg);
- }
- if (error.status == 408) {
- this._validationService.openSnackBar('Conexion lenta');
- }
- }
- );
- }
- cambiarContrasena(contrasena: String, item: any) {
- let datos = {
- numero_empleado: item.IDUSUARIO,
- numero_empleado_modifica: this._encService.desencriptar(this.usuario_session.IDUSUARIO),
- password: contrasena,
- password_confirmation: contrasena,
- };
- this._mcomauService.cambiarContrasena(datos).subscribe(
- (res) => {
- if (res.status == 'Token is Expired') {
- this._iamService.logout();
- this._validationService.openSnackBar('Sesión expirada. Vuelva a iniciar sesión');
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (res.status == 'IP change') {
- localStorage.removeItem('jwt');
- localStorage.removeItem('jwt');
- this._validationService.openSnackBar('La IP fue cambiada');
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (!res.error) {
- this._validationService.openSnackBar('¡Contraseña Cambiada!');
- } else {
- this._validationService.openSnackBar(res.msg);
- }
- },
- (error) => {
- if (!error.ok) {
- this._validationService.openSnackBar('Ocurrió un error inesperado');
- }
- if (error.error.msg != undefined) {
- this._validationService.openSnackBar(error.error.msg);
- }
- if (error.status == 408) {
- this._validationService.openSnackBar('Conexion lenta');
- }
- }
- );
- }
- bloquear(item: any) {
- let datos = {
- numero_empleado: item.IDUSUARIO,
- numero_empleado_modifica: this._encService.desencriptar(
- this.usuario_session.IDUSUARIO
- ),
- };
- this._mcomauService.bloquear(datos).subscribe(
- (res) => {
- if (res.status == 'Token is Expired') {
- this._iamService.logout();
- this._validationService.openSnackBar(
- 'Sesión expirada. Vuelva a iniciar sesión'
- );
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (res.status == 'IP change') {
- localStorage.removeItem('jwt');
- localStorage.removeItem('jwt');
- this._validationService.openSnackBar('La IP fue cambiada');
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (!res.error) {
- this.obtener();
- this._validationService.openSnackBar('¡Usuario Bloqueado!');
- } else {
- this._validationService.openSnackBar(res.msg);
- }
- },
- (error) => {
- if (!error.ok) {
- this._validationService.openSnackBar('Ocurrió un error inesperado');
- }
- if (error.error.msg != undefined) {
- this._validationService.openSnackBar(error.error.msg);
- }
- if (error.status == 408) {
- this._validationService.openSnackBar('Conexion lenta');
- }
- }
- );
- }
- desbloquear(item: any) {
- let datos = {
- user_id_empleado: item.IDUSUARIO,
- user_id_empleado_modifica: this._encService.desencriptar(
- this.usuario_session.IDUSUARIO
- ),
- };
- this._mcomauService.desbloquear(datos).subscribe(
- (res) => {
- if (res.status == 'Token is Expired') {
- this._iamService.logout();
- this._validationService.openSnackBar(
- 'Sesión expirada. Vuelva a iniciar sesión'
- );
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (res.status == 'IP change') {
- localStorage.removeItem('jwt');
- localStorage.removeItem('jwt');
- this._validationService.openSnackBar('La IP fue cambiada');
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (!res.error) {
- this.obtener();
- this._validationService.openSnackBar('¡Usuario Desbloqueado!');
- } else {
- this._validationService.openSnackBar(res.msg);
- }
- },
- (error) => {
- if (!error.ok) {
- this._validationService.openSnackBar('Ocurrió un error inesperado');
- }
- if (error.error.msg != undefined) {
- this._validationService.openSnackBar(error.error.msg);
- }
- if (error.status == 408) {
- this._validationService.openSnackBar('Conexion lenta');
- }
- }
- );
- }
- applyFilter(filterValue: any) {
- this.dataSource.filter = filterValue.target.value.trim().toLowerCase();
- }
- filterUser() {
- let usuarios_aux: MCOMAUInterface[] = [];
- switch (this.filtro_usuarios) {
- case 1:
- usuarios_aux = this.usuarios_todos;
- break;
- case 2:
- this.usuarios_todos.forEach((element: MCOMAUInterface) => {
- if (element.ESTATUS === 'Activo') {
- usuarios_aux.push(element);
- }
- });
- break;
- case 3:
- this.usuarios_todos.forEach((element: MCOMAUInterface) => {
- if (element.ESTATUS === 'Inactivo') {
- usuarios_aux.push(element);
- }
- });
- break;
- case 4:
- this.usuarios_todos.forEach((element: MCOMAUInterface) => {
- if (element.ESTATUS === 'Eliminado') {
- usuarios_aux.push(element);
- }
- });
- break;
- default:
- this._validationService.openSnackBar('Ocurrió un error inesperado');
- break;
- }
- usuarios_aux.length > 0
- ? (this.data_empty = false)
- : (this.data_empty = true);
- this.dataSource.data = usuarios_aux;
- this.isFilter = true;
- }
- openDialog(item: MCOMAUInterface, action: String) {
- let dataAction = {};
- switch (action) {
- case 'Eliminar':
- dataAction = {
- titulo: 'Eliminar usuario',
- descripcion: `¿Esta seguro de eliminar a ${item.NOMBRE}?`,
- };
- break;
- case 'Bloquear':
- dataAction = {
- titulo: 'Bloquear acceso',
- descripcion: `¿Esta seguro bloquear el acceso a ${item.NOMBRE}?`,
- };
- break;
- case 'Desbloquear':
- dataAction = {
- titulo: 'Desbloquear acceso',
- descripcion: `¿Esta seguro desbloquear el acceso a ${item.NOMBRE}?`,
- };
- break;
- default:
- this._validationService.openSnackBar('Ocurrió un error inesperado');
- break;
- }
- const dialogRef = this.dialog.open(AlertaComponent, {
- data: dataAction,
- });
- dialogRef.afterClosed().subscribe((result) => {
- if (result) {
- switch (action) {
- case 'Eliminar':
- this.eliminar(item);
- break;
- case 'Bloquear':
- this.bloquear(item);
- break;
- case 'Desbloquear':
- this.desbloquear(item);
- break;
- default:
- this._validationService.openSnackBar('Ocurrió un error inesperado');
- break;
- }
- }
- });
- }
- openDialogPassword(item: any) {
- const dialogRef = this.dialog.open(CambiarContrasenaComponent, {
- data: item,
- disableClose: true
- });
- dialogRef.afterClosed().subscribe((result) => {
- if (result != '') {
- this.cambiarContrasena(result, item);
- }
- });
- }
- openDialogInfo(item: MCOMAUInterface) {
- this.dialog.open(MCOMAUINFOComponent, {
- data: item,
- });
- }
- async actionForm(action: String, item: any = null) {
- this.boton_register_disabled = true;
- this.loading = true;
- let data = item != null ? JSON.stringify(item) : null;
- await lastValueFrom(this._mcomunService.obtener()).then(
- (res: any) => {
- if (res.status == 'Token is Expired') {
- this._iamService.logout();
- this._validationService.openSnackBar(
- 'Sesión expirada. Vuelva a iniciar sesión'
- );
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (res.status == 'IP change') {
- localStorage.removeItem('jwt');
- localStorage.removeItem('jwt');
- this._validationService.openSnackBar('La IP fue cambiada');
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (!res.error) {
- this.unidades_negocio = res.response;
- } else {
- this._validationService.openSnackBar(res.msg);
- }
- },
- (error) => {
- if (!error.ok) {
- this._validationService.openSnackBar('Ocurrió un error inesperado');
- }
- if (error.error.msg != undefined) {
- this._validationService.openSnackBar(error.error.msg);
- }
- if (error.status == 408) {
- this._validationService.openSnackBar('Conexion lenta');
- }
- }
- );
- await lastValueFrom(this._mcompvService.obtener()).then(
- (res: any) => {
- if (res.status == 'Token is Expired') {
- this._iamService.logout();
- this._validationService.openSnackBar(
- 'Sesión expirada. Vuelva a iniciar sesión'
- );
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (res.status == 'IP change') {
- localStorage.removeItem('jwt');
- localStorage.removeItem('jwt');
- this._validationService.openSnackBar('La IP fue cambiada');
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (!res.error) {
- this.politicas = res.response;
- } else {
- this._validationService.openSnackBar(res.msg);
- }
- },
- (error) => {
- if (!error.ok) {
- this._validationService.openSnackBar('Ocurrió un error inesperado');
- }
- if (error.error.msg != undefined) {
- this._validationService.openSnackBar(error.error.msg);
- }
- if (error.status == 408) {
- this._validationService.openSnackBar('Conexion lenta');
- }
- }
- );
- await lastValueFrom(this._mcomauService.obtenerTodos()).then(
- (res: any) => {
- if (res.status == 'Token is Expired') {
- this._iamService.logout();
- this._validationService.openSnackBar(
- 'Sesión expirada. Vuelva a iniciar sesión'
- );
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (res.status == 'IP change') {
- localStorage.removeItem('jwt');
- localStorage.removeItem('jwt');
- this._validationService.openSnackBar('La IP fue cambiada');
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (!res.error) {
- this.usuarios_menos = res.response;
- } else {
- this._validationService.openSnackBar(res.msg);
- }
- },
- (error) => {
- if (!error.ok) {
- this._validationService.openSnackBar('Ocurrió un error inesperado');
- }
- if (error.error.msg != undefined) {
- this._validationService.openSnackBar(error.error.msg);
- }
- if (error.status == 408) {
- this._validationService.openSnackBar('Conexion lenta');
- }
- }
- );
- await lastValueFrom(this._mcomapService.obtener()).then(
- (res: any) => {
- if (res.status == 'Token is Expired') {
- this._iamService.logout();
- this._validationService.openSnackBar(
- 'Sesión expirada. Vuelva a iniciar sesión'
- );
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (res.status == 'IP change') {
- localStorage.removeItem('jwt');
- localStorage.removeItem('jwt');
- this._validationService.openSnackBar('La IP fue cambiada');
- window.location.href = 'https://qasirh.ittec.mx/';
- } else if (!res.status) {
- this.perfiles = res.response;
- } else {
- this._validationService.openSnackBar(
- res.response.length > 0 ? res.msg : 'No hay datos para mostrar'
- );
- this.data_empty = true;
- }
- },
- (error: any) => {
- if (!error.ok) {
- this._validationService.openSnackBar('Ocurrió un error inesperado');
- }
- if (error.error.msg != undefined) {
- this._validationService.openSnackBar(error.error.msg);
- }
- if (error.status == 408) {
- this._validationService.openSnackBar('Conexion lenta');
- }
- }
- );
- let unidades = JSON.stringify(this.unidades_negocio);
- let politicas = JSON.stringify(this.politicas);
- let usuarios_menos = JSON.stringify(this.usuarios_menos);
- let perfiles = JSON.stringify(this.perfiles);
- this.router.navigate([
- '/admin/mcomau-form',
- {
- action: action,
- data: data,
- unidades: unidades,
- politicas: politicas,
- usuarios_menos: usuarios_menos,
- perfiles: perfiles,
- },
- ]);
- this.boton_register_disabled = false;
- this.loading = false;
- }
- }
|