Add basic front page with shortcuts to web apps

This commit is contained in:
James Valleroy 2016-08-29 22:46:26 -04:00 committed by Sunil Mohan Adapa
parent b69720e0d4
commit 3eb7dd914a
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
11 changed files with 229 additions and 7 deletions

42
plinth/frontpage.py Normal file
View File

@ -0,0 +1,42 @@
#
# This file is part of Plinth.
#
# 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 <http://www.gnu.org/licenses/>.
#
"""
Manage application shortcuts on front page.
"""
shortcuts = {}
def get_shortcuts():
"""Return menu items in sorted order according to current locale."""
return sorted(shortcuts.values(), key=lambda x: x['label'])
def add_shortcut(app, label, url, icon):
"""Add shortcut to front page."""
shortcuts[app] = {
'label': label,
'url': url,
'icon': icon,
}
def remove_shortcut(app):
"""Remove shortcut from front page."""
if app in shortcuts:
del shortcuts[app]

View File

@ -24,6 +24,7 @@ from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import frontpage
from plinth import service as service_module
@ -59,12 +60,20 @@ def init():
managed_services[0], title, ports=['http', 'https'], is_external=True,
is_enabled=is_enabled, enable=enable, disable=disable)
if is_enabled():
add_shortcut()
def setup(helper, old_version=None):
"""Install and configure the module."""
helper.install(managed_packages)
helper.call('post', actions.superuser_run, 'deluge', ['enable'])
helper.call('post', service.notify_enabled, None, True)
helper.call('post', add_shortcut)
def add_shortcut():
frontpage.add_shortcut('deluge', title, '/deluge', 'glyphicon-magnet')
def is_enabled():
@ -76,11 +85,13 @@ def is_enabled():
def enable():
"""Enable the module."""
actions.superuser_run('deluge', ['enable'])
add_shortcut()
def disable():
"""Disable the module."""
actions.superuser_run('deluge', ['disable'])
frontpage.remove_shortcut('deluge')
def diagnose():

View File

@ -24,6 +24,7 @@ from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import frontpage
from plinth import service as service_module
@ -58,12 +59,20 @@ def init():
'ikiwiki', title, ports=['http', 'https'], is_external=True,
is_enabled=is_enabled, enable=enable, disable=disable)
if is_enabled():
add_shortcut()
def setup(helper, old_version=None):
"""Install and configure the module."""
helper.install(managed_packages)
helper.call('post', actions.superuser_run, 'ikiwiki', ['setup'])
helper.call('post', service.notify_enabled, None, True)
helper.call('post', add_shortcut)
def add_shortcut():
frontpage.add_shortcut('ikiwiki', title, '/ikiwiki', 'glyphicon-edit')
def is_enabled():
@ -74,11 +83,13 @@ def is_enabled():
def enable():
"""Enable the module."""
actions.superuser_run('ikiwiki', ['enable'])
add_shortcut()
def disable():
"""Enable the module."""
actions.superuser_run('ikiwiki', ['disable'])
frontpage.remove_shortcut('ikiwiki')
def diagnose():

View File

@ -24,6 +24,7 @@ from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import frontpage
from plinth import service as service_module
@ -70,12 +71,21 @@ def init():
'roundcube', title, ports=['http', 'https'], is_external=True,
is_enabled=is_enabled, enable=enable, disable=disable)
if is_enabled():
add_shortcut()
def setup(helper, old_version=None):
"""Install and configure the module."""
helper.call('pre', actions.superuser_run, 'roundcube', ['pre-install'])
helper.install(managed_packages)
helper.call('post', actions.superuser_run, 'roundcube', ['setup'])
helper.call('post', add_shortcut)
def add_shortcut():
frontpage.add_shortcut(
'roundcube', title, '/roundcube', 'glyphicon-envelope')
def is_enabled():
@ -86,11 +96,13 @@ def is_enabled():
def enable():
"""Enable the module."""
actions.superuser_run('roundcube', ['enable'])
add_shortcut()
def disable():
"""Enable the module."""
actions.superuser_run('roundcube', ['disable'])
frontpage.remove_shortcut('roundcube')
def diagnose():

