diff --git a/plinth/templates/app.html b/plinth/templates/app.html index e50f3f12b..ea43a9989 100644 --- a/plinth/templates/app.html +++ b/plinth/templates/app.html @@ -57,21 +57,7 @@

{% endif %} - {% if clients|length == 1 %} - {% with clients|first|lookup:'platforms' as platforms %} - {% if platforms|length == 1 and platforms|first|lookup:'type' == 'web' %} - {% block launch_button %} -

- - {% trans "Launch web client" %} -

- {% endblock %} - {% endif %} - {% endwith %} - {% else %} - {% include "clients.html" with clients=clients enabled=is_enabled %} - {% endif %} + {% include "toolbar.html" with clients=clients enabled=is_enabled diagnostics_module_name=diagnostics_module_name %} {% block subsubmenu %} {% if subsubmenu %} @@ -100,12 +86,6 @@ {% endif %} {% endblock %} - {% block diagnostics %} - {% if diagnostics_module_name %} - {% include "diagnostics_button.html" with module=diagnostics_module_name enabled=is_enabled %} - {% endif %} - {% endblock %} - {% include "internal-zone.html" %} {% include "port-forwarding-info.html" with service_name=name %} diff --git a/plinth/templates/clients.html b/plinth/templates/clients.html index bd84a01c0..7ac5636dd 100644 --- a/plinth/templates/clients.html +++ b/plinth/templates/clients.html @@ -22,14 +22,6 @@ {% load static %} {% if clients %} -

- -

-
@@ -44,7 +36,7 @@
{{ client.name }} diff --git a/plinth/templates/setup.html b/plinth/templates/setup.html index 60bf8c64e..a79d3f414 100644 --- a/plinth/templates/setup.html +++ b/plinth/templates/setup.html @@ -50,7 +50,7 @@

{% endif %} - {% include "clients.html" with clients=setup_helper.module.clients %} + {% include "toolbar.html" with clients=setup_helper.module.clients %} {% if setup_state == 'up-to-date' %} diff --git a/plinth/templates/toolbar.html b/plinth/templates/toolbar.html new file mode 100644 index 000000000..de5cc556e --- /dev/null +++ b/plinth/templates/toolbar.html @@ -0,0 +1,96 @@ +{% comment %} +# +# This file is part of FreedomBox. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +{% endcomment %} + +{% load bootstrap %} +{% load i18n %} +{% load plinth_extras %} +{% load static %} + +{% block toolbar %} + {% if clients %} +
+
+
+ + {% if clients|get_self_hosted_web_apps|length == 1 and clients|length == 1 %} + + + + + + {% elif clients|get_self_hosted_web_apps|length == 1 %} + + + + + {% else %} + + {% endif %} + + {% block diagnostics %} + {% if diagnostics_module_name %} + {% include "diagnostics_button.html" with module=diagnostics_module_name enabled=is_enabled %} + {% endif %} + {% endblock %} + +
+
+
+ {% include "clients.html" with clients=clients enabled=is_enabled %} +
+
+ + {% endif %} +{% endblock toolbar %} \ No newline at end of file diff --git a/plinth/templatetags/plinth_extras.py b/plinth/templatetags/plinth_extras.py index 541429b9c..2a0047d06 100644 --- a/plinth/templatetags/plinth_extras.py +++ b/plinth/templatetags/plinth_extras.py @@ -16,6 +16,7 @@ # import os +from urllib.parse import urlparse from django import template @@ -73,3 +74,32 @@ def clients_of_type(clients, client_type): def lookup(dictionary, key): """Get the value in the dictionary at given key""" return dictionary[key] + + +@register.filter(name='is_relative_url') +def is_relative_url(url): + """Check if the given link is relative or not""" + parsed_url = urlparse(url) + return not parsed_url.netloc + + +@register.filter(name='get_self_hosted_web_apps') +def get_self_hosted_web_apps(clients): + """Get a list of self hosted web apps""" + clients_with_web_platforms = list( + filter( + lambda c: len( + list(filter(lambda p: p['type'] == 'web', c['platforms']))), + clients)) + clients_with_self_hosted_apps = list( + filter( + lambda c: len( + list( + filter(lambda p: is_relative_url(p['url']), c['platforms']) + )), clients_with_web_platforms)) + mapped_list = list( + map( + lambda c: list(filter(lambda p: p['type'] == 'web', c['platforms']) + ), clients_with_self_hosted_apps)) + + return [elm for clnt in mapped_list for elm in clnt] diff --git a/static/themes/default/css/plinth.css b/static/themes/default/css/plinth.css index 60a71d872..c5e8bc166 100644 --- a/static/themes/default/css/plinth.css +++ b/static/themes/default/css/plinth.css @@ -513,3 +513,25 @@ a.menu_link_active { .header-bar .app-toggle-container, .header-bar h2 { margin: auto 0; } +.toolbar, .panel-heading { + border: none; +} + +.toolbar-heading { + padding: 10px 0; +} + +.toolbar-title > :not(:first-child) { + margin-left: 10px; +} + +.toolbar-body { + min-height: 0; + padding: 0; + margin: 0; + overflow: auto; +} + +.toolbar-body #clients.table { + margin-bottom: 0; +}