Skip to content

Commit

Permalink
Weather widget: Convert placeholders format from PHP to Moment (#2171)
Browse files Browse the repository at this point in the history
* Weather widget: Convert placeholders format from PHP to Moment
relates to xibosignage/xibo#3167

* Cypress fix
  • Loading branch information
maurofmferrao authored Oct 19, 2023
1 parent 9481d10 commit bbadc29
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cypress/e2e/campaigns.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ describe('Campaigns', function() {
// Perform your desired actions or assertions here
cy.log('Layout Loading');

cy.get('#layoutAssignments tbody tr').should('have.length', 2);

// Assign a layout
cy.get('#layoutAssignments tr:nth-child(1) a.assignItem').click();
cy.get('#layoutAssignments tr:nth-child(2) a.assignItem').click();
Expand Down
2 changes: 0 additions & 2 deletions modules/forecastio.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ moment.locale(globalOptions.locale);
var makeReplacement = (html, item) => {
// Make replacements [] with item data
return html.replace(/\[([^\]]+)\]/g, (match, key) => {
// If its [time] or [time|format] then return the time
if (key === 'time' || key.indexOf('time|') === 0) {
// If its [time|format] then return the time with format
if (key.indexOf('time|') === 0) {
return moment.unix(item.time).format(key.split('|')[1]);
}
Expand Down
52 changes: 52 additions & 0 deletions modules/src/xibo-legacy-template-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,48 @@
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/

// Based on https://github.com/octalmage/phptomoment/tree/master
const PHP_TO_MOMENT = {
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: '',
L: '',
o: 'YYYY',
Y: 'YYYY',
y: 'YY',
a: 'a',
A: 'A',
B: '',
g: 'h',
G: 'H',
h: 'hh',
H: 'HH',
i: 'mm',
s: 'ss',
u: 'SSS',
e: 'zz',
I: '',
O: '',
P: '',
T: '',
Z: '',
c: '',
r: '',
U: 'X',
'\\': '',
};

jQuery.fn.extend({
xiboLegacyTemplateRender: function(options, widget) {
// Default options
Expand Down Expand Up @@ -51,6 +93,16 @@ jQuery.fn.extend({
'data-days-offset="' + offset + '"></div>',
));
}

// Check if we have a time placeholder
$(element).html(
$(element).html().replace(/\[time\|.*?\]/g, function(match) {
const oldFormat = match.split('|')[1].replace(']', '');
const newFormat = PHP_TO_MOMENT[oldFormat];

return '[time|' + newFormat + ']';
}),
);
}

// Social Media
Expand Down
18 changes: 13 additions & 5 deletions modules/templates/forecast-static.xml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
<div class="container-row">
<div class="details-box text-center shadowed">
<div class="big-icon"><i class="wi [wicon]"></i></div>
<div class="big-day">[time|D]</div>
<div class="big-day">[time|ddd]</div>
<div class="big-temp">[temperatureRound]&deg;[temperatureUnit]</div>
</div>
<div class="forecast-container" data-days-num="4"></div>
Expand All @@ -375,7 +375,7 @@
<div class="upcoming-days shadowed">
<div class="small-icon"><i class="wi [wicon]"></i></div>
<div class="small-temp">[temperatureMaxRound] &deg; [temperatureUnit]</div>
<div class="small-day">[time|D]</div>
<div class="small-day">[time|ddd]</div>
</div>
</div>
Expand Down Expand Up @@ -2935,7 +2935,7 @@ body {
<div class="row main-panel">
<div class="offset-xs-1 weather-col col-3">
<div class="row">
<div class="date">[time|ddd] [time|d]</div>
<div class="date">[time|ddd] [time|DD]</div>
<div class="month">[time|MMM]</div>
<div class="current-temp">[temperatureRound]<sup>&deg;[temperatureUnit]</sup></div>
</div>
Expand Down Expand Up @@ -6401,6 +6401,10 @@ body {
<helpText>The color of the footer text</helpText>
<default></default>
</property>
<property id="fontSize" type="number">
<title>Font Size</title>
<default>13</default>
</property>
<property id="background-image" type="dropdown" mode="single">
<title>Background Image</title>
<helpText>The background image to use</helpText>
Expand Down Expand Up @@ -6534,7 +6538,7 @@ body {
width: 100%;
padding: 4px 0;
color: #000;
font-size: 13px;
font-size: {{fontSize}}px;
text-align: center;
background-color: white;
background-color: rgba(255, 255, 255, 0.787);
Expand Down Expand Up @@ -6589,6 +6593,10 @@ body {
<helpText>The color of the icons</helpText>
<default></default>
</property>
<property id="fontSize" type="number">
<title>Font Size</title>
<default>13</default>
</property>
<property id="background-image" type="dropdown" mode="single">
<title>Background Image</title>
<helpText>The background image to use</helpText>
Expand Down Expand Up @@ -6803,7 +6811,7 @@ text-shadow: 0px 0px 2px rgba(0, 0, 0, 0.4);
width: 100%;
padding: 4px 0;
color: #000;
font-size: 13px;
font-size: {{fontSize}}px;
text-align: center;
background-color: white;
background-color: rgba(255, 255, 255, 0.787);
Expand Down

0 comments on commit bbadc29

Please sign in to comment.