View File

@ -24,6 +24,7 @@ from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import frontpage
from plinth import service as service_module
@ -57,11 +58,19 @@ def init():
'shaarli', title, ports=['http', 'https'], is_external=True,
is_enabled=is_enabled, enable=enable, disable=disable)
if is_enabled():
add_shortcut()
def setup(helper, old_version=None):
"""Install and configure the module."""
helper.install(managed_packages)
helper.call('post', service.notify_enabled, None, True)
helper.call('post', add_shortcut)
def add_shortcut():
frontpage.add_shortcut('shaarli', title, '/shaarli', 'glyphicon-bookmark')
def is_enabled():
@ -72,8 +81,10 @@ def is_enabled():
def enable():
"""Enable the module."""
actions.superuser_run('shaarli', ['enable'])
add_shortcut()
def disable():
"""Enable the module."""
actions.superuser_run('shaarli', ['disable'])
frontpage.remove_shortcut('shaarli')

View File

@ -25,6 +25,7 @@ import json
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import frontpage
from plinth import service as service_module
@ -58,6 +59,9 @@ def init():
managed_services[0], title, ports=['http', 'https'], is_external=True,
is_enabled=is_enabled, enable=enable, disable=disable)
if is_enabled():
add_shortcut()
def setup(helper, old_version=None):
"""Install and configure the module."""
@ -70,6 +74,12 @@ def setup(helper, old_version=None):
helper.call('post', actions.superuser_run, 'transmission', ['enable'])
helper.call('post', service.notify_enabled, None, True)
helper.call('post', add_shortcut)
def add_shortcut():
frontpage.add_shortcut(
'transmission', title, '/transmission', 'glyphicon-save')
def is_enabled():
@ -81,11 +91,13 @@ def is_enabled():
def enable():
"""Enable the module."""
actions.superuser_run('transmission', ['enable'])
add_shortcut()
def disable():
"""Enable the module."""
actions.superuser_run('transmission', ['disable'])
frontpage.remove_shortcut('transmission')
def diagnose():

View File

@ -24,6 +24,7 @@ from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import frontpage
from plinth import service as service_module
@ -59,6 +60,9 @@ def init():
managed_services[0], title, ports=['http', 'https'], is_external=True,
is_enabled=is_enabled, enable=enable, disable=disable)
if is_enabled():
add_shortcut()
def setup(helper, old_version=None):
"""Install and configure the module."""
@ -66,6 +70,11 @@ def setup(helper, old_version=None):
helper.install(managed_packages)
helper.call('post', actions.superuser_run, 'ttrss', ['setup'])
helper.call('post', service.notify_enabled, None, True)
helper.call('post', add_shortcut)
def add_shortcut():
frontpage.add_shortcut('ttrss', title, '/tt-rss', 'glyphicon-envelope')
def is_enabled():
@ -77,11 +86,13 @@ def is_enabled():
def enable():
"""Enable the module."""
actions.superuser_run('ttrss', ['enable'])
add_shortcut()
def disable():
"""Enable the module."""
actions.superuser_run('ttrss', ['disable'])
frontpage.remove_shortcut('ttrss')
def diagnose():

View File

