From 92f1d6de38905d619501a16dbe000ba4f556d38f Mon Sep 17 00:00:00 2001 From: halwan-bot Date: Fri, 20 Nov 2020 19:54:39 +0200 Subject: [PATCH] Fixed hiistory update issue and render issue --- control/content/app.js | 1 + tests/control/content.spec.js | 2 +- widget/app.js | 22 +++++++++------------- widget/js/classes/histories.js | 12 +++--------- widget/js/classes/metrics.js | 2 +- widget/js/helper.js | 2 +- 6 files changed, 16 insertions(+), 25 deletions(-) diff --git a/control/content/app.js b/control/content/app.js index f50bc0b..192bdd5 100644 --- a/control/content/app.js +++ b/control/content/app.js @@ -170,6 +170,7 @@ const initIconComponent = (imageUrl = "") => { imageUrl: imageUrl, title: "Icon", dimensionsLabel: "400x400", + multiSelection: false }); let thumbElement = document diff --git a/tests/control/content.spec.js b/tests/control/content.spec.js index 92b1fe7..b20d6a4 100644 --- a/tests/control/content.spec.js +++ b/tests/control/content.spec.js @@ -231,7 +231,7 @@ describe("Test The Control Side", () => { buildfire.datastore.save({}, "metrics", async (err, data) => { if (err) reject(err); else { - await buildfire.datastore.save( + await buildfire.publicData.save( { metrics: {} }, `history${clientProfile}`, async (err, result) => { diff --git a/widget/app.js b/widget/app.js index b156661..2ecf085 100644 --- a/widget/app.js +++ b/widget/app.js @@ -124,12 +124,7 @@ buildfire.datastore.onUpdate((event) => { metrics.id = event.id; renderInit(); } else if (event.tag === "settings") { - return Settings.load().then(() => { - if (!isQeuryProvided && Settings.dataPolicyType === "private") { - Settings.tags = []; - } - loadApp(); - }); + loadApp(); } } }); @@ -139,12 +134,13 @@ buildfire.publicData.onUpdate((event) => { if (event.status && event.nModified) { Histories.getHistories(clientProfile).then((result) => { histories = result; - loadApp(); + renderInit(); + }); + } else if (event.tag && event.tag.indexOf("history") > -1) { + Histories.getHistories(clientProfile).then((result) => { + histories = result; + renderInit(); }); - } else if (event.data && event.id && event.tag.includes("history")) { - histories = event.data; - histories = event.id; - loadApp(); } }); @@ -627,10 +623,10 @@ buildfire.history.onPop((breadcrumb) => { helpers.showElem("#metricsScreen"); helpers.hideElem("#updateHistoryContainer, #updateHistoryButton"); - renderInit(); - if (numberOfPops) { buildfire.history.pop(); + } else { + renderInit(); } } else { // This condition is for preventing the control side from going back (when clicking back in widget) diff --git a/widget/js/classes/histories.js b/widget/js/classes/histories.js index 17ab89a..29364b4 100644 --- a/widget/js/classes/histories.js +++ b/widget/js/classes/histories.js @@ -8,8 +8,7 @@ class Histories { if (err) { console.error(err); return reject(err); - } - else { + } else { // Check if there is already objects in the database if (!result.data.metrics) { // If there is no object, then create the parent object @@ -20,8 +19,7 @@ class Histories { if (err) { console.error(err); return reject(err); - } - else { + } else { this.getHistories(clientProfile).then((result) => { resolve(result); }); @@ -38,7 +36,7 @@ class Histories { } static updateMetricHistory({ clientProfile, nodeSelector, historyId }, data) { - const dateOnly = helpers.getAbsoluteDate() + const dateOnly = helpers.getCurrentDate(); return new Promise((resolve, reject) => { if (!nodeSelector) return reject("nodeSelector not provided"); @@ -98,10 +96,6 @@ class Histories { updatedMetricId = updatedMetricId[updatedMetricId.length - 1]; // Track action Analytics.trackAction(`METRIC_${updatedMetricId}_HISTORY_UPDATE`); - - Metrics.getMetrics().then((result) => { - resolve(result); - }); } ); }); diff --git a/widget/js/classes/metrics.js b/widget/js/classes/metrics.js index d1d6913..56eac5a 100644 --- a/widget/js/classes/metrics.js +++ b/widget/js/classes/metrics.js @@ -17,7 +17,7 @@ class Metrics { } static updateMetricHistory({ nodeSelector, metricsId }, data) { - const dateOnly = helpers.getAbsoluteDate(); + const dateOnly = helpers.getCurrentDate(); return new Promise((resolve, reject) => { if (!nodeSelector) return reject("nodeSelector not provided"); diff --git a/widget/js/helper.js b/widget/js/helper.js index e26da12..e1b0ea9 100644 --- a/widget/js/helper.js +++ b/widget/js/helper.js @@ -2,7 +2,7 @@ const helpers = { uuidv4: (m = Math, d = Date, h = 16, s = (s) => m.floor(s).toString(h)) => s(d.now() / 1000) + " ".repeat(h).replace(/./g, () => s(m.random() * h)), // Returns current date in ISO string - getAbsoluteDate: () => { + getCurrentDate: () => { let date = new Date(); return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`; },