mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-02-15 02:59:41 +00:00
Make dark theme a user level property, lazy load dark CSS
- Also now respects the colour-scheme media query - Added meta tag to tell the browser we support dark theme, allowing dark UA stylesheet if the user sends said media query - Means you only have to set it once per account rather than once per machine - Dark themed embeds!
This commit is contained in:
18
RIGS/migrations/0040_profile_dark_theme.py
Normal file
18
RIGS/migrations/0040_profile_dark_theme.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.1.5 on 2021-02-06 10:43
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('RIGS', '0039_auto_20210123_1910'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='profile',
|
||||||
|
name='dark_theme',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -26,6 +26,7 @@ class Profile(AbstractUser):
|
|||||||
is_approved = models.BooleanField(default=False)
|
is_approved = models.BooleanField(default=False)
|
||||||
last_emailed = models.DateTimeField(blank=True,
|
last_emailed = models.DateTimeField(blank=True,
|
||||||
null=True) # Currently only populated by the admin approval email. TODO: Populate it each time we send any email, might need that...
|
null=True) # Currently only populated by the admin approval email. TODO: Populate it each time we send any email, might need that...
|
||||||
|
dark_theme = models.BooleanField(default=False)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def make_api_key(cls):
|
def make_api_key(cls):
|
||||||
|
|||||||
@@ -146,10 +146,7 @@ class Asset(models.Model, RevisionMixin):
|
|||||||
return reverse('asset_detail', kwargs={'pk': self.asset_id})
|
return reverse('asset_detail', kwargs={'pk': self.asset_id})
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
out = "{} | {}".format(self.asset_id, self.description)
|
return "{} | {}".format(self.asset_id, self.description)
|
||||||
if self.is_cable and self.cable_type is not None:
|
|
||||||
out += '{} - {}m - {}'.format(self.cable_type.plug, self.length, self.cable_type.socket)
|
|
||||||
return out
|
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
errdict = {}
|
errdict = {}
|
||||||
|
|||||||
11
package-lock.json
generated
11
package-lock.json
generated
@@ -18,7 +18,6 @@
|
|||||||
"bootstrap-select": "^1.13.17",
|
"bootstrap-select": "^1.13.17",
|
||||||
"clipboard": "^2.0.6",
|
"clipboard": "^2.0.6",
|
||||||
"cssnano": "^4.1.10",
|
"cssnano": "^4.1.10",
|
||||||
"dark-mode-switch": "^1.0.0",
|
|
||||||
"flatpickr": "^4.6.6",
|
"flatpickr": "^4.6.6",
|
||||||
"fullcalendar": "^5.3.2",
|
"fullcalendar": "^5.3.2",
|
||||||
"gulp": "^4.0.2",
|
"gulp": "^4.0.2",
|
||||||
@@ -1663,11 +1662,6 @@
|
|||||||
"type": "^1.0.1"
|
"type": "^1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/dark-mode-switch": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/dark-mode-switch/-/dark-mode-switch-1.0.0.tgz",
|
|
||||||
"integrity": "sha512-wRoqYGmph7mwRbPcSNRR6DpRQe5wOK0lG6O3Hz7nIWWDyLAHSqje7PUI6c/acOYACiSPHc7sqysn57GSuklb6w=="
|
|
||||||
},
|
|
||||||
"node_modules/dashdash": {
|
"node_modules/dashdash": {
|
||||||
"version": "1.14.1",
|
"version": "1.14.1",
|
||||||
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
|
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
|
||||||
@@ -10583,11 +10577,6 @@
|
|||||||
"type": "^1.0.1"
|
"type": "^1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dark-mode-switch": {
|
|
||||||
"version": "1.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/dark-mode-switch/-/dark-mode-switch-1.0.0.tgz",
|
|
||||||
"integrity": "sha512-wRoqYGmph7mwRbPcSNRR6DpRQe5wOK0lG6O3Hz7nIWWDyLAHSqje7PUI6c/acOYACiSPHc7sqysn57GSuklb6w=="
|
|
||||||
},
|
|
||||||
"dashdash": {
|
"dashdash": {
|
||||||
"version": "1.14.1",
|
"version": "1.14.1",
|
||||||
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
|
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
"bootstrap-select": "^1.13.17",
|
"bootstrap-select": "^1.13.17",
|
||||||
"clipboard": "^2.0.6",
|
"clipboard": "^2.0.6",
|
||||||
"cssnano": "^4.1.10",
|
"cssnano": "^4.1.10",
|
||||||
"dark-mode-switch": "^1.0.0",
|
|
||||||
"flatpickr": "^4.6.6",
|
"flatpickr": "^4.6.6",
|
||||||
"fullcalendar": "^5.3.2",
|
"fullcalendar": "^5.3.2",
|
||||||
"gulp": "^4.0.2",
|
"gulp": "^4.0.2",
|
||||||
|
|||||||
@@ -111,4 +111,12 @@
|
|||||||
.custom-control-input:focus ~ .custom-control-label::before {
|
.custom-control-input:focus ~ .custom-control-label::before {
|
||||||
box-shadow: 0 0 0 $input-focus-width rgba($primary, 0.7) !important;
|
box-shadow: 0 0 0 $input-focus-width rgba($primary, 0.7) !important;
|
||||||
}
|
}
|
||||||
|
.source {
|
||||||
|
color: white !important;
|
||||||
|
}
|
||||||
|
.embed_container {
|
||||||
|
border-color: #3853a4 !important;
|
||||||
|
background: #222;
|
||||||
|
color: $gray-100;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
@import "dark_screen";
|
|
||||||
@import "custom-variables";
|
@import "custom-variables";
|
||||||
//Required
|
//Required
|
||||||
@import "node_modules/bootstrap/scss/bootstrap-reboot";
|
@import "node_modules/bootstrap/scss/bootstrap-reboot";
|
||||||
|
|||||||
@@ -10,11 +10,14 @@
|
|||||||
|
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
<meta name="theme-color" content="#3853a4">
|
||||||
|
<meta name="color-scheme" content="light dark">
|
||||||
|
|
||||||
<link rel="icon" type="image/png" href="{% static 'imgs/pyrigs-avatar.png' %}">
|
<link rel="icon" type="image/png" href="{% static 'imgs/pyrigs-avatar.png' %}">
|
||||||
<link rel="apple-touch-icon" href="{% static 'imgs/pyrigs-avatar.png' %}">
|
<link rel="apple-touch-icon" href="{% static 'imgs/pyrigs-avatar.png' %}">
|
||||||
<link href="{% static 'fonts/OpenSans-Regular.tff' %}">
|
<link href="{% static 'fonts/OpenSans-Regular.tff' %}">
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="{% static 'css/dark_screen.css' %}" {% if not request.user.dark_theme %}media="(prefers-color-scheme: dark)"{% endif %}>
|
||||||
<link rel="stylesheet" type="text/css" href="{% static 'css/screen.css' %}">
|
<link rel="stylesheet" type="text/css" href="{% static 'css/screen.css' %}">
|
||||||
{% block css %}
|
{% block css %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -77,7 +80,11 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal fade" id="modal" role="dialog" tabindex=-1></div>
|
<div class="modal fade" id="modal" role="dialog" tabindex=-1></div>
|
||||||
|
<script>
|
||||||
|
if({{ request.user.dark_theme|lower }} || window.matchMedia('(prefers-color-scheme: dark)')) {
|
||||||
|
document.body.setAttribute('data-theme', 'dark');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
<script>
|
<script>
|
||||||
Date.prototype.getISOString = function () {
|
Date.prototype.getISOString = function () {
|
||||||
var yyyy = this.getFullYear().toString();
|
var yyyy = this.getFullYear().toString();
|
||||||
@@ -123,7 +130,6 @@
|
|||||||
easter_egg.load();
|
easter_egg.load();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<script src="{% static 'js/dark-mode-switch.min.js' %}"></script>
|
|
||||||
<script>
|
<script>
|
||||||
document.body.addEventListener('keydown', function(e) {
|
document.body.addEventListener('keydown', function(e) {
|
||||||
if(e.keyCode == 13 && (e.metaKey || e.ctrlKey)) {
|
if(e.keyCode == 13 && (e.metaKey || e.ctrlKey)) {
|
||||||
|
|||||||
@@ -7,8 +7,10 @@
|
|||||||
lang="{% firstof LANGUAGE_CODE 'en' %}"
|
lang="{% firstof LANGUAGE_CODE 'en' %}"
|
||||||
class="embedded">
|
class="embedded">
|
||||||
<head>
|
<head>
|
||||||
<base target="_blank" />
|
<base target="_blank" /><!-- Open all links in a new tab, not in the iframe -->
|
||||||
<!-- Open all links in a new tab, not in the iframe -->
|
|
||||||
|
<meta name="color-scheme" content="light dark">
|
||||||
|
<link rel="stylesheet" type="text/css" href="{% static 'css/dark_screen.css' %}" {% if not request.user.dark_theme %}media="(prefers-color-scheme: dark)"{% endif %}>
|
||||||
|
|
||||||
<link href="{% static 'fonts/OpenSans-Regular.tff' %}">
|
<link href="{% static 'fonts/OpenSans-Regular.tff' %}">
|
||||||
|
|
||||||
@@ -34,6 +36,11 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script>
|
||||||
|
if({{ request.user.dark_theme|lower }} || window.matchMedia('(prefers-color-scheme: dark)')) {
|
||||||
|
document.body.setAttribute('data-theme', 'dark');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
{% block js %}
|
{% block js %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -3,22 +3,17 @@
|
|||||||
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
Hi {{ user.first_name }}
|
Hi {{ user.first_name }}
|
||||||
</a>
|
</a>
|
||||||
<ul class="dropdown-menu p-3 clearfix" id="userdropdown">
|
<ul class="dropdown-menu clearfix" id="userdropdown">
|
||||||
<li class="media">
|
<li class="media">
|
||||||
<a href="{% url 'profile_detail' %}">
|
<a href="{% url 'profile_detail' %}">
|
||||||
<img src="{{ request.user.profile_picture }}" class="media-object"/>
|
<img src="{{ request.user.profile_picture }}" class="media-object float-left pr-2"/>
|
||||||
<div class="media-body">
|
<div class="media-body">
|
||||||
<b>{{ request.user.first_name }} {{ request.user.last_name }}</b>
|
<b>{{ request.user.first_name }} {{ request.user.last_name }}</b>
|
||||||
<p class="muted">{{ request.user.email }}</p>
|
<p class="text-muted">{{ request.user.email }}</p>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="mb-2">
|
<div class="dropdown-divider"></div>
|
||||||
<div class="custom-control custom-switch">
|
|
||||||
<input type="checkbox" class="custom-control-input" id="darkSwitch" />
|
|
||||||
<label class="custom-control-label" for="darkSwitch">Dark Mode</label>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
<li class="float-right"><a href="{% url 'logout' %}" class="btn btn-primary"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
|
<li class="float-right"><a href="{% url 'logout' %}" class="btn btn-primary"><i class="fas fa-sign-out-alt"></i> Logout</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|||||||
@@ -5,10 +5,18 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col-md-6 offset-md-3">
|
||||||
{% include 'form_errors.html' %}
|
{% include 'form_errors.html' %}
|
||||||
<h3>Update Profile {{object.name}}</h3>
|
<h3>Update Profile {{object.name}}</h3>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<a href="https://gravatar.com/">
|
||||||
|
<img src="{{object.profile_picture}}" class="img-fluid rounded" />
|
||||||
|
<div class="text-center">
|
||||||
|
Images hosted by Gravatar
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<form action="{{form.action|default:request.path}}" method="post">{% csrf_token %}
|
<form action="{{form.action|default:request.path}}" method="post">{% csrf_token %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -17,34 +25,26 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{% include 'partials/form_field.html' with field=form.last_name %}
|
{% include 'partials/form_field.html' with field=form.last_name %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="{{form.email.id_for_label}}" class="col-form-label">{{form.email.label}}</label>
|
<label for="{{form.email.id_for_label}}" class="col-form-label">{{form.email.label}}</label>
|
||||||
{% render_field form.email type="email" class+="form-control" placeholder=form.email.label %}
|
{% render_field form.email type="email" class+="form-control" placeholder=form.email.label %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{% include 'partials/form_field.html' with field=form.initials %}
|
{% include 'partials/form_field.html' with field=form.initials %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="{{form.phone.id_for_label}}" class="col-form-label">{{form.phone.label}}</label>
|
<label for="{{form.phone.id_for_label}}" class="col-form-label">{{form.phone.label}}</label>
|
||||||
{% render_field form.phone type="tel" class+="form-control" placeholder=form.phone.label %}
|
{% render_field form.phone type="tel" class+="form-control" placeholder=form.phone.label %}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="{{ form.dark_theme.id_for_label }}">Enable Dark Theme?</label>
|
||||||
|
{% render_field form.dark_theme %}
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input class="btn btn-primary float-right" type="submit"/>
|
<input class="btn btn-primary float-right" type="submit"/>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col">
|
|
||||||
<a href="https://gravatar.com/">
|
|
||||||
<img src="{{object.profile_picture}}" class="img-fluid rounded" />
|
|
||||||
<div class="text-center">
|
|
||||||
Images hosted by Gravatar
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class ProfileDetail(generic.DetailView):
|
|||||||
class ProfileUpdateSelf(generic.UpdateView):
|
class ProfileUpdateSelf(generic.UpdateView):
|
||||||
template_name = "profile_form.html"
|
template_name = "profile_form.html"
|
||||||
model = models.Profile
|
model = models.Profile
|
||||||
fields = ['first_name', 'last_name', 'email', 'initials', 'phone']
|
fields = ['first_name', 'last_name', 'email', 'initials', 'phone', 'dark_theme']
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
pk = self.request.user.id
|
pk = self.request.user.id
|
||||||
|
|||||||
Reference in New Issue
Block a user