From 0454ac51526a4c45188f04cfcbe24ce4586e4b0f Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 9 Dec 2015 13:24:36 +0100 Subject: [PATCH] Group minions by rows (draft) --- app.py | 8 +-- manifold.py | 33 ++++++++++++ static/css/manifold.css | 29 ++++++++++- templates/containers.html | 105 +++++++++++++++++++++----------------- 4 files changed, 123 insertions(+), 52 deletions(-) diff --git a/app.py b/app.py index 430e67d..82dd057 100644 --- a/app.py +++ b/app.py @@ -21,14 +21,14 @@ @app.route('/all') def all_containers(): - minions = manifold.minions(trunc=True, all=True) - return render_template('containers.html', minions=minions) + rows = manifold.rows(trunc=True, all=True) + return render_template('containers.html', rows=rows) @app.route('/') def containers(): - minions = manifold.minions(trunc=True) - return render_template('containers.html', minions=minions) + rows = manifold.rows(trunc=True) + return render_template('containers.html', rows=rows) @app.route('/container//start') diff --git a/manifold.py b/manifold.py index af5350e..7b0b9ea 100644 --- a/manifold.py +++ b/manifold.py @@ -32,6 +32,11 @@ def minion_by_id(self, cont_id): container = self.dock.inspect_container(container=cont_id) return Minion(self, container) + def rows(self, trunc=True, all=False): + minions = self.minions(trunc=trunc, all=all) + rows = BranchRow.rows_from_minions(minions) + return rows + def minions(self, trunc=True, all=False): containers = self.containers(trunc=trunc, all=all) return [Minion(self, container) for container in containers] @@ -63,6 +68,34 @@ def nginx_server_name(self): return r'~^{}\..*$'.format(self.subdomain) +class BranchRow(): + + @classmethod + def rows_from_minions(cls, minions, max_cell=4): + # group by branch + rows = [] + row = [] + to_group = minions[:] + while to_group: + minion = to_group.pop() + row.append(minion) + # Simulate several rows with a max-length (only for test) The real + # implementation will have to group by the docker label 'branch' + # (or pull-request?) and discard containers above max_cell + if len(row) == max_cell: + rows.append(BranchRow(row)) + row = [] + if row: # remaining + rows.append(BranchRow(row)) + return rows + + def __init__(self, minions): + self.minions = minions + self.name = '#1' # name of the branch + self.link = '' # link to the branch + # later, one cell of a row will be a composition + + class Composition(): """ A composition of minions """ diff --git a/static/css/manifold.css b/static/css/manifold.css index 6c9622f..15bac0a 100644 --- a/static/css/manifold.css +++ b/static/css/manifold.css @@ -5,6 +5,7 @@ .card-composition > .mdl-card__title { align-items: flex-start; background: #009688; + color: #fff; } .card-composition > .mdl-card__title > h6 { margin-top: 0; @@ -14,11 +15,35 @@ box-sizing:border-box; align-items: center; } -.card-composition > .mdl-card__title { + +.card-composition > .mdl-card__actions .mdl-button { + min-width: 40px; + padding: 0 8px; +} + +.card-row.mdl-card { + width: 128px; + height: 128px; +} +.card-row > .mdl-card__title { + align-items: flex-start; + background: #009688; + color: #fff; +} +.card-row > .mdl-card__supporting-text { + background: #009688; color: #fff; } +.card-row > .mdl-card__title > h6 { + margin-top: 0; +} +.card-row > .mdl-card__actions { + display: flex; + box-sizing:border-box; + align-items: center; +} -.card-composition > .mdl-card__actions .mdl-button { +.card-row > .mdl-card__actions .mdl-button { min-width: 40px; padding: 0 8px; } diff --git a/templates/containers.html b/templates/containers.html index d5f658a..8a4a6bf 100644 --- a/templates/containers.html +++ b/templates/containers.html @@ -12,57 +12,70 @@ All containers -
-{% for minion in minions %} -
-
-
-
{{ minion.container.Image }}
-
-
- {{ minion.container.Status }} -
-
-
    -
  • Names: {{ minion.container.Names }}
  • -
  • Id: {{ minion.container.Id }}
  • -
  • Image: {{ minion.container.Image }}
  • -
  • ImageID: {{ minion.container.ImageID[:12] }}
  • -
  • Status: {{ minion.container.Status }}
  • -
  • Ports: {{ minion.container.Ports }}
  • -
  • Label: {{ minion.container.Label }}
  • -
  • Created: {{ minion.container.Created }}
  • -
+{% for row in rows %} +
+ +
+
+
+
{{ row.name }}
+
+
+ Link to GitHub +
-
- {% if minion.state == 'running' %} - - pause - - - launch - - {% elif minion.state == 'paused' %} +
+ {% for minion in row.minions %} +
+
+
+
{{ minion.container.Image }}
+
+
+ {{ minion.container.Status }} +
+
+
    +
  • Names: {{ minion.container.Names }}
  • +
  • Id: {{ minion.container.Id }}
  • +
  • Image: {{ minion.container.Image }}
  • +
  • ImageID: {{ minion.container.ImageID[:12] }}
  • +
  • Status: {{ minion.container.Status }}
  • +
  • Ports: {{ minion.container.Ports }}
  • +
  • Label: {{ minion.container.Label }}
  • +
  • Created: {{ minion.container.Created }}
  • +
+
+
+ {% if minion.state == 'running' %} + + pause + + + launch + + {% elif minion.state == 'paused' %} + + play_arrow + + {% else %} + + play_arrow + + {% endif %} - play_arrow + href="{{ url_for('logs', cont_id=minion.container.Id) }}"> + subject - {% else %} - - play_arrow - {% endif %} - - subject - - +
-
-{% endfor %} + {% endfor %}
+{% endfor %} {% endblock %}