aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2015-11-16 23:44:53 +0100
committerMatěj Cepl <mcepl@cepl.eu>2015-11-16 23:44:53 +0100
commitf51412de797ca2a683dc04311f4c7195756f5f9c (patch)
treebb77f509fdd84fac98c5673f4126a59d2a233d9c
parentf244fefbcd9a2116c337bf20e8088e389e3adc32 (diff)
downloadbugzilla-triage-localStorage.tar.gz
The first version of the rewrite of logger.js to ES6 + WebExtesions API.localStorage
See https://bugzilla.mozilla.org/show_bug.cgi?id=1214790
-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!");
+ }
+};
+