validaciones publicar encuesta
This commit is contained in:
parent
593905bf01
commit
dcd6dfd5ef
|
@ -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> <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">
|
||||
<span jhiTranslate="entity.action.publish">Delete</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
|
@ -0,0 +1,24 @@
|
|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { EncuestaPublishDialogComponent } from './encuesta-publish-dialog.component';
|
||||
|
||||
describe('EncuestaPublishDialogComponent', () => {
|
||||
let component: EncuestaPublishDialogComponent;
|
||||
let fixture: ComponentFixture<EncuestaPublishDialogComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [EncuestaPublishDialogComponent],
|
||||
}).compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(EncuestaPublishDialogComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
|
@ -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 {}
|
||||
}
|
|
@ -6,10 +6,17 @@ import { EncuestaUpdateComponent } from './update/encuesta-update.component';
|
|||
import { EncuestaDeleteDialogComponent } from './delete/encuesta-delete-dialog.component';
|
||||
import { EncuestaRoutingModule } from './route/encuesta-routing.module';
|
||||
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
|
||||
import { EncuestaPublishDialogComponent } from './encuesta-publish-dialog/encuesta-publish-dialog.component';
|
||||
|
||||
@NgModule({
|
||||
imports: [SharedModule, EncuestaRoutingModule, FontAwesomeModule],
|
||||
declarations: [EncuestaComponent, EncuestaDetailComponent, EncuestaUpdateComponent, EncuestaDeleteDialogComponent],
|
||||
declarations: [
|
||||
EncuestaComponent,
|
||||
EncuestaDetailComponent,
|
||||
EncuestaUpdateComponent,
|
||||
EncuestaDeleteDialogComponent,
|
||||
EncuestaPublishDialogComponent,
|
||||
],
|
||||
entryComponents: [EncuestaDeleteDialogComponent],
|
||||
})
|
||||
export class EncuestaModule {}
|
||||
|
|
|
@ -29,7 +29,12 @@
|
|||
|
||||
<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">×</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-warning" id="no-result" *ngIf="encuestas?.length === 0">
|
||||
<span jhiTranslate="dataSurveyApp.encuesta.home.notFound">No encuestas found</span>
|
||||
|
@ -61,8 +66,17 @@
|
|||
<button type="button" id="contextmenu-duplicate"><fa-icon class="contextmenu__icon" [icon]="faCopy"></fa-icon>Duplicar</button>
|
||||
</li>
|
||||
<li>
|
||||
<button type="button" id="contextmenu-rename">
|
||||
<fa-icon class="contextmenu__icon" [icon]="faFile"></fa-icon>Cambiar nombre
|
||||
<button
|
||||
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>
|
||||
</li>
|
||||
<li>
|
||||
|
@ -194,7 +208,7 @@
|
|||
<fa-icon icon="pencil-alt"></fa-icon>
|
||||
<span class="d-none d-md-inline" jhiTranslate="entity.action.edit">Edit</span>
|
||||
</button>
|
||||
|
||||
|
||||
<button type="submit" (click)="delete(encuesta)" class="btn btn-danger btn-sm" data-cy="entityDeleteButton">
|
||||
<fa-icon icon="times"></fa-icon>
|
||||
<span class="d-none d-md-inline" jhiTranslate="entity.action.delete">Delete</span>
|
||||
|
|
|
@ -34,9 +34,11 @@ import {
|
|||
faTrashAlt,
|
||||
faPlus,
|
||||
faStar,
|
||||
faUpload,
|
||||
} from '@fortawesome/free-solid-svg-icons';
|
||||
|
||||
import * as $ from 'jquery';
|
||||
import { EncuestaPublishDialogComponent } from '../encuesta-publish-dialog/encuesta-publish-dialog.component';
|
||||
|
||||
@Component({
|
||||
selector: 'jhi-encuesta',
|
||||
|
@ -54,13 +56,15 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
|
|||
faTrashAlt = faTrashAlt;
|
||||
faPlus = faPlus;
|
||||
faStar = faStar;
|
||||
|
||||
faUpload = faUpload;
|
||||
isPublished = false;
|
||||
successPublished = false;
|
||||
account: Account | null = null;
|
||||
usuarioExtra: UsuarioExtra | null = null;
|
||||
|
||||
encuestas?: IEncuesta[];
|
||||
isLoading = false;
|
||||
|
||||
selectedSurvey?: IEncuesta | null = null;
|
||||
isSaving = false;
|
||||
|
||||
categoriasSharedCollection: ICategoria[] = [];
|
||||
|
@ -83,6 +87,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
|
|||
});
|
||||
|
||||
createAnother: Boolean = false;
|
||||
selectedSurveyId: Number = 0;
|
||||
|
||||
constructor(
|
||||
protected encuestaService: EncuestaService,
|
||||
|
@ -328,7 +333,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
|
|||
return 5 - something;
|
||||
}
|
||||
|
||||
openContextMenu(event: any): void {
|
||||
async openContextMenu(event: any): Promise<void> {
|
||||
document.querySelectorAll('.ds-list--entity').forEach(e => {
|
||||
e.classList.remove('active');
|
||||
});
|
||||
|
@ -336,12 +341,25 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
|
|||
if (event.type === 'contextmenu') {
|
||||
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-edit--separator')!.style.display = 'block';
|
||||
document.getElementById('contextmenu-delete--separator')!.style.display = 'block';
|
||||
document.getElementById('contextmenu-edit')!.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';
|
||||
|
||||
if ((event.target as HTMLElement).classList.contains('ds-list')) {
|
||||
|
@ -359,4 +377,18 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
|
|||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ export class EncuestaService {
|
|||
.pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
|
||||
}
|
||||
|
||||
find(id: number): Observable<EntityResponseType> {
|
||||
find(id: Number): Observable<EntityResponseType> {
|
||||
return this.http
|
||||
.get<IEncuesta>(`${this.resourceUrl}/${id}`, { observe: 'response' })
|
||||
.pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
|
||||
|
|
|
@ -129,7 +129,8 @@
|
|||
"create": "Crear",
|
||||
"enable": "Habilitar",
|
||||
"disable": "Deshabilitar",
|
||||
"toggleStatus": "Cambiar Estado"
|
||||
"toggleStatus": "Cambiar Estado",
|
||||
"publish": "Publicar"
|
||||
},
|
||||
"detail": {
|
||||
"field": "Campo",
|
||||
|
@ -150,6 +151,11 @@
|
|||
"number": "Este campo debe ser un número.",
|
||||
"integerNumber": "Este campo debe ser un número entero.",
|
||||
"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": {
|
||||
|
|
Loading…
Reference in New Issue