Skip to contentSkip to conversation

toaster: orm Fix get_number_of_builds to all apart from IN_PROGRESS

PATCH In review Michael Wood 2 participants 5 messages Nov 10, 2015 – Nov 13, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 toaster: orm Fix get_number_of_builds to all apart from IN_PROGRESS

A projects builds should be counted apart from those which are currently in progress.

---
 bitbake/lib/toaster/orm/models.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
bitbake/lib/toaster/orm/models.py +4 -5
index 3832905..0ac94b9 100644
@@ -130,13 +130,12 @@ class Project(models.Model):
         try:
             return self.projectvariable_set.get(name="MACHINE").value
         except (ProjectVariable.DoesNotExist,IndexError):
-            return( "None" );
+            return None;
 
     def get_number_of_builds(self):
-        try:
-            return len(Build.objects.filter( project = self.id ))
-        except (Build.DoesNotExist,IndexError):
-            return( 0 )
+        """Return the number of builds which have ended"""
+
+        return self.build_set.filter(~Q(outcome=Build.IN_PROGRESS)).count()
 
     def get_last_build_id(self):
         try:
Signature · 1 line
2.5.0
#1 lore raw

PATCH 2/4 toaster: projectpage Disable/Enable build input if we have 0 layers

If we've removed all the layers in the configuration disabled the build button and build input.

---
 bitbake/lib/toaster/toastergui/static/js/projectpage.js | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
