Skip to content

Commit

Permalink
Merge pull request #23 from raul-ortega/nexgen
Browse files Browse the repository at this point in the history
Nexgen
  • Loading branch information
raul-ortega authored Apr 30, 2021
2 parents 5720a97 + f19b452 commit ad46673
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 135 deletions.
280 changes: 156 additions & 124 deletions js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,102 +130,23 @@ TABS.firmware_flasher.initialize = function (callback) {
}
});
}

function buildBoardOptions(releaseData, showDevReleases) {
if (!releaseData) {
$('select[name="board"]').empty().append('<option value="0">Offline</option>');
$('select[name="firmware_version"]').empty().append('<option value="0">Offline</option>');
} else {
var boards_e = $('select[name="board"]');
var versions_e = $('select[name="firmware_version"]');

var releases = {};
var sortedTargets = [];
var unsortedTargets = [];
releaseData.forEach(function(release){
release.assets.forEach(function(asset){
var targetFromFilenameExpression = /amv-open360tracker_([\d.]+(?:-rc\d+)?)?_?([^.]+)\.(.*)/;
var match = targetFromFilenameExpression.exec(asset.name);

if ((!showDevReleases && release.prerelease) || !match) {
return;
}
var target = match[2];
if($.inArray(target, unsortedTargets) == -1) {
unsortedTargets.push(target);
}
});
sortedTargets = unsortedTargets.sort();
});
sortedTargets.forEach(function(release) {
releases[release] = [];
});

releaseData.forEach(function(release){
var versionFromTagExpression = /v?(.*)/;
var matchVersionFromTag = versionFromTagExpression.exec(release.tag_name);
var version = matchVersionFromTag[1];

release.assets.forEach(function(asset){
var targetFromFilenameExpression = /amv-open360tracker_([\d.]+(?:-rc\d+)?)?_?([^.]+)\.(.*)/;
var match = targetFromFilenameExpression.exec(asset.name);

if ((!showDevReleases && release.prerelease) || !match) {
return;
}

var target = match[2];
var format = match[3];

if (format != 'hex') {
return;
}

var date = new Date(release.published_at);
var formattedDate = ("0" + date.getDate()).slice(-2) + "-" + ("0"+(date.getMonth()+1)).slice(-2) + "-" + date.getFullYear() + " " + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2);

var descriptor = {
"releaseUrl": release.html_url,
"name" : version,
"version" : version,
"url" : asset.browser_download_url,
"file" : asset.name,
"target" : target,
"date" : formattedDate,
"notes" : release.body,
"status" : release.prerelease ? "release-candidate" : "stable"
};
releases[target].push(descriptor);
});
});
var selectTargets = [];
Object.keys(releases)
.sort()
.forEach(function(target, i) {
var descriptors = releases[target];
descriptors.forEach(function(descriptor){
if($.inArray(target, selectTargets) == -1) {
selectTargets.push(target);
var select_e =
$("<option value='{0}'>{0}</option>".format(
descriptor.target
)).data('summary', descriptor);
boards_e.append(select_e);
}
});
});
TABS.firmware_flasher.releases = releases;

chrome.storage.local.get('selected_board', function (result) {
if (result.selected_board) {
var boardReleases = releases[result.selected_board]
$('select[name="board"]').val(boardReleases ? result.selected_board : 0).trigger('change');
}
});

function parseFilename(filename) {
var targetFromFilenameExpression = /amv-open360tracker_([\d.]+)?_?([^.]+)\.(.*)/;
//var targetFromFilenameExpression = /amv-open360tracker_([\d.]+(?:-rc\d+)?)?_?([^.]+)\.(.*)/;
var match = targetFromFilenameExpression.exec(filename);

if (!match) {
return null;
}
};

function showOrHideBuildTypeSelect() {
return {
target: match[2].replace("_", " "),
format: match[3],
};
}

/*function showOrHideBuildTypeSelect() {
var showDevReleases = $(this).is(':checked');
if (showDevReleases) {
Expand All @@ -234,45 +155,65 @@ TABS.firmware_flasher.initialize = function (callback) {
$('tr.build_type').hide();
buildType_e.val(0).trigger('change');
}
}
}*/

$.get('https://api.github.com/repos/raul-ortega/u360gts/releases', function (releasesData){
TABS.firmware_flasher.releasesData = releasesData;
buildBoardOptions();

var buildTypes = [
{
tag: 'firmwareFlasherOptionLabelBuildTypeRelease',
loader: () => self.releaseChecker.loadReleaseData(releaseData => buildBoardOptions(releaseData, false))
},
{
tag: 'firmwareFlasherOptionLabelBuildTypeReleaseCandidate',
loader: () => self.releaseChecker.loadReleaseData(releaseData => buildBoardOptions(releaseData, true))
},
/*
{
tag: 'firmwareFlasherOptionLabelBuildTypeDevelopment',
loader: () => new JenkinsLoader('https://ci.betaflight.tech', 'Betaflight').loadBuilds(buildJenkinsBoardOptions)
},
{
tag: 'firmwareFlasherOptionLabelBuildTypeAKK3_3',
loader: () => new JenkinsLoader('https://ci.betaflight.tech', 'Betaflight Maintenance 3.3 (AKK - RDQ VTX Patch)').loadBuilds(buildJenkinsBoardOptions)
},
{
tag: 'firmwareFlasherOptionLabelBuildTypeAKK3_4',
loader: () => new JenkinsLoader('https://ci.betaflight.tech', 'Betaflight Maintenance 3.4 (AKK - RDQ VTX Patch)').loadBuilds(buildJenkinsBoardOptions)
// bind events
$('select[name="board"]').change(function() {

$("a.load_remote_file").addClass('disabled');
var target = $(this).val();

if (!GUI.connect_lock) {
$('.progress').val(0).removeClass('valid invalid');
$('span.progressLabel').text(chrome.i18n.getMessage('firmwareFlasherLoadFirmwareFile'));
$('div.git_info').slideUp();
$('div.release_info').slideUp();
$('a.flash_firmware').addClass('disabled');

var versions_e = $('select[name="firmware_version"]').empty();
if(target == 0) {
versions_e.append($("<option value='0'>{0}</option>".format(chrome.i18n.getMessage('firmwareFlasherOptionLabelSelectFirmwareVersion'))));
} else {
versions_e.append($("<option value='0'>{0} {1}</option>".format(chrome.i18n.getMessage('firmwareFlasherOptionLabelSelectFirmwareVersionFor'), target)));
}

TABS.firmware_flasher.releases[target].forEach(function(descriptor) {
var select_e =
$("<option value='{0}'>{0} - {1} - {2} ({3})</option>".format(
descriptor.version,
descriptor.target,
descriptor.date,
descriptor.status
)).data('summary', descriptor);

versions_e.append(select_e);
});
}
});

}).fail(function (data){
if (data["responseJSON"]){
GUI.log("<b>GITHUB Query Failed: <code>{0}</code></b>".format(data["responseJSON"].message));
}
*/
];
$('select[name="release"]').empty().append('<option value="0">Offline</option>');
});

var buildType_e = $('select[name="build_type"]');
/*var buildType_e = $('select[name="build_type"]');
buildTypes.forEach((build, index) => {
buildType_e.append($("<option value='{0}' selected>{1}</option>".format(index, i18n.getMessage(build.tag))))
});
});*/

showOrHideBuildTypeSelect();
/*showOrHideBuildTypeSelect();*/
//$('input.show_development_releases').change(showOrHideBuildTypeSelect);

// translate to user-selected language
i18n.localizePage();

buildType_e.change(function() {
/*buildType_e.change(function() {
$("a.load_remote_file").addClass('disabled');
var build_type = $(this).val();
Expand All @@ -287,8 +228,99 @@ TABS.firmware_flasher.initialize = function (callback) {
}
chrome.storage.local.set({'selected_build_type': build_type});
});*/

$('input.show_development_releases').click(function(){
buildBoardOptions();
});

var buildBoardOptions = function(){

var boards_e = $('select[name="board"]').empty();
var showDevReleases = ($('input.show_development_releases').is(':checked'));
boards_e.append($("<option value='0'>{0}</option>".format(i18n.getMessage('firmwareFlasherOptionLabelSelectBoard'))));

var versions_e = $('select[name="firmware_version"]').empty();
versions_e.append($("<option value='0'>{0}</option>".format(i18n.getMessage('firmwareFlasherOptionLabelSelectFirmwareVersion'))));

var releases = {};
var sortedTargets = [];
var unsortedTargets = [];
TABS.firmware_flasher.releasesData.forEach(function(release){
release.assets.forEach(function(asset){
var result = parseFilename(asset.name);

if ((!showDevReleases && release.prerelease) || !result) {
return;
}
if($.inArray(result.target, unsortedTargets) == -1) {
unsortedTargets.push(result.target);
}
});
sortedTargets = unsortedTargets.sort();
});
sortedTargets.forEach(function(release) {
releases[release] = [];
});

TABS.firmware_flasher.releasesData.forEach(function(release){

var versionFromTagExpression = /v?(.*)/;
var matchVersionFromTag = versionFromTagExpression.exec(release.tag_name);
var version = matchVersionFromTag[1];

release.assets.forEach(function(asset){
var result = parseFilename(asset.name);
if ((!showDevReleases && release.prerelease) || !result) {
return;
}

if (result.format != 'hex') {
return;
}

var date = new Date(release.published_at);
var formattedDate = "{0}-{1}-{2} {3}:{4}".format(
date.getFullYear(),
date.getMonth() + 1,
date.getDate(),
date.getUTCHours(),
date.getMinutes()
);

var descriptor = {
"releaseUrl": release.html_url,
"name" : semver.clean(release.name),
"version" : release.tag_name,
"url" : asset.browser_download_url,
"file" : asset.name,
"target" : result.target,
"date" : formattedDate,
"notes" : release.body,
"status" : release.prerelease ? "release-candidate" : "stable"
};
releases[result.target].push(descriptor);
});
});
var selectTargets = [];
Object.keys(releases)
.sort()
.forEach(function(target, i) {
var descriptors = releases[target];
descriptors.forEach(function(descriptor){
if($.inArray(target, selectTargets) == -1) {
selectTargets.push(target);
var select_e =
$("<option value='{0}'>{0}</option>".format(
descriptor.target
)).data('summary', descriptor);
boards_e.append(select_e);
}
});
});
TABS.firmware_flasher.releases = releases;
};

$('select[name="board"]').change(function() {
$("a.load_remote_file").addClass('disabled');
var target = $(this).val();
Expand Down Expand Up @@ -513,10 +545,10 @@ TABS.firmware_flasher.initialize = function (callback) {
});
});

chrome.storage.local.get('selected_build_type', function (result) {
/*chrome.storage.local.get('selected_build_type', function (result) {
// ensure default build type is selected
buildType_e.val(result.selected_build_type || 0).trigger('change');
});
});*/

chrome.storage.local.get('no_reboot_sequence', function (result) {
if (result.no_reboot_sequence) {
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
"vendorId": 1155
} ]
}, "webview", "unlimitedStorage" ],
"short_name": "u360gts configurator v4.2.0",
"short_name": "u360gts configurator v4.2.1",
"sockets": {
"tcp": {
"connect": "*:*"
}
},
"update_url": "https://clients2.google.com/service/update2/crx",
"version": "4.2.0",
"version": "4.2.1",
"webview": {
"partitions": [ {
"accessible_resources": [ "tabs/map.html", "/js/tabs/map.js", "/images/icons/tracker-map-icon.png", "/js/libraries/openlayer/css/ol.css", "/js/libraries/openlayer/build/ol.js", "/js/libraries/openlayer/build/ol.js.map" ],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "u360gts-configurator",
"description": "Crossplatform configuration tool for u360gts flight control system.",
"version": "4.2.0",
"version": "4.2.1",
"bg-script": "js/eventPage.js",
"default_locale": "en",
"main": "main_nwjs.html",
Expand Down
8 changes: 0 additions & 8 deletions tabs/firmware_flasher.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
</label></td>
<td><span class="description" i18n="firmwareFlasherShowDevelopmentReleasesDescription"></span></td>
</tr>
<tr class="build_type">
<td>
<select name="build_type">
<!-- options generated at runtime -->
</select>
</td>
<td><span class="description" i18n="firmwareFlasherOnlineSelectBuildType"></span></td>
</tr>
<tr>
<td><select name="board">
<option value="0" i18n="firmwareFlasherOptionLoading">Loading ...</option>
Expand Down

0 comments on commit ad46673

Please sign in to comment.