Skip to content

Commit

Permalink
Improvements for adding/updating grid fields
Browse files Browse the repository at this point in the history
  • Loading branch information
kbuffington committed Jan 15, 2021
1 parent 2bc8f37 commit b55fd9b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions georgia-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const fileList = [
'js\\configuration.js', // reads/write from config file. The actual configuration values are specified in globals.js
'js\\helpers.js',
'js\\CaTRoX_QWR\\Common.js',
'js\\defaults.js', // used in settings.js
'js\\hyperlinks.js', // used in settings.js
'js\\settings.js', // must be below hyperlinks.js and Common.js
'js\\CaTRoX_QWR\\Utility_LinkedList.js',
Expand Down
3 changes: 2 additions & 1 deletion js/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tf.edition = '[$if(%original release date%,$ifequal($year(%original release date
tf.last_played = '[$if2(%last_played_enhanced%,%last_played%)]';
tf.lyrics = '[$if3(%lyrics%,%lyric%,%unsyncedlyrics%,%unsynced lyrics%)]';
tf.original_artist = '[ \'(\'%original artist%\' cover)\']';
tf.releaseCountry = '%releasecountry%';
tf.releaseCountry = '$replace(%releasecountry%,AF,XW)';
tf.title = '%title%[ \'[\'%translation%\']\']';
tf.tracknum = '[%tracknumber%.]';
tf.vinyl_side = '%vinyl side%';
Expand All @@ -32,6 +32,7 @@ const titleFormatComments = {
artist_country: 'Only used for displaying artist flags.',
date: 'The full date stored for the track',
lyrics: 'Lyrics.js will check these fields in order if no local lyrics file is found.',
releaseCountry: 'Releases tagged from Musicbrainz with a release country of AF (Afghanistan) are almost always whole world releases that have each country listed individually, so replace with \'XW\' (Worldwide) tag.',
title: 'Track title shown above the progress bar',
vinyl_side: 'Used for determining what side a song appears on for vinyl releases - i.e. song A1 has a %vinyl side% of "A"',
vinyl_tracknum: 'Used for determining the track number on vinyl releases - i.e. song A1 has %vinyl tracknumber% set to "1"',
Expand Down
4 changes: 4 additions & 0 deletions js/georgia-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,10 @@ function onOptionsMenu(x, y) {
loadCountryFlags();
RepaintWindow();
});
menu.addToggleItem('Show release country flags', settings, 'showReleaseCountryFlag', () => {
loadReleaseCountryFlag();
RepaintWindow();
});

menu.addSeparator();

Expand Down
2 changes: 2 additions & 0 deletions js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,8 @@ const countryCodes = {
'VU': 'Vanuatu',
'WF': 'Wallis and Futuna',
'WS': 'Samoa',
'XE': 'European Union', // Musicbrainz code for European releases. Council of Europe uses same flag as EU.
'XW': 'United Nations', // Musicbrainz code for all World releases. Uses the UN flag which is the MB standard.
'YE': 'Yemen',
'YT': 'Mayotte',
'ZA': 'South Africa',
Expand Down
29 changes: 20 additions & 9 deletions js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let settings = {};
let globals = {};


const currentVersion = '2.0.0-beta2';
let configVersion = currentVersion; // will be overwritten when loaded from config file
let updateAvailable = false;
let updateHyperlink;
Expand Down Expand Up @@ -175,6 +176,22 @@ pref.cdart_path = '$replace(%path%,%filename_ext%,)' + settings.cdArtBasename +
pref.cdart_amount = 0.48; // show 48% of the CD image if it will fit on the screen

function migrateCheck(version, storedVersion) {
/**
* Adds or Replaces value in the grid with updated string from defaults
* @param {MetadataGridEntry[]} grid
* @param {string} label Label of the value to add or replace
* @param {number} position 0-based index of place to insert new value if existing entry not found
*/
const replaceGridEntry = (grid, label, position) => {
const entryIdx = grid.findIndex(gridEntry => gridEntry.label.toLowerCase() === label.toLowerCase());
const newVal = defaultMetadataGrid[defaultMetadataGrid.findIndex(e => e.label.toLowerCase() === label.toLowerCase())];
if (entryIdx >= 0) {
grid[entryIdx] = newVal;
} else {
grid.splice(position, 0, newVal);
}
}

if (version !== storedVersion) {
const configFile = config.readConfiguration();
/** @type {MetadataGridEntry[]} */
Expand All @@ -184,14 +201,8 @@ function migrateCheck(version, storedVersion) {
switch (storedVersion) {

case '2.0.0-beta1':
// TODO: move this update code to a function
const catIndex = grid.findIndex(gridEntry => gridEntry.label.toLowerCase() === 'catalog #');
const newCatVal = defaultMetadataGrid[defaultMetadataGrid.findIndex(e => e.label === 'Catalog #')];
if (catIndex >= 0) {
grid[catIndex] = newCatVal;
} else {
grid.splice(6, 0, newCatVal);
}
replaceGridEntry(grid, 'Catalog #', 6);
replaceGridEntry(grid, 'Release Country', 7);
config.addConfigurationObject(gridSchema, grid);


Expand All @@ -204,7 +215,7 @@ function migrateCheck(version, storedVersion) {
config.writeConfiguration();
window.Reload();

default:
default:
pref.version = currentVersion;
break;

Expand Down

0 comments on commit b55fd9b

Please sign in to comment.