Skip to contentSkip to conversation

toaster: hide other projects while in analysis mode

PATCH New brian avery 1 participant 7 messages Oct 17, 2015

lore
Share & tools
lore
#0 lore raw

cover toaster: hide other projects while in analysis mode

The UI currently shows all the navigation elements in both analysis and build modes, even if they are irrelevant or broken.

As a temporary measure (until we merge the two modes), hide most of the navigation and UI elements when in analysis mode, so the user only gets to see the command-line builds project.

-b

The following changes since commit 049d42197c7096e2e8389cc136777770cda0e792:

toaster: add get_or_create_targets API (2015-10-16 09:57:43 -0700)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib bavery/submit/elliot/2015-10-16_hide-proj-analysis-mode
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=bavery/submit/elliot/2015-10-16_hide-proj-analysis-mode

Elliot Smith (6):
toaster: Add BUILD_MODE flag to context
toaster: Show mode-appropriate landing page
toaster: Hide top bar buttons in analysis mode
toaster: Hide builds for non-cli projects in analysis mode
toaster: Run tests in build mode
toaster: Remove all navigation when not in build mode

 lib/toaster/toastergui/templates/base.html    |  22 ++++--
 lib/toaster/toastergui/templates/landing.html | 103 +++++++++++++++-----------
 lib/toaster/toastergui/tests.py               |   6 ++
 lib/toaster/toastergui/views.py               |  36 +++++++--
 lib/toaster/toastermain/settings.py           |   6 +-
 lib/toaster/toastermain/urls.py               |   2 +-
 6 files changed, 113 insertions(+), 62 deletions(-)

--
1.9.1

#1 lore raw

PATCH 1/6 toaster: Add BUILD_MODE flag to context

From: Elliot Smith <[email protected]>

We set a TOASTER_MANAGED env variable in the startup script, which has a value of "1" if Toaster should run in build mode.

Add a BUILD_MODE variable to settings.py which is True if TOASTER_MANAGED is set to "1", False otherwise.

Add this to the context for every template, so we can use this information to conditionally alter the content of pages according to the mode we're in.

