Skip to content

Commit

Permalink
list of users and loading modal
Browse files Browse the repository at this point in the history
  • Loading branch information
EngelberAmaya committed Aug 16, 2020
1 parent cbb3407 commit c8c4ad3
Show file tree
Hide file tree
Showing 16 changed files with 439 additions and 21 deletions.
33 changes: 33 additions & 0 deletions src/app/components/modal-upload/modal-upload.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="fondo-negro animated fadeIn fast" [ngClass]="_modalUploadService.oculto">
<div class="modal" style="display: block;" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Modal</h5>
<button type="button" class="close" aria-label="Close" (click)="cerrarModal()">
<span aria-hidden>&times;</span>
</button>

</div>

<div class="modal-body text-center">
<div>
<img *ngIf="!imagenTemp" [src]="'xxx' | imagen" class="w150">
<img *ngIf="imagenTemp" [src]="imagenTemp" class="w150">
</div>
<br>

<input type="file"
(change)="seleccionImagen($event.target.files[0])">
</div>

<div class="modal-footer">
<button (click)="subirImagen()" [disabled]="!imagenTemp" type="button" class="btn btn-primary">Subir Imagen</button>
<button (click)="cerrarModal()" type="button" class="btn btn-secondary">Cerrar</button>
</div>

</div>
</div>
</div>
</div>

66 changes: 66 additions & 0 deletions src/app/components/modal-upload/modal-upload.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Component, OnInit } from '@angular/core';
import { Usuario } from '../../models/usuario.model';
import swal from 'sweetalert';
import { SubirArchivoService } from '../../services/subir-archivo/subir-archivo.service';
import { ModalUploadService } from './modal-upload.service';

@Component({
selector: 'app-modal-upload',
templateUrl: './modal-upload.component.html',
styles: [
]
})
export class ModalUploadComponent implements OnInit {


imagenTemp: any;
public usuario: Usuario;
imagenSubir: File;

constructor(public _subirArchivoService: SubirArchivoService,
public _modalUploadService: ModalUploadService) { }

ngOnInit(): void {
}

cerrarModal(){
this.imagenTemp = null;
this.imagenSubir = null;
this._modalUploadService.ocultarModal();
}

subirImagen(){
this._subirArchivoService.subirArchivo(this.imagenSubir, this._modalUploadService.tipo, this._modalUploadService.id)
.then( resp => {
//console.log(resp);
this._modalUploadService.notificacion.emit(resp);
this.cerrarModal();
swal('Excelente','Imagen subida exitosamente', 'success');
})
.catch( err => {
console.log('Error en la carga...');
});
}

seleccionImagen(archivo: File){

if (!archivo) {
this.imagenSubir = null;
return;
}

if (archivo.type.indexOf('image') < 0) {
swal('Sólo imágenes', 'El archivo seleccionado no es una imagen', 'error');
this.imagenSubir = null;
return;
}

this.imagenSubir = archivo;

let reader = new FileReader();
let urlImagenTemp = reader.readAsDataURL(archivo);
reader.onloadend = () => this.imagenTemp = reader.result;

}

}
27 changes: 27 additions & 0 deletions src/app/components/modal-upload/modal-upload.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Injectable, EventEmitter } from '@angular/core';

