Merge branch 'dev' into feature/US-01
This commit is contained in:
commit
10587cf511
|
@ -157,3 +157,5 @@ Desktop.ini
|
||||||
######################
|
######################
|
||||||
/coverage/
|
/coverage/
|
||||||
/.nyc_output/
|
/.nyc_output/
|
||||||
|
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
|
@ -156,8 +156,7 @@ public class UserService {
|
||||||
* Modified to register extra user data
|
* Modified to register extra user data
|
||||||
* name, iconoPerfil, fechaNacimiento, estado, pais
|
* name, iconoPerfil, fechaNacimiento, estado, pais
|
||||||
*/
|
*/
|
||||||
public User registerUser(AdminUserDTO userDTO, String password, String name, Integer profileIcon) {
|
public User registerUser(AdminUserDTO userDTO, String password, String name, Integer profileIcon, Integer isAdmin) {
|
||||||
System.out.println(name);
|
|
||||||
userRepository
|
userRepository
|
||||||
.findOneByLogin(userDTO.getLogin().toLowerCase())
|
.findOneByLogin(userDTO.getLogin().toLowerCase())
|
||||||
.ifPresent(
|
.ifPresent(
|
||||||
|
@ -195,7 +194,12 @@ public class UserService {
|
||||||
// new user gets registration key
|
// new user gets registration key
|
||||||
newUser.setActivationKey(RandomUtil.generateActivationKey());
|
newUser.setActivationKey(RandomUtil.generateActivationKey());
|
||||||
Set<Authority> authorities = new HashSet<>();
|
Set<Authority> authorities = new HashSet<>();
|
||||||
|
// Check whether it's an ADMIN or USER and apply authorities
|
||||||
|
if (isAdmin == 1) {
|
||||||
|
authorityRepository.findById(AuthoritiesConstants.ADMIN).ifPresent(authorities::add);
|
||||||
|
}
|
||||||
authorityRepository.findById(AuthoritiesConstants.USER).ifPresent(authorities::add);
|
authorityRepository.findById(AuthoritiesConstants.USER).ifPresent(authorities::add);
|
||||||
|
|
||||||
newUser.setAuthorities(authorities);
|
newUser.setAuthorities(authorities);
|
||||||
userRepository.save(newUser);
|
userRepository.save(newUser);
|
||||||
this.clearUserCaches(newUser);
|
this.clearUserCaches(newUser);
|
||||||
|
|
|
@ -66,7 +66,8 @@ public class AccountResource {
|
||||||
managedUserVM,
|
managedUserVM,
|
||||||
managedUserVM.getPassword(),
|
managedUserVM.getPassword(),
|
||||||
managedUserVM.getName(),
|
managedUserVM.getName(),
|
||||||
managedUserVM.getProfileIcon()
|
managedUserVM.getProfileIcon(),
|
||||||
|
managedUserVM.getIsAdmin()
|
||||||
);
|
);
|
||||||
mailService.sendActivationEmail(user);
|
mailService.sendActivationEmail(user);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,8 @@ public class ManagedUserVM extends AdminUserDTO {
|
||||||
|
|
||||||
private Integer profileIcon;
|
private Integer profileIcon;
|
||||||
|
|
||||||
|
private Integer isAdmin;
|
||||||
|
|
||||||
public ManagedUserVM() {
|
public ManagedUserVM() {
|
||||||
// Empty constructor needed for Jackson.
|
// Empty constructor needed for Jackson.
|
||||||
}
|
}
|
||||||
|
@ -50,6 +52,14 @@ public class ManagedUserVM extends AdminUserDTO {
|
||||||
this.profileIcon = profileIcon;
|
this.profileIcon = profileIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getIsAdmin() {
|
||||||
|
return isAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsAdmin(Integer isAdmin) {
|
||||||
|
this.isAdmin = isAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -64,6 +64,7 @@ describe('Component Tests', () => {
|
||||||
langKey: 'es',
|
langKey: 'es',
|
||||||
name: '',
|
name: '',
|
||||||
profileIcon: 1,
|
profileIcon: 1,
|
||||||
|
isAdmin: 0,
|
||||||
});
|
});
|
||||||
expect(comp.success).toBe(true);
|
expect(comp.success).toBe(true);
|
||||||
expect(comp.errorUserExists).toBe(false);
|
expect(comp.errorUserExists).toBe(false);
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { Component, AfterViewInit, ElementRef, ViewChild } from '@angular/core';
|
import { Component, OnInit, AfterViewInit, ElementRef, ViewChild } from '@angular/core';
|
||||||
import { HttpErrorResponse } from '@angular/common/http';
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
import { FormBuilder, Validators } from '@angular/forms';
|
import { FormBuilder, Validators } from '@angular/forms';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
import { EMAIL_ALREADY_USED_TYPE, LOGIN_ALREADY_USED_TYPE } from 'app/config/error.constants';
|
import { EMAIL_ALREADY_USED_TYPE, LOGIN_ALREADY_USED_TYPE } from 'app/config/error.constants';
|
||||||
import { RegisterService } from './register.service';
|
import { RegisterService } from './register.service';
|
||||||
|
@ -86,7 +87,15 @@ export class RegisterComponent implements AfterViewInit {
|
||||||
console.log(name);
|
console.log(name);
|
||||||
|
|
||||||
this.registerService
|
this.registerService
|
||||||
.save({ login, email, password, langKey: this.translateService.currentLang, name, profileIcon: this.profileIcon })
|
.save({
|
||||||
|
login,
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
langKey: this.translateService.currentLang,
|
||||||
|
name,
|
||||||
|
profileIcon: this.profileIcon,
|
||||||
|
isAdmin: 0,
|
||||||
|
})
|
||||||
.subscribe(
|
.subscribe(
|
||||||
() => (this.success = true),
|
() => (this.success = true),
|
||||||
response => this.processError(response)
|
response => this.processError(response)
|
||||||
|
|
|
@ -5,6 +5,7 @@ export class Registration {
|
||||||
public password: string,
|
public password: string,
|
||||||
public langKey: string,
|
public langKey: string,
|
||||||
public name: string,
|
public name: string,
|
||||||
public profileIcon: number
|
public profileIcon: number,
|
||||||
|
public isAdmin: number
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,118 +1,246 @@
|
||||||
<div class="row justify-content-center">
|
<div class="container">
|
||||||
<div class="col-8">
|
<div class="row justify-content-center">
|
||||||
<form name="editForm" role="form" novalidate (ngSubmit)="save()" [formGroup]="editForm">
|
<div class="col-xxl-8 col-lg-6">
|
||||||
<h2
|
<div class="card mt-1">
|
||||||
id="jhi-usuario-extra-heading"
|
<!-- <div class="pl-4 pt-4 pr-4 pb-1 text-center">
|
||||||
data-cy="UsuarioExtraCreateUpdateHeading"
|
<img src="../../content/img_datasurvey/datasurvey-logo-text-black.svg" alt="" />
|
||||||
jhiTranslate="dataSurveyApp.usuarioExtra.home.createOrEditLabel"
|
</div> -->
|
||||||
>
|
|
||||||
Create or edit a Usuario Extra
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<div>
|
<div class="card-body p-4">
|
||||||
<jhi-alert-error></jhi-alert-error>
|
<div class="text-center w-75 m-auto">
|
||||||
|
<h4 class="text-dark-50 text-center pb-0 fw-bold p-0 m-0" style="color: #727070; font-weight: 700; font-size: 1.3rem">
|
||||||
<div class="form-group" [hidden]="editForm.get('id')!.value == null">
|
REGISTRAR ADMIN
|
||||||
<label class="form-control-label" jhiTranslate="global.field.id" for="field_id">ID</label>
|
</h4>
|
||||||
<input type="number" class="form-control" name="id" id="field_id" data-cy="id" formControlName="id" [readonly]="true" />
|
<p class="mb-4" style="color: rgba(146, 146, 146, 0.664)">Ingrese los datos para registrar a un admin.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="alert alert-success" *ngIf="success" jhiTranslate="register.messages.adminsuccess">
|
||||||
|
<strong>Registration saved!</strong> Please check your email for confirmation.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="alert alert-danger" *ngIf="error" jhiTranslate="register.messages.error.fail">
|
||||||
|
<strong>Registration failed!</strong> Please try again later.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="alert alert-danger" *ngIf="errorEmailExists" jhiTranslate="register.messages.error.emailexists">
|
||||||
|
<strong>Email is already in use!</strong> Please choose another one.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="alert alert-danger" *ngIf="doNotMatch" jhiTranslate="global.messages.error.dontmatch">
|
||||||
|
The password and its confirmation do not match!
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form name="form" role="form" class="form" (ngSubmit)="register()" [formGroup]="registerForm" *ngIf="!success" autocomplete="off">
|
||||||
|
<div class="mb-3">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.nombre" for="field_nombre">Nombre</label>
|
<label for="name" class="form-label">Nombre</label>
|
||||||
<input type="text" class="form-control" name="nombre" id="field_nombre" data-cy="nombre" formControlName="nombre" />
|
|
||||||
<div *ngIf="editForm.get('nombre')!.invalid && (editForm.get('nombre')!.dirty || editForm.get('nombre')!.touched)">
|
|
||||||
<small class="form-text text-danger" *ngIf="editForm.get('nombre')?.errors?.required" jhiTranslate="entity.validation.required">
|
|
||||||
This field is required.
|
|
||||||
</small>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.iconoPerfil" for="field_iconoPerfil"
|
|
||||||
>Icono Perfil</label
|
|
||||||
>
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
class="form-control"
|
class="form-control"
|
||||||
name="iconoPerfil"
|
id="name"
|
||||||
id="field_iconoPerfil"
|
name="name"
|
||||||
data-cy="iconoPerfil"
|
placeholder="{{ 'global.form.name.placeholder' | translate }}"
|
||||||
formControlName="iconoPerfil"
|
formControlName="name"
|
||||||
|
data-cy="name"
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<div *ngIf="registerForm.get('name')!.invalid && (registerForm.get('name')!.dirty || registerForm.get('name')!.touched)">
|
||||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.fechaNacimiento" for="field_fechaNacimiento"
|
<small
|
||||||
>Fecha Nacimiento</label
|
class="form-text text-danger"
|
||||||
|
*ngIf="registerForm.get('name')?.errors?.required"
|
||||||
|
jhiTranslate="global.messages.validate.name.required"
|
||||||
>
|
>
|
||||||
<div class="d-flex">
|
Your name is required.
|
||||||
<input
|
</small>
|
||||||
id="field_fechaNacimiento"
|
|
||||||
data-cy="fechaNacimiento"
|
|
||||||
type="datetime-local"
|
|
||||||
class="form-control"
|
|
||||||
name="fechaNacimiento"
|
|
||||||
formControlName="fechaNacimiento"
|
|
||||||
placeholder="YYYY-MM-DD HH:mm"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="form-group">
|
<small
|
||||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.estado" for="field_estado">Estado</label>
|
class="form-text text-danger"
|
||||||
<select class="form-control" name="estado" formControlName="estado" id="field_estado" data-cy="estado">
|
*ngIf="registerForm.get('name')?.errors?.invalid"
|
||||||
<option [ngValue]="null">{{ 'dataSurveyApp.EstadoUsuario.null' | translate }}</option>
|
jhiTranslate="global.messages.validate.name.invalid"
|
||||||
<option value="ACTIVE">{{ 'dataSurveyApp.EstadoUsuario.ACTIVE' | translate }}</option>
|
>
|
||||||
<option value="SUSPENDED">{{ 'dataSurveyApp.EstadoUsuario.SUSPENDED' | translate }}</option>
|
Your name is invalid.
|
||||||
</select>
|
</small>
|
||||||
<div *ngIf="editForm.get('estado')!.invalid && (editForm.get('estado')!.dirty || editForm.get('estado')!.touched)">
|
|
||||||
<small class="form-text text-danger" *ngIf="editForm.get('estado')?.errors?.required" jhiTranslate="entity.validation.required">
|
<small
|
||||||
This field is required.
|
class="form-text text-danger"
|
||||||
|
*ngIf="registerForm.get('name')?.errors?.minlength"
|
||||||
|
jhiTranslate="global.messages.validate.name.minlength"
|
||||||
|
>
|
||||||
|
Your name is required to be at least 2 characters.
|
||||||
|
</small>
|
||||||
|
|
||||||
|
<small
|
||||||
|
class="form-text text-danger"
|
||||||
|
*ngIf="registerForm.get('name')?.errors?.maxlength"
|
||||||
|
jhiTranslate="global.messages.validate.name.maxlength"
|
||||||
|
>
|
||||||
|
Your name cannot be longer than 50 characters.
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.user" for="field_user">User</label>
|
<label for="emailaddress" class="form-label">Correo electrónico</label>
|
||||||
<select class="form-control" id="field_user" data-cy="user" name="user" formControlName="user">
|
<input
|
||||||
<option [ngValue]="null"></option>
|
type="email"
|
||||||
<option
|
class="form-control"
|
||||||
[ngValue]="userOption.id === editForm.get('user')!.value?.id ? editForm.get('user')!.value : userOption"
|
id="email"
|
||||||
*ngFor="let userOption of usersSharedCollection; trackBy: trackUserById"
|
name="email"
|
||||||
|
placeholder="{{ 'global.form.email.placeholder' | translate }}"
|
||||||
|
formControlName="email"
|
||||||
|
data-cy="email"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div *ngIf="registerForm.get('email')!.invalid && (registerForm.get('email')!.dirty || registerForm.get('email')!.touched)">
|
||||||
|
<small
|
||||||
|
class="form-text text-danger"
|
||||||
|
*ngIf="registerForm.get('email')?.errors?.required"
|
||||||
|
jhiTranslate="global.messages.validate.email.required"
|
||||||
>
|
>
|
||||||
{{ userOption.id }}
|
Your email is required.
|
||||||
</option>
|
</small>
|
||||||
</select>
|
|
||||||
|
<small
|
||||||
|
class="form-text text-danger"
|
||||||
|
*ngIf="registerForm.get('email')?.errors?.invalid"
|
||||||
|
jhiTranslate="global.messages.validate.email.invalid"
|
||||||
|
>
|
||||||
|
Your email is invalid.
|
||||||
|
</small>
|
||||||
|
|
||||||
|
<small
|
||||||
|
class="form-text text-danger"
|
||||||
|
*ngIf="registerForm.get('email')?.errors?.minlength"
|
||||||
|
jhiTranslate="global.messages.validate.email.minlength"
|
||||||
|
>
|
||||||
|
Your email is required to be at least 5 characters.
|
||||||
|
</small>
|
||||||
|
|
||||||
|
<small
|
||||||
|
class="form-text text-danger"
|
||||||
|
*ngIf="registerForm.get('email')?.errors?.maxlength"
|
||||||
|
jhiTranslate="global.messages.validate.email.maxlength"
|
||||||
|
>
|
||||||
|
Your email cannot be longer than 100 characters.
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label jhiTranslate="dataSurveyApp.usuarioExtra.plantilla" for="field_plantillas">Plantilla</label>
|
<label for="password" jhiTranslate="global.form.newpassword.label">Password</label>
|
||||||
<select class="form-control" id="field_plantillas" data-cy="plantilla" multiple name="plantillas" formControlName="plantillas">
|
<input
|
||||||
<option
|
type="password"
|
||||||
[ngValue]="getSelectedPlantilla(plantillaOption, editForm.get('plantillas')!.value)"
|
class="form-control"
|
||||||
*ngFor="let plantillaOption of plantillasSharedCollection; trackBy: trackPlantillaById"
|
id="password"
|
||||||
|
name="password"
|
||||||
|
placeholder="{{ 'global.form.newpassword.placeholder' | translate }}"
|
||||||
|
formControlName="password"
|
||||||
|
data-cy="firstPassword"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
*ngIf="
|
||||||
|
registerForm.get('password')!.invalid && (registerForm.get('password')!.dirty || registerForm.get('password')!.touched)
|
||||||
|
"
|
||||||
>
|
>
|
||||||
{{ plantillaOption.id }}
|
<small
|
||||||
</option>
|
class="form-text text-danger"
|
||||||
</select>
|
*ngIf="registerForm.get('password')?.errors?.required"
|
||||||
|
jhiTranslate="global.messages.validate.newpassword.required"
|
||||||
|
>
|
||||||
|
Your password is required.
|
||||||
|
</small>
|
||||||
|
|
||||||
|
<small
|
||||||
|
class="form-text text-danger"
|
||||||
|
*ngIf="registerForm.get('password')?.errors?.minlength"
|
||||||
|
jhiTranslate="global.messages.validate.newpassword.minlength"
|
||||||
|
>
|
||||||
|
Your password is required to be at least 4 characters.
|
||||||
|
</small>
|
||||||
|
|
||||||
|
<small
|
||||||
|
class="form-text text-danger"
|
||||||
|
*ngIf="registerForm.get('password')?.errors?.maxlength"
|
||||||
|
jhiTranslate="global.messages.validate.newpassword.maxlength"
|
||||||
|
>
|
||||||
|
Your password cannot be longer than 50 characters.
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div class="mb-3">
|
||||||
<button type="button" id="cancel-save" data-cy="entityCreateCancelButton" class="btn btn-secondary" (click)="previousState()">
|
<div class="form-group">
|
||||||
<fa-icon icon="ban"></fa-icon> <span jhiTranslate="entity.action.cancel">Cancel</span>
|
<label for="password" jhiTranslate="global.form.newpassword.label">Password</label>
|
||||||
</button>
|
<input
|
||||||
|
type="password"
|
||||||
|
class="form-control"
|
||||||
|
id="confirmPassword"
|
||||||
|
name="confirmPassword"
|
||||||
|
placeholder="{{ 'global.form.confirmpassword.placeholder' | translate }}"
|
||||||
|
formControlName="confirmPassword"
|
||||||
|
data-cy="secondPassword"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
*ngIf="
|
||||||
|
registerForm.get('confirmPassword')!.invalid &&
|
||||||
|
(registerForm.get('confirmPassword')!.dirty || registerForm.get('confirmPassword')!.touched)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<small
|
||||||
|
class="form-text text-danger"
|
||||||
|
*ngIf="registerForm.get('confirmPassword')?.errors?.required"
|
||||||
|
jhiTranslate="global.messages.validate.confirmpassword.required"
|
||||||
|
>
|
||||||
|
Your confirmation password is required.
|
||||||
|
</small>
|
||||||
|
|
||||||
|
<small
|
||||||
|
class="form-text text-danger"
|
||||||
|
*ngIf="registerForm.get('confirmPassword')?.errors?.minlength"
|
||||||
|
jhiTranslate="global.messages.validate.confirmpassword.minlength"
|
||||||
|
>
|
||||||
|
Your confirmation password is required to be at least 4 characters.
|
||||||
|
</small>
|
||||||
|
|
||||||
|
<small
|
||||||
|
class="form-text text-danger"
|
||||||
|
*ngIf="registerForm.get('confirmPassword')?.errors?.maxlength"
|
||||||
|
jhiTranslate="global.messages.validate.confirmpassword.maxlength"
|
||||||
|
>
|
||||||
|
Your confirmation password cannot be longer than 50 characters.
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="password">Ícono de perfil</label>
|
||||||
|
<jhi-swiper [data]="profileIcons" (onSelectEvent)="selectIcon($event)"></jhi-swiper>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3 mb-0 text-center">
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
id="save-entity"
|
[disabled]="registerForm.invalid"
|
||||||
data-cy="entityCreateSaveButton"
|
class="btn btn-primary w-100"
|
||||||
[disabled]="editForm.invalid || isSaving"
|
jhiTranslate="register.form.button"
|
||||||
class="btn btn-primary"
|
data-cy="submit"
|
||||||
>
|
>
|
||||||
<fa-icon icon="save"></fa-icon> <span jhiTranslate="entity.action.save">Save</span>
|
Register
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,212 +1,144 @@
|
||||||
jest.mock('@angular/router');
|
jest.mock('@ngx-translate/core');
|
||||||
|
|
||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, waitForAsync, inject, tick, fakeAsync } from '@angular/core/testing';
|
||||||
import { HttpResponse } from '@angular/common/http';
|
|
||||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||||
import { FormBuilder } from '@angular/forms';
|
import { FormBuilder } from '@angular/forms';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import { of, throwError } from 'rxjs';
|
||||||
import { of, Subject } from 'rxjs';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
import { UsuarioExtraService } from '../service/usuario-extra.service';
|
import { EMAIL_ALREADY_USED_TYPE, LOGIN_ALREADY_USED_TYPE } from 'app/config/error.constants';
|
||||||
import { IUsuarioExtra, UsuarioExtra } from '../usuario-extra.model';
|
|
||||||
|
|
||||||
import { IUser } from 'app/entities/user/user.model';
|
|
||||||
import { UserService } from 'app/entities/user/user.service';
|
|
||||||
import { IPlantilla } from 'app/entities/plantilla/plantilla.model';
|
|
||||||
import { PlantillaService } from 'app/entities/plantilla/service/plantilla.service';
|
|
||||||
|
|
||||||
|
import { RegisterService } from 'app/account/register/register.service';
|
||||||
import { UsuarioExtraUpdateComponent } from './usuario-extra-update.component';
|
import { UsuarioExtraUpdateComponent } from './usuario-extra-update.component';
|
||||||
|
|
||||||
describe('Component Tests', () => {
|
describe('Component Tests', () => {
|
||||||
describe('UsuarioExtra Management Update Component', () => {
|
describe('RegisterComponent', () => {
|
||||||
let comp: UsuarioExtraUpdateComponent;
|
|
||||||
let fixture: ComponentFixture<UsuarioExtraUpdateComponent>;
|
let fixture: ComponentFixture<UsuarioExtraUpdateComponent>;
|
||||||
let activatedRoute: ActivatedRoute;
|
let comp: UsuarioExtraUpdateComponent;
|
||||||
let usuarioExtraService: UsuarioExtraService;
|
|
||||||
let userService: UserService;
|
|
||||||
let plantillaService: PlantillaService;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(
|
||||||
|
waitForAsync(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [HttpClientTestingModule],
|
imports: [HttpClientTestingModule],
|
||||||
declarations: [UsuarioExtraUpdateComponent],
|
declarations: [UsuarioExtraUpdateComponent],
|
||||||
providers: [FormBuilder, ActivatedRoute],
|
providers: [FormBuilder, TranslateService],
|
||||||
})
|
})
|
||||||
.overrideTemplate(UsuarioExtraUpdateComponent, '')
|
.overrideTemplate(UsuarioExtraUpdateComponent, '')
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(UsuarioExtraUpdateComponent);
|
fixture = TestBed.createComponent(UsuarioExtraUpdateComponent);
|
||||||
activatedRoute = TestBed.inject(ActivatedRoute);
|
|
||||||
usuarioExtraService = TestBed.inject(UsuarioExtraService);
|
|
||||||
userService = TestBed.inject(UserService);
|
|
||||||
plantillaService = TestBed.inject(PlantillaService);
|
|
||||||
|
|
||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ngOnInit', () => {
|
it('should ensure the two passwords entered match', () => {
|
||||||
it('Should call User query and add missing value', () => {
|
comp.registerForm.patchValue({
|
||||||
const usuarioExtra: IUsuarioExtra = { id: 456 };
|
password: 'password',
|
||||||
const user: IUser = { id: 58280 };
|
confirmPassword: 'non-matching',
|
||||||
usuarioExtra.user = user;
|
|
||||||
|
|
||||||
const userCollection: IUser[] = [{ id: 29686 }];
|
|
||||||
jest.spyOn(userService, 'query').mockReturnValue(of(new HttpResponse({ body: userCollection })));
|
|
||||||
const additionalUsers = [user];
|
|
||||||
const expectedCollection: IUser[] = [...additionalUsers, ...userCollection];
|
|
||||||
jest.spyOn(userService, 'addUserToCollectionIfMissing').mockReturnValue(expectedCollection);
|
|
||||||
|
|
||||||
activatedRoute.data = of({ usuarioExtra });
|
|
||||||
comp.ngOnInit();
|
|
||||||
|
|
||||||
expect(userService.query).toHaveBeenCalled();
|
|
||||||
expect(userService.addUserToCollectionIfMissing).toHaveBeenCalledWith(userCollection, ...additionalUsers);
|
|
||||||
expect(comp.usersSharedCollection).toEqual(expectedCollection);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should call Plantilla query and add missing value', () => {
|
comp.register();
|
||||||
const usuarioExtra: IUsuarioExtra = { id: 456 };
|
|
||||||
const plantillas: IPlantilla[] = [{ id: 54411 }];
|
|
||||||
usuarioExtra.plantillas = plantillas;
|
|
||||||
|
|
||||||
const plantillaCollection: IPlantilla[] = [{ id: 32212 }];
|
expect(comp.doNotMatch).toBe(true);
|
||||||
jest.spyOn(plantillaService, 'query').mockReturnValue(of(new HttpResponse({ body: plantillaCollection })));
|
|
||||||
const additionalPlantillas = [...plantillas];
|
|
||||||
const expectedCollection: IPlantilla[] = [...additionalPlantillas, ...plantillaCollection];
|
|
||||||
jest.spyOn(plantillaService, 'addPlantillaToCollectionIfMissing').mockReturnValue(expectedCollection);
|
|
||||||
|
|
||||||
activatedRoute.data = of({ usuarioExtra });
|
|
||||||
comp.ngOnInit();
|
|
||||||
|
|
||||||
expect(plantillaService.query).toHaveBeenCalled();
|
|
||||||
expect(plantillaService.addPlantillaToCollectionIfMissing).toHaveBeenCalledWith(plantillaCollection, ...additionalPlantillas);
|
|
||||||
expect(comp.plantillasSharedCollection).toEqual(expectedCollection);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should update editForm', () => {
|
it('should update success to true after creating an account', inject(
|
||||||
const usuarioExtra: IUsuarioExtra = { id: 456 };
|
[RegisterService, TranslateService],
|
||||||
const user: IUser = { id: 30429 };
|
fakeAsync((service: RegisterService, mockLanguageService: TranslateService) => {
|
||||||
usuarioExtra.user = user;
|
jest.spyOn(service, 'save').mockReturnValue(of({}));
|
||||||
const plantillas: IPlantilla = { id: 61011 };
|
mockLanguageService.currentLang = 'es';
|
||||||
usuarioExtra.plantillas = [plantillas];
|
comp.registerForm.patchValue({
|
||||||
|
password: 'password',
|
||||||
activatedRoute.data = of({ usuarioExtra });
|
confirmPassword: 'password',
|
||||||
comp.ngOnInit();
|
|
||||||
|
|
||||||
expect(comp.editForm.value).toEqual(expect.objectContaining(usuarioExtra));
|
|
||||||
expect(comp.usersSharedCollection).toContain(user);
|
|
||||||
expect(comp.plantillasSharedCollection).toContain(plantillas);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('save', () => {
|
comp.register();
|
||||||
it('Should call update service on save for existing entity', () => {
|
tick();
|
||||||
// GIVEN
|
|
||||||
const saveSubject = new Subject<HttpResponse<UsuarioExtra>>();
|
|
||||||
const usuarioExtra = { id: 123 };
|
|
||||||
jest.spyOn(usuarioExtraService, 'update').mockReturnValue(saveSubject);
|
|
||||||
jest.spyOn(comp, 'previousState');
|
|
||||||
activatedRoute.data = of({ usuarioExtra });
|
|
||||||
comp.ngOnInit();
|
|
||||||
|
|
||||||
// WHEN
|
expect(service.save).toHaveBeenCalledWith({
|
||||||
comp.save();
|
email: '',
|
||||||
expect(comp.isSaving).toEqual(true);
|
password: 'password',
|
||||||
saveSubject.next(new HttpResponse({ body: usuarioExtra }));
|
login: '',
|
||||||
saveSubject.complete();
|
langKey: 'es',
|
||||||
|
name: '',
|
||||||
|
profileIcon: 1,
|
||||||
|
isAdmin: 1,
|
||||||
|
});
|
||||||
|
expect(comp.success).toBe(true);
|
||||||
|
expect(comp.errorUserExists).toBe(false);
|
||||||
|
expect(comp.errorEmailExists).toBe(false);
|
||||||
|
expect(comp.error).toBe(false);
|
||||||
|
})
|
||||||
|
));
|
||||||
|
|
||||||
// THEN
|
it('should notify of user existence upon 400/login already in use', inject(
|
||||||
expect(comp.previousState).toHaveBeenCalled();
|
[RegisterService],
|
||||||
expect(usuarioExtraService.update).toHaveBeenCalledWith(usuarioExtra);
|
fakeAsync((service: RegisterService) => {
|
||||||
expect(comp.isSaving).toEqual(false);
|
jest.spyOn(service, 'save').mockReturnValue(
|
||||||
|
throwError({
|
||||||
|
status: 400,
|
||||||
|
error: { type: LOGIN_ALREADY_USED_TYPE },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
comp.registerForm.patchValue({
|
||||||
|
password: 'password',
|
||||||
|
confirmPassword: 'password',
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should call create service on save for new entity', () => {
|
comp.register();
|
||||||
// GIVEN
|
tick();
|
||||||
const saveSubject = new Subject<HttpResponse<UsuarioExtra>>();
|
|
||||||
const usuarioExtra = new UsuarioExtra();
|
|
||||||
jest.spyOn(usuarioExtraService, 'create').mockReturnValue(saveSubject);
|
|
||||||
jest.spyOn(comp, 'previousState');
|
|
||||||
activatedRoute.data = of({ usuarioExtra });
|
|
||||||
comp.ngOnInit();
|
|
||||||
|
|
||||||
// WHEN
|
expect(comp.errorUserExists).toBe(true);
|
||||||
comp.save();
|
expect(comp.errorEmailExists).toBe(false);
|
||||||
expect(comp.isSaving).toEqual(true);
|
expect(comp.error).toBe(false);
|
||||||
saveSubject.next(new HttpResponse({ body: usuarioExtra }));
|
})
|
||||||
saveSubject.complete();
|
));
|
||||||
|
|
||||||
// THEN
|
it('should notify of email existence upon 400/email address already in use', inject(
|
||||||
expect(usuarioExtraService.create).toHaveBeenCalledWith(usuarioExtra);
|
[RegisterService],
|
||||||
expect(comp.isSaving).toEqual(false);
|
fakeAsync((service: RegisterService) => {
|
||||||
expect(comp.previousState).toHaveBeenCalled();
|
jest.spyOn(service, 'save').mockReturnValue(
|
||||||
|
throwError({
|
||||||
|
status: 400,
|
||||||
|
error: { type: EMAIL_ALREADY_USED_TYPE },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
comp.registerForm.patchValue({
|
||||||
|
password: 'password',
|
||||||
|
confirmPassword: 'password',
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should set isSaving to false on error', () => {
|
comp.register();
|
||||||
// GIVEN
|
tick();
|
||||||
const saveSubject = new Subject<HttpResponse<UsuarioExtra>>();
|
|
||||||
const usuarioExtra = { id: 123 };
|
|
||||||
jest.spyOn(usuarioExtraService, 'update').mockReturnValue(saveSubject);
|
|
||||||
jest.spyOn(comp, 'previousState');
|
|
||||||
activatedRoute.data = of({ usuarioExtra });
|
|
||||||
comp.ngOnInit();
|
|
||||||
|
|
||||||
// WHEN
|
expect(comp.errorEmailExists).toBe(true);
|
||||||
comp.save();
|
expect(comp.errorUserExists).toBe(false);
|
||||||
expect(comp.isSaving).toEqual(true);
|
expect(comp.error).toBe(false);
|
||||||
saveSubject.error('This is an error!');
|
})
|
||||||
|
));
|
||||||
|
|
||||||
// THEN
|
it('should notify of generic error', inject(
|
||||||
expect(usuarioExtraService.update).toHaveBeenCalledWith(usuarioExtra);
|
[RegisterService],
|
||||||
expect(comp.isSaving).toEqual(false);
|
fakeAsync((service: RegisterService) => {
|
||||||
expect(comp.previousState).not.toHaveBeenCalled();
|
jest.spyOn(service, 'save').mockReturnValue(
|
||||||
});
|
throwError({
|
||||||
|
status: 503,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
comp.registerForm.patchValue({
|
||||||
|
password: 'password',
|
||||||
|
confirmPassword: 'password',
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Tracking relationships identifiers', () => {
|
comp.register();
|
||||||
describe('trackUserById', () => {
|
tick();
|
||||||
it('Should return tracked User primary key', () => {
|
|
||||||
const entity = { id: 123 };
|
|
||||||
const trackResult = comp.trackUserById(0, entity);
|
|
||||||
expect(trackResult).toEqual(entity.id);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('trackPlantillaById', () => {
|
expect(comp.errorUserExists).toBe(false);
|
||||||
it('Should return tracked Plantilla primary key', () => {
|
expect(comp.errorEmailExists).toBe(false);
|
||||||
const entity = { id: 123 };
|
expect(comp.error).toBe(true);
|
||||||
const trackResult = comp.trackPlantillaById(0, entity);
|
})
|
||||||
expect(trackResult).toEqual(entity.id);
|
));
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Getting selected relationships', () => {
|
|
||||||
describe('getSelectedPlantilla', () => {
|
|
||||||
it('Should return option if no Plantilla is selected', () => {
|
|
||||||
const option = { id: 123 };
|
|
||||||
const result = comp.getSelectedPlantilla(option);
|
|
||||||
expect(result === option).toEqual(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should return selected Plantilla for according option', () => {
|
|
||||||
const option = { id: 123 };
|
|
||||||
const selected = { id: 123 };
|
|
||||||
const selected2 = { id: 456 };
|
|
||||||
const result = comp.getSelectedPlantilla(option, [selected2, selected]);
|
|
||||||
expect(result === selected).toEqual(true);
|
|
||||||
expect(result === selected2).toEqual(false);
|
|
||||||
expect(result === option).toEqual(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Should return option if this Plantilla is not selected', () => {
|
|
||||||
const option = { id: 123 };
|
|
||||||
const selected = { id: 456 };
|
|
||||||
const result = comp.getSelectedPlantilla(option, [selected]);
|
|
||||||
expect(result === option).toEqual(true);
|
|
||||||
expect(result === selected).toEqual(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,161 +1,121 @@
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { HttpResponse } from '@angular/common/http';
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
import { FormBuilder, Validators } from '@angular/forms';
|
import { FormBuilder, Validators } from '@angular/forms';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { Observable } from 'rxjs';
|
|
||||||
import { finalize, map } from 'rxjs/operators';
|
|
||||||
|
|
||||||
import * as dayjs from 'dayjs';
|
import { EMAIL_ALREADY_USED_TYPE, LOGIN_ALREADY_USED_TYPE } from 'app/config/error.constants';
|
||||||
import { DATE_TIME_FORMAT } from 'app/config/input.constants';
|
import { RegisterService } from 'app/account/register/register.service';
|
||||||
|
|
||||||
import { IUsuarioExtra, UsuarioExtra } from '../usuario-extra.model';
|
|
||||||
import { UsuarioExtraService } from '../service/usuario-extra.service';
|
|
||||||
import { IUser } from 'app/entities/user/user.model';
|
|
||||||
import { UserService } from 'app/entities/user/user.service';
|
|
||||||
import { IPlantilla } from 'app/entities/plantilla/plantilla.model';
|
|
||||||
import { PlantillaService } from 'app/entities/plantilla/service/plantilla.service';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'jhi-usuario-extra-update',
|
selector: 'jhi-usuario-extra-update',
|
||||||
templateUrl: './usuario-extra-update.component.html',
|
templateUrl: './usuario-extra-update.component.html',
|
||||||
})
|
})
|
||||||
export class UsuarioExtraUpdateComponent implements OnInit {
|
export class UsuarioExtraUpdateComponent {
|
||||||
isSaving = false;
|
// @ViewChild('name', { static: false })
|
||||||
|
// name?: ElementRef;
|
||||||
|
|
||||||
usersSharedCollection: IUser[] = [];
|
profileIcon: number = 1;
|
||||||
plantillasSharedCollection: IPlantilla[] = [];
|
profileIcons: any[] = [
|
||||||
|
{ name: 'C1', class: 'active' },
|
||||||
|
{ name: 'C2' },
|
||||||
|
{ name: 'C3' },
|
||||||
|
{ name: 'C4' },
|
||||||
|
{ name: 'C5' },
|
||||||
|
{ name: 'C6' },
|
||||||
|
{ name: 'C7' },
|
||||||
|
{ name: 'C8' },
|
||||||
|
{ name: 'C9' },
|
||||||
|
{ name: 'C10' },
|
||||||
|
{ name: 'C11' },
|
||||||
|
{ name: 'C12' },
|
||||||
|
{ name: 'C13' },
|
||||||
|
{ name: 'C14' },
|
||||||
|
{ name: 'C15' },
|
||||||
|
{ name: 'C16' },
|
||||||
|
{ name: 'C17' },
|
||||||
|
{ name: 'C18' },
|
||||||
|
{ name: 'C19' },
|
||||||
|
{ name: 'C20' },
|
||||||
|
{ name: 'C21' },
|
||||||
|
{ name: 'C22' },
|
||||||
|
{ name: 'C23' },
|
||||||
|
{ name: 'C24' },
|
||||||
|
{ name: 'C25' },
|
||||||
|
{ name: 'C26' },
|
||||||
|
{ name: 'C27' },
|
||||||
|
{ name: 'C28' },
|
||||||
|
];
|
||||||
|
|
||||||
editForm = this.fb.group({
|
doNotMatch = false;
|
||||||
id: [],
|
error = false;
|
||||||
nombre: [null, [Validators.required]],
|
errorEmailExists = false;
|
||||||
iconoPerfil: [],
|
errorUserExists = false;
|
||||||
fechaNacimiento: [],
|
success = false;
|
||||||
estado: [null, [Validators.required]],
|
|
||||||
user: [],
|
// Login will be used to store the email as well.
|
||||||
plantillas: [],
|
// login: ['', [Validators.required, Validators.minLength(5), Validators.maxLength(254), Validators.email]]
|
||||||
|
registerForm = this.fb.group({
|
||||||
|
name: ['', [Validators.required, Validators.minLength(2), Validators.maxLength(254)]],
|
||||||
|
email: ['', [Validators.required, Validators.minLength(5), Validators.maxLength(254), Validators.email]],
|
||||||
|
password: ['', [Validators.required, Validators.minLength(4), Validators.maxLength(50)]],
|
||||||
|
confirmPassword: ['', [Validators.required, Validators.minLength(4), Validators.maxLength(50)]],
|
||||||
});
|
});
|
||||||
|
|
||||||
constructor(
|
constructor(private translateService: TranslateService, private registerService: RegisterService, private fb: FormBuilder) {}
|
||||||
protected usuarioExtraService: UsuarioExtraService,
|
|
||||||
protected userService: UserService,
|
|
||||||
protected plantillaService: PlantillaService,
|
|
||||||
protected activatedRoute: ActivatedRoute,
|
|
||||||
protected fb: FormBuilder
|
|
||||||
) {}
|
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngAfterViewInit(): void {
|
||||||
this.activatedRoute.data.subscribe(({ usuarioExtra }) => {
|
// if (this.name) {
|
||||||
if (usuarioExtra.id === undefined) {
|
// this.name.nativeElement.focus();
|
||||||
const today = dayjs().startOf('day');
|
// }
|
||||||
usuarioExtra.fechaNacimiento = today;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateForm(usuarioExtra);
|
register(): void {
|
||||||
|
this.doNotMatch = false;
|
||||||
|
this.error = false;
|
||||||
|
this.errorEmailExists = false;
|
||||||
|
this.errorUserExists = false;
|
||||||
|
|
||||||
this.loadRelationshipsOptions();
|
const password = this.registerForm.get(['password'])!.value;
|
||||||
});
|
if (password !== this.registerForm.get(['confirmPassword'])!.value) {
|
||||||
}
|
this.doNotMatch = true;
|
||||||
|
|
||||||
previousState(): void {
|
|
||||||
window.history.back();
|
|
||||||
}
|
|
||||||
|
|
||||||
save(): void {
|
|
||||||
this.isSaving = true;
|
|
||||||
const usuarioExtra = this.createFromForm();
|
|
||||||
if (usuarioExtra.id !== undefined) {
|
|
||||||
this.subscribeToSaveResponse(this.usuarioExtraService.update(usuarioExtra));
|
|
||||||
} else {
|
} else {
|
||||||
this.subscribeToSaveResponse(this.usuarioExtraService.create(usuarioExtra));
|
const login = this.registerForm.get(['email'])!.value;
|
||||||
}
|
const email = this.registerForm.get(['email'])!.value;
|
||||||
}
|
const name = this.registerForm.get(['name'])!.value;
|
||||||
|
console.log(name);
|
||||||
|
|
||||||
trackUserById(index: number, item: IUser): number {
|
this.registerService
|
||||||
return item.id!;
|
.save({
|
||||||
}
|
login,
|
||||||
|
email,
|
||||||
trackPlantillaById(index: number, item: IPlantilla): number {
|
password,
|
||||||
return item.id!;
|
langKey: this.translateService.currentLang,
|
||||||
}
|
name,
|
||||||
|
profileIcon: this.profileIcon,
|
||||||
getSelectedPlantilla(option: IPlantilla, selectedVals?: IPlantilla[]): IPlantilla {
|
isAdmin: 1,
|
||||||
if (selectedVals) {
|
})
|
||||||
for (const selectedVal of selectedVals) {
|
.subscribe(
|
||||||
if (option.id === selectedVal.id) {
|
() => (this.success = true),
|
||||||
return selectedVal;
|
response => this.processError(response)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return option;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected subscribeToSaveResponse(result: Observable<HttpResponse<IUsuarioExtra>>): void {
|
|
||||||
result.pipe(finalize(() => this.onSaveFinalize())).subscribe(
|
|
||||||
() => this.onSaveSuccess(),
|
|
||||||
() => this.onSaveError()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onSaveSuccess(): void {
|
|
||||||
this.previousState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onSaveError(): void {
|
private processError(response: HttpErrorResponse): void {
|
||||||
// Api for inheritance.
|
if (response.status === 400 && response.error.type === LOGIN_ALREADY_USED_TYPE) {
|
||||||
|
this.errorUserExists = true;
|
||||||
|
} else if (response.status === 400 && response.error.type === EMAIL_ALREADY_USED_TYPE) {
|
||||||
|
this.errorEmailExists = true;
|
||||||
|
} else {
|
||||||
|
this.error = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onSaveFinalize(): void {
|
selectIcon(event: MouseEvent): void {
|
||||||
this.isSaving = false;
|
if (event.target instanceof Element) {
|
||||||
|
document.querySelectorAll('.active').forEach(e => e.classList.remove('active'));
|
||||||
|
event.target.classList.add('active');
|
||||||
|
this.profileIcon = +event.target.getAttribute('id')! + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updateForm(usuarioExtra: IUsuarioExtra): void {
|
|
||||||
this.editForm.patchValue({
|
|
||||||
id: usuarioExtra.id,
|
|
||||||
nombre: usuarioExtra.nombre,
|
|
||||||
iconoPerfil: usuarioExtra.iconoPerfil,
|
|
||||||
fechaNacimiento: usuarioExtra.fechaNacimiento ? usuarioExtra.fechaNacimiento.format(DATE_TIME_FORMAT) : null,
|
|
||||||
estado: usuarioExtra.estado,
|
|
||||||
user: usuarioExtra.user,
|
|
||||||
plantillas: usuarioExtra.plantillas,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.usersSharedCollection = this.userService.addUserToCollectionIfMissing(this.usersSharedCollection, usuarioExtra.user);
|
|
||||||
this.plantillasSharedCollection = this.plantillaService.addPlantillaToCollectionIfMissing(
|
|
||||||
this.plantillasSharedCollection,
|
|
||||||
...(usuarioExtra.plantillas ?? [])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected loadRelationshipsOptions(): void {
|
|
||||||
this.userService
|
|
||||||
.query()
|
|
||||||
.pipe(map((res: HttpResponse<IUser[]>) => res.body ?? []))
|
|
||||||
.pipe(map((users: IUser[]) => this.userService.addUserToCollectionIfMissing(users, this.editForm.get('user')!.value)))
|
|
||||||
.subscribe((users: IUser[]) => (this.usersSharedCollection = users));
|
|
||||||
|
|
||||||
this.plantillaService
|
|
||||||
.query()
|
|
||||||
.pipe(map((res: HttpResponse<IPlantilla[]>) => res.body ?? []))
|
|
||||||
.pipe(
|
|
||||||
map((plantillas: IPlantilla[]) =>
|
|
||||||
this.plantillaService.addPlantillaToCollectionIfMissing(plantillas, ...(this.editForm.get('plantillas')!.value ?? []))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.subscribe((plantillas: IPlantilla[]) => (this.plantillasSharedCollection = plantillas));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected createFromForm(): IUsuarioExtra {
|
|
||||||
return {
|
|
||||||
...new UsuarioExtra(),
|
|
||||||
id: this.editForm.get(['id'])!.value,
|
|
||||||
nombre: this.editForm.get(['nombre'])!.value,
|
|
||||||
iconoPerfil: this.editForm.get(['iconoPerfil'])!.value,
|
|
||||||
fechaNacimiento: this.editForm.get(['fechaNacimiento'])!.value
|
|
||||||
? dayjs(this.editForm.get(['fechaNacimiento'])!.value, DATE_TIME_FORMAT)
|
|
||||||
: undefined,
|
|
||||||
estado: this.editForm.get(['estado'])!.value,
|
|
||||||
user: this.editForm.get(['user'])!.value,
|
|
||||||
plantillas: this.editForm.get(['plantillas'])!.value,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,10 @@ import { UsuarioExtraDetailComponent } from './detail/usuario-extra-detail.compo
|
||||||
import { UsuarioExtraUpdateComponent } from './update/usuario-extra-update.component';
|
import { UsuarioExtraUpdateComponent } from './update/usuario-extra-update.component';
|
||||||
import { UsuarioExtraDeleteDialogComponent } from './delete/usuario-extra-delete-dialog.component';
|
import { UsuarioExtraDeleteDialogComponent } from './delete/usuario-extra-delete-dialog.component';
|
||||||
import { UsuarioExtraRoutingModule } from './route/usuario-extra-routing.module';
|
import { UsuarioExtraRoutingModule } from './route/usuario-extra-routing.module';
|
||||||
|
import { ComponentsModule } from 'app/components/components.module';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [SharedModule, UsuarioExtraRoutingModule],
|
imports: [SharedModule, UsuarioExtraRoutingModule, ComponentsModule],
|
||||||
declarations: [UsuarioExtraComponent, UsuarioExtraDetailComponent, UsuarioExtraUpdateComponent, UsuarioExtraDeleteDialogComponent],
|
declarations: [UsuarioExtraComponent, UsuarioExtraDetailComponent, UsuarioExtraUpdateComponent, UsuarioExtraDeleteDialogComponent],
|
||||||
entryComponents: [UsuarioExtraDeleteDialogComponent],
|
entryComponents: [UsuarioExtraDeleteDialogComponent],
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,7 +8,8 @@ import { SocialAuthService, SocialUser } from 'angularx-social-login';
|
||||||
import { GoogleLoginProvider } from 'angularx-social-login';
|
import { GoogleLoginProvider } from 'angularx-social-login';
|
||||||
import { RegisterService } from '../account/register/register.service';
|
import { RegisterService } from '../account/register/register.service';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { RegisterComponent } from '../account/register/register.component';
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
|
import { EMAIL_ALREADY_USED_TYPE, LOGIN_ALREADY_USED_TYPE } from '../config/error.constants';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'jhi-login',
|
selector: 'jhi-login',
|
||||||
|
@ -20,6 +21,9 @@ export class LoginComponent implements OnInit, AfterViewInit {
|
||||||
username!: ElementRef;
|
username!: ElementRef;
|
||||||
|
|
||||||
authenticationError = false;
|
authenticationError = false;
|
||||||
|
error = false;
|
||||||
|
errorEmailExists = false;
|
||||||
|
errorUserExists = false;
|
||||||
|
|
||||||
loginForm = this.fb.group({
|
loginForm = this.fb.group({
|
||||||
username: [null, [Validators.required]],
|
username: [null, [Validators.required]],
|
||||||
|
@ -38,8 +42,7 @@ export class LoginComponent implements OnInit, AfterViewInit {
|
||||||
private fb: FormBuilder,
|
private fb: FormBuilder,
|
||||||
private authService: SocialAuthService,
|
private authService: SocialAuthService,
|
||||||
private registerService: RegisterService,
|
private registerService: RegisterService,
|
||||||
private translateService: TranslateService,
|
private translateService: TranslateService
|
||||||
private registerAuth: RegisterComponent
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
@ -94,7 +97,7 @@ export class LoginComponent implements OnInit, AfterViewInit {
|
||||||
})
|
})
|
||||||
.subscribe(
|
.subscribe(
|
||||||
() => (this.success = true),
|
() => (this.success = true),
|
||||||
response => this.registerAuth.processError(response)
|
response => this.processError(response)
|
||||||
) //console.log("Numero random: " + this.randomProfilePic())
|
) //console.log("Numero random: " + this.randomProfilePic())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -103,6 +106,16 @@ export class LoginComponent implements OnInit, AfterViewInit {
|
||||||
return Math.floor(Math.random() * (28 - 1 + 1)) + 1;
|
return Math.floor(Math.random() * (28 - 1 + 1)) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processError(response: HttpErrorResponse): void {
|
||||||
|
if (response.status === 400 && response.error.type === LOGIN_ALREADY_USED_TYPE) {
|
||||||
|
this.errorUserExists = true;
|
||||||
|
} else if (response.status === 400 && response.error.type === EMAIL_ALREADY_USED_TYPE) {
|
||||||
|
this.errorEmailExists = true;
|
||||||
|
} else {
|
||||||
|
this.error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
refreshToken(): void {
|
refreshToken(): void {
|
||||||
this.authService.refreshAuthToken(GoogleLoginProvider.PROVIDER_ID);
|
this.authService.refreshAuthToken(GoogleLoginProvider.PROVIDER_ID);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,20 +2,20 @@
|
||||||
"dataSurveyApp": {
|
"dataSurveyApp": {
|
||||||
"categoria": {
|
"categoria": {
|
||||||
"home": {
|
"home": {
|
||||||
"title": "Categorias",
|
"title": "Categorías",
|
||||||
"refreshListLabel": "Refrescar lista",
|
"refreshListLabel": "Refrescar lista",
|
||||||
"createLabel": "Crear nuevo Categoria",
|
"createLabel": "Crear nueva Categoría",
|
||||||
"createOrEditLabel": "Crear o editar Categoria",
|
"createOrEditLabel": "Crear o editar Categoría",
|
||||||
"notFound": "Ningún Categorias encontrado"
|
"notFound": "Ninguna Categoría encontrada"
|
||||||
},
|
},
|
||||||
"created": "Un nuevo Categoria ha sido creado con el identificador {{ param }}",
|
"created": "Una nueva Categoría ha sido creada con el identificador {{ param }}",
|
||||||
"updated": "Un Categoria ha sido actualizado con el identificador {{ param }}",
|
"updated": "Una Categoría ha sido actualizado con el identificador {{ param }}",
|
||||||
"deleted": "Un Categoria ha sido eliminado con el identificador {{ param }}",
|
"deleted": "Una Categoría ha sido eliminado con el identificador {{ param }}",
|
||||||
"delete": {
|
"delete": {
|
||||||
"question": "¿Seguro que quiere eliminar Categoria {{ id }}?"
|
"question": "¿Seguro que quiere eliminar Categoría {{ id }}?"
|
||||||
},
|
},
|
||||||
"detail": {
|
"detail": {
|
||||||
"title": "Categoria"
|
"title": "Categoría"
|
||||||
},
|
},
|
||||||
"id": "ID",
|
"id": "ID",
|
||||||
"nombre": "Nombre",
|
"nombre": "Nombre",
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
"dataSurveyApp": {
|
"dataSurveyApp": {
|
||||||
"EstadoCategoria": {
|
"EstadoCategoria": {
|
||||||
"null": "",
|
"null": "",
|
||||||
"ACTIVE": "ACTIVE",
|
"ACTIVE": "ACTIVA",
|
||||||
"INACTIVE": "INACTIVE"
|
"INACTIVE": "INACTIVA"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"success": "<strong>¡Registro guardado!</strong> Por favor, revise su correo electrónico para confirmar.",
|
"success": "<strong>¡Registro guardado!</strong> Por favor, revise su correo electrónico para confirmar.",
|
||||||
|
"adminsuccess": "<strong>¡Registro guardado!</strong> Por favor, revise el correo electrónico para confirmar.",
|
||||||
"error": {
|
"error": {
|
||||||
"fail": "<strong>¡El registro ha fallado!</strong> Por favor, inténtelo de nuevo más tarde.",
|
"fail": "<strong>¡El registro ha fallado!</strong> Por favor, inténtelo de nuevo más tarde.",
|
||||||
"userexists": "<strong>¡El nombre de usuario ya está registrado!</strong> Por favor, escoja otro usuario.",
|
"userexists": "<strong>¡El nombre de usuario ya está registrado!</strong> Por favor, escoja otro usuario.",
|
||||||
|
|
Loading…
Reference in New Issue