Skip to content

Commit

Permalink
se completo el dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
matias1305 committed Dec 11, 2018
1 parent ff9f64d commit f3cabbe
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 60 deletions.
111 changes: 56 additions & 55 deletions src/app/admin/dashboard/dashboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,59 +56,6 @@ <h2 class="m-t-0">{{ count_messages }}</h2>
<!-- End report boxes -->
<!-- =============================================================== -->

<!-- =============================================================== -->
<!-- Users status -->
<!-- =============================================================== -->
<div class="row">
<div class="col-lg-12 col-md-12">
<div class="card">
<div class="card-body">
<div class="d-flex">
<div>
<h4 class="card-title"><span class="lstick"></span>Estado de usuarios</h4>
</div>
</div>
<div class="table-responsive m-t-20">
<table class="table vm no-th-brd no-wrap pro-of-month">
<thead>
<tr>
<th colspan="2">Usuario</th>
<th>Tipo de usuario</th>
<th>Estado</th>
<th>Cambiar estado</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let u of users">
<td style="width:50px;"><span class="round">
<img src="../assets/images/users/1.jpg" alt="user" width="50"></span>
</td>
<td>
<h6>{{ u.name | titlecase }} {{ u.last_name1 | titlecase }} {{ u.last_name2 | titlecase }}</h6>
<small class="text-muted">Creado el: {{ u.created_date }}</small>
</td>
<td>{{ u.role | titlecase }}</td>
<td>
<span *ngIf="[u.status] == 'true'" class="label label-success label-rounded">Activo</span>
<span *ngIf="[u.status] == 'false'" class="label label-danger label-rounded">Inactivo</span>
</td>
<!-- FIXME: Probar -->
<td>
<button class="btn btn-circle btn-info" (click)="changeState(u)">Cambiar estado</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- =============================================================== -->
<!-- End users status -->
<!-- =============================================================== -->


