Merge pull request #59 from Quantum-P3/feature/US-41

Feature/us 41
This commit is contained in:
Eduardo Quiros 2021-07-24 05:22:46 +00:00 committed by GitHub
commit 49d721e32f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 124 additions and 11 deletions

View File

@ -0,0 +1,21 @@
<form *ngIf="encuesta" name="deleteForm" (ngSubmit)="confirmPublish(encuesta)">
<div class="modal-header">
<!-- <h4 class="modal-title" data-cy="encuestaDeleteDialogHeading" jhiTranslate="entity.publish.title">Confirm delete operation</h4>-->
</div>
<div class="modal-body">
<jhi-alert-error></jhi-alert-error>
<p id="jhi-delete-encuesta-heading" jhiTranslate="entity.publish.detail">Are you sure you want to delete this Encuesta?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" (click)="cancel()">
<fa-icon icon="ban"></fa-icon>&nbsp;<span jhiTranslate="entity.action.cancel">Cancel</span>
</button>
<button id="jhi-confirm-delete-encuesta" data-cy="entityConfirmDeleteButton" type="submit" class="ds-btn ds-btn--primary">
&nbsp;<span jhiTranslate="entity.action.publish">Delete</span>
</button>
</div>
</form>

View File

@ -0,0 +1,33 @@
import { Component, OnInit } from '@angular/core';
import { IEncuesta } from '../encuesta.model';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { EncuestaService } from '../service/encuesta.service';
import { EstadoEncuesta } from '../../enumerations/estado-encuesta.model';
@Component({
selector: 'jhi-encuesta-publish-dialog',
templateUrl: './encuesta-publish-dialog.component.html',
styleUrls: ['./encuesta-publish-dialog.component.scss'],
})
export class EncuestaPublishDialogComponent implements OnInit {
encuesta?: IEncuesta;
constructor(protected encuestaService: EncuestaService, protected activeModal: NgbActiveModal) {}
cancel(): void {
this.activeModal.dismiss();
}
confirmPublish(encuesta: IEncuesta): void {
debugger;
if (encuesta.estado === 'DRAFT') {
encuesta.estado = EstadoEncuesta.ACTIVE;
}
this.encuestaService.update(encuesta).subscribe(() => {
this.activeModal.close('published');
});
}
ngOnInit(): void {}
}

View File

@ -6,10 +6,17 @@ import { EncuestaUpdateComponent } from './update/encuesta-update.component';
import { EncuestaDeleteDialogComponent } from './delete/encuesta-delete-dialog.component'; import { EncuestaDeleteDialogComponent } from './delete/encuesta-delete-dialog.component';
import { EncuestaRoutingModule } from './route/encuesta-routing.module'; import { EncuestaRoutingModule } from './route/encuesta-routing.module';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { EncuestaPublishDialogComponent } from './encuesta-publish-dialog/encuesta-publish-dialog.component';
@NgModule({ @NgModule({
imports: [SharedModule, EncuestaRoutingModule, FontAwesomeModule], imports: [SharedModule, EncuestaRoutingModule, FontAwesomeModule],
declarations: [EncuestaComponent, EncuestaDetailComponent, EncuestaUpdateComponent, EncuestaDeleteDialogComponent], declarations: [
EncuestaComponent,
EncuestaDetailComponent,
EncuestaUpdateComponent,
EncuestaDeleteDialogComponent,
EncuestaPublishDialogComponent,
],
entryComponents: [EncuestaDeleteDialogComponent], entryComponents: [EncuestaDeleteDialogComponent],
}) })
export class EncuestaModule {} export class EncuestaModule {}

View File

