Skip to content

Commit

Permalink
Add: organization setting for time format (#3754)
Browse files Browse the repository at this point in the history
* Support for time format

* Add selects test

* Rename into date_time_format_config
  • Loading branch information
yusukegoto authored and arikfr committed May 5, 2019
1 parent 72d0031 commit 2cd1b07
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
10 changes: 9 additions & 1 deletion client/app/pages/settings/organization.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ <h3 class="m-t-0">General</h3>
<label>
Date Format
</label>
<select class="form-control" ng-model="$ctrl.settings.date_format" ng-change="$ctrl.update('date_format')">
<select class="form-control" ng-model="$ctrl.settings.date_format" ng-change="$ctrl.update('date_format')" data-test="DateFormatSelect">
<option ng-repeat="date_format in $ctrl.dateFormatList" value="{{date_format}}">{{date_format}}</option>
</select>
</p>
<p>
<label>
Time Format
</label>
<select class="form-control" ng-model="$ctrl.settings.time_format" ng-change="$ctrl.update('time_format')" data-test="TimeFormatSelect">
<option ng-repeat="time_format in $ctrl.timeFormatList" value="{{time_format}}">{{time_format}}</option>
</select>
</p>

<p>
<h4>Feature Flags</h4>
Expand Down
1 change: 1 addition & 0 deletions client/app/pages/settings/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function OrganizationSettingsCtrl($http, clientConfig, Events) {
};

this.dateFormatList = clientConfig.dateFormatList;
this.timeFormatList = clientConfig.timeFormatList;
this.googleLoginEnabled = clientConfig.googleLoginEnabled;

// eslint-disable-next-line max-len
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ describe('Settings', () => {

it('renders the page and takes a screenshot', () => {
cy.getByTestId('OrganizationSettings').within(() => {
cy.get('select').should('have.value', 'DD/MM/YY');
cy.getByTestId('DateFormatSelect').should('have.value', 'DD/MM/YY');
cy.getByTestId('TimeFormatSelect').should('have.value', 'HH:mm');
});

cy.percySnapshot('Organization Settings');
Expand Down
9 changes: 6 additions & 3 deletions redash/handlers/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,16 @@ def base_href():
return base_href


def date_format_config():
def date_time_format_config():
date_format = current_org.get_setting('date_format')
date_format_list = set(["DD/MM/YY", "MM/DD/YY", "YYYY-MM-DD", settings.DATE_FORMAT])
time_format = current_org.get_setting('time_format')
time_format_list = set(["HH:mm", "MM:mm:ss", "HH:mm:ss.SSS", settings.TIME_FORMAT])
return {
'dateFormat': date_format,
'dateFormatList': list(date_format_list),
'dateTimeFormat': "{0} HH:mm".format(date_format),
'timeFormatList': list(time_format_list),
'dateTimeFormat': "{0} {1}".format(date_format, time_format),
}


Expand Down Expand Up @@ -237,7 +240,7 @@ def client_config():
client_config.update({
'basePath': base_href()
})
client_config.update(date_format_config())
client_config.update(date_time_format_config())
client_config.update(number_format_config())

return client_config
Expand Down
2 changes: 1 addition & 1 deletion redash/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flask_talisman import talisman

from .helpers import fix_assets_path, array_from_string, parse_boolean, int_or_none, set_from_string
from .organization import DATE_FORMAT # noqa
from .organization import DATE_FORMAT, TIME_FORMAT # noqa

REDIS_URL = os.environ.get('REDASH_REDIS_URL', os.environ.get('REDIS_URL', "redis://localhost:6379/0"))
PROXIES_COUNT = int(os.environ.get('REDASH_PROXIES_COUNT', "1"))
Expand Down
2 changes: 2 additions & 0 deletions redash/settings/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
SAML_LOGIN_ENABLED = SAML_METADATA_URL != ""

DATE_FORMAT = os.environ.get("REDASH_DATE_FORMAT", "DD/MM/YY")
TIME_FORMAT = os.environ.get("REDASH_TIME_FORMAT", "HH:mm")
INTEGER_FORMAT = os.environ.get("REDASH_INTEGER_FORMAT", "0,0")
FLOAT_FORMAT = os.environ.get("REDASH_FLOAT_FORMAT", "0,0.00")

Expand All @@ -37,6 +38,7 @@
"auth_saml_metadata_url": SAML_METADATA_URL,
"auth_saml_nameid_format": SAML_NAMEID_FORMAT,
"date_format": DATE_FORMAT,
"time_format": TIME_FORMAT,
"integer_format": INTEGER_FORMAT,
"float_format": FLOAT_FORMAT,
"auth_jwt_login_enabled": JWT_LOGIN_ENABLED,
Expand Down

0 comments on commit 2cd1b07

Please sign in to comment.