mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-15 12:25:15 +03:00
chore: remove custom string formatting
String template literals are in built way to handle these cases now
This commit is contained in:
parent
71586c914a
commit
2938c4338d
3 changed files with 36 additions and 37 deletions
|
@ -262,12 +262,7 @@ GuiControl.prototype.log = function (message) {
|
||||||
const seconds = (d.getSeconds() < 10) ? `0${d.getSeconds()}` : d.getSeconds();
|
const seconds = (d.getSeconds() < 10) ? `0${d.getSeconds()}` : d.getSeconds();
|
||||||
const time = `${hours}:${minutes}:${seconds}`;
|
const time = `${hours}:${minutes}:${seconds}`;
|
||||||
|
|
||||||
const formattedDate = "{0}-{1}-{2} {3}".format(
|
const formattedDate = `${year}-${month}-${date} @${time}`;
|
||||||
year,
|
|
||||||
month,
|
|
||||||
date,
|
|
||||||
`@ ${time}`
|
|
||||||
);
|
|
||||||
$('div.wrapper', commandLog).append(`<p>${formattedDate} -- ${message}</p>`);
|
$('div.wrapper', commandLog).append(`<p>${formattedDate} -- ${message}</p>`);
|
||||||
commandLog.scrollTop($('div.wrapper', commandLog).height());
|
commandLog.scrollTop($('div.wrapper', commandLog).height());
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,22 +2,6 @@ Number.prototype.clamp = function(min, max) {
|
||||||
return Math.min(Math.max(this, min), max);
|
return Math.min(Math.max(this, min), max);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* String formatting now supports currying (partial application).
|
|
||||||
* For a format string with N replacement indices, you can call .format
|
|
||||||
* with M <= N arguments. The result is going to be a format string
|
|
||||||
* with N-M replacement indices, properly counting from 0 .. N-M.
|
|
||||||
* The following Example should explain the usage of partial applied format:
|
|
||||||
* "{0}:{1}:{2}".format("a","b","c") === "{0}:{1}:{2}".format("a","b").format("c")
|
|
||||||
* "{0}:{1}:{2}".format("a").format("b").format("c") === "{0}:{1}:{2}".format("a").format("b", "c")
|
|
||||||
**/
|
|
||||||
String.prototype.format = function () {
|
|
||||||
var args = arguments;
|
|
||||||
return this.replace(/\{(\d+)\}/g, function (t, i) {
|
|
||||||
return args[i] !== void 0 ? args[i] : "{"+(i-args.length)+"}";
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Array.prototype.push8 = function(val) {
|
Array.prototype.push8 = function(val) {
|
||||||
this.push(0xFF & val);
|
this.push(0xFF & val);
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -150,10 +150,9 @@ TABS.firmware_flasher.initialize = function (callback) {
|
||||||
descriptors.forEach(function(descriptor){
|
descriptors.forEach(function(descriptor){
|
||||||
if($.inArray(target, selectTargets) == -1) {
|
if($.inArray(target, selectTargets) == -1) {
|
||||||
selectTargets.push(target);
|
selectTargets.push(target);
|
||||||
var select_e =
|
var select_e = $(
|
||||||
$("<option value='{0}'>{0}</option>".format(
|
`<option value='${descriptor.target}'>${descriptor.target}</option>`,
|
||||||
descriptor.target
|
);
|
||||||
));
|
|
||||||
boards_e.append(select_e);
|
boards_e.append(select_e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -352,8 +351,14 @@ TABS.firmware_flasher.initialize = function (callback) {
|
||||||
var buildType_e = $('select[name="build_type"]');
|
var buildType_e = $('select[name="build_type"]');
|
||||||
function buildBuildTypeOptionsList() {
|
function buildBuildTypeOptionsList() {
|
||||||
buildType_e.empty();
|
buildType_e.empty();
|
||||||
buildTypesToShow.forEach((build, index) => {
|
buildTypesToShow.forEach(({ tag, title }, index) => {
|
||||||
buildType_e.append($("<option value='{0}'>{1}</option>".format(index, build.tag ? i18n.getMessage(build.tag) : build.title)))
|
buildType_e.append(
|
||||||
|
$(
|
||||||
|
`<option value='${index}'>${
|
||||||
|
tag ? i18n.getMessage(tag) : title
|
||||||
|
}</option>`
|
||||||
|
)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
buildType_e.val($('select[name="build_type"] option:first').val());
|
buildType_e.val($('select[name="build_type"] option:first').val());
|
||||||
}
|
}
|
||||||
|
@ -455,7 +460,13 @@ TABS.firmware_flasher.initialize = function (callback) {
|
||||||
versions_element.empty();
|
versions_element.empty();
|
||||||
const targetVersions = Object.keys(builds);
|
const targetVersions = Object.keys(builds);
|
||||||
if (targetVersions.length > 0) {
|
if (targetVersions.length > 0) {
|
||||||
versions_element.append($("<option value='0'>{0} {1}</option>".format(i18n.getMessage('firmwareFlasherOptionLabelSelectFirmwareVersionFor'), target)));
|
versions_element.append(
|
||||||
|
$(
|
||||||
|
`<option value='0'>${i18n.getMessage(
|
||||||
|
"firmwareFlasherOptionLabelSelectFirmwareVersionFor"
|
||||||
|
)} ${target}</option>`
|
||||||
|
)
|
||||||
|
);
|
||||||
targetVersions
|
targetVersions
|
||||||
.sort(sortVersions)
|
.sort(sortVersions)
|
||||||
.forEach(function(versionName) {
|
.forEach(function(versionName) {
|
||||||
|
@ -478,12 +489,9 @@ TABS.firmware_flasher.initialize = function (callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var select_e =
|
var select_e = $(
|
||||||
$("<option value='{0}'>{2} - {1}</option>".format(
|
`<option value='${versionName}'>${version.descriptor.date} - ${versionLabel}</option>`
|
||||||
versionName,
|
);
|
||||||
version.descriptor.date,
|
|
||||||
versionLabel
|
|
||||||
));
|
|
||||||
if (FirmwareCache.has(version.descriptor)) {
|
if (FirmwareCache.has(version.descriptor)) {
|
||||||
select_e.addClass("cached");
|
select_e.addClass("cached");
|
||||||
}
|
}
|
||||||
|
@ -564,11 +572,23 @@ TABS.firmware_flasher.initialize = function (callback) {
|
||||||
clearBufferedFirmware();
|
clearBufferedFirmware();
|
||||||
|
|
||||||
versions_e.empty();
|
versions_e.empty();
|
||||||
versions_e.append($("<option value='0'>{0}</option>".format(i18n.getMessage('firmwareFlasherOptionLabelSelectFirmwareVersion'))));
|
versions_e.append(
|
||||||
|
$(
|
||||||
|
`<option value='0'>${i18n.getMessage(
|
||||||
|
"firmwareFlasherOptionLabelSelectFirmwareVersion"
|
||||||
|
)}</option>`
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// Show a loading message as there is a delay in loading a configuration
|
// Show a loading message as there is a delay in loading a configuration
|
||||||
versions_e.empty();
|
versions_e.empty();
|
||||||
versions_e.append($("<option value='0'>{0}</option>".format(i18n.getMessage('firmwareFlasherOptionLoading'))));
|
versions_e.append(
|
||||||
|
$(
|
||||||
|
`<option value='0'>${i18n.getMessage(
|
||||||
|
"firmwareFlasherOptionLoading"
|
||||||
|
)}</option>`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
let selecteBuild = buildTypesToShow[$('select[name="build_type"]').val()];
|
let selecteBuild = buildTypesToShow[$('select[name="build_type"]').val()];
|
||||||
const builds = [];
|
const builds = [];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue