Skip to content

Commit

Permalink
Fixed ALGORITHM
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian De La Cruz authored and Ian De La Cruz committed Feb 28, 2016
1 parent 1942ecb commit f3a7170
Show file tree
Hide file tree
Showing 4 changed files with 10,053 additions and 28 deletions.
8 changes: 4 additions & 4 deletions dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ <h1>Add Task</h1>
</main>
<script src="js/jquery-2.1.4.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="http://www.parsecdn.com/js/parse-latest.js" charset="utf-8"></script>
<script src="js/parse-1.6.14.js" charset="utf-8"></script>
<script src="js/moment.js" charset="utf-8"></script>
<script src="js/task.js" charset="utf-8"></script>
<script src="js/dashboard.js" charset="utf-8"></script>
Expand Down Expand Up @@ -185,9 +185,9 @@ <h1>Add Task</h1>
}
}

$(function () {
$('#datepicker').datepicker();
});
// $(function () {
// $('#datepicker').datepicker();
// });
</script>
</body>
</html>
152 changes: 136 additions & 16 deletions js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,153 @@ logout.addEventListener('click', function(){
});
});

var locArr = [];

var createTask = function(){
function localTask(dayAssigned,deadline, diffLvl, name, taskType){
this.name = name;
this.dayAssigned = dayAssigned;
this.deadline = deadline;
this.diffLvl = parseInt(diffLvl);
this.task = null;
this.timeStarted = null;
this.duration = null;
this.prioLvl = null;
this.timeToStart = (this.deadline-this.dayAssigned)+this.duration;
this.setTaskType = function(taskType){
console.log(taskType)
switch (taskType) {
case "Project":
this.task = 7;
break;
case "Paper":
this.task = 2;
break;
case "Orals":
this.task = 3;
break;
case "Homework":
this.task = 2;
break;
case "Exam":
this.task = 2;
break;
case "Quiz":
this.task = 1;
break;
case "Reading":
this.task = 2;
break;
default:
//the part where you can specify another task
break;
}
};
this.setDuration = function(diffLevel){
console.log(diffLevel);

switch(diffLevel){
case "1":
this.duration = this.task*0.25;
break;
case "2":
this.duration = this.task*0.75;
break;
case "3":
this.duration = this.task;
break;
case "4":
this.duration = this.task*1.25;
break;
case "5":
this.duration = this.task*1.75;
break;
default:
break;
}
};
this.setPrioLevel = function(level){
switch (level) {
case "Low Priority":
this.prioLvl = 1;
break;
case "Medium Priority":
this.prioLvl = 2;
break;
case "High Priority":
this.prioLvl = 3;
break;
default:
this.prioLvl = 2;
}
};
}

var createTask = function(arr){
var taskName = document.getElementById('task_name').value;
var taskType_input = document.getElementById('task_type');
var taskType = taskType_input.options[taskType_input.selectedIndex].text;
var taskDiff_input = document.getElementById('diff_level');
var taskDiff = taskDiff_input.options[taskDiff_input.selectedIndex].value;
var prioLvl_input = document.getElementById('prio_level');
var prioLvl = prioLvl_input.options[prioLvl_input.selectedIndex].value;
var prioLvl = prioLvl_input.options[prioLvl_input.selectedIndex].text;
var deadline = document.getElementById('datepicker').value;
var currDate = new Date();
console.log(typeof taskName);
var task = new Task();
task.set("dayAssigned", currDate);
task.set('name', taskName);
task.set('deadline', )
task.save({
success:function(res){
console.log("Hi");
},
error:function(res,error){
console.log("Error: " + error.code + " " + error.message);
}
});
var local = new localTask(currDate, new Date(deadline), taskDiff, taskName, taskType);
local.setTaskType(taskType);
local.setDuration(taskDiff);
local.setPrioLevel(prioLvl);
console.log(typeof local.timeToStart);

addTask(local,arr);
};
var createBtn = document.getElementById('add');
createBtn.addEventListener('click', function(event){
event.preventDefault();
createTask();
createTask(locArr);
});

function addTask(localTask, localTaskArr){
if(localTaskArr.length == 0){
localTaskArr.push(localTask);
} else {
for(var i = 0; i < localTaskArr.length; i++){
if(new Date(localTask.timeToStart).getHours() == new Date(localTaskArr[i].timeToStart).getHours()){
if(localTask.prioLvl == localTaskArr[i].prioLvl){
if(localTask.diffLvl == localTaskArr[i].diffLvl){
if(localTask.duration == localTaskArr[i].duration){
localTaskArr.splice(i,0,localTask);
break;
} else if(localTask.duration < localTaskArr[i].duration){
localTaskArr.splice(i,0,localTask);
break;
} else {
localTaskArr.splice(i+1,0,localTask);
break;
}
} else if(localTask.diffLvl < localTaskArr[i].diffLvl){
localTaskArr.splice(i,0,localTask);
break;
} else {
localTaskArr.splice(i+1,0,localTask);
break;
}
} else if(localTask.prioLvl > localTaskArr[i].prioLvl){
localTaskArr.splice(i,0,localTask);
break;
} else {
localTaskArr.splice(i+1,0,localTask);
break;
}
} else if(new Date(localTask.timeToStart).getHours() < new Date(localTaskArr[i].timeToStart).getHours()){
localTaskArr.splice(i,0,localTask);
break;
} else {
localTaskArr.splice(i+1,0,localTask);
break;
}
if(i == localTaskArr){
localTaskArr.push(localTask);
}
}
}
}
Loading

0 comments on commit f3a7170

Please sign in to comment.