@Injectable({
providedIn: 'root'
})
export class ModalUploadService {

public tipo: string;
public id: string;
public oculto: string = 'oculto';
public notificacion = new EventEmitter<any>();

constructor() { }

ocultarModal(){
this.oculto = 'oculto';
this.id = null;
this.tipo = null;
}

mostrarModal(tipo: string, id:string){
this.oculto = '';
this.id = id;
this.tipo = tipo;
}

}
3 changes: 2 additions & 1 deletion src/app/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export class LoginComponent implements OnInit {
.subscribe( resp => {
console.log(resp);
this.router.navigate(['/dashboard']);
//swal('Bienvenido al sistema', '', 'success');
//window.location.href = '#/dashboard'
swal('Bienvenido al sistema', usuario.email, 'success');
},
(err) => {
// Si sucede un error
Expand Down
3 changes: 3 additions & 0 deletions src/app/pages/pages.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

</div>

<!-- Modal Uplod-->
<app-modal-upload></app-modal-upload>




Expand Down
6 changes: 5 additions & 1 deletion src/app/pages/pages.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { RxjsComponent } from './rxjs/rxjs.component';
//Pipe Module
import { PipesModule } from '../pipes/pipes.module';
import { ProfileComponent } from './profile/profile.component';
import { UsuariosComponent } from './usuarios/usuarios.component';
import { ModalUploadComponent } from '../components/modal-upload/modal-upload.component';

@NgModule({
declarations: [
Expand All @@ -34,7 +36,9 @@ import { ProfileComponent } from './profile/profile.component';
AccoutSettingsComponent,
PromesasComponent,
RxjsComponent,
ProfileComponent
ProfileComponent,
UsuariosComponent,
ModalUploadComponent
],
exports: [
DashboardComponent,
Expand Down
5 changes: 4 additions & 1 deletion src/app/pages/pages.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PromesasComponent } from './promesas/promesas.component';
import { RxjsComponent } from './rxjs/rxjs.component';
import { LoginGuardGuard } from '../services/service.index';
import { ProfileComponent } from './profile/profile.component';
import { UsuariosComponent } from './usuarios/usuarios.component';


const pagesRoutes: Routes = [
Expand All @@ -20,7 +21,9 @@ const pagesRoutes: Routes = [
{ path: 'grafica1', component: Grafica1Component, data: { titulo:'Gráficas' } },
{ path: 'promesas', component: PromesasComponent, data: { titulo:'Promesas' } },
{ path: 'rxjs', component: RxjsComponent, data: { titulo:'Rxjs' } },
{ path: 'perfil', component: ProfileComponent, data: { titulo:'Perfil de usuario' } },
{ path: 'perfil', component: ProfileComponent, data: { titulo:'Perfil de usuario' } },
// Manteniemientos
{ path: 'usuarios', component: UsuariosComponent, data: { titulo:'Manteniemiento de Usuarios' } },
{ path: 'account-settings', component: AccoutSettingsComponent, data: { titulo:'Ajustes de Tema' } },
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' }
]
Expand Down
3 changes: 1 addition & 2 deletions src/app/pages/profile/profile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ProfileComponent implements OnInit {
//public perfilForm: FormGroup;
public usuario: Usuario;
imagenSubir: File;
imagenTemp: string;
imagenTemp: any;

constructor(private _usuarioService: UsuarioService) {
this.usuario = _usuarioService.usuario;
Expand Down Expand Up @@ -59,5 +59,4 @@ export class ProfileComponent implements OnInit {
this._usuarioService.cambiarImagen(this.imagenSubir, this.usuario._id);
}


}
94 changes: 94 additions & 0 deletions src/app/pages/usuarios/usuarios.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<div class="row animated fadeIn fast">
<div class="col-12">
<div class="card">
<div class="card-body">

<input type="text"
class="form-control"
placeholder="Buscar usuario..."
(keyup)="buscarUsuario(txtTermino.value)"
#txtTermino/>

</div>
</div>
</div>
</div>

<div class="row animated fadeIn fast" *ngIf="cargando">
<div class="col-sm-12">

<div class="alert alert-warning text-center">
<strong>Cargando</strong>
<br>
<i class="fa fa-spin fa-refresh fa-2x"></i>
<br>
<p class="">Por favor espere</p>
</div>

</div>
</div>


<div class="row animated fadeIn fast" *ngIf="!cargando">
<div class="col-12">
<div class="card">
<div class="card-body">
<h3 class="card-title">Usuarios registrados (<small>{{totalRegistros}}</small>)</h3>

<table class="table table-hover">
<thead>
<tr>
<th class="text-center">Imagen</th>
<th class="text-center">Correo</th>
<th class="text-center">Nombre</th>
<th class="text-center">Role</th>
<!--<th>Auth</th>-->
<th class="text-center">Opciones</th>
</tr>
</thead>

<tbody>
<tr *ngFor="let usuario of usuarios">
<th class="w70">
<img (click)="mostarModal(usuario._id)" [src]="usuario.img | imagen" class="img-50 img-circle pointer">
</th>
<th class="text-center">{{usuario.email}}</th>
<th class="text-center">{{usuario.nombre}}</th>
<!--<th class="text-center">{{usuario.role}}</th>-->
<th>
<select class="form-control" [(ngModel)]="usuario.role">
<option value="ADMIN_ROLE">ADMIN_ROLE</option>
<option value="USER_ROLE">USER_ROLE</option>
</select>
</th>
<!--<th>
<label class="label label-danger">Google</label>
<label class="label label-primary">Normal</label>
</th>-->
<th class="text-center">
<button class="btn btn-primary" (click)="modRoleUsuario(usuario)">
<i class="fa fa-save"></i>
</button>

<button (click)="borrarUsuario(usuario)" style="margin-left: 5px" class="btn btn-danger">
<i class="fa fa-trash-o"></i>
</button>

</th>
</tr>
</tbody>

</table>

<div class="btn btn-success" (click)="cambiarDesde(-5)">
Anteriores
</div>

<div class="btn btn-success" (click)="cambiarDesde(5)" style="margin-left: 5px">
Siguientes
</div>

</div>
</div>
</div>
</div>
Loading

0 comments on commit c8c4ad3

Please sign in to comment.