[YOCTO #8514]

---
 lib/toaster/toastergui/views.py     | 4 ++++
 lib/toaster/toastermain/settings.py | 6 ++----
 lib/toaster/toastermain/urls.py     | 2 +-
 3 files changed, 7 insertions(+), 5 deletions(-)
lib/toaster/toastergui/views.py +4 -0
index e2f2874..10bbef5 100755
@@ -1880,6 +1880,10 @@ def managedcontextprocessor(request):
         "projects": projects,
         "non_cli_projects": projects.exclude(is_default=True),
         "DEBUG" : toastermain.settings.DEBUG,
+
+        # True if Toaster is in build mode, False otherwise
+        "BUILD_MODE": toastermain.settings.BUILD_MODE,
+
         "CUSTOM_IMAGE" : toastermain.settings.CUSTOM_IMAGE,
         "TOASTER_BRANCH": toastermain.settings.TOASTER_BRANCH,
         "TOASTER_REVISION" : toastermain.settings.TOASTER_REVISION,
lib/toaster/toastermain/settings.py +2 -4
index 6439d68..b28ddb2 100644
@@ -92,11 +92,9 @@ if 'DATABASE_URL' in os.environ:
     else:
         raise Exception("FIXME: Please implement missing database url schema for url: %s" % dburl)
 
-
+BUILD_MODE = False
 if 'TOASTER_MANAGED' in os.environ and os.environ['TOASTER_MANAGED'] == "1":
-    MANAGED = True
-else:
-    MANAGED = False
+    BUILD_MODE = True
 
 # Allows current database settings to be exported as a DATABASE_URL environment variable value
 
lib/toaster/toastermain/urls.py +1 -1
index 521588a..6c4a953 100644
@@ -60,7 +60,7 @@ if toastermain.settings.DEBUG_PANEL_ENABLED:
     #logger.info("Enabled django_toolbar extension")
 
 
-if toastermain.settings.MANAGED:
+if toastermain.settings.BUILD_MODE:
     urlpatterns = [
         # Uncomment the next line to enable the admin:
         url(r'^admin/', include(admin.site.urls)),
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/6 toaster: Show mode-appropriate landing page

From: Elliot Smith <[email protected]>

The same landing page is shown for both analysis and build modes. This means that users in analysis mode can see options which are not available or broken in that mode.

Modify the landing page template to show a simple "run a build" message if the user is in analysis mode and has no builds yet.

Also clean up the landing page HTML, because the indentation was a mess and the HTML was invalid.

[YOCTO #8514]

---
 lib/toaster/toastergui/templates/landing.html | 103 +++++++++++++++-----------
 1 file changed, 58 insertions(+), 45 deletions(-)
lib/toaster/toastergui/templates/landing.html +58 -45
index 45e9532..65d8c3c 100644
@@ -6,53 +6,66 @@
 
 {% block pagecontent %}
 
-  <div class="container-fluid">
-   <div class="row-fluid">
-    <!-- Empty - no data in database -->
-    <div class="hero-unit span12 well-transparent">
-     <div class="row-fluid">
-      <div class="span6">
-       <h1>
-        This is Toaster
-       </h1>
-       <p>A web interface to <a href="http://www.openembedded.org">OpenEmbedded</a> and <a href="http://www.yoctoproject.org/tools-resources/projects/bitbake">BitBake</a>, the <a href="http://www.yoctoproject.org">Yocto Project</a> build system.</p>
-
-
-		{% if lvs_nos %}
-		    <p class="hero-actions">
-			    <a class="btn btn-primary btn-large" href="{% url 'newproject' %}">
-				    To start building, create your first Toaster project
-			    </a>
-		    </p>
-		{% else %}
-		    <div class="alert alert-info lead air">
-			    Toaster has no layer information. Without layer information, you cannot run builds. To generate layer information you can:
-			    <ul>
-			        <li>
-			            <a href="http://www.yoctoproject.org/docs/latest/toaster-manual/toaster-manual.html#layer-source">Configure a layer source</a>
-			        </li>
-			        <li>
-			            <a href="{% url 'newproject' %}">Create a project</a>, then import layers
-			        </li>
-			    </ul>
-		    </div>
-	        {% endif %}
-
-        <ul class="unstyled">
-            <li>
-                <a href="http://www.yoctoproject.org/docs/latest/toaster-manual/toaster-manual.html">Read the Toaster manual</a>
-            </li>
-            <li>
-                <a href="https://wiki.yoctoproject.org/wiki/Contribute_to_Toaster">Contribute to Toaster</a>
-            </li>
-        </ul>
+  {% if BUILD_MODE %}
+    <!-- build mode -->
+    <div class="container-fluid">
+      <div class="row-fluid">
+        <div class="hero-unit span12 well-transparent">
+          <div class="row-fluid">
 
+            <div class="span6">
+              <h1>This is Toaster</h1>
+
+              <p>A web interface to <a href="http://www.openembedded.org">OpenEmbedded</a> and <a href="http://www.yoctoproject.org/tools-resources/projects/bitbake">BitBake</a>, the <a href="http://www.yoctoproject.org">Yocto Project</a> build system.</p>
+
+		          {% if lvs_nos %}
+		            <p class="hero-actions">
+		              <a class="btn btn-primary btn-large" href="{% url 'newproject' %}">
+			              To start building, create your first Toaster project
+		              </a>
+		            </p>
+		          {% else %}
+                <div class="alert alert-info lead air">
+                  Toaster has no layer information. Without layer information, you cannot run builds. To generate layer information you can:
+                  <ul>
+                    <li>
+                      <a href="http://www.yoctoproject.org/docs/latest/toaster-manual/toaster-manual.html#layer-source">Configure a layer source</a>
+                    </li>
+                    <li>
+			                <a href="{% url 'newproject' %}">Create a project</a>, then import layers
+                    </li>
+                  </ul>
+                </div>
+              {% endif %}
+
+              <ul class="unstyled">
+                <li>
+                  <a href="http://www.yoctoproject.org/docs/latest/toaster-manual/toaster-manual.html">
+                    Read the Toaster manual
+                  </a>
+                </li>
+
+                <li>
+                  <a href="https://wiki.yoctoproject.org/wiki/Contribute_to_Toaster">
+                    Contribute to Toaster
+                  </a>
+                </li>
+              </ul>
+            </div>
+
+            <div class="span6">
+              <img alt="Yocto Project" class="thumbnail" src="{% static 'img/toaster_bw.png' %}"/>
+            </div>
+
+          </div>
+        </div>
       </div>
-      <div class="span6">
-          <img alt="Yocto Project" class="thumbnail" src="{% static 'img/toaster_bw.png' %}"/>
-      </div>
-     </div>
     </div>
-   </div>
+  {% else %}
+    <!-- analysis mode -->
+    <div class="alert alert-info lead top-air">
+      Toaster has not recorded any builds yet. Run a build from the command line to see it here.
+    </div>
+  {% endif %}
 
 {% endblock %}
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/6 toaster: Hide top bar buttons in analysis mode

In reply to brian avery

From: Elliot Smith <[email protected]>

The "new build" and "new project" buttons are irrelevant in analysis mode, as you can't start a build or a project.

Hide these buttons if not in BUILD_MODE.

[YOCTO #8514]

---
 lib/toaster/toastergui/templates/base.html | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
lib/toaster/toastergui/templates/base.html +13 -5
index c1d0693..073c342 100644
@@ -120,11 +120,19 @@
             </li>
           </ul>
           <span class="pull-right divider-vertical"></span>
-          <div class="btn-group pull-right">
-            <a class="btn" id="new-project-button" href="{% url 'newproject' %}">New project</a>
-          </div>
-          <!-- New build popover; only shown if there is at least one user-created project -->
-          {% if non_cli_projects.count > 0 %}
+
+          <!-- new project button; only show in build mode -->
+          {% if BUILD_MODE %}
+            <div class="btn-group pull-right">
+              <a class="btn" id="new-project-button" href="{% url 'newproject' %}">New project</a>
+            </div>
+          {% endif %}
+
+          <!--
+          New build popover; only shown if there is at least one user-created project
+          and we're in build mode
+          -->
+          {% if BUILD_MODE and non_cli_projects.count > 0 %}
             <div class="btn-group pull-right" id="new-build-button" style="display:none">
               <button class="btn dropdown-toggle" data-toggle="dropdown">
                 New build
Signature · 1 line
1.9.1
#4 lore raw

PATCH 4/6 toaster: Hide builds for non-cli projects in analysis mode

In reply to brian avery

From: Elliot Smith <[email protected]>

The "latest builds" sections of the "all builds" page show builds for all projects. This is not appropriate for analysis mode, where we can only affect the command-line builds project.

Modify the "latest builds" section to only show builds for the command line builds project if in analysis mode.

Also rationalise where we get the queryset of latest builds from:
we have a _get_latest_builds() function which was being used to get the latest builds in most places, but not all.

Also modify _get_latest_builds() to sort by started_on, rather than primary key, as assuming that a higher primary key value equates with later start time is incorrect.

[YOCTO #8514]

---
 lib/toaster/toastergui/views.py | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
lib/toaster/toastergui/views.py +15 -3
index 10bbef5..d675f4f 100755
@@ -92,9 +92,12 @@ def _get_latest_builds(prj=None):
     if prj is not None:
         queryset = queryset.filter(project = prj)
 
+    if not toastermain.settings.BUILD_MODE:
+        queryset = queryset.exclude(project__is_default=False)
+
     return list(itertools.chain(
-        queryset.filter(outcome=Build.IN_PROGRESS).order_by("-pk"),
-        queryset.filter(outcome__lt=Build.IN_PROGRESS).order_by("-pk")[:3] ))
+        queryset.filter(outcome=Build.IN_PROGRESS).order_by("-started_on"),
+        queryset.filter(outcome__lt=Build.IN_PROGRESS).order_by("-started_on")[:3] ))
 
 
 # a JSON-able dict of recent builds; for use in the Project page, xhr_ updates,  and other places, as needed
@@ -1926,6 +1929,11 @@ if True:
 
         queryset = Build.objects.all()
 
+        # if in analysis mode, exclude builds for all projects except
+        # command line builds
+        if not toastermain.settings.BUILD_MODE:
+            queryset = queryset.exclude(project__is_default=False)
+
         redirect_page = resolve(request.path_info).url_name
 
         context, pagesize, orderby = _build_list_helper(request,
@@ -2000,7 +2008,7 @@ if True:
         build_info = _build_page_range(Paginator(queryset, pagesize), request.GET.get('page', 1))
 
         # build view-specific information; this is rendered specifically in the builds page, at the top of the page (i.e. Recent builds)
-        build_mru = Build.objects.order_by("-started_on")[:3]
+        build_mru = _get_latest_builds()[:3]
 
         # calculate the exact begining of local today and yesterday, append context
         context_date,today_begin,yesterday_begin = _add_daterange_context(queryset_all, request, {'started_on','completed_on'})
@@ -3030,6 +3038,10 @@ if True:
         queryset_all = queryset_all.filter(Q(is_default=False) |
                                            q_default_with_builds)
 
+        # if in BUILD_MODE, exclude everything but the command line builds project
+        if not toastermain.settings.BUILD_MODE:
+            queryset_all = queryset_all.exclude(is_default=False)
+
         # boilerplate code that takes a request for an object type and returns a queryset
         # for that object type. copypasta for all needed table searches
         (filter_string, search_term, ordering_string) = _search_tuple(request, Project)
Signature · 1 line
1.9.1
#5 lore raw

PATCH 5/6 toaster: Run tests in build mode

In reply to brian avery

From: Elliot Smith <[email protected]>

Now that the UI content is conditional on whether BUILD_MODE is active, modify the existing tests so that they run in this mode by default.

[YOCTO #8514]

---
 lib/toaster/toastergui/tests.py | 6 ++++++
 1 file changed, 6 insertions(+)
lib/toaster/toastergui/tests.py +6 -0
index 29dd7fd..9e6c46a 100644
@@ -32,6 +32,8 @@ from orm.models import Layer_Version, Recipe, Machine, ProjectLayer, Target
 from orm.models import CustomImageRecipe, ProjectVariable
 from orm.models import Branch
 
+import toastermain
+
 from toastergui.tables import SoftwareRecipesTable
 import json
 from bs4 import BeautifulSoup
@@ -40,6 +42,10 @@ import re
 PROJECT_NAME = "test project"
 CLI_BUILDS_PROJECT_NAME = 'Command line builds'
 
+# by default, tests are run in build mode; to run in analysis mode,
+# set this to False in individual test cases
+toastermain.settings.BUILD_MODE = True
+
 class ViewTests(TestCase):
     """Tests to verify view APIs."""
 
Signature · 1 line
1.9.1
#6 lore raw

PATCH 6/6 toaster: Remove all navigation when not in build mode

In reply to brian avery

From: Elliot Smith <[email protected]>

The user is redirected to the all builds page or all projects page from the landing page, regardless of mode.

In build mode, this makes sense; but in analysis mode, we are restricting the view to just the cli builds project. This means that "all projects" and "all builds" only contains items relating to this one project.

Modify the landing page so it redirects to the project builds page for the cli builds project when not in build mode. Also remove navigation elements which are irrelevant when not in build mode.

[YOCTO #8514]

---
 lib/toaster/toastergui/templates/base.html |  4 ++--
 lib/toaster/toastergui/views.py            | 14 ++++++++++++--
 2 files changed, 14 insertions(+), 4 deletions(-)
lib/toaster/toastergui/templates/base.html +2 -2
index 073c342..dfa6bba 100644
@@ -91,9 +91,9 @@
             <i class="icon-info-sign" title="<strong>Toaster version information</strong>" data-content="<dl><dt>Branch</dt><dd>{{TOASTER_BRANCH}}</dd><dt>Revision</dt><dd>{{TOASTER_REVISION}}</dd></dl>"></i>
             {% endif %}
           </span>
-          {% if request.resolver_match.url_name != 'landing' and request.resolver_match.url_name != 'newproject' %}
+          {% if BUILD_MODE and request.resolver_match.url_name != 'landing' and request.resolver_match.url_name != 'newproject' %}
           <ul class="nav">
-            <li  {% if request.resolver_match.url_name == 'all-builds' %}
+            <li {% if request.resolver_match.url_name == 'all-builds' %}
                 class="active"
                 {% endif %}>
               <a href="{% url 'all-builds' %}">
lib/toaster/toastergui/views.py +12 -2
index d675f4f..6ebb6a9 100755
@@ -71,14 +71,24 @@ class MimeTypeFinder(object):
 # all new sessions should come through the landing page;
 # determine in which mode we are running in, and redirect appropriately
 def landing(request):
+    # in build mode, we redirect to the command-line builds page
+    # if there are any builds for the default (cli builds) project
+    default_project = Project.objects.get_default_project()
+    default_project_builds = Build.objects.filter(project = default_project)
+
+    if (not toastermain.settings.BUILD_MODE) and default_project_builds.count() > 0:
+        args = (default_project.id,)
+        return redirect(reverse('projectbuilds', args = args), permanent = False)
+
     # we only redirect to projects page if there is a user-generated project
+    num_builds = Build.objects.all().count()
     user_projects = Project.objects.filter(is_default = False)
     has_user_project = user_projects.count() > 0
 
-    if Build.objects.count() == 0 and has_user_project:
+    if num_builds == 0 and has_user_project:
         return redirect(reverse('all-projects'), permanent = False)
 
-    if Build.objects.all().count() > 0:
+    if num_builds > 0:
         return redirect(reverse('all-builds'), permanent = False)
 
     context = {'lvs_nos' : Layer_Version.objects.all().count()}
Signature · 1 line
1.9.1