diff options
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js')
10 files changed, 190 insertions, 73 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/base.js b/bitbake/lib/toaster/toastergui/static/js/base.js index 895e61b2a..ed22a4ebc 100644 --- a/bitbake/lib/toaster/toastergui/static/js/base.js +++ b/bitbake/lib/toaster/toastergui/static/js/base.js @@ -6,6 +6,7 @@ function basePageInit(ctx) { var newBuildTargetInput; var newBuildTargetBuildBtn; var projectNameForm = $("#project-name-change-form"); + var projectNameContainer = $("#project-name-container"); var projectName = $("#project-name"); var projectNameFormToggle = $("#project-change-form-toggle"); var projectNameChangeCancel = $("#project-name-change-cancel"); @@ -23,24 +24,21 @@ function basePageInit(ctx) { /* Project name change functionality */ projectNameFormToggle.click(function(e){ e.preventDefault(); - - $(this).add(projectName).hide(); + projectNameContainer.hide(); projectNameForm.fadeIn(); }); projectNameChangeCancel.click(function(e){ e.preventDefault(); - projectNameForm.hide(); - projectName.add(projectNameFormToggle).fadeIn(); + projectNameContainer.fadeIn(); }); $("#project-name-change-btn").click(function(e){ var newProjectName = $("#project-name-change-input").val(); - libtoaster.editCurrentProject({ projectName: newProjectName },function (){ - - projectName.text(newProjectName); + libtoaster.editCurrentProject({ projectName: newProjectName }, function (){ + projectName.html(newProjectName); libtoaster.ctx.projectName = newProjectName; projectNameChangeCancel.click(); }); @@ -123,14 +121,14 @@ function basePageInit(ctx) { }); function _checkProjectBuildable() { - if (selectedProject.projectId === undefined) { + if (selectedProject.projectId === undefined || selectedProject.projectIsDefault) { return; } libtoaster.getProjectInfo(selectedProject.projectPageUrl, function (data) { if (data.machine === null || data.machine.name === undefined || data.layers.length === 0) { - /* we can't build anything with out a machine and some layers */ + /* we can't build anything without a machine and some layers */ $("#new-build-button #targets-form").hide(); $("#new-build-button .alert").show(); } else { @@ -149,7 +147,7 @@ function basePageInit(ctx) { /* If we don't have a current project then present the set project * form. */ - if (selectedProject.projectId === undefined) { + if (selectedProject.projectId === undefined || selectedProject.projectIsDefault) { $('#change-project-form').show(); $('#project .icon-pencil').hide(); } diff --git a/bitbake/lib/toaster/toastergui/static/js/customrecipe.js b/bitbake/lib/toaster/toastergui/static/js/customrecipe.js new file mode 100644 index 000000000..4f6b304dd --- /dev/null +++ b/bitbake/lib/toaster/toastergui/static/js/customrecipe.js @@ -0,0 +1,50 @@ +"use strict"; + +function customRecipePageInit(ctx) { + + var urlParams = libtoaster.parseUrlParams(); + + (function notificationRequest(){ + if (urlParams.hasOwnProperty('notify') && urlParams.notify === 'new'){ + $("#image-created-notification").show(); + } + })(); + + $("#recipeselection").on('table-done', function(e, total, tableParams){ + /* Table is done so now setup the click handler for the package buttons */ + $(".add-rm-package-btn").click(function(e){ + e.preventDefault(); + addRemovePackage($(this), tableParams); + }); + }); + + function addRemovePackage(pkgBtn, tableParams){ + var pkgBtnData = pkgBtn.data(); + var method; + var buttonToShow; + + if (pkgBtnData.directive == 'add') { + method = 'PUT'; + buttonToShow = '#package-rm-btn-' + pkgBtnData.package; + } else if (pkgBtnData.directive == 'remove') { + method = 'DELETE'; + buttonToShow = '#package-add-btn-' + pkgBtnData.package; + } else { + throw("Unknown package directive: should be add or remove"); + } + + $.ajax({ + type: method, + url: pkgBtnData.packageUrl, + headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, + success: function(data){ + /* Invalidate the Add | Rm package table's current cache */ + tableParams.nocache = true; + $.get(ctx.tableApiUrl, tableParams); + /* Swap the buttons around */ + pkgBtn.hide(); + $(buttonToShow).show(); + } + }); + } +} diff --git a/bitbake/lib/toaster/toastergui/static/js/importlayer.js b/bitbake/lib/toaster/toastergui/static/js/importlayer.js index 2fadbc097..c68f3669f 100644 --- a/bitbake/lib/toaster/toastergui/static/js/importlayer.js +++ b/bitbake/lib/toaster/toastergui/static/js/importlayer.js @@ -195,8 +195,8 @@ function importLayerPageInit (ctx) { var dupLayerInfo = $("#duplicate-layer-info"); dupLayerInfo.find(".dup-layer-name").text(layer.name); dupLayerInfo.find(".dup-layer-link").attr("href", layer.layerdetailurl); - dupLayerInfo.find("#dup-layer-vcs-url").text(layer.layer__vcs_url); - dupLayerInfo.find("#dup-layer-revision").text(layer.revision.commit); + dupLayerInfo.find("#dup-layer-vcs-url").text(layer.vcs_url); + dupLayerInfo.find("#dup-layer-revision").text(layer.vcs_reference); $(".fields-apart-from-layer-name").fadeOut(function(){ @@ -214,11 +214,10 @@ function importLayerPageInit (ctx) { $.getJSON(libtoaster.ctx.layersTypeAheadUrl, { include_added: "true" , search: name, format: "json" }, function(layer) { - if (layer.rows.length > 0) { - for (var i in layer.rows){ - if (layer.rows[i].name == name) { - console.log(layer.rows[i]) - layerExistsError(layer.rows[i]); + if (layer.results.length > 0) { + for (var i in layer.results){ + if (layer.results[i].name == name) { + layerExistsError(layer.results[i]); } } } diff --git a/bitbake/lib/toaster/toastergui/static/js/jquery.treetable.js b/bitbake/lib/toaster/toastergui/static/js/jquery.treetable.js index 42e7427cc..794b902c5 100644 --- a/bitbake/lib/toaster/toastergui/static/js/jquery.treetable.js +++ b/bitbake/lib/toaster/toastergui/static/js/jquery.treetable.js @@ -421,7 +421,7 @@ columnElType: "td", // i.e. 'td', 'th' or 'td,th' expandable: false, expanderTemplate: "<a href='#'> </a>", - indent: 19, + indent: 10, indenterTemplate: "<span class='indenter'></span>", initialState: "collapsed", nodeIdAttr: "ttId", // maps to data-tt-id diff --git a/bitbake/lib/toaster/toastergui/static/js/layerBtn.js b/bitbake/lib/toaster/toastergui/static/js/layerBtn.js index a0509f9aa..7318b3f50 100644 --- a/bitbake/lib/toaster/toastergui/static/js/layerBtn.js +++ b/bitbake/lib/toaster/toastergui/static/js/layerBtn.js @@ -1,6 +1,6 @@ "use strict"; -function layerBtnsInit(ctx) { +function layerBtnsInit() { /* Remove any current bindings to avoid duplicated binds */ $(".layerbtn").unbind('click'); @@ -68,10 +68,16 @@ function layerBtnsInit(ctx) { }); }); - /* Setup the initial state of the buttons */ - for (var i in ctx.projectLayers){ - $(".layer-exists-" + ctx.projectLayers[i]).show(); - $(".layer-add-" + ctx.projectLayers[i]).hide(); - } + $(".customise-btn").unbind('click'); + $(".customise-btn").click(function(e){ + e.preventDefault(); + var imgCustomModal = $("#new-custom-image-modal"); + + if (imgCustomModal.length == 0) + throw("Modal new-custom-image not found"); + + imgCustomModal.data('recipe', $(this).data('recipe')); + imgCustomModal.modal('show'); + }); } diff --git a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js index 000e8038f..8c2ec4cdd 100644 --- a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js +++ b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js @@ -7,6 +7,9 @@ function layerDetailsPageInit (ctx) { var layerDepsList = $("#layer-deps-list"); var currentLayerDepSelection; var addRmLayerBtn = $("#add-remove-layer-btn"); + var targetTab = $("#targets-tab"); + var machineTab = $("#machines-tab"); + var detailsTab = $("#details-tab"); /* setup the dependencies typeahead */ libtoaster.makeTypeahead(layerDepInput, libtoaster.ctx.layersTypeAheadUrl, { include_added: "true" }, function(item){ @@ -15,6 +18,21 @@ function layerDetailsPageInit (ctx) { layerDepBtn.removeAttr("disabled"); }); + $(window).on('hashchange', function(e){ + switch(window.location.hash){ + case '#machines': + machineTab.tab('show'); + break; + case '#recipes': + targetTab.tab('show'); + break; + default: + detailsTab.tab('show'); + break; + } + }); + + $(".breadcrumb li:first a").click(function(e){ e.preventDefault(); /* By default this link goes to the project configuration page. However @@ -143,7 +161,7 @@ function layerDetailsPageInit (ctx) { addRmLayerBtn.removeClass("btn-danger"); } - $("#details-tab").on('show', function(){ + detailsTab.on('show', function(){ if (!ctx.layerVersion.inCurrentPrj) defaultAddBtnText(); @@ -174,7 +192,7 @@ function layerDetailsPageInit (ctx) { $("#no-recipes-yet").hide(); } - $("#targets-tab").removeClass("muted"); + targetTab.removeClass("muted"); if (window.location.hash === "#recipes"){ /* re run the machinesTabShow to update the text */ targetsTabShow(); @@ -189,7 +207,7 @@ function layerDetailsPageInit (ctx) { else $("#no-machines-yet").hide(); - $("#machines-tab").removeClass("muted"); + machineTab.removeClass("muted"); if (window.location.hash === "#machines"){ /* re run the machinesTabShow to update the text */ machinesTabShow(); @@ -202,7 +220,7 @@ function layerDetailsPageInit (ctx) { }); - $("#targets-tab").on('show', targetsTabShow); + targetTab.on('show', targetsTabShow); function machinesTabShow(){ if (!ctx.layerVersion.inCurrentPrj) { @@ -219,7 +237,7 @@ function layerDetailsPageInit (ctx) { window.location.hash = "machines"; } - $("#machines-tab").on('show', machinesTabShow); + machineTab.on('show', machinesTabShow); $(".pagesize").change(function(){ var search = libtoaster.parseUrlParams(); @@ -236,7 +254,7 @@ function layerDetailsPageInit (ctx) { if (added){ /* enable and switch all the button states */ - $(".build-target-btn").removeAttr("disabled"); + $(".build-recipe-btn").removeAttr("disabled"); $(".select-machine-btn").removeAttr("disabled"); addRmLayerBtn.addClass("btn-danger"); addRmLayerBtn.data('directive', "remove"); @@ -245,7 +263,7 @@ function layerDetailsPageInit (ctx) { } else { /* disable and switch all the button states */ - $(".build-target-btn").attr("disabled","disabled"); + $(".build-recipe-btn").attr("disabled","disabled"); $(".select-machine-btn").attr("disabled", "disabled"); addRmLayerBtn.removeClass("btn-danger"); addRmLayerBtn.data('directive', "add"); diff --git a/bitbake/lib/toaster/toastergui/static/js/newcustomimage.js b/bitbake/lib/toaster/toastergui/static/js/newcustomimage.js new file mode 100644 index 000000000..935b21ede --- /dev/null +++ b/bitbake/lib/toaster/toastergui/static/js/newcustomimage.js @@ -0,0 +1,49 @@ +"use strict"; + +function newCustomImagePageInit(ctx){ + + var newCustomImgBtn = $("#create-new-custom-image-btn"); + var imgCustomModal = $("#new-custom-image-modal"); + + newCustomImgBtn.click(function(e){ + e.preventDefault(); + + var name = imgCustomModal.find('input').val(); + var baseRecipeId = imgCustomModal.data('recipe'); + + if (name.length > 0) { + createCustomRecipe(name, baseRecipeId); + imgCustomModal.modal('hide'); + } else { + console.warn("TODO No name supplied"); + } + }); + + function createCustomRecipe(name, baseRecipeId){ + var data = { + 'name' : name, + 'project' : libtoaster.ctx.projectId, + 'base' : baseRecipeId, + }; + + $.ajax({ + type: "POST", + url: ctx.xhrCustomRecipeUrl, + data: data, + headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, + success: function (ret) { + if (ret.error !== "ok") { + console.warn(ret.error); + } else { + window.location.replace(ret.url + '?notify=new'); + } + }, + error: function (ret) { + console.warn("Call failed"); + console.warn(ret); + } + }); + } + + +} diff --git a/bitbake/lib/toaster/toastergui/static/js/projectpage.js b/bitbake/lib/toaster/toastergui/static/js/projectpage.js index d36704751..e742ef291 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projectpage.js +++ b/bitbake/lib/toaster/toastergui/static/js/projectpage.js @@ -23,7 +23,7 @@ function projectPageInit(ctx) { var cancelReleaseChange = $("#cancel-release-change"); var currentLayerAddSelection; - var currentMachineAddSelection = {}; + var currentMachineAddSelection = ""; var urlParams = libtoaster.parseUrlParams(); @@ -38,7 +38,7 @@ function projectPageInit(ctx) { */ if (urlParams.hasOwnProperty('setMachine') && urlParams.setMachine !== prjInfo.machine.name){ - currentMachineAddSelection.name = urlParams.setMachine; + machineChangeInput.val(urlParams.setMachine); machineChangeBtn.click(); } else { updateMachineName(prjInfo.machine.name); @@ -103,6 +103,12 @@ function projectPageInit(ctx) { layerAddBtn.removeAttr("disabled"); }); + layerAddInput.keyup(function() { + if ($(this).val().length == 0) { + layerAddBtn.attr("disabled", "disabled") + } + }); + layerAddBtn.click(function(e){ e.preventDefault(); var layerObj = currentLayerAddSelection; @@ -146,10 +152,7 @@ function projectPageInit(ctx) { link.attr("href", layerObj.layerdetailurl); link.text(layerObj.name); - /* YOCTO #8024 - link.tooltip({title: layerObj.giturl + " | "+ layerObj.branch.name, placement: "right"}); - branch name not accessible sometimes it is revision instead - */ + link.tooltip({title: layerObj.vcs_url + " | "+ layerObj.vcs_reference, placement: "right"}); var trashItem = projectLayer.children("span"); trashItem.click(function (e) { @@ -251,29 +254,33 @@ function projectPageInit(ctx) { } libtoaster.makeTypeahead(machineChangeInput, libtoaster.ctx.machinesTypeAheadUrl, { }, function(item){ - currentMachineAddSelection = item; + currentMachineAddSelection = item.name; machineChangeBtn.removeAttr("disabled"); }); machineChangeBtn.click(function(e){ e.preventDefault(); - if (currentMachineAddSelection.name === undefined) + /* We accept any value regardless of typeahead selection or not */ + if (machineChangeInput.val().length === 0) return; - libtoaster.editCurrentProject({ machineName : currentMachineAddSelection.name }, + currentMachineAddSelection = machineChangeInput.val(); + + libtoaster.editCurrentProject( + { machineName : currentMachineAddSelection }, function(){ /* Success machine changed */ - updateMachineName(currentMachineAddSelection.name); + updateMachineName(currentMachineAddSelection); machineChangeCancel.click(); /* Show the alert message */ var message = $('<span class="lead">You have changed the machine to: <strong><span id="notify-machine-name"></span></strong></span>'); - message.find("#notify-machine-name").text(currentMachineAddSelection.name); + message.find("#notify-machine-name").text(currentMachineAddSelection); libtoaster.showChangeNotification(message); }, function(){ /* Failed machine changed */ - console.log("failed to change machine"); + console.warn("Failed to change machine"); }); }); diff --git a/bitbake/lib/toaster/toastergui/static/js/table.js b/bitbake/lib/toaster/toastergui/static/js/table.js index f18034df5..40b5022de 100644 --- a/bitbake/lib/toaster/toastergui/static/js/table.js +++ b/bitbake/lib/toaster/toastergui/static/js/table.js @@ -33,14 +33,6 @@ function tableInit(ctx){ loadData(tableParams); - window.onpopstate = function(event){ - if (event.state){ - tableParams = event.state.tableParams; - /* We skip loadData and just update the table */ - updateTable(event.state.tableData); - } - }; - function loadData(tableParams){ $.ajax({ type: "GET", @@ -49,10 +41,8 @@ function tableInit(ctx){ headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, success: function(tableData) { updateTable(tableData); - window.history.pushState({ - tableData: tableData, - tableParams: tableParams - }, null, libtoaster.dumpsUrlParams(tableParams)); + window.history.replaceState(null, null, + libtoaster.dumpsUrlParams(tableParams)); } }); } @@ -140,7 +130,7 @@ function tableInit(ctx){ tableBody.append(row); /* If we have layerbtns then initialise them */ - layerBtnsInit(ctx); + layerBtnsInit(); /* If we have popovers initialise them now */ $('td > a.btn').popover({ diff --git a/bitbake/lib/toaster/toastergui/static/js/tests/test.js b/bitbake/lib/toaster/toastergui/static/js/tests/test.js index d61011302..aac0ba60a 100644 --- a/bitbake/lib/toaster/toastergui/static/js/tests/test.js +++ b/bitbake/lib/toaster/toastergui/static/js/tests/test.js @@ -13,8 +13,6 @@ QUnit.test("Layer alert notification", function(assert) { "name":"meta-example" }; - var correctResponse = "You have added <strong>3</strong> layers to your project: <a id=\"layer-affected-name\" href=\"/toastergui/project/1/layer/22\">meta-example</a> and its dependencies <a href=\"/toastergui/project/1/layer/9\" data-original-title=\"\" title=\"\">meta-example-two</a>, <a href=\"/toastergui/project/1/layer/9\" data-original-title=\"\" title=\"\">meta-example-three</a>"; - var layerDepsList = [ { "layerdetailurl":"/toastergui/project/1/layer/9", @@ -68,9 +66,9 @@ QUnit.test("Show notification", function(assert){ }); var layer = { - "id": 91, - "name": "meta-crystalforest", - "layerdetailurl": "/toastergui/project/4/layer/91" + "id": 1, + "name": "meta-testing", + "layerdetailurl": "/toastergui/project/1/layer/1" }; QUnit.test("Add layer", function(assert){ @@ -84,11 +82,19 @@ QUnit.test("Add layer", function(assert){ } }, 200); - libtoaster.addRmLayer(layer, true, function(deps){ - assert.equal(deps.length, 1); - done(); + /* Compare the number of layers before and after the add in the project */ + libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, function(prjInfo){ + var origNumLayers = prjInfo.layers.length; + + libtoaster.addRmLayer(layer, true, function(deps){ + libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, + function(prjInfo){ + assert.ok(prjInfo.layers.length > origNumLayers, + "Layer not added to project"); + done(); + }); + }); }); - }); QUnit.test("Rm layer", function(assert){ @@ -152,11 +158,11 @@ QUnit.test("Layer details page init", function(assert){ }); QUnit.test("Layer btns init", function(assert){ - assert.throws(layerBtnsInit({ projectLayers : [] })); + assert.throws(layerBtnsInit()); }); QUnit.test("Table init", function(assert){ - assert.throws(tableInit({ url : tableUrl })); + assert.throws(tableInit({ url : ctx.tableUrl })); }); $(document).ajaxError(function(event, jqxhr, settings, errMsg){ @@ -167,9 +173,3 @@ $(document).ajaxError(function(event, jqxhr, settings, errMsg){ assert.notOk(jqxhr.responseText); }); }); - - - - - - |