From d9b04132cef7739b07d3e339bf0e8db3b5859401 Mon Sep 17 00:00:00 2001 From: Kameron Kenny Date: Tue, 18 Jun 2019 12:58:12 -0400 Subject: [PATCH] fix array indexing --- punch_list/api_code.html | 60 +++++++++++++++++++++++++++++++++++- punch_list/eventManage.js | 65 ++++++++++++++++++++++++++------------- punch_list/metadata.js | 2 +- 3 files changed, 104 insertions(+), 23 deletions(-) diff --git a/punch_list/api_code.html b/punch_list/api_code.html index f65a22e..9889ef7 100644 --- a/punch_list/api_code.html +++ b/punch_list/api_code.html @@ -26,6 +26,65 @@ diff --git a/punch_list/eventManage.js b/punch_list/eventManage.js index 43ade46..c7dd765 100644 --- a/punch_list/eventManage.js +++ b/punch_list/eventManage.js @@ -38,6 +38,16 @@ function getJson() { } +function findArrayId(uid) { + var length = window.punches.length; + + for (x = 0; x < length; x++) { + if (window.punches[x].uuid === uid) { + return x; + } + } +} + function tagFilter(tagItem) { console.log(`In tagFilter function`); window.tagFilterItem = tagItem; @@ -81,7 +91,7 @@ function genList(punchList, element) { list += "
"; // list += "
"; // list += "
"; - list += "
" + punchList[i].subject + "
"; // + list += "
" + punchList[i].subject + "
"; // list += "
Status: " + punchList[i].progress + "
"; list += "
Priority: " + punchList[i].priority + "
"; list += "
Need By: " + punchList[i].nDate + "
"; @@ -96,12 +106,12 @@ function genList(punchList, element) { list += "
"; list += "
"; list += "
"; } } else { @@ -109,7 +119,7 @@ function genList(punchList, element) { list += "
"; // list += "
"; // list += "
"; - list += "
" + punchList[i].subject + "
"; // + list += "
" + punchList[i].subject + "
"; // list += "
Status: " + punchList[i].progress + "
"; list += "
Priority: " + punchList[i].priority + "
"; list += "
Need By: " + punchList[i].nDate + "
"; @@ -124,12 +134,12 @@ function genList(punchList, element) { list += "
"; list += "
"; list += "
"; } } @@ -160,13 +170,12 @@ function completePunch(item) { putJson(jsonStr); } -function enablePunchDetail(item) { +function enablePunchDetail(uuid) { var punchList = window.punches; + item = findArrayId(uuid); console.log(`inside enablePunchDetail`); disableElement("punchListAll"); - console.log(`punchList Disabled`); enableElement("punchDetail"); - console.log(`punchDetail Enabled`); // html = ""; html = "

subject: " + punchList[item].subject + "
Created: " + punchList[item].cDate + "
Modified Date: " + punchList[item].mDate + "
Priority: " + punchList[item].priority + "
Progress: " + punchList[item].progress + "

"; document.getElementById("punchDetail").innerHTML = html; @@ -185,7 +194,7 @@ function createNewEvent() { var nDateField = document.getElementById("timepickerCreate").value; var notesField = document.getElementById("newNotes").value; - var newEventJson = { nDate: nDateField, subject: subjectField, priority: priorityField, progress: progressField, notes: notesField }; + var newEventJson = { uuid: genUid(), nDate: nDateField, subject: subjectField, priority: priorityField, progress: progressField, notes: notesField }; punchList.push(newEventJson); jsonStr = JSON.stringify(punchList); putJson(jsonStr); @@ -194,10 +203,11 @@ function createNewEvent() { // document.getElementById("newEventList").innerHTML = jsonStr; } -function deletePunch(item) { +function deletePunch(uuid) { // console.log(`${punchList}`); // console.log(`${window.punches}`); punchList = window.punches; + item = findArrayId(uuid); console.log(`splicing ${item}`); @@ -251,12 +261,13 @@ function toggleShowDone() { getJson(); } -function editPunch(item) { +function editPunch(uuid) { disableElement("newEvent"); disableElement("punchListAll"); enableElement("editPunch"); punchList = window.punches; + item = findArrayId(uuid); var id = item; @@ -297,7 +308,7 @@ function submitEditPunch() { function addTag() { var item = document.getElementById("editID").value; - var newTag = document.getElementById("tag").value; + var newTag = document.getElementById("tag").value.toLowerCase(); console.log(`Item: ${item}`); console.log(`New Tag: ${newTag}`); @@ -321,3 +332,15 @@ function clearDefault(a){ a.value=""; } } + +function genUid() { + function chr4() { + return Math.random().toString(16).slice(-4); + } + return chr4() + chr4() + + '-' + chr4() + + '-' + chr4() + + '-' + chr4() + + '-' + chr4() + chr4() + chr4(); +} + diff --git a/punch_list/metadata.js b/punch_list/metadata.js index 4e47cb0..5b3c3b2 100644 --- a/punch_list/metadata.js +++ b/punch_list/metadata.js @@ -1,4 +1,4 @@ -var version = "0.3.045", +var version = "0.3.047", debug = false, jsonUrl = "https://api.myjson.com/bins/1dodsj", showDone = false,