Skip to content

Commit

Permalink
Merge pull request #35 from Kartones/task-end-time
Browse files Browse the repository at this point in the history
due_time -> start_time + end_time
  • Loading branch information
Kartones authored Jul 17, 2020
2 parents eddc9dd + 2a9e00b commit 38cb1b2
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 41 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ HTML inputs are favoring HTML5 ones instead of fancy jquery-like plugins to redu

Other requirements are on the `requirements.txt` file. Install them with `pip` or similar.

## Data Migrations

Starting with version `v1.0`, there is a `\scripts` folder that will contain any required migrations. They will be listed here in this section to simplify things.

### Migrations

- `data_migration_001`: **`v0.9` -> `v1.0`**. Not backwards compatible once migrated. Must be run before `v1.0` logic or server will throw errors and maybe could override old `due_time` fields.

## Docker Environment

- Development strongly encourages using Docker and Docker Compose.
Expand Down
12 changes: 6 additions & 6 deletions data/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"title": "Task title",
"id": 0,
"color": "#039BE5",
"due_time": "00:00",
"start_time": "00:00","end_time": "00:00",
"is_all_day": true
},
{
"details": "Task 2 details",
"title": "Task #2",
"id": 1,
"color": "#EF6C00",
"due_time": "15:30",
"start_time": "15:30","end_time": "15:30",
"is_all_day": false
}
]
Expand All @@ -32,7 +32,7 @@
"title": "Repetitive weekly weekday",
"id": 0,
"color": "#B19CDA",
"due_time": "00:00",
"start_time": "00:00","end_time": "00:00",
"repetition_subtype": "w",
"is_all_day": true
},
Expand All @@ -43,7 +43,7 @@
"title": "Repetitive monthly weekday",
"id": 1,
"color": "#53A93F",
"due_time": "00:00",
"start_time": "00:00","end_time": "00:00",
"repetition_subtype": "w",
"is_all_day": true
},
Expand All @@ -54,7 +54,7 @@
"title": "Repetitive monthly monthday",
"id": 2,
"color": "#777777",
"due_time": "00:00",
"start_time": "00:00","end_time": "00:00",
"repetition_subtype": "m",
"is_all_day": true
},
Expand All @@ -65,7 +65,7 @@
"title": "Repetitive weekly weekday",
"id": 3,
"color": "#785649",
"due_time": "19:30",
"start_time": "19:30","end_time": "19:30",
"repetition_subtype": "w",
"is_all_day": false
}
Expand Down
14 changes: 7 additions & 7 deletions data/sample2.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"repetition_value": 0,
"details": "every monday (all day task)",
"title": "Repetitive weekly weekday",
"due_time": "00:00",
"start_time": "00:00","end_time": "00:00",
"color": "#B19CDA",
"repetition_subtype": "w",
"is_all_day": true,
Expand All @@ -16,7 +16,7 @@
"repetition_value": 5,
"details": "1st saturday of the month",
"title": "Repetitive monthly weekday",
"due_time": "00:00",
"start_time": "00:00","end_time": "00:00",
"color": "#53A93F",
"repetition_subtype": "w",
"is_all_day": true,
Expand All @@ -27,7 +27,7 @@
"repetition_value": 1,
"details": "1st day of the month",
"title": "Repetitive monthly monthday",
"due_time": "00:00",
"start_time": "00:00","end_time": "00:00",
"color": "#777777",
"repetition_subtype": "m",
"is_all_day": true,
Expand All @@ -38,7 +38,7 @@
"repetition_value": 3,
"details": "every thursday at afternoon",
"title": "Repetitive weekly weekday",
"due_time": "19:30",
"start_time": "19:30","end_time": "19:30",
"color": "#785649",
"repetition_subtype": "w",
"is_all_day": false,
Expand All @@ -55,7 +55,7 @@
"color": "#53A93F",
"details": " ",
"title": "test 2222",
"due_time": "00:00",
"start_time": "00:00","end_time": "00:00",
"id": 1517683764,
"is_all_day": true
}
Expand All @@ -69,15 +69,15 @@
"color": "#039BE5",
"details": "Task details",
"title": "Task title",
"due_time": "00:00",
"start_time": "00:00","end_time": "00:00",
"is_all_day": true,
"id": 0
},
{
"color": "#EF6C00",
"details": "Task 2 details",
"title": "Task #2",
"due_time": "15:30",
"start_time": "15:30","end_time": "15:30",
"is_all_day": false,
"id": 1
}
Expand Down
12 changes: 8 additions & 4 deletions flask_calendar/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ def update_task_action(calendar_id: str, year: str, month: str, day: str, task_i
else:
updated_year = updated_month = updated_day = None
is_all_day = request.form.get("is_all_day", "0") == "1"
due_time = request.form["due_time"]
start_time = request.form["start_time"]
end_time = request.form.get("end_time", None)
details = request.form["details"].replace("\r", "").replace("\n", "<br>")
color = request.form["color"]
has_repetition = request.form.get("repeats", "0") == "1"
Expand All @@ -252,7 +253,8 @@ def update_task_action(calendar_id: str, year: str, month: str, day: str, task_i
day=updated_day,
title=title,
is_all_day=is_all_day,
due_time=due_time,
start_time=start_time,
end_time=end_time,
details=details,
color=color,
has_repetition=has_repetition,
Expand Down Expand Up @@ -287,7 +289,8 @@ def save_task_action(calendar_id: str) -> Response:
else:
year = month = day = None
is_all_day = request.form.get("is_all_day", "0") == "1"
due_time = request.form["due_time"]
start_time = request.form["start_time"]
end_time = request.form.get("end_time", None)
details = request.form["details"].replace("\r", "").replace("\n", "<br>")
color = request.form["color"]
has_repetition = request.form.get("repeats", "0") == "1"
Expand All @@ -303,7 +306,8 @@ def save_task_action(calendar_id: str) -> Response:
day=day,
title=title,
is_all_day=is_all_day,
due_time=due_time,
start_time=start_time,
end_time=end_time,
details=details,
color=color,
has_repetition=has_repetition,
Expand Down
6 changes: 4 additions & 2 deletions flask_calendar/calendar_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,23 @@ def create_task(
day: Optional[int],
title: str,
is_all_day: bool,
due_time: str,
start_time: str,
details: str,
color: str,
has_repetition: bool,
repetition_type: Optional[str],
repetition_subtype: Optional[str],
repetition_value: int,
end_time: Optional[str] = None,
) -> bool:
details = details if len(details) > 0 else "&nbsp;"
data = self.load_calendar(calendar_id)

new_task = {
"id": int(time.time()),
"color": color,
"due_time": due_time,
"start_time": start_time,
"end_time": end_time if end_time else start_time,
"is_all_day": is_all_day,
"title": title,
"details": details,
Expand Down
11 changes: 11 additions & 0 deletions flask_calendar/scripts/data_migration_001.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

if [[ $# -eq 0 ]] ; then
echo 'Must pass as an argument the data folder'
exit 0
fi
DATA_FOLDER=$1

find $DATA_FOLDER -name '*.json' -type f -exec sed -i 's/"due_time":\(\s\?"[0-9]\{1,2\}:[0-9]\{1,2\}"\)/"start_time":\1,"end_time":\1/g' {} \;

echo 'Migration of json data complete. Data files are not backwards compatible with versions previous to v1.0.'
4 changes: 4 additions & 0 deletions flask_calendar/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ li {
cursor: auto;
}

span.time {
font-size: 9px;
}

span.daynumber {
font-size: 13.5px;
font-weight: 400;
Expand Down
7 changes: 4 additions & 3 deletions flask_calendar/templates/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
{{ day.day }}</span>
<ul class="tasks">
{% if day.month|string in tasks and day.day|string in tasks[day.month|string] %}
{% for task in tasks[day.month|string][day.day|string]|sort(attribute="due_time") %}
{% for task in tasks[day.month|string][day.day|string]|sort(attribute="start_time") %}
<li
{% if day.month != month %}
class="task greyed"
Expand All @@ -72,7 +72,7 @@
{% if "repetition_type" in task %}data-recurrent="1"{% endif %}>

{% if not task["is_all_day"] %}
{{ task["due_time"] }}
<span class="time">{{ task["start_time"] }}{% if task["start_time"] != task["end_time"] %} - {{ task["end_time"] }}{% endif %}</span>
{% endif %}
{{ task["title"] }}
<p class="accordion-hidden">
Expand Down Expand Up @@ -324,7 +324,8 @@
return;
}
if (eventData.target.nodeName === "LI" && eventData.target.className === "task") {
ToggleDetails(eventData.target.children[0]);
// If is not "all day" there will be a span containing the time before the content
ToggleDetails(eventData.target.children[eventData.target.children.length - 1]);
return;
}
if (eventData.target.nodeName === "P" && (eventData.target.className === "accordion-hidden" ||
Expand Down
20 changes: 14 additions & 6 deletions flask_calendar/templates/task.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@
/>
<br/>

<div id="due_time_block"
<div id="start_time_block"
{% if task["is_all_day"] %}
class="hidden"
{% endif %}
>
<label for="due_time">Due time</label>
<input type="time" id="due_time" name="due_time" value="{{ task.get("due_time", "00:00") }}" />
<label for="start_time">Start time</label>
<input type="time" id="start_time" name="start_time" value="{{ task.get("start_time", "00:00") }}" />
<br/>
<label for="end_time">End time</label>
<input type="time" id="end_time" name="end_time" value="{{ task.get("end_time", "00:00") }}" />
<br/>
</div>

Expand Down Expand Up @@ -227,13 +230,18 @@
window.onload = function() {
document.getElementById("is_all_day").onclick = function(eventData) {
if (eventData.target.checked === true) {
document.getElementById("due_time_block").className = "hidden";
document.getElementById("due_time").value ="00:00";
document.getElementById("start_time_block").className = "hidden";
document.getElementById("start_time").value ="00:00";
document.getElementById("end_time").value ="00:00";
} else {
document.getElementById("due_time_block").className = "";
document.getElementById("start_time_block").className = "";
}
};

document.getElementById("start_time").onchange = function(eventData) {
document.getElementById("end_time").value = eventData.target.value;
}

document.getElementById("repeats").onclick = function(eventData) {
if (eventData.target.checked === true) {
document.getElementById("type_weekly").checked = true;
Expand Down
6 changes: 4 additions & 2 deletions test/fixtures/past_normal_tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"title": "A task",
"details": "Task details",
"id": 1,
"due_time": "00:00",
"start_time": "00:00",
"end_time": "00:00",
"color": "#000"
}
]
Expand All @@ -25,7 +26,8 @@
"title": "Another task",
"details": "Task details",
"id": 2,
"due_time": "15:30",
"start_time": "15:30",
"end_time": "16:00",
"color": "#EF6C00"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"title": "Repetitive monthly monthday",
"details": "1st day of the month",
"id": 2,
"due_time": "00:00",
"start_time": "00:00",
"end_time": "00:00",
"repetition_value": 1,
"repetition_subtype": "m",
"repetition_type": "m",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"title": "Repetitive monthly weekday",
"details": "1st saturday of the month",
"id": 1,
"due_time": "00:00",
"start_time": "00:00",
"end_time": "00:00",
"repetition_value": 5,
"repetition_subtype": "w",
"repetition_type": "m",
Expand Down
Loading

0 comments on commit 38cb1b2

Please sign in to comment.