Skip to content

Commit

Permalink
Sección 15 lista
Browse files Browse the repository at this point in the history
  • Loading branch information
betolix committed Oct 20, 2019
1 parent 0482af2 commit f94f195
Show file tree
Hide file tree
Showing 16 changed files with 482 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ServiceModule } from './services/service.module';
import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
import { RegisterComponent } from './login/register.component';
import { ModalUploadComponent } from './components/modal-upload/modal-upload.component';
//import { ImagenPipe } from './pipes/imagen.pipe';


Expand Down
37 changes: 37 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,37 @@
<div class="fondo-negro animated fadeIn" [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 title</h5>
<button
(click)="cerrarModal()"
type="button"
class="close"
aria-label="Close"
>
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body text-center">


<img *ngIf="!imagenTemp" [src]=" 'xxx' | imagen" class="w150">
<img *ngIf="imagenTemp" [src]="imagenTemp" class="w150">

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



</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>

83 changes: 83 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,83 @@
import { Component, OnInit } from '@angular/core';
import { SubirArchivoService } from 'src/app/services/service.index';

import { ModalUploadService } from './modal-upload.service';

import Swal from 'sweetalert2'

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

imagenSubir: File;
imagenTemp: any;

constructor(
public _subirArchivoService: SubirArchivoService,
public _modalUploadService: ModalUploadService
) {
// console.log('Modal Listo');
}

ngOnInit() {
}



cerrarModal() {
this.imagenTemp = null;
this.imagenSubir = null;

this._modalUploadService.ocultarModal();
}


seleccionImage(archivo: File) {

if (!archivo) {
this.imagenSubir = null;
return;
}
// console.log( event );

if (archivo.type.indexOf('image') < 0) {
Swal.fire({
title: 'Sólo imágenes!',
text: 'El archivo seleccionado no es una imagen',
type: 'error',
confirmButtonText: 'Ok'
});
this.imagenSubir = null;
return;
}

this.imagenSubir = archivo;

let reader = new FileReader();
let urlImagenTemp = reader.readAsDataURL(archivo);

reader.onloadend = () => this.imagenTemp = reader.result;

}

subirImagen() {

this._subirArchivoService.subirArchivo( this.imagenSubir, this._modalUploadService.tipo, this._modalUploadService.id )
.then( resp => {

// console.log( resp );
this._modalUploadService.notificacion.emit( resp );
// this._modalUploadService.ocultarModal();
this.cerrarModal();
} )
.catch( err => {
console.log('Error en la carga...');
} );
}



}
33 changes: 33 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,33 @@
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() {
console.log('Modal upload listo!');
}


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

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


}
3 changes: 3 additions & 0 deletions src/app/pages/pages.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@
<!-- ============================================================== -->
<!-- END Page wrapper -->
<!-- ============================================================== -->

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

6 changes: 5 additions & 1 deletion src/app/pages/pages.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { AccountSettingsComponent } from './account-settings/account-settings.co
import { PromesasComponent } from './promesas/promesas.component';
import { RxjsComponent } from './rxjs/rxjs.component';
import { ProfileComponent } from './profile/profile.component';
import { UsuariosComponent } from './usuarios/usuarios.component';
import { ModalUploadComponent } from '../components/modal-upload/modal-upload.component';


@NgModule({
Expand All @@ -38,7 +40,9 @@ import { ProfileComponent } from './profile/profile.component';
AccountSettingsComponent,
PromesasComponent,
RxjsComponent,
ProfileComponent
ProfileComponent,
UsuariosComponent,
ModalUploadComponent
],
exports: [
DashboardComponent,
Expand Down
7 changes: 6 additions & 1 deletion src/app/pages/pages.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import { Graficas1Component } from './graficas1/graficas1.component';
import { AccountSettingsComponent } from './account-settings/account-settings.component';
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 { LoginGuardGuard } from '../services/service.index';
import { UsuariosComponent } from './usuarios/usuarios.component';



const pagesRoutes: Routes = [
Expand All @@ -25,6 +28,8 @@ const pagesRoutes: Routes = [
{ path: 'rxjs', component: RxjsComponent, data: {titulo: 'RxJs'} },
{ path: 'account-settings', component: AccountSettingsComponent, data: {titulo: 'Ajustes del Tema'} },
{ path: 'perfil', component: ProfileComponent, data: {titulo: 'Perfil de usuario'} },
// MANTENIMIENTOS
{ path: 'usuarios', component: UsuariosComponent, data: {titulo: 'Mantenimiento de Usuarios'} },
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
]
}
Expand Down
98 changes: 98 additions & 0 deletions src/app/pages/usuarios/usuarios.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<div class="row animated fadeIn">
<div class="col-12">
<div class="card">
<div class="card-body">
<input
#input
(keyup)="buscarUsuario( input.value )"
type="text"
class="form-control"
placeholder="Buscar Usuario..."
/>
</div>
</div>
</div>
</div>

<div class="row animated fadeIn" *ngIf="cargando">
<div class="col-sm-12">
<div class="alert alert-warning text-center">
<strong>Cargando</strong>
<br />
<i class="fa fa-refresh fa-spin fa-2x"></i>
<br />
<span>Espere por favor</span>
</div>
</div>
</div>


<div class="row animated fadeIn" *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>Imagen</th>
<th>Correo</th>
<th>Nombre</th>
<th>Role</th>
<th>Auth</th>
<th></th>
</tr>
</thead>

<tbody>
<tr *ngFor="let usuario of usuarios" >
<td class="w70">
<img (click)="mostrarModal( usuario._id )" [src]="usuario.img | imagen" class ="img-50 img-circle pointer">
</td>
<td>
{{ usuario.email }}
</td>
<td>
{{ usuario.nombre }}
</td>
<td>

<select [(ngModel)]="usuario.role" name="role" class="form-control" > <!-- {{ usuario.role }} -->
<option value="ADMIN_ROLE">ADMIN_ROLE</option>
<option value="USER_ROLE">USER_ROLE</option>

</select>
</td>
<td>
<label *ngIf="usuario.google" class="label label-danger">Google</label>
<label *ngIf="!usuario.google" class="label label-info">Normal</label>
</td>
<td>
<button (click)="guardarUsuario( usuario )" class="btn btn-primary">
<i class="fa fa-save"></i>
</button>

<button (click)="borrarUsuario( usuario )" class="btn btn-danger">
<i class="fa fa-trash-o"></i>
</button>

</td>
</tr>
</tbody>

</table>

<button (click)="cambiarDesde(-5)" class="btn btn-secondary">
Anteriores
</button>

<button (click)="cambiarDesde(5)" class="btn btn-secondary">
Siguientes
</button>

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

0 comments on commit f94f195

Please sign in to comment.