From 1344baa59cec0484fa935b09590dd5e828291aa8 Mon Sep 17 00:00:00 2001 From: Tomas Chmelevskij Date: Wed, 4 Jan 2023 13:42:02 +0100 Subject: [PATCH] Refactor presets tab to use modules as much as possible (#3190) Refactor presets to use modules --- src/js/tabs/logging.js | 1 + src/main.html | 12 ------------ src/tabs/presets/CliEngine.js | 5 +++-- .../DetailedDialog/PresetsDetailedDialog.js | 7 +++++-- src/tabs/presets/FavoritePresets.js | 5 +++-- src/tabs/presets/PickedPreset.js | 4 +--- .../presets/PresetsRepoIndexed/PresetParser.js | 3 +-- .../PresetsRepoIndexed/PresetsGithubRepo.js | 4 ++-- .../PresetsRepoIndexed/PresetsRepoIndexed.js | 4 ++-- .../PresetsRepoIndexed/PresetsWebsiteRepo.js | 4 ++-- src/tabs/presets/SourcesDialog/PresetSource.js | 4 +--- src/tabs/presets/SourcesDialog/SourcePanel.js | 9 +++++---- src/tabs/presets/SourcesDialog/SourcesDialog.js | 15 +++++++++------ src/tabs/presets/TitlePanel/PresetTitlePanel.js | 4 ++-- src/tabs/presets/presets.js | 9 +++++++++ 15 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/js/tabs/logging.js b/src/js/tabs/logging.js index dfd3f87d..6954d1fe 100644 --- a/src/js/tabs/logging.js +++ b/src/js/tabs/logging.js @@ -1,5 +1,6 @@ import { millitime } from '../utils/common.js'; import GUI from '../gui'; +import { i18n } from '../localization'; import { get as getConfig, set as setConfig } from '../ConfigStorage'; const logging = {}; diff --git a/src/main.html b/src/main.html index 721d0241..4591b1b1 100644 --- a/src/main.html +++ b/src/main.html @@ -108,18 +108,6 @@ - - - - - - - - - - - - diff --git a/src/tabs/presets/CliEngine.js b/src/tabs/presets/CliEngine.js index 896a06cd..5473f941 100644 --- a/src/tabs/presets/CliEngine.js +++ b/src/tabs/presets/CliEngine.js @@ -1,6 +1,7 @@ -'use strict'; +import GUI from "../../js/gui"; +import { i18n } from "../../js/localization"; -class CliEngine +export default class CliEngine { constructor(currentTab) { this._currentTab = currentTab; diff --git a/src/tabs/presets/DetailedDialog/PresetsDetailedDialog.js b/src/tabs/presets/DetailedDialog/PresetsDetailedDialog.js index cbf4e075..ee794b39 100644 --- a/src/tabs/presets/DetailedDialog/PresetsDetailedDialog.js +++ b/src/tabs/presets/DetailedDialog/PresetsDetailedDialog.js @@ -1,6 +1,9 @@ -'use strict'; +import GUI from "../../../js/gui"; +import { i18n } from "../../../js/localization"; +import PickedPreset from "../PickedPreset"; +import PresetTitlePanel from "../TitlePanel/PresetTitlePanel"; -class PresetsDetailedDialog { +export default class PresetsDetailedDialog { constructor(domDialog, pickedPresetList, onPresetPickedCallback, favoritePresets) { this._domDialog = domDialog; this._pickedPresetList = pickedPresetList; diff --git a/src/tabs/presets/FavoritePresets.js b/src/tabs/presets/FavoritePresets.js index 9693d7d5..b4ce87a0 100644 --- a/src/tabs/presets/FavoritePresets.js +++ b/src/tabs/presets/FavoritePresets.js @@ -1,3 +1,4 @@ +import { get as getConfig, set as setConfig } from "../../js/ConfigStorage"; const s_maxFavoritePresetsCount = 50; const s_favoritePresetsListConfigStorageName = "FavoritePresetsList"; @@ -25,7 +26,7 @@ class FavoritePresetsData { loadFromStorage() { this._favoritePresetsList = []; - const obj = ConfigStorage.get(s_favoritePresetsListConfigStorageName); + const obj = getConfig(s_favoritePresetsListConfigStorageName); if (obj[s_favoritePresetsListConfigStorageName]) { this._favoritePresetsList = obj[s_favoritePresetsListConfigStorageName]; @@ -35,7 +36,7 @@ class FavoritePresetsData { saveToStorage() { const obj = {}; obj[s_favoritePresetsListConfigStorageName] = this._favoritePresetsList; - ConfigStorage.set(obj); + setConfig(obj); } add(presetPath) { diff --git a/src/tabs/presets/PickedPreset.js b/src/tabs/presets/PickedPreset.js index e8440e21..96b197e0 100644 --- a/src/tabs/presets/PickedPreset.js +++ b/src/tabs/presets/PickedPreset.js @@ -1,6 +1,4 @@ -'use strict'; - -class PickedPreset +export default class PickedPreset { constructor(preset, presetCli) { diff --git a/src/tabs/presets/PresetsRepoIndexed/PresetParser.js b/src/tabs/presets/PresetsRepoIndexed/PresetParser.js index 111465e4..2234314e 100644 --- a/src/tabs/presets/PresetsRepoIndexed/PresetParser.js +++ b/src/tabs/presets/PresetsRepoIndexed/PresetParser.js @@ -1,6 +1,5 @@ -'use strict'; -class PresetParser { +export default class PresetParser { constructor(settings) { this._settings = settings; } diff --git a/src/tabs/presets/PresetsRepoIndexed/PresetsGithubRepo.js b/src/tabs/presets/PresetsRepoIndexed/PresetsGithubRepo.js index 2f1a39ec..e3405784 100644 --- a/src/tabs/presets/PresetsRepoIndexed/PresetsGithubRepo.js +++ b/src/tabs/presets/PresetsRepoIndexed/PresetsGithubRepo.js @@ -1,6 +1,6 @@ -'use strict'; +import PresetsRepoIndexed from "./PresetsRepoIndexed"; -class PresetsGithubRepo extends PresetsRepoIndexed { +export default class PresetsGithubRepo extends PresetsRepoIndexed { constructor(urlRepo, branch) { let correctUrlRepo = urlRepo.trim(); diff --git a/src/tabs/presets/PresetsRepoIndexed/PresetsRepoIndexed.js b/src/tabs/presets/PresetsRepoIndexed/PresetsRepoIndexed.js index e8f5ea11..a013cb27 100644 --- a/src/tabs/presets/PresetsRepoIndexed/PresetsRepoIndexed.js +++ b/src/tabs/presets/PresetsRepoIndexed/PresetsRepoIndexed.js @@ -1,6 +1,6 @@ -'use strict'; +import PresetParser from "./PresetParser"; -class PresetsRepoIndexed { +export default class PresetsRepoIndexed { constructor(urlRaw, urlViewOnline) { this._urlRaw = urlRaw; this._urlViewOnline = urlViewOnline; diff --git a/src/tabs/presets/PresetsRepoIndexed/PresetsWebsiteRepo.js b/src/tabs/presets/PresetsRepoIndexed/PresetsWebsiteRepo.js index 63165510..28388cd6 100644 --- a/src/tabs/presets/PresetsRepoIndexed/PresetsWebsiteRepo.js +++ b/src/tabs/presets/PresetsRepoIndexed/PresetsWebsiteRepo.js @@ -1,6 +1,6 @@ -'use strict'; +import PresetsRepoIndexed from "./PresetsRepoIndexed"; -class PresetsWebsiteRepo extends PresetsRepoIndexed { +export default class PresetsWebsiteRepo extends PresetsRepoIndexed { constructor(url) { let correctUrl = url.trim(); diff --git a/src/tabs/presets/SourcesDialog/PresetSource.js b/src/tabs/presets/SourcesDialog/PresetSource.js index 6d4dd425..ead8760d 100644 --- a/src/tabs/presets/SourcesDialog/PresetSource.js +++ b/src/tabs/presets/SourcesDialog/PresetSource.js @@ -1,6 +1,4 @@ -'use strict'; - -class PresetSource { +export default class PresetSource { constructor(name, url, gitHubBranch = "") { this.name = name; this.url = url; diff --git a/src/tabs/presets/SourcesDialog/SourcePanel.js b/src/tabs/presets/SourcesDialog/SourcePanel.js index 3533b8c9..a930b8a5 100644 --- a/src/tabs/presets/SourcesDialog/SourcePanel.js +++ b/src/tabs/presets/SourcesDialog/SourcePanel.js @@ -1,6 +1,8 @@ -'use strict'; +import { i18n } from "../../../js/localization"; +import GUI from "../../../js/gui"; +import PresetSource from "./PresetSource"; -class SourcePanel { +export default class SourcePanel { constructor(parentDiv, presetSource) { this._parentDiv = parentDiv; this._presetSource = presetSource; @@ -130,7 +132,7 @@ class SourcePanel { } _checkIfGithub() { - const isGithubUrl = PresetSource.isUrlGithubRepo(this._domEditUrl.val()); + const isGithubUrl = PresetSource.isUrlGithubRepo(this._domEditUrl.val()); this._domDivGithubBranch.toggle(isGithubUrl); } @@ -197,4 +199,3 @@ class SourcePanel { } SourcePanel.s_panelCounter = 0; - diff --git a/src/tabs/presets/SourcesDialog/SourcesDialog.js b/src/tabs/presets/SourcesDialog/SourcesDialog.js index abde48be..bf9679d5 100644 --- a/src/tabs/presets/SourcesDialog/SourcesDialog.js +++ b/src/tabs/presets/SourcesDialog/SourcesDialog.js @@ -1,6 +1,9 @@ -'use strict'; +import { i18n } from "../../../js/localization"; +import { get as getConfig, set as setConfig } from "../../../js/ConfigStorage"; +import PresetSource from "./PresetSource"; +import SourcePanel from "./SourcePanel"; -class PresetsSourcesDialog { +export default class PresetsSourcesDialog { constructor(domDialog) { this._domDialog = domDialog; this._sourceSelectedPromiseResolve = null; @@ -47,7 +50,7 @@ class PresetsSourcesDialog { const officialSource = this._createOfficialSource(); const officialSourceSecondary = this._createSecondaryOfficialSource(); - const obj = ConfigStorage.get('PresetSources'); + const obj = getConfig('PresetSources'); let sources = obj.PresetSources; if (sources && sources.length > 0) { @@ -64,7 +67,7 @@ class PresetsSourcesDialog { } _readActiveSourceIndexFromStorage(sourcesCount) { - const obj = ConfigStorage.get('PresetSourcesActiveIndex'); + const obj = getConfig('PresetSourcesActiveIndex'); const index = Number(obj.PresetSourcesActiveIndex); let result = 0; @@ -147,8 +150,8 @@ class PresetsSourcesDialog { } _saveSources() { - ConfigStorage.set({'PresetSources': this._sources}); - ConfigStorage.set({'PresetSourcesActiveIndex': this._activeSourceIndex}); + setConfig({'PresetSources': this._sources}); + setConfig({'PresetSourcesActiveIndex': this._activeSourceIndex}); } _updateSourcesFromPanels() { diff --git a/src/tabs/presets/TitlePanel/PresetTitlePanel.js b/src/tabs/presets/TitlePanel/PresetTitlePanel.js index 8c49760d..373fdcb7 100644 --- a/src/tabs/presets/TitlePanel/PresetTitlePanel.js +++ b/src/tabs/presets/TitlePanel/PresetTitlePanel.js @@ -1,6 +1,6 @@ -'use strict'; +import { i18n } from "../../../js/localization"; -class PresetTitlePanel +export default class PresetTitlePanel { constructor(parentDiv, preset, clickable, onLoadedCallback, favoritePresets) { diff --git a/src/tabs/presets/presets.js b/src/tabs/presets/presets.js index 17249e0e..3ef6d78b 100644 --- a/src/tabs/presets/presets.js +++ b/src/tabs/presets/presets.js @@ -1,7 +1,16 @@ import GUI from '../../js/gui'; import { get as getConfig, set as setConfig } from '../../js/ConfigStorage'; +import { i18n } from '../../js/localization'; import { favoritePresets } from './FavoritePresets'; +import CliEngine from './CliEngine'; +import PickedPreset from './PickedPreset'; +import PresetsDetailedDialog from './DetailedDialog/PresetsDetailedDialog'; +import PresetsGithubRepo from './PresetsRepoIndexed/PresetsGithubRepo'; +import PresetsWebsiteRepo from './PresetsRepoIndexed/PresetsWebsiteRepo'; +import PresetTitlePanel from './TitlePanel/PresetTitlePanel'; +import PresetsSourcesDialog from './SourcesDialog/SourcesDialog'; +import PresetSource from './SourcesDialog/PresetSource'; const presets = { presetsRepo: null,