mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 03:10:42 -03:30
Make usage of moment consistent throughout app
This always includes the user's language preference when loading moment. It also deletes the moment global, so if you don't require it somehow you will get an error trying to call `moment`'. This is setup to provide moment to both angular and plain JavaScript modules. In angular modules, just add `moment` as a dependency. In plain js use `import moment from 'tower/shared/moment/moment';`.
This commit is contained in:
parent
fdb8fdf24a
commit
884423f86c
@ -37,6 +37,7 @@ import setupMenu from 'tower/setup-menu/main';
|
||||
import mainMenu from 'tower/main-menu/main';
|
||||
import browserData from 'tower/browser-data/main';
|
||||
import dashboard from 'tower/dashboard/main';
|
||||
import moment from 'tower/shared/moment/main';
|
||||
|
||||
import {JobDetailController} from 'tower/controllers/JobDetail';
|
||||
import {JobStdoutController} from 'tower/controllers/JobStdout';
|
||||
@ -82,6 +83,7 @@ var tower = angular.module('Tower', [
|
||||
setupMenu.name,
|
||||
mainMenu.name,
|
||||
dashboard.name,
|
||||
moment.name,
|
||||
'AuthService',
|
||||
'Utilities',
|
||||
'LicenseHelper',
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
/* jshint unused: vars */
|
||||
export default
|
||||
[function JobsList() {
|
||||
['moment',
|
||||
function JobsList(moment) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
link: link,
|
||||
|
||||
@ -4,16 +4,15 @@
|
||||
* All Rights Reserved
|
||||
*************************************************/
|
||||
|
||||
angular.module('longDateFilter', []).filter('longDate', function() {
|
||||
return function(input) {
|
||||
|
||||
// navigator.language is available in all modern browsers.
|
||||
// however navigator.languages is a new technology that
|
||||
// lists the user's preferred languages, the first in the array
|
||||
// being the user's top choice. navigator.languages is currently
|
||||
// comptabile with chrome>v32, ffox>32, but not IE/Safari
|
||||
var lang = navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage),
|
||||
date = moment(input).locale(lang);
|
||||
function longDateFilter(moment, input) {
|
||||
var date = moment(input);
|
||||
return date.format('l LTS');
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
angular.module('longDateFilter', [])
|
||||
.filter('longDate',
|
||||
[ 'moment',
|
||||
function(moment) {
|
||||
return _.partial(longDateFilter, moment);
|
||||
}
|
||||
]);
|
||||
|
||||
9
awx/ui/static/js/shared/moment/main.js
Normal file
9
awx/ui/static/js/shared/moment/main.js
Normal file
@ -0,0 +1,9 @@
|
||||
import newMoment from './moment';
|
||||
|
||||
export default
|
||||
angular.module('moment', ['angularMoment'])
|
||||
.config(function() {
|
||||
// Remove the global variable for moment
|
||||
delete window.moment;
|
||||
})
|
||||
.constant('moment', newMoment);
|
||||
18
awx/ui/static/js/shared/moment/moment.js
Normal file
18
awx/ui/static/js/shared/moment/moment.js
Normal file
@ -0,0 +1,18 @@
|
||||
var originalMoment = window.moment;
|
||||
|
||||
export default function moment() {
|
||||
|
||||
// navigator.language is available in all modern browsers.
|
||||
// however navigator.languages is a new technology that
|
||||
// lists the user's preferred languages, the first in the array
|
||||
// being the user's top choice. navigator.languages is currently
|
||||
// comptabile with chrome>v32, ffox>32, but not IE/Safari
|
||||
var lang = navigator.languages ?
|
||||
navigator.languages[0] :
|
||||
(navigator.language || navigator.userLanguage);
|
||||
|
||||
originalMoment.locale(lang);
|
||||
return originalMoment.apply(this, arguments);
|
||||
}
|
||||
|
||||
|
||||
18
awx/ui/static/js/shared/moment/moment.value.js
Normal file
18
awx/ui/static/js/shared/moment/moment.value.js
Normal file
@ -0,0 +1,18 @@
|
||||
var originalMoment = window.moment;
|
||||
|
||||
export default function moment() {
|
||||
|
||||
// navigator.language is available in all modern browsers.
|
||||
// however navigator.languages is a new technology that
|
||||
// lists the user's preferred languages, the first in the array
|
||||
// being the user's top choice. navigator.languages is currently
|
||||
// comptabile with chrome>v32, ffox>32, but not IE/Safari
|
||||
var lang = navigator.languages ?
|
||||
navigator.languages[0] :
|
||||
(navigator.language || navigator.userLanguage);
|
||||
|
||||
originalMoment.locale(lang);
|
||||
return originalMoment.apply(this, arguments);
|
||||
}
|
||||
|
||||
|
||||
@ -7,8 +7,8 @@
|
||||
/* jshint unused: vars */
|
||||
|
||||
export default
|
||||
[ '$rootScope',
|
||||
function() {
|
||||
[ 'moment',
|
||||
function(moment) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
|
||||
@ -16,8 +16,7 @@ import datePicker from './date-picker/main';
|
||||
|
||||
export default
|
||||
angular.module('systemTracking',
|
||||
[ 'angularMoment',
|
||||
utilities.name,
|
||||
[ utilities.name,
|
||||
shared.name,
|
||||
datePicker.name
|
||||
])
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
* All Rights Reserved
|
||||
*************************************************/
|
||||
|
||||
import moment from 'tower/shared/moment/moment';
|
||||
|
||||
export function searchDateRange(dateString) {
|
||||
var date;
|
||||
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
|
||||
export default
|
||||
[ 'amDateFormatFilter',
|
||||
function(dateFormat) {
|
||||
'moment',
|
||||
function(dateFormat, moment) {
|
||||
return function(string, format) {
|
||||
if (moment.isMoment(string)) {
|
||||
return dateFormat(string, format);
|
||||
|
||||
@ -15,7 +15,7 @@ function controller($rootScope,
|
||||
initialFactData,
|
||||
getDataForComparison,
|
||||
waitIndicator,
|
||||
|
||||
moment,
|
||||
_) {
|
||||
// var inventoryId = $routeParams.id;
|
||||
var hostIds = $routeParams.hosts.split(',');
|
||||
@ -201,6 +201,7 @@ export default
|
||||
'factScanData',
|
||||
'getDataForComparison',
|
||||
'Wait',
|
||||
'moment',
|
||||
'lodashAsPromised',
|
||||
controller
|
||||
];
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
*************************************************/
|
||||
|
||||
import {searchDateRange} from './search-date-range';
|
||||
import moment from 'tower/shared/moment/moment';
|
||||
|
||||
export default {
|
||||
name: 'systemTracking',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user