From d1795e6413f34022c915a62ac1d234ced07d7f9d Mon Sep 17 00:00:00 2001 From: "Liangbin.Zhang" Date: Thu, 17 Mar 2011 23:12:01 -0700 Subject: [PATCH 01/11] add estimate table, addEstimate() method and a html page. --- js/SQLiteHelper.js | 68 +++++++++++++++++++++++++++++++++++++++++++- js/createDatabase.js | 13 +++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/js/SQLiteHelper.js b/js/SQLiteHelper.js index b94860a..c4d41ae 100755 --- a/js/SQLiteHelper.js +++ b/js/SQLiteHelper.js @@ -8,7 +8,8 @@ addUser(String userEmail, String userNickname, String userPassword, function callback) To add a comment, use the function addComment(String commentText, int taskid, String commenterEmail) - + To add an estimate(int taskid, int timeSpent, int timeRemaining) + Error codes: 0: everythings OK -1: error from above (opening db, closing db, ....) @@ -341,6 +342,71 @@ exports.addComment = function (commentText, commentTaskid, commenterEmail, callb }); } +/** + Parameter1: a taskid that the estmate refers to. (int) + Parameter2: time spent fo the task. (int) + Parameter3: the estimated remaining time of the task. (int) + callback : a function + + This function adds an estimate to the estimate table in the database. +*/ +exports.addEstimate = function (estTaskid, estTimeSpent, estTimeRemaining, callback) { + + var sql = "SELECT * FROM task WHERE taskid = ?"; + + accessDB(sql, [estTaskid], function(error, rows){ + if(error){ + writeLog(error); + if(callback != undefined) { callback({status:-2, detail:error});} + return -2; // error code for caller + } + + if(rows.length == 0) { + writeLog("func: addEstimate, taskid " + estTaskid + " not found."); + if(callback != undefined) { callback({status:-1, detail:error});} + return -1; // error code for caller + } + + }); + + var sql = "SELECT * FROM estimate WHERE taskid = ?"; + accessDB(sql, [estTaskid], function(error, rows){ + if(error){ + writeLog(error); + if(callback != undefined) { callback({status:-2, detail:error});} + return -2; // error code for caller + } + + if(rows.length == 0) { + sql = "INSERT INTO estimate (taskid,timeSpent,timeRemaining) VALUES (?,?,?)" + db.execute(sql, [estTaskid, estTimeSpent, estTimeRemaining], + function(error, rows) { + if(error) { + writeLog(error); + if(callback != undefined) { callback({status:-1, detail:error});} + return -1; // error code for caller + } + + writeLog("estimate of task " + estTaskid + " added."); + if (callback != undefined) { callback({status:0, detail:error}); + }); + } else { + sql = "UPDATE estimate (timeSpent,timeRemaining) VALUES(?,?) WHERE taskid="+estTaskid; + db.execute(sql, [estTimespent, estTimeRemaining], + function(error, rows){ + if(error) { + writeLog(error); + if(callback != undefined) { callback({status:-2, detail:error});} + return -2; + } + + writeLog("estimate of task " + estTaskid " updated"); + if (callback != undefined) { callback({status:0, detail:error}); + }); + } + }); +} + /** Parameter1: Table name. diff --git a/js/createDatabase.js b/js/createDatabase.js index c742e75..0f3681f 100755 --- a/js/createDatabase.js +++ b/js/createDatabase.js @@ -11,6 +11,7 @@ user(email, nickname, password) task(taskid, taskName, description, priority, status, user, date) comment(thecomment, taskid, creator) + estimate(taskid, timeSpent, timeRemaining) */ sqlite = require('./../lib/node-sqlite/sqlite'); @@ -71,6 +72,18 @@ db.open(dbLocation, function (error) { console.log("comment table created."); }); + db.execute("CREATE TABLE estimate (" + + "taskid NUMBER," + // FOREIGN KEY + "timeSpent NUMBER," + + "timeRemaining NUMBER)", + function (error) { + if(error) { + console.log("Error creating estimate table."); + throw error; + } + + console.log("Estimate table created."); + }); }); db.close(function(error) { From ecba0ef79c6d1159bc4fdb04ba8da09e5475d7de Mon Sep 17 00:00:00 2001 From: "Liangbin.Zhang" Date: Fri, 18 Mar 2011 10:09:52 -0700 Subject: [PATCH 02/11] bug fixed --- js/SQLiteHelper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/SQLiteHelper.js b/js/SQLiteHelper.js index c4d41ae..013c0d7 100755 --- a/js/SQLiteHelper.js +++ b/js/SQLiteHelper.js @@ -388,7 +388,7 @@ exports.addEstimate = function (estTaskid, estTimeSpent, estTimeRemaining, callb } writeLog("estimate of task " + estTaskid + " added."); - if (callback != undefined) { callback({status:0, detail:error}); + if (callback != undefined) { callback({status:0, detail:error})}; }); } else { sql = "UPDATE estimate (timeSpent,timeRemaining) VALUES(?,?) WHERE taskid="+estTaskid; @@ -401,7 +401,7 @@ exports.addEstimate = function (estTaskid, estTimeSpent, estTimeRemaining, callb } writeLog("estimate of task " + estTaskid " updated"); - if (callback != undefined) { callback({status:0, detail:error}); + if (callback != undefined) { callback({status:0, detail:error})}; }); } }); From 675d1d6595745688ad4870e9618ec8c6e57dbf3d Mon Sep 17 00:00:00 2001 From: "Liangbin.Zhang" Date: Fri, 18 Mar 2011 10:13:55 -0700 Subject: [PATCH 03/11] Bug fixed and html added to static folder. --- static/add_estimate.html | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 static/add_estimate.html diff --git a/static/add_estimate.html b/static/add_estimate.html new file mode 100644 index 0000000..018da14 --- /dev/null +++ b/static/add_estimate.html @@ -0,0 +1,17 @@ + + + + Task Estimation + + + + +
+

+ Task ID                          :

+ Time Spent(in hours)       :

+ Time Remains(in hours)   :

+

+
+ + \ No newline at end of file From 83995fa83ce47109234e679c5ae033c26962e32b Mon Sep 17 00:00:00 2001 From: "Liangbin.Zhang" Date: Fri, 1 Apr 2011 10:40:39 -0700 Subject: [PATCH 04/11] remove files --- js/SQLiteHelper.js | 516 --------------------------------------- js/createDatabase.js | 93 ------- static/add_estimate.html | 17 -- 3 files changed, 626 deletions(-) delete mode 100755 js/SQLiteHelper.js delete mode 100755 js/createDatabase.js delete mode 100644 static/add_estimate.html diff --git a/js/SQLiteHelper.js b/js/SQLiteHelper.js deleted file mode 100755 index 013c0d7..0000000 --- a/js/SQLiteHelper.js +++ /dev/null @@ -1,516 +0,0 @@ -/** - Before using these functions, must create the database by first - running from command line: node createDatabase.js - - To add a task, use the function - addTask(Task taskObj, function callback) - To add a user, use the function - addUser(String userEmail, String userNickname, String userPassword, function callback) - To add a comment, use the function - addComment(String commentText, int taskid, String commenterEmail) - To add an estimate(int taskid, int timeSpent, int timeRemaining) - - Error codes: - 0: everythings OK - -1: error from above (opening db, closing db, ....) - -2: insertion or deletion object already exists or doesn't exist, etc...) -*/ -var basepath = "../"; -sqlite = require(basepath + 'lib/node-sqlite/sqlite'); -fs = require('fs'); -path = require('path'); - -// directories changed, assuming the node process will be -// started with CourseProject/ as the working directory -var dbLocation = "db/main.db"; // database location in file system -var dbLogLocation = "db/log.txt"; // database log -var db; - -/** - Parameter1: an error object describing an error. (error) - - This function logs this error in a txt file. -*/ -function writeLog(logLine) { - - console.log(logLine); - var logStream = fs.createWriteStream(dbLogLocation, - {flags: 'w', - flags: 'a', - encoding: 'binary', - mode: 0666} - ); - logStream.write(new Date() + "\n\t" + logLine + "\n"); - - logStream.on('drain', function() { - logStream.end(); - }); -} - -/** - Parameter1: a sql query. (String) - Parameter2: the arguments to bind to the query. (String) - Parameter3: a function with 2 args, error and rows, which - performs operations on the query results. (function) - - This is only a helper function for this js file. -*/ -function accessDB(sql, executionArgs, inputFunction) { - - path.exists(dbLocation, function(exists) { - if(!exists) { - console.log("Database doesn't exist. First run createDatabase.js"); - throw new Error(''); - } - }); - - db = new sqlite.Database(); - - inputFunctionWithClose = function(err,row){ - db.close(function(error) { - if(error) { - writeLog(error); - return -2; // error code for caller - } else { - inputFunction(err,row); - } - }); - } - - db.open(dbLocation, function(error) { - if(error) { - writeLog(new Date() + "\n\tfunc: accessDB" + error + "\n"); - return -2; // error code for caller - } - - if(executionArgs == null) - db.execute(sql, inputFunctionWithClose); - else - db.execute(sql, executionArgs, inputFunctionWithClose); - }); -} - -/** - Parameter1: an object of type Task from task.js. (Task) - Parameter2: callback. (function) - - This function stores the task object in the database. -*/ -exports.addTask = function(taskObj, callback) { - - var sql = "SELECT * FROM task"; - - accessDB(sql, null, function(error, rows) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - return -2; - } - - for(i = 0; i < rows.length; i++) { - if ((rows != undefined) || (rows[i].taskName.toLowerCase() == - taskObj.getTaskName().toLowerCase())) { - writeLog("func: addTask, task " + taskObj.getTaskName() + - " already exists."); - if (callback != undefined) { - callback({status:-1, detail:{message:"task already exists."}}); - } - return -2; - } - } - - sql = "INSERT INTO task " + - "(taskName, description, priority, status, user, date) " + - "VALUES (?,?,?,?,?,?)"; - - accessDB(sql, [taskObj.getTaskName(), taskObj.getDescription(), - taskObj.getPriority(), taskObj.getStatus(), taskObj.getUser(), - taskObj.getDate()], - function(error, rows) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - } - - writeLog("task " + taskObj.getTaskName() + " by " + - taskObj.getUser() + " added."); - if (callback != undefined) { callback({status:0, detail:error}); } - } - ); - }); -} - -/** - Parameter1: name of task to delete. (String) - Parameter2: callback. (function) - - removes task with given taskName if it exists. -*/ -exports.removeTask = function (taskName, callback) { - - var sql = "DELETE FROM task WHERE taskName = ?"; - - accessDB(sql, [taskName], function(error) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - return -2; - } - else{ - writeLog("Task: " + taskName + "successfully removed."); - if (callback != undefined) { callback({status:0, detail:error}); } - } - - }); -} - -/** - Parameter1: an email. (String) - Parameter2: a nickname. (String) - Parameter3: a password. (String) - Parameter4: callback (function) - - This function takes the input and stores it in the user table - of the database. -*/ -exports.addUser = function(userEmail, userNickname, userPassword, callback) { - - var sql = "SELECT * FROM user WHERE email = ? OR nickname = ?"; - - accessDB(sql, [userEmail, userNickname], function(error, rows) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - } - - if(rows.length != 0) { - writeLog("func: addUser, email " + userEmail + " already exists."); - if (callback != undefined) { callback({status:-2, detail:{message:"user exists"}}); } - return -1; // error code for caller - } else { - sql = "INSERT INTO user (email,nickname,password) " + - "VALUES (?,?,?)"; - - accessDB(sql, [userEmail, userNickname, userPassword], - function(error, rows) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - } - - writeLog("user " + userEmail + ", " + - userNickname +", with password " + - userPassword + " added."); - if (callback != undefined) { callback({status:0, detail:error}); } - } - ); - } - }); -} - -/** - Parameter1: nickName to check for. (String) - Parameter2: callback (function) - - this function is used to check if a user with the given nickName exists - in the database. -*/ -exports.nickExists = function (nickName, callback) { - var sql = "SELECT * FROM user WHERE nickname = ?"; - - accessDB(sql, [nickName], function(error, rows) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - } - else if(rows.length != 0) { - writeLog("user: " + nickName + " exists."); - if (callback != undefined) { callback({status:0, exists:true, detail:error}); } - } - else { - writeLog("user: " + nickName + " does not exist."); - if (callback != undefined) { callback({status:0, exists:false, detail:error}); } - } - }); -} - -/** - Parameter1: email to check. (String) - Parameter2: callback. (function) - - Checks if a user email exists in the db. -*/ -exports.userExists = function (userEmail, callback) { - var sql = "SELECT * FROM user WHERE email = ?"; - - accessDB(sql, [userEmail], function(error, rows) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - } - else if(rows.length != 0) { - writeLog("user: " + userEmail + " exists."); - if (callback != undefined) { callback({status:0, exists:true, detail:error}); } - } - else { - writeLog("user: " + userEmail + " does not exist."); - if (callback != undefined) { callback({status:0, exists:false, detail:error}); } - } - }); -} - -/** - Parameter1: email of user to remove. (String) - Parameter2: callback. (function) - - removes the user corresponding to the given email if it exists. -*/ -exports.removeUser = function (userEmail, callback) { - var sql = "DELETE FROM user WHERE email = ?"; - - accessDB(sql, [userEmail], function(error, rows) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - } - else { - writeLog("user: " + userEmail + " removed."); - if (callback != undefined) { callback({status:0, detail:error}); } - } - }); -} - -/** - Parameter1: a comment. (String) - Parameter2: the taskid that the comment refers to. (String) - Parameter3: the email of the commenter. (String) - - This function adds a comment to the comment table in the database. -*/ -exports.addComment = function (commentText, commentTaskid, commenterEmail, callback) { - - var sql = "SELECT * FROM user WHERE email = ?"; - - accessDB(sql, [commenterEmail], function(error, rows) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - return -2; // error code for caller - } - - if(rows.length == 0) { - writeLog("func: addComment, user email " + - commenterEmail + " not found."); - if (callback != undefined) { callback({status:-1, detail:error}); } - return -1; // error code for caller - } - - sql = "SELECT * FROM task WHERE taskid = ?"; - - accessDB(sql, [commentTaskid], function(error, rows) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - return -2; // error code for caller - } - - if(rows.length == 0) { - writeLog("func: addComment, taskid " + - commentTaskid + " not found."); - if (callback != undefined) { callback({status:-1, detail:error}); } - return -1; // error code for caller - } - - sql = "INSERT INTO comment (thecomment,taskid,email) " + - "VALUES (?,?,?)"; - - accessDB(sql, - [commentText, commentTaskid, commenterEmail], - function(error, rows) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - return -2; // error code for caller - } - - writeLog("comment for taskid " + commentTaskid + - " by " + commenterEmail + " added."); - if (callback != undefined) { callback({status:0, detail:error}); } - } - ); - }); - }); -} - -/** - Parameter1: a taskid that the estmate refers to. (int) - Parameter2: time spent fo the task. (int) - Parameter3: the estimated remaining time of the task. (int) - callback : a function - - This function adds an estimate to the estimate table in the database. -*/ -exports.addEstimate = function (estTaskid, estTimeSpent, estTimeRemaining, callback) { - - var sql = "SELECT * FROM task WHERE taskid = ?"; - - accessDB(sql, [estTaskid], function(error, rows){ - if(error){ - writeLog(error); - if(callback != undefined) { callback({status:-2, detail:error});} - return -2; // error code for caller - } - - if(rows.length == 0) { - writeLog("func: addEstimate, taskid " + estTaskid + " not found."); - if(callback != undefined) { callback({status:-1, detail:error});} - return -1; // error code for caller - } - - }); - - var sql = "SELECT * FROM estimate WHERE taskid = ?"; - accessDB(sql, [estTaskid], function(error, rows){ - if(error){ - writeLog(error); - if(callback != undefined) { callback({status:-2, detail:error});} - return -2; // error code for caller - } - - if(rows.length == 0) { - sql = "INSERT INTO estimate (taskid,timeSpent,timeRemaining) VALUES (?,?,?)" - db.execute(sql, [estTaskid, estTimeSpent, estTimeRemaining], - function(error, rows) { - if(error) { - writeLog(error); - if(callback != undefined) { callback({status:-1, detail:error});} - return -1; // error code for caller - } - - writeLog("estimate of task " + estTaskid + " added."); - if (callback != undefined) { callback({status:0, detail:error})}; - }); - } else { - sql = "UPDATE estimate (timeSpent,timeRemaining) VALUES(?,?) WHERE taskid="+estTaskid; - db.execute(sql, [estTimespent, estTimeRemaining], - function(error, rows){ - if(error) { - writeLog(error); - if(callback != undefined) { callback({status:-2, detail:error});} - return -2; - } - - writeLog("estimate of task " + estTaskid " updated"); - if (callback != undefined) { callback({status:0, detail:error})}; - }); - } - }); -} - -/** - Parameter1: Table name. - - Parameter2: a function that takes in 2 arguments, the first - being an error object, the second being an array of row - objects representing the tuples returned from the - database. - - Usage example: - - getTable("user", function(obj) { - if(obj.status != 0) { - console.log(obj.detail); - return; - } - - for(i = 0; i < obj.rows.length; i++) { - console.log(obj.rows[i].email); - console.log(obj.rows[i].nickname); - console.log(obj.rows[i].password); - } - }); -*/ -exports.getTable = function(tableName, callback) { - var sql = "SELECT * FROM " + tableName; - - db = new sqlite.Database(); - - db.open(dbLocation, function(error) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - return -2; - } - - db.execute(sql, function(error, rows) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - return -2; - } - db.close(function(error) { - if(error){ - throw error; - } else { - if (callback != undefined) { callback({status:0, rows:rows, detail:error}); } - } - }); - }); - }); -} - -/** - Parameter1: taskid for the task whose comments the caller wants. - - Parameter2: a function that takes in 2 arguments, the first - being an error object, the second being an array of row - objects representing the tuples returned from the - database. - - Usage example: - - getCommentsForTask(1, function(obj) { - if(obj.status != 0) { - console.log(obj.detail); - return; - } - - for(i = 0; i < obj.rows.length; i++) { - console.log(obj.rows[i].thecomment); - console.log(obj.rows[i].taskid); - console.log(obj.rows[i].email); - } - }); -*/ -exports.getCommentsForTask = function(taskid, callback) { - var sql = "SELECT * FROM comment WHERE taskid = " + taskid; - - db = new sqlite.Database(); - - db.open(dbLocation, function(error) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - return -2; - } - - db.execute(sql, function(error, rows) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - return -2; - } - db.close(function(error) { - if(error) { - writeLog(error); - if (callback != undefined) { callback({status:-2, detail:error}); } - return -2; - } else { - if (callback != undefined) { callback({status:0, rows:rows, detail:error}); } - } - }); - }); - }); - - -} diff --git a/js/createDatabase.js b/js/createDatabase.js deleted file mode 100755 index 0f3681f..0000000 --- a/js/createDatabase.js +++ /dev/null @@ -1,93 +0,0 @@ -/** - To create the database, run from command line: node createDatabase.js - - This code will create the database tables used on the website. - Should only be run when changes are made, and after the old - database has been deleted. - - Please update this comment when changing the database tables. - - The tables created are: - user(email, nickname, password) - task(taskid, taskName, description, priority, status, user, date) - comment(thecomment, taskid, creator) - estimate(taskid, timeSpent, timeRemaining) -*/ - -sqlite = require('./../lib/node-sqlite/sqlite'); -fs = require('fs'); - -var db = sqlite.Database(); -var dbLocation = "./db/main.db"; // location of database - -fs.mkdir('./db', 0777); - -db.open(dbLocation, function (error) { - if(error) { - console.log(error); - throw error; - } - - db.execute("CREATE TABLE user (" + - "email TEXT PRIMARY KEY," + - "nickname TEXT," + - "password TEXT)", - function (error) { - if(error) { - console.log("Error creating user table."); - throw error; - } - - console.log("User table created."); - }); - - db.execute("CREATE TABLE task (" + - "taskid INTEGER PRIMARY KEY AUTOINCREMENT," + - "taskName TEXT," + - "description TEXT," + - "priority TEXT," + - "status TEXT," + - "user TEXT," + - "date TEXT)", - function (error) { - if(error) { - console.log("Error creating task table."); - throw error; - } - - console.log("Task table created."); - } - ); - - db.execute("CREATE TABLE comment (" + - "thecomment TEXT," + // do i need a primary key? - "taskid NUMBER," + // FOREIGN KEY(taskid) REFERENCES task(taskid) - "email TEXT)", // FOREIGN KEY(creator) REFERENCES user(email) - function (error) { - if(error) { - console.log("Error creating task table."); - throw error; - } - - console.log("comment table created."); - }); - - db.execute("CREATE TABLE estimate (" + - "taskid NUMBER," + // FOREIGN KEY - "timeSpent NUMBER," + - "timeRemaining NUMBER)", - function (error) { - if(error) { - console.log("Error creating estimate table."); - throw error; - } - - console.log("Estimate table created."); - }); -}); - -db.close(function(error) { - if(error) - throw error; -}); - diff --git a/static/add_estimate.html b/static/add_estimate.html deleted file mode 100644 index 018da14..0000000 --- a/static/add_estimate.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - Task Estimation - - - - -
-

- Task ID                          :

- Time Spent(in hours)       :

- Time Remains(in hours)   :

-

-
- - \ No newline at end of file From b71d15bf1c972e7bccd0b460a2f25a5653b865fd Mon Sep 17 00:00:00 2001 From: "Liangbin.Zhang" Date: Fri, 1 Apr 2011 12:57:48 -0700 Subject: [PATCH 05/11] correct the mistake in README file, the path was changed. add estimate table to DB. add addEstimate() and removeEstimate() functions. add a new link to index.html, so that user can go to estimate page. add addestimate.html and taskestimate.js. --- README | 2 +- src/js/createDatabase.js | 13 ++++++ src/node_modules/SQLiteHelper.js | 75 ++++++++++++++++++++++++++++++++ src/static/index.html | 3 ++ 4 files changed, 92 insertions(+), 1 deletion(-) diff --git a/README b/README index 9115aa1..2689622 100644 --- a/README +++ b/README @@ -9,7 +9,7 @@ $ ./runserver where port is a positive integer > 1023. To run the server on a different environment, use -$ node js/dispatcher.js +$ node /src/js/dispatcher.js To interact with the server with your internet browser, browse host:port where host is the hostname of the machine you are running the server diff --git a/src/js/createDatabase.js b/src/js/createDatabase.js index c4ffda4..cdc320b 100755 --- a/src/js/createDatabase.js +++ b/src/js/createDatabase.js @@ -11,6 +11,7 @@ user(email, nickname, password) task(taskid, taskName, description, priority, status, user, date) comment(thecomment, taskid, creator) + estimate(taskid, timeSpent, timeRemaining) */ var basepath = require('basepath').mainpath; @@ -78,6 +79,18 @@ db.open(dbLocation, function (error) { console.log("comment table created."); }); + db.execute("CREATE TABLE estimate (" + + "taskid NUMBER," + + "timeSpent NUMBER," + + "timeRemaining NUMBER)", + function (error) { + if(error) { + console.log("Error creating estimate table."); + throw error; + } + + console.log("estimate table created."); + }); }); db.close(function(error) { diff --git a/src/node_modules/SQLiteHelper.js b/src/node_modules/SQLiteHelper.js index 25e4e72..ae24c7d 100755 --- a/src/node_modules/SQLiteHelper.js +++ b/src/node_modules/SQLiteHelper.js @@ -401,6 +401,81 @@ exports.addComment = function (commentText, commentTaskid, commenterEmail, callb }); } +/** + Parameter1: a taskid that the estmate refers to. (int) + Parameter2: time spent fo the task. (int) + Parameter3: the estimated remaining time of the task. (int) + callback : a function + + This function adds an estimate to the estimate table in the database. +*/ +exports.addEstimate = function (estTaskid, estTimeSpent, estTimeRemaining, callback) { + + var sql = "SELECT * FROM task WHERE taskid = ?"; + + accessDB(sql, [estTaskid], function(error, rows){ + if(error){ + writeLog(error); + if(callback != undefined) { callback({status:-2, detail:error});} + return -2; // error code for caller + } + + if(rows.length == 0) { + writeLog("func: addEstimate, taskid " + estTaskid + " not found."); + if(callback != undefined) { callback({status:-1, detail:error});} + return -1; // error code for caller + } + + }); + + var sql = "SELECT * FROM estimate WHERE taskid = ?"; + accessDB(sql, [estTaskid], function(error, rows){ + if(error){ + writeLog(error); + if(callback != undefined) { callback({status:-2, detail:error});} + return -2; // error code for caller + } + + if(rows.length == 0) { + sql = "INSERT INTO estimate (taskid,timeSpent,timeRemaining) VALUES (?,?,?)" + db.execute(sql, [estTaskid, estTimeSpent, estTimeRemaining], + function(error, rows) { + if(error) { + writeLog(error); + if(callback != undefined) { callback({status:-1, detail:error});} + return -1; // error code for caller + } + + writeLog("estimate of task " + estTaskid + " added."); + if (callback != undefined) { callback({status:0, detail:error})}; + }); + } else { + sql = "UPDATE estimate (timeSpent,timeRemaining) VALUES(?,?) WHERE taskid="+estTaskid; + db.execute(sql, [estTimespent, estTimeRemaining], + function(error, rows){ + if(error) { + writeLog(error); + if(callback != undefined) { callback({status:-2, detail:error});} + return -2; + } + + writeLog("estimate of task " + estTaskid + " updated"); + if (callback != undefined) { callback({status:0, detail:error})}; + }); + } + }); +} + +/** + Parameter1: name of estimate to delete. (String) + Parameter2: callback. (function) + + removes estimate with given taskId if it exists. +*/ +exports.removeTask = function (theTaskid, callback) { + queryGetRows("DELETE FROM estimate WHERE taskid = ?", callback, [theTaskid]); +} + /** Parameter1: Table name. diff --git a/src/static/index.html b/src/static/index.html index b673d98..22b200e 100644 --- a/src/static/index.html +++ b/src/static/index.html @@ -23,6 +23,9 @@

This is a placeholder for the main page

Add Task page

+

+ Edit Estimate page +

Example dynamic page request, using jquery

From 55aaff8de2fa727a67c3ae1fb5f6c478e4138603 Mon Sep 17 00:00:00 2001 From: "Liangbin.Zhang" Date: Fri, 1 Apr 2011 13:08:56 -0700 Subject: [PATCH 06/11] add new html files. --- src/node_modules/SQLiteHelper.js | 2 +- src/static/addestimate.html | 17 +++++++++++++++++ src/static/js/taskestimate.js | 4 ++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/static/addestimate.html create mode 100644 src/static/js/taskestimate.js diff --git a/src/node_modules/SQLiteHelper.js b/src/node_modules/SQLiteHelper.js index ae24c7d..5df27e8 100755 --- a/src/node_modules/SQLiteHelper.js +++ b/src/node_modules/SQLiteHelper.js @@ -472,7 +472,7 @@ exports.addEstimate = function (estTaskid, estTimeSpent, estTimeRemaining, callb removes estimate with given taskId if it exists. */ -exports.removeTask = function (theTaskid, callback) { +exports.removeEstimate = function (theTaskid, callback) { queryGetRows("DELETE FROM estimate WHERE taskid = ?", callback, [theTaskid]); } diff --git a/src/static/addestimate.html b/src/static/addestimate.html new file mode 100644 index 0000000..cbeb924 --- /dev/null +++ b/src/static/addestimate.html @@ -0,0 +1,17 @@ + + + + Add a Task Estimate + + + + +
+

+ Task ID:

+ Time Spent(in hours):

+ Time Remains(in hours):

+

+
+ + \ No newline at end of file diff --git a/src/static/js/taskestimate.js b/src/static/js/taskestimate.js new file mode 100644 index 0000000..33d74a7 --- /dev/null +++ b/src/static/js/taskestimate.js @@ -0,0 +1,4 @@ + +function submitData(id, timeSpent, timeRemain) { + exports.addEstimate(id,timeSpent,timeRemain); +} From d71c78e401cd4c9d2fa112d4c791fed31000e55c Mon Sep 17 00:00:00 2001 From: "Liangbin.Zhang" Date: Fri, 1 Apr 2011 14:08:03 -0700 Subject: [PATCH 07/11] Make Changes. --- src/js/createDatabase.js | 14 ----- src/node_modules/SQLiteHelper.js | 54 ++++++------------- .../{addestimate.html => editestimate.html} | 2 +- src/static/index.html | 2 +- src/static/js/taskestimate.js | 2 +- 5 files changed, 18 insertions(+), 56 deletions(-) rename src/static/{addestimate.html => editestimate.html} (93%) diff --git a/src/js/createDatabase.js b/src/js/createDatabase.js index cdc320b..526778c 100755 --- a/src/js/createDatabase.js +++ b/src/js/createDatabase.js @@ -11,7 +11,6 @@ user(email, nickname, password) task(taskid, taskName, description, priority, status, user, date) comment(thecomment, taskid, creator) - estimate(taskid, timeSpent, timeRemaining) */ var basepath = require('basepath').mainpath; @@ -78,19 +77,6 @@ db.open(dbLocation, function (error) { console.log("comment table created."); }); - - db.execute("CREATE TABLE estimate (" + - "taskid NUMBER," + - "timeSpent NUMBER," + - "timeRemaining NUMBER)", - function (error) { - if(error) { - console.log("Error creating estimate table."); - throw error; - } - - console.log("estimate table created."); - }); }); db.close(function(error) { diff --git a/src/node_modules/SQLiteHelper.js b/src/node_modules/SQLiteHelper.js index 5df27e8..94cd0fb 100755 --- a/src/node_modules/SQLiteHelper.js +++ b/src/node_modules/SQLiteHelper.js @@ -409,7 +409,7 @@ exports.addComment = function (commentText, commentTaskid, commenterEmail, callb This function adds an estimate to the estimate table in the database. */ -exports.addEstimate = function (estTaskid, estTimeSpent, estTimeRemaining, callback) { +exports.updateEstimate = function (estTaskid, estTimeSpent, estTimeRemaining, callback) { var sql = "SELECT * FROM task WHERE taskid = ?"; @@ -421,14 +421,14 @@ exports.addEstimate = function (estTaskid, estTimeSpent, estTimeRemaining, callb } if(rows.length == 0) { - writeLog("func: addEstimate, taskid " + estTaskid + " not found."); + writeLog("func: updateEstimate, taskid " + estTaskid + " not found."); if(callback != undefined) { callback({status:-1, detail:error});} return -1; // error code for caller } }); - var sql = "SELECT * FROM estimate WHERE taskid = ?"; + var sql = "SELECT * FROM task WHERE taskid = ?"; accessDB(sql, [estTaskid], function(error, rows){ if(error){ writeLog(error); @@ -436,46 +436,22 @@ exports.addEstimate = function (estTaskid, estTimeSpent, estTimeRemaining, callb return -2; // error code for caller } - if(rows.length == 0) { - sql = "INSERT INTO estimate (taskid,timeSpent,timeRemaining) VALUES (?,?,?)" - db.execute(sql, [estTaskid, estTimeSpent, estTimeRemaining], - function(error, rows) { - if(error) { - writeLog(error); - if(callback != undefined) { callback({status:-1, detail:error});} - return -1; // error code for caller - } - - writeLog("estimate of task " + estTaskid + " added."); - if (callback != undefined) { callback({status:0, detail:error})}; - }); - } else { - sql = "UPDATE estimate (timeSpent,timeRemaining) VALUES(?,?) WHERE taskid="+estTaskid; - db.execute(sql, [estTimespent, estTimeRemaining], - function(error, rows){ - if(error) { - writeLog(error); - if(callback != undefined) { callback({status:-2, detail:error});} - return -2; - } + sql = "UPDATE task (timeSpent,timeLeft) VALUES(?,?) WHERE taskid="+estTaskid; + db.execute(sql, [estTimespent, estTimeRemaining], + function(error, rows){ + if(error) { + writeLog(error); + if(callback != undefined) { callback({status:-2, detail:error});} + return -2; + } - writeLog("estimate of task " + estTaskid + " updated"); - if (callback != undefined) { callback({status:0, detail:error})}; - }); - } + writeLog("estimate of task " + estTaskid + " updated"); + if (callback != undefined) { callback({status:0, detail:error})}; + }); + }); } -/** - Parameter1: name of estimate to delete. (String) - Parameter2: callback. (function) - - removes estimate with given taskId if it exists. -*/ -exports.removeEstimate = function (theTaskid, callback) { - queryGetRows("DELETE FROM estimate WHERE taskid = ?", callback, [theTaskid]); -} - /** Parameter1: Table name. diff --git a/src/static/addestimate.html b/src/static/editestimate.html similarity index 93% rename from src/static/addestimate.html rename to src/static/editestimate.html index cbeb924..a2ba5d0 100644 --- a/src/static/addestimate.html +++ b/src/static/editestimate.html @@ -1,7 +1,7 @@ - Add a Task Estimate + Edit Task Estimate diff --git a/src/static/index.html b/src/static/index.html index 22b200e..a43cb44 100644 --- a/src/static/index.html +++ b/src/static/index.html @@ -24,7 +24,7 @@

This is a placeholder for the main page

- Edit Estimate page + Edit Estimate page

Example dynamic page request, using jquery diff --git a/src/static/js/taskestimate.js b/src/static/js/taskestimate.js index 33d74a7..dae6eee 100644 --- a/src/static/js/taskestimate.js +++ b/src/static/js/taskestimate.js @@ -1,4 +1,4 @@ function submitData(id, timeSpent, timeRemain) { - exports.addEstimate(id,timeSpent,timeRemain); + //Need to be done } From df8cc7d13541722c32092ad97ec6c8ff782073b5 Mon Sep 17 00:00:00 2001 From: "Liangbin.Zhang" Date: Fri, 1 Apr 2011 14:12:51 -0700 Subject: [PATCH 08/11] ... --- src/js/createDatabase.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/js/createDatabase.js b/src/js/createDatabase.js index 526778c..0bf5827 100755 --- a/src/js/createDatabase.js +++ b/src/js/createDatabase.js @@ -77,6 +77,7 @@ db.open(dbLocation, function (error) { console.log("comment table created."); }); + }); db.close(function(error) { From 019953fd477e860c219b004f41e1612fa8d1435c Mon Sep 17 00:00:00 2001 From: "Liangbin.Zhang" Date: Fri, 15 Apr 2011 10:51:57 -0700 Subject: [PATCH 09/11] add removeCommints to SQLitehelper.js and test. --- src/node_modules/SQLiteHelper.js | 61 ++++----------------- src/static/editestimate.html | 17 ------ src/tests/comments/commentstest_nodeunit.js | 43 +++++++++++++++ src/tests/comments/commentstest_nodeunit.sh | 8 +++ src/tests/dbtest/dbtest.js | 54 ++++++++++++++++++ 5 files changed, 115 insertions(+), 68 deletions(-) delete mode 100644 src/static/editestimate.html create mode 100644 src/tests/comments/commentstest_nodeunit.js create mode 100644 src/tests/comments/commentstest_nodeunit.sh diff --git a/src/node_modules/SQLiteHelper.js b/src/node_modules/SQLiteHelper.js index acffc48..cd61826 100644 --- a/src/node_modules/SQLiteHelper.js +++ b/src/node_modules/SQLiteHelper.js @@ -292,6 +292,16 @@ module.exports.removeUser = function (userEmail, callback) { queryGetRows("DELETE FROM user WHERE email = ?", callback, [userEmail]); }; +/** + Parameter1: taskid of the comments which need to be removed. (String) + Parameter2: callback. (function) + + removes the comments corresponding to the given taskid if it exists. +*/ +module.exports.removeComments = function (commentsTaskid, callback) { + queryGetRows("DELETE FROM user WHERE taskid = ?", callback, [commentsTaskid]); +}; + /** Parameter1: a comment. (String) Parameter2: the taskid that the comment refers to. (String) @@ -353,57 +363,6 @@ module.exports.addComment = function (commentText, commentTaskid, commenterEmail }); }; -/** - Parameter1: a taskid that the estmate refers to. (int) - Parameter2: time spent fo the task. (int) - Parameter3: the estimated remaining time of the task. (int) - callback : a function - - This function adds an estimate to the estimate table in the database. -*/ -exports.updateEstimate = function (estTaskid, estTimeSpent, estTimeRemaining, callback) { - - var sql = "SELECT * FROM task WHERE taskid = ?"; - - accessDB(sql, [estTaskid], function(error, rows){ - if(error){ - writeLog(error); - if(callback != undefined) { callback({status:-2, detail:error});} - return -2; // error code for caller - } - - if(rows.length == 0) { - writeLog("func: updateEstimate, taskid " + estTaskid + " not found."); - if(callback != undefined) { callback({status:-1, detail:error});} - return -1; // error code for caller - } - - }); - - var sql = "SELECT * FROM task WHERE taskid = ?"; - accessDB(sql, [estTaskid], function(error, rows){ - if(error){ - writeLog(error); - if(callback != undefined) { callback({status:-2, detail:error});} - return -2; // error code for caller - } - - sql = "UPDATE task (timeSpent,timeLeft) VALUES(?,?) WHERE taskid="+estTaskid; - db.execute(sql, [estTimespent, estTimeRemaining], - function(error, rows){ - if(error) { - writeLog(error); - if(callback != undefined) { callback({status:-2, detail:error});} - return -2; - } - - writeLog("estimate of task " + estTaskid + " updated"); - if (callback != undefined) { callback({status:0, detail:error})}; - }); - - }); -} - /** Parameter1: Table name. diff --git a/src/static/editestimate.html b/src/static/editestimate.html deleted file mode 100644 index a2ba5d0..0000000 --- a/src/static/editestimate.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - Edit Task Estimate - - - - -

-

- Task ID:

- Time Spent(in hours):

- Time Remains(in hours):

-

-
- - \ No newline at end of file diff --git a/src/tests/comments/commentstest_nodeunit.js b/src/tests/comments/commentstest_nodeunit.js new file mode 100644 index 0000000..4d48dc6 --- /dev/null +++ b/src/tests/comments/commentstest_nodeunit.js @@ -0,0 +1,43 @@ +var path = require('path'); +var fs = require('fs'); +var basepath = require('basepath').mainpath; +var sqlite = require(basepath + 'lib/node-sqlite/sqlite'); +var slh = require('SQLiteHelper'); +var dbLocation = (basepath + 'db/main.db'); +var task = require('task'); + + +exports.CommentsTest = { + 'Test That Comments Can Be Added': function (test) { + test.expect(1); + + var succeeded = false; + + slh.addComment("testcomment", commentsTaskid, "test@test.com", + function (rtv) { + if (rtv.status == 0) { + succeeded = true; + + } + + test.ok(succeeded, "Adding comments failed!"); + test.done(); + }); + }, + + 'Test That Comments Can Be Removed': function (test) { + test.expect(1); + + var succeeded = false; + slh.removeComments(commentsTaskid, + function (rtv) { + if (rtv.status == 0) { + succeeded = true; + + } + + test.ok(succeeded, "Removing comments failed!"); + test.done(); + }); + }, +}; \ No newline at end of file diff --git a/src/tests/comments/commentstest_nodeunit.sh b/src/tests/comments/commentstest_nodeunit.sh new file mode 100644 index 0000000..b18e118 --- /dev/null +++ b/src/tests/comments/commentstest_nodeunit.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +cd .. +cd .. +node js/createDatabase.js + +node tests/nodeunit/bin/nodeunit tests/comments/commentstest_nodeunit.js + diff --git a/src/tests/dbtest/dbtest.js b/src/tests/dbtest/dbtest.js index 2b1d6ac..87b7f52 100644 --- a/src/tests/dbtest/dbtest.js +++ b/src/tests/dbtest/dbtest.js @@ -145,6 +145,30 @@ function userExistsTest(){ }); } +/* + * addCommentsTest() + * + * tests whether or not a comment can be added. + * + */ +function addCommentsTest(){ + dbtest.addToLog("attempting to add a comment..."); + slh.addUser("test@thisdomainshouldnotexist.com", + "testuser", + "thereismorethanoneofeverything", + function(error){ + if (error.status == 0){ + dbtest.addToLog("user added successfully\n"); + dbtest.callNext(); + } + else { + dbtest.addToLog("failed to add user(" + + error.detail.message +")\n"); + dbtest.callNext(); + } + }); +} + /* * addTaskTest() * @@ -175,6 +199,36 @@ function addTaskTest(){ }); } +/* + * + * + * + */ + + function addCommentsTest(){ + dbtest.addToLog("attempting to add a comment..."); + + var taskObj = new task.Task("dummy comment", + "Find out where that noise is coming from", + "High", + "Work in progress", + "test@thisdomainshouldnotexist.com", + new Date()); + + slh.addTask(taskObj, + function(error){ + if (error.status == -1){ + dbtest.addToLog("user task added successfully\n"); + dbtest.callNext(); + } + else { + dbtest.addToLog("failed to add task(" + + error.detail.message +")\n"); + dbtest.callNext(); + } + }); +} + /* * removeTaskTest() * From 998ed7791d9c71f650e619ba606c074b324d1895 Mon Sep 17 00:00:00 2001 From: "Liangbin.Zhang" Date: Fri, 15 Apr 2011 11:01:06 -0700 Subject: [PATCH 10/11] fixed problems. --- README | 2 +- src/static/index.html | 4 +--- src/static/js/taskestimate.js | 4 ---- src/tests/dbtest/dbtest.js | 24 ------------------------ 4 files changed, 2 insertions(+), 32 deletions(-) delete mode 100644 src/static/js/taskestimate.js diff --git a/README b/README index 2689622..1c4beac 100644 --- a/README +++ b/README @@ -9,7 +9,7 @@ $ ./runserver where port is a positive integer > 1023. To run the server on a different environment, use -$ node /src/js/dispatcher.js +$ node js/dispatcher.js To interact with the server with your internet browser, browse host:port where host is the hostname of the machine you are running the server diff --git a/src/static/index.html b/src/static/index.html index fed0545..b3e1739 100644 --- a/src/static/index.html +++ b/src/static/index.html @@ -27,9 +27,7 @@

This is a placeholder for the main page

Add Task page

-

- Edit Estimate page -

+

Example dynamic page request, using jquery

diff --git a/src/static/js/taskestimate.js b/src/static/js/taskestimate.js deleted file mode 100644 index dae6eee..0000000 --- a/src/static/js/taskestimate.js +++ /dev/null @@ -1,4 +0,0 @@ - -function submitData(id, timeSpent, timeRemain) { - //Need to be done -} diff --git a/src/tests/dbtest/dbtest.js b/src/tests/dbtest/dbtest.js index 87b7f52..8e6ffbf 100644 --- a/src/tests/dbtest/dbtest.js +++ b/src/tests/dbtest/dbtest.js @@ -145,30 +145,6 @@ function userExistsTest(){ }); } -/* - * addCommentsTest() - * - * tests whether or not a comment can be added. - * - */ -function addCommentsTest(){ - dbtest.addToLog("attempting to add a comment..."); - slh.addUser("test@thisdomainshouldnotexist.com", - "testuser", - "thereismorethanoneofeverything", - function(error){ - if (error.status == 0){ - dbtest.addToLog("user added successfully\n"); - dbtest.callNext(); - } - else { - dbtest.addToLog("failed to add user(" - + error.detail.message +")\n"); - dbtest.callNext(); - } - }); -} - /* * addTaskTest() * From 48747d4164f84d9118ac0fab0f90be248bf9a61e Mon Sep 17 00:00:00 2001 From: "Liangbin.Zhang" Date: Fri, 15 Apr 2011 11:03:43 -0700 Subject: [PATCH 11/11] fixed. --- src/tests/dbtest/dbtest.js | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/src/tests/dbtest/dbtest.js b/src/tests/dbtest/dbtest.js index 8e6ffbf..2b1d6ac 100644 --- a/src/tests/dbtest/dbtest.js +++ b/src/tests/dbtest/dbtest.js @@ -175,36 +175,6 @@ function addTaskTest(){ }); } -/* - * - * - * - */ - - function addCommentsTest(){ - dbtest.addToLog("attempting to add a comment..."); - - var taskObj = new task.Task("dummy comment", - "Find out where that noise is coming from", - "High", - "Work in progress", - "test@thisdomainshouldnotexist.com", - new Date()); - - slh.addTask(taskObj, - function(error){ - if (error.status == -1){ - dbtest.addToLog("user task added successfully\n"); - dbtest.callNext(); - } - else { - dbtest.addToLog("failed to add task(" - + error.detail.message +")\n"); - dbtest.callNext(); - } - }); -} - /* * removeTaskTest() *