src/app/pages/dates/dates.component.ts
selector | framadate-dates |
styleUrls | ./dates.component.scss |
templateUrl | ./dates.component.html |
Properties |
Methods |
constructor(config: ConfigService, cd: ChangeDetectorRef, messageService: MessageService, dateUtilities: DateUtilities, document: any)
|
||||||||||||||||||
Defined in src/app/pages/dates/dates.component.ts:19
|
||||||||||||||||||
Parameters :
|
addDate |
addDate()
|
Defined in src/app/pages/dates/dates.component.ts:47
|
Returns :
void
|
addIntervalOfDates |
addIntervalOfDates()
|
Defined in src/app/pages/dates/dates.component.ts:117
|
add all the dates between the start and end dates in the interval section
Returns :
void
|
addTime |
addTime()
|
Defined in src/app/pages/dates/dates.component.ts:64
|
change time spans
Returns :
void
|
addTimeToDate |
addTimeToDate(config: any, id: number)
|
Defined in src/app/pages/dates/dates.component.ts:89
|
add a time period to a specific date choice, focus on the new input
Returns :
void
|
countDays |
countDays()
|
Defined in src/app/pages/dates/dates.component.ts:30
|
Returns :
void
|
emptyAll |
emptyAll()
|
Defined in src/app/pages/dates/dates.component.ts:102
|
remove all input contents, does not reset to default
Returns :
void
|
ngOnInit |
ngOnInit()
|
Defined in src/app/pages/dates/dates.component.ts:40
|
set the interval options
Returns :
void
|
removeAllTimes |
removeAllTimes()
|
Defined in src/app/pages/dates/dates.component.ts:74
|
Returns :
void
|
resetTimes |
resetTimes()
|
Defined in src/app/pages/dates/dates.component.ts:78
|
Returns :
void
|
checkValidity |
checkValidity()
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:21
|
Returns :
boolean
|
displayErrorMessage |
displayErrorMessage()
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:27
|
Returns :
boolean
|
ngOnInit |
ngOnInit()
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:17
|
Returns :
void
|
Public config |
Type : ConfigService
|
Defined in src/app/pages/dates/dates.component.ts:21
|
endDateInterval |
Type : any
|
Defined in src/app/pages/dates/dates.component.ts:19
|
intervalDays |
Type : any
|
Defined in src/app/pages/dates/dates.component.ts:17
|
intervalDaysDefault |
Type : number
|
Default value : 7
|
Defined in src/app/pages/dates/dates.component.ts:18
|
showDateInterval |
Type : boolean
|
Default value : true
|
Defined in src/app/pages/dates/dates.component.ts:15
|
startDateInterval |
Type : any
|
Defined in src/app/pages/dates/dates.component.ts:16
|
Public config |
Type : ConfigService
|
Inherited from
BaseComponent
|
Defined in
BaseComponent:14
|
import {ChangeDetectorRef, Component, Inject, OnInit} from '@angular/core';
import {ConfigService} from '../../services/config.service';
import {BaseComponent} from '../base-page/base.component';
import {DOCUMENT} from '@angular/common';
import {MessageService} from "primeng/api";
import {otherDefaultDates} from "../../config/defaultConfigs";
import {DateUtilities} from "../../config/DateUtilities";
@Component({
selector: 'framadate-dates',
templateUrl: './dates.component.html',
styleUrls: ['./dates.component.scss']
})
export class DatesComponent extends BaseComponent implements OnInit {
showDateInterval: boolean = true;
startDateInterval: any;
intervalDays: any;
intervalDaysDefault: number = 7;
endDateInterval: any;
constructor(public config: ConfigService,
private cd: ChangeDetectorRef,
private messageService: MessageService,
private dateUtilities: DateUtilities,
@Inject(DOCUMENT) private document: any
) {
super(config);
}
countDays() {
// compute the number of days in the date interval
if (this.endDateInterval && this.startDateInterval) {
this.intervalDays = (this.dateUtilities.dayDiff(this.endDateInterval, this.startDateInterval)).toFixed(0)
}
}
/**
* set the interval options
*/
ngOnInit() {
let dateCurrent = new Date();
const dateJson = dateCurrent.toISOString();
this.startDateInterval = dateJson.substring(0, 10);
this.endDateInterval = this.dateUtilities.addDaysToDate(this.intervalDaysDefault, dateCurrent).toISOString().substring(0, 10);
}
addDate() {
this.config.dateList.push({
literal: '',
date_object: new Date(),
timeList: []
});
let selector = '[ng-reflect-name="dateChoices_' + (this.config.dateList.length - 1) + '"]';
this.cd.detectChanges();
const elem = this.document.querySelector(selector);
if (elem) {
elem.focus();
}
}
/**
* change time spans
*/
addTime() {
this.config.timeList.push(
{
literal: '',
timeList: [],
date_object: new Date()
}
);
}
removeAllTimes() {
this.config.timeList = [];
}
resetTimes() {
this.config.timeList = otherDefaultDates;
}
/**
* add a time period to a specific date choice,
* focus on the new input
* @param config
* @param id
*/
addTimeToDate(config: any, id: number) {
config.timeList.push({literal: ''});
let selector = '[ng-reflect-name="dateTime_' + id + '_Choices_' + (config.timeList.length - 1) + '"]';
this.cd.detectChanges();
const elem = this.document.querySelector(selector);
if (elem) {
elem.focus();
}
}
/**
* remove all input contents, does not reset to default
*/
emptyAll() {
this.config.dateList.forEach(element => {
element.literal = '';
element.date_object = new Date();
element.timeList = ['', '', ''];
});
this.config.timeList.forEach(element => {
element.literal = '';
});
}
/**
* add all the dates between the start and end dates in the interval section
*/
addIntervalOfDates() {
let newIntervalArray = this.dateUtilities.getDatesInRange(this.startDateInterval, this.endDateInterval, 1);
const converted = [];
newIntervalArray.forEach(element => {
converted.push({
literal: element.literal,
date_object: element.date_object,
timeList: []
});
});
this.config.dateList = [...new Set(converted)]; // add only dates that are not already present with a Set of unique items
this.showDateInterval = false;
this.messageService.add({
severity: 'success',
summary: 'Dates ajoutées',
detail: `les dates ont été ajoutées aux réponses possibles`
});
}
}
<div i18n >
{{"dates.title"|translate}}
</div >
<div >
<label for="multi_hours" >
<span >
{{"dates.hours_different"|translate}}
</span >
<select
[(ngModel)]="config.allowSeveralHours"
id="multi_hours"
name="multi_hours"
>
<option value=true >{{"dates.multiple.different"|translate}}</option >
<option value=false >{{"dates.multiple.identical"|translate}}</option >
</select >
<span i18n >
{{"dates.hours_each_day"|translate}}
</span >
</label >
</div >
<button
(click)="addDate()"
class="btn btn--primary"
id="add_date_button"
>
<i class='fa fa-plus' ></i >
{{"dates.add"|translate}}
</button >
<button
(click)="showDateInterval = !showDateInterval "
[ngClass]="{active: showDateInterval}"
class="btn btn--primary"
id="toggle_interval_button"
>
<i class='fa fa-clock-o' ></i >
{{"dates.add_interval"|translate}}
</button >
<button
(click)="emptyAll()"
class="btn btn--warning"
id="empty_button"
>
<i class='fa fa-trash' ></i >
{{"dates.empty"|translate}}
</button >
<section
*ngIf="showDateInterval"
class="date-interval " >
<!-- TODO à mettre en popup-->
<hr >
<h2 > {{"dates.add_interval"|translate}}</h2 >
<p >
{{"dates.interval_propose"|translate}}
<input
(change)="countDays()"
[(ngModel)]="startDateInterval"
type="date" >
{{"dates.interval_span"|translate}}
<input
(change)="countDays()"
[(ngModel)]="endDateInterval"
type="date" >
<br >
</p >
<button
(click)="addIntervalOfDates()"
class="btn btn-block btn--primary" >
<i class='fa fa-plus' ></i >
{{"dates.interval_button"|translate}}
{{intervalDays}}
{{"dates.interval_button_dates"|translate}}
</button >
<hr >
</section >
<div class='columns' >
<div class='column' >
<div class="dates-list " >
<div class='title' >
<span class="count-dates" >
{{config.timeList.length}}
</span >
<span class="count-dates-txt " >
{{"dates.count_time"|translate}}
(pour chaque jour)
</span >
</div >
<div class='actions' >
<button
(click)="addTime()"
*ngIf=" 'false' === config.allowSeveralHours "
class="btn btn--primary"
id="add_time_button"
>
<i class='fa fa-plus' ></i >
{{"dates.add_time"|translate}}
</button >
<button
(click)="removeAllTimes()"
*ngIf=" 'false' === config.allowSeveralHours "
class="btn btn--warning"
id="remove_time_button"
>
<i class='fa fa-trash' ></i >
Aucune plage horaire
</button >
<button
(click)="resetTimes()"
*ngIf=" 'false' === config.allowSeveralHours"
class="btn btn--warning"
id="reset_time_button"
>
<i class='fa fa-refresh' ></i >
réinitialiser
</button >
</div >
<div
*ngIf=" 'false' === config.allowSeveralHours"
class="identical-dates"
>
<div
*ngFor="let time of config.timeList; index as id"
class="time-choice"
>
<label for='timeChoices_{{id}}' >
<i class='fa fa-clock-o' ></i >
</label >
<input
[(ngModel)]="time.literal"
name="timeChoices_{{id}}"
type="text"
id='timeChoices_{{id}}'
>
<button
(click)="time.timeList.splice(id, 1)"
class="btn btn-warning" ><i class="fa fa-times" ></i >
</button >
</div >
</div >
<hr >
<span class="count-dates title" >
{{config.dateList.length}}
</span >
<span >
{{"dates.count_dates"|translate}}
</span >
<button
class='btn btn--primary'
(click)='addDate()' >
{{"dates.add"|translate}}
</button >
<div
*ngFor="let choice of config.dateList; index as id"
class="date-choice"
>
{{id}})
<input
[(ngModel)]="choice.date_object"
name="dateChoices_{{id}}"
id="dateChoices_{{id}}"
useValueAsDate
type="date"
>
<button
(click)="config.dateList.splice(id, 1)"
class="btn btn-warning"
><i class="fa fa-times" ></i >
</button >
<button
(click)="addTimeToDate(choice, id)"
*ngIf=" 'true' === config.allowSeveralHours"
class="btn btn--primary"
>
{{"dates.add_time"|translate}}
</button >
<div
*ngIf=" 'true' === config.allowSeveralHours"
class="several-times"
>
<pre class='debug padded warning' >
choice.timeList :
{{choice.timeList|json}}
</pre >
<h2 >Several hours</h2 >
<div
*ngFor="let timeItem of choice.timeList; index as idTime"
class="time-choice"
>
<input
[(ngModel)]="timeItem.literal"
name="dateTime_{{id}}_Choices_{{idTime}}"
id="dateTime_{{id}}_Choices_{{idTime}}"
type="text"
>
<button
(click)="choice.timeList.splice(idTime, 1)"
class="btn btn-warning"
><i class="fa fa-times" ></i >
</button >
</div >
</div >
</div >
</div >
</div >
<div class='column' >
<framadate-resume ></framadate-resume >
</div >
</div >
<a
[routerLink]="'/step/resume'"
class="btn btn--full btn--primary"
>
C'est parfait!
</a >
<a
[routerLink]="'/step/home'"
class="prev"
>
Retour
</a >
./dates.component.scss
.several-times {
padding-left: 1em;
}
.date-interval {
padding: 1em;
margin-bottom: 1em;
}
.title {
font-size: 1.5rem;
}
:host {
input, button {
+ button {
margin-left: 1em;
}
}
}