|
|
@@ -13,6 +13,8 @@ import { USERInterface } from '../../../interfaces/user-interface';
|
|
|
import { ENCService } from 'src/app/services/enc/enc.service';
|
|
|
import { MCOMAUService } from 'src/app/services/mco/mcomau/mcomau.service';
|
|
|
import { ValidationsService } from 'src/app/services/validations.service';
|
|
|
+import { map, Observable, startWith } from 'rxjs';
|
|
|
+import { FormControl } from '@angular/forms';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-mesmhs',
|
|
|
@@ -32,10 +34,17 @@ export class MESMHSComponent implements AfterViewInit {
|
|
|
displayedColumns: string[] = [];
|
|
|
dataSource = new MatTableDataSource<any>(this.solicitudes);
|
|
|
subordinados: any;
|
|
|
+ subordinadosAux: any = [];
|
|
|
isAdmin = false;
|
|
|
today = new Date();
|
|
|
@ViewChild(MatPaginator) paginator!: MatPaginator;
|
|
|
|
|
|
+ controlUsuarioAdmin = new FormControl();
|
|
|
+ controlUsuarioEstandar = new FormControl();
|
|
|
+
|
|
|
+ filteredOptions!: Observable<any>;
|
|
|
+ filteredOptionsAux!: Observable<any>;
|
|
|
+
|
|
|
constructor(
|
|
|
public dialog: MatDialog,
|
|
|
private _mesmhsService: MESMHSService,
|
|
|
@@ -47,10 +56,11 @@ export class MESMHSComponent implements AfterViewInit {
|
|
|
) {
|
|
|
this.usuario_session = JSON.parse(localStorage.getItem('TIMUSERENC')!);
|
|
|
|
|
|
- this.isAdmin = this._encService.desencriptar(
|
|
|
+ this.isAdmin =
|
|
|
+ this._encService.desencriptar(
|
|
|
JSON.parse(localStorage.getItem('TIMUSERENC')!).PERFIL
|
|
|
- ) == "1";
|
|
|
-
|
|
|
+ ) == '1';
|
|
|
+
|
|
|
if (this.isAdmin) {
|
|
|
this.displayedColumns = [
|
|
|
'no',
|
|
|
@@ -86,8 +96,29 @@ export class MESMHSComponent implements AfterViewInit {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- OnInit() {
|
|
|
- this.dataSource.data = [];
|
|
|
+ private _filter(value: any): Observable<string> {
|
|
|
+ const filterValue =
|
|
|
+ this.isAdmin == true
|
|
|
+ ? value.toLowerCase()
|
|
|
+ : value.toString().toLowerCase();
|
|
|
+
|
|
|
+ if (this.isAdmin) {
|
|
|
+ return this.subordinados
|
|
|
+ .map((option: any) => {
|
|
|
+ return option.USUARIO + ' (' + option.IDUSUARIO + ')';
|
|
|
+ })
|
|
|
+ .filter((option: any) =>
|
|
|
+ option.toString().toLowerCase().includes(filterValue)
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ return this.subordinados
|
|
|
+ .map((option: any) => {
|
|
|
+ return option.USUARIO;
|
|
|
+ })
|
|
|
+ .filter((option: any) =>
|
|
|
+ option.toString().toLowerCase().includes(filterValue)
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
applyFilter(filterValue: any) {
|
|
|
@@ -134,6 +165,15 @@ export class MESMHSComponent implements AfterViewInit {
|
|
|
}
|
|
|
|
|
|
obtenerHistorialSubordinado(numero_empleado: string) {
|
|
|
+ let position = this.subordinadosAux.findIndex((object: any) => {
|
|
|
+ return object == numero_empleado;
|
|
|
+ });
|
|
|
+
|
|
|
+ numero_empleado =
|
|
|
+ this.isAdmin == true
|
|
|
+ ? this.subordinados[position].IDUSUARIO
|
|
|
+ : this.obtenerIDUsuario(this.subordinados[position].USUARIO);
|
|
|
+
|
|
|
this._mesmhsService.obtenerHistorial(numero_empleado).subscribe(
|
|
|
(res) => {
|
|
|
if (res.status == 'Token is Expired') {
|
|
|
@@ -194,10 +234,12 @@ export class MESMHSComponent implements AfterViewInit {
|
|
|
);
|
|
|
this.dataSource.data = mi_historial;
|
|
|
this.cargarTabla(mi_historial);
|
|
|
+ this.data_empty = mi_historial.length > 0 ? false : true;
|
|
|
} else {
|
|
|
this._validationService.openSnackBar(
|
|
|
res.response.length > 0 ? res.msg : 'No hay datos para mostrar'
|
|
|
);
|
|
|
+
|
|
|
this.data_empty = true;
|
|
|
this.dataSource.data = [];
|
|
|
}
|
|
|
@@ -271,6 +313,7 @@ export class MESMHSComponent implements AfterViewInit {
|
|
|
hash[current.IDUSUARIO] = true;
|
|
|
return exists;
|
|
|
});
|
|
|
+
|
|
|
let arr_user: any[] = [];
|
|
|
usuarios.forEach((element) => {
|
|
|
if (
|
|
|
@@ -282,9 +325,21 @@ export class MESMHSComponent implements AfterViewInit {
|
|
|
});
|
|
|
|
|
|
this.subordinados = arr_user;
|
|
|
+
|
|
|
+ this.subordinadosAux = arr_user.map((option: any) => {
|
|
|
+ return option.USUARIO + ' (' + option.IDUSUARIO + ')';
|
|
|
+ });
|
|
|
+
|
|
|
+ this.filteredOptions = this.controlUsuarioAdmin.valueChanges.pipe(
|
|
|
+ startWith(''),
|
|
|
+ map((value: any) => this._filter(value))
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
- private cargarSubordiandos() {
|
|
|
+ private async cargarSubordiandos() {
|
|
|
+ const sleep = (ms: number) =>
|
|
|
+ new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
+ await sleep(1000);
|
|
|
this._mesmhsService
|
|
|
.obtenerSubordinados(
|
|
|
this._encService.desencriptar(this.usuario_session.IDUSUARIO)
|
|
|
@@ -298,6 +353,16 @@ export class MESMHSComponent implements AfterViewInit {
|
|
|
);
|
|
|
} else if (!res.status) {
|
|
|
this.subordinados = res;
|
|
|
+ this.subordinadosAux = res.map((option: any) => {
|
|
|
+ return option.USUARIO;
|
|
|
+ });
|
|
|
+
|
|
|
+ this.filteredOptionsAux =
|
|
|
+ this.controlUsuarioEstandar.valueChanges.pipe(
|
|
|
+ startWith(''),
|
|
|
+ map((value: any) => this._filter(value))
|
|
|
+ );
|
|
|
+
|
|
|
this.data_empty = false;
|
|
|
} else {
|
|
|
this._validationService.openSnackBar(
|