listar usuarios
historia de usuario: listar usuarios registrados
This commit is contained in:
parent
6d4e76a193
commit
48cd746b59
|
@ -1,10 +1,21 @@
|
||||||
export interface IUser {
|
export interface IUser {
|
||||||
id?: number;
|
id?: number;
|
||||||
login?: string;
|
login?: string;
|
||||||
|
firstName?: string | null;
|
||||||
|
lastName?: string | null;
|
||||||
|
email?: string;
|
||||||
|
authorities?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class User implements IUser {
|
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 {
|
export function getUserIdentifier(user: IUser): number | undefined {
|
||||||
|
|
|
@ -32,8 +32,10 @@ describe('Service Tests', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const req = httpMock.expectOne({ method: 'GET' });
|
const req = httpMock.expectOne({ method: 'GET' });
|
||||||
req.flush([new User(123, 'user')]);
|
req.flush([new User(123, 'user', 'fist name', 'last name', 'email@gmail.com', ['ROLE_USER'])]);
|
||||||
expect(expectedResult).toEqual([{ id: 123, login: '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', () => {
|
it('should propagate not found response', () => {
|
||||||
|
|
|
@ -7,6 +7,9 @@ import { createRequestOption } from 'app/core/request/request-util';
|
||||||
import { isPresent } from 'app/core/util/operators';
|
import { isPresent } from 'app/core/util/operators';
|
||||||
import { Pagination } from 'app/core/request/request.model';
|
import { Pagination } from 'app/core/request/request.model';
|
||||||
import { IUser, getUserIdentifier } from './user.model';
|
import { IUser, getUserIdentifier } from './user.model';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
|
export type EntityResponseType = HttpResponse<IUser>;
|
||||||
|
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class UserService {
|
export class UserService {
|
||||||
|
|
|
@ -32,34 +32,38 @@
|
||||||
<table class="table table-striped" aria-describedby="page-heading">
|
<table class="table table-striped" aria-describedby="page-heading">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col"><span jhiTranslate="global.field.id">ID</span></th>
|
<th scope="col"><span>Rol de usuario</span></th>
|
||||||
<th scope="col"><span jhiTranslate="dataSurveyApp.usuarioExtra.nombre">Nombre</span></th>
|
|
||||||
<th scope="col"><span jhiTranslate="dataSurveyApp.usuarioExtra.iconoPerfil">Icono Perfil</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.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>
|
<th scope="col"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr *ngFor="let usuarioExtra of usuarioExtras; trackBy: trackId" data-cy="entityTable">
|
<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>
|
<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>
|
||||||
<td>{{ usuarioExtra.nombre }}</td>
|
<td>{{ usuarioExtra.nombre }}</td>
|
||||||
<td>{{ usuarioExtra.iconoPerfil }}</td>
|
<td *ngIf="usuarioExtra.user">{{ usuarioExtra.user.firstName }} {{ usuarioExtra.user.lastName }}</td>
|
||||||
<td>{{ usuarioExtra.fechaNacimiento | formatMediumDatetime }}</td>
|
<td *ngIf="usuarioExtra.user">{{ usuarioExtra.user.email }}</td>
|
||||||
<td jhiTranslate="{{ 'dataSurveyApp.EstadoUsuario.' + usuarioExtra.estado }}">{{ usuarioExtra.estado }}</td>
|
<td jhiTranslate="{{ 'dataSurveyApp.EstadoUsuario.' + usuarioExtra.estado }}">{{ usuarioExtra.estado }}</td>
|
||||||
<td>
|
<!--<td>
|
||||||
{{ usuarioExtra.user?.id }}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<span *ngFor="let plantilla of usuarioExtra.plantillas; let last = last">
|
<span *ngFor="let plantilla of usuarioExtra.plantillas; let last = last">
|
||||||
<a class="form-control-static" [routerLink]="['/plantilla', plantilla.id, 'view']">{{ plantilla.id }}</a
|
<a class="form-control-static" [routerLink]="['/plantilla', plantilla.id, 'view']">{{ plantilla.id }}</a
|
||||||
>{{ last ? '' : ', ' }}
|
>{{ last ? '' : ', ' }}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>-->
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button
|
<button
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
.photo {
|
||||||
|
width: 80px;
|
||||||
|
height: 80px;
|
||||||
|
overflow: hidden;
|
||||||
|
z-index: 5;
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.listRoles {
|
||||||
|
list-style: none;
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
|
@ -5,24 +5,48 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { IUsuarioExtra } from '../usuario-extra.model';
|
import { IUsuarioExtra } from '../usuario-extra.model';
|
||||||
import { UsuarioExtraService } from '../service/usuario-extra.service';
|
import { UsuarioExtraService } from '../service/usuario-extra.service';
|
||||||
import { UsuarioExtraDeleteDialogComponent } from '../delete/usuario-extra-delete-dialog.component';
|
import { UsuarioExtraDeleteDialogComponent } from '../delete/usuario-extra-delete-dialog.component';
|
||||||
|
import { IUser } from '../../user/user.model';
|
||||||
|
import { finalize } from 'rxjs/operators';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'jhi-usuario-extra',
|
selector: 'jhi-usuario-extra',
|
||||||
templateUrl: './usuario-extra.component.html',
|
templateUrl: './usuario-extra.component.html',
|
||||||
|
styleUrls: ['./usuario-extra.component.scss'],
|
||||||
})
|
})
|
||||||
export class UsuarioExtraComponent implements OnInit {
|
export class UsuarioExtraComponent implements OnInit {
|
||||||
usuarioExtras?: IUsuarioExtra[];
|
usuarioExtras?: IUsuarioExtra[];
|
||||||
|
publicUsers?: IUser[];
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
|
|
||||||
constructor(protected usuarioExtraService: UsuarioExtraService, protected modalService: NgbModal) {}
|
constructor(protected usuarioExtraService: UsuarioExtraService, protected modalService: NgbModal) {}
|
||||||
|
|
||||||
loadAll(): void {
|
loadPublicUser(): void {
|
||||||
this.isLoading = true;
|
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(
|
this.usuarioExtraService.query().subscribe(
|
||||||
(res: HttpResponse<IUsuarioExtra[]>) => {
|
(res: HttpResponse<IUsuarioExtra[]>) => {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
this.usuarioExtras = res.body ?? [];
|
this.usuarioExtras = res.body ?? [];
|
||||||
|
this.usuarioExtras.forEach(uE => {
|
||||||
|
uE.user = this.publicUsers?.find(pU => pU.id == uE.user?.id);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
|
@ -30,6 +54,11 @@ export class UsuarioExtraComponent implements OnInit {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadAll(): void {
|
||||||
|
this.isLoading = true;
|
||||||
|
this.loadPublicUser();
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.loadAll();
|
this.loadAll();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,17 @@ import { isPresent } from 'app/core/util/operators';
|
||||||
import { ApplicationConfigService } from 'app/core/config/application-config.service';
|
import { ApplicationConfigService } from 'app/core/config/application-config.service';
|
||||||
import { createRequestOption } from 'app/core/request/request-util';
|
import { createRequestOption } from 'app/core/request/request-util';
|
||||||
import { IUsuarioExtra, getUsuarioExtraIdentifier } from '../usuario-extra.model';
|
import { IUsuarioExtra, getUsuarioExtraIdentifier } from '../usuario-extra.model';
|
||||||
|
import { IUser } from '../../user/user.model';
|
||||||
|
|
||||||
export type EntityResponseType = HttpResponse<IUsuarioExtra>;
|
export type EntityResponseType = HttpResponse<IUsuarioExtra>;
|
||||||
export type EntityArrayResponseType = HttpResponse<IUsuarioExtra[]>;
|
export type EntityArrayResponseType = HttpResponse<IUsuarioExtra[]>;
|
||||||
|
|
||||||
|
export type EntityArrayUserPublicResponseType = HttpResponse<IUser[]>;
|
||||||
|
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class UsuarioExtraService {
|
export class UsuarioExtraService {
|
||||||
protected resourceUrl = this.applicationConfigService.getEndpointFor('api/usuario-extras');
|
protected resourceUrl = this.applicationConfigService.getEndpointFor('api/usuario-extras');
|
||||||
|
protected resourceUrlPublicUser = this.applicationConfigService.getEndpointFor('api');
|
||||||
|
|
||||||
constructor(protected http: HttpClient, protected applicationConfigService: ApplicationConfigService) {}
|
constructor(protected http: HttpClient, protected applicationConfigService: ApplicationConfigService) {}
|
||||||
|
|
||||||
|
@ -45,6 +49,10 @@ export class UsuarioExtraService {
|
||||||
.pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
|
.pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
retrieveAllPublicUsers(): Observable<IUser[]> {
|
||||||
|
return this.http.get<IUser[]>(this.resourceUrlPublicUser + '/admin/users');
|
||||||
|
}
|
||||||
|
|
||||||
query(req?: any): Observable<EntityArrayResponseType> {
|
query(req?: any): Observable<EntityArrayResponseType> {
|
||||||
const options = createRequestOption(req);
|
const options = createRequestOption(req);
|
||||||
return this.http
|
return this.http
|
||||||
|
|
Loading…
Reference in New Issue