Add night mode (#890)

* Split base template menus out

* Add toggle for night mode setting

* Add vertical flexbox row

Makes each col-* expand to fill the space created by the largest column.

* Use flexbox on main character and group panels

* Fix data table sort control clipping

* Build new css
This commit is contained in:
Basraah 2017-10-05 14:32:58 +10:00 committed by GitHub
parent 111105d48b
commit e5d76cbce8
18 changed files with 291 additions and 108 deletions

View File

@ -7,9 +7,9 @@
{% block content %}
<h1 class="page-header text-center">{% trans "Dashboard" %}</h1>
<div class="col-sm-12">
<div class="row">
<div class="row vertical-flexbox-row">
<div class="col-sm-6 text-center">
<div class="panel panel-primary">
<div class="panel panel-primary" style="height:100%">
<div class="panel-heading"><h3 class="panel-title">{% trans "Main Character" %}</h3></div>
<div class="panel-body">
{% if request.user.profile.main_character %}
@ -69,10 +69,10 @@
</div>
</div>
<div class="col-sm-6 text-center">
<div class="panel panel-success">
<div class="panel panel-success" style="height:100%">
<div class="panel-heading"><h3 class="panel-title">{% trans "Groups" %}</h3></div>
<div class="panel-body">
<div style="height: 236px;overflow:-moz-scrollbars-vertical;overflow-y:auto;">
<div style="height: 240px;overflow:-moz-scrollbars-vertical;overflow-y:auto;">
<table class="table table-striped">
{% for group in user.groups.all %}
<tr>

View File

@ -1,7 +1,9 @@
from django.conf import settings
from .views import NightModeRedirectView
def auth_settings(request):
return {
'SITE_NAME': settings.SITE_NAME,
'NIGHT_MODE': NightModeRedirectView.night_mode_state(request),
}

View File

@ -49,7 +49,7 @@
<table class="table table-hover" id="table-mains">
<thead>
<tr>
<th></th>
<th style="height:1em;"><!-- Must have text or height to prevent clipping --></th>
<th></th>
</tr>
</thead>

View File

@ -0,0 +1,10 @@
// Import the fonts from CDN
@font-face {
font-family: 'Glyphicons Halflings';
src: url('https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/fonts/glyphicons-halflings-regular.eot');
src: url('https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
url('https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/fonts/glyphicons-halflings-regular.woff2') format('woff2'),
url('https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/fonts/glyphicons-halflings-regular.woff') format('woff'),
url('https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/fonts/glyphicons-halflings-regular.ttf') format('truetype'),
url('https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.3.7/fonts/glyphicons-halflings-regular.svg#@{icon-font-svg-id}') format('svg');
}

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2013 Thomas Park
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,9 @@
// Alliance Auth customisations of the bootswatch Darkly theme
// To build a new CSS file you need to `npm install -g less less-plugin-clean-css`
// Then `lessc --clean-css darkly.less darkly.min.css`
@import "https://raw.githubusercontent.com/thomaspark/bootswatch/gh-pages/bower_components/bootstrap/less/bootstrap.less";
@import "https://raw.githubusercontent.com/thomaspark/bootswatch/gh-pages/darkly/variables.less";
@import "https://raw.githubusercontent.com/thomaspark/bootswatch/gh-pages/darkly/bootswatch.less";
@import "../bootstrap-locals.less";
@import "../flatly-shared.less";

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,31 @@
// Shared variables between flatly and darkly themes
// Fade down table row colors to prevent them looking like a bag of skittles
@table-bg-fade-percent: 20%;
.table-row-variant(active; fade(@table-bg-active, @table-bg-fade-percent));
.table-row-variant(success; fade(@state-success-bg, @table-bg-fade-percent));
.table-row-variant(info; fade(@state-info-bg, @table-bg-fade-percent));
.table-row-variant(warning; fade(@state-warning-bg, @table-bg-fade-percent));
.table-row-variant(danger; fade(@state-danger-bg, @table-bg-fade-percent));
// From bootswatch Superhero
@brand-success: #5cb85c;
@brand-warning: #f0ad4e;
@brand-danger: #d9534f;
// Bootstrap extension, allow vertical columns to be same height
.row.vertical-flexbox-row {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
}
.row.vertical-flexbox-row > [class*='col-'] {
display: flex;
flex-direction: column;
}

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2013 Thomas Park
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,35 @@
// Alliance Auth customisations of the bootswatch Flatly theme
// To build a new CSS file you need to `npm install -g less less-plugin-clean-css`
// Then `lessc --clean-css flatly.less flatly.min.css`
@import "https://raw.githubusercontent.com/thomaspark/bootswatch/gh-pages/bower_components/bootstrap/less/bootstrap.less";
@import "https://raw.githubusercontent.com/thomaspark/bootswatch/gh-pages/flatly/variables.less";
@import "https://raw.githubusercontent.com/thomaspark/bootswatch/gh-pages/flatly/bootswatch.less";
@import "../bootstrap-locals.less";
@import "../flatly-shared.less";
.nav-tabs > li > a,
.nav-pills > li > a {
color: #000;
}
// From bootswatch Superhero
@brand-info: #5bc0de;
@table-bg-fade-percent: 40%;
// Fixup table colors to match fade
.table {
.active,
.success,
.info,
.warning,
.danger {
color: @gray-darker;
> td {
> a:not(.btn) {
color: @link-color;
}
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -1,12 +1,9 @@
{% load static %}
{% load i18n %}
{% load navactive %}
{% load menu_items %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
@ -21,103 +18,13 @@
<link href="{% static 'css/auth-base.css' %}" type="text/css" rel="stylesheet">
{% block extra_css %}{% endblock extra_css %}
</head>
<body>
{% if user.is_authenticated %}
<div id="wrapper" class="container">
<!-- Navigation -->
<nav class="navbar navbar-static-top navbar-inverse auth-navbar-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".auth-menus-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand">
{{ SITE_NAME }}
</a>
</div>
<div class="collapse navbar-collapse auth-menus-collapse">
<ul class="nav navbar-nav navbar-right">
{% if notifications %}
<li>
<a href="{% url 'notifications:list' %}">
<span class="fa-stack">
<i class="fa fa-bell fa-stack-2x notification-bell-color"></i>
<i class="fa fa-inverse fa-stack-1x">{{ notifications }}</i>
</span>
</a>
</li>
{% else %}
<li><a href="{% url 'notifications:list' %}">
<i class="fa fa-bell-o"></i></a>
</li>
{% endif %}
{% if user.is_authenticated %}
{% if user.is_staff %}
<li><a href="{% url 'admin:index' %}">{% trans "Admin" %}</a></li>
{% endif %}
<li><a href="{% url 'auth_logout' %}">{% trans "Logout" %}</a></li>
{% else %}
<li><a href="{% url 'authentication:login' %}">{% trans "Login" %}</a></li>
{% endif %}
</ul>
<form id="f-lang-select" class="navbar-form navbar-right" action="{% url 'set_language' %}" method="post">
{% csrf_token %}
<input name="next" type="hidden" value="{{ request.get_full_path|slice:'3:' }}"/>
<div class="form-group">
<select onchange="this.form.submit()" class="form-control" id="lang-select" name="language">
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %}
selected="selected"{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
</div>
</form>
</div>
</div>
</nav>
{% include 'allianceauth/top-menu.html' %}
<div class="row" id="site-body-wrapper">
<div class="col-sm-2 auth-side-navbar" role="navigation">
<div class="collapse navbar-collapse auth-menus-collapse auth-side-navbar-collapse">
<ul class="nav nav-pills nav-stacked gray-icon-color" id="side-menu">
<li>
<a class="{% navactive request 'authentication:dashboard' %}"
href="{% url 'authentication:dashboard' %}">
<i class="fa fa-dashboard fa-fw"></i>{% trans " Dashboard" %}
</a>
</li>
<li>
<a class="{% navactive request 'groupmanagement:groups' %}" href="{% url 'groupmanagement:groups' %}">
<i class="fa fa-cogs fa-fw fa-sitemap"></i>{% trans " Groups" %}
</a>
</li>
{% if can_manage_groups %}
<li>
<a class="{% navactive request 'groupmanagement:management groupmanagement:membership groupmanagement:membership_list' %}"
href="{% url 'groupmanagement:management' %}">
<i class="fa fa-lock fa-sitemap fa-fw"></i>{% trans " Group Management" %}
</a>
</li>
{% endif %}
{% menu_items %}
<li>
<a class="{% navactive request 'authentication:help' %}"
href="{% url 'authentication:help' %}">
<i class="fa fa-question fa-fw"></i>{% trans " Help" %}
</a>
</li>
</ul>
</div>
</div>
{% include 'allianceauth/side-menu.html' %}
<div class="col-sm-10">
{% if messages %}
<br>
@ -128,10 +35,10 @@
{% endif %}
{% endfor %}
{% endif %}
{% block content %}
{% endblock content %}
{% block content %}
{% endblock content %}
</div>
<div class="clearfix"></div>
<div class="clearfix"></div>
</div>
</div>
{% endif %}

View File

@ -0,0 +1,5 @@
{% load i18n %}
<a href="{% url 'nightmode' %}?next={{ request.path|urlencode }}">
{% trans "Night" %}
<i class="fa {% if NIGHT_MODE %}fa-toggle-on{% else %}fa-toggle-off{% endif %}" aria-hidden="true"></i>
</a>

View File

@ -0,0 +1,38 @@
{% load i18n %}
{% load navactive %}
{% load menu_items %}
<div class="col-sm-2 auth-side-navbar" role="navigation">
<div class="collapse navbar-collapse auth-menus-collapse auth-side-navbar-collapse">
<ul class="nav nav-pills nav-stacked gray-icon-color" id="side-menu">
<li>
<a class="{% navactive request 'authentication:dashboard' %}"
href="{% url 'authentication:dashboard' %}">
<i class="fa fa-dashboard fa-fw"></i>{% trans " Dashboard" %}
</a>
</li>
<li>
<a class="{% navactive request 'groupmanagement:groups' %}" href="{% url 'groupmanagement:groups' %}">
<i class="fa fa-cogs fa-fw fa-sitemap"></i>{% trans " Groups" %}
</a>
</li>
{% if can_manage_groups %}
<li>
<a class="{% navactive request 'groupmanagement:management groupmanagement:membership groupmanagement:membership_list' %}"
href="{% url 'groupmanagement:management' %}">
<i class="fa fa-lock fa-sitemap fa-fw"></i>{% trans " Group Management" %}
</a>
</li>
{% endif %}
{% menu_items %}
<li>
<a class="{% navactive request 'authentication:help' %}"
href="{% url 'authentication:help' %}">
<i class="fa fa-question fa-fw"></i>{% trans " Help" %}
</a>
</li>
</ul>
</div>
</div>

View File

@ -0,0 +1,58 @@
{% load i18n %}
{% load navactive %}
<nav class="navbar navbar-default navbar-static-top auth-navbar-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".auth-menus-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand">
{{ SITE_NAME }}
</a>
</div>
<div class="collapse navbar-collapse auth-menus-collapse">
<ul class="nav navbar-nav navbar-right navbar-pills">
<li>
{% include 'allianceauth/night-toggle.html' %}
</li>
{% if notifications %}
<li class="{% navactive request 'notifications:' %}">
<a href="{% url 'notifications:list' %}">Notifications
<span class="badge">{{ notifications }}</span>
</a>
</li>
{% else %}
<li><a href="{% url 'notifications:list' %}">
<i class="fa fa-bell-o"></i></a>
</li>
{% endif %}
{% if user.is_authenticated %}
{% if user.is_staff %}
<li><a href="{% url 'admin:index' %}">{% trans "Admin" %}</a></li>
{% endif %}
<li><a href="{% url 'auth_logout' %}">{% trans "Logout" %}</a></li>
{% else %}
<li><a href="{% url 'authentication:login' %}">{% trans "Login" %}</a></li>
{% endif %}
</ul>
<form id="f-lang-select" class="navbar-form navbar-right" action="{% url 'set_language' %}" method="post">
{% csrf_token %}
<input name="next" type="hidden" value="{{ request.get_full_path|slice:'3:' }}"/>
<div class="form-group">
<select onchange="this.form.submit()" class="form-control" id="lang-select" name="language">
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %}
selected="selected"{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
</div>
</form>
</div>
</div>
</nav>

View File

@ -1,7 +1,20 @@
{% load staticfiles %}
<!-- Bootstrap Core CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<!-- Extra Bootstrap CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/startbootstrap-sb-admin-2/3.3.7+1/css/sb-admin-2.min.css" rel="stylesheet">
<!-- Bootstrap CSS -->
{% if NIGHT_MODE %}
{% if debug %}
<!-- In template debug, loading less file instead of CSS -->
<link rel="stylesheet/less" type="text/css" href="{% static 'css/themes/darkly/darkly.less' %}" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/less.js/2.7.2/less.min.js"></script>
{% else %}
<link rel="stylesheet" href="{% static 'css/themes/darkly/darkly.min.css' %}" />
{% endif %}
{% else %}
{% if debug %}
<!-- In template debug, loading less file instead of CSS -->
<link rel="stylesheet/less" type="text/css" href="{% static 'css/themes/flatly/flatly.less' %}" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/less.js/2.7.2/less.min.js"></script>
{% else %}
<link rel="stylesheet" href="{% static 'css/themes/flatly/flatly.min.css' %}" />
{% endif %}
{% endif %}
<!-- End Bootstrap CSS -->

View File

@ -10,6 +10,7 @@ import allianceauth.notifications.urls
import allianceauth.groupmanagement.urls
import allianceauth.services.urls
from allianceauth import NAME
from allianceauth import views
from allianceauth.authentication import hmac_urls
from allianceauth.hooks import get_hooks
@ -42,6 +43,9 @@ urlpatterns = [
# Services
url(r'', include(allianceauth.services.urls)),
# Night mode
url(r'^night/', views.NightModeRedirectView.as_view(), name='nightmode')
]
# Append app urls

19
allianceauth/views.py Normal file
View File

@ -0,0 +1,19 @@
from django.views.generic.base import View
from django.http import HttpResponseRedirect
class NightModeRedirectView(View):
SESSION_VAR = 'NIGHT_MODE'
def get(self, request, *args, **kwargs):
request.session[self.SESSION_VAR] = not self.night_mode_state(request)
return HttpResponseRedirect(request.GET.get('next', '/'))
@classmethod
def night_mode_state(cls, request):
try:
return request.session.get(cls.SESSION_VAR, False)
except AttributeError:
# Session is middleware
# Sometimes request wont have a session attribute
return False