diff --git a/bitbake/lib/toaster/toastergui/static/js/base.js b/bitbake/lib/toaster/toastergui/static/js/base.js index 6fd77ea457..0fb1f8b6bf 100644 --- a/bitbake/lib/toaster/toastergui/static/js/base.js +++ b/bitbake/lib/toaster/toastergui/static/js/base.js @@ -6,13 +6,20 @@ function basePageInit(ctx) { var newBuildTargetInput; var newBuildTargetBuildBtn; + /* initially the current project is used unless overridden by the new build + * button in top right nav + */ var selectedProject = libtoaster.ctx; + var selectedTarget; var newBuildProjectInput = $("#new-build-button #project-name-input"); var newBuildProjectSaveBtn = $("#new-build-button #save-project-button"); - $("#config-nav .nav li a").each(function(){ + + _checkProjectBuildable(); + + $("#project-topbar .nav li a").each(function(){ if (window.location.pathname === $(this).attr('href')) $(this).parent().addClass('active'); else @@ -26,7 +33,7 @@ function basePageInit(ctx) { }); } - /* Hide the button if we're on the project,newproject or importlyaer page + /* Hide the button if we're on the project,newproject or importlyaer page * or if there are no projects yet defined * only show if there isn't already a build-target-input already */ @@ -37,8 +44,8 @@ function basePageInit(ctx) { newBuildTargetInput = $("#new-build-button .build-target-input"); newBuildTargetBuildBtn = $("#new-build-button .build-button"); - newBuildButton.show(); _setupNewBuildButton(); + newBuildButton.show(); } else if ($(".build-target-input").length > 0) { newBuildTargetInput = $("#project-topbar .build-target-input"); newBuildTargetBuildBtn = $("#project-topbar .build-button"); @@ -52,9 +59,35 @@ function basePageInit(ctx) { $('#project .icon-pencil').hide(); } + libtoaster.makeTypeahead(newBuildTargetInput, selectedProject.projectTargetsUrl, { format: "json" }, function (item) { + /* successfully selected a target */ + selectedTarget = item; + }); - _checkProjectBuildable(); + newBuildTargetInput.on('input', function () { + if ($(this).val().length === 0) { + newBuildTargetBuildBtn.attr("disabled", "disabled"); + } else { + newBuildTargetBuildBtn.removeAttr("disabled"); + } + }); + newBuildTargetBuildBtn.click(function (e) { + e.preventDefault(); + + if (!newBuildTargetInput.val()) { + return; + } + + if (!selectedTarget) { + selectedTarget = { name: newBuildTargetInput.val() }; + } + /* Fire off the build */ + libtoaster.startABuild(selectedProject.projectBuildsUrl, + selectedProject.projectId, selectedTarget.name, function(){ + window.location.replace(selectedProject.projectBuildsUrl); + }, null); + }); function _checkProjectBuildable() { if (selectedProject.projectId === undefined) { @@ -74,21 +107,12 @@ function basePageInit(ctx) { /* we can build this project; enable input fields */ newBuildTargetInput.prop("disabled", false); newBuildTargetBuildBtn.prop("disabled", false); - - libtoaster.makeTypeahead(newBuildTargetInput, selectedProject.projectTargetsUrl, { format: "json" }, function (item) { - /* successfully selected a target */ - selectedProject.projectPageUrl = item.projectPageUrl; - selectedProject.projectName = item.name; - selectedProject.projectId = item.id; - selectedProject.projectBuildsUrl = item.projectBuildsUrl; - }); - - } + } }, null); } + /* Setup New build button in the top nav bar */ function _setupNewBuildButton() { - /* Setup New build button */ /* If we don't have a current project then present the set project * form. @@ -98,7 +122,6 @@ function basePageInit(ctx) { $('#project .icon-pencil').hide(); } - libtoaster.makeTypeahead(newBuildProjectInput, selectedProject.projectsUrl, { format : "json" }, function (item) { /* successfully selected a project */ newBuildProjectSaveBtn.removeAttr("disabled"); @@ -115,40 +138,16 @@ function basePageInit(ctx) { newBuildProjectSaveBtn.attr("disabled", "disabled"); }); - newBuildTargetInput.on('input', function () { - if ($(this).val().length === 0) { - newBuildTargetBuildBtn.attr("disabled", "disabled"); - } else { - newBuildTargetBuildBtn.removeAttr("disabled"); - } - }); - - newBuildTargetBuildBtn.click(function () { - if (!newBuildTargetInput.val()) { - return; - } - - if (!selectedTarget) { - selectedTarget = { name: newBuildTargetInput.val() }; - } - /* fire and forget */ - libtoaster.startABuild(selectedProject.projectBuildsUrl, selectedProject.projectId, selectedTarget.name, null, null); - window.location.replace(selectedProject.projectPageUrl); - }); newBuildProjectSaveBtn.click(function () { selectedProject.projectId = selectedProject.pk; /* Update the typeahead project_id paramater */ _checkProjectBuildable(); - /* we set the effective context of the page to the currently selected project */ - /* TBD: do we override even if we already have a context project ?? */ - /* TODO: replace global library context with references to the "selected" project */ - - /* we can create a target typeahead only after we have a project selected */ newBuildTargetInput.prop("disabled", false); newBuildTargetBuildBtn.prop("disabled", false); + /* Update the typeahead to use the new selectedProject */ libtoaster.makeTypeahead(newBuildTargetInput, selectedProject.projectTargetsUrl, { format: "json" }, function (item) { /* successfully selected a target */ selectedTarget = item; diff --git a/bitbake/lib/toaster/toastergui/static/js/importlayer.js b/bitbake/lib/toaster/toastergui/static/js/importlayer.js index 560e25a01c..03274c00f3 100644 --- a/bitbake/lib/toaster/toastergui/static/js/importlayer.js +++ b/bitbake/lib/toaster/toastergui/static/js/importlayer.js @@ -16,8 +16,6 @@ function importLayerPageInit (ctx) { var currentLayerDepSelection; var validLayerName = /^(\w|-)+$/; - $("#new-project-button").hide(); - libtoaster.makeTypeahead(layerDepInput, libtoaster.ctx.projectLayersUrl, { include_added: "true" }, function(item){ currentLayerDepSelection = item; @@ -154,7 +152,7 @@ function importLayerPageInit (ctx) { } else { /* Success layer import now go to the project page */ $.cookie('layer-imported-alert', JSON.stringify(data), { path: '/'}); - window.location.replace(libtoaster.ctx.projectPageUrl+'#/layerimported'); + window.location.replace(libtoaster.ctx.projectPageUrl+'?notify=layer-imported'); } }, error: function (data) { diff --git a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js index 291ed98c34..be6bbcd20f 100644 --- a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js +++ b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js @@ -16,14 +16,15 @@ function layerDetailsPageInit (ctx) { }); $(".breadcrumb li:first a").click(function(e){ + e.preventDefault(); /* By default this link goes to the project configuration page. However * if we have some builds we go there instead of the default href */ libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, function(prjInfo){ if (prjInfo.builds && prjInfo.builds.length > 0) { window.location.replace(libtoaster.ctx.projectBuildsUrl); - e.preventDefault(); - return; + } else { + window.location.replace(libtoaster.ctx.projectPageUrl); } }); }); diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index afd665ca99..079bbcb0b8 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js @@ -79,11 +79,12 @@ var libtoaster = (function (){ data: data, headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, success: function (_data) { + /* No proper reponse YOCTO #7995 if (_data.error !== "ok") { console.warn(_data.error); - } else { + } else { */ if (onsuccess !== undefined) onsuccess(_data); - } + // } }, error: function (_data) { console.warn("Call failed"); @@ -180,7 +181,15 @@ var libtoaster = (function (){ if (onFail !== undefined) onFail(data); } else { - onSuccess(data.layerdeps); + var deps = {}; + /* Filter out layer dep ids which are in the + * project already. + */ + deps.list = data.layerdeps.list.filter(function(layerObj){ + return (data.projectlayers.lastIndexOf(layerObj.id) < 0); + }); + + onSuccess(deps); } }, function() { console.log("E: Failed to make request"); diff --git a/bitbake/lib/toaster/toastergui/static/js/projectpage.js b/bitbake/lib/toaster/toastergui/static/js/projectpage.js new file mode 100644 index 0000000000..b7cb074f11 --- /dev/null +++ b/bitbake/lib/toaster/toastergui/static/js/projectpage.js @@ -0,0 +1,429 @@ +"use strict"; + +function projectPageInit(ctx) { + + var layerAddInput = $("#layer-add-input"); + var layersInPrjList = $("#layers-in-project-list"); + var layerAddBtn = $("#add-layer-btn"); + + var machineChangeInput = $("#machine-change-input"); + var machineChangeBtn = $("#machine-change-btn"); + var machineForm = $("#select-machine-form"); + var machineChangeFormToggle = $("#change-machine-toggle"); + var machineNameTitle = $("#project-machine-name"); + var machineChangeCancel = $("#cancel-machine-change"); + + var freqBuildBtn = $("#freq-build-btn"); + var freqBuildList = $("#freq-build-list"); + + var releaseChangeFormToggle = $("#release-change-toggle"); + var releaseTitle = $("#project-release-title"); + var releaseForm = $("#change-release-form"); + var releaseModal = $("#change-release-modal"); + var cancelReleaseChange = $("#cancel-release-change"); + + var currentLayerAddSelection; + var currentMachineAddSelection = {}; + + var urlParams = libtoaster.parseUrlParams(); + + libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, function(prjInfo){ + updateProjectLayers(prjInfo.layers); + updateFreqBuildRecipes(prjInfo.freqtargets); + updateProjectRelease(prjInfo.release); + updateProjectReleases(prjInfo.releases, prjInfo.release); + + /* If we're receiving a machine set from the url and it's different from + * our current machine then activate set machine sequence. + */ + if (urlParams.hasOwnProperty('setMachine') && + urlParams.setMachine !== prjInfo.machine.name){ + currentMachineAddSelection.name = urlParams.setMachine; + machineChangeBtn.click(); + } else { + updateMachineName(prjInfo.machine.name); + } + + /* Now we're really ready show the page */ + $("#project-page").show(); + }); + + (function notificationRequest(){ + + if (urlParams.hasOwnProperty('notify')){ + switch (urlParams.notify){ + case 'new-project': + $("#project-created-notification").show(); + break; + case 'layer-imported': + layerImportedNotification(); + break; + default: + break; + } + } + })(); + + /* Layer imported notification */ + function layerImportedNotification(){ + var imported = $.cookie("layer-imported-alert"); + var message = "Layer imported"; + + if (!imported) + return; + else + imported = JSON.parse(imported); + + if (imported.deps_added.length === 0) { + message = "You have imported "+imported.imported_layer.name+" and added it to your project."; + } else { + + var links = ""+imported.imported_layer.name+", "; + + imported.deps_added.map (function(item, index){ + links +=''+item.name+''; + /*If we're at the last element we don't want the trailing comma */ + if (imported.deps_added[index+1] !== undefined) + links += ', '; + }); + + /* Length + 1 here to do deps + the imported layer */ + message = 'You have imported '+imported.imported_layer.name+' and added '+(imported.deps_added.length+1)+' layers to your project: '+links+''; + } + + libtoaster.showChangeNotification(message); + + $.removeCookie("layer-imported-alert", { path: "/"}); + } + + /* Add/Rm layer functionality */ + + libtoaster.makeTypeahead(layerAddInput, libtoaster.ctx.projectLayersUrl, { include_added: "false" }, function(item){ + currentLayerAddSelection = item; + layerAddBtn.removeAttr("disabled"); + }); + + layerAddBtn.click(function(e){ + e.preventDefault(); + var layerObj = currentLayerAddSelection; + + addRmLayer(layerObj, true); + /* Reset the text input */ + layerAddInput.val(""); + }); + + function addRmLayer(layerObj, add){ + + libtoaster.addRmLayer(layerObj, add, function(layerDepsList){ + if (add){ + updateProjectLayers([layerObj]); + updateProjectLayers(layerDepsList); + } + + /* Show the alert message */ + var message = libtoaster.makeLayerAddRmAlertMsg(layerObj, layerDepsList, add); + libtoaster.showChangeNotification(message); + }); + } + + function updateProjectLayers(layers){ + + /* No layers to add */ + if (layers.length === 0){ + updateLayersCount(); + return; + } + + for (var i in layers){ + var layerObj = layers[i]; + + var projectLayer = $("