From 174ff725316ce879ae87597da2873b24962f35c6 Mon Sep 17 00:00:00 2001 From: RobertFridolin Date: Wed, 12 Jun 2024 19:48:00 +0200 Subject: [PATCH 1/3] Update content_dashboard.js attempt to delete invalid data --- extension/content_dashboard.js | 74 +++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 5 deletions(-) diff --git a/extension/content_dashboard.js b/extension/content_dashboard.js index cbfb700..3340d3e 100644 --- a/extension/content_dashboard.js +++ b/extension/content_dashboard.js @@ -7,16 +7,80 @@ $(function() { airline = AES.getAirlineCode(); server = AES.getServerName(); chrome.storage.local.get(['settings'], function(result) { - settings = result.settings; + settings = result.settings; - displayDashboard(); + if ((settings['flightInformationsFixed'] === undefined) || (settings['flightInformationsFixed'] !== 1)) { + fixAndDeleteInvalidData(); + } + + displayDashboard(); + dashboardHandle(); + + $("#aes-select-dashboard-main").change(function() { dashboardHandle(); - $("#aes-select-dashboard-main").change(function() { - dashboardHandle(); - }); + }); }); }); +function fixAndDeleteInvalidData() { + const DataToFix = []; + + chrome.storage.local.get(null, async function (entries) { + for (const key in entries) { + if (key.endsWith("routeAnalysis") || key.endsWith("schedule")) { + const invalidDates = []; + for (const date in entries[key]['date']) { + if (!date.startsWith("20") || date.length !== 8) { + invalidDates.push(date); + } + } + if (invalidDates.length) { + invalidDates.forEach(date => delete entries[key]['date'][date]); + DataToFix.push(entries[key]); + } + } else if (key.endsWith("personelManagement") || key.includes("flightInfo")) { + if (entries[key]['date'] !== undefined && (!entries[key]['date'].startsWith("20") || entries[key]['date'].length !== 8)) { + chrome.storage.local.remove([key], function () { + if (chrome.runtime.lastError) { + throw new Error('Error deleting invalid data:' + chrome.runtime.lastError.message); + } + }); + } + } + } + + await fixInvalidData(DataToFix); + }); +} + +async function fixInvalidData(entries) { + let fixingSuccess = false; + + if (entries.length !== 0) { + const promises = entries.map(entry => chrome.storage.local.set({ [entry.key]: entry })); + + try { + await Promise.all(promises); + fixingSuccess = true; + } catch (error) { + throw new Error('Error fixing invalid data:' + error); + } + } + + if (entries.length === 0 || fixingSuccess) { + chrome.storage.local.get('settings', function(result) { + let settings = result.settings || {}; + settings['flightInformationsFixed'] = 1; + + chrome.storage.local.set({ 'settings': settings }, function() { + if (chrome.runtime.lastError) { + throw new Error('Error saving settings:' + chrome.runtime.lastError.message); + } + }); + }); + } +} + function displayDashboard() { let mainDiv = $("#enterprise-dashboard"); mainDiv.before( From 9398d224bc14c05bb54e51a21370ea975f6b0605 Mon Sep 17 00:00:00 2001 From: RobertFridolin Date: Thu, 13 Jun 2024 22:10:52 +0200 Subject: [PATCH 2/3] Update content_dashboard.js attempt 2 to delete invalid data added some more data to clean more consistent Promise use --- extension/content_dashboard.js | 95 ++++++++++++++++------------------ 1 file changed, 46 insertions(+), 49 deletions(-) diff --git a/extension/content_dashboard.js b/extension/content_dashboard.js index 3340d3e..63ca0f3 100644 --- a/extension/content_dashboard.js +++ b/extension/content_dashboard.js @@ -23,62 +23,59 @@ $(function() { }); function fixAndDeleteInvalidData() { - const DataToFix = []; - - chrome.storage.local.get(null, async function (entries) { - for (const key in entries) { - if (key.endsWith("routeAnalysis") || key.endsWith("schedule")) { - const invalidDates = []; - for (const date in entries[key]['date']) { - if (!date.startsWith("20") || date.length !== 8) { - invalidDates.push(date); - } - } - if (invalidDates.length) { - invalidDates.forEach(date => delete entries[key]['date'][date]); - DataToFix.push(entries[key]); - } - } else if (key.endsWith("personelManagement") || key.includes("flightInfo")) { - if (entries[key]['date'] !== undefined && (!entries[key]['date'].startsWith("20") || entries[key]['date'].length !== 8)) { - chrome.storage.local.remove([key], function () { - if (chrome.runtime.lastError) { - throw new Error('Error deleting invalid data:' + chrome.runtime.lastError.message); + chrome.storage.local.get(null, function (entries) { + const tasks = []; + let settingsUpdated = false; + + function cleanAndSave(entry, key) { + return new Promise((resolve, reject) => { + if (key.endsWith("routeAnalysis") || key.endsWith("schedule")) { + if (entry.date) { + for (const dateKey in entry.date) { + if (!dateKey.startsWith("20") || dateKey.length !== 8) { + delete entry.date[dateKey]; + } } - }); + } + } else if (key.endsWith("aircraftFleet")) { + entry.fleet = entry.fleet.filter(item => item.date && item.date.startsWith("20") && item.date.length === 8); + } else if (key.endsWith("personelManagement") || key.includes("flightInfo") || key.includes("aircraftFlights")) { + if (entry.date && (!entry.date.startsWith("20") || entry.date.length !== 8)) { + delete entries[key]; + } } - } - } - - await fixInvalidData(DataToFix); - }); -} - -async function fixInvalidData(entries) { - let fixingSuccess = false; - if (entries.length !== 0) { - const promises = entries.map(entry => chrome.storage.local.set({ [entry.key]: entry })); - - try { - await Promise.all(promises); - fixingSuccess = true; - } catch (error) { - throw new Error('Error fixing invalid data:' + error); + chrome.storage.local.set({ [key]: entry }, function () { + if (chrome.runtime.lastError) { + reject(new Error('Error saving cleaned data for ' + key + ': ' + chrome.runtime.lastError.message)); + } else { + resolve(); + } + }); + }); } - } - if (entries.length === 0 || fixingSuccess) { - chrome.storage.local.get('settings', function(result) { - let settings = result.settings || {}; - settings['flightInformationsFixed'] = 1; + Object.keys(entries).forEach(key => { + tasks.push(cleanAndSave(entries[key], key)); + }); - chrome.storage.local.set({ 'settings': settings }, function() { - if (chrome.runtime.lastError) { - throw new Error('Error saving settings:' + chrome.runtime.lastError.message); - } - }); + Promise.all(tasks).then(() => { + if (!settingsUpdated) { + chrome.storage.local.get('settings', function (result) { + const settings = result.settings || {}; + settings.flightInformationsFixed = 1; + chrome.storage.local.set({ settings: settings }, function () { + if (chrome.runtime.lastError) { + console.error('Error setting flightInformationsFixed:', chrome.runtime.lastError.message); + } + }); + }); + settingsUpdated = true; + } + }).catch(error => { + console.error('Error cleaning and saving data:', error); }); - } + }); } function displayDashboard() { From 8e11befb64cf97623515bec0c72d2d11fcee1169 Mon Sep 17 00:00:00 2001 From: RobertFridolin Date: Fri, 14 Jun 2024 06:30:32 +0200 Subject: [PATCH 3/3] Update content_dashboard.js removed some unnecessary code --- extension/content_dashboard.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/extension/content_dashboard.js b/extension/content_dashboard.js index 63ca0f3..897dc08 100644 --- a/extension/content_dashboard.js +++ b/extension/content_dashboard.js @@ -25,7 +25,6 @@ $(function() { function fixAndDeleteInvalidData() { chrome.storage.local.get(null, function (entries) { const tasks = []; - let settingsUpdated = false; function cleanAndSave(entry, key) { return new Promise((resolve, reject) => { @@ -60,18 +59,15 @@ function fixAndDeleteInvalidData() { }); Promise.all(tasks).then(() => { - if (!settingsUpdated) { - chrome.storage.local.get('settings', function (result) { - const settings = result.settings || {}; - settings.flightInformationsFixed = 1; - chrome.storage.local.set({ settings: settings }, function () { - if (chrome.runtime.lastError) { - console.error('Error setting flightInformationsFixed:', chrome.runtime.lastError.message); - } - }); + chrome.storage.local.get('settings', function (result) { + const settings = result.settings || {}; + settings.flightInformationsFixed = 1; + chrome.storage.local.set({ settings: settings }, function () { + if (chrome.runtime.lastError) { + console.error('Error setting flightInformationsFixed:', chrome.runtime.lastError.message); + } }); - settingsUpdated = true; - } + }); }).catch(error => { console.error('Error cleaning and saving data:', error); });