1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-26 17:55:24 +03:00

Refactor presets tab to use modules as much as possible (#3190)

Refactor presets to use modules
This commit is contained in:
Tomas Chmelevskij 2023-01-04 13:42:02 +01:00 committed by GitHub
parent 05aa4b0fca
commit 1344baa59c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 46 additions and 44 deletions

View file

@ -1,5 +1,6 @@
import { millitime } from '../utils/common.js'; import { millitime } from '../utils/common.js';
import GUI from '../gui'; import GUI from '../gui';
import { i18n } from '../localization';
import { get as getConfig, set as setConfig } from '../ConfigStorage'; import { get as getConfig, set as setConfig } from '../ConfigStorage';
const logging = {}; const logging = {};

View file

@ -108,18 +108,6 @@
<script type="text/javascript" src="./js/ConfigInserter.js"></script> <script type="text/javascript" src="./js/ConfigInserter.js"></script>
<script type="text/javascript" src="./js/GitHubApi.js"></script> <script type="text/javascript" src="./js/GitHubApi.js"></script>
<script type="module" src="./js/main.js"></script> <script type="module" src="./js/main.js"></script>
<!-- TODO: might be removed when everythign is in modules -->
<script type="text/javascript" src="./tabs/presets/CliEngine.js"></script>
<script type="text/javascript" src="./tabs/presets/PickedPreset.js"></script>
<script type="text/javascript" src="./tabs/presets/DetailedDialog/PresetsDetailedDialog.js"></script>
<script type="text/javascript" src="./tabs/presets/TitlePanel/PresetTitlePanel.js"></script>
<script type="text/javascript" src="./tabs/presets/PresetsRepoIndexed/PresetParser.js"></script>
<script type="text/javascript" src="./tabs/presets/PresetsRepoIndexed/PresetsRepoIndexed.js"></script>
<script type="text/javascript" src="./tabs/presets/PresetsRepoIndexed/PresetsGithubRepo.js"></script>
<script type="text/javascript" src="./tabs/presets/PresetsRepoIndexed/PresetsWebsiteRepo.js"></script>
<script type="text/javascript" src="./tabs/presets/SourcesDialog/SourcesDialog.js"></script>
<script type="text/javascript" src="./tabs/presets/SourcesDialog/SourcePanel.js"></script>
<script type="text/javascript" src="./tabs/presets/SourcesDialog/PresetSource.js"></script>
<script type="text/javascript" src="./js/LogoManager.js"></script> <script type="text/javascript" src="./js/LogoManager.js"></script>
<script type="text/javascript" src="./node_modules/jquery-textcomplete/dist/jquery.textcomplete.min.js"></script> <script type="text/javascript" src="./node_modules/jquery-textcomplete/dist/jquery.textcomplete.min.js"></script>
<script type="text/javascript" src="./js/CliAutoComplete.js"></script> <script type="text/javascript" src="./js/CliAutoComplete.js"></script>

View file

@ -1,6 +1,7 @@
'use strict'; import GUI from "../../js/gui";
import { i18n } from "../../js/localization";
class CliEngine export default class CliEngine
{ {
constructor(currentTab) { constructor(currentTab) {
this._currentTab = currentTab; this._currentTab = currentTab;

View file

@ -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) { constructor(domDialog, pickedPresetList, onPresetPickedCallback, favoritePresets) {
this._domDialog = domDialog; this._domDialog = domDialog;
this._pickedPresetList = pickedPresetList; this._pickedPresetList = pickedPresetList;

View file

@ -1,3 +1,4 @@
import { get as getConfig, set as setConfig } from "../../js/ConfigStorage";
const s_maxFavoritePresetsCount = 50; const s_maxFavoritePresetsCount = 50;
const s_favoritePresetsListConfigStorageName = "FavoritePresetsList"; const s_favoritePresetsListConfigStorageName = "FavoritePresetsList";
@ -25,7 +26,7 @@ class FavoritePresetsData {
loadFromStorage() { loadFromStorage() {
this._favoritePresetsList = []; this._favoritePresetsList = [];
const obj = ConfigStorage.get(s_favoritePresetsListConfigStorageName); const obj = getConfig(s_favoritePresetsListConfigStorageName);
if (obj[s_favoritePresetsListConfigStorageName]) { if (obj[s_favoritePresetsListConfigStorageName]) {
this._favoritePresetsList = obj[s_favoritePresetsListConfigStorageName]; this._favoritePresetsList = obj[s_favoritePresetsListConfigStorageName];
@ -35,7 +36,7 @@ class FavoritePresetsData {
saveToStorage() { saveToStorage() {
const obj = {}; const obj = {};
obj[s_favoritePresetsListConfigStorageName] = this._favoritePresetsList; obj[s_favoritePresetsListConfigStorageName] = this._favoritePresetsList;
ConfigStorage.set(obj); setConfig(obj);
} }
add(presetPath) { add(presetPath) {

View file

@ -1,6 +1,4 @@
'use strict'; export default class PickedPreset
class PickedPreset
{ {
constructor(preset, presetCli) constructor(preset, presetCli)
{ {

View file

@ -1,6 +1,5 @@
'use strict';
class PresetParser { export default class PresetParser {
constructor(settings) { constructor(settings) {
this._settings = settings; this._settings = settings;
} }

View file

@ -1,6 +1,6 @@
'use strict'; import PresetsRepoIndexed from "./PresetsRepoIndexed";
class PresetsGithubRepo extends PresetsRepoIndexed { export default class PresetsGithubRepo extends PresetsRepoIndexed {
constructor(urlRepo, branch) { constructor(urlRepo, branch) {
let correctUrlRepo = urlRepo.trim(); let correctUrlRepo = urlRepo.trim();

View file

@ -1,6 +1,6 @@
'use strict'; import PresetParser from "./PresetParser";
class PresetsRepoIndexed { export default class PresetsRepoIndexed {
constructor(urlRaw, urlViewOnline) { constructor(urlRaw, urlViewOnline) {
this._urlRaw = urlRaw; this._urlRaw = urlRaw;
this._urlViewOnline = urlViewOnline; this._urlViewOnline = urlViewOnline;

View file

@ -1,6 +1,6 @@
'use strict'; import PresetsRepoIndexed from "./PresetsRepoIndexed";
class PresetsWebsiteRepo extends PresetsRepoIndexed { export default class PresetsWebsiteRepo extends PresetsRepoIndexed {
constructor(url) { constructor(url) {
let correctUrl = url.trim(); let correctUrl = url.trim();

View file

@ -1,6 +1,4 @@
'use strict'; export default class PresetSource {
class PresetSource {
constructor(name, url, gitHubBranch = "") { constructor(name, url, gitHubBranch = "") {
this.name = name; this.name = name;
this.url = url; this.url = url;

View file

@ -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) { constructor(parentDiv, presetSource) {
this._parentDiv = parentDiv; this._parentDiv = parentDiv;
this._presetSource = presetSource; this._presetSource = presetSource;
@ -130,7 +132,7 @@ class SourcePanel {
} }
_checkIfGithub() { _checkIfGithub() {
const isGithubUrl = PresetSource.isUrlGithubRepo(this._domEditUrl.val()); const isGithubUrl = PresetSource.isUrlGithubRepo(this._domEditUrl.val());
this._domDivGithubBranch.toggle(isGithubUrl); this._domDivGithubBranch.toggle(isGithubUrl);
} }
@ -197,4 +199,3 @@ class SourcePanel {
} }
SourcePanel.s_panelCounter = 0; SourcePanel.s_panelCounter = 0;

View file

@ -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) { constructor(domDialog) {
this._domDialog = domDialog; this._domDialog = domDialog;
this._sourceSelectedPromiseResolve = null; this._sourceSelectedPromiseResolve = null;
@ -47,7 +50,7 @@ class PresetsSourcesDialog {
const officialSource = this._createOfficialSource(); const officialSource = this._createOfficialSource();
const officialSourceSecondary = this._createSecondaryOfficialSource(); const officialSourceSecondary = this._createSecondaryOfficialSource();
const obj = ConfigStorage.get('PresetSources'); const obj = getConfig('PresetSources');
let sources = obj.PresetSources; let sources = obj.PresetSources;
if (sources && sources.length > 0) { if (sources && sources.length > 0) {
@ -64,7 +67,7 @@ class PresetsSourcesDialog {
} }
_readActiveSourceIndexFromStorage(sourcesCount) { _readActiveSourceIndexFromStorage(sourcesCount) {
const obj = ConfigStorage.get('PresetSourcesActiveIndex'); const obj = getConfig('PresetSourcesActiveIndex');
const index = Number(obj.PresetSourcesActiveIndex); const index = Number(obj.PresetSourcesActiveIndex);
let result = 0; let result = 0;
@ -147,8 +150,8 @@ class PresetsSourcesDialog {
} }
_saveSources() { _saveSources() {
ConfigStorage.set({'PresetSources': this._sources}); setConfig({'PresetSources': this._sources});
ConfigStorage.set({'PresetSourcesActiveIndex': this._activeSourceIndex}); setConfig({'PresetSourcesActiveIndex': this._activeSourceIndex});
} }
_updateSourcesFromPanels() { _updateSourcesFromPanels() {

View file

@ -1,6 +1,6 @@
'use strict'; import { i18n } from "../../../js/localization";
class PresetTitlePanel export default class PresetTitlePanel
{ {
constructor(parentDiv, preset, clickable, onLoadedCallback, favoritePresets) constructor(parentDiv, preset, clickable, onLoadedCallback, favoritePresets)
{ {

View file

@ -1,7 +1,16 @@
import GUI from '../../js/gui'; import GUI from '../../js/gui';
import { get as getConfig, set as setConfig } from '../../js/ConfigStorage'; import { get as getConfig, set as setConfig } from '../../js/ConfigStorage';
import { i18n } from '../../js/localization';
import { favoritePresets } from './FavoritePresets'; 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 = { const presets = {
presetsRepo: null, presetsRepo: null,