summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/static
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2015-05-19 16:14:29 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-06-12 00:01:47 +0100
commitafe06e313eac61f598f65e622ceb5951a9fabc9a (patch)
tree02e37805b7b10a30c77fc3c82987bf435b221423 /bitbake/lib/toaster/toastergui/static
parent94aa0d5408f71a2e9fd48fd2c0e283acfc9ac2a2 (diff)
downloadpoky-afe06e313eac61f598f65e622ceb5951a9fabc9a.tar.gz
bitbake: toaster: move project data typeahead to the REST API
This patch enables JSON requests on the project REST endpoint, and replaces the universal queries "xhr_datatypeahead" with the `project` type to the REST project endpoint. The patch adds a decorator that takes a context returned by a view and either renders the template specified as the decorator argument, or converts the context to JSON. Normal "search", "filter" and "order" options for view work as normal on the JSON API format. To enable the JSON return, set the "format" GET parameter to "json". In order to demonstrate the functionality, the "New build" button is switched from using the xhr_datatypeahead to the project REST API with JSON formatting. Additionally, the XHR APIs that perform actions with the project id passed as parameter are removed, and the needed URLs are populated from the project JSON API returns after the project has been selected. (Bitbake rev: 15a2274eba13d19b864f337057d61c75ff7849cc) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static')
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/base.js51
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/importlayer.js6
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/layerdetails.js2
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/libtoaster.js12
4 files changed, 44 insertions, 27 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/base.js b/bitbake/lib/toaster/toastergui/static/js/base.js
index ccc23e0e60..9424b6c328 100644
--- a/bitbake/lib/toaster/toastergui/static/js/base.js
+++ b/bitbake/lib/toaster/toastergui/static/js/base.js
@@ -15,20 +15,21 @@ function basePageInit (ctx) {
15 15
16 /* Hide the change project icon when there is only one project */ 16 /* Hide the change project icon when there is only one project */
17 if (ctx.numProjects == 1){ 17 if (ctx.numProjects == 1){
18 $('#project .icon-pencil').hide(); 18 $('#project .icon-pencil').hide();
19 } 19 }
20 20
21 newBuildButton.show().removeAttr("disabled"); 21 newBuildButton.show().removeAttr("disabled");
22 22
23
23 _checkProjectBuildable() 24 _checkProjectBuildable()
24 _setupNewBuildButton(); 25 _setupNewBuildButton();
25 26
26 27
27 function _checkProjectBuildable(){ 28 function _checkProjectBuildable(){
28 if (currentProjectId == undefined) 29 if (libtoaster.ctx.projectId == undefined)
29 return; 30 return;
30 31
31 libtoaster.getProjectInfo(ctx.projectInfoUrl, currentProjectId, 32 libtoaster.getProjectInfo(ctx.projectInfoUrl, libtoaster.ctx.projectId,
32 function(data){ 33 function(data){
33 if (data.machine.name == undefined || data.layers.length == 0) { 34 if (data.machine.name == undefined || data.layers.length == 0) {
34 /* we can't build anything with out a machine and some layers */ 35 /* we can't build anything with out a machine and some layers */
@@ -53,18 +54,13 @@ function basePageInit (ctx) {
53 /* If we don't have a current project then present the set project 54 /* If we don't have a current project then present the set project
54 * form. 55 * form.
55 */ 56 */
56 if (currentProjectId == undefined) { 57 if (libtoaster.ctx.projectId == undefined) {
57 $('#change-project-form').show(); 58 $('#change-project-form').show();
58 $('#project .icon-pencil').hide(); 59 $('#project .icon-pencil').hide();
59 } 60 }
60 61
61 libtoaster.makeTypeahead(newBuildTargetInput, { type : "targets", project_id: currentProjectId }, function(item){
62 /* successfully selected a target */
63 selectedTarget = item;
64 });
65 62
66 63 libtoaster.makeTypeahead(newBuildProjectInput, libtoaster.ctx.projectsUrl, { format : "json" }, function(item){
67 libtoaster.makeTypeahead(newBuildProjectInput, { type : "projects" }, function(item){
68 /* successfully selected a project */ 64 /* successfully selected a project */
69 newBuildProjectSaveBtn.removeAttr("disabled"); 65 newBuildProjectSaveBtn.removeAttr("disabled");
70 selectedProject = item; 66 selectedProject = item;
@@ -93,20 +89,40 @@ function basePageInit (ctx) {
93 if (!selectedTarget) 89 if (!selectedTarget)
94 selectedTarget = { name: newBuildTargetInput.val() }; 90 selectedTarget = { name: newBuildTargetInput.val() };
95 /* fire and forget */ 91 /* fire and forget */
96 libtoaster.startABuild(ctx.projectBuildUrl, currentProjectId, selectedTarget.name, null, null); 92 libtoaster.startABuild(ctx.projectBuildUrl, libtoaster.ctx.projectId, selectedTarget.name, null, null);
97 window.location.replace(ctx.projectBasePageUrl+currentProjectId); 93 window.location.replace(libtoaster.ctx.projectPageUrl);
98 }); 94 });
99 95
100 newBuildProjectSaveBtn.click(function() { 96 newBuildProjectSaveBtn.click(function() {
101 currentProjectId = selectedProject.id 97 libtoaster.ctx.projectId = selectedProject.pk
102 /* Update the typeahead project_id paramater */ 98 /* Update the typeahead project_id paramater */
103 _checkProjectBuildable(); 99 _checkProjectBuildable();
104 newBuildTargetInput.data('typeahead').options.xhrParams.project_id = currentProjectId;
105 newBuildTargetInput.val("");
106 100
107 $("#new-build-button #project a").text(selectedProject.name).attr('href', ctx.projectBasePageUrl+currentProjectId); 101 /* we set the effective context of the page to the currently selected project */
108 $("#new-build-button .alert a").attr('href', ctx.projectBasePageUrl+currentProjectId); 102 /* TBD: do we override even if we already have a context project ?? */
103 /* TODO: replace global library context with references to the "selected" project */
104 libtoaster.ctx.projectPageUrl = selectedProject.projectPageUrl;
105 libtoaster.ctx.xhrProjectEditUrl = selectedProject.xhrProjectEditUrl;
106 libtoaster.ctx.projectName = selectedProject.name;
107 libtoaster.ctx.projectId = selectedProject.id;
108
109 ctx.projectBuildUrl = selectedProject.projectBuildUrl;
110
111 /* we can create a target typeahead only after we have a project selected */
112 newBuildTargetInput.prop("disabled", false);
113 newBuildTargetBuildBtn.prop("disabled", false);
114
115 libtoaster.makeTypeahead(newBuildTargetInput, selectedProject.xhrProjectDataTypeaheadUrl, { type : "targets" }, function(item){
116 /* successfully selected a target */
117 selectedTarget = item;
118 });
119
120 newBuildTargetInput.val("");
109 121
122 /* set up new form aspect */
123 $("#new-build-button #project a").text(selectedProject.name).attr('href', libtoaster.ctx.projectPageUrl);
124 $("#new-build-button .alert a").attr('href', libtoaster.ctx.projectPageUrl);
125 $("#project .icon-pencil").show();
110 126
111 $("#change-project-form").slideUp({ 'complete' : function() { 127 $("#change-project-form").slideUp({ 'complete' : function() {
112 $("#new-build-button #project").show(); 128 $("#new-build-button #project").show();
@@ -116,6 +132,7 @@ function basePageInit (ctx) {
116 $('#new-build-button #project .icon-pencil').click(function() { 132 $('#new-build-button #project .icon-pencil').click(function() {
117 newBuildProjectSaveBtn.attr("disabled", "disabled"); 133 newBuildProjectSaveBtn.attr("disabled", "disabled");
118 newBuildProjectInput.val($("#new-build-button #project a").text()); 134 newBuildProjectInput.val($("#new-build-button #project a").text());
135 $("#cancel-change-project").show();
119 $(this).parent().hide(); 136 $(this).parent().hide();
120 $("#change-project-form").slideDown(); 137 $("#change-project-form").slideDown();
121 }); 138 });
diff --git a/bitbake/lib/toaster/toastergui/static/js/importlayer.js b/bitbake/lib/toaster/toastergui/static/js/importlayer.js
index 875cc342b8..beb2ede3dc 100644
--- a/bitbake/lib/toaster/toastergui/static/js/importlayer.js
+++ b/bitbake/lib/toaster/toastergui/static/js/importlayer.js
@@ -18,7 +18,7 @@ function importLayerPageInit (ctx) {
18 18
19 $("#new-project-button").hide(); 19 $("#new-project-button").hide();
20 20
21 libtoaster.makeTypeahead(layerDepInput, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" }, function(item){ 21 libtoaster.makeTypeahead(layerDepInput, libtoaster.ctx.xhrProjectDataTypeaheadUrl, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" }, function(item){
22 currentLayerDepSelection = item; 22 currentLayerDepSelection = item;
23 23
24 layerDepBtn.removeAttr("disabled"); 24 layerDepBtn.removeAttr("disabled");
@@ -28,7 +28,7 @@ function importLayerPageInit (ctx) {
28 /* We automatically add "openembedded-core" layer for convenience as a 28 /* We automatically add "openembedded-core" layer for convenience as a
29 * dependency as pretty much all layers depend on this one 29 * dependency as pretty much all layers depend on this one
30 */ 30 */
31 $.getJSON(libtoaster.ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" , value: "openembedded-core" }, function(layer) { 31 $.getJSON(libtoaster.ctx.xhrProjectDataTypeaheadUrl, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" , value: "openembedded-core" }, function(layer) {
32 if (layer.list.length == 1) { 32 if (layer.list.length == 1) {
33 currentLayerDepSelection = layer.list[0]; 33 currentLayerDepSelection = layer.list[0];
34 layerDepBtn.click(); 34 layerDepBtn.click();
@@ -211,7 +211,7 @@ function importLayerPageInit (ctx) {
211 var name = $(this).val(); 211 var name = $(this).val();
212 212
213 /* Check if the layer name exists */ 213 /* Check if the layer name exists */
214 $.getJSON(libtoaster.ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" , value: name }, function(layer) { 214 $.getJSON(libtoaster.ctx.xhrProjectDataTypeaheadUrl, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" , value: name }, function(layer) {
215 if (layer.list.length > 0) { 215 if (layer.list.length > 0) {
216 for (var i in layer.list){ 216 for (var i in layer.list){
217 if (layer.list[i].name == name) { 217 if (layer.list[i].name == name) {
diff --git a/bitbake/lib/toaster/toastergui/static/js/layerdetails.js b/bitbake/lib/toaster/toastergui/static/js/layerdetails.js
index 3746ea26e3..8e14b8f277 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) {
9 var addRmLayerBtn = $("#add-remove-layer-btn"); 9 var addRmLayerBtn = $("#add-remove-layer-btn");
10 10
11 /* setup the dependencies typeahead */ 11 /* setup the dependencies typeahead */
12 libtoaster.makeTypeahead(layerDepInput, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" }, function(item){ 12 libtoaster.makeTypeahead(layerDepInput, libtoaster.ctx.xhrProjectDataTypeaheadUrl, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" }, function(item){
13 currentLayerDepSelection = item; 13 currentLayerDepSelection = item;
14 14
15 layerDepBtn.removeAttr("disabled"); 15 layerDepBtn.removeAttr("disabled");
diff --git a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js
index 99e1f03095..72fb0a93f5 100644
--- a/bitbake/lib/toaster/toastergui/static/js/libtoaster.js
+++ b/bitbake/lib/toaster/toastergui/static/js/libtoaster.js
@@ -10,16 +10,16 @@ var libtoaster = (function (){
10 * xhrUrl: the url to get the JSON from expects JSON in the form: 10 * xhrUrl: the url to get the JSON from expects JSON in the form:
11 * { "list": [ { "name": "test", "detail" : "a test thing" }, .... ] } 11 * { "list": [ { "name": "test", "detail" : "a test thing" }, .... ] }
12 * xhrParams: the data/parameters to pass to the getJSON url e.g. 12 * xhrParams: the data/parameters to pass to the getJSON url e.g.
13 * { 'type' : 'projects' } the text typed will be passed as 'value'. 13 * { 'type' : 'projects' } the text typed will be passed as 'search'.
14 * selectedCB: function to call once an item has been selected one 14 * selectedCB: function to call once an item has been selected one
15 * arg of the item. 15 * arg of the item.
16 */ 16 */
17 function _makeTypeahead (jQElement, xhrParams, selectedCB) { 17 function _makeTypeahead (jQElement, xhrUrl, xhrParams, selectedCB) {
18 18
19 jQElement.typeahead({ 19 jQElement.typeahead({
20 source: function(query, process){ 20 source: function(query, process){
21 xhrParams.value = query; 21 xhrParams.search = query;
22 $.getJSON(libtoaster.ctx.xhrDataTypeaheadUrl, this.options.xhrParams, function(data){ 22 $.getJSON(xhrUrl, this.options.xhrParams, function(data){
23 if (data.error !== "ok") { 23 if (data.error !== "ok") {
24 console.log("Error getting data from server "+data.error); 24 console.log("Error getting data from server "+data.error);
25 return; 25 return;
@@ -41,7 +41,7 @@ var libtoaster = (function (){
41 return $('<span></span>').text(item.name).get(0); 41 return $('<span></span>').text(item.name).get(0);
42 }, 42 },
43 sorter: function (items) { return items; }, 43 sorter: function (items) { return items; },
44 xhrUrl: libtoaster.ctx.xhrDataTypeaheadUrl, 44 xhrUrl: xhrUrl,
45 xhrParams: xhrParams, 45 xhrParams: xhrParams,
46 }); 46 });
47 47
@@ -172,7 +172,7 @@ var libtoaster = (function (){
172 172
173 function _getLayerDepsForProject(projectId, layerId, onSuccess, onFail){ 173 function _getLayerDepsForProject(projectId, layerId, onSuccess, onFail){
174 /* Check for dependencies not in the current project */ 174 /* Check for dependencies not in the current project */
175 $.getJSON(libtoaster.ctx.xhrDataTypeaheadUrl, 175 $.getJSON(libtoaster.ctx.xhrProjectDataTypeaheadUrl,
176 { type: 'layerdeps', 'value': layerId , project_id: projectId }, 176 { type: 'layerdeps', 'value': layerId , project_id: projectId },
177 function(data) { 177 function(data) {
178 if (data.error != "ok") { 178 if (data.error != "ok") {