Skip to content

Commit

Permalink
Task advanced : add the possibility to create non-repetitive card (#7379
Browse files Browse the repository at this point in the history
)

Signed-off-by: vlo-rte <[email protected]>
  • Loading branch information
vlo-rte committed Oct 18, 2024
1 parent bb70747 commit 832b0cb
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const NB_MILLISECONDS_IN_ONE_MINUTE = 60000; // 1 minute

export function getNextTimeForRepeating(card: Card, startingDate?: number): number {
let nextTime = -1;

if (startingDate == null) {
startingDate = new Date().valueOf();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class RRuleReminderService implements EventListener {
const reminderItem = await this.databaseService.getReminder(card.id);
if (reminderItem != null) {
if (reminderItem.cardUid === card.uid) {
// reminder exists , a remind has just occur , we need to set the reminder for next occurrence
// reminder exists, a reminder has just occur, we need to set the reminder for next occurrence
this.logger.debug(
`RRuleReminder - Card ${card.id} (uid=${card.uid}) reminder exist for this uid , it means a remind just occurs , set next remind date`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class TaskCardTemplate extends HTMLElement {
<br/>
${opfab.utils.getTranslation('builtInTemplate.taskCard.duration')}: ${this.taskCardTemplateView.getDurationInMinutes()} ${opfab.utils.getTranslation('builtInTemplate.taskCard.minutes')} <br/>
<br/>
${this.taskCardTemplateView.getDateForCardWithoutRecurrence()}
${opfab.utils.getTranslation('builtInTemplate.taskCard.at')} ${this.taskCardTemplateView.getHourAndMinutes()}
<span id="bysetpos"></span><span id="byweekday"></span><br/>
<br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* This file is part of the OperatorFabric project.
*/

import {DateTimeFormatterService} from '../../../services/date-time-formatter.service';

declare const opfab;

export class TaskCardTemplateView {
Expand Down Expand Up @@ -36,12 +38,26 @@ export class TaskCardTemplateView {
}

public getDurationInMinutes(): number {
return opfab.currentCard.getCard()?.rRule?.durationInMinutes;
return (
opfab.currentCard.getCard()?.rRule?.durationInMinutes ?? opfab.currentCard.getCard()?.data.durationInMinutes
);
}

public getDateForCardWithoutRecurrence(): string {
if (opfab.currentCard.getCard()?.rRule?.freq) return '';
return 'On ' + DateTimeFormatterService.getFormattedDate(opfab.currentCard.getCard()?.startDate, 'dd/MM/yyyy');
}

public getHourAndMinutes(): string {
const hour = opfab.currentCard.getCard()?.rRule?.byhour[0]?.toString().padStart(2, '0');
const minute = opfab.currentCard.getCard()?.rRule?.byminute[0]?.toString().padStart(2, '0');
let hour, minute;

if (opfab.currentCard.getCard()?.rRule) {
hour = opfab.currentCard.getCard().rRule.byhour[0]?.toString().padStart(2, '0');
minute = opfab.currentCard.getCard().rRule.byminute[0]?.toString().padStart(2, '0');
} else {
hour = new Date(opfab.currentCard.getCard()?.startDate).getHours().toString().padStart(2, '0');
minute = new Date(opfab.currentCard.getCard()?.startDate).getMinutes().toString().padStart(2, '0');
}
return hour + ':' + minute;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class TaskUserCardTemplate extends BaseUserCardTemplate {
<br/>
<div>
<table style="width: 30%;margin-bottom: -5px;">
<table style="width: 60%;margin-bottom: -5px;">
<tr>
<td>
<label class="opfab-radio-button"> <span> ${opfab.utils.getTranslation('builtInTemplate.taskUserCard.dailyFreq')} </span>
Expand All @@ -81,6 +81,12 @@ export class TaskUserCardTemplate extends BaseUserCardTemplate {
<span class="opfab-radio-button-checkmark"></span>
</label>
</td>
<td>
<label class="opfab-radio-button"> <span> ${opfab.utils.getTranslation('builtInTemplate.taskUserCard.withoutRecurrence')} </span>
<input type="radio" id="radioButtonWithoutRecurrence">
<span class="opfab-radio-button-checkmark"></span>
</label>
</td>
</tr>
</table>
</div>
Expand Down Expand Up @@ -110,7 +116,7 @@ export class TaskUserCardTemplate extends BaseUserCardTemplate {
<br/>
</div>
<div class="opfab-border-box">
<div class="opfab-border-box" id="monthsCheckboxes">
<table width="100%" style="margin-bottom: -5px;">
<tr>
<td><label class="opfab-checkbox" style="padding-left:25px">${opfab.utils.getTranslation('builtInTemplate.taskUserCard.selectAll')} <input type="checkbox" id="selectAllMonths"> <span class="opfab-checkbox-checkmark"> </span> </label> </td>
Expand Down Expand Up @@ -211,18 +217,18 @@ export class TaskUserCardTemplate extends BaseUserCardTemplate {
<table style="width:65%">
<tr>
<td style="width:6%">
<td style="width:6%" id="atCell">
${opfab.utils.getTranslation('builtInTemplate.taskUserCard.at')} :
</td>
<td style="width:15%">
<td style="width:15%" id="timeCell">
<div class="opfab-input">
<label> ${opfab.utils.getTranslation('builtInTemplate.taskUserCard.time')} </label>
<input type="time" id="time" style="text-align:center" value=${this.view.getByHourAndMinutes()} >
</div>
</td>
<td style="width:6%">
<td style="width:6%" id="separatorCell">
</td>
<td style="width:22%">
<div class="opfab-input">
Expand Down Expand Up @@ -253,29 +259,37 @@ export class TaskUserCardTemplate extends BaseUserCardTemplate {
this.initEventListeners();
this.initInitialDates();
this.initTimeForRecurrence();
this.doWeHaveToDisplayMonthlyFreqInEditMode();
this.displayWithoutRecurrenceUIInEditModeIfNeeded();
this.displayMonthlyFreqUIInEditModeIfNeeded();
this.checkIsAllDaysSelected();
this.checkIsAllMonthsSelected();
this.selectAllDaysIfInCreateMode();
this.selectAllMonthsIfInCreateMode();
}

displayDailyFrequency() {
displayDailyFrequencyUI() {
(<HTMLInputElement>document.getElementById('radioButtonDailyFreq')).checked = true;
(<HTMLInputElement>document.getElementById('radioButtonMonthlyFreq')).checked = false;
(<HTMLInputElement>document.getElementById('radioButtonWithoutRecurrence')).checked = false;
document.getElementById('daysOfWeek').hidden = false;
document.getElementById('dayPositionInTheMonth').hidden = true;
document.getElementById('monthsCheckboxes').hidden = false;
document.getElementById('monthsCheckboxesForMonthlyFreq').hidden = true;
document.getElementById('monthsCheckboxesForDailyFreq').hidden = false;
this.displayTimeInput();
this.checkIsAllMonthsSelected();
}

displayMonthlyFrequency() {
displayMonthlyFrequencyUI() {
(<HTMLInputElement>document.getElementById('radioButtonDailyFreq')).checked = false;
(<HTMLInputElement>document.getElementById('radioButtonMonthlyFreq')).checked = true;
(<HTMLInputElement>document.getElementById('radioButtonWithoutRecurrence')).checked = false;
document.getElementById('daysOfWeek').hidden = true;
document.getElementById('monthsCheckboxes').hidden = false;
document.getElementById('monthsCheckboxesForDailyFreq').hidden = true;
document.getElementById('monthsCheckboxesForMonthlyFreq').hidden = false;
document.getElementById('dayPositionInTheMonth').hidden = false;
this.displayTimeInput();
this.checkIsAllMonthsSelected();

if (
Expand All @@ -287,6 +301,39 @@ export class TaskUserCardTemplate extends BaseUserCardTemplate {
}
}

displayWithoutRecurrenceUI() {
(<HTMLInputElement>document.getElementById('radioButtonDailyFreq')).checked = false;
(<HTMLInputElement>document.getElementById('radioButtonMonthlyFreq')).checked = false;
(<HTMLInputElement>document.getElementById('radioButtonWithoutRecurrence')).checked = true;
document.getElementById('daysOfWeek').hidden = true;
document.getElementById('monthsCheckboxesForDailyFreq').hidden = true;
document.getElementById('monthsCheckboxesForMonthlyFreq').hidden = true;
document.getElementById('dayPositionInTheMonth').hidden = true;
document.getElementById('monthsCheckboxes').hidden = true;
this.hideTimeInput();
this.checkIsAllMonthsSelected();

if (
opfab.currentUserCard.getEditionMode() === 'CREATE' &&
this.hasMonthlyFreqAlreadyBeenDisplayedInCreateMode === false
) {
this.hasMonthlyFreqAlreadyBeenDisplayedInCreateMode = true;
this.selectAllMonthsIfInCreateMode();
}
}

displayTimeInput() {
document.getElementById('atCell').hidden = false;
document.getElementById('timeCell').hidden = false;
document.getElementById('separatorCell').hidden = false;
}

hideTimeInput() {
document.getElementById('atCell').hidden = true;
document.getElementById('timeCell').hidden = true;
document.getElementById('separatorCell').hidden = true;
}

displayNthDayTable() {
(<HTMLInputElement>document.getElementById('radioButtonNthWeekday')).checked = false;
(<HTMLInputElement>document.getElementById('radioButtonNthDay')).checked = true;
Expand Down Expand Up @@ -332,11 +379,11 @@ export class TaskUserCardTemplate extends BaseUserCardTemplate {
});
}

doWeHaveToDisplayMonthlyFreqInEditMode() {
displayMonthlyFreqUIInEditModeIfNeeded() {
const freq = this.view.getFrequency();

if (freq === 'MONTHLY') {
this.displayMonthlyFrequency();
this.displayMonthlyFrequencyUI();
if (opfab.currentUserCard.getEditionMode() !== 'CREATE') {
this.selectValuesInEditModeForMonthlyFreq();
}
Expand All @@ -345,6 +392,12 @@ export class TaskUserCardTemplate extends BaseUserCardTemplate {
}
}

displayWithoutRecurrenceUIInEditModeIfNeeded() {
if (opfab.currentUserCard.getEditionMode() !== 'CREATE' && this.view.getFrequency() === undefined) {
(<HTMLInputElement>document.getElementById('radioButtonWithoutRecurrence')).click();
}
}

selectAllDaysIfInCreateMode() {
if (opfab.currentUserCard.getEditionMode() === 'CREATE') {
(<HTMLInputElement>document.getElementById('selectAllDays')).click();
Expand Down Expand Up @@ -446,10 +499,13 @@ export class TaskUserCardTemplate extends BaseUserCardTemplate {
initEventListeners() {
const that = this;
document.querySelector('#radioButtonDailyFreq').addEventListener('click', function () {
that.displayDailyFrequency();
that.displayDailyFrequencyUI();
});
document.querySelector('#radioButtonMonthlyFreq').addEventListener('click', function () {
that.displayMonthlyFrequency();
that.displayMonthlyFrequencyUI();
});
document.querySelector('#radioButtonWithoutRecurrence').addEventListener('click', function () {
that.displayWithoutRecurrenceUI();
});

document.querySelector('#selectAllDays').addEventListener('click', function () {
Expand Down Expand Up @@ -558,22 +614,41 @@ export class TaskUserCardTemplate extends BaseUserCardTemplate {
};
}
} else {
freq = 'DAILY';
byweekday = this.fetchWeekDay();
bymonth = this.fetchMonthDaily();
if ((<HTMLInputElement>document.getElementById('radioButtonDailyFreq')).checked === true) {
freq = 'DAILY';
byweekday = this.fetchWeekDay();
bymonth = this.fetchMonthDaily();

if (byweekday.length === 0) {
return {
valid: false,
errorMsg: opfab.utils.getTranslation('builtInTemplate.taskUserCard.youMustProvideAtLeastOneWeekday')
};
}
if (byweekday.length === 0) {
return {
valid: false,
errorMsg: opfab.utils.getTranslation(
'builtInTemplate.taskUserCard.youMustProvideAtLeastOneWeekday'
)
};
}

if (bymonth.length === 0) {
return {
valid: false,
errorMsg: opfab.utils.getTranslation('builtInTemplate.taskUserCard.youMustProvideAtLeastOneMonth')
};
if (bymonth.length === 0) {
return {
valid: false,
errorMsg: opfab.utils.getTranslation(
'builtInTemplate.taskUserCard.youMustProvideAtLeastOneMonth'
)
};
}
} else {
return this.view.getSpecificCardInformation(
taskTitle,
quillTaskDescriptionEditor,
null,
durationInMinutes,
minutesForReminder,
null,
null,
null,
bymonthday,
null
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,25 @@ export class TaskUserCardTemplateView {
bymonthday: number[],
time: string
) {
const byhour = [parseInt(time.slice(0, 2))]; // the hours are the 2 first characters
const byminute = [parseInt(time.slice(-2))]; // the minutes are the 2 last characters

const rRule = {
freq: freq,
byweekday: byweekday,
byhour: byhour,
byminute: byminute,
durationInMinutes: durationInMinutes,
bymonth: bymonth,
bysetpos: bysetpos,
bymonthday: bymonthday
};
let byhour, byminute;
if (time) {
byhour = [parseInt(time.slice(0, 2))]; // the hours are the 2 first characters
byminute = [parseInt(time.slice(-2))]; // the minutes are the 2 last characters
}

let rRule;
if (freq) {
rRule = {
freq: freq,
byweekday: byweekday,
byhour: byhour,
byminute: byminute,
durationInMinutes: durationInMinutes,
bymonth: bymonth,
bysetpos: bysetpos,
bymonthday: bymonthday
};
}

const card = {
summary: {key: 'taskAdvanced.summary'},
Expand All @@ -43,14 +49,16 @@ export class TaskUserCardTemplateView {
data: {
taskTitle: taskTitle,
richTaskDescription: quillTaskDescriptionEditor.getContents(),
minutesForReminder: minutesForReminder
minutesForReminder: minutesForReminder,
durationInMinutes: durationInMinutes
},
rRule: rRule
};

return {
valid: true,
card: card
card: card,
viewCardInCalendar: freq ? undefined : true
};
}

Expand Down
1 change: 1 addition & 0 deletions ui/main/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@
"taskDescriptionLabel": "TASK DESCRIPTION",
"dailyFreq": "Daily frequency",
"monthlyFreq": "Monthly frequency",
"withoutRecurrence": "Without recurrence",
"Repeat": "REPEAT EVERY",
"selectAll": "Select all",
"ordinalDay": "Nth day",
Expand Down
1 change: 1 addition & 0 deletions ui/main/src/assets/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@
"taskDescriptionLabel": "DESCRIPTION DE LA TÂCHE",
"dailyFreq": "Répétition quotidienne",
"monthlyFreq": "Répétition mensuelle",
"withoutRecurrence": "Sans récurrence",
"Repeat": "RÉPÉTER CHAQUE",
"selectAll": "Sélectionner tout",
"ordinalDay": "Numéro de jour",
Expand Down
1 change: 1 addition & 0 deletions ui/main/src/assets/i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@
"taskDescriptionLabel": "TAAK BESCHRIJVING",
"dailyFreq": "Dagelijkse frequentie",
"monthlyFreq": "Maandelijkse frequentie",
"withoutRecurrence": "Zonder herhaling",
"Repeat": "HERHAAL ELKE",
"selectAll": "Alles selecteren",
"ordinalDay": "N-de dag",
Expand Down

0 comments on commit 832b0cb

Please sign in to comment.