Projet

Général

Profil

0001-turn-home-page-into-a-list-of-services-status-26761.patch

Frédéric Péters, 30 septembre 2018 19:27

Télécharger (5,69 ko)

Voir les différences:

Subject: [PATCH] turn home page into a list of services + status (#26761)

 hobo/static/css/style.css     | 58 ++++++++++++++++++++++++++++
 hobo/templates/hobo/home.html | 73 +++++++++++++++++++++++++++++++----
 hobo/views.py                 |  7 +++-
 3 files changed, 129 insertions(+), 9 deletions(-)
hobo/static/css/style.css
154 154
div.buttons {
155 155
	margin: 1em 0;
156 156
}
157

  
158
div#services > div {
159
	box-sizing: border-box;
160
	border: 1px solid #ccc;
161
	border-width: 1px 1px 1px 10px;
162
	margin-bottom: 1rem;
163
	width: 49%;
164
	padding: 0 1ex;
165
}
166

  
167
div#services > div h3 {
168
	margin-top: 0.5rem;
169
}
170

  
171
div#services > div h3 a {
172
	font-size: 80%;
173
	font-weight: normal;
174
}
175

  
176
div#services > div:nth-child(2n+1) {
177
	float: left;
178
}
179

  
180
div#services > div:nth-child(2n) {
181
	float: right;
182
}
183

  
184
div#services > div.op-ok {
185
	border-color: #00b000;
186
}
187

  
188
div#services > div.op-nok {
189
	border-color: #b00000;
190
}
191

  
192
div#services p {
193
	margin-bottom: 0.5rem;
194
}
195

  
196
div#services span.op-ok::before {
197
	font-family: FontAwesome;
198
	content: "\f058";  /* check-circle */
199
	display: inline-block;
200
	width: 1.5rem;
201
	color: #00b000;
202
}
203

  
204
div#services span.op-nok::before {
205
	font-family: FontAwesome;
206
	content: "\f057";  /* times-circle */
207
	display: inline-block;
208
	width: 1.5rem;
209
	color: #b00000;
210
}
211

  
212
div#services span {
213
	margin-right: 1rem;
214
}
hobo/templates/hobo/home.html
2 2
{% load i18n %}
3 3

  
4 4
{% block appbar %}
5
  <h2>{% trans 'Welcome' %}</h2>
5
  <h2>{% trans 'System' %}</h2>
6
  <span class="actions">
7
  <a class="extra-actions-menu-opener"></a>
8
  <ul class="extra-actions-menu">
9
    <li><a href="{% url 'profile-home' %}">{% trans 'User Profile' %}</a></li>
10
    <li><a href="{% url 'theme-home' %}">{% trans 'Theme' %}</a></li>
11
    <li><a href="{% url 'emails-home' %}">{% trans 'Emails' %}</a></li>
12
    <li><a href="{% url 'environment-home' %}">{% trans 'Services' %}</a></li>
13
    <li><a href="{% url 'environment-variables' %}">{% trans 'Variables' %}</a></li>
14
  </ul>
15
  </span>
6 16
{% endblock %}
7 17

  
8 18
{% block content %}
9 19

  
10
<ul class="apps">
11
  <li class="icon-users"><a href="{% url 'profile-home' %}">{% trans 'User Profile' %}</a></li>
12
  <li class="icon-theme"><a href="{% url 'theme-home' %}">{% trans 'Theme' %}</a></li>
13
  <li class="icon-mail"><a href="{% url 'emails-home' %}">{% trans 'Emails' %}</a></li>
14
  <li class="icon-portal"><a href="{% url 'environment-home' %}">{% trans 'Sites' %}</a></li>
15
  <li class="icon-settings"><a href="{% url 'environment-variables' %}">{% trans 'Variables' %}</a></li>
16
</ul>
20
<div id="services">
21
{% for service in services %}
22
  <div class="service-{{ service.Extra.service_id }}"
23
       data-service-slug="{{ service.slug }}">
24
    <h3>{{ service.title }} <a href="{{ service.base_url }}">{{ service.base_url }}</a></h3>
25
    <p>
26
      <span class="checking">{% trans "checking..." %}</span>
27
      <span style="display: none" class="dns">{% trans "DNS" %}</span>
28
      <span style="display: none" class="certificate">{% trans "Certificate" %}</span>
29
      <span style="display: none" class="web">{% trans "Web" %}</span>
30
    </p>
31
  </div>
32
{% endfor %}
33
</div>
34

  
35
<script>
36
$(function() {
37
  $.ajax({
38
    url: '/api/health/',
39
    success: function(data, status) {
40
      $(data).each(function(idx, service) {
41
        var $service_block = $('div[data-service-slug="' + service.slug + '"]');
42
        var ok = true;
43
        if (service.is_resolvable) {
44
          $service_block.find('.dns').addClass('op-ok');
45
        } else {
46
          $service_block.find('.dns').addClass('op-nok');
47
          ok = false;
48
        }
49
        if (service.has_valid_certificate) {
50
          $service_block.find('.certificate').addClass('op-ok');
51
        } else {
52
          $service_block.find('.certificate').addClass('op-nok');
53
          ok = false;
54
        }
55
        if (service.is_running) {
56
          $service_block.find('.web').addClass('op-ok');
57
        } else {
58
          $service_block.find('.web').addClass('op-nok');
59
          ok = false;
60
        }
61
        var $service_p = $service_block.find('span.checking')
62
        $service_block.find('span').show();
63
        $service_p.hide();
64
        if (ok) {
65
          $service_block.addClass('op-ok');
66
        } else {
67
          $service_block.addClass('op-nok');
68
        }
69
      });
70
    }
71
  });
72
});
73
</script>
17 74

  
18 75
{% endblock %}
hobo/views.py
15 15
from django.utils.encoding import force_text
16 16

  
17 17
from .environment.models import Authentic
18
from .environment.utils import Zone, get_operational_services
18
from .environment.utils import Zone, get_installed_services
19 19
from .forms import HoboForm, HoboUpdateForm, get_tenant_model
20 20

  
21 21
def is_superuser(u):
......
30 30
class Home(TemplateView):
31 31
    template_name = 'hobo/home.html'
32 32

  
33
    def get_context_data(self, **kwargs):
34
        context = super(Home, self).get_context_data(**kwargs)
35
        context['services'] = [x for x in get_installed_services() if not x.secondary]
36
        return context
37

  
33 38
home = admin_required(Home.as_view())
34 39

  
35 40
class ManagerHome(edit.CreateView):
36
-