Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Group minions by rows (draft) #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<cont_id>/start')
Expand Down
33 changes: 33 additions & 0 deletions manifold.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 """

Expand Down
29 changes: 27 additions & 2 deletions static/css/manifold.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
105 changes: 59 additions & 46 deletions templates/containers.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,70 @@
All containers
</a>

<div class="mdl-grid">
{% for minion in minions %}
<div class="mdl-cell mdl-cell--2-col">
<div class="card-composition mdl-card mdl-shadow--2dp">
<div class="mdl-card__title mdl-card--expand" id="composition-descr-{{ minion.container.Id }}">
<h6>{{ minion.container.Image }}</h6>
</div>
<div class="mdl-card__supporting-text">
{{ minion.container.Status }}
</div>
<div class="mdl-tooltip" for="composition-descr-{{ minion.container.Id }}">
<ul>
<li>Names: {{ minion.container.Names }}</li>
<li>Id: {{ minion.container.Id }}</li>
<li>Image: {{ minion.container.Image }}</li>
<li>ImageID: {{ minion.container.ImageID[:12] }}</li>
<li>Status: {{ minion.container.Status }}</li>
<li>Ports: {{ minion.container.Ports }}</li>
<li>Label: {{ minion.container.Label }}</li>
<li>Created: {{ minion.container.Created }}</li>
</ul>
{% for row in rows %}
<div class="mdl-grid">

<div class="mdl-cell mdl-cell--1-col">
<div class="card-row mdl-card mdl-shadow--2dp">
<div class="mdl-card__title mdl-card--expand">
<h6>{{ row.name }}</h6>
</div>
<div class="mdl-card__supporting-text">
Link to GitHub
</div>
</div>
<div class="mdl-card__actions mdl-card--border">
{% if minion.state == 'running' %}
<a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"
href="{{ url_for('pause', cont_id=minion.container.Id) }}">
<i class="material-icons">pause</i>
</a>
<a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"
href="{{ url_for('login', cont_id=minion.container.Id) }}">
<i class="material-icons">launch</i>
</a>
{% elif minion.state == 'paused' %}
</div>
{% for minion in row.minions %}
<div class="mdl-cell mdl-cell--2-col">
<div class="card-composition mdl-card mdl-shadow--2dp">
<div class="mdl-card__title mdl-card--expand" id="composition-descr-{{ minion.container.Id }}">
<h6>{{ minion.container.Image }}</h6>
</div>
<div class="mdl-card__supporting-text">
{{ minion.container.Status }}
</div>
<div class="mdl-tooltip" for="composition-descr-{{ minion.container.Id }}">
<ul>
<li>Names: {{ minion.container.Names }}</li>
<li>Id: {{ minion.container.Id }}</li>
<li>Image: {{ minion.container.Image }}</li>
<li>ImageID: {{ minion.container.ImageID[:12] }}</li>
<li>Status: {{ minion.container.Status }}</li>
<li>Ports: {{ minion.container.Ports }}</li>
<li>Label: {{ minion.container.Label }}</li>
<li>Created: {{ minion.container.Created }}</li>
</ul>
</div>
<div class="mdl-card__actions mdl-card--border">
{% if minion.state == 'running' %}
<a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"
href="{{ url_for('pause', cont_id=minion.container.Id) }}">
<i class="material-icons">pause</i>
</a>
<a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"
href="{{ url_for('login', cont_id=minion.container.Id) }}">
<i class="material-icons">launch</i>
</a>
{% elif minion.state == 'paused' %}
<a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"
href="{{ url_for('unpause', cont_id=minion.container.Id) }}">
<i class="material-icons">play_arrow</i>
</a>
{% else %}
<a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"
href="{{ url_for('start', cont_id=minion.container.Id) }}">
<i class="material-icons">play_arrow</i>
</a>
{% endif %}
<a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"
href="{{ url_for('unpause', cont_id=minion.container.Id) }}">
<i class="material-icons">play_arrow</i>
href="{{ url_for('logs', cont_id=minion.container.Id) }}">
<i class="material-icons">subject</i>
</a>
{% else %}
<a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"
href="{{ url_for('start', cont_id=minion.container.Id) }}">
<i class="material-icons">play_arrow</i>
</a>
{% endif %}
<a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect"
href="{{ url_for('logs', cont_id=minion.container.Id) }}">
<i class="material-icons">subject</i>
</a>
</a>
</div>
</div>
</div>
</div>
{% endfor %}
{% endfor %}
</div>
{% endfor %}
{% endblock %}