add: allow to choose a custom timezone for the UI (fix #329)

This commit is contained in:
ziirish 2020-03-31 00:17:56 +02:00
parent 57d2d41775
commit a04f58e9e9
No known key found for this signature in database
GPG key ID: 72DB229A64B54E46
15 changed files with 34 additions and 10 deletions

View file

@ -149,6 +149,12 @@ class PrefsUI(Resource):
required=False,
help='Date format'
)
parser.add_argument(
'timezone',
type=str,
required=False,
help='Timezone'
)
@staticmethod
def _user_language(language):

View file

@ -381,6 +381,7 @@ def create_app(conf=None, verbose=0, logfile=None, **kwargs):
g.locale = get_locale()
g.now = round(time.time())
g.date_format = session.get('dateFormat', 'llll')
g.timezone = session.get('timezone')
# make sure to store secure cookie if required
if app.config['BUI_SCOOKIE']:
criteria = (

@ -1 +1 @@
Subproject commit 7e90a1461b1c118bbc190c003184365890320729
Subproject commit 8a343173cd3b7fd07a27579ff291fb144f594a2e

View file

@ -7,6 +7,12 @@ var SESSION_TAG = $('meta[name=session]').attr("content");
var _EXTRA = $('meta[name=_extra]').attr('content');
var AJAX_CACHE = true;
{% if g.timezone -%}
var TIMEZONE = "{{ g.timezone }}";
{% else -%}
var TIMEZONE = moment.tz.guess();
{% endif -%}
var _ajax_setup = function() {
$.ajaxSetup({
headers: { 'X-From-UI': true, 'X-Session-Tag': SESSION_TAG },

View file

@ -113,7 +113,7 @@ var _sessions_table = $('#table-sessions').DataTable( {
if (type === 'filter') {
return data;
}
return '<span data-toggle="tooltip" title="'+data+'">'+moment(data, moment.ISO_8601).subtract(3, 'seconds').fromNow()+'</span>';
return '<span data-toggle="tooltip" title="'+data+'">'+moment(data, moment.ISO_8601).tz(TIMEZONE).subtract(3, 'seconds').fromNow()+'</span>';
}
},
{
@ -174,7 +174,7 @@ var _sessions_table = $('#table-sessions').DataTable( {
if (type === 'filter') {
return data;
}
return '<span data-toggle="tooltip" title="'+data+'">'+moment(data, moment.ISO_8601).fromNow()+'</span>';
return '<span data-toggle="tooltip" title="'+data+'">'+moment(data, moment.ISO_8601).tz(TIMEZONE).fromNow()+'</span>';
}
},
],

View file

@ -48,6 +48,7 @@ $(document).ready(function() {
$('#calendar').fullCalendar({
{{ macros.translate_calendar() }}
timezone: TIMEZONE,
editable: false,
eventLimit: true,
eventLimitClick: 'day',

View file

@ -118,7 +118,7 @@ $( document ).ready(function() {
$tdList.eq(2).text(node.data.uid);
$tdList.eq(3).text(node.data.gid);
$tdList.eq(4).text(node.data.size);
$tdList.eq(5).html('<span title="'+node.data.date+'">'+moment(node.data.date).format({{ g.date_format|tojson }})+'</span>');
$tdList.eq(5).html('<span title="'+node.data.date+'">'+moment(node.data.date).tz(TIMEZONE).format({{ g.date_format|tojson }})+'</span>');
},
select: function(event, data) {
toggleRestorationForms(data.tree);

View file

@ -115,7 +115,7 @@ var _client_table = $('#table-client').DataTable( {
data: 'date',
type: 'timestamp',
render: function ( data, type, row ) {
return '<span data-toggle="tooltip" title="'+data+'">'+moment(data, moment.ISO_8601).format({{ g.date_format|tojson }})+'</span>';
return '<span data-toggle="tooltip" title="'+data+'">'+moment(data, moment.ISO_8601).tz(TIMEZONE).format({{ g.date_format|tojson }})+'</span>';
}
},
{

View file

@ -135,7 +135,7 @@ var _clients_table = $('#table-clients').DataTable( {
return data;
}
if (!(data in __status || data in __date)) {
return '<span data-toggle="tooltip" title="'+data+'">'+moment(data, moment.ISO_8601).format({{ g.date_format|tojson }})+'</span>';
return '<span data-toggle="tooltip" title="'+data+'">'+moment(data, moment.ISO_8601).tz(TIMEZONE).format({{ g.date_format|tojson }})+'</span>';
}
return data;
}

View file

@ -282,7 +282,7 @@ var _sessions_table = $('#table-sessions').DataTable( {
if (type === 'filter') {
return data;
}
return '<span data-toggle="tooltip" title="'+data+'">'+moment(data, moment.ISO_8601).subtract(3, 'seconds').fromNow()+'</span>';
return '<span data-toggle="tooltip" title="'+data+'">'+moment(data, moment.ISO_8601).tz(TIMEZONE).subtract(3, 'seconds').fromNow()+'</span>';
}
},
{
@ -343,7 +343,7 @@ var _sessions_table = $('#table-sessions').DataTable( {
if (type === 'filter') {
return data;
}
return '<span data-toggle="tooltip" title="'+data+'">'+moment(data, moment.ISO_8601).fromNow()+'</span>';
return '<span data-toggle="tooltip" title="'+data+'">'+moment(data, moment.ISO_8601).tz(TIMEZONE).fromNow()+'</span>';
}
},
],

View file

@ -77,6 +77,7 @@
<!-- MomentJS
================================================== -->
<script src="{{ url_for('bower.static', filename='moment/min/moment.min.js') }}"></script>
<script src="{{ url_for('bower.static', filename='moment-timezone/builds/moment-timezone-with-data-10-year-range.min.js') }}"></script>
{% if g.locale and g.locale != 'en' -%}
<script src="{{ url_for('bower.static', filename='moment/locale/{}.js'.format(g.locale)) }}"></script>
{% endif -%}

View file

@ -164,11 +164,11 @@ jQuery.extend( jQuery.fn.dataTableExt.oSort, {
var $obj = $(a);
var title = $obj.attr('title');
if (typeof title !== typeof undefined && title !== false)
return moment(title, moment.ISO_8601).valueOf();
return moment(title, moment.ISO_8601).tz(TIMEZONE).valueOf();
// we are using the filter the "right" way here
if (moment(a, moment.ISO_8601).isValid())
return ''+moment(a, moment.ISO_8601).valueOf();
return ''+moment(a, moment.ISO_8601).tz(TIMEZONE).valueOf();
// return some string that should be "last"
if (a === '{{ _("now") }}') {
return 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'+a;

View file

@ -85,6 +85,13 @@
</div>
<span class="help-inline text-default">{{ _('See <a href="%(url)s">here</a> for available formats', url='http://momentjs.com/docs/#/displaying/') }}</span>
</div>
<div class="form-group">
<label for="timezone" class="col-lg-2 control-label">{{ _('Timezone') }}</label>
<div class="col-lg-3">
<input class="form-control" name="timezone" id="timezone" type="text" ng-model="prefs.timezone" placeholder="{{ _('UI timezone') }}">
</div>
<span class="help-inline text-default">{{ _('See <a href="%(url)s">here</a> for available formats', url='https://momentjs.com/timezone/') }}</span>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" class="btn btn-primary"><i class="fa fa-fw fa-floppy-o" aria-hidden="true"></i>{{ _('Save') }}</button>