Skip to content

Commit eac652d

Browse files
authored
Merge pull request #3234 from jeedom/feat/while-block
Feat: add while block in scenario
2 parents 228b330 + 0e686ae commit eac652d

15 files changed

Lines changed: 155 additions & 63 deletions

File tree

core/class/scenarioElement.class.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ public function remove(): void {
131131
}
132132

133133
/**
134-
* @return void|bool
135-
*/
134+
* @return void|bool
135+
*/
136136
public function execute(&$_scenario = null) {
137137
if ($_scenario != null && !$_scenario->getDo()) {
138138
return;
@@ -207,6 +207,37 @@ public function execute(&$_scenario = null) {
207207
$return = $this->getSubElement('do')->execute($_scenario);
208208
}
209209
return $return;
210+
} elseif ($this->getType() == 'while') {
211+
if ($this->getSubElement('while')->getOptions('enable', 1) == 0) {
212+
return true;
213+
}
214+
$result = $this->getSubElement('while')->execute($_scenario);
215+
if (is_string($result) && strlen($result) > 1) {
216+
$_scenario->setLog($GLOBALS['JEEDOM_SCLOG_TEXT']['invalidExpr']['txt'] . $result);
217+
$expresssion_str = '';
218+
if ($this->getSubElement('while')->getSubtype() == 'condition' && is_array($this->getSubElement('while')->getExpression())) {
219+
foreach (($this->getSubElement('while')->getExpression()) as $expression) {
220+
$expresssion_str = $expression->getExpression();
221+
}
222+
}
223+
$message = __('Expression non valide', __FILE__) . ' [' . $expresssion_str . '] ' . __('trouvée dans le scénario :', __FILE__) . ' ' . $_scenario->getHumanName() . __(', résultat : ', __FILE__) . $result;
224+
$action = '<a href="/' . $_scenario->getLinkToConfiguration() . '">' . __('Scenario', __FILE__) . '</a>';
225+
$logicalId = 'invalidExprScenarioElement::' . $this->getId();
226+
message::add('scenario', $message, $action, $logicalId);
227+
return;
228+
}
229+
$endTime = time() + 3600;
230+
$return = false;
231+
while ($result) {
232+
$return = $this->getSubElement('do')->execute($_scenario);
233+
if (time() > $endTime) {
234+
$_scenario->setLog(__('[While] Arrêt de la boucle pour cause de durée d\'exécution trop longue', __FILE__));
235+
return;
236+
}
237+
sleep(1);
238+
$result = $this->getSubElement('while')->execute($_scenario);
239+
}
240+
return $return;
210241
} elseif ($this->getType() == 'in') {
211242
if ($this->getSubElement('in')->getOptions('enable', 1) == 0) {
212243
return true;
@@ -425,6 +456,9 @@ public function export() {
425456
case 'do':
426457
$return .= __('FAIRE', __FILE__);
427458
break;
459+
case 'while':
460+
$return .= __('TANT QUE', __FILE__);
461+
break;
428462
case 'code':
429463
$return .= __('CODE', __FILE__);
430464
break;

core/js/jeedom.class.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ jeedom.init = function() {
167167
cssComputedStyle.getPropertyValue('--al-danger-color'),
168168
cssComputedStyle.getPropertyValue('--scBlocCOM'),
169169
cssComputedStyle.getPropertyValue('--scBlocFOR'),
170+
cssComputedStyle.getPropertyValue('--scBlocWHILE'),
170171
cssComputedStyle.getPropertyValue('--scBlocACTION'),
171172
cssComputedStyle.getPropertyValue('--scBlocAT')
172173
]

core/php/icon.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
$root_dir = __DIR__ . '/../../data/fonts/';
2121
foreach (ls($root_dir, '*') as $dir) {
2222
if (is_dir($root_dir . $dir) && file_exists($root_dir . $dir . '/style.css')) {
23-
echo '<link rel="stylesheet" href="data/fonts/' . $dir . 'style.css?md5=' . md5($root_dir . $dir . '/style.css') . '">' . "\n";
23+
echo '<link rel="stylesheet" href="data/fonts/' . $dir . 'style.css?md5=' . md5_file($root_dir . $dir . '/style.css') . '">' . "\n";
2424
}
2525
}
2626

core/themes/core2019_Dark/desktop/colors.css

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Theme Core 2019 @Jeedom
33
colors Dark
44
*/
55
:root {
6-
--lineheight : 1.42em;
6+
--lineheight: 1.42em;
77
/* keep it as rem even when zero!!*/
88
--border-radius: 0rem;
99
--opacity: 1;
@@ -55,22 +55,23 @@ colors Dark
5555
--lb-info-color: rgb(80, 160, 180);
5656
--lb-yellow-color: rgb(210, 180, 0);
5757
--al-info-color: rgb(80, 120, 170);
58-
--al-primary-color: rgb(50, 110, 160);
58+
--al-primary-color: rgb(50, 110, 160);
5959
--al-success-color: rgb(50, 130, 60);
6060
--al-warning-color: rgb(195, 125, 40);
6161
--al-danger-color: rgb(185, 58, 62);
6262
--bt-success-color: rgb(150, 201, 39);
6363

64-
--scBlocIF: rgb(65,90,110);
65-
--scBlocElse: rgb(50,75,95);
66-
--scBlocACTION: rgb(132,120,112);
67-
--scBlocIN: rgb(75,128,62);
68-
--scBlocAT: rgb(92,122,132);
69-
--scBlocFOR: rgb(152,116,22);
70-
--scBlocCODE: rgb(160,60,25);
71-
--scBlocCOM: rgb(60,60,60);
64+
--scBlocIF: rgb(65, 90, 110);
65+
--scBlocElse: rgb(50, 75, 95);
66+
--scBlocACTION: rgb(132, 120, 112);
67+
--scBlocIN: rgb(75, 128, 62);
68+
--scBlocAT: rgb(92, 122, 132);
69+
--scBlocFOR: rgb(152, 116, 22);
70+
--scBlocWHILE: rgb(102, 82, 120);
71+
--scBlocCODE: rgb(160, 60, 25);
72+
--scBlocCOM: rgb(60, 60, 60);
7273

73-
--scBlocSep: rgb(35,35,35);
74+
--scBlocSep: rgb(35, 35, 35);
7475

7576
--shd-color: rgba(15, 15, 15, 0.55);
76-
}
77+
}

core/themes/core2019_Dark/desktop/core2019_Dark.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Theme Core 2019 @Jeedom
33
*/
44

5-
@import url("colors.css");
5+
@import url("colors.css?v=2");
66

77
::-webkit-scrollbar-thumb {
88
background: var(--btn-default-color) !important;

core/themes/core2019_Dark/mobile/core2019_Dark.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Theme Core 2019 @Jeedom
33
Mobile Dark
44
*/
55

6-
@import url("colors.css");
6+
@import url("colors.css?v=2");
77

88
::-webkit-scrollbar-thumb {
99
background: var(--btn-default-color) !important;

core/themes/core2019_Light/desktop/colors.css

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Theme Core 2019 @Jeedom
33
colors Light
44
*/
55
:root {
6-
--lineheight : 1.42em;
6+
--lineheight: 1.42em;
77
/* keep it as rem even when zero!!*/
88
--border-radius: 0rem;
99
--opacity: 1;
@@ -55,22 +55,23 @@ colors Light
5555
--lb-info-color: rgb(110, 180, 240);
5656
--lb-yellow-color: rgb(240, 215, 0);
5757
--al-info-color: rgb(100, 160, 230);
58-
--al-primary-color: rgb(60, 120, 180);
58+
--al-primary-color: rgb(60, 120, 180);
5959
--al-success-color: rgb(80, 170, 80);
6060
--al-warning-color: rgb(240, 160, 40);
6161
--al-danger-color: rgb(190, 0, 0);
6262
--bt-success-color: rgb(150, 201, 39);
6363

64-
--scBlocIF: rgb(85,110,130);
65-
--scBlocElse: rgb(70,95,115);
66-
--scBlocACTION: rgb(155,146,138);
67-
--scBlocIN: rgb(85,138,72);
68-
--scBlocAT: rgb(107,137,147);
69-
--scBlocFOR: rgb(172,136,42);
70-
--scBlocCODE: rgb(180,80,45);
71-
--scBlocCOM: rgb(70,70,70);
64+
--scBlocIF: rgb(85, 110, 130);
65+
--scBlocElse: rgb(70, 95, 115);
66+
--scBlocACTION: rgb(155, 146, 138);
67+
--scBlocIN: rgb(85, 138, 72);
68+
--scBlocAT: rgb(107, 137, 147);
69+
--scBlocFOR: rgb(172, 136, 42);
70+
--scBlocWHILE: rgb(116, 92, 134);
71+
--scBlocCODE: rgb(180, 80, 45);
72+
--scBlocCOM: rgb(70, 70, 70);
7273

73-
--scBlocSep: rgb(35,35,35);
74+
--scBlocSep: rgb(35, 35, 35);
7475

7576
--shd-color: rgba(0, 0, 0, 0.55);
76-
}
77+
}

core/themes/core2019_Light/desktop/core2019_Light.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Theme Core 2019 @Jeedom
33
*/
44

5-
@import url("colors.css");
5+
@import url("colors.css?v=2");
66

77
a,
88
span.cursor > i,
@@ -111,4 +111,3 @@ div.div_viewZone {
111111
#div_displayObject .btn:hover {
112112
color: var(--txt-color) !important;
113113
}
114-

core/themes/core2019_Light/mobile/core2019_Light.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Theme Core 2019 @Jeedom
33
Mobile Light
44
*/
55

6-
@import url("colors.css");
6+
@import url("colors.css?v=2");
77

88
/* _____________________________DASHBOARD CATEGORIES title coloring */
99
.eqLogic.eqLogic-widget {

desktop/common/js/utils.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -413,17 +413,17 @@ jeedomUtils.setJeedomTheme = function() {
413413
}
414414

415415
jeedomUtils.switchTheme = function() {
416-
var theme = 'core/themes/' + jeedom.theme.jeedom_theme_alternate + '/desktop/' + jeedom.theme.jeedom_theme_alternate + '.css'
417-
var themeShadows = 'core/themes/' + jeedom.theme.jeedom_theme_alternate + '/desktop/shadows.css'
416+
var theme = 'core/themes/' + jeedom.theme.jeedom_theme_alternate + '/desktop/' + jeedom.theme.jeedom_theme_alternate + '.css?v=' + jeeFrontEnd.jeedomVersion
417+
var themeShadows = 'core/themes/' + jeedom.theme.jeedom_theme_alternate + '/desktop/shadows.css?v=' + jeeFrontEnd.jeedomVersion
418418
var themeCook = 'alternate'
419419
var themeButton = '<i class="fas fa-adjust"></i> {{Thème principal}}'
420420
var cssTag = document.getElementById('jeedom_theme_currentcss')
421421
cssTag.setAttribute('data-nochange', 1)
422422

423-
if (cssTag.attributes.href.value.split('?md5')[0] == theme) {
423+
if (cssTag.attributes.href.value == theme) {
424424
document.body.setAttribute('data-theme', jeedom.theme.jeedom_theme_main)
425-
theme = 'core/themes/' + jeedom.theme.jeedom_theme_main + '/desktop/' + jeedom.theme.jeedom_theme_main + '.css'
426-
themeShadows = 'core/themes/' + jeedom.theme.jeedom_theme_main + '/desktop/shadows.css'
425+
theme = 'core/themes/' + jeedom.theme.jeedom_theme_main + '/desktop/' + jeedom.theme.jeedom_theme_main + '.css?v=' + jeeFrontEnd.jeedomVersion
426+
themeShadows = 'core/themes/' + jeedom.theme.jeedom_theme_main + '/desktop/shadows.css?v=' + jeeFrontEnd.jeedomVersion
427427
themeCook = 'default'
428428
themeButton = '<i class="fas fa-adjust"></i> {{Thème alternatif}}'
429429
} else {
@@ -476,7 +476,7 @@ jeedomUtils.checkThemechange = function() {
476476

477477
//Should have themeCss, check currentTheme:
478478
var theme = jeedom.theme.jeedom_theme_alternate
479-
var themeCss = 'core/themes/' + jeedom.theme.jeedom_theme_alternate + '/desktop/' + jeedom.theme.jeedom_theme_alternate + '.css'
479+
var themeCss = 'core/themes/' + jeedom.theme.jeedom_theme_alternate + '/desktop/' + jeedom.theme.jeedom_theme_alternate + '.css?v=' + jeeFrontEnd.jeedomVersion
480480
var currentTime = parseInt((new Date()).getHours() * 100 + (new Date()).getMinutes())
481481

482482
//if (parseInt(jeedom.theme.theme_start_day_hour.replace(':', '')) < currentTime && parseInt(jeedom.theme.theme_end_day_hour.replace(':', '')) > currentTime) {
@@ -487,17 +487,14 @@ jeedomUtils.checkThemechange = function() {
487487
|| jeedom.theme.theme_changeAccordingTime == 0
488488
) {
489489
theme = jeedom.theme.jeedom_theme_main
490-
themeCss = 'core/themes/' + jeedom.theme.jeedom_theme_main + '/desktop/' + jeedom.theme.jeedom_theme_main + '.css'
490+
themeCss = 'core/themes/' + jeedom.theme.jeedom_theme_main + '/desktop/' + jeedom.theme.jeedom_theme_main + '.css?v=' + jeeFrontEnd.jeedomVersion
491491
}
492492

493493
var currentTheme = document.getElementById('jeedom_theme_currentcss').getAttribute('href')
494-
if (currentTheme.indexOf('?md5') != -1) {
495-
currentTheme = currentTheme.substring(0, currentTheme.indexOf('?md5'))
496-
}
497494
if (currentTheme != themeCss) {
498495
document.body.setAttribute('data-theme', theme)
499496
document.getElementById('jeedom_theme_currentcss').setAttribute('href', themeCss)
500-
document.getElementById('shadows_theme_css')?.setAttribute('href', 'core/themes/' + theme + '/desktop/shadows.css')
497+
document.getElementById('shadows_theme_css')?.setAttribute('href', 'core/themes/' + theme + '/desktop/shadows.css?v=' + jeeFrontEnd.jeedomVersion)
501498
jeedomUtils.setBackgroundImage('')
502499
jeedomUtils.triggerThemechange()
503500
}
@@ -1140,7 +1137,7 @@ jeedomUtils.initDataTables = function(_selector, _paging, _searching,_init) {
11401137
document.querySelector(_selector).querySelectorAll('table.dataTable').forEach(_table => {
11411138
if (_table._dataTable) {
11421139
_table._dataTable.destroy()
1143-
}
1140+
}
11441141
new DataTable(_table, {
11451142
columns: _init || [{ select: 0, sort: "asc" }],
11461143
paging: _paging,
@@ -1166,7 +1163,7 @@ jeedomUtils.resizableTable = function(table) {
11661163
div.addEventListener('mousedown', function (e) {
11671164
curCol = e.target.parentElement;
11681165
nxtCol = curCol.nextElementSibling;
1169-
pageX = e.pageX;
1166+
pageX = e.pageX;
11701167
var padding = paddingDiff(curCol);
11711168
curColWidth = curCol.offsetWidth - padding;
11721169
if (nxtCol)
@@ -1186,7 +1183,7 @@ jeedomUtils.resizableTable = function(table) {
11861183
curCol.style.width = (curColWidth + diffX)+'px';
11871184
}
11881185
});
1189-
document.addEventListener('mouseup', function (e) {
1186+
document.addEventListener('mouseup', function (e) {
11901187
curCol = undefined;
11911188
nxtCol = undefined;
11921189
pageX = undefined;

0 commit comments

Comments
 (0)