From 58cd4a14ea81b72dcd9679608e5e2231ec3d3631 Mon Sep 17 00:00:00 2001 From: Alexandru DAMIAN Date: Mon, 8 Jun 2015 18:33:44 +0100 Subject: bitbake: toaster: fixes after refactoring This patch fixes issues brought in by refactoring: * the New Build button is working with pre-set projects * the xhr_datatypeahead is exposed for calls that are not mapable to the REST objects * a new table returing recipes provided by layers currently selected in the project is used to provide recipe suggestions * the field names in json are switched from "list" to "rows" as to maintain consistency with the ToasterTables * the "value" field in xhr_ calls is now named "search" to maintain consistency (Bitbake rev: a5bc29083d4f85a5695f3f62d5badb783c6f7224) Signed-off-by: Alexandru DAMIAN Signed-off-by: Richard Purdie --- bitbake/lib/toaster/toastergui/static/js/base.js | 104 ++++++++++++--------- .../lib/toaster/toastergui/static/js/libtoaster.js | 2 +- .../lib/toaster/toastergui/static/js/projectapp.js | 24 +++-- 3 files changed, 78 insertions(+), 52 deletions(-) (limited to 'bitbake/lib/toaster/toastergui/static') diff --git a/bitbake/lib/toaster/toastergui/static/js/base.js b/bitbake/lib/toaster/toastergui/static/js/base.js index 747442cc9e..06d0676cbf 100644 --- a/bitbake/lib/toaster/toastergui/static/js/base.js +++ b/bitbake/lib/toaster/toastergui/static/js/base.js @@ -1,100 +1,118 @@ +'use strict'; - -function basePageInit (ctx) { +function basePageInit(ctx) { var newBuildButton = $("#new-build-button"); /* Hide the button if we're on the project,newproject or importlyaer page * or if there are no projects yet defined */ - if (ctx.numProjects == 0 || ctx.currentUrl.search('newproject|project/\\d$|importlayer$') > 0){ - newBuildButton.hide(); - return; + if (ctx.numProjects === 0 || ctx.currentUrl.search('newproject|project/\\d$|importlayer$') > 0) { + newBuildButton.hide(); + return; } var currentProjectId = libtoaster.ctx.projectId; /* Hide the change project icon when there is only one project */ - if (ctx.numProjects == 1){ - $('#project .icon-pencil').hide(); + if (ctx.numProjects === 1) { + $('#project .icon-pencil').hide(); } newBuildButton.show().removeAttr("disabled"); - _checkProjectBuildable() + var newBuildProjectInput = $("#new-build-button #project-name-input"); + var newBuildTargetBuildBtn = $("#new-build-button #build-button"); + var newBuildTargetInput = $("#new-build-button #build-target-input"); + var newBuildProjectSaveBtn = $("#new-build-button #save-project-button"); + + + var selectedTarget; + + _checkProjectBuildable(); _setupNewBuildButton(); - function _checkProjectBuildable(){ - if (libtoaster.ctx.projectId == undefined) + function _checkProjectBuildable() { + if (libtoaster.ctx.projectId === undefined) { return; + } libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, - function(data){ - if (data.machine.name == undefined || data.layers.length == 0) { + function (data) { + if (data.machine.name === undefined || data.layers.length === 0) { /* we can't build anything with out a machine and some layers */ $("#new-build-button #targets-form").hide(); $("#new-build-button .alert").show(); } else { $("#new-build-button #targets-form").show(); $("#new-build-button .alert").hide(); + + /* we can build this project; enable input fields */ + newBuildTargetInput.prop("disabled", false); + newBuildTargetBuildBtn.prop("disabled", false); + + libtoaster.makeTypeahead(newBuildTargetInput, libtoaster.ctx.projectTargetsUrl, { format: "json" }, function (item) { + /* successfully selected a target */ + selectedTarget = item; + }); + } - }, null); + }, null); } function _setupNewBuildButton() { /* Setup New build button */ - var newBuildProjectInput = $("#new-build-button #project-name-input"); - var newBuildTargetBuildBtn = $("#new-build-button #build-button"); - var newBuildTargetInput = $("#new-build-button #build-target-input"); - var newBuildProjectSaveBtn = $("#new-build-button #save-project-button"); - var selectedTarget; var selectedProject; /* If we don't have a current project then present the set project * form. */ - if (libtoaster.ctx.projectId == undefined) { + if (libtoaster.ctx.projectId === undefined) { $('#change-project-form').show(); $('#project .icon-pencil').hide(); } - libtoaster.makeTypeahead(newBuildProjectInput, libtoaster.ctx.projectsUrl, { format : "json" }, function(item){ - /* successfully selected a project */ - newBuildProjectSaveBtn.removeAttr("disabled"); - selectedProject = item; + libtoaster.makeTypeahead(newBuildProjectInput, libtoaster.ctx.projectsUrl, { format : "json" }, function (item) { + /* successfully selected a project */ + newBuildProjectSaveBtn.removeAttr("disabled"); + selectedProject = item; }); /* Any typing in the input apart from enter key is going to invalidate * the value that has been set by selecting a suggestion from the typeahead */ - newBuildProjectInput.on('input', function(event) { - if (event.keyCode == 13) - return; - newBuildProjectSaveBtn.attr("disabled", "disabled"); + newBuildProjectInput.on('input', function (event) { + if (event.keyCode === 13) { + return; + } + newBuildProjectSaveBtn.attr("disabled", "disabled"); }); - newBuildTargetInput.on('input', function() { - if ($(this).val().length == 0) + newBuildTargetInput.on('input', function () { + if ($(this).val().length === 0) { newBuildTargetBuildBtn.attr("disabled", "disabled"); - else + } else { newBuildTargetBuildBtn.removeAttr("disabled"); + } }); - newBuildTargetBuildBtn.click(function() { - if (!newBuildTargetInput.val()) + newBuildTargetBuildBtn.click(function () { + if (!newBuildTargetInput.val()) { return; + } - if (!selectedTarget) + if (!selectedTarget) { selectedTarget = { name: newBuildTargetInput.val() }; + } /* fire and forget */ - libtoaster.startABuild(ctx.projectBuildsUrl, libtoaster.ctx.projectId, selectedTarget.name, null, null); + libtoaster.startABuild(libtoaster.ctx.projectBuildsUrl, libtoaster.ctx.projectId, selectedTarget.name, null, null); window.location.replace(libtoaster.ctx.projectPageUrl); }); - newBuildProjectSaveBtn.click(function() { - libtoaster.ctx.projectId = selectedProject.pk + newBuildProjectSaveBtn.click(function () { + libtoaster.ctx.projectId = selectedProject.pk; /* Update the typeahead project_id paramater */ _checkProjectBuildable(); @@ -111,10 +129,10 @@ function basePageInit (ctx) { newBuildTargetInput.prop("disabled", false); newBuildTargetBuildBtn.prop("disabled", false); - libtoaster.makeTypeahead(newBuildTargetInput, selectedProject.projectTargetsUrl, { format: "json" }, function(item){ + libtoaster.makeTypeahead(newBuildTargetInput, selectedProject.projectTargetsUrl, { format: "json" }, function (item) { /* successfully selected a target */ selectedTarget = item; - }); + }); newBuildTargetInput.val(""); @@ -123,12 +141,12 @@ function basePageInit (ctx) { $("#new-build-button .alert a").attr('href', libtoaster.ctx.projectPageUrl); $("#project .icon-pencil").show(); - $("#change-project-form").slideUp({ 'complete' : function() { + $("#change-project-form").slideUp({ 'complete' : function () { $("#new-build-button #project").show(); }}); }); - $('#new-build-button #project .icon-pencil').click(function() { + $('#new-build-button #project .icon-pencil').click(function () { newBuildProjectSaveBtn.attr("disabled", "disabled"); newBuildProjectInput.val($("#new-build-button #project a").text()); $("#cancel-change-project").show(); @@ -136,8 +154,8 @@ function basePageInit (ctx) { $("#change-project-form").slideDown(); }); - $("#new-build-button #cancel-change-project").click(function() { - $("#change-project-form").hide(function(){ + $("#new-build-button #cancel-change-project").click(function () { + $("#change-project-form").hide(function () { $('#new-build-button #project').show(); }); @@ -146,7 +164,7 @@ function basePageInit (ctx) { }); /* Keep the dropdown open even unless we click outside the dropdown area */ - $(".new-build").click (function(event) { + $(".new-build").click (function (event) { event.stopPropagation(); }); }; diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index b1038cf618..23755a75f2 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js @@ -25,7 +25,7 @@ var libtoaster = (function (){ return; } - return process (data.list); + return process (data.rows); }); }, updater: function(item) { diff --git a/bitbake/lib/toaster/toastergui/static/js/projectapp.js b/bitbake/lib/toaster/toastergui/static/js/projectapp.js index a915278444..44e244d302 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projectapp.js +++ b/bitbake/lib/toaster/toastergui/static/js/projectapp.js @@ -217,13 +217,13 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $scope.getAutocompleteSuggestions = function(type, currentValue) { var deffered = $q.defer(); - $http({method:"GET", url: $scope.urls.xhr_datatypeahead, params : { type: type, value: currentValue}}) + $http({method:"GET", url: $scope.urls.xhr_datatypeahead, params : { type: type, search: currentValue}}) .success(function (_data) { if (_data.error != "ok") { console.warn(_data.error); deffered.reject(_data.error); } - deffered.resolve(_data.list); + deffered.resolve(_data.rows); }); return deffered.promise; @@ -534,8 +534,17 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc if (_data.error != "ok") { console.warn(_data.error); } else { - console.log("got layer deps", _data.layerdeps.list); - if (_data.layerdeps.list.length > 0) { + /* filter out layers that are already in the project */ + var filtered_list = []; + var projectlayers_ids = $scope.layers.map(function (e) { return e.id }); + for (var i = 0; i < _data.layerdeps.list.length; i++) { + if (projectlayers_ids.indexOf(_data.layerdeps.list[i].id) == -1) { + filtered_list.push( _data.layerdeps.list[i]); + } + } + + _data.layerdeps.list = filtered_list; + if (_data.layerdeps.list.length > 0) { // activate modal console.log("listing modals"); var modalInstance = $modal.open({ @@ -575,7 +584,6 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc console.log("built modal instance", modalInstance); modalInstance.result.then(function (selectedArray) { - console.log("layer to add", $scope.layerToAdd) selectedArray.push($scope.layerToAdd.id); console.warn("TRC6: selected", selectedArray); @@ -634,13 +642,13 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc $scope.testProjectSettingsChange = function(elementid) { if (elementid != '#change-project-version') throw "Not implemented"; - $http({method:"GET", url: $scope.urls.xhr_datatypeahead, params : { type: "versionlayers", value: $scope.projectVersion }}). + $http({method:"GET", url: $scope.urls.xhr_datatypeahead, params : { type: "versionlayers", search: $scope.projectVersion }}). success(function (_data) { if (_data.error != "ok") { alert (_data.error); } else { - if (_data.list.length > 0) { + if (_data.rows.length > 0) { // activate modal var modalInstance = $modal.open({ templateUrl: 'change_version_modal', @@ -660,7 +668,7 @@ projectApp.controller('prjCtrl', function($scope, $modal, $http, $interval, $loc }, resolve: { items: function () { - return _data.list; + return _data.rows; }, releaseName: function () { return $scope.releases.filter(function (e) { if (e.id == $scope.projectVersion) return e;})[0].name; -- cgit v1.2.3-54-g00ecf