mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Add themes to users page/base
This commit is contained in:
parent
05f08773a3
commit
a5a81aa22a
@ -399,6 +399,10 @@ class Helpers:
|
||||
)
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def get_themes():
|
||||
return ["default", "dark", "light", "ronald"]
|
||||
|
||||
@staticmethod
|
||||
def get_local_ip():
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
@ -878,6 +878,7 @@ class PanelHandler(BaseHandler):
|
||||
page_data["user"]["roles"] = set()
|
||||
page_data["user"]["hints"] = True
|
||||
page_data["superuser"] = superuser
|
||||
page_data["themes"] = self.helper.get_themes()
|
||||
|
||||
if EnumPermissionsCrafty.USER_CONFIG not in exec_user_crafty_permissions:
|
||||
self.redirect(
|
||||
@ -1092,6 +1093,7 @@ class PanelHandler(BaseHandler):
|
||||
page_data["exec_user"] = exec_user["user_id"]
|
||||
page_data["servers_all"] = self.controller.servers.get_all_defined_servers()
|
||||
page_data["superuser"] = superuser
|
||||
page_data["themes"] = self.helper.get_themes()
|
||||
if page_data["user"]["manager"] is not None:
|
||||
page_data["manager"] = self.controller.users.get_user_by_id(
|
||||
page_data["user"]["manager"]
|
||||
@ -2011,6 +2013,7 @@ class PanelHandler(BaseHandler):
|
||||
user_id = bleach.clean(self.get_argument("id", None))
|
||||
user = self.controller.users.get_user_by_id(user_id)
|
||||
username = bleach.clean(self.get_argument("username", None).lower())
|
||||
theme = bleach.clean(self.get_argument("theme", "default"))
|
||||
if (
|
||||
username != self.controller.users.get_user_by_id(user_id)["username"]
|
||||
and username in self.controller.users.get_all_usernames()
|
||||
@ -2077,6 +2080,7 @@ class PanelHandler(BaseHandler):
|
||||
"email": email,
|
||||
"lang": lang,
|
||||
"hints": hints,
|
||||
"theme": theme,
|
||||
}
|
||||
self.controller.users.update_user(user_id, user_data=user_data)
|
||||
|
||||
@ -2113,6 +2117,7 @@ class PanelHandler(BaseHandler):
|
||||
"lang": lang,
|
||||
"superuser": superuser,
|
||||
"hints": hints,
|
||||
"theme": theme,
|
||||
}
|
||||
user_crafty_data = {
|
||||
"permissions_mask": permissions_mask,
|
||||
@ -2224,6 +2229,7 @@ class PanelHandler(BaseHandler):
|
||||
password1 = bleach.clean(self.get_argument("password1", None))
|
||||
email = bleach.clean(self.get_argument("email", "default@example.com"))
|
||||
enabled = int(float(self.get_argument("enabled", "0")))
|
||||
theme = bleach.clean(self.get_argument("theme"), "default")
|
||||
hints = True
|
||||
lang = bleach.clean(
|
||||
self.get_argument("lang", self.helper.get_setting("language"))
|
||||
@ -2279,6 +2285,7 @@ class PanelHandler(BaseHandler):
|
||||
email=email,
|
||||
enabled=enabled,
|
||||
superuser=new_superuser,
|
||||
theme=theme,
|
||||
)
|
||||
user_data = {"roles": roles, "lang": lang, "hints": True}
|
||||
user_crafty_data = {
|
||||
|
@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ data['lang_page'] }}" class="default">
|
||||
<html lang="{{ data['lang_page'] }}" class="{{data['user_data'].get('theme', 'default')}}">
|
||||
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
|
@ -9,22 +9,22 @@
|
||||
|
||||
<div class="content-wrapper">
|
||||
|
||||
<!-- Page Title Header Starts-->
|
||||
<!-- Page Title Header Starts-->
|
||||
<div class="row page-title-header">
|
||||
<div class="col-12">
|
||||
<div class="page-header">
|
||||
{% if data['new_role'] %}
|
||||
<h4 class="page-title">
|
||||
{{ translate('rolesConfig', 'pageTitleNew', data['lang']) }}
|
||||
<br />
|
||||
<small>RID: N/A</small>
|
||||
</h4>
|
||||
<h4 class="page-title">
|
||||
{{ translate('rolesConfig', 'pageTitleNew', data['lang']) }}
|
||||
<br />
|
||||
<small>RID: N/A</small>
|
||||
</h4>
|
||||
{% else %}
|
||||
<h4 class="page-title">
|
||||
{{ translate('rolesConfig', 'pageTitle', data['lang']) }} - {{ data['role']['role_name'] }}
|
||||
<br />
|
||||
<small>RID: {{ data['role']['role_id'] }}</small>
|
||||
</h4>
|
||||
<h4 class="page-title">
|
||||
{{ translate('rolesConfig', 'pageTitle', data['lang']) }} - {{ data['role']['role_name'] }}
|
||||
<br />
|
||||
<small>RID: {{ data['role']['role_id'] }}</small>
|
||||
</h4>
|
||||
{% end %}
|
||||
</div>
|
||||
</div>
|
||||
@ -49,24 +49,19 @@
|
||||
</ul>
|
||||
<div class="">
|
||||
<div class="">
|
||||
<form id="role_form" class="forms-sample" method="post"
|
||||
action="{{ '/panel/add_role' if data['new_role'] else '/panel/edit_role' }}">
|
||||
<form id="role_form" class="forms-sample" method="post" action="{{ '/panel/add_role' if data['new_role'] else '/panel/edit_role' }}">
|
||||
{% raw xsrf_form_html() %}
|
||||
<input type="hidden" name="id" value="{{ data['role']['role_id'] }}">
|
||||
<input type="hidden" name="subpage" value="config">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header header-sm d-flex justify-content-between align-items-center">
|
||||
<h4 class="card-title"><i class="fas fa-user-tag"></i> {{ translate('rolesConfig', 'roleTitle',
|
||||
data['lang']) }}</h4>
|
||||
<h4 class="card-title"><i class="fas fa-user-tag"></i> {{ translate('rolesConfig', 'roleTitle', data['lang']) }}</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<label for="role_name">{{ translate('rolesConfig', 'roleName', data['lang']) }} <small
|
||||
class="text-muted ml-1"> - {{ translate('rolesConfig', 'roleDesc', data['lang']) }}</small>
|
||||
</label>
|
||||
<input type="text" class="form-control" name="role_name" id="role_name"
|
||||
value="{{ data['role']['role_name'] }}" placeholder="Role Name">
|
||||
<label for="role_name">{{ translate('rolesConfig', 'roleName', data['lang']) }} <small class="text-muted ml-1"> - {{ translate('rolesConfig', 'roleDesc', data['lang']) }}</small> </label>
|
||||
<input type="text" class="form-control" name="role_name" id="role_name" value="{{ data['role']['role_name'] }}" placeholder="Role Name" >
|
||||
</div>
|
||||
|
||||
<br />
|
||||
@ -96,9 +91,7 @@
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header header-sm d-flex justify-content-between align-items-center">
|
||||
<h4 class="card-title"><i class="fas fa-server"></i> {{ translate('rolesConfig', 'roleServers',
|
||||
data['lang']) }} <small class="text-muted ml-1"> {{ translate('rolesConfig', 'serversDesc',
|
||||
data['lang']) }}</small> </h4>
|
||||
<h4 class="card-title"><i class="fas fa-server"></i> {{ translate('rolesConfig', 'roleServers', data['lang']) }} <small class="text-muted ml-1"> {{ translate('rolesConfig', 'serversDesc', data['lang']) }}</small> </h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
@ -116,14 +109,13 @@
|
||||
--table-border-width: 1px;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
th.rotate-column-header {
|
||||
/* Something you can count on */
|
||||
height: 140px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
th.rotate-column-header>div {
|
||||
th.rotate-column-header > div {
|
||||
transform:
|
||||
/* Magic Numbers */
|
||||
translate(0px, 51px)
|
||||
@ -131,18 +123,15 @@
|
||||
rotate(315deg);
|
||||
width: 30px;
|
||||
}
|
||||
|
||||
th.rotate-column-header>div>span {
|
||||
th.rotate-column-header > div > span {
|
||||
border-bottom: 1px solid #ccc;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
|
||||
th.rotate {
|
||||
white-space: nowrap;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
th.rotate>div {
|
||||
th.rotate > div {
|
||||
/* place div at bottom left of the th parent */
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
@ -152,13 +141,13 @@
|
||||
/* Move the top left corner of the span's bottom-border to line up with the top left corner of the td's border-right border so that the border corners are matched
|
||||
* Rotate 315 (-45) degrees about matched border corners */
|
||||
transform:
|
||||
translate(calc(100% - var(--table-border-width) / 2), var(--table-border-width)) rotate(-45deg);
|
||||
translate(calc(100% - var(--table-border-width) / 2), var(--table-border-width))
|
||||
rotate(-45deg);
|
||||
transform-origin: 0% calc(100% - var(--table-border-width));
|
||||
transition: transform 500ms;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
th.rotate>div>span {
|
||||
th.rotate > div > span {
|
||||
/* make sure the bottom of the span is matched up with the bottom of the parent div */
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
@ -168,8 +157,7 @@
|
||||
padding-bottom: 5px;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
table.rotate-table>tbody td {
|
||||
table.rotate-table > tbody td {
|
||||
border-right: var(--table-border-width) solid var(--outline);
|
||||
/* make sure this is at least as wide as sqrt(2) * height of the tallest letter in your font or the headers will overlap each other*/
|
||||
min-width: 30px;
|
||||
@ -179,57 +167,53 @@
|
||||
}
|
||||
|
||||
@media screen and (min-width: 1650px) {
|
||||
th.rotate>div {
|
||||
th.rotate > div {
|
||||
transform: translate(15px, 0px) rotate(0deg);
|
||||
}
|
||||
|
||||
th.rotate>div>span {
|
||||
th.rotate > div > span {
|
||||
border-bottom-color: transparent;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<tr class="rounded">
|
||||
<th>{{ translate('rolesConfig', 'serverName', data['lang']) }}</th>
|
||||
<th class="rotate">
|
||||
<div><span>{{ translate('rolesConfig', 'serverAccess', data['lang']) }}</span></div>
|
||||
</th>
|
||||
<th class="rotate"><div><span>{{ translate('rolesConfig', 'serverAccess', data['lang']) }}</span></div></th>
|
||||
{% for permission in data['permissions_all'] %}
|
||||
<th class="rotate">
|
||||
<div><span>{{ permission.name }}</span></div>
|
||||
</th>
|
||||
<th class="rotate"><div><span>{{ permission.name }}</span></div></th>
|
||||
{% end %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for server in data['servers_all'] %}
|
||||
{% for server in data['servers_all'] %}
|
||||
<tr>
|
||||
<td>{{ server['server_name'] }}</td>
|
||||
<td>
|
||||
<input type="checkbox" class="" onclick="enable_disable(event)"
|
||||
data-id="{{server['server_id']}}" id="server_{{ server['server_id'] }}_access"
|
||||
name="server_{{ server['server_id'] }}_access" {{ 'checked' if server['server_id'] in
|
||||
data['role']['servers'] else '' }} autocomplete="off" value="1">
|
||||
<input type="checkbox" class="" onclick="enable_disable(event)" data-id="{{server['server_id']}}"
|
||||
id="server_{{ server['server_id'] }}_access"
|
||||
name="server_{{ server['server_id'] }}_access"
|
||||
{{ 'checked' if server['server_id'] in data['role']['servers'] else '' }}
|
||||
autocomplete="off" value="1">
|
||||
</td>
|
||||
{% for permission in data['permissions_all'] %}
|
||||
{% if server['server_id'] in data['role']['servers'] %}
|
||||
<td>
|
||||
<input type="checkbox" class="{{server['server_id']}}_perms"
|
||||
<td>
|
||||
<input type="checkbox" class="{{server['server_id']}}_perms"
|
||||
id="permission_{{ server['server_id'] }}_{{ permission.name }}"
|
||||
name="permission_{{ server['server_id'] }}_{{ permission.name }}" {{ 'checked' if
|
||||
permission in data['permissions_dict'].get(server['server_id'], []) else '' }}
|
||||
name="permission_{{ server['server_id'] }}_{{ permission.name }}"
|
||||
{{ 'checked' if permission in data['permissions_dict'].get(server['server_id'], []) else '' }}
|
||||
autocomplete="off" value="1">
|
||||
</td>
|
||||
</td>
|
||||
{% else %}
|
||||
<td>
|
||||
<input type="checkbox" class="{{server['server_id']}}_perms"
|
||||
id="permission_{{ server['server_id'] }}_{{ permission.name }}"
|
||||
name="permission_{{ server['server_id'] }}_{{ permission.name }}" autocomplete="off"
|
||||
value="1" disabled>
|
||||
id="permission_{{ server['server_id'] }}_{{ permission.name }}"
|
||||
name="permission_{{ server['server_id'] }}_{{ permission.name }}"
|
||||
autocomplete="off" value="1" disabled>
|
||||
</td>
|
||||
{% end %}
|
||||
{% end %}
|
||||
</tr>
|
||||
{% end %}
|
||||
{% end %}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
@ -240,22 +224,18 @@
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header header-sm d-flex justify-content-between align-items-center">
|
||||
<h4 class="card-title"><i class="fas fa-settings"></i> {{ translate('panelConfig', 'save',
|
||||
data['lang']) }}</h4>
|
||||
<h4 class="card-title"><i class="fas fa-settings"></i> {{ translate('panelConfig', 'save', data['lang']) }}</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<button type="submit" class="btn btn-success mr-2"><i class="fas fa-save"></i> {{
|
||||
translate('panelConfig', 'save', data['lang']) }}</button>
|
||||
<button type="reset" onclick="location.href='/panel/panel_config'" class="btn btn-light"><i
|
||||
class="fas fa-undo-alt"></i> {{ translate('panelConfig', 'cancel', data['lang']) }}</button>
|
||||
<button type="submit" class="btn btn-success mr-2"><i class="fas fa-save"></i> {{ translate('panelConfig', 'save', data['lang']) }}</button>
|
||||
<button type="reset" onclick="location.href='/panel/panel_config'" class="btn btn-light"><i class="fas fa-undo-alt"></i> {{ translate('panelConfig', 'cancel', data['lang']) }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header header-sm d-flex justify-content-between align-items-center">
|
||||
<h4 class="card-title"><i class="fas fa-users"></i> {{ translate('rolesConfig', 'roleUsers',
|
||||
data['lang']) }}</h4>
|
||||
<h4 class="card-title"><i class="fas fa-users"></i> {{ translate('rolesConfig', 'roleUsers', data['lang']) }}</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
@ -267,18 +247,18 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for user in data['users'] %}
|
||||
{% for user in data['users'] %}
|
||||
{% for ruser in data['user-roles'][user.user_id] %}
|
||||
{% if ruser == data['role']['role_name'] %}
|
||||
<tr>
|
||||
<td>{{ user.username }}</td>
|
||||
<td>
|
||||
<a href="/panel/edit_user?id={{user.user_id}}"><i class="fas fa-user-edit"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
{% end %}
|
||||
{% end %}
|
||||
{% if ruser == data['role']['role_name'] %}
|
||||
<tr>
|
||||
<td>{{ user.username }}</td>
|
||||
<td>
|
||||
<a href="/panel/edit_user?id={{user.user_id}}"><i class="fas fa-user-edit"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
{% end %}
|
||||
{% end %}
|
||||
{% end %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@ -292,24 +272,20 @@
|
||||
<blockquote class="blockquote">
|
||||
<p class="mb-0">
|
||||
{{ translate('rolesConfig', 'created', data['lang']) }} {{ str(data['role']['created']) }}
|
||||
<br />
|
||||
{{ translate('rolesConfig', 'configUpdate', data['lang']) }} {{ str(data['role']['last_update'])
|
||||
}}
|
||||
<br />
|
||||
{{ translate('userConfig', 'manager', data['lang']) }}: {{ data['role_manager']['username'] }}
|
||||
<br />
|
||||
<br />
|
||||
{{ translate('rolesConfig', 'configUpdate', data['lang']) }} {{ str(data['role']['last_update']) }}
|
||||
<br />
|
||||
{{ translate('userConfig', 'manager', data['lang']) }}: {{ data['role_manager']['username'] }}
|
||||
<br />
|
||||
</p>
|
||||
</blockquote>
|
||||
<div class="text-center">
|
||||
{% if data['new_role'] %}
|
||||
<a class="btn btn-sm btn-danger disabled"><i class="fas fa-trash"></i>{{ translate('rolesConfig',
|
||||
'delRole', data['lang']) }}</a><br />
|
||||
<small>{{ translate('rolesConfig', 'doesNotExist', data['lang']) }}</small>
|
||||
<a class="btn btn-sm btn-danger disabled"><i class="fas fa-trash"></i>{{ translate('rolesConfig', 'delRole', data['lang']) }}</a><br />
|
||||
<small>{{ translate('rolesConfig', 'doesNotExist', data['lang']) }}</small>
|
||||
{% else %}
|
||||
<a href="/panel/remove_role?id={{ data['role']['role_id'] }}" class="btn btn-sm btn-danger"><i
|
||||
class="fas fa-trash"></i>{{ translate('rolesConfig', 'delRole', data['lang']) }}</a>
|
||||
<a href="/panel/remove_role?id={{ data['role']['role_id'] }}" class="btn btn-sm btn-danger"><i class="fas fa-trash"></i>{{ translate('rolesConfig', 'delRole', data['lang']) }}</a>
|
||||
{% end %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -318,37 +294,38 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- content-wrapper ends -->
|
||||
</div>
|
||||
<!-- content-wrapper ends -->
|
||||
|
||||
{% end %}
|
||||
{% end %}
|
||||
|
||||
{% block js %}
|
||||
<script>
|
||||
{% block js %}
|
||||
<script>
|
||||
|
||||
function enable_disable(event) {
|
||||
function enable_disable(event) {
|
||||
let server_id = event.target.getAttribute('data-id');
|
||||
console.log(server_id);
|
||||
if (document.getElementById("server_" + server_id + "_access").checked) {
|
||||
$('.' + server_id + '_perms').attr('disabled', false);
|
||||
$('.' + server_id + '_perms').attr('enabled', true);
|
||||
} else {
|
||||
$('.' + server_id + '_perms').prop('checked', false);
|
||||
$('.' + server_id + '_perms').attr('disabled', true);
|
||||
$('.' + server_id + '_perms').attr('enabled', false);
|
||||
$('.'+server_id+'_perms').attr('disabled', false);
|
||||
$('.'+server_id+'_perms').attr('enabled', true);
|
||||
}else{
|
||||
$('.'+server_id+'_perms').prop('checked', false);
|
||||
$('.'+server_id+'_perms').attr('disabled', true);
|
||||
$('.'+server_id+'_perms').attr('enabled', false);
|
||||
}
|
||||
|
||||
}
|
||||
//used to get cookies from browser - this is part of tornados xsrf protection - it's for extra security
|
||||
function getCookie(name) {
|
||||
var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
|
||||
return r ? r[1] : undefined;
|
||||
var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
|
||||
return r ? r[1] : undefined;
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
console.log("ready!");
|
||||
$( document ).ready(function() {
|
||||
console.log( "ready!" );
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
</script>
|
||||
|
||||
{% end %}
|
||||
{% end %}
|
||||
|
@ -121,6 +121,19 @@ data['lang']) }}{% end %}
|
||||
{% end %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="theme">{{ translate('userConfig', 'userTheme', data['lang'])
|
||||
}}</label>
|
||||
<select class="form-select form-control form-control-lg select-css" id="language"
|
||||
name="theme" form="user_form">
|
||||
<option value="{{data['user'].get('theme', 'default')}}">{{data['user'].get('theme', 'default')}}</option>
|
||||
{% for theme in data['themes'] %}
|
||||
{% if theme != data['user'].get('theme', 'default') %}
|
||||
<option value="{{theme}}">{{theme}}</option>
|
||||
{% end %}
|
||||
{% end %}
|
||||
</select>
|
||||
</div>
|
||||
{% if data['superuser'] %}
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="manager">{{ translate('userConfig', 'selectManager',
|
||||
|
Loading…
Reference in New Issue
Block a user