<!-- ============================================================== -->
<!-- Reports -->
<!-- ============================================================== -->
Expand Down Expand Up @@ -140,11 +87,11 @@ <h3 class="card-title m-b-5">
<th>Hora</th>
<th>Reporte</th>
<th>Estado</th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let r of reports">
<!-- TODO: Revisar visualmente y borrar referencis sin ID -->
<tr *ngFor="let r of reports; let i = index;">
<td>
<h6>{{ r.user.name | titlecase }} {{ r.user.last_name1 | titlecase }} {{ r.user.last_name2 | titlecase }}</h6>
</td>
Expand All @@ -165,6 +112,9 @@ <h6 *ngIf="r.type == 'Reporte de usuario'">Se reporta al usuario {{ r.user_repor
<span *ngIf="[r.status] == 'Revisado'" class="label label-success label-rounded">Revisado</span>
<span *ngIf="[r.status] == 'No revisado'" class="label label-danger label-rounded">No revisado</span>
</td>
<td>
<button class="btn btn-primary mr-3" (click)="reportBlock(r.type, r, i)"> Bloquear </button>
</td>
</tr>
</tbody>
</table>
Expand All @@ -175,6 +125,57 @@ <h6 *ngIf="r.type == 'Reporte de usuario'">Se reporta al usuario {{ r.user_repor
<!-- End reports -->
<!-- ============================================================== -->

<!-- =============================================================== -->
<!-- Users status -->
<!-- =============================================================== -->
<div class="row">
<div class="col-lg-12 col-md-12">
<div class="card">
<div class="card-body">
<div class="d-flex">
<div>
<h4 class="card-title"><span class="lstick"></span>Estado de usuarios</h4>
</div>
</div>
<div class="table-responsive m-t-20">
<table class="table vm no-th-brd no-wrap pro-of-month">
<thead>
<tr>
<th colspan="2">Usuario</th>
<th>Tipo de usuario</th>
<th>Estado</th>
<th>Cambiar estado</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let u of users">
<td style="width:50px;"><span class="round">
<img src="../assets/images/users/1.jpg" alt="user" width="50"></span>
</td>
<td>
<h6>{{ u.name | titlecase }} {{ u.last_name1 | titlecase }} {{ u.last_name2 | titlecase }}</h6>
<small class="text-muted">Creado el: {{ u.created_date }}</small>
</td>
<td>{{ u.role | titlecase }}</td>
<td>
<span *ngIf="[u.status] == 'true'" class="label label-success label-rounded">Activo</span>
<span *ngIf="[u.status] == 'false'" class="label label-danger label-rounded">Inactivo</span>
</td>
<td>
<button class="btn btn-info" (click)="changeState(u)">Cambiar estado</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<!-- =============================================================== -->
<!-- End users status -->
<!-- =============================================================== -->

<!-- ============================================================== -->
<!-- Todo list -->
<!-- ============================================================== -->
Expand Down
70 changes: 65 additions & 5 deletions src/app/admin/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FormControl, FormControlName, FormGroup, Validators } from '@angular/fo
// SERVICES
import { DatabaseService } from '../../services/database.service';
import { DateService } from '../../services/date.service';
import { map } from 'rxjs/operators';

@Component({
selector: 'app-dashboard',
Expand Down Expand Up @@ -39,7 +40,14 @@ export class DashboardComponent implements OnInit {
this.actual_day = this._date.actual_day();

this._dbService.getData( "users")
.valueChanges()
.snapshotChanges()
.pipe(
map( actions => actions.map( a => {
const data = a.payload.doc.data();
const key = a.payload.doc.id;
return { key, ...data };
}))
)
.subscribe( (data:any) => {
this.users = data;
this.count_users = data.length;
Expand All @@ -54,7 +62,14 @@ export class DashboardComponent implements OnInit {
.subscribe( data => this.count_messages = data.length );

this._dbService.getData( "reports")
.valueChanges()
.snapshotChanges()
.pipe(
map( actions => actions.map( a => {
const data = a.payload.doc.data();
const key = a.payload.doc.id;
return { key, ...data };
}))
)
.subscribe( data => {
this.reports = data;
this.reportsData = this.reports;
Expand Down Expand Up @@ -84,7 +99,6 @@ export class DashboardComponent implements OnInit {
}
}

// FIXME: Probar
changeState(user:any){
user.status = ! user.status;

Expand All @@ -95,13 +109,59 @@ export class DashboardComponent implements OnInit {
.catch( () => {
swal('Error', 'Por favor, vuelva a intentarlo', 'error');
});


}

// addTask(){
// this._dbService.addDataIdCustom('tasks', this.actual_user, this.form)
// .then( () => swal('Tarea guardada', 'La tarea ha sido guardada con éxito', 'success') )
// .catch( () => swal('Error', 'La tarea no ha podido guardarse, vuelva a intentarlo', 'error') );
// }

reportBlock(type, report, index) {
report.status = 'Revisado';

if( type === 'Reporte de imagen' ) {
swal({
title: type,
text: `¿Desea bloquear esta imagen?`,
icon: "warning",
buttons: ['Omitir', 'Bloquear'],
dangerMode: true
})
.then(( bloqued ) => {
if ( bloqued ) {
this._dbService.updateData('reports', report.key, report)
.then( ()=>{
swal("La imagen fue bloqueada del sistema!", {
icon: "success",
});
});
} else {
swal("Esta reporte fue omitido");
}
});


}else if( type === 'Reporte de usuario' ) {
swal({
title: type,
text: `¿Desea bloquear al usuario ${report.user_reported.name} ${report.user_reported.last_name1}?`,
icon: "warning",
buttons: ['Omitir', 'Bloquear'],
dangerMode: true
})
.then(( bloqued ) => {
if ( bloqued ) {
this._dbService.updateData('reports', report.key, report)
.then( ()=>{
swal("Este usuario fue bloqueado del sistema!", {
icon: "success",
});
});
} else {
swal("Este reporte fue omitido");
}
});
}
}
}

0 comments on commit f3cabbe

Please sign in to comment.