@ -26,6 +26,7 @@ import socket
from plinth import actions
from plinth import action_utils
from plinth import cfg
from plinth import frontpage
from plinth import service as service_module
from plinth.views import ServiceView
from plinth.signals import pre_hostname_change, post_hostname_change
@ -72,6 +73,9 @@ def init():
post_hostname_change.connect(on_post_hostname_change)
domainname_change.connect(on_domainname_change)
if is_enabled():
add_shortcut()
def setup(helper, old_version=None):
"""Install and configure the module."""
@ -83,6 +87,11 @@ def setup(helper, old_version=None):
helper.install(managed_packages)
helper.call('post', actions.superuser_run, 'xmpp', ['setup'])
helper.call('post', service.notify_enabled, None, True)
helper.call('post', add_shortcut)
def add_shortcut():
frontpage.add_shortcut('xmpp', title, '/jwchat', 'glyphicon-comment')
class EjabberdServiceView(ServiceView):
@ -112,11 +121,13 @@ def get_domainname():
def enable():
"""Enable the module."""
actions.superuser_run('xmpp', ['enable'])
add_shortcut()
def disable():
"""Enable the module."""
actions.superuser_run('xmpp', ['disable'])
frontpage.remove_shortcut('xmpp')
def on_pre_hostname_change(sender, old_hostname, new_hostname, **kwargs):

View File

@ -86,11 +86,13 @@
<span class="icon-bar"></span>
</button>
{% block mainmenu_left %}
<span class="navbar-brand">
<a href="{% url 'index' %}" class="navbar-brand"
title="{{ box_name }}">
<img src="{% static 'theme/img/freedombox-logo-32px.png' %}"
alt="{{ box_name }}" />
</span>
<a href="{% url 'index' %}" class="navbar-brand" title="{% trans "Applications" %}">
</a>
<a href="{% url 'apps:index' %}" class="navbar-brand"
title="{% trans "Applications" %}">
<span class="glyphicon glyphicon-th"></span>
</a>
{% endblock %}

View File

@ -0,0 +1,96 @@
{% extends 'base.html' %}
{% comment %}
#
# This file is part of Plinth.
#
# 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 <http://www.gnu.org/licenses/>.
#
{% endcomment %}
{% load i18n %}
{% block content %}
{% if shortcuts %}
{% for shortcut in shortcuts %}
<div class="col-sm-4">
<ul class="nav nav-pills nav-stacked">
<li>
<a href="{{ shortcut.url }}">
<span class="{{ shortcut.icon }} glyphicon"></span>
{{ shortcut.label }}
</a>
</li>
</ul>
</div>
{% endfor %}
{% else %}
<h4>
{% url 'apps:index' as apps_url %}
{% blocktrans trimmed %}
Enable some <a href="{{ apps_url }}">applications</a> to add
shortcuts to this page.
{% endblocktrans %}
</h4>
{% endif %}
{% endblock %}
{% block sidebar %}
<h4>
{% blocktrans trimmed %}
Welcome to {{ box_name }}!
{% endblocktrans %}
</h4>
<p>
{% blocktrans trimmed %}
{{ box_name }} is a 100% free software self-hosting web server
to deploy social applications on small machines. It provides
online communication tools respecting your privacy and data
ownership.
{% endblocktrans %}
</p>
<p>
{% blocktrans trimmed %}
More info about {{ box_name }} is available on the
project <a href="https://freedombox.org">homepage</a>
and <a href="https://wiki.debian.org/FreedomBox">wiki</a>.
{% endblocktrans %}
</p>
<p>
{% blocktrans trimmed %}
This portal is a part of Plinth, the {{ box_name }} web
interface. Plinth is free software, distributed under the GNU
Affero General Public License, Version 3 or later.
{% endblocktrans %}
</p>
{% endblock %}

View File

@ -21,20 +21,23 @@ Main Plinth views
from django.contrib import messages
from django.core.exceptions import ImproperlyConfigured
from django.http.response import HttpResponseRedirect
from django.template.response import TemplateResponse
from django.views.generic import TemplateView
from django.views.generic.edit import FormView
from django.urls import reverse
from django.utils.translation import ugettext as _
from stronghold.decorators import public
import time
from . import forms
from . import forms, frontpage
import plinth
@public
def index(request):
"""Serve the main index page."""
return HttpResponseRedirect(reverse('apps:index'))
return TemplateResponse(request, 'index.html',
{'title': _('FreedomBox'),
'shortcuts': frontpage.get_shortcuts()})
class ServiceView(FormView):