From b55fd9ba67042e5e4123839fe5e5b1b76ad8b3bd Mon Sep 17 00:00:00 2001 From: "kbuffington@gmail.com" Date: Fri, 15 Jan 2021 03:15:01 -0600 Subject: [PATCH] Improvements for adding/updating grid fields --- georgia-theme.js | 1 + js/defaults.js | 3 ++- js/georgia-main.js | 4 ++++ js/helpers.js | 2 ++ js/settings.js | 29 ++++++++++++++++++++--------- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/georgia-theme.js b/georgia-theme.js index 8a759e60..2e9ff995 100644 --- a/georgia-theme.js +++ b/georgia-theme.js @@ -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', diff --git a/js/defaults.js b/js/defaults.js index c916c332..0d415d55 100644 --- a/js/defaults.js +++ b/js/defaults.js @@ -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%'; @@ -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"', diff --git a/js/georgia-main.js b/js/georgia-main.js index 84a632cb..bfaa5775 100644 --- a/js/georgia-main.js +++ b/js/georgia-main.js @@ -1088,6 +1088,10 @@ function onOptionsMenu(x, y) { loadCountryFlags(); RepaintWindow(); }); + menu.addToggleItem('Show release country flags', settings, 'showReleaseCountryFlag', () => { + loadReleaseCountryFlag(); + RepaintWindow(); + }); menu.addSeparator(); diff --git a/js/helpers.js b/js/helpers.js index 274bd2ec..ddc1800c 100644 --- a/js/helpers.js +++ b/js/helpers.js @@ -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', diff --git a/js/settings.js b/js/settings.js index 60bc09f0..ea13fd2f 100644 --- a/js/settings.js +++ b/js/settings.js @@ -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; @@ -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[]} */ @@ -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); @@ -204,7 +215,7 @@ function migrateCheck(version, storedVersion) { config.writeConfiguration(); window.Reload(); - default: + default: pref.version = currentVersion; break;