bitbake/lib/toaster/toastergui/static/js/projectpage.js +10 -3
index e742ef2..ae08d9a 100644
@@ -175,11 +175,18 @@ function projectPageInit(ctx) {
 
   function updateLayersCount(){
     var count = $("#layers-in-project-list").children().length;
+    var noLayerMsg = $("#no-layers-in-project");
+    var buildInput = $("#build-input");
 
-    if (count === 0)
+
+    if (count === 0) {
+      noLayerMsg.fadeIn();
       $("#no-layers-in-project").fadeIn();
-    else
-      $("#no-layers-in-project").hide();
+      buildInput.attr("disabled", "disabled");
+    } else {
+      noLayerMsg.hide();
+      buildInput.removeAttr("disabled");
+    }
 
     $("#project-layers-count").text(count);
 
Signature · 1 line
2.5.0
#2 lore raw

PATCH 3/4 toaster: projecttopbar Use the project in context to get num builds

In reply to Michael Wood

Use the project in the template context rather than ajax request to get the number of ended builds.

---
 bitbake/lib/toaster/toastergui/templates/projecttopbar.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/toaster/toastergui/templates/projecttopbar.html +1 -1
index ee86b54..d8f7cbd 100644
@@ -28,7 +28,7 @@
     <ul class="nav nav-pills">
       <li>
         <a href="{% url 'projectbuilds' project.id %}">
-          Builds (<span class="total-builds">0</span>)
+          Builds ({{project.get_number_of_builds}})
         </a>
       </li>
       <li id="topbar-configuration-tab">
Signature · 1 line
2.5.0
#3 lore raw

PATCH 4/4 toaster: Remove new-build-input form

In reply to Michael Wood

Remove the new-build-input button widget. The button isn't particularly useful and requires a lot of state maintenance to make sure it showed up when the project was configured properly or if there were any projects and what mode toaster was in and then to be able to change project using it.

---
 bitbake/lib/toaster/toastergui/static/js/base.js   | 229 ---------------------
 .../toaster/toastergui/static/js/projecttopbar.js  |  81 ++++++++
 bitbake/lib/toaster/toastergui/templates/base.html | 133 +++---------
 .../toastergui/templates/projecttopbar.html        |  18 ++
 4 files changed, 132 insertions(+), 329 deletions(-)
 delete mode 100644 bitbake/lib/toaster/toastergui/static/js/base.js
 create mode 100644 bitbake/lib/toaster/toastergui/static/js/projecttopbar.js
bitbake/lib/toaster/toastergui/static/js/base.js deleted +0 -229
deleted file mode 100644
index ed22a4e..0000000
@@ -1,229 +0,0 @@
-'use strict';
-
-function basePageInit(ctx) {
-
-  var newBuildButton = $("#new-build-button");
-  var newBuildTargetInput;
-  var newBuildTargetBuildBtn;
-  var projectNameForm = $("#project-name-change-form");
-  var projectNameContainer = $("#project-name-container");
-  var projectName = $("#project-name");
-  var projectNameFormToggle = $("#project-change-form-toggle");
-  var projectNameChangeCancel = $("#project-name-change-cancel");
-
-  /* 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");
-
-  /* Project name change functionality */
-  projectNameFormToggle.click(function(e){
-    e.preventDefault();
-    projectNameContainer.hide();
-    projectNameForm.fadeIn();
-  });
-
-  projectNameChangeCancel.click(function(e){
-    e.preventDefault();
-    projectNameForm.hide();
-    projectNameContainer.fadeIn();
-  });
-
-  $("#project-name-change-btn").click(function(e){
-    var newProjectName = $("#project-name-change-input").val();
-
-    libtoaster.editCurrentProject({ projectName: newProjectName }, function (){
-      projectName.html(newProjectName);
-      libtoaster.ctx.projectName = newProjectName;
-      projectNameChangeCancel.click();
-    });
-  });
-
-  _checkProjectBuildable();
-
-  $("#project-topbar .nav li a").each(function(){
-    if (window.location.pathname === $(this).attr('href'))
-      $(this).parent().addClass('active');
-    else
-      $(this).parent().removeClass('active');
-  });
-
-  if ($(".total-builds").length !== 0){
-    libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, function(prjInfo){
-      if (prjInfo.completedbuilds)
-        $(".total-builds").text(prjInfo.completedbuilds.length);
-    });
-  }
-
-  /* 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
-   */
-  if (ctx.numProjects > 0 &&
-      ctx.currentUrl.search('newproject') < 0 &&
-      $(".build-target-input").length === 1) {
-
-    newBuildTargetInput = $("#new-build-button .build-target-input");
-    newBuildTargetBuildBtn = $("#new-build-button").find(".build-button");
-
-    _setupNewBuildButton();
-    newBuildButton.show();
-  } else if ($(".build-target-input").length > 0) {
-    newBuildTargetInput = $("#project-topbar .build-target-input");
-    newBuildTargetBuildBtn = $("#project-topbar .build-button");
-  } else {
-    return;
-  }
-
-  /* Hide the change project icon when there is only one project */
-  if (ctx.numProjects === 1) {
-    $('#project .icon-pencil').hide();
-  }
-
-  /* If we have a project setup the typeahead */
-  if (selectedProject.recipesTypeAheadUrl){
-    libtoaster.makeTypeahead(newBuildTargetInput, selectedProject.recipesTypeAheadUrl, { format: "json" }, function (item) {
-      selectedTarget = item;
-      newBuildTargetBuildBtn.removeAttr("disabled");
-    });
-  }
-
-  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;
-    }
-
-    /* We use the value of the input field so as to maintain any command also
-     * added e.g. core-image-minimal:clean
-     */
-    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 || selectedProject.projectIsDefault) {
-      return;
-    }
-
-    libtoaster.getProjectInfo(selectedProject.projectPageUrl,
-      function (data) {
-        if (data.machine === null || data.machine.name === undefined || data.layers.length === 0) {
-          /* we can't build anything without 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.removeAttr("disabled");
-       }
-      }, null);
-  }
-
-  /* Setup New build button in the top nav bar */
-  function _setupNewBuildButton() {
-
-    /* If we don't have a current project then present the set project
-     * form.
-     */
-    if (selectedProject.projectId === undefined || selectedProject.projectIsDefault) {
-      $('#change-project-form').show();
-      $('#project .icon-pencil').hide();
-    }
-
-    libtoaster.makeTypeahead(newBuildProjectInput, selectedProject.projectsTypeAheadUrl, { 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");
-    });
-
-
-    newBuildProjectSaveBtn.click(function () {
-      selectedProject.projectId = selectedProject.id;
-      /* Update the typeahead project_id paramater */
-      _checkProjectBuildable();
-
-      newBuildTargetInput.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 */
-      $("#new-build-button #project a").text(selectedProject.name).attr('href', selectedProject.projectPageUrl);
-      $("#new-build-button .alert a").attr('href', selectedProject.projectPageUrl);
-      $("#project .icon-pencil").show();
-
-      $("#change-project-form").slideUp({ 'complete' : function () {
-          $("#new-build-button #project").show();
-      }});
-    });
-
-    $('#new-build-button #project .icon-pencil').click(function () {
-      newBuildProjectSaveBtn.attr("disabled", "disabled");
-      newBuildProjectInput.val($("#new-build-button #project a").text());
-      $("#cancel-change-project").show();
-      $(this).parent().hide();
-      $("#change-project-form").slideDown();
-    });
-
-    $("#new-build-button #cancel-change-project").click(function () {
-      $("#change-project-form").hide(function () {
-        $('#new-build-button #project').show();
-      });
-
-      newBuildProjectInput.val("");
-      newBuildProjectSaveBtn.attr("disabled", "disabled");
-    });
-
-    /* Keep the dropdown open even unless we click outside the dropdown area */
-    $(".new-build").click (function (event) {
-      event.stopPropagation();
-    });
-  };
-
-}
bitbake/lib/toaster/toastergui/static/js/projecttopbar.js new file +81 -0

81 lines not on this page · raw message

bitbake/lib/toaster/toastergui/templates/base.html +33 -100

164 lines not on this page · raw message

bitbake/lib/toaster/toastergui/templates/projecttopbar.html +18 -0
index d8f7cbd..8b44acc 100644
@@ -1,3 +1,21 @@
+{% load static %}
+<script src="{% static 'js/projecttopbar.js' %}"></script>
+<script>
+  $(document).ready(function () {
+    var ctx = {
+      numProjectLayers : {{project.get_project_layer_versions.count}},
+      machine : "{{project.get_current_machine_name|default_if_none:""}}",
+    }
+
+    try {
+      projectTopBarInit(ctx);
+    } catch (e) {
+      document.write("Sorry, An error has occurred loading this page");
+      console.warn(e);
+    }
+  });
+</script>
+
 <div class="alert alert-success lead" id="project-created-notification" style="margin-top:15px; display:none">
   <button type="button" class="close" data-dismiss="alert">×</button>
   Your project <strong>{{project.name}}</strong> has been created. You can now <a href="{% url 'projectmachines' project.id %}">select your target machine</a> and <a href="{% url 'projectsoftwarerecipes' project.id %}">choose image recipes</a> to build.
Signature · 1 line
2.5.0
#4 lore raw
In reply to Michael Wood
Quoted 3 lines · Michael Wood

A projects builds should be counted apart from those which are currently in progress.

I've submitted this and the other patches to bitbake-devel (I couldn't find any trace of the cover letter to respond to).

I will add these patches to toaster-next shortly.

Elliot

Quoted 39 lines
---
 bitbake/lib/toaster/orm/models.py | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
bitbake/lib/toaster/orm/models.py +4 -5
index 3832905..0ac94b9 100644
@@ -130,13 +130,12 @@ class Project(models.Model):
         try:
             return self.projectvariable_set.get(name="MACHINE").value
         except (ProjectVariable.DoesNotExist,IndexError):
-            return( "None" );
+            return None;
 
     def get_number_of_builds(self):
-        try:
-            return len(Build.objects.filter( project = self.id ))
-        except (Build.DoesNotExist,IndexError):
-            return( 0 )
+        """Return the number of builds which have ended"""
+
+        return
 self.build_set.filter(~Q(outcome=Build.IN_PROGRESS)).count()
 
     def get_last_build_id(self):

try:
--
2.5.0

--
_______________________________________________
toaster mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/toaster

Signature · 3 lines
Elliot Smith
Software Engineer
Intel Open Source Technology Centre