|
| 1 | +<div class="cmd cmd-widget" data-type="info" data-subtype="numeric" data-template="tile" data-cmd_id="#id#" data-cmd_uid="#uid#" data-version="#version#" data-eqLogic_id="#eqLogic_id#"> |
| 2 | + <div class="title #hide_name#"> |
| 3 | + <div class="cmdName">#name_display#</div> |
| 4 | + </div> |
| 5 | + <!--<span class="#hide_history#">{{La commande source n'est pas historisée}}</span>--> |
| 6 | + <div class="value"> |
| 7 | + <div class="col-xs-12 center-block"> |
| 8 | + <a class="#hide_history#" onclick="jeeDialog.dialog({id: 'md_cmdHistory', title: '{{Historique}}', contentUrl: 'index.php?v=d&modal=cmd.history&id=#id#&derive=1&groupingType=none'})"> |
| 9 | + <span class="conteneurStats"> |
| 10 | + </span> |
| 11 | + </a> |
| 12 | + <a onclick="jeeDialog.dialog({id: 'md_cmdHistory', title: '{{Historique}}', contentUrl: 'index.php?v=d&modal=cmd.history&id=#id#&derive=0&groupingType=none'})"> |
| 13 | + Total : <span class="state state_mini"></span><span class="unit">#unite#</span> |
| 14 | + </a> |
| 15 | + </div> |
| 16 | + </div> |
| 17 | + <template> |
| 18 | + <div>tabJour : {{Jours a afficher.}} {{Défaut}} : 0,1,2,3,4</div> |
| 19 | + <div>tabSemaine : {{Semaines a afficher.}} {{Défaut}} : 0,1</div> |
| 20 | + </template> |
| 21 | + <script> |
| 22 | + var hasNow = false; |
| 23 | + if(dateMaj === undefined) |
| 24 | + var dateMaj = []; |
| 25 | + dateMaj[#id#] = 0; |
| 26 | + if(cacheValue === undefined) |
| 27 | + var cacheValue = []; |
| 28 | + if(recupCache === undefined) |
| 29 | + var recupCache = 0; |
| 30 | + |
| 31 | + if ($.issetWidgetOptParam('#tabJour#', 'tabJour')) |
| 32 | + var tabJour = eval('[#tabJour#]'); |
| 33 | + else |
| 34 | + var tabJour = [0,1,2,3,4,5,6,7]; |
| 35 | + if ($.issetWidgetOptParam('#tabSemaine#', 'tabSemaine')) |
| 36 | + var tabSemaine = eval('[#tabSemaine#]'); |
| 37 | + else |
| 38 | + var tabSemaine = [0,1]; |
| 39 | + |
| 40 | + for(var j in tabJour){ |
| 41 | + var html = ' : <span title="{{Histo}}" class="tooltips J'+tabJour[j]+'Ty cursor"></span>'; |
| 42 | + if(tabJour[j] == 0){ |
| 43 | + hasNow = true; |
| 44 | + html = '<span class="state_max">J' + html + '</span><br/>'; |
| 45 | + } |
| 46 | + else |
| 47 | + html = 'J-'+ tabJour[j] + html + '<br/>'; |
| 48 | + |
| 49 | + $('.cmd[data-cmd_id=#id#] .conteneurStats').append(html); |
| 50 | + } |
| 51 | + for(var s in tabSemaine){ |
| 52 | + var html = ' : <span title="{{Histo}}" class="tooltips S'+tabSemaine[s]+'Ty cursor"></span>'; |
| 53 | + if(tabSemaine[s] == 0) |
| 54 | + html = 'S' + html + '<br/>'; |
| 55 | + else |
| 56 | + html = 'S-'+ tabSemaine[s] + html + '<br/>'; |
| 57 | + |
| 58 | + $('.cmd[data-cmd_id=#id#] .conteneurStats').append(html); |
| 59 | + } |
| 60 | + |
| 61 | + |
| 62 | + jeedom.cmd.addUpdateFunction('#id#',function(_options) { |
| 63 | + var unite = 'nc'; |
| 64 | + $('.cmd[data-cmd_id=#id#]').attr('title', '{{Date de valeur}} : '+_options.valueDate+'<br/>{{Date de collecte}} : '+_options.collectDate) |
| 65 | + $('.cmd[data-cmd_id=#id#] .state').empty().append(_options.display_value) |
| 66 | + $('.cmd[data-cmd_id=#id#] .unit').empty().append(_options.unit) |
| 67 | + |
| 68 | + var dateNow = new Date(); |
| 69 | + if(dateMaj[#id#] < dateNow.getDate()){//rafraichissement que tous les jours |
| 70 | + cacheValue[#id#] = []; |
| 71 | + debug('eraseCache', 0); |
| 72 | + |
| 73 | + for(var j in tabJour){ |
| 74 | + if(j>0){ |
| 75 | + getHisto(tabJour[j],1, 'J'+tabJour[j]+'Ty'); |
| 76 | + } |
| 77 | + } |
| 78 | + for(var s in tabSemaine){ |
| 79 | + getHisto((tabSemaine[s]+1)*7,7, 'S'+tabSemaine[s]+'Ty'); |
| 80 | + } |
| 81 | + |
| 82 | + dateMaj[#id#] = dateNow.getDate(); |
| 83 | + } |
| 84 | + if(hasNow) |
| 85 | + getHisto(0,1, 'J0Ty'); |
| 86 | + |
| 87 | + function debug(msg, nbDay){ |
| 88 | +// console.log(msg, nbDay, 'id', #id#); |
| 89 | + } |
| 90 | + |
| 91 | + |
| 92 | + function getHisto(nbDayOldValue, nbDayComparaison, classResponse){ |
| 93 | + var nbDayNewValueFin = nbDayOldValue-nbDayComparaison; |
| 94 | + var nbDayOldValueFin = nbDayOldValue; |
| 95 | +// var unite = _options.unit.replace('M', '').replace('k', ''); |
| 96 | + |
| 97 | + function getValue(nbDay, success){ |
| 98 | + if(cacheValue[#id#][nbDay] === undefined || nbDay < 0){//nbDay < 0 pour ne pas utiliser le cache de aujourd'hui |
| 99 | + debug('get', nbDay) ; |
| 100 | + cacheValue[#id#][nbDay] = 'run'; |
| 101 | + jeedom.history.getLast({ |
| 102 | + cmd_id: #id#, |
| 103 | + time : moment().subtract(nbDay, 'days').format('YYYY-MM-DD 00:01:00'), |
| 104 | + error: function (error) { |
| 105 | + console.log('error old value cmd_id #id#', error); |
| 106 | + }, |
| 107 | + success: function (result) { |
| 108 | + cacheValue[#id#][nbDay] = result.value; |
| 109 | + unite = result.unite |
| 110 | + debug('save', nbDay); |
| 111 | + success(); |
| 112 | + }, |
| 113 | + error: function (error) { |
| 114 | + console.log('error new value cmd_id #id#', error); |
| 115 | + } |
| 116 | + }); |
| 117 | + } |
| 118 | + else{ |
| 119 | + attendreValeur(nbDay, success); |
| 120 | + } |
| 121 | + } |
| 122 | + function attendreValeur(nbDay, success){ |
| 123 | + if(cacheValue[#id#][nbDay] == 'run'){ |
| 124 | + debug('attente', nbDay); |
| 125 | + setTimeout(function(){ |
| 126 | + attendreValeur(nbDay, success); |
| 127 | + }, 200); |
| 128 | + } |
| 129 | + else{ |
| 130 | + recupCache++; |
| 131 | + success(); |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + getValue(nbDayNewValueFin, function(){ |
| 136 | + getValue(nbDayOldValueFin, function(){ |
| 137 | + traiteValue(cacheValue[#id#][nbDayNewValueFin] - cacheValue[#id#][nbDayOldValueFin], unite, '.cmd[data-cmd_id=#id#] .'+classResponse); |
| 138 | + }); |
| 139 | + }); |
| 140 | + } |
| 141 | + }); |
| 142 | + |
| 143 | + function traiteValue(value, unite, conteneur){ |
| 144 | + if(value > 10000 || value < -1000){ |
| 145 | + value = value / 1000; |
| 146 | + if(value > 10000){ |
| 147 | + value = value / 1000; |
| 148 | + unite = 'M'+unite; |
| 149 | + } |
| 150 | + else{ |
| 151 | + unite = 'k'+unite; |
| 152 | + } |
| 153 | + } |
| 154 | + value = Math.round(value*100)/100 +' '+ unite; |
| 155 | + $(conteneur).empty().append(value); |
| 156 | + } |
| 157 | + |
| 158 | + jeedom.cmd.refreshValue([{cmd_id :'#id#',display_value: '#state#', valueDate: '#valueDate#', collectDate: '#collectDate#', alertLevel: '#alertLevel#', unit: '#unite#'}]) |
| 159 | + </script> |
| 160 | + <style> |
| 161 | + div.cmd-widget .content-sm.state_mini, .state_mini span, .state_mini{ |
| 162 | + font-size: 1em!important; |
| 163 | + font-weight: normal; |
| 164 | + height: 20px!important; |
| 165 | + } |
| 166 | + .state_max{ |
| 167 | + font-size: 1.5em; |
| 168 | + font-weight: bold; |
| 169 | + display: block; |
| 170 | + } |
| 171 | + </style> |
| 172 | +</div> |
0 commit comments