From 6833e3a1cde01cc06c8157ec615bef5336e4283c Mon Sep 17 00:00:00 2001 From: Kenneth Jao Date: Sat, 13 Aug 2016 18:58:54 -0400 Subject: [PATCH 1/5] Adding work, display each work in correct class --- hourglass/client/main/main.css | 87 ++++++++++++++++- hourglass/client/main/main.html | 56 ++++++++--- hourglass/client/main/main.js | 139 ++++++++++++++++++++++++---- hourglass/client/profile/profile.js | 2 +- hourglass/server/main.js | 8 +- 5 files changed, 251 insertions(+), 41 deletions(-) diff --git a/hourglass/client/main/main.css b/hourglass/client/main/main.css index a214497..d0107e5 100644 --- a/hourglass/client/main/main.css +++ b/hourglass/client/main/main.css @@ -112,8 +112,9 @@ h4 { transition: color 0.5s ease; } -input { +input, textarea { font-family: 'Raleway'; + resize: none; } #aboveBar { @@ -159,6 +160,10 @@ input { background-color: #33ADFF; } +#login-buttons { + display: none; +} + #menuContainer, #optionsContainer { min-height: 100%; max-height: 100%; @@ -311,12 +316,14 @@ input { } .creWork { + margin-bottom: 5%; cursor: pointer; + box-shadow: 0px 5px 5px 1px #666; -webkit-transition: background-color 0.4s ease; -moz-transition: background-color 0.4s ease; -ms-transition: background-color 0.4s ease; - transition: background-color 0.4s ease + transition: background-color 0.4s ease; } .creWork:hover { @@ -327,6 +334,45 @@ input { padding-left: 0; } +.workHolder { + width: 90%; + position: relative; + left: 5%; +} + +.workCard { + width: 100%; + margin-right: 0; + margin-bottom: 5%; + + background-color: rgba(255,255,255,0.3); + + box-shadow: 2px 2px 5px 3px #666; + cursor: pointer; + + -webkit-transition: background-color 0.4s ease; + -moz-transition: background-color 0.4s ease; + -ms-transition: background-color 0.4s ease; + transition: background-color 0.4s ease; +} + +.workCard:hover { + background-color: rgba(0,0,0,0.05); +} + +.cWorkCont { + padding: 5%; +} + +.cWorkType { + height: 5px; +} + +.cWorkName { + font-weight: 400; + margin-top: 0; +} + #editWork { position: absolute; top: 50%; @@ -396,6 +442,43 @@ input { margin-bottom: 5%; } +.inputRadio { + margin-bottom: 0 !important; +} + +.type { + margin-left: 30%; +} + +#workComments h3 { + margin-bottom: 2%; + -webkit-filter: none; + filter: none; +} + +#workSubmit { + font-weight: 200; + font-size: 140%; + padding: 4%; + + background-color: rgba(0,0,0,0.25); + text-align: center; + cursor: pointer; + + position: absolute; + left: -91%; + bottom: 7%; + + -webkit-transition: background-color 0.4s ease; + -moz-transition: background-color 0.4s ease; + -ms-transition: background-color 0.4s ease; + transition: background-color 0.4s ease; +} + +#workSubmit:hover { + background-color: rgba(0,0,0,0.15); +} + .overlay { width: 100%; height: 100%; diff --git a/hourglass/client/main/main.html b/hourglass/client/main/main.html index d6c169f..9f8fd6c 100644 --- a/hourglass/client/main/main.html +++ b/hourglass/client/main/main.html @@ -4,11 +4,13 @@ + + \ No newline at end of file diff --git a/hourglass/client/main/main.js b/hourglass/client/main/main.js index 4742ad1..5a242e2 100644 --- a/hourglass/client/main/main.js +++ b/hourglass/client/main/main.js @@ -63,12 +63,21 @@ Template.registerHelper('myClasses', () => { } else { var array = []; var courses = Meteor.user().profile.classes; + for(var i = 0; i < courses.length; i++) { array.push(classes.findOne({_id:courses[i]})); + var thisWork = work.find({class:array[i]["_id"]}).fetch(); + + for(var j = 0; j < thisWork.length; j++) { + thisWork[j].dueDate = getReadableDate(thisWork[j].dueDate); + thisWork[j].typeColor = workColors[thisWork[j].type]; + } + console.log(thisWork); + array[i].thisClassWork = thisWork; } return array; } -}); +}) Template.main.helpers({ schoolName() { @@ -171,8 +180,21 @@ Template.main.helpers({ return workColors.type; } }, + cWorkColor(type) { + return workColors["type"]; + }, newWork() { return Session.get("newWork"); + }, + inRole() { + if(Session.get("newWork")) { + return true; + } else { + if(Meteor.userId() === work.findOne({_id: Session.get("workId")}).creator || + Roles.userIsInRole(Meteor.userId(), ['superadmin', 'admin']) || + classes.findOne({_id: work.findOne({_id: Session.get("workId")}).class}).moderators.indexOf(Meteor.userId()) !== -1 + ) return true; + } } }); @@ -244,7 +266,7 @@ Template.main.events({ if (event.target.id !== sessval && event.target.id !== sessval + "a" && !Session.equals("modifying", null) && - !event.target.parentNode.className.includes("profOptions")) { + !event.target.parentNode.className.includes("workOptions")) { closeInput(sessval); } if (!event.target.className.includes("radio") && @@ -262,12 +284,17 @@ Template.main.events({ } }, 'click .creWork' (event) { + if(event.target.className !== "creWork") { + var attr = event.target.parentNode.getAttribute("classid"); + } else { + var attr = event.target.getAttribute("classid"); + } openDivFade(document.getElementsByClassName("overlay")[0]); Session.set("newWork", true); Session.set("currentWork", { name:"Name | Click here to edit...", - class:event.target.getAttribute("classid"), + class:attr, dueDate:"Click here to edit...", description:"Click here to edit...", type:"Click here to edit..." @@ -283,14 +310,21 @@ Template.main.events({ ele.style.display = "none"; var input = document.createElement("input"); - if (ele.getAttribute("type") !== null) { - input.type = ele.getAttribute("type"); + var typ = ele.getAttribute("type") + if (typ === "textarea") { + input = document.createElement("textarea"); + input.style.height = 3 * dim.height.toString() + "px"; + input.rows = "4"; + } else if (typ !== null) { + input.type = typ; + input.style.height = 0.9 * dim.height.toString() + "px"; } else { - input.type = "text"; + input.typ = "text"; + input.style.height = 0.9 * dim.height.toString() + "px"; } input.value = ele.childNodes[0].nodeValue; input.className = "changeInput"; - input.style.height = 0.9 * dim.height.toString() + "px"; + input.style.width = "70%"; input.style.padding = "0.1%"; input.id = ele.id + "a"; @@ -316,9 +350,38 @@ Template.main.events({ ele.parentNode.appendChild(span); } }, + 'click .radio' (event) { + var op = event.target; + Session.set("radioDiv", op.getAttribute("op")); + Session.set("radioOffset", op.getAttribute("opc")); + try { + for (var i = 0; i < document.getElementsByClassName("workOptions").length; i++) { + var curr = document.getElementsByClassName("workOptions")[i]; + if (Session.get("radioDiv") !== i.toString()) { + closeDivFade(document.getElementsByClassName("workOptions")[i]); + } + } + } catch (err) {} + openDivFade(document.getElementsByClassName("workOptions")[op.getAttribute("op")]); + }, + 'click .workOptions p' (event) { + var sessval = Session.get("modifying"); + var p = event.target; + var opnum = (parseInt(Session.get("radioDiv")) - parseInt(Session.get("radioOffset"))); + var input = document.getElementsByClassName("op")[opnum]; + input.value = p.childNodes[0].nodeValue; + try { + closeInput(sessval); + } catch (err) {} + + closeDivFade(p.parentNode); + input.focus(); + Session.set("radioDiv", null); + Session.set("radioOffset", null); + }, 'keydown' (event) { var sessval = Session.get("modifying"); - if (event.keyCode == 13) { + if (event.keyCode == 13 && sessval != "workDesc") { try { closeInput(sessval); } catch (err) {} @@ -344,15 +407,23 @@ Template.main.events({ } }, 'click #workSubmit' () { - Session.set("serverData",getHomeworkFormData()); + data = getHomeworkFormData(); + if(data === null) return; + console.log(data); + Session.set("serverData",data); if(Session.get("newWork")) { - sendData("editWork"); - } else { sendData("createWork"); + } else { + sendData("editWork"); } Session.set("newWork",null); - Session.set("currentWork",null); - } + closeDivFade(document.getElementsByClassName("overlay")[0]); + Session.set("currentWork", null); + }, + 'focus .op' (event) { + event.target.click(); + }, + }); function openDivFade(div) { @@ -377,6 +448,7 @@ function sendData(funcName) { function closeInput(sessval) { var input = document.getElementById(sessval + "a"); var span = document.getElementById(sessval); + span.style.color = "#8C8C8C"; input.parentNode.removeChild(input); try { var restrict = document.getElementById("restrict"); @@ -389,17 +461,44 @@ function closeInput(sessval) { } span.style.display = "initial"; Session.set("modifying", null); - if(Session.get("newWork")) { + if(!Session.get("newWork")) { Session.set("serverData",getHomeworkFormData()); - sendData("editProfile"); + sendData("editWork"); } - } function getHomeworkFormData() { - return; + var inputs = document.getElementsByClassName("req"); + var stop; + for(var i = 0; i < inputs.length; i++) { + var value = inputs[i].childNodes[0].nodeValue; + if(i === 2) { + if(Date.parse(inputs[i]) === NaN) { // Implement moment. + value = "Invalid date"; + stop = true; + } + } else { + if(value.includes("Click here to edit")) { + value = "Missing field"; + inputs[i].style.color = "#FF1A1A"; + stop = true; + } + } + } + if(stop) return null; + + var data = Session.get("currentWork"); + data.name = document.getElementById("workName").childNodes[0].nodeValue; + data.dueDate = new Date(document.getElementById("workDate").childNodes[0].nodeValue); + data.description = document.getElementById("workDesc").childNodes[0].nodeValue; + data.type = document.getElementById("workType").childNodes[0].nodeValue.toLowerCase(); + Session.set("currentWork", data); + + return data; } -function clearHomeworkForm() { - -} +function getReadableDate(date) { + var days = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]; + var months = ["January","February","March","April","May","June","July","August","September","October","November","December"]; + return days[date.getDay()]+", "+months[date.getMonth()]+" "+date.getDate(); +} \ No newline at end of file diff --git a/hourglass/client/profile/profile.js b/hourglass/client/profile/profile.js index a317043..b8e7422 100644 --- a/hourglass/client/profile/profile.js +++ b/hourglass/client/profile/profile.js @@ -305,7 +305,7 @@ Template.profile.events({ 'click .profOptions p' (event) { var sessval = Session.get("modifying"); var p = event.target; - var opnum = (parseInt(Session.get("radioDiv")) - parseInt(Session.get("radioOffset"))).toString(); + var opnum = parseInt(Session.get("radioDiv")) - parseInt(Session.get("radioOffset")); var input = document.getElementsByClassName("op")[opnum]; input.value = p.childNodes[0].nodeValue; try { diff --git a/hourglass/server/main.js b/hourglass/server/main.js index 0171ac8..22fd27e 100644 --- a/hourglass/server/main.js +++ b/hourglass/server/main.js @@ -166,13 +166,13 @@ Meteor.methods({ var found = classes.findOne({ _id: input.class }); - console.log(input); + if (Meteor.user() !== null && found !== null && Meteor.user().profile.classes.indexOf(input.class) !== -1 && found.banned.indexOf(Meteor.userId()) === -1 && found.blockEdit.indexOf(Meteor.userId()) === -1 && - input.dueDate.getTime() >= ref && worktype.indexOf(type) != -1 && + input.dueDate.getTime() >= ref && worktype.indexOf(input.type) != -1 && input.name.length <= 50 && input.description.length <= 150) { input.confirmations = [Meteor.userId()]; @@ -201,7 +201,7 @@ Meteor.methods({ $set: change }); } else if (authorized.indexOf(Meteor.userId()) != -1) { - if (change.name.length <= 50 && change.description.length <= 150 && worktype.indexOf(type) != -1) { + if (change.name.length <= 50 && change.description.length <= 150 && worktype.indexOf(change.type) != -1) { Meteor.update({ _id: change._id }, { @@ -219,7 +219,7 @@ Meteor.methods({ } else if (Meteor.userId() === work.findOne({ _id: change._id }).creator) { - if (change.name.length <= 50 && worktype.indexOf(type) != -1 && input.dueDate.getTime() >= ref) { + if (change.name.length <= 50 && worktype.indexOf(change.type) != -1 && input.dueDate.getTime() >= ref) { Meteor.update({ _id: change._id }, { From 00ded2965dd93b0f2de53aa5de76058f8da45e3d Mon Sep 17 00:00:00 2001 From: Kenneth Jao Date: Sat, 13 Aug 2016 19:24:10 -0400 Subject: [PATCH 2/5] Fixed editWork, and displays work information on click --- hourglass/client/main/main.html | 2 +- hourglass/client/main/main.js | 22 +++++++++++++++------- hourglass/server/main.js | 4 ++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/hourglass/client/main/main.html b/hourglass/client/main/main.html index 9f8fd6c..cfb63d6 100644 --- a/hourglass/client/main/main.html +++ b/hourglass/client/main/main.html @@ -145,7 +145,7 @@