listar usuarios

historia de usuario: listar usuarios registrados
This commit is contained in:
Mariela Bonilla 2021-07-06 22:53:02 -06:00
parent 6d4e76a193
commit 48cd746b59
7 changed files with 87 additions and 18 deletions

View File

@ -1,10 +1,21 @@
export interface IUser {
id?: number;
login?: string;
firstName?: string | null;
lastName?: string | null;
email?: string;
authorities?: string[];
}
export class User implements IUser {
constructor(public id: number, public login: string) {}
constructor(
public id: number,
public login: string,
public firstName?: string,
public lastName?: string,
public email?: string,
public authorities?: string[]
) {}
}
export function getUserIdentifier(user: IUser): number | undefined {

View File

@ -32,8 +32,10 @@ describe('Service Tests', () => {
});
const req = httpMock.expectOne({ method: 'GET' });
req.flush([new User(123, 'user')]);
expect(expectedResult).toEqual([{ id: 123, login: 'user' }]);
req.flush([new User(123, 'user', 'fist name', 'last name', 'email@gmail.com', ['ROLE_USER'])]);
expect(expectedResult).toEqual([
{ id: 123, login: 'user', firstName: 'fist name', lastName: 'last name', email: 'email@gmail.com', authorities: ['ROLE_USER'] },
]);
});
it('should propagate not found response', () => {

View File

@ -7,6 +7,9 @@ import { createRequestOption } from 'app/core/request/request-util';
import { isPresent } from 'app/core/util/operators';
import { Pagination } from 'app/core/request/request.model';
import { IUser, getUserIdentifier } from './user.model';
import { map } from 'rxjs/operators';
export type EntityResponseType = HttpResponse<IUser>;
@Injectable({ providedIn: 'root' })
export class UserService {

View File

@ -32,34 +32,38 @@
<table class="table table-striped" aria-describedby="page-heading">
<thead>
<tr>
<th scope="col"><span jhiTranslate="global.field.id">ID</span></th>
<th scope="col"><span jhiTranslate="dataSurveyApp.usuarioExtra.nombre">Nombre</span></th>
<th scope="col"><span>Rol de usuario</span></th>
<th scope="col"><span jhiTranslate="dataSurveyApp.usuarioExtra.iconoPerfil">Icono Perfil</span></th>
<th scope="col"><span jhiTranslate="dataSurveyApp.usuarioExtra.fechaNacimiento">Fecha Nacimiento</span></th>
<th scope="col"><span jhiTranslate="dataSurveyApp.usuarioExtra.nombre">Nombre Usuario</span></th>
<th scope="col"><span>Nombre Completo</span></th>
<th scope="col"><span>Correo electrónico</span></th>
<th scope="col"><span jhiTranslate="dataSurveyApp.usuarioExtra.estado">Estado</span></th>
<th scope="col"><span jhiTranslate="dataSurveyApp.usuarioExtra.user">User</span></th>
<th scope="col"><span jhiTranslate="dataSurveyApp.usuarioExtra.plantilla">Plantilla</span></th>
<!--<th scope="col"><span jhiTranslate="dataSurveyApp.usuarioExtra.plantilla">Plantilla</span></th>-->
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let usuarioExtra of usuarioExtras; trackBy: trackId" data-cy="entityTable">
<td *ngIf="usuarioExtra.user">
<ul class="listRoles">
<li *ngFor="let userRole of usuarioExtra.user.authorities">
<p>{{ userRole }}</p>
</li>
</ul>
</td>
<td>
<a [routerLink]="['/usuario-extra', usuarioExtra.id, 'view']">{{ usuarioExtra.id }}</a>
<div class="photo mb-2"><img src="../../../../content/profile_icons/C{{ usuarioExtra.iconoPerfil }}.png" /></div>
</td>
<td>{{ usuarioExtra.nombre }}</td>
<td>{{ usuarioExtra.iconoPerfil }}</td>
<td>{{ usuarioExtra.fechaNacimiento | formatMediumDatetime }}</td>
<td *ngIf="usuarioExtra.user">{{ usuarioExtra.user.firstName }} {{ usuarioExtra.user.lastName }}</td>
<td *ngIf="usuarioExtra.user">{{ usuarioExtra.user.email }}</td>
<td jhiTranslate="{{ 'dataSurveyApp.EstadoUsuario.' + usuarioExtra.estado }}">{{ usuarioExtra.estado }}</td>
<td>
{{ usuarioExtra.user?.id }}
</td>
<td>
<!--<td>
<span *ngFor="let plantilla of usuarioExtra.plantillas; let last = last">
<a class="form-control-static" [routerLink]="['/plantilla', plantilla.id, 'view']">{{ plantilla.id }}</a
>{{ last ? '' : ', ' }}
</span>
</td>
</td>-->
<td class="text-right">
<div class="btn-group">
<button

View File

@ -0,0 +1,12 @@
.photo {
width: 80px;
height: 80px;
overflow: hidden;
z-index: 5;
border-radius: 50%;
}
.listRoles {
list-style: none;
padding-left: 10px;
}

View File

@ -5,24 +5,48 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { IUsuarioExtra } from '../usuario-extra.model';
import { UsuarioExtraService } from '../service/usuario-extra.service';
import { UsuarioExtraDeleteDialogComponent } from '../delete/usuario-extra-delete-dialog.component';
import { IUser } from '../../user/user.model';
import { finalize } from 'rxjs/operators';
@Component({
selector: 'jhi-usuario-extra',
templateUrl: './usuario-extra.component.html',
styleUrls: ['./usuario-extra.component.scss'],
})
export class UsuarioExtraComponent implements OnInit {
usuarioExtras?: IUsuarioExtra[];
publicUsers?: IUser[];
isLoading = false;
constructor(protected usuarioExtraService: UsuarioExtraService, protected modalService: NgbModal) {}
loadAll(): void {
this.isLoading = true;
loadPublicUser(): void {
this.usuarioExtraService
.retrieveAllPublicUsers()
.pipe(finalize(() => this.loadUserExtras()))
.subscribe(res => {
res.forEach(user => {
let rolList: string[] | undefined;
rolList = user.authorities;
let a = rolList?.pop();
if (a == 'ROLE_ADMIN') {
user.authorities = ['ADMIN'];
} else if (a == 'ROLE_USER') {
user.authorities = ['USUARIO'];
}
});
this.publicUsers = res;
});
}
loadUserExtras() {
this.usuarioExtraService.query().subscribe(
(res: HttpResponse<IUsuarioExtra[]>) => {
this.isLoading = false;
this.usuarioExtras = res.body ?? [];
this.usuarioExtras.forEach(uE => {
uE.user = this.publicUsers?.find(pU => pU.id == uE.user?.id);
});
},
() => {
this.isLoading = false;
@ -30,6 +54,11 @@ export class UsuarioExtraComponent implements OnInit {
);
}
loadAll(): void {
this.isLoading = true;
this.loadPublicUser();
}
ngOnInit(): void {
this.loadAll();
}

View File

@ -8,13 +8,17 @@ import { isPresent } from 'app/core/util/operators';
import { ApplicationConfigService } from 'app/core/config/application-config.service';
import { createRequestOption } from 'app/core/request/request-util';
import { IUsuarioExtra, getUsuarioExtraIdentifier } from '../usuario-extra.model';
import { IUser } from '../../user/user.model';
export type EntityResponseType = HttpResponse<IUsuarioExtra>;
export type EntityArrayResponseType = HttpResponse<IUsuarioExtra[]>;
export type EntityArrayUserPublicResponseType = HttpResponse<IUser[]>;
@Injectable({ providedIn: 'root' })
export class UsuarioExtraService {
protected resourceUrl = this.applicationConfigService.getEndpointFor('api/usuario-extras');
protected resourceUrlPublicUser = this.applicationConfigService.getEndpointFor('api');
constructor(protected http: HttpClient, protected applicationConfigService: ApplicationConfigService) {}
@ -45,6 +49,10 @@ export class UsuarioExtraService {
.pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
}
retrieveAllPublicUsers(): Observable<IUser[]> {
return this.http.get<IUser[]>(this.resourceUrlPublicUser + '/admin/users');
}
query(req?: any): Observable<EntityArrayResponseType> {
const options = createRequestOption(req);
return this.http