Merge branch 'dev' into feature/US-04

This commit is contained in:
Mariela Bonilla 2021-07-18 03:40:45 -06:00
commit b730079e08
14 changed files with 107 additions and 207 deletions

View File

@ -1,7 +1,8 @@
package org.datasurvey.repository; package org.datasurvey.repository;
import org.datasurvey.domain.Categoria; import org.datasurvey.domain.Categoria;
import org.springframework.data.jpa.repository.*; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
/** /**

View File

@ -175,7 +175,7 @@
<p class="ds-title">Perfil</p> <p class="ds-title">Perfil</p>
</div> </div>
<div> <div>
<p class="ds-subtitle">Información general de su usuario, el correo electrónico es su identificador en DataSurvey.</p> <p class="ds-subtitle">Información general de su usuario, el correo electrónico es su identificador en DataSurvey</p>
</div> </div>
</div> </div>
</div> </div>
@ -284,7 +284,7 @@
</div> </div>
<div> <div>
<p class="ds-subtitle"> <p class="ds-subtitle">
Utilice una contraseña segura al realizar el cambio, este dato debe ser secreto ya que provee acceso a su cuenta. Utilice una contraseña segura al realizar el cambio, este dato debe ser secreto ya que provee acceso a su cuenta
</p> </p>
</div> </div>
@ -305,19 +305,35 @@
<div class="row mb-3 pb-3" style="border-bottom: 1px solid #e7ebf3"> <div class="row mb-3 pb-3" style="border-bottom: 1px solid #e7ebf3">
<div <div
class="alert alert-danger" class="alert alert-danger"
*ngIf="errorPassword && !doNotMatch && !successPassword" *ngIf="errorPassword && !doNotMatch && !successPassword && !samePassword"
jhiTranslate="global.messages.info.authenticated.passwordForm" jhiTranslate="global.messages.info.authenticated.passwordForm"
data-cy="loginError" data-cy="loginError"
></div> ></div>
<div *ngIf="successPassword" class="alert alert-success alert-dismissible fade show" role="alert"> <div
*ngIf="successPassword && !errorPassword && !samePassword && !doNotMatch"
class="alert alert-success alert-dismissible fade show"
role="alert"
>
Sus contraseña fue actualizada de manera exitosa Sus contraseña fue actualizada de manera exitosa
<!-- <button type="button" class="close" data-dismiss="alert" aria-label="Close"> <!-- <button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button>--> </button>-->
</div> </div>
<div class="alert alert-danger" *ngIf="doNotMatch && !successPassword" jhiTranslate="global.messages.error.dontmatch"> <div
class="alert alert-danger"
*ngIf="doNotMatch && !successPassword && !errorPassword"
jhiTranslate="global.messages.error.dontmatch"
>
The password and its confirmation do not match!
</div>
<div
class="alert alert-danger"
*ngIf="samePassword && !successPassword && !errorPassword && !doNotMatch"
jhiTranslate="global.messages.error.samePassword"
>
The password and its confirmation do not match! The password and its confirmation do not match!
</div> </div>
@ -477,7 +493,7 @@
type="submit" type="submit"
id="save-entity" id="save-entity"
data-cy="entityCreateSaveButton" data-cy="entityCreateSaveButton"
[disabled]="isSaving" [disabled]="passwordForm.invalid || isSaving"
class="ds-btn ds-btn--primary" class="ds-btn ds-btn--primary"
> >
<span jhiTranslate="entity.action.save">Save</span> <span jhiTranslate="entity.action.save">Save</span>

View File

@ -26,6 +26,7 @@ export class SettingsComponent implements OnInit {
isSaving = false; isSaving = false;
success = false; success = false;
successPassword = false; successPassword = false;
samePassword = false;
error = false; error = false;
errorPassword = false; errorPassword = false;
doNotMatch = false; doNotMatch = false;
@ -49,8 +50,8 @@ export class SettingsComponent implements OnInit {
//form de la contraseña //form de la contraseña
passwordForm = this.fb.group({ passwordForm = this.fb.group({
password: [null, [Validators.required], Validators.minLength(8), Validators.maxLength(50)], password: [null, [Validators.required, Validators.minLength(8), Validators.maxLength(50)]],
passwordNew: [null, [Validators.required], Validators.minLength(8), Validators.maxLength(50)], passwordNew: [null, [Validators.required, Validators.minLength(8), Validators.maxLength(50)]],
passwordNewConfirm: [null, [Validators.required, Validators.minLength(8), Validators.maxLength(50)]], passwordNewConfirm: [null, [Validators.required, Validators.minLength(8), Validators.maxLength(50)]],
}); });
@ -120,7 +121,7 @@ export class SettingsComponent implements OnInit {
} }
}); });
console.log(this.isGoogle); //console.log(this.isGoogle);
// this.activatedRoute.data.subscribe(({ usuarioExtra }) => { // this.activatedRoute.data.subscribe(({ usuarioExtra }) => {
@ -143,16 +144,27 @@ export class SettingsComponent implements OnInit {
} }
savePassword(): void { savePassword(): void {
this.successPassword = false;
this.doNotMatch = false;
this.samePassword = false;
this.errorPassword = false;
const passwordNew = this.passwordForm.get(['passwordNew'])!.value; const passwordNew = this.passwordForm.get(['passwordNew'])!.value;
if (passwordNew !== this.passwordForm.get(['passwordNewConfirm'])!.value) { const passwordOld = this.passwordForm.get(['password'])!.value;
this.doNotMatch = true; if (passwordOld == passwordNew) {
this.samePassword = true;
} else { } else {
this.passwordService.save(this.passwordForm.get(['passwordNew'])!.value, this.passwordForm.get(['password'])!.value).subscribe( if (passwordNew !== this.passwordForm.get(['passwordNewConfirm'])!.value) {
(this.doNotMatch = true), (this.samePassword = false);
} else {
this.passwordService.save(passwordNew, passwordOld).subscribe(
() => (this.successPassword = true), () => (this.successPassword = true),
() => (this.errorPassword = true) () => (this.errorPassword = true)
); );
} }
} }
}
trackUserById(index: number, item: IUser): number { trackUserById(index: number, item: IUser): number {
return item.id!; return item.id!;
@ -175,15 +187,16 @@ export class SettingsComponent implements OnInit {
protected subscribeToSaveResponse(result: Observable<HttpResponse<IUsuarioExtra>>): void { protected subscribeToSaveResponse(result: Observable<HttpResponse<IUsuarioExtra>>): void {
result.pipe(finalize(() => this.onSaveFinalize())).subscribe( result.pipe(finalize(() => this.onSaveFinalize())).subscribe(
() => ( () => ((this.success = true), this.windowReload()),
(this.success = true),
this.router.navigate(['account/settings']).then(() => {
window.location.reload();
})
),
response => this.processError(response) response => this.processError(response)
); );
} }
windowReload() {
this.router.navigate(['account/settings']).then(() => {
window.location.reload();
});
}
processError(response: HttpErrorResponse): void { processError(response: HttpErrorResponse): void {
if (response.status === 400) { if (response.status === 400) {
this.error = true; this.error = true;
@ -217,8 +230,10 @@ export class SettingsComponent implements OnInit {
// Update swiper // Update swiper
this.profileIcon = usuarioExtra.iconoPerfil!; this.profileIcon = usuarioExtra.iconoPerfil!;
console.log(this.profileIcon);
this.profileIcons.forEach(icon => { this.profileIcons.forEach(icon => {
if (parseInt(icon.name.split('C')[1]) === this.profileIcon) { if (icon.name.split('C')[1] === this.profileIcon) {
icon.class = 'active'; icon.class = 'active';
} }
}); });
@ -269,7 +284,7 @@ export class SettingsComponent implements OnInit {
event.target.classList.add('active'); event.target.classList.add('active');
this.profileIcon = +event.target.getAttribute('id')! + 1; this.profileIcon = +event.target.getAttribute('id')! + 1;
console.log(this.profileIcon); //console.log(this.profileIcon);
} }
} }
} }

View File

@ -1,14 +1,13 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { SharedModule } from 'app/shared/shared.module'; import { SharedModule } from 'app/shared/shared.module';
import { CategoriaComponent } from './list/categoria.component'; import { CategoriaComponent } from './list/categoria.component';
import { CategoriaDetailComponent } from './detail/categoria-detail.component';
import { CategoriaUpdateComponent } from './update/categoria-update.component'; import { CategoriaUpdateComponent } from './update/categoria-update.component';
import { CategoriaDeleteDialogComponent } from './delete/categoria-delete-dialog.component'; import { CategoriaDeleteDialogComponent } from './delete/categoria-delete-dialog.component';
import { CategoriaRoutingModule } from './route/categoria-routing.module'; import { CategoriaRoutingModule } from './route/categoria-routing.module';
@NgModule({ @NgModule({
imports: [SharedModule, CategoriaRoutingModule], imports: [SharedModule, CategoriaRoutingModule],
declarations: [CategoriaComponent, CategoriaDetailComponent, CategoriaUpdateComponent, CategoriaDeleteDialogComponent], declarations: [CategoriaComponent, CategoriaUpdateComponent, CategoriaDeleteDialogComponent],
entryComponents: [CategoriaDeleteDialogComponent], entryComponents: [CategoriaDeleteDialogComponent],
}) })
export class CategoriaModule {} export class CategoriaModule {}

View File

@ -1,4 +1,4 @@
<form class="ds-form" *ngIf="categoria" name="deleteForm" (ngSubmit)="confirmDelete(categoria.id!)"> <form class="ds-form" *ngIf="categoria" name="deleteForm" (ngSubmit)="confirmDelete(categoria!)">
<div class="modal-header"> <div class="modal-header">
<h4 class="modal-title" data-cy="categoriaDeleteDialogHeading" jhiTranslate="entity.delete.title">Confirm delete operation</h4> <h4 class="modal-title" data-cy="categoriaDeleteDialogHeading" jhiTranslate="entity.delete.title">Confirm delete operation</h4>
@ -9,7 +9,7 @@
<jhi-alert-error></jhi-alert-error> <jhi-alert-error></jhi-alert-error>
<p id="jhi-delete-categoria-heading" jhiTranslate="dataSurveyApp.categoria.delete.question" [translateValues]="{ id: categoria.id }"> <p id="jhi-delete-categoria-heading" jhiTranslate="dataSurveyApp.categoria.delete.question" [translateValues]="{ id: categoria.id }">
Are you sure you want to delete this Categoria? Are you sure you want to delete this category?
</p> </p>
</div> </div>

View File

@ -1,65 +0,0 @@
jest.mock('@ng-bootstrap/ng-bootstrap');
import { ComponentFixture, TestBed, inject, fakeAsync, tick } from '@angular/core/testing';
import { HttpResponse } from '@angular/common/http';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { of } from 'rxjs';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { CategoriaService } from '../service/categoria.service';
import { CategoriaDeleteDialogComponent } from './categoria-delete-dialog.component';
describe('Component Tests', () => {
describe('Categoria Management Delete Component', () => {
let comp: CategoriaDeleteDialogComponent;
let fixture: ComponentFixture<CategoriaDeleteDialogComponent>;
let service: CategoriaService;
let mockActiveModal: NgbActiveModal;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
declarations: [CategoriaDeleteDialogComponent],
providers: [NgbActiveModal],
})
.overrideTemplate(CategoriaDeleteDialogComponent, '')
.compileComponents();
fixture = TestBed.createComponent(CategoriaDeleteDialogComponent);
comp = fixture.componentInstance;
service = TestBed.inject(CategoriaService);
mockActiveModal = TestBed.inject(NgbActiveModal);
});
describe('confirmDelete', () => {
it('Should call delete service on confirmDelete', inject(
[],
fakeAsync(() => {
// GIVEN
jest.spyOn(service, 'delete').mockReturnValue(of(new HttpResponse({})));
// WHEN
comp.confirmDelete(123);
tick();
// THEN
expect(service.delete).toHaveBeenCalledWith(123);
expect(mockActiveModal.close).toHaveBeenCalledWith('deleted');
})
));
it('Should not call delete service on clear', () => {
// GIVEN
jest.spyOn(service, 'delete');
// WHEN
comp.cancel();
// THEN
expect(service.delete).not.toHaveBeenCalled();
expect(mockActiveModal.close).not.toHaveBeenCalled();
expect(mockActiveModal.dismiss).toHaveBeenCalled();
});
});
});
});

View File

@ -1,7 +1,10 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { IEncuesta } from 'app/entities/encuesta/encuesta.model';
import { EncuestaService } from 'app/entities/encuesta/service/encuesta.service';
import { EstadoCategoria } from 'app/entities/enumerations/estado-categoria.model';
import { ICategoria } from '../categoria.model'; import { Categoria, ICategoria } from '../categoria.model';
import { CategoriaService } from '../service/categoria.service'; import { CategoriaService } from '../service/categoria.service';
@Component({ @Component({
@ -9,16 +12,52 @@ import { CategoriaService } from '../service/categoria.service';
}) })
export class CategoriaDeleteDialogComponent { export class CategoriaDeleteDialogComponent {
categoria?: ICategoria; categoria?: ICategoria;
encuestas?: IEncuesta[];
encuestasFiltradas?: IEncuesta[];
constructor(protected categoriaService: CategoriaService, protected activeModal: NgbActiveModal) {} constructor(
protected categoriaService: CategoriaService,
protected activeModal: NgbActiveModal,
protected encuestaService: EncuestaService
) {}
cancel(): void { cancel(): void {
this.activeModal.dismiss(); this.activeModal.dismiss();
} }
confirmDelete(id: number): void { confirmDelete(categoria: ICategoria): void {
this.categoriaService.delete(id).subscribe(() => { this.ensureNulaExists();
const categoriaNula = new Categoria(0, 'Otra', EstadoCategoria.ACTIVE);
this.getEncuestas(categoria);
if (this.encuestas) {
this.encuestas!.forEach(encuesta => {
encuesta.categoria = categoriaNula;
this.encuestaService.update(encuesta);
});
}
categoria.estado = EstadoCategoria.INACTIVE;
this.categoriaService.update(categoria).subscribe(() => {
this.activeModal.close('deleted'); this.activeModal.close('deleted');
}); });
} }
ensureNulaExists(): void {
const categoriaNula = new Categoria(0, 'Otra', EstadoCategoria.ACTIVE);
const categoria = this.categoriaService.find(0);
if (categoria) {
this.categoriaService.update(categoriaNula);
} else {
this.categoriaService.create(categoriaNula);
}
}
protected getEncuestas(categoria: ICategoria): void {
this.encuestaService.query().subscribe(res => {
this.encuestas = res.body ?? [];
});
if (this.encuestas) {
this.encuestasFiltradas = this.encuestas.filter(encuesta => {
encuesta.categoria!.id === categoria.id;
});
}
}
} }

View File

@ -1,36 +0,0 @@
<div class="row justify-content-center">
<div class="col-8">
<div *ngIf="categoria">
<h2 data-cy="categoriaDetailsHeading"><span jhiTranslate="dataSurveyApp.categoria.detail.title">Categoria</span></h2>
<hr />
<jhi-alert-error></jhi-alert-error>
<jhi-alert></jhi-alert>
<dl class="row-md jh-entity-details">
<dt><span jhiTranslate="global.field.id">ID</span></dt>
<dd>
<span>{{ categoria.id }}</span>
</dd>
<dt><span jhiTranslate="dataSurveyApp.categoria.nombre">Nombre</span></dt>
<dd>
<span>{{ categoria.nombre }}</span>
</dd>
<dt><span jhiTranslate="dataSurveyApp.categoria.estado">Estado</span></dt>
<dd>
<span jhiTranslate="{{ 'dataSurveyApp.EstadoCategoria.' + categoria.estado }}">{{ categoria.estado }}</span>
</dd>
</dl>
<button type="submit" (click)="previousState()" class="btn btn-ds btn-info" data-cy="entityDetailsBackButton">
<fa-icon icon="arrow-left"></fa-icon>&nbsp;<span jhiTranslate="entity.action.back">Back</span>
</button>
<button type="button" [routerLink]="['/categoria', categoria.id, 'edit']" class="btn btn-ds btn-ds-primary btn-primary">
<fa-icon icon="pencil-alt"></fa-icon>&nbsp;<span jhiTranslate="entity.action.edit">Edit</span>
</button>
</div>
</div>
</div>

View File

@ -1,38 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';
import { CategoriaDetailComponent } from './categoria-detail.component';
describe('Component Tests', () => {
describe('Categoria Management Detail Component', () => {
let comp: CategoriaDetailComponent;
let fixture: ComponentFixture<CategoriaDetailComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [CategoriaDetailComponent],
providers: [
{
provide: ActivatedRoute,
useValue: { data: of({ categoria: { id: 123 } }) },
},
],
})
.overrideTemplate(CategoriaDetailComponent, '')
.compileComponents();
fixture = TestBed.createComponent(CategoriaDetailComponent);
comp = fixture.componentInstance;
});
describe('OnInit', () => {
it('Should load categoria on init', () => {
// WHEN
comp.ngOnInit();
// THEN
expect(comp.categoria).toEqual(expect.objectContaining({ id: 123 }));
});
});
});
});

View File

@ -1,24 +0,0 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ICategoria } from '../categoria.model';
@Component({
selector: 'jhi-categoria-detail',
templateUrl: './categoria-detail.component.html',
})
export class CategoriaDetailComponent implements OnInit {
categoria: ICategoria | null = null;
constructor(protected activatedRoute: ActivatedRoute) {}
ngOnInit(): void {
this.activatedRoute.data.subscribe(({ categoria }) => {
this.categoria = categoria;
});
}
previousState(): void {
window.history.back();
}
}

View File

@ -38,7 +38,7 @@ export class CategoriaComponent implements OnInit {
this.loadAll(); this.loadAll();
} }
trackId(index: number, item: ICategoria): number { trackId(_index: number, item: ICategoria): number {
return item.id!; return item.id!;
} }

View File

@ -3,7 +3,6 @@ import { RouterModule, Routes } from '@angular/router';
import { UserRouteAccessService } from 'app/core/auth/user-route-access.service'; import { UserRouteAccessService } from 'app/core/auth/user-route-access.service';
import { CategoriaComponent } from '../list/categoria.component'; import { CategoriaComponent } from '../list/categoria.component';
import { CategoriaDetailComponent } from '../detail/categoria-detail.component';
import { CategoriaUpdateComponent } from '../update/categoria-update.component'; import { CategoriaUpdateComponent } from '../update/categoria-update.component';
import { CategoriaRoutingResolveService } from './categoria-routing-resolve.service'; import { CategoriaRoutingResolveService } from './categoria-routing-resolve.service';
@ -13,14 +12,6 @@ const categoriaRoute: Routes = [
component: CategoriaComponent, component: CategoriaComponent,
canActivate: [UserRouteAccessService], canActivate: [UserRouteAccessService],
}, },
{
path: ':id/view',
component: CategoriaDetailComponent,
resolve: {
categoria: CategoriaRoutingResolveService,
},
canActivate: [UserRouteAccessService],
},
{ {
path: 'new', path: 'new',
component: CategoriaUpdateComponent, component: CategoriaUpdateComponent,

View File

@ -64,7 +64,7 @@ export class CategoriaUpdateComponent implements OnInit {
protected categoryExists(categoria: ICategoria): boolean { protected categoryExists(categoria: ICategoria): boolean {
this.loadAll(); this.loadAll();
var condicion = this.categorias!.some(cat => cat.nombre!.toLowerCase() === categoria.nombre!.toLowerCase()); var condicion = this.categorias!.some(cat => cat.nombre!.toLowerCase() === categoria.nombre!.toLowerCase() && cat.id !== categoria.id);
return condicion; return condicion;
} }

View File

@ -68,6 +68,7 @@
"suffix": ", puede intentar con las cuentas predeterminadas:<br/>- Administrador (usuario=\"admin\" y contraseña=\"admin\") <br/>- Usuario (usuario=\"user\" y contraseña=\"user\").", "suffix": ", puede intentar con las cuentas predeterminadas:<br/>- Administrador (usuario=\"admin\" y contraseña=\"admin\") <br/>- Usuario (usuario=\"user\" y contraseña=\"user\").",
"updateForm": "Ocurrió un error al actualizar su información, favor revisar los campos e intentar de nuevo", "updateForm": "Ocurrió un error al actualizar su información, favor revisar los campos e intentar de nuevo",
"passwordForm": "Ocurrió un error al actualizar su contraseña, favor revisar los campos e intentar de nuevo", "passwordForm": "Ocurrió un error al actualizar su contraseña, favor revisar los campos e intentar de nuevo",
"botonInicio": "Iniciar Sesión" "botonInicio": "Iniciar Sesión"
}, },
"register": { "register": {
@ -76,7 +77,8 @@
} }
}, },
"error": { "error": {
"dontmatch": "¡La contraseña y la confirmación de contraseña no coinciden!" "samePassword": "La contraseña actual y la nueva contraseña no pueden ser iguales",
"dontmatch": "La contraseña y la confirmación de contraseña no coinciden"
}, },
"validate": { "validate": {
"newpassword": { "newpassword": {