]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
bitbake: toaster: Move project context variables to common scope
authorMichael Wood <michael.g.wood@intel.com>
Fri, 10 Apr 2015 17:15:03 +0000 (18:15 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 8 May 2015 16:42:05 +0000 (17:42 +0100)
We have a bunch of context data which are used in multiple pages so it
makes more sense to have this in a single place libtoaster.ctx that's
accessible from each page rather than request it from every page.

(Bitbake rev: 4ef2774a2f683929c700550a9acc7b8f6074195b)

Signed-off-by: Michael Wood <michael.g.wood@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
bitbake/lib/toaster/toastergui/static/js/base.js
bitbake/lib/toaster/toastergui/static/js/importlayer.js
bitbake/lib/toaster/toastergui/static/js/layerdetails.js
bitbake/lib/toaster/toastergui/static/js/libtoaster.js
bitbake/lib/toaster/toastergui/static/js/machines.js
bitbake/lib/toaster/toastergui/templates/base.html
bitbake/lib/toaster/toastergui/templates/importlayer.html
bitbake/lib/toaster/toastergui/templates/layerdetails.html
bitbake/lib/toaster/toastergui/templates/layers_dep_modal.html
bitbake/lib/toaster/toastergui/templates/machines.html

index 667c5dff6c71e81b0eb7e95f7e88f00e5b7c8d7d..c4c96c80e6d145de124218c7a6e01f1350f5cfb7 100644 (file)
@@ -6,7 +6,7 @@ function basePageInit (ctx) {
   /* 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){
+  if (ctx.numProjects == 0 || ctx.currentUrl.search('newproject|project/\\d/$|importlayer/$') > 0){
       newBuildButton.hide();
       return;
   }
@@ -18,17 +18,18 @@ function basePageInit (ctx) {
 
   newBuildButton.show().removeAttr("disabled");
 
-  _checkProjectBuildable();
+  _checkProjectBuildable()
   _setupNewBuildButton();
 
+  var currentProjectId = libtoaster.ctx.projectId;
 
   function _checkProjectBuildable(){
-    if (ctx.projectId === undefined)
+    if (currentProjectId == undefined)
       return;
 
-    libtoaster.getProjectInfo(ctx.projectInfoUrl, ctx.projectId,
+    libtoaster.getProjectInfo(ctx.projectInfoUrl, currentProjectId,
       function(data){
-        if (data.machine.name === undefined || data.layers.length === 0) {
+        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();
@@ -51,18 +52,18 @@ function basePageInit (ctx) {
     /* If we don't have a current project then present the set project
      * form.
      */
-    if (ctx.projectId === undefined) {
+    if (currentProjectId == undefined) {
       $('#change-project-form').show();
       $('#project .icon-pencil').hide();
     }
 
-    libtoaster.makeTypeahead(newBuildTargetInput, ctx.xhrDataTypeaheadUrl, { type : "targets", project_id: ctx.projectId }, function(item){
+    libtoaster.makeTypeahead(newBuildTargetInput, { type : "targets", project_id: currentProjectId }, function(item){
         /* successfully selected a target */
         selectedTarget = item;
     });
 
 
-    libtoaster.makeTypeahead(newBuildProjectInput, ctx.xhrDataTypeaheadUrl, { type : "projects" }, function(item){
+    libtoaster.makeTypeahead(newBuildProjectInput, { type : "projects" }, function(item){
         /* successfully selected a project */
         newBuildProjectSaveBtn.removeAttr("disabled");
         selectedProject = item;
@@ -72,13 +73,13 @@ function basePageInit (ctx) {
      * the value that has been set by selecting a suggestion from the typeahead
      */
     newBuildProjectInput.on('input', function(event) {
-        if (event.keyCode === 13)
+        if (event.keyCode == 13)
           return;
         newBuildProjectSaveBtn.attr("disabled", "disabled");
     });
 
     newBuildTargetInput.on('input', function() {
-      if ($(this).val().length === 0)
+      if ($(this).val().length == 0)
         newBuildTargetBuildBtn.attr("disabled", "disabled");
       else
         newBuildTargetBuildBtn.removeAttr("disabled");
@@ -88,21 +89,22 @@ function basePageInit (ctx) {
       if (!newBuildTargetInput.val())
         return;
 
-      var selectedTargetName = newBuildTargetInput.val();
+      if (!selectedTarget)
+        selectedTarget = { name: newBuildTargetInput.val() };
       /* fire and forget */
-      libtoaster.startABuild(ctx.projectBuildUrl, ctx.projectId, selectedTargetName, null, null);
-      window.location.replace(ctx.projectPageUrl+ctx.projectId);
+      libtoaster.startABuild(ctx.projectBuildUrl, currentProjectId, selectedTarget.name, null, null);
+      window.location.replace(ctx.projectBasePageUrl+currentProjectId);
     });
 
     newBuildProjectSaveBtn.click(function() {
-      ctx.projectId = selectedProject.id;
+      currentProjectId = selectedProject.id
       /* Update the typeahead project_id paramater */
       _checkProjectBuildable();
-      newBuildTargetInput.data('typeahead').options.xhrParams.project_id = ctx.projectId;
+      newBuildTargetInput.data('typeahead').options.xhrParams.project_id = currentProjectId;
       newBuildTargetInput.val("");
 
-      $("#new-build-button #project a").text(selectedProject.name).attr('href', ctx.projectPageUrl+ctx.projectId);
-      $("#new-build-button .alert a").attr('href', ctx.projectPageUrl+ctx.projectId);
+      $("#new-build-button #project a").text(selectedProject.name).attr('href', ctx.projectBasePageUrl+currentProjectId);
+      $("#new-build-button .alert a").attr('href', ctx.projectBasePageUrl+currentProjectId);
 
 
       $("#change-project-form").slideUp({ 'complete' : function() {
@@ -130,5 +132,6 @@ function basePageInit (ctx) {
     $(".new-build").click (function(event) {
       event.stopPropagation();
     });
-  }
+  };
+
 }
index d14a8abcafacf98b864e5c1f779f865990537c19..ec1cc19e90005f783c52bfe1526f82fbafaed946 100644 (file)
@@ -18,7 +18,7 @@ function importLayerPageInit (ctx) {
 
   $("#new-project-button").hide();
 
-  libtoaster.makeTypeahead(layerDepInput, ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: ctx.projectId, include_added: "true" }, function(item){
+  libtoaster.makeTypeahead(layerDepInput, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" }, function(item){
     currentLayerDepSelection = item;
 
     layerDepBtn.removeAttr("disabled");
@@ -28,7 +28,7 @@ function importLayerPageInit (ctx) {
   /* We automatically add "openembedded-core" layer for convenience as a
    * dependency as pretty much all layers depend on this one
    */
-  $.getJSON(ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: ctx.projectId, include_added: "true" , value: "openembedded-core" }, function(layer) {
+  $.getJSON(libtoaster.ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" , value: "openembedded-core" }, function(layer) {
     if (layer.list.length == 1) {
       currentLayerDepSelection = layer.list[0];
       layerDepBtn.click();
@@ -63,7 +63,7 @@ function importLayerPageInit (ctx) {
 
     $("#layer-deps-list").append(newLayerDep);
 
-    libtoaster.getLayerDepsForProject(ctx.xhrDataTypeaheadUrl, ctx.projectId, currentLayerDepSelection.id, function (data){
+    libtoaster.getLayerDepsForProject(libtoaster.ctx.projectId, currentLayerDepSelection.id, function (data){
         /* These are the dependencies of the layer added as a dependency */
         if (data.list.length > 0) {
           currentLayerDepSelection.url = ctx.layerDetailsUrl+currentLayerDepSelection.id;
@@ -137,7 +137,7 @@ function importLayerPageInit (ctx) {
         vcs_url: vcsURLInput.val(),
         git_ref: gitRefInput.val(),
         dir_path: $("#layer-subdir").val(),
-        project_id: ctx.projectId,
+        project_id: libtoaster.ctx.projectId,
         layer_deps: layerDepsCsv,
       };
 
@@ -152,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(ctx.projectPageUrl+'#/layerimported');
+              window.location.replace(libtoaster.ctx.projectPageUrl+'#/layerimported');
             }
           },
           error: function (data) {
@@ -211,7 +211,7 @@ function importLayerPageInit (ctx) {
       var name = $(this).val();
 
       /* Check if the layer name exists */
-      $.getJSON(ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: ctx.projectId, include_added: "true" , value: name }, function(layer) {
+      $.getJSON(libtoaster.ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" , value: name }, function(layer) {
       if (layer.list.length > 0) {
         for (var i in layer.list){
           if (layer.list[i].name == name) {
index bac60c45120932607035cfe891dc354957fc216c..3b6423f7f41d4b0af9359108034bd207c082fe00 100644 (file)
@@ -9,7 +9,7 @@ function layerDetailsPageInit (ctx) {
   var addRmLayerBtn = $("#add-remove-layer-btn");
 
   /* setup the dependencies typeahead */
-  libtoaster.makeTypeahead(layerDepInput, ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: ctx.projectId, include_added: "true" }, function(item){
+  libtoaster.makeTypeahead(layerDepInput, { type : "layers", project_id: libtoaster.ctx.projectId, include_added: "true" }, function(item){
     currentLayerDepSelection = item;
 
     layerDepBtn.removeAttr("disabled");
@@ -125,15 +125,14 @@ function layerDetailsPageInit (ctx) {
   $(".build-target-btn").click(function(){
     /* fire a build */
     var target = $(this).data('target-name');
-    libtoaster.startABuild(ctx.projectBuildUrl, ctx.projectId, target, null, null);
-    window.location.replace(ctx.projectPageUrl);
+    libtoaster.startABuild(ctx.projectBuildUrl, libtoaster.ctx.projectId, target, null, null);
+    window.location.replace(libtoaster.ctx.projectPageUrl);
   });
 
   $(".select-machine-btn").click(function(){
     var data =  { machineName : $(this).data('machine-name') };
-    libtoaster.editProject(ctx.xhrEditProjectUrl, ctx.projectId, data,
-      function (){
-        window.location.replace(ctx.projectPageUrl+"#/machineselected");
+    libtoaster.editCurrentProject(data, function (){
+        window.location.replace(libtoaster.ctx.projectPageUrl+"#/machineselected");
     }, null);
   });
 
@@ -256,8 +255,8 @@ function layerDetailsPageInit (ctx) {
     }
 
     alertMsg.children("#layer-affected-name").text(ctx.layerVersion.name);
-    alertMsg.children("#project-affected-name").text(ctx.projectName);
-    alertMsg.children("#project-affected-name").attr("href", ctx.projectPageUrl);
+    alertMsg.children("#project-affected-name").text(libtoaster.ctx.projectName);
+    alertMsg.children("#project-affected-name").attr("href", libtoaster.ctx.projectPageUrl);
     $("#alert-area").show();
   }
 
@@ -269,12 +268,11 @@ function layerDetailsPageInit (ctx) {
 
     if (directive == 'add') {
       /* If adding get the deps for this layer */
-      libtoaster.getLayerDepsForProject(ctx.xhrDataTypeaheadUrl, ctx.projectId, ctx.layerVersion.id, function (data) {
+      libtoaster.getLayerDepsForProject(libtoaster.ctx.projectId, ctx.layerVersion.id, function (data) {
         /* got result for dependencies */
         if (data.list.length == 0){
           var editData = { layerAdd : ctx.layerVersion.id };
-          libtoaster.editProject(ctx.xhrEditProjectUrl, ctx.projectId, editData,
-            function() {
+          libtoaster.editCurrentProject(editData, function() {
               setLayerInCurrentPrj(true);
           });
           return;
@@ -291,8 +289,7 @@ function layerDetailsPageInit (ctx) {
     } else if (directive == 'remove') {
       var editData = { layerDel : ctx.layerVersion.id };
 
-      libtoaster.editProject(ctx.xhrEditProjectUrl, ctx.projectId, editData,
-        function () {
+      libtoaster.editCurrentProject(editData, function () {
           /* Success removed layer */
            //window.location.reload();
            setLayerInCurrentPrj(false);
index ae9e4556a1756734706e480e07febd47571d49a4..9257f735dbc1d541bc54f4545e1c61c83ce09358 100644 (file)
@@ -14,12 +14,12 @@ var libtoaster = (function (){
    *  selectedCB: function to call once an item has been selected one
    *  arg of the item.
    */
-  function _makeTypeahead (jQElement, xhrUrl, xhrParams, selectedCB) {
+  function _makeTypeahead (jQElement, xhrParams, selectedCB) {
 
     jQElement.typeahead({
         source: function(query, process){
           xhrParams.value = query;
-          $.getJSON(xhrUrl, this.options.xhrParams, function(data){
+          $.getJSON(libtoaster.ctx.xhrDataTypeaheadUrl, this.options.xhrParams, function(data){
             if (data.error !== "ok") {
               console.log("Error getting data from server "+data.error);
               return;
@@ -41,7 +41,7 @@ var libtoaster = (function (){
           return $('<span></span>').text(item.name).get(0);
         },
         sorter: function (items) { return items; },
-        xhrUrl: xhrUrl,
+        xhrUrl: libtoaster.ctx.xhrDataTypeaheadUrl,
         xhrParams: xhrParams,
     });
 
@@ -147,10 +147,10 @@ var libtoaster = (function (){
    * projectVersion
    * machineName
    */
-  function _editProject(url, projectId, data, onSuccess, onFail){
+  function _editCurrentProject(data, onSuccess, onFail){
     $.ajax({
         type: "POST",
-        url: url,
+        url: libtoaster.ctx.xhrProjectEditUrl,
         data: data,
         headers: { 'X-CSRFToken' : $.cookie('csrftoken')},
         success: function (data) {
@@ -170,9 +170,9 @@ var libtoaster = (function (){
     });
   }
 
-  function _getLayerDepsForProject(xhrDataTypeaheadUrl, projectId, layerId, onSuccess, onFail){
+  function _getLayerDepsForProject(projectId, layerId, onSuccess, onFail){
     /* Check for dependencies not in the current project */
-    $.getJSON(xhrDataTypeaheadUrl,
+    $.getJSON(libtoaster.ctx.xhrDataTypeaheadUrl,
       { type: 'layerdeps', 'value': layerId , project_id: projectId },
       function(data) {
         if (data.error != "ok") {
@@ -227,7 +227,7 @@ var libtoaster = (function (){
     makeTypeahead : _makeTypeahead,
     getProjectInfo: _getProjectInfo,
     getLayerDepsForProject : _getLayerDepsForProject,
-    editProject : _editProject,
+    editCurrentProject : _editCurrentProject,
     debug: false,
     parseUrlParams : _parseUrlParams,
     dumpsUrlParams : _dumpsUrlParams,
index 973a037be70794fbad8304388d3e43e4db8e17ab..fbcafc26b50872f5e70955325fd731a74c00bcd2 100644 (file)
@@ -45,7 +45,7 @@ function machinesPageInit (ctx) {
 
     var layerName = addLayerBtn.data('layer-name');
     alertMsg.children("#layer-affected-name").text(layerName);
-    alertMsg.children("#project-affected-name").text(ctx.projectName).attr('href', ctx.projectPageUrl);
+    alertMsg.children("#project-affected-name").text(libtoaster.ctx.projectName).attr('href', libtoaster.ctx.projectPageUrl);
 
     $("#alert-area").show();
   }
@@ -61,12 +61,11 @@ function machinesPageInit (ctx) {
         name : $(this).data('layer-name'),
       };
 
-      libtoaster.getLayerDepsForProject(ctx.xhrDataTypeaheadUrl, ctx.projectId, layer.id, function (data) {
+      libtoaster.getLayerDepsForProject(libtoaster.ctx.projectId, layer.id, function (data) {
         /* got result for dependencies */
         if (data.list.length == 0){
           var editData = { layerAdd : layer.id };
-          libtoaster.editProject(ctx.xhrEditProjectUrl, ctx.projectId, editData,
-            function() {
+          libtoaster.editCurrentProject(editData, function() {
               setLayerInCurrentPrj(btn);
           });
           return;
@@ -84,9 +83,8 @@ function machinesPageInit (ctx) {
 
   $(".select-machine-btn").click(function(){
     var data =  { machineName : $(this).data('machine-name') };
-    libtoaster.editProject(ctx.xhrEditProjectUrl, ctx.projectId, data,
-      function (){
-        window.location.replace(ctx.projectPageUrl+"#/machineselected");
+    libtoaster.editCurrentProject(data, function (){
+        window.location.replace(libtoaster.ctx.projectPageUrl+"#/machineselected");
     }, null);
   });
 
index 58392b36f5edbe9da08eeff509535301bedb73a4..25933a1e90b192a669225066ae8874dca8fe527d 100644 (file)
   libtoaster.debug = true;
  </script>
 {% endif %}
+<script>
+  libtoaster.ctx = {
+    projectId : {{project.id|default:'undefined'}},
+    xhrDataTypeaheadUrl : "{% url 'xhr_datatypeahead' %}",
+    {% if project.id %}
+    xhrProjectEditUrl : "{% url 'xhr_projectedit' project.id %}",
+    projectPageUrl : "{% url 'project' project.id %}",
+    projectName : "{{project.name}}",
+    {% endif %}
+  };
+</script>
 <script src="{% static 'js/base.js' %}"></script>
 {%if MANAGED %}
 <script>
   $(document).ready(function () {
     /* Vars needed for base.js */
     var ctx = {};
-    ctx.xhrDataTypeaheadUrl = "{% url 'xhr_datatypeahead' %}";
     ctx.projectBuildUrl = "{% url 'xhr_build' %}";
-    ctx.projectPageUrl = "{% url 'base_project' %}";
+    ctx.projectBasePageUrl = "{% url 'base_project' %}";
     ctx.projectInfoUrl = "{% url 'xhr_projectinfo' %}";
     ctx.numProjects = {{projects|length}};
-    {% if project %}
-      ctx.projectId = {{project.id}};
-    {% endif %}
     ctx.currentUrl = "{{request.path|escapejs}}";
 
     basePageInit(ctx);
index 5ef8a5786ca039fc9836637d376ff89f1ce94b99..c92b5d8b242e66cf7dda3d9dc8a884c5a4477910 100644 (file)
                   <script>
                     $(document).ready(function (){
                       var ctx = {
-                        xhrDataTypeaheadUrl : "{% url 'xhr_datatypeahead' %}",
                         layerDetailsUrl : "{% url 'base_layerdetails' %}",
                         xhrImportLayerUrl : "{% url 'xhr_importlayer' %}",
-                        xhrEditProjectUrl : "{% url 'xhr_projectedit' project.id %}",
-                        projectPageUrl : "{% url 'project' project.id %}",
-                        projectId : {{project.id}}
                       };
 
                       try {
index 0d3aa15373d495dcf64834edbb730122838e7381..435bf04e42d819035d3f081144e169aed4598cee 100644 (file)
     var ctx = {
       projectBuildUrl : "{% url 'xhr_build' %}",
       layerDetailsUrl : "{% url 'base_layerdetails' %}",
-      projectPageUrl : "{% url 'project' project.id %}",
-      xhrEditProjectUrl : "{% url 'xhr_projectedit' project.id %}",
-      xhrDataTypeaheadUrl : "{% url 'xhr_datatypeahead' %}",
       xhrUpdateLayerUrl : "{% url 'xhr_updatelayer' %}",
-      projectId : {{project.id}},
-      projectName : "{{project.name}}",
       numTargets : {{total_targets}},
       numMachines: {{machines|length}},
       layerVersion : {
index 8222027d4f2ef18067a395885d5dc45877574546..ea49af50d8e17538b8548774a535db02889a4bed 100644 (file)
@@ -18,7 +18,7 @@
     </div>
 
 <script>
-  /* projectId: current project
+  /*
    * layer: Object representing the parent layer { id: .. name: ... url }
    * dependencies: array of dependency layer objects { id: .. name: ..}
    * title: optional override for title
index 2ac35378e0b64be5029b24bafc62f3169bd25a15..64db0f9ca7a13da14d83318ca5053551a57da4d3 100644 (file)
 
   $(document).ready(function (){
     var ctx = {
-      projectPageUrl : "{% url 'project' project.id %}",
-      projectName : "{{project.name}}",
-      xhrEditProjectUrl : "{% url 'xhr_projectedit' project.id %}",
-      projectId : {{project.id}},
-      xhrDataTypeaheadUrl : "{% url 'xhr_datatypeahead' %}",
     };
 
     try {