Skip to content

Commit

Permalink
Fixed bugs
Browse files Browse the repository at this point in the history
Removed unneeded logging, fixed modifyItem bug, fixed increasing number
of shown Tasks. Improved if statements.
  • Loading branch information
Roy Kokkelkoren committed Sep 2, 2015
1 parent 3a80937 commit f32eb20
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 29 deletions.
5 changes: 2 additions & 3 deletions chrome/content/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ window.addEventListener("load", function(e) {
let found = false;

for each (calendar in calManager.getCalendars({})){
todotxtLogger.debug("overlay.js: providerID"+calendar.id);
if(calendar.providerID == ID){
todotxtLogger.debug("overlay.js: Calendar found");
todotxtLogger.debug("overlay.js","Calendar found");
found = true;
break;
}
Expand All @@ -21,7 +20,7 @@ window.addEventListener("load", function(e) {
}, false);

function createCal(calManager){
todotxtLogger.debug("overlay.js: Create calendar");
todotxtLogger.debug("overlay.js","Create calendar");
let url = cal.makeURL('todotxt://_unused');
let newCal = calManager.createCalendar('todotxt',url);
newCal.name = "Todo.txt";
Expand Down
12 changes: 6 additions & 6 deletions components/calTodotxt.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ calTodoTxt.prototype = {
Components.results.NS_ERROR_UNEXPECTED,
Components.interfaces.calIOperationListener.MODIFY,
null,
'Unable to modify task.');
e.message);

}
},
Expand Down Expand Up @@ -264,14 +264,14 @@ calTodoTxt.prototype = {
}

try {
if(this.mLastSync == null){
if(!this.mLastSync){
items = todoClient.getItems(this,true);

this.mLastSync = new Date();
this.mTaskCache[this.id] = {};

for each(item in items){
for each(item in items)
this.mTaskCache[this.id][item.id] = item;
}

aListener.onGetResult(this.superCalendar,
Components.results.NS_OK,
Expand All @@ -284,9 +284,9 @@ calTodoTxt.prototype = {
Components.interfaces.calIOperationListener.GET,
null,
null);
}else{
}else
this.getCachedItems(aItemFilter, aCount, aRangeStart, aRangeEnd, aListener);
}

} catch (e) {
todotxtLogger.error('calTodotxt.js:getItems()',e);
this.notifyOperationComplete(aListener,
Expand Down
5 changes: 3 additions & 2 deletions modules/logger.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ let todotxtLogger = {
if (src) {
output += '[' + src + ']';
}
if (error){
output += e.result+' ('+e.message+')';
if (!error){
output += ' ERROR: ';
output += error.result+' ('+error.message+')';
}
cal.LOG(output);
app = this.App;
Expand Down
34 changes: 16 additions & 18 deletions modules/todoclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ let todoClient = {
});
item.setCategories(projects.length,projects);

if(todoItem.priority() != null)
item.priority = (todoItem.priority().charCodeAt(0)-64)*2;
if(todoItem.priority())
item.priority = this.calPriority(todoItem.priority());

items.push(item);
}
Expand All @@ -57,7 +57,7 @@ let todoClient = {
let todoItem = todo.addItem(newItem.title);
todoItem.setCreatedDate(null);

if(todoItem.priority() != null)
if(todoItem.priority())
newItem.priority = this.calPriority(todoItem.priority());

let projects = todoItem.projects().map(function(item){
Expand All @@ -75,25 +75,23 @@ let todoClient = {
},

modifyItem: function(oldItem, newItem){
let todo = this.getTodo();
let found = false;
let todo = this.getTodo();

for each(todoItem in todo.items()){
if(todoItem.id() == newItem.id){

todoItem.replaceWith(newItem.title);
if(todoItem.id() == oldItem.id){

let parseItem = newItem.title;

// Verify if priorty is altered
if(newItem.priority != null && newItem.priority != 0){
if(newItem.priority && newItem.priority != 0){
let pri = this.calPriority(newItem.priority);
let parseItem = this.makeTitle(todoItem);
if(pri != null)
if(pri)
parseItem = '('+pri+') '+parseItem;
todo.removeItem(todoItem);
todoItem = todo.addItem(parseItem);
newItem.id = todoItem.id();
}

todoItem.replaceWith(parseItem);

// Verify if completed changed
if(newItem.isCompleted)
todoItem.completeTask();
Expand All @@ -112,9 +110,10 @@ let todoClient = {
}
}

if(found)
if(found){
this.writeTodo(todo);
else
return todoItem.id();
}else
throw Components.Exception("Modify item not found in Todo.txt",Components.results.NS_ERROR_UNEXPECTED);
},

Expand Down Expand Up @@ -186,9 +185,9 @@ let todoClient = {

writeCallback = function(status){
if (Components.isSuccessCode(status))
throw Components.Exception("Cannot write to file",Components.results.NS_ERROR_UNEXPECTED);
todotxtLogger.debug("todoClient.js","written to file");
else
todotxtLogger.debug("todoClient.js: written to file");
throw Components.Exception("Cannot write to file",Components.results.NS_ERROR_UNEXPECTED);
};

NetUtil.asyncCopy(iTodoStream, oTodoStream, writeCallback);
Expand Down Expand Up @@ -236,7 +235,6 @@ let todoClient = {
// B --> 2, Normal
// C --> 3, Low
calPriority: function(pri){
todotxtLogger.debug("todoClient.js: calPriority, "+pri);
if(typeof pri === 'string'){
let p = pri.charAt(0);
switch(p){
Expand Down

0 comments on commit f32eb20

Please sign in to comment.