Skip to content

Commit

Permalink
Merge pull request #38 from gheinzer/gheinzer/issue11
Browse files Browse the repository at this point in the history
Added edit task feature. (This fixes issue Edit task feature request #11)
  • Loading branch information
gheinzer committed Nov 1, 2021
2 parents fa96a3c + 7464f59 commit c7e3503
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 21 deletions.
15 changes: 15 additions & 0 deletions public_html/js/checkForValues.js
Expand Up @@ -12,6 +12,20 @@ function checkForValuesInCreateTaskOverlay() {
document.getElementById("task_submit").disabled = true;
}
}
function checkForValuesInEditTaskOverlay() {
var values = 0;
if (document.getElementById("edit_task_description").value !== "") {
values += 1;
}
if (document.getElementById("edit_task_date").value !== "") {
values += 1;
}
if (values > 1) {
document.getElementById("edit_task_submit").disabled = false;
} else {
document.getElementById("edit_task_submit").disabled = true;
}
}
function checkForValuesInCreateCategoryOverlay() {
var values = 0;
if (document.getElementById("category_name").value !== "") {
Expand All @@ -23,6 +37,7 @@ function checkForValuesInCreateCategoryOverlay() {
document.getElementById("category_submit").disabled = true;
}
}

function checkForValuesInCreateTypeOverlay() {
var values = 0;
if (document.getElementById("type_name").value !== "") {
Expand Down
90 changes: 70 additions & 20 deletions public_html/js/ws.js
Expand Up @@ -92,7 +92,7 @@ function connect() {
case "updateAll":
todo_get_categories(function () {
todo_get_types(function () {
todo_get_tasks();
todo_get_tasks(hideLoader);
});
});
return;
Expand Down Expand Up @@ -167,6 +167,7 @@ function connect() {
html += `<option value="${element.ID}">${element.Name}</option>`;
});
document.getElementById("task_category").innerHTML = html;
document.getElementById("edit_task_category").innerHTML = html;

html = "";
categoryFilterIDs = [];
Expand Down Expand Up @@ -211,14 +212,15 @@ function connect() {
lastestActionCompleted = true;
if (callback) callback();
});
}
};
window.todo_get_types = function (callback) {
_getTypes(function (result) {
var html = "";
result.forEach((element) => {
html += `<option value="${element.ID}">${element.Name}</option>`;
});
document.getElementById("task_type").innerHTML = html;
document.getElementById("edit_task_type").innerHTML = html;

html = "";
typeFilterIDs = [];
Expand Down Expand Up @@ -264,7 +266,7 @@ function connect() {
lastestActionCompleted = true;
if (callback) callback();
});
}
};
window.todo_get_tasks = function (callback) {
_getTasks(function (result) {
result = result.sort(function (a, b) {
Expand All @@ -275,7 +277,7 @@ function connect() {
todo_update_tasks();
if (callback) callback();
});
}
};
function _reorderDate(date) {
date = date.split(".")[2] + date.split(".")[1] + date.split(".")[0];
return date;
Expand All @@ -289,7 +291,7 @@ function connect() {
document.getElementById("notfound_message").style.display = "none";
}
document.getElementById("tasks").innerHTML = html;
}
};
window.testForFilters = function () {
var html = "";
tasks.forEach((element, index) => {
Expand Down Expand Up @@ -374,6 +376,9 @@ function connect() {
<td>${categoryIDs[element.CategoryID]}</td>
<td>${desc}</td>
<td>${date}</td>
<td><img src="/assets/icons/edit_white_24dp.svg" alt="" class="todo_state_symbol" onclick="edit_Task(${
element.ID
})"></td>
</tr>`;
html += elementHTML;
} else if (searchFilter == "") {
Expand All @@ -383,13 +388,58 @@ function connect() {
<td>${categoryIDs[element.CategoryID]}</td>
<td>${element.Description}</td>
<td>${element.Date}</td>
<td><img src="/assets/icons/edit_white_24dp.svg" alt="" class="todo_state_symbol" onclick="edit_Task(${
element.ID
})"></td>
</tr>`;
html += elementHTML;
}
});
return html;
}

};
window.edit_Task = function (id) {
var taskDesc,
taskCategoryID,
taskTypeID,
taskDate = "";
tasks.forEach((element) => {
if (element.ID == id) {
taskDesc = element.Description;
var day = parseInt(element.Date.split(".")[0]) + 1;
var month = parseInt(element.Date.split(".")[1]) - 1; // Months begin at 0
var year = parseInt(element.Date.split(".")[2]);
taskDate = new Date(year, month, day);
taskCategoryID = element.CategoryID;
taskTypeID = element.TypeID;
}
});
document.getElementById("edit_task_category").value = taskCategoryID;
document.getElementById("edit_task_type").value = taskTypeID;
document.getElementById("edit_task_description").value = taskDesc;
document.getElementById("edit_task_date").valueAsDate = taskDate;
document.getElementById("edit_task_id").value = id;
showOverlay("editTaskOverlay");
checkForValuesInEditTaskOverlay();
};
window.submit_edited_task = function () {
var id = document.getElementById("edit_task_id").value;
var desc = document.getElementById("edit_task_description").value;
var type = document.getElementById("edit_task_type").value;
var category = document.getElementById("edit_task_category").value;
var duedate = document.getElementById("edit_task_date").value;
duedate = duedate.toString().split("-");
duedate = `${duedate[2]}.${duedate[1]}.${duedate[0]}`;
var data = {
id: id,
description: desc,
type: type,
category: category,
date: duedate,
};
socket.send("EDIT-TASK=" + JSON.stringify(data));
hideOverlay("editTaskOverlay");
showLoader();
};
function _getCategories(callback) {
socket.send("getCategories");
getCategoriesHandleAnswer = function (msg) {
Expand Down Expand Up @@ -445,7 +495,7 @@ function connect() {
document.getElementById("task_date").value = "";
});
});
}
};
function _addType(type_name, callback) {
socket.send(`ADD-TYPE=${type_name}`);
addTypeHandleAnswer = function () {
Expand All @@ -457,10 +507,10 @@ function connect() {
addCategoryHandleAnswer = function () {
if (callback) callback();
};
}
};
window.todo_toggle_state = function (id, state) {
socket.send(`TOGGLE_STATE=${id},${state}`);
}
};
window.todo_add_type = function () {
showLoader();
const type_name = document.getElementById("type_name").value;
Expand All @@ -469,7 +519,7 @@ function connect() {
hideOverlay("createTypeOverlay");
todo_get_types();
});
}
};
window.todo_add_category = function () {
showLoader();
const type_name = document.getElementById("category_name").value;
Expand All @@ -478,11 +528,11 @@ function connect() {
hideOverlay("createCategoryOverlay");
todo_get_categories();
});
}
};
window.todo_set_search_filter = function () {
searchFilter = document.getElementById("search").value;
todo_update_tasks();
}
};
window.todo_set_state_filter = function (element) {
const selected = element.classList.contains("selected");
const id = element.id;
Expand All @@ -498,7 +548,7 @@ function connect() {
stateFilter = -1;
}
todo_update_tasks();
}
};
window.todo_set_type_filter = function (element) {
const selected = element.classList.contains("selected");
const id = element.id;
Expand All @@ -514,7 +564,7 @@ function connect() {
typeFilter = -1;
}
todo_update_tasks();
}
};
window.todo_set_category_filter = function (element) {
const selected = element.classList.contains("selected");
const id = element.id;
Expand All @@ -530,14 +580,14 @@ function connect() {
categoryFilter = -1;
}
todo_update_tasks();
}
};
window.editCategory = function (id) {
document.getElementById("editCategoryID").value = id;
document.getElementById("category_edit_name").value = categoryIDs[id];
document
.getElementById("editCategoriesForm")
.classList.remove("hidden");
}
};
window.editType = function (id) {
document.getElementById("editTypeID").value = id;
document.getElementById("type_edit_name").value = typeIDs[id];
Expand Down Expand Up @@ -620,7 +670,7 @@ function connect() {
document.getElementById("notification-title").value = "";
document.getElementById("notification-text").value = "";
showMessage("{label58}");
}
};
window.getNotifications = function () {
socket.send("getNotifications");
getNotificationsHandleAnswer = function (result) {
Expand All @@ -646,9 +696,9 @@ function connect() {
showOverlay("notification-overlay" + id);
});
};
}
};
window.markNotificationAsSeen = function (id) {
socket.send("markNotificationAsSeen=" + id);
hideOverlay("notification-overlay" + id);
}
};
}
5 changes: 5 additions & 0 deletions public_html/style/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public_html/style/style.css.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public_html/style/style.scss
Expand Up @@ -271,6 +271,7 @@ body {
.createCategoryOverlay,
.createTypeOverlay,
.filter-overlay,
.editTaskOverlay,
.editTypesOverlay,
.editCategoriesOverlay,
.cookie-note,
Expand Down

0 comments on commit c7e3503

Please sign in to comment.