Update retrieve data from usuario extra to display on profile
This commit is contained in:
parent
34597f8209
commit
f5c2f626df
|
@ -163,7 +163,9 @@
|
|||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
-------------------------------------------------------------------------------
|
||||
-->
|
||||
|
||||
<div>
|
||||
<div class="row justify-content-center">
|
||||
|
@ -178,263 +180,184 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg ml-lg-5 mr-lg-5 pr-lg-5">
|
||||
|
||||
<div class="col-lg ml-lg-5 mr-lg-5 pr-lg-5" name="editForm" role="form" novalidate (ngSubmit)="save()" [formGroup]="editForm">
|
||||
<div class="row">
|
||||
<div class="form-group w-100">
|
||||
<label class="form-control-label" for="email" jhiTranslate="global.form.email.label">Email</label>
|
||||
<label class="form-control-label" for="field_email">Correo electrónico</label>
|
||||
<input
|
||||
type="email"
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="email"
|
||||
name="email"
|
||||
placeholder="{{ 'global.form.email.placeholder' | translate }}"
|
||||
formControlName="email"
|
||||
id="field_email"
|
||||
data-cy="email"
|
||||
formControlName="email"
|
||||
[readonly]="true"
|
||||
/>
|
||||
|
||||
<div *ngIf="settingsForm.get('email')!.invalid && (settingsForm.get('email')!.dirty || settingsForm.get('email')!.touched)">
|
||||
<div *ngIf="editForm.get('email')!.invalid && (editForm.get('email')!.dirty || editForm.get('email')!.touched)">
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.get('email')?.errors?.required"
|
||||
jhiTranslate="global.messages.validate.email.required"
|
||||
*ngIf="editForm.get('email')?.errors?.required"
|
||||
jhiTranslate="entity.validation.required"
|
||||
>
|
||||
Your email is required.
|
||||
</small>
|
||||
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.get('email')?.errors?.email"
|
||||
jhiTranslate="global.messages.validate.email.invalid"
|
||||
>
|
||||
Your email is invalid.
|
||||
</small>
|
||||
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.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="settingsForm.get('email')?.errors?.maxlength"
|
||||
jhiTranslate="global.messages.validate.email.maxlength"
|
||||
>
|
||||
Your email cannot be longer than 100 characters.
|
||||
This field is required.
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group w-100">
|
||||
<label class="form-control-label" for="firstName" jhiTranslate="settings.form.firstname">First Name</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="firstName"
|
||||
name="firstName"
|
||||
placeholder="{{ 'settings.form.firstname.placeholder' | translate }}"
|
||||
formControlName="firstName"
|
||||
data-cy="firstname"
|
||||
/>
|
||||
|
||||
<div
|
||||
*ngIf="
|
||||
settingsForm.get('firstName')!.invalid && (settingsForm.get('firstName')!.dirty || settingsForm.get('firstName')!.touched)
|
||||
"
|
||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.nombre" for="field_nombre">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>
|
||||
<div class="row">
|
||||
<div class="form-group w-100">
|
||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.fechaNacimiento" for="field_fechaNacimiento"
|
||||
>Fecha de nacimiento</label
|
||||
>
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.get('firstName')?.errors?.required"
|
||||
jhiTranslate="settings.messages.validate.firstname.required"
|
||||
>
|
||||
Your first name is required.
|
||||
</small>
|
||||
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.get('firstName')?.errors?.minlength"
|
||||
jhiTranslate="settings.messages.validate.firstname.minlength"
|
||||
>
|
||||
Your first name is required to be at least 1 character.
|
||||
</small>
|
||||
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.get('firstName')?.errors?.maxlength"
|
||||
jhiTranslate="settings.messages.validate.firstname.maxlength"
|
||||
>
|
||||
Your first name cannot be longer than 50 characters.
|
||||
</small>
|
||||
<div class="d-flex">
|
||||
<input
|
||||
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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- <div class="col-md-8">
|
||||
<h2 jhiTranslate="settings.title" [translateValues]="{ username: account.login }" *ngIf="account">
|
||||
User settings for [<strong>{{ account.login }}</strong
|
||||
>]
|
||||
<!-- <div class="row justify-content-center">
|
||||
<div class="col-8">
|
||||
<form name="editForm" role="form" novalidate (ngSubmit)="save()" [formGroup]="editForm">
|
||||
<h2
|
||||
id="jhi-usuario-extra-heading"
|
||||
data-cy="UsuarioExtraCreateUpdateHeading"
|
||||
jhiTranslate="dataSurveyApp.usuarioExtra.home.createOrEditLabel"
|
||||
>
|
||||
Create or edit a Usuario Extra
|
||||
</h2>
|
||||
|
||||
<div class="alert alert-success" *ngIf="success" jhiTranslate="settings.messages.success">
|
||||
<strong>Settings saved!</strong>
|
||||
</div>
|
||||
<div>
|
||||
<jhi-alert-error></jhi-alert-error>
|
||||
|
||||
<jhi-alert-error></jhi-alert-error>
|
||||
<div class="form-group" [hidden]="editForm.get('id')!.value == null">
|
||||
<label class="form-control-label" jhiTranslate="global.field.id" for="field_id">ID</label>
|
||||
<input type="number" class="form-control" name="id" id="field_id" data-cy="id" formControlName="id" [readonly]="true" />
|
||||
</div>
|
||||
|
||||
<form name="form" role="form" (ngSubmit)="save()" [formGroup]="settingsForm" *ngIf="account" novalidate>
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="firstName" jhiTranslate="settings.form.firstname">First Name</label>
|
||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.nombre" for="field_nombre">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
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="firstName"
|
||||
name="firstName"
|
||||
placeholder="{{ 'settings.form.firstname.placeholder' | translate }}"
|
||||
formControlName="firstName"
|
||||
data-cy="firstname"
|
||||
name="iconoPerfil"
|
||||
id="field_iconoPerfil"
|
||||
data-cy="iconoPerfil"
|
||||
formControlName="iconoPerfil"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div
|
||||
*ngIf="
|
||||
settingsForm.get('firstName')!.invalid && (settingsForm.get('firstName')!.dirty || settingsForm.get('firstName')!.touched)
|
||||
"
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.fechaNacimiento" for="field_fechaNacimiento"
|
||||
>Fecha Nacimiento</label
|
||||
>
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.get('firstName')?.errors?.required"
|
||||
jhiTranslate="settings.messages.validate.firstname.required"
|
||||
>
|
||||
Your first name is required.
|
||||
</small>
|
||||
<div class="d-flex">
|
||||
<input
|
||||
id="field_fechaNacimiento"
|
||||
data-cy="fechaNacimiento"
|
||||
type="datetime-local"
|
||||
class="form-control"
|
||||
name="fechaNacimiento"
|
||||
formControlName="fechaNacimiento"
|
||||
placeholder="YYYY-MM-DD HH:mm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.get('firstName')?.errors?.minlength"
|
||||
jhiTranslate="settings.messages.validate.firstname.minlength"
|
||||
>
|
||||
Your first name is required to be at least 1 character.
|
||||
</small>
|
||||
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.get('firstName')?.errors?.maxlength"
|
||||
jhiTranslate="settings.messages.validate.firstname.maxlength"
|
||||
>
|
||||
Your first name cannot be longer than 50 characters.
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.estado" for="field_estado">Estado</label>
|
||||
<select class="form-control" name="estado" formControlName="estado" id="field_estado" data-cy="estado">
|
||||
<option [ngValue]="null">{{ 'dataSurveyApp.EstadoUsuario.null' | translate }}</option>
|
||||
<option value="ACTIVE">{{ 'dataSurveyApp.EstadoUsuario.ACTIVE' | translate }}</option>
|
||||
<option value="SUSPENDED">{{ 'dataSurveyApp.EstadoUsuario.SUSPENDED' | translate }}</option>
|
||||
</select>
|
||||
<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">
|
||||
This field is required.
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="lastName" jhiTranslate="settings.form.lastname">Last Name</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="lastName"
|
||||
name="lastName"
|
||||
placeholder="{{ 'settings.form.lastname.placeholder' | translate }}"
|
||||
formControlName="lastName"
|
||||
data-cy="lastname"
|
||||
/>
|
||||
|
||||
<div
|
||||
*ngIf="settingsForm.get('lastName')!.invalid && (settingsForm.get('lastName')!.dirty || settingsForm.get('lastName')!.touched)"
|
||||
>
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.get('lastName')?.errors?.required"
|
||||
jhiTranslate="settings.messages.validate.lastname.required"
|
||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.user" for="field_user">User</label>
|
||||
<select class="form-control" id="field_user" data-cy="user" name="user" formControlName="user">
|
||||
<option [ngValue]="null"></option>
|
||||
<option
|
||||
[ngValue]="userOption.id === editForm.get('user')!.value?.id ? editForm.get('user')!.value : userOption"
|
||||
*ngFor="let userOption of usersSharedCollection; trackBy: trackUserById"
|
||||
>
|
||||
Your last name is required.
|
||||
</small>
|
||||
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.get('lastName')?.errors?.minlength"
|
||||
jhiTranslate="settings.messages.validate.lastname.minlength"
|
||||
>
|
||||
Your last name is required to be at least 1 character.
|
||||
</small>
|
||||
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.get('lastName')?.errors?.maxlength"
|
||||
jhiTranslate="settings.messages.validate.lastname.maxlength"
|
||||
>
|
||||
Your last name cannot be longer than 50 characters.
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="email" jhiTranslate="global.form.email.label">Email</label>
|
||||
<input
|
||||
type="email"
|
||||
class="form-control"
|
||||
id="email"
|
||||
name="email"
|
||||
placeholder="{{ 'global.form.email.placeholder' | translate }}"
|
||||
formControlName="email"
|
||||
data-cy="email"
|
||||
/>
|
||||
|
||||
<div *ngIf="settingsForm.get('email')!.invalid && (settingsForm.get('email')!.dirty || settingsForm.get('email')!.touched)">
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.get('email')?.errors?.required"
|
||||
jhiTranslate="global.messages.validate.email.required"
|
||||
>
|
||||
Your email is required.
|
||||
</small>
|
||||
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.get('email')?.errors?.email"
|
||||
jhiTranslate="global.messages.validate.email.invalid"
|
||||
>
|
||||
Your email is invalid.
|
||||
</small>
|
||||
|
||||
<small
|
||||
class="form-text text-danger"
|
||||
*ngIf="settingsForm.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="settingsForm.get('email')?.errors?.maxlength"
|
||||
jhiTranslate="global.messages.validate.email.maxlength"
|
||||
>
|
||||
Your email cannot be longer than 100 characters.
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" *ngIf="languages && languages.length > 0">
|
||||
<label for="langKey" jhiTranslate="settings.form.language">Language</label>
|
||||
<select class="form-control" id="langKey" name="langKey" formControlName="langKey" data-cy="langKey">
|
||||
<option *ngFor="let language of languages" [value]="language">{{ language | findLanguageFromKey }}</option>
|
||||
{{ userOption.id }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label jhiTranslate="dataSurveyApp.usuarioExtra.plantilla" for="field_plantillas">Plantilla</label>
|
||||
<select class="form-control" id="field_plantillas" data-cy="plantilla" multiple name="plantillas" formControlName="plantillas">
|
||||
<option
|
||||
[ngValue]="getSelectedPlantilla(plantillaOption, editForm.get('plantillas')!.value)"
|
||||
*ngFor="let plantillaOption of plantillasSharedCollection; trackBy: trackPlantillaById"
|
||||
>
|
||||
{{ plantillaOption.id }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button type="button" id="cancel-save" data-cy="entityCreateCancelButton" class="btn btn-secondary" (click)="previousState()">
|
||||
<fa-icon icon="ban"></fa-icon> <span jhiTranslate="entity.action.cancel">Cancel</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
[disabled]="settingsForm.invalid"
|
||||
id="save-entity"
|
||||
data-cy="entityCreateSaveButton"
|
||||
[disabled]="editForm.invalid || isSaving"
|
||||
class="btn btn-primary"
|
||||
jhiTranslate="settings.form.button"
|
||||
data-cy="submit"
|
||||
>
|
||||
Save
|
||||
<fa-icon icon="save"></fa-icon> <span jhiTranslate="entity.action.save">Save</span>
|
||||
</button>
|
||||
</form>
|
||||
</div> -->
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
|
|
|
@ -1,59 +1,177 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { HttpResponse } from '@angular/common/http';
|
||||
import { FormBuilder, Validators } from '@angular/forms';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { finalize, map } from 'rxjs/operators';
|
||||
|
||||
import * as dayjs from 'dayjs';
|
||||
import { DATE_TIME_FORMAT } from 'app/config/input.constants';
|
||||
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 { IUsuarioExtra, UsuarioExtra } from 'app/entities/usuario-extra/usuario-extra.model';
|
||||
import { UsuarioExtraService } from 'app/entities/usuario-extra/service/usuario-extra.service';
|
||||
import { AccountService } from 'app/core/auth/account.service';
|
||||
import { Account } from 'app/core/auth/account.model';
|
||||
import { LANGUAGES } from 'app/config/language.constants';
|
||||
|
||||
@Component({
|
||||
selector: 'jhi-settings',
|
||||
templateUrl: './settings.component.html',
|
||||
})
|
||||
export class SettingsComponent implements OnInit {
|
||||
account!: Account;
|
||||
success = false;
|
||||
languages = LANGUAGES;
|
||||
settingsForm = this.fb.group({
|
||||
firstName: [undefined, [Validators.required, Validators.minLength(1), Validators.maxLength(50)]],
|
||||
lastName: [undefined, [Validators.required, Validators.minLength(1), Validators.maxLength(50)]],
|
||||
email: [undefined, [Validators.required, Validators.minLength(5), Validators.maxLength(254), Validators.email]],
|
||||
langKey: [undefined],
|
||||
isSaving = false;
|
||||
|
||||
usersSharedCollection: IUser[] = [];
|
||||
plantillasSharedCollection: IPlantilla[] = [];
|
||||
|
||||
editForm = this.fb.group({
|
||||
email: [null, [Validators.required]],
|
||||
id: [],
|
||||
nombre: [null, [Validators.required]],
|
||||
iconoPerfil: [],
|
||||
fechaNacimiento: [],
|
||||
estado: [null, [Validators.required]],
|
||||
user: [],
|
||||
plantillas: [],
|
||||
});
|
||||
|
||||
constructor(private accountService: AccountService, private fb: FormBuilder, private translateService: TranslateService) {}
|
||||
usuarioExtra: UsuarioExtra | null = null;
|
||||
|
||||
constructor(
|
||||
protected usuarioExtraService: UsuarioExtraService,
|
||||
protected userService: UserService,
|
||||
protected plantillaService: PlantillaService,
|
||||
protected activatedRoute: ActivatedRoute,
|
||||
protected fb: FormBuilder,
|
||||
protected accountService: AccountService
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.accountService.identity().subscribe(account => {
|
||||
if (account) {
|
||||
this.settingsForm.patchValue({
|
||||
firstName: account.firstName,
|
||||
lastName: account.lastName,
|
||||
email: account.email,
|
||||
langKey: account.langKey,
|
||||
});
|
||||
// Get jhi_user and usuario_extra information
|
||||
this.accountService.getAuthenticationState().subscribe(account => {
|
||||
if (account !== null) {
|
||||
this.usuarioExtraService.find(account.id).subscribe(usuarioExtra => {
|
||||
this.usuarioExtra = usuarioExtra.body;
|
||||
if (this.usuarioExtra !== null) {
|
||||
if (this.usuarioExtra.id === undefined) {
|
||||
const today = dayjs().startOf('day');
|
||||
this.usuarioExtra.fechaNacimiento = today;
|
||||
}
|
||||
this.updateForm(this.usuarioExtra);
|
||||
}
|
||||
|
||||
this.account = account;
|
||||
// this.loadRelationshipsOptions();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// this.activatedRoute.data.subscribe(({ usuarioExtra }) => {
|
||||
|
||||
// });
|
||||
}
|
||||
|
||||
previousState(): void {
|
||||
window.history.back();
|
||||
}
|
||||
|
||||
save(): void {
|
||||
this.success = false;
|
||||
this.isSaving = true;
|
||||
const usuarioExtra = this.createFromForm();
|
||||
if (usuarioExtra.id !== undefined) {
|
||||
this.subscribeToSaveResponse(this.usuarioExtraService.update(usuarioExtra));
|
||||
} else {
|
||||
this.subscribeToSaveResponse(this.usuarioExtraService.create(usuarioExtra));
|
||||
}
|
||||
}
|
||||
|
||||
this.account.firstName = this.settingsForm.get('firstName')!.value;
|
||||
this.account.lastName = this.settingsForm.get('lastName')!.value;
|
||||
this.account.email = this.settingsForm.get('email')!.value;
|
||||
this.account.langKey = this.settingsForm.get('langKey')!.value;
|
||||
trackUserById(index: number, item: IUser): number {
|
||||
return item.id!;
|
||||
}
|
||||
|
||||
this.accountService.save(this.account).subscribe(() => {
|
||||
this.success = true;
|
||||
trackPlantillaById(index: number, item: IPlantilla): number {
|
||||
return item.id!;
|
||||
}
|
||||
|
||||
this.accountService.authenticate(this.account);
|
||||
|
||||
if (this.account.langKey !== this.translateService.currentLang) {
|
||||
this.translateService.use(this.account.langKey);
|
||||
getSelectedPlantilla(option: IPlantilla, selectedVals?: IPlantilla[]): IPlantilla {
|
||||
if (selectedVals) {
|
||||
for (const selectedVal of selectedVals) {
|
||||
if (option.id === selectedVal.id) {
|
||||
return selectedVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
// Api for inheritance.
|
||||
}
|
||||
|
||||
protected onSaveFinalize(): void {
|
||||
this.isSaving = false;
|
||||
}
|
||||
|
||||
protected updateForm(usuarioExtra: IUsuarioExtra): void {
|
||||
this.editForm.patchValue({
|
||||
email: usuarioExtra.user?.login,
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,3 +244,122 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- <div class="row justify-content-center">
|
||||
<div class="col-8">
|
||||
<form name="editForm" role="form" novalidate (ngSubmit)="save()" [formGroup]="editForm">
|
||||
<h2
|
||||
id="jhi-usuario-extra-heading"
|
||||
data-cy="UsuarioExtraCreateUpdateHeading"
|
||||
jhiTranslate="dataSurveyApp.usuarioExtra.home.createOrEditLabel"
|
||||
>
|
||||
Create or edit a Usuario Extra
|
||||
</h2>
|
||||
|
||||
<div>
|
||||
<jhi-alert-error></jhi-alert-error>
|
||||
|
||||
<div class="form-group" [hidden]="editForm.get('id')!.value == null">
|
||||
<label class="form-control-label" jhiTranslate="global.field.id" for="field_id">ID</label>
|
||||
<input type="number" class="form-control" name="id" id="field_id" data-cy="id" formControlName="id" [readonly]="true" />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.nombre" for="field_nombre">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
|
||||
type="text"
|
||||
class="form-control"
|
||||
name="iconoPerfil"
|
||||
id="field_iconoPerfil"
|
||||
data-cy="iconoPerfil"
|
||||
formControlName="iconoPerfil"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.fechaNacimiento" for="field_fechaNacimiento"
|
||||
>Fecha Nacimiento</label
|
||||
>
|
||||
<div class="d-flex">
|
||||
<input
|
||||
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">
|
||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.estado" for="field_estado">Estado</label>
|
||||
<select class="form-control" name="estado" formControlName="estado" id="field_estado" data-cy="estado">
|
||||
<option [ngValue]="null">{{ 'dataSurveyApp.EstadoUsuario.null' | translate }}</option>
|
||||
<option value="ACTIVE">{{ 'dataSurveyApp.EstadoUsuario.ACTIVE' | translate }}</option>
|
||||
<option value="SUSPENDED">{{ 'dataSurveyApp.EstadoUsuario.SUSPENDED' | translate }}</option>
|
||||
</select>
|
||||
<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">
|
||||
This field is required.
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" jhiTranslate="dataSurveyApp.usuarioExtra.user" for="field_user">User</label>
|
||||
<select class="form-control" id="field_user" data-cy="user" name="user" formControlName="user">
|
||||
<option [ngValue]="null"></option>
|
||||
<option
|
||||
[ngValue]="userOption.id === editForm.get('user')!.value?.id ? editForm.get('user')!.value : userOption"
|
||||
*ngFor="let userOption of usersSharedCollection; trackBy: trackUserById"
|
||||
>
|
||||
{{ userOption.id }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label jhiTranslate="dataSurveyApp.usuarioExtra.plantilla" for="field_plantillas">Plantilla</label>
|
||||
<select class="form-control" id="field_plantillas" data-cy="plantilla" multiple name="plantillas" formControlName="plantillas">
|
||||
<option
|
||||
[ngValue]="getSelectedPlantilla(plantillaOption, editForm.get('plantillas')!.value)"
|
||||
*ngFor="let plantillaOption of plantillasSharedCollection; trackBy: trackPlantillaById"
|
||||
>
|
||||
{{ plantillaOption.id }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button type="button" id="cancel-save" data-cy="entityCreateCancelButton" class="btn btn-secondary" (click)="previousState()">
|
||||
<fa-icon icon="ban"></fa-icon> <span jhiTranslate="entity.action.cancel">Cancel</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
id="save-entity"
|
||||
data-cy="entityCreateSaveButton"
|
||||
[disabled]="editForm.invalid || isSaving"
|
||||
class="btn btn-primary"
|
||||
>
|
||||
<fa-icon icon="save"></fa-icon> <span jhiTranslate="entity.action.save">Save</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div> -->
|
||||
|
|
Loading…
Reference in New Issue