diff --git a/modules/assets/template-thumbnails/forecast/elements/weather-date.png b/modules/assets/template-thumbnails/forecast/elements/weather-date.png new file mode 100644 index 0000000000..427e66c3ce Binary files /dev/null and b/modules/assets/template-thumbnails/forecast/elements/weather-date.png differ diff --git a/modules/templates/forecast-elements.xml b/modules/templates/forecast-elements.xml index a0b27a94d0..06beaf9a65 100644 --- a/modules/templates/forecast-elements.xml +++ b/modules/templates/forecast-elements.xml @@ -262,6 +262,22 @@ if (meta && meta.hasOwnProperty('Attribution')) { weather-condition-bg-image 480 600 + + + Round Border + 0 + Should the square have rounded corners? + + + Border Radius + 20 + + + 1 + + + + element forecast true - weather-date-thumb + weather-date 420 100 + + + Date Format + M d + + - + \ No newline at end of file diff --git a/modules/templates/global-elements.xml b/modules/templates/global-elements.xml index c971d51f9f..8afcccd0bc 100644 --- a/modules/templates/global-elements.xml +++ b/modules/templates/global-elements.xml @@ -200,7 +200,7 @@ Date Format - DD/MM/YYYY HH:mm:ss + d/m/Y H:i:s Font Family diff --git a/ui/bundle_tools.js b/ui/bundle_tools.js index d6bbb6d181..942fd1dc58 100644 --- a/ui/bundle_tools.js +++ b/ui/bundle_tools.js @@ -1,3 +1,4 @@ // --- Add global TOOLS for the CMS ---- window.formHelpers = require('./src/helpers/form-helpers.js'); window.transformer = require('./src/helpers/transformer.js'); +window.DateFormatHelper = require('./src/helpers/date-format-helper.js'); diff --git a/ui/src/helpers/date-format-helper.js b/ui/src/helpers/date-format-helper.js new file mode 100644 index 0000000000..850bad7921 --- /dev/null +++ b/ui/src/helpers/date-format-helper.js @@ -0,0 +1,65 @@ +const DateFormatHelper = function(options) { + this.timezone = null; + this.systemFormat = 'Y-m-d H:i:s'; + + this.convertPhpToMomentFormat = function(format) { + if (String(format).length === 0) { + return ''; + } + + const replacements = { + d: 'DD', + D: 'ddd', + j: 'D', + l: 'dddd', + N: 'E', + S: 'o', + w: 'e', + z: 'DDD', + W: 'W', + F: 'MMMM', + m: 'MM', + M: 'MMM', + n: 'M', + t: '', // no equivalent + L: '', // no equivalent + o: 'YYYY', + Y: 'YYYY', + y: 'YY', + a: 'a', + A: 'A', + B: '', // no equivalent + g: 'h', + G: 'H', + h: 'hh', + H: 'HH', + i: 'mm', + s: 'ss', + u: 'SSS', + e: 'zz', // deprecated since version 1.6.0 of moment.js + I: '', // no equivalent + O: '', // no equivalent + P: '', // no equivalent + T: '', // no equivalent + Z: '', // no equivalent + c: '', // no equivalent + r: '', // no equivalent + U: 'X', + }; + let convertedFormat = ''; + + String(format).split('').forEach(function(char) { + if (Object.keys(replacements).indexOf(char) === -1) { + convertedFormat += char; + } else { + convertedFormat += replacements[char]; + } + }); + + return convertedFormat; + }; + + return this; +}; + +module.exports = new DateFormatHelper(); diff --git a/ui/src/layout-editor/viewer.js b/ui/src/layout-editor/viewer.js index 2a760b52cf..5340f67267 100644 --- a/ui/src/layout-editor/viewer.js +++ b/ui/src/layout-editor/viewer.js @@ -1388,6 +1388,15 @@ Viewer.prototype.renderElementContent = function( // Add property to properties object convertedProperties[property.id] = (property.value == undefined) ? property.default : property.value; + + // Convert variant=dateFormat from PHP to Moment format + if (property.id === 'dateFormat' && + convertedProperties.hasOwnProperty(property.id)) { + convertedProperties[property.id] = DateFormatHelper + .convertPhpToMomentFormat(String( + convertedProperties[property.id], + )); + } } }