From f32eb20e5b5d0b786018503fa60f98a7dbc91429 Mon Sep 17 00:00:00 2001 From: Roy Kokkelkoren Date: Wed, 2 Sep 2015 16:32:01 +0200 Subject: [PATCH] Fixed bugs Removed unneeded logging, fixed modifyItem bug, fixed increasing number of shown Tasks. Improved if statements. --- chrome/content/overlay.js | 5 ++--- components/calTodotxt.js | 12 ++++++------ modules/logger.jsm | 5 +++-- modules/todoclient.js | 34 ++++++++++++++++------------------ 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js index 15f1051..6427213 100644 --- a/chrome/content/overlay.js +++ b/chrome/content/overlay.js @@ -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; } @@ -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"; diff --git a/components/calTodotxt.js b/components/calTodotxt.js index 3c0a259..71db7ed 100644 --- a/components/calTodotxt.js +++ b/components/calTodotxt.js @@ -220,7 +220,7 @@ calTodoTxt.prototype = { Components.results.NS_ERROR_UNEXPECTED, Components.interfaces.calIOperationListener.MODIFY, null, - 'Unable to modify task.'); + e.message); } }, @@ -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, @@ -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, diff --git a/modules/logger.jsm b/modules/logger.jsm index 196ddba..fc53227 100644 --- a/modules/logger.jsm +++ b/modules/logger.jsm @@ -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; diff --git a/modules/todoclient.js b/modules/todoclient.js index 7164179..20f481f 100644 --- a/modules/todoclient.js +++ b/modules/todoclient.js @@ -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); } @@ -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){ @@ -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(); @@ -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); }, @@ -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); @@ -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){