Merge pull request #11 from Quantum-P3/feature/US-07

Feature/US-07
This commit is contained in:
Eduardo Quiros 2021-07-09 06:19:07 +00:00 committed by GitHub
commit 15a7969cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 87 additions and 76 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
@ -72,16 +76,6 @@
<span class="d-none d-md-inline" jhiTranslate="entity.action.view">View</span>
</button>
<button
type="submit"
[routerLink]="['/usuario-extra', usuarioExtra.id, 'edit']"
class="btn btn-primary btn-sm"
data-cy="entityEditButton"
>
<fa-icon icon="pencil-alt"></fa-icon>
<span class="d-none d-md-inline" jhiTranslate="entity.action.edit">Edit</span>
</button>
<button type="submit" (click)="delete(usuarioExtra)" class="btn btn-danger btn-sm" data-cy="entityDeleteButton">
<fa-icon icon="times"></fa-icon>
<span class="d-none d-md-inline" jhiTranslate="entity.action.delete">Delete</span>

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

@ -1,48 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { HttpHeaders, HttpResponse } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { of } from 'rxjs';
import { UsuarioExtraService } from '../service/usuario-extra.service';
import { UsuarioExtraComponent } from './usuario-extra.component';
describe('Component Tests', () => {
describe('UsuarioExtra Management Component', () => {
let comp: UsuarioExtraComponent;
let fixture: ComponentFixture<UsuarioExtraComponent>;
let service: UsuarioExtraService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
declarations: [UsuarioExtraComponent],
})
.overrideTemplate(UsuarioExtraComponent, '')
.compileComponents();
fixture = TestBed.createComponent(UsuarioExtraComponent);
comp = fixture.componentInstance;
service = TestBed.inject(UsuarioExtraService);
const headers = new HttpHeaders().append('link', 'link;link');
jest.spyOn(service, 'query').mockReturnValue(
of(
new HttpResponse({
body: [{ id: 123 }],
headers,
})
)
);
});
it('Should call load all on init', () => {
// WHEN
comp.ngOnInit();
// THEN
expect(service.query).toHaveBeenCalled();
expect(comp.usuarioExtras?.[0]).toEqual(expect.objectContaining({ id: 123 }));
});
});
});

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