empty and reset time slices

This commit is contained in:
Tykayn 2021-05-03 15:47:27 +02:00 committed by tykayn
parent af4dfacec9
commit 1d8aeb2f54
4 changed files with 66 additions and 31 deletions

View File

@ -34,7 +34,7 @@ export class StorageService {
public dateList: DateChoice[] = otherDefaultDates; public dateList: DateChoice[] = otherDefaultDates;
@LocalStorage() @LocalStorage()
public timeSlices: TimeSlices[] = basicSlicesOfDay; public timeSlices: TimeSlices[];
@LocalStorage() @LocalStorage()
public vote_stack: Stack = new Stack(); public vote_stack: Stack = new Stack();
@ -46,6 +46,7 @@ export class StorageService {
this.userPolls.push( this.userPolls.push(
new Poll(new Owner(), 'Démo: Réunion du département des chatons', 'aujourdhui-ou-demain') new Poll(new Owner(), 'Démo: Réunion du département des chatons', 'aujourdhui-ou-demain')
); );
// this.timeSlices = basicSlicesOfDay;
} }
} }

View File

@ -4,14 +4,6 @@
{{ 'choices.title' | translate }} {{ 'choices.title' | translate }}
</h2> </h2>
{{ 'dates.add' | translate }} {{ 'dates.add' | translate }}
<p>
<i>
{{ 'choices.helper' | translate }}
</i>
</p>
{{ 'choices.answer_preset_1' | translate }}
{{ 'choices.add' | translate }}
{{ 'choices.continue' | translate }}
<!-- interval--> <!-- interval-->
<button <button
@ -123,6 +115,12 @@
<span class="count-dates"> <span class="count-dates">
{{ timeList.length }} {{ timeList.length }}
</span> </span>
<button class="button is-warning" (click)="removeAllTimes()">
<i class="fa fa-trash"></i>
</button>
<button class="button is-info" (click)="resetTimes()">
<i class="fa fa-refresh"></i>
</button>
</div> </div>
<div class="identical-dates" cdkDropListGroup> <div class="identical-dates" cdkDropListGroup>
<div <div
@ -174,12 +172,16 @@
</div> </div>
</div> </div>
<div class="columns"> <div
class="columns days-list"
cdkDropList
[cdkDropListData]="dateList"
(cdkDropListDropped)="dropDayItem($event)"
>
<div class="column"> <div class="column">
<!-- TODO lier au formulaire les valeurs des dates--> <!-- TODO lier au formulaire les valeurs des dates-->
<h2>Dates</h2> <h2>Dates</h2>
<div *ngFor="let choice of dateList; index as id" class="date-choice"> <div *ngFor="let choice of dateList; index as id" class="date-choice" cdkDrag>
{{ id }})
<input <input
[(ngModel)]="choice.date_object" [(ngModel)]="choice.date_object"
name="dateChoices_{{ id }}" name="dateChoices_{{ id }}"

View File

@ -9,11 +9,11 @@ import { Router } from '@angular/router';
import { DOCUMENT } from '@angular/common'; import { DOCUMENT } from '@angular/common';
import { import {
DateChoice, DateChoice,
moreTimeOfDay, defaultTimeOfDay,
otherDefaultDates, otherDefaultDates,
TimeSlices, TimeSlices,
} from '../../../../../../mocks/old-stuff/config/defaultConfigs'; } from '../../../../../../mocks/old-stuff/config/defaultConfigs';
import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop'; import { moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { StorageService } from '../../../../core/services/storage.service'; import { StorageService } from '../../../../core/services/storage.service';
@ -55,14 +55,18 @@ export class DateSelectComponent implements OnInit {
this.timeList = this.storageService.timeSlices; this.timeList = this.storageService.timeSlices;
} }
ngOnInit(): void {
// this.setDefaultDatesForInterval();
}
get choices(): FormArray { get choices(): FormArray {
return this.form.get('choices') as FormArray; return this.form.get('choices') as FormArray;
} }
get dateChoices() {
return this.form.get('dateChoices') as FormArray;
}
ngOnInit(): void {
// this.setDefaultDatesForInterval();
}
/** /**
* default interval of dates proposed is from today to 7 days more * default interval of dates proposed is from today to 7 days more
*/ */
@ -137,10 +141,12 @@ export class DateSelectComponent implements OnInit {
removeAllTimes() { removeAllTimes() {
this.timeList = []; this.timeList = [];
this.toastService.display('périodes horaires vidées');
} }
resetTimes() { resetTimes() {
this.timeList = otherDefaultDates; this.timeList = defaultTimeOfDay;
this.toastService.display('périodes horaires réinitialisées');
} }
/** /**
@ -161,10 +167,6 @@ export class DateSelectComponent implements OnInit {
} }
} }
get dateChoices() {
return this.form.get('dateChoices') as FormArray;
}
addChoice(optionalLabel = ''): void { addChoice(optionalLabel = ''): void {
const newControlGroup = this.fb.group({ const newControlGroup = this.fb.group({
label: this.fb.control('', [Validators.required]), label: this.fb.control('', [Validators.required]),
@ -253,7 +255,21 @@ export class DateSelectComponent implements OnInit {
this.addChoice('abricot'); this.addChoice('abricot');
} }
dropTimeItem(event: any) { dropTimeItem(event: any): void {
// moveItemInArray(this.timeSlices, event.previousIndex, event.currentIndex);
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
transferArrayItem(
event.previousContainer.data,
event.container.data,
event.previousIndex,
event.currentIndex
);
}
}
dropDayItem(event: any): void {
// moveItemInArray(this.timeSlices, event.previousIndex, event.currentIndex); // moveItemInArray(this.timeSlices, event.previousIndex, event.currentIndex);
if (event.previousContainer === event.container) { if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex); moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);

View File

@ -7,13 +7,6 @@
{{ 'creation.title' | translate }} {{ 'creation.title' | translate }}
</h1> </h1>
</div> </div>
<!-- [disabled]="!form.valid || !form.valid"-->
<button class="btn is-success is-fixed-bottom" (click)="createPoll()">
<i class="fa fa-save"></i>
Enregistrer le sondage
</button>
</header> </header>
<main class="columns"> <main class="columns">
<div class="column"> <div class="column">
@ -62,6 +55,29 @@
</div> </div>
</div> </div>
</main> </main>
<p>
<i>
{{ 'choices.helper' | translate }}
</i>
</p>
{{ 'choices.answer_preset_1' | translate }}
{{ 'choices.add' | translate }}
{{ 'choices.continue' | translate }}
<button
[disabled]="!form.valid && form.touched"
class="btn is-success is-fixed-bottom"
(click)="createPoll()"
>
<i class="fa fa-save"></i>
Enregistrer le sondage (vérifier la validité)
</button>
<button class="btn is-success is-fixed-bottom" (click)="createPoll()">
<i class="fa fa-save"></i>
Enregistrer le sondage (sans vérifier)
</button>
<footer class="column" *ngIf="show_debug_data"> <footer class="column" *ngIf="show_debug_data">
<h2>Debug data</h2> <h2>Debug data</h2>
<pre class="debug padded warning"> <pre class="debug padded warning">