From aff29d2cd837df90a2897b9b75753e4af30f132e Mon Sep 17 00:00:00 2001 From: Michael Wood Date: Tue, 4 Aug 2015 22:46:34 +0300 Subject: bitbake: toastergui: Switch to using the new toaster typeahead widget Switch the existing typeahead inputs to use the new typeahead widget. This means we have a defined mechanism and end point for typeaheads which meets the design specification. (Bitbake rev: 31a8ae7909347f7b6edde5bbdf02b86dc1b32ed0) Signed-off-by: Michael Wood Signed-off-by: Ed Bartosh Signed-off-by: Richard Purdie --- bitbake/lib/toaster/toastergui/static/js/base.js | 26 ++++++++++++++-------- .../toaster/toastergui/static/js/importlayer.js | 12 +++++----- .../toaster/toastergui/static/js/layerdetails.js | 2 +- .../lib/toaster/toastergui/static/js/libtoaster.js | 5 ++--- .../toaster/toastergui/static/js/projectpage.js | 4 ++-- bitbake/lib/toaster/toastergui/templates/base.html | 8 ++++--- bitbake/lib/toaster/toastergui/views.py | 6 +++-- 7 files changed, 37 insertions(+), 26 deletions(-) diff --git a/bitbake/lib/toaster/toastergui/static/js/base.js b/bitbake/lib/toaster/toastergui/static/js/base.js index f25336110a..eba9c16783 100644 --- a/bitbake/lib/toaster/toastergui/static/js/base.js +++ b/bitbake/lib/toaster/toastergui/static/js/base.js @@ -89,8 +89,8 @@ function basePageInit(ctx) { } /* If we have a project setup the typeahead */ - if (selectedProject.projectTargetsUrl){ - libtoaster.makeTypeahead(newBuildTargetInput, selectedProject.projectTargetsUrl, { format: "json" }, function (item) { + if (selectedProject.recipesTypeAheadUrl){ + libtoaster.makeTypeahead(newBuildTargetInput, selectedProject.recipesTypeAheadUrl, { format: "json" }, function (item) { selectedTarget = item; newBuildTargetBuildBtn.removeAttr("disabled"); }); @@ -156,7 +156,7 @@ function basePageInit(ctx) { $('#project .icon-pencil').hide(); } - libtoaster.makeTypeahead(newBuildProjectInput, selectedProject.projectsUrl, { format : "json" }, function (item) { + libtoaster.makeTypeahead(newBuildProjectInput, selectedProject.projectsTypeAheadUrl, { format : "json" }, function (item) { /* successfully selected a project */ newBuildProjectSaveBtn.removeAttr("disabled"); selectedProject = item; @@ -180,13 +180,21 @@ function basePageInit(ctx) { newBuildTargetInput.removeAttr("disabled"); - /* Update the typeahead to use the new selectedProject */ - libtoaster.makeTypeahead(newBuildTargetInput, selectedProject.projectTargetsUrl, { format: "json" }, function (item) { - /* successfully selected a target */ - selectedTarget = item; - newBuildTargetBuildBtn.removeAttr("disabled"); - }); + /* We've got a new project so now we need to update the + * target urls. We can get this from the new project's info + */ + $.getJSON(selectedProject.projectPageUrl, { format: "json" }, + function(projectInfo){ + /* Update the typeahead to use the new selectedProject */ + selectedProject = projectInfo; + + libtoaster.makeTypeahead(newBuildTargetInput, selectedProject.recipesTypeAheadUrl, { format: "json" }, function (item) { + /* successfully selected a target */ + selectedTarget = item; + newBuildTargetBuildBtn.removeAttr("disabled"); + }); + }); newBuildTargetInput.val(""); /* set up new form aspect */ diff --git a/bitbake/lib/toaster/toastergui/static/js/importlayer.js b/bitbake/lib/toaster/toastergui/static/js/importlayer.js index 50bc4ddd7c..2fadbc0978 100644 --- a/bitbake/lib/toaster/toastergui/static/js/importlayer.js +++ b/bitbake/lib/toaster/toastergui/static/js/importlayer.js @@ -16,7 +16,7 @@ function importLayerPageInit (ctx) { var currentLayerDepSelection; var validLayerName = /^(\w|-)+$/; - libtoaster.makeTypeahead(layerDepInput, libtoaster.ctx.projectLayersUrl, { include_added: "true" }, function(item){ + libtoaster.makeTypeahead(layerDepInput, libtoaster.ctx.layersTypeAheadUrl, { include_added: "true" }, function(item){ currentLayerDepSelection = item; layerDepBtn.removeAttr("disabled"); @@ -26,11 +26,11 @@ function importLayerPageInit (ctx) { /* We automatically add "openembedded-core" layer for convenience as a * dependency as pretty much all layers depend on this one */ - $.getJSON(libtoaster.ctx.projectLayersUrl, - { include_added: "true" , search: "openembedded-core", format: "json" }, + $.getJSON(libtoaster.ctx.layersTypeAheadUrl, + { include_added: "true" , search: "openembedded-core" }, function(layer) { - if (layer.rows.length > 0) { - currentLayerDepSelection = layer.rows[0]; + if (layer.results.length > 0) { + currentLayerDepSelection = layer.results[0]; layerDepBtn.click(); } }); @@ -211,7 +211,7 @@ function importLayerPageInit (ctx) { var name = $(this).val(); /* Check if the layer name exists */ - $.getJSON(libtoaster.ctx.projectLayersUrl, + $.getJSON(libtoaster.ctx.layersTypeAheadUrl, { include_added: "true" , search: name, format: "json" }, function(layer) { if (layer.rows.length > 0) { diff --git a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js index be6bbcd20f..96372f06f4 100644 --- a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js +++ b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js @@ -9,7 +9,7 @@ function layerDetailsPageInit (ctx) { var addRmLayerBtn = $("#add-remove-layer-btn"); /* setup the dependencies typeahead */ - libtoaster.makeTypeahead(layerDepInput, libtoaster.ctx.projectLayersUrl, { include_added: "true" }, function(item){ + libtoaster.makeTypeahead(layerDepInput, libtoaster.ctx.layersTypeAheadUrl, { include_added: "true" }, function(item){ currentLayerDepSelection = item; layerDepBtn.removeAttr("disabled"); diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js index 7edd0190f3..c9ff6507ef 100644 --- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js +++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js @@ -19,14 +19,13 @@ var libtoaster = (function (){ jQElement.typeahead({ source: function(query, process){ xhrParams.search = query; - xhrParams.format = "json"; $.getJSON(xhrUrl, this.options.xhrParams, function(data){ if (data.error !== "ok") { console.log("Error getting data from server "+data.error); return; } - return process (data.rows); + return process(data.results); }); }, updater: function(item) { @@ -40,7 +39,7 @@ var libtoaster = (function (){ return 0; } - return ~item.name.toLowerCase().indexOf(this.query.toLowerCase()); + return 1; }, highlighter: function (item) { if (item.hasOwnProperty('detail')) diff --git a/bitbake/lib/toaster/toastergui/static/js/projectpage.js b/bitbake/lib/toaster/toastergui/static/js/projectpage.js index b7cb074f11..b82f7408e7 100644 --- a/bitbake/lib/toaster/toastergui/static/js/projectpage.js +++ b/bitbake/lib/toaster/toastergui/static/js/projectpage.js @@ -98,7 +98,7 @@ function projectPageInit(ctx) { /* Add/Rm layer functionality */ - libtoaster.makeTypeahead(layerAddInput, libtoaster.ctx.projectLayersUrl, { include_added: "false" }, function(item){ + libtoaster.makeTypeahead(layerAddInput, libtoaster.ctx.layersTypeAheadUrl, { include_added: "false" }, function(item){ currentLayerAddSelection = item; layerAddBtn.removeAttr("disabled"); }); @@ -251,7 +251,7 @@ function projectPageInit(ctx) { machineNameTitle.text(machineName); } - libtoaster.makeTypeahead(machineChangeInput, libtoaster.ctx.projectMachinesUrl, { }, function(item){ + libtoaster.makeTypeahead(machineChangeInput, libtoaster.ctx.machinesTypeAheadUrl, { }, function(item){ currentMachineAddSelection = item; machineChangeBtn.removeAttr("disabled"); }); diff --git a/bitbake/lib/toaster/toastergui/templates/base.html b/bitbake/lib/toaster/toastergui/templates/base.html index 65367e20dd..d75bf16bf2 100644 --- a/bitbake/lib/toaster/toastergui/templates/base.html +++ b/bitbake/lib/toaster/toastergui/templates/base.html @@ -32,14 +32,16 @@ jsUrl : "{% static 'js/' %}", htmlUrl : "{% static 'html/' %}", projectsUrl : "{% url 'all-projects' %}", + projectsTypeAheadUrl: {% url 'xhr_projectstypeahead' as prjurl%}{{prjurl|json}}, {% if project.id %} projectId : {{project.id}}, projectPageUrl : {% url 'project' project.id as purl%}{{purl|json}}, projectName : {{project.name|json}}, - projectTargetsUrl: {% url 'projectavailabletargets' project.id as paturl%}{{paturl|json}}, + recipesTypeAheadUrl: {% url 'xhr_recipestypeahead' project.id as paturl%}{{paturl|json}}, + layersTypeAheadUrl: {% url 'xhr_layerstypeahead' project.id as paturl%}{{paturl|json}}, + machinesTypeAheadUrl: {% url 'xhr_machinestypeahead' project.id as paturl%}{{paturl|json}}, + projectBuildsUrl: {% url 'projectbuilds' project.id as pburl %}{{pburl|json}}, - projectLayersUrl: {% url 'projectlayers' project.id as plurl %}{{plurl|json}}, - projectMachinesUrl: {% url 'projectmachines' project.id as pmurl %}{{pmurl|json}}, projectId : {{project.id}}, {% else %} projectId : undefined, diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index b43a01e951..b7bfb9a69d 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py @@ -2235,6 +2235,8 @@ if True: "freqtargets": freqtargets[:5], "releases": map(lambda x: {"id": x.pk, "name": x.name, "description":x.description}, Release.objects.all()), "project_html": 1, + "recipesTypeAheadUrl": reverse('xhr_recipestypeahead', args=(prj.pk,)), + "projectBuildsUrl": reverse('projectbuilds', args=(prj.pk,)), } if prj.release is not None: @@ -2784,9 +2786,9 @@ if True: for p in project_info.object_list: p.id = p.pk p.projectPageUrl = reverse('project', args=(p.id,)) - p.projectLayersUrl = reverse('projectlayers', args=(p.id,)) + p.layersTypeAheadUrl = reverse('xhr_layerstypeahead', args=(p.id,)) + p.recipesTypeAheadUrl = reverse('xhr_recipestypeahead', args=(p.id,)) p.projectBuildsUrl = reverse('projectbuilds', args=(p.id,)) - p.projectTargetsUrl = reverse('projectavailabletargets', args=(p.id,)) # build view-specific information; this is rendered specifically in the builds page, at the top of the page (i.e. Recent builds) build_mru = _get_latest_builds() -- cgit v1.2.3-54-g00ecf