@ -29,7 +29,12 @@
<jhi-alert-error></jhi-alert-error> <jhi-alert-error></jhi-alert-error>
<jhi-alert></jhi-alert> <div *ngIf="successPublished" class="alert alert-success alert-dismissible fade show" role="alert">
Su encuesta fue publicada exitosamente
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="alert alert-warning" id="no-result" *ngIf="encuestas?.length === 0"> <div class="alert alert-warning" id="no-result" *ngIf="encuestas?.length === 0">
<span jhiTranslate="dataSurveyApp.encuesta.home.notFound">No surveys found</span> <span jhiTranslate="dataSurveyApp.encuesta.home.notFound">No surveys found</span>
@ -61,8 +66,17 @@
<button type="button" id="contextmenu-duplicate"><fa-icon class="contextmenu__icon" [icon]="faCopy"></fa-icon>Duplicar</button> <button type="button" id="contextmenu-duplicate"><fa-icon class="contextmenu__icon" [icon]="faCopy"></fa-icon>Duplicar</button>
</li> </li>
<li> <li>
<button type="button" id="contextmenu-rename"> <button
<fa-icon class="contextmenu__icon" [icon]="faFile"></fa-icon>Cambiar nombre type="button"
id="contextmenu-publish"
type="button"
(click)="publish()"
data-toggle="modal"
data-target="#publicarEncuesta"
*ngIf="isPublished"
>
<!--Agarrar el id de la encuesta -->
<fa-icon class="contextmenu__icon" [icon]="faUpload"></fa-icon>Publicar
</button> </button>
</li> </li>
<li> <li>

View File

@ -34,9 +34,11 @@ import {
faTrashAlt, faTrashAlt,
faPlus, faPlus,
faStar, faStar,
faUpload,
} from '@fortawesome/free-solid-svg-icons'; } from '@fortawesome/free-solid-svg-icons';
import * as $ from 'jquery'; import * as $ from 'jquery';
import { EncuestaPublishDialogComponent } from '../encuesta-publish-dialog/encuesta-publish-dialog.component';
@Component({ @Component({
selector: 'jhi-encuesta', selector: 'jhi-encuesta',
@ -54,14 +56,16 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
faTrashAlt = faTrashAlt; faTrashAlt = faTrashAlt;
faPlus = faPlus; faPlus = faPlus;
faStar = faStar; faStar = faStar;
faUpload = faUpload;
isPublished = false;
successPublished = false;
account: Account | null = null; account: Account | null = null;
usuarioExtra: UsuarioExtra | null = null; usuarioExtra: UsuarioExtra | null = null;
estadoDeleted = EstadoEncuesta.DELETED; estadoDeleted = EstadoEncuesta.DELETED;
encuestas?: IEncuesta[]; encuestas?: IEncuesta[];
isLoading = false; isLoading = false;
selectedSurvey?: IEncuesta | null = null;
isSaving = false; isSaving = false;
categoriasSharedCollection: ICategoria[] = []; categoriasSharedCollection: ICategoria[] = [];
@ -84,6 +88,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
}); });
createAnother: Boolean = false; createAnother: Boolean = false;
selectedSurveyId: Number = 0;
constructor( constructor(
protected encuestaService: EncuestaService, protected encuestaService: EncuestaService,
@ -335,7 +340,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
return 5 - something; return 5 - something;
} }
openContextMenu(event: any): void { async openContextMenu(event: any): Promise<void> {
document.querySelectorAll('.ds-list--entity').forEach(e => { document.querySelectorAll('.ds-list--entity').forEach(e => {
e.classList.remove('active'); e.classList.remove('active');
}); });
@ -343,12 +348,25 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
if (event.type === 'contextmenu') { if (event.type === 'contextmenu') {
event.preventDefault(); event.preventDefault();
debugger;
this.selectedSurveyId = event.target.dataset.id;
console.log(this.selectedSurveyId);
debugger;
let res = await this.encuestaService.find(this.selectedSurveyId).toPromise();
this.selectedSurvey = res.body;
this.isPublished = this.selectedSurvey!.estado === 'DRAFT'; // QUE SE LE MUESTRE CUANDO ESTE EN DRAFT
document.getElementById('contextmenu-create--separator')!.style.display = 'block'; document.getElementById('contextmenu-create--separator')!.style.display = 'block';
document.getElementById('contextmenu-edit--separator')!.style.display = 'block'; document.getElementById('contextmenu-edit--separator')!.style.display = 'block';
document.getElementById('contextmenu-delete--separator')!.style.display = 'block'; document.getElementById('contextmenu-delete--separator')!.style.display = 'block';
document.getElementById('contextmenu-edit')!.style.display = 'block'; document.getElementById('contextmenu-edit')!.style.display = 'block';
document.getElementById('contextmenu-duplicate')!.style.display = 'block'; document.getElementById('contextmenu-duplicate')!.style.display = 'block';
document.getElementById('contextmenu-rename')!.style.display = 'block';
if (this.isPublished) {
document.getElementById('contextmenu-publish')!.style.display = 'block'; //cambiar
}
document.getElementById('contextmenu-share')!.style.display = 'block'; document.getElementById('contextmenu-share')!.style.display = 'block';
if ((event.target as HTMLElement).classList.contains('ds-list')) { if ((event.target as HTMLElement).classList.contains('ds-list')) {
@ -366,4 +384,18 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
document.getElementById('contextmenu')!.style.maxHeight = '100%'; document.getElementById('contextmenu')!.style.maxHeight = '100%';
} }
} }
publish() {
debugger;
const modalRef = this.modalService.open(EncuestaPublishDialogComponent, { size: 'lg', backdrop: 'static' });
modalRef.componentInstance.encuesta = this.selectedSurvey;
// unsubscribe not needed because closed completes on modal close
modalRef.closed.subscribe(reason => {
if (reason === 'published') {
this.successPublished = true;
this.loadAll();
}
});
}
} }

