aboutsummaryrefslogtreecommitdiffstats
path: root/lib/logger.es
diff options
context:
space:
mode:
Diffstat (limited to 'lib/logger.es')
-rw-r--r--lib/logger.es91
1 files changed, 91 insertions, 0 deletions
diff --git a/lib/logger.es b/lib/logger.es
new file mode 100644
index 0000000..89e8ad1
--- /dev/null
+++ b/lib/logger.es
@@ -0,0 +1,91 @@
+// Released under the MIT/X11 license
+// http://www.opensource.org/licenses/mit-license.php
+"use strict";
+var fileMod = require("sdk/io/file");
+var prompts = require("prompts");
+var myStorage = require("sdk/simple-storage");
+
+var EmptyLogsColor = "rgb(0, 255, 0)";
+var FullLogsColor = "rgb(0, 40, 103)";
+
+var abbsMap = {};
+
+class LogStorage {
+ // yes, also JSON.parsin and back are horribly slow, but I don't want
+ // to deal with the mess of caching
+ constructor() {
+ if (!localStorage.logs) {
+ localStorage.logs = "";
+ }
+ }
+
+ get data() {
+ return JSON.parse(localStorage.logs);
+ }
+
+ get length() {
+ return this.data.length
+ }
+
+ get(key) {
+ return this.data[key];
+ }
+
+ set(key, value) {
+ let data = this.data;
+ data[key] = value;
+ localStorage.logs = JSON.stringify(data);
+ }
+
+ has_key(key) {
+ return (key in this.data);
+ }
+
+ clear() {
+ localStorage.logs = "";
+ }
+}
+
+var myStorage = LogStorage();
+
+exports.initialize = function initialize() {
+ //
+};
+
+exports.addLogRecord = function addLogRecord(rec) {
+ if (myStorage.has_key(rec.key) && myStorage.get(rec.key).comment) {
+ let storage_rec = myStorage.get(rec.key);
+ storage_rec.comment += "<br/>\n" + rec.comment;
+ myStorage.set(rec.key, storage_rec);
+ }
+ else {
+ myStorage.set(rec.key, rec);
+ }
+};
+
+exports.getAllRecords = function getAllRecords() {
+ return myStorage.data;
+};
+
+exports.clearTimeSheet = function clearTimeSheet() {
+ myStorage.clear();
+};
+
+exports.importTimeSheet = function importTimeSheet() {
+ var filename = prompts.promptFileOpenPicker();
+ if (fileMod.exists(filename)) {
+ var otherTS = JSON.parse(fileMod.read(filename));
+ if (otherTS.logs) {
+ for ( var rec in otherTS.logs) {
+ myStorage.set(rec, otherTS.logs[rc]);
+ }
+ }
+ else {
+ console.error("This is not a log file!");
+ }
+ }
+ else {
+ console.error("File " + filename + " doesn't exist!");
+ }
+};
+