Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove invalid data #75

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 62 additions & 5 deletions extension/content_dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,73 @@ $(function() {
airline = AES.getAirlineCode();
server = AES.getServerName();
chrome.storage.local.get(['settings'], function(result) {
settings = result.settings;
settings = result.settings;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I ask why you changed the indenting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was not intentional


displayDashboard();
if ((settings['flightInformationsFixed'] === undefined) || (settings['flightInformationsFixed'] !== 1)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it might be nice to base this on version number. Perhaps we could do if versionNumber < 0.6.9? What do you think?

Copy link
Contributor Author

@RobertFridolin RobertFridolin Jun 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course you can do that, but i don't know when exactly the version number changes. So i used this simple "versioning" 1,2,3 in case further fixes are necessary and people already using this need to rerun this.

fixAndDeleteInvalidData();
}

displayDashboard();
dashboardHandle();

$("#aes-select-dashboard-main").change(function() {
dashboardHandle();
$("#aes-select-dashboard-main").change(function() {
dashboardHandle();
});
});
});
});

function fixAndDeleteInvalidData() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please adjust the indent size to .editorconfig spec?

Copy link
Contributor Author

@RobertFridolin RobertFridolin Jun 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, had this set to two because the whole AES code was/is 2 spaces.

chrome.storage.local.get(null, function (entries) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to get the data into a const with an await. Fewer nesting levels make the code easier to read.

Copy link
Contributor Author

@RobertFridolin RobertFridolin Jun 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes maybe, it was just good good enough for temporary use. Do you want to change it?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like you to change it, yes.

const tasks = [];

function cleanAndSave(entry, key) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this function is nested?

Copy link
Contributor Author

@RobertFridolin RobertFridolin Jun 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has access to entries then and functionallity belonged to fixAndDeleteInvalidData, nothing special.
Of course it can be written differently and also moved somewhere else if you want, in content_dashboard.js is already very large anyway.
But it's actually only there temporarily, isn't it?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should write code as if it were permanent.

Improving the code base is a long term project :)

Copy link
Contributor Author

@RobertFridolin RobertFridolin Jun 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, i think this is a code style question. Just rewrite it according to your wishes. :)

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];
}
}

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();
}
});
});
}

Object.keys(entries).forEach(key => {
tasks.push(cleanAndSave(entries[key], key));
});

Promise.all(tasks).then(() => {
chrome.storage.local.get('settings', function (result) {
const settings = result.settings || {};
settings.flightInformationsFixed = 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps instead of a 1 this could be true | false. Or better yet the current AES version number? That way we could verify / update the data in the future

Copy link
Contributor Author

@RobertFridolin RobertFridolin Jun 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added 1 one in case if it needs further fixing, see second answer above

chrome.storage.local.set({ settings: settings }, function () {
if (chrome.runtime.lastError) {
console.error('Error setting flightInformationsFixed:', chrome.runtime.lastError.message);
}
});
});
}).catch(error => {
console.error('Error cleaning and saving data:', error);
});
});
}

function displayDashboard() {
let mainDiv = $("#enterprise-dashboard");
mainDiv.before(
Expand Down