add toggle function to yes on all timeslices of a group choice

This commit is contained in:
Tykayn 2021-05-20 13:25:45 +02:00 committed by tykayn
parent 406bf71b92
commit 3b8aa9d849
9 changed files with 50 additions and 8 deletions

View File

@ -3,6 +3,7 @@ import { Owner } from './owner.model';
export class ChoiceGroup { export class ChoiceGroup {
date_string: string; date_string: string;
subSetToYes = false; // to know if all the choices are set to YES, to toggle them all at once without checking them individually
choices: Choice[]; choices: Choice[];
} }

View File

@ -102,4 +102,14 @@ export class StorageService {
} }
return false; return false;
} }
setAllSubchoicesTo(groupe, newAnswer = 'yes') {
groupe.choices.map((choice) => {
for (const vote of this.vote_stack.votes) {
if (vote.choice_id == choice.id) {
vote.value = newAnswer;
}
}
});
}
} }

View File

@ -52,6 +52,7 @@ export class ConsultationComponent implements OnInit, OnDestroy {
if (newpoll) { if (newpoll) {
this.isArchived = new Date(newpoll.expiracy_date) < new Date(); this.isArchived = new Date(newpoll.expiracy_date) < new Date();
this.poll.is_archived = this.isArchived; this.poll.is_archived = this.isArchived;
this.poll.choices_grouped.map((elem) => (elem.subSetToYes = false));
} }
}); });

View File

@ -2,13 +2,19 @@
<div class="date-choices" *ngIf="poll.kind == 'date'"> <div class="date-choices" *ngIf="poll.kind == 'date'">
<div class="box" *ngFor="let group of poll.choices_grouped"> <div class="box" *ngFor="let group of poll.choices_grouped">
<h3 class="title is-3"> <h3 class="title is-3">
<button
class="icon button padded"
(click)="toggleAllOfChoice(group)"
[ngClass]="{ 'has-background-primary': group.subSetToYes }"
>
<i class="fa fa-check-circle-o fa"></i>
</button>
{{ showAsDate(group.date_string) | date: 'fullDate':'Europe/Paris':'fr_FR' }} {{ showAsDate(group.date_string) | date: 'fullDate':'Europe/Paris':'fr_FR' }}
</h3> </h3>
<div class="time-slice-choice" *ngFor="let choice of group.choices"> <div class="time-slice-choice" *ngFor="let choice of group.choices">
<div class="columns is-vcentered is-mobile"> <div class="columns is-vcentered is-mobile">
<div class="column"> <div class="column">
<label class="label"> <label class="label">
<!-- {{choice.id}} )-->
{{ choice.name }} {{ choice.name }}
</label> </label>
</div> </div>

View File

@ -16,7 +16,6 @@ import { StorageService } from '../../../core/services/storage.service';
export class PollResultsCompactComponent implements OnInit { export class PollResultsCompactComponent implements OnInit {
@Input() public poll: Poll; @Input() public poll: Poll;
public answerEnum = Answer; public answerEnum = Answer;
constructor(private modalService: ModalService, private storageService: StorageService) {} constructor(private modalService: ModalService, private storageService: StorageService) {}
ngOnInit(): void { ngOnInit(): void {
@ -35,4 +34,19 @@ export class PollResultsCompactComponent implements OnInit {
showAsDate(date_string: string) { showAsDate(date_string: string) {
return new Date(date_string); return new Date(date_string);
} }
toggleAllOfChoice(groupe: any) {
console.log('groupe', groupe);
if (!groupe.subSetToYes) {
this.storageService.setAllSubchoicesTo(groupe, 'yes');
groupe.subSetToYes = true;
} else {
this.storageService.setAllSubchoicesTo(groupe, '');
groupe.subSetToYes = false;
}
// savoir si on a déjà tout mis en "yes"
// si oui, on enlève toutes les réponses
// autrement on met tout à "yes"
}
} }

View File

@ -8,7 +8,7 @@
<!-- {{choice.id}}--> <!-- {{choice.id}}-->
<span class="label" *ngIf="poll.kind == 'text'">{{ choice.name }} </span> <span class="label" *ngIf="poll.kind == 'text'">{{ choice.name }} </span>
<span class="label" *ngIf="poll.kind == 'date'"> <span class="label" *ngIf="poll.kind == 'date'">
{{ choice.name | date: 'short':'Europe/Paris':'fr_FR' }} {{ make_date(choice.name) | date: 'fullDate':'Europe/Paris':'fr_FR' }}
</span> </span>
</th> </th>
</tr> </tr>

View File

@ -10,6 +10,11 @@
background: #ffd7d7; background: #ffd7d7;
} }
table {
overflow: scroll;
max-width: 90vw !important;
display: block;
}
table { table {
th, th,
th * { th * {

View File

@ -1,6 +1,5 @@
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { Answer } from '../../../core/enums/answer.enum';
import { Poll } from '../../../core/models/poll.model'; import { Poll } from '../../../core/models/poll.model';
import { PollService } from '../../../core/services/poll.service'; import { PollService } from '../../../core/services/poll.service';
@ -24,4 +23,10 @@ export class PollResultsDetailedComponent {
} }
return null; return null;
} }
make_date(name: string) {
name = name.substr(0, 24);
console.log('name.length', name.length, name);
return new Date(name);
}
} }

View File

@ -3,12 +3,12 @@
// The list of file replacements can be found in `angular.json`. // The list of file replacements can be found in `angular.json`.
const backendApiUrlsInDev = { const backendApiUrlsInDev = {
local: 'http://tktest.lan/api/v1', local: 'http://127.0.0.1:8000/api/v1',
remote: 'http://tktest.lan/api/v1', remote: 'http://127.0.0.1:8000/api/v1',
// remote: 'https://framadate-api.cipherbliss.com/api/v1', // remote: 'https://framadate-api.cipherbliss.com/api/v1',
}; };
const apiV1 = { const apiV1 = {
baseHref: 'http://tktest.lan/api/v1', baseHref: 'http://127.0.0.1:8000/api/v1',
// baseHref: 'https://framadate-api.cipherbliss.com/api/v1', // baseHref: 'https://framadate-api.cipherbliss.com/api/v1',
api_new_poll: '/poll/', api_new_poll: '/poll/',
api_get_poll: '/poll/{id}', api_get_poll: '/poll/{id}',
@ -18,7 +18,7 @@ const apiV1 = {
}; };
export const environment = { export const environment = {
frontDomain: 'http://tktest.lan', frontDomain: 'http://127.0.0.1:8000',
production: false, production: false,
display_routes: false, display_routes: false,
autofill: true, autofill: true,