View File

@ -34,7 +34,7 @@ describe('Service Tests', () => {
describe('resolve', () => { describe('resolve', () => {
it('should return IEncuesta returned by find', () => { it('should return IEncuesta returned by find', () => {
// GIVEN // GIVEN
service.find = jest.fn(id => of(new HttpResponse({ body: { id } }))); // service.find = jest.fn(id => of(new HttpResponse({ body: { id } })));
mockActivatedRouteSnapshot.params = { id: 123 }; mockActivatedRouteSnapshot.params = { id: 123 };
// WHEN // WHEN

View File

@ -39,7 +39,7 @@ export class EncuestaService {
.pipe(map((res: EntityResponseType) => this.convertDateFromServer(res))); .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
} }
find(id: number): Observable<EntityResponseType> { find(id: Number): Observable<EntityResponseType> {
return this.http return this.http
.get<IEncuesta>(`${this.resourceUrl}/${id}`, { observe: 'response' }) .get<IEncuesta>(`${this.resourceUrl}/${id}`, { observe: 'response' })
.pipe(map((res: EntityResponseType) => this.convertDateFromServer(res))); .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));

View File

@ -129,7 +129,8 @@
"create": "Crear", "create": "Crear",
"enable": "Habilitar", "enable": "Habilitar",
"disable": "Deshabilitar", "disable": "Deshabilitar",
"toggleStatus": "Cambiar Estado" "toggleStatus": "Cambiar Estado",
"publish": "Publicar"
}, },
"detail": { "detail": {
"field": "Campo", "field": "Campo",
@ -150,6 +151,11 @@
"number": "Este campo debe ser un número.", "number": "Este campo debe ser un número.",
"integerNumber": "Este campo debe ser un número entero.", "integerNumber": "Este campo debe ser un número entero.",
"datetimelocal": "Este campo debe ser una fecha y hora." "datetimelocal": "Este campo debe ser una fecha y hora."
},
"publish": {
"title": "Publicar encuesta",
"detail": "¿Está seguro de querer publicar esta encuesta?",
"success": "Su encuesta fue publicada exitosamente"
} }
}, },
"error": { "error": {