@@ -51,20 +51,21 @@ app.directive('ngWheel', ['$parse', function($parse) {
51
51
52
52
53
53
app . directive ( 'refresh' , [ '$interval' , function ( $interval ) {
54
- var refreshTime_ = 0 ;
55
- var onRefresh_ = null ;
56
- var iv_ = null ;
57
54
return {
58
55
restrict :'A' ,
59
56
link :function ( scope , elem , attrs ) {
57
+ var refreshTime_ = 0 ;
58
+ var onRefresh_ = null ;
59
+ var iv_ = null ;
60
60
elem . on ( '$destroy' , function ( ) {
61
61
if ( iv_ != null ) $interval . cancel ( iv_ ) ;
62
62
} ) ;
63
63
if ( angular . isDefined ( attrs . refresh ) && ! isNaN ( parseInt ( attrs . refresh ) ) )
64
64
refreshTime_ = attrs . refresh ;
65
65
if ( angular . isDefined ( attrs . onRefresh ) && angular . isFunction ( scope [ attrs . onRefresh ] ) ) {
66
66
onRefresh_ = scope [ attrs . onRefresh ] ;
67
- iv_ = $interval ( function ( ) { onRefresh_ ( elem [ 0 ] ) } , refreshTime_ * 1000 ) ;
67
+ if ( refreshTime_ > 0 )
68
+ iv_ = $interval ( function ( ) { onRefresh_ ( elem [ 0 ] ) ; console . log ( 'refresh' , elem [ 0 ] ) } , refreshTime_ * 1000 ) ;
68
69
attrs . $observe ( 'refresh' , function ( new_iv ) {
69
70
if ( ! angular . equals ( new_iv , refreshTime_ ) ) {
70
71
if ( iv_ != null ) $interval . cancel ( iv_ ) ;
@@ -483,11 +484,6 @@ var config = app.config(['$routeProvider', '$locationProvider', '$sceDelegatePro
483
484
controller : 'fuel' ,
484
485
css : cdn + theme + 'css/modules/fuel' + ext + '?v=' + version ( )
485
486
} ) .
486
- when ( '/visors' , {
487
- templateUrl : cdn + theme + 'html/modules/visors.module.html?v=' + version ( ) ,
488
- controller : 'visors' ,
489
- css : cdn + theme + 'css/modules/visors' + ext + '?v=' + version ( )
490
- } ) .
491
487
when ( '/init/:instId1/:instId2' , {
492
488
redirectTo : function ( params ) {
493
489
app . initialInstanceUri = atou ( params . instId1 + '/' + params . instId2 ) ;
@@ -627,15 +623,19 @@ config.factory('dataService', ['$http', '$location', '$rootScope', '$window', '$
627
623
return si ;
628
624
}
629
625
630
- var setInstance = function ( inst ) {
631
- var initial = ( ! instance ) ;
632
- if ( ! instance || ( instance . id != inst . id ) ) instance = inst ;
626
+ var setSI = function ( inst ) {
633
627
//preserve the token, unless a new one is given
634
- var si = store [ instance . id ] ;
628
+ var si = store [ inst . id ] ;
635
629
if ( ! si ) si = { } ;
636
630
si . token = inst . token ? inst . token : si . token ;
637
631
si . uri = inst . uri ? inst . uri . replace ( ':443' , '' ) : si . uri ;
638
- store [ instance . id ] = fixSI ( si ) ;
632
+ store [ inst . id ] = fixSI ( si ) ;
633
+ }
634
+
635
+ var setInstance = function ( inst ) {
636
+ var initial = ( ! instance ) ;
637
+ if ( ! instance || ( instance . id != inst . id ) ) instance = inst ;
638
+ setSI ( inst ) ;
639
639
delete ( instance . token ) ;
640
640
delete ( instance . uri ) ;
641
641
if ( inst . contacts ) {
@@ -680,10 +680,18 @@ config.factory('dataService', ['$http', '$location', '$rootScope', '$window', '$
680
680
writeObject ( 'instances' , instances ) ;
681
681
writeObject ( 'store' , store ) ;
682
682
writeObject ( 'instance' , instance . id , _dk ) ;
683
- if ( ( instance . coreVersion ) && ( version ( ) != instance . coreVersion ) && ! nagged ) {
683
+ var coreVersionComparison = compareVersions ( version ( ) , instance . coreVersion ) ;
684
+ if ( ( instance . coreVersion ) && coreVersionComparison !== 0 && ! nagged ) {
684
685
nagged = true ;
685
- if ( version ( ) > instance . coreVersion ) {
686
- status ( 'A newer SmartApp version (' + version ( ) + ') is available, please update and publish all the webCoRE SmartApps in the SmartThings IDE.' , true ) ;
686
+ if ( compareVersions ( minCoreVersion , instance . coreVersion ) > 0 ) {
687
+ status ( 'A newer SmartApp version (' + version ( ) + ') is available.<br><strong>Please update and publish all the webCoRE SmartApps in the SmartThings IDE.</strong>' , true ) ;
688
+ } else if ( coreVersionComparison > 0 ) {
689
+ localforage . getItem ( 'lastOptionalVersion' ) . then ( function ( lastOptionalVersion ) {
690
+ if ( lastOptionalVersion !== version ( ) ) {
691
+ status ( 'A newer SmartApp version (' + version ( ) + ') is available.<br>This is an <strong>optional</strong> update; consider updating the webCoRE SmartApps in the SmartThings IDE.' , true ) ;
692
+ localforage . setItem ( 'lastOptionalVersion' , version ( ) ) ;
693
+ }
694
+ } ) ;
687
695
} else {
688
696
status ( 'A newer UI version (' + instance . coreVersion + ') is available, please hard reload this web page to get the newest version.' , true ) ;
689
697
}
@@ -935,6 +943,7 @@ config.factory('dataService', ['$http', '$location', '$rootScope', '$window', '$
935
943
data . endpoint = si . uri ;
936
944
data . accessToken = si . accessToken ;
937
945
if ( data . instance && ! data . instance . devices && data . instance . deviceVersion !== deviceVersion ) {
946
+ setSI ( data . instance ) ;
938
947
return dataService . getDevices ( data . instance ) . then ( function ( devices ) {
939
948
data . instance . devices = devices ;
940
949
return data ;
@@ -1003,7 +1012,7 @@ config.factory('dataService', ['$http', '$location', '$rootScope', '$window', '$
1003
1012
} ) ;
1004
1013
}
1005
1014
1006
- dataService . getPiston = function ( pistonId ) {
1015
+ dataService . getPiston = function ( pistonId , shouldSetInstance ) {
1007
1016
var inst = dataService . getPistonInstance ( pistonId ) ;
1008
1017
if ( ! inst ) { inst = dataService . getInstance ( ) } ;
1009
1018
si = store && inst ? store [ inst . id ] : null ;
@@ -1014,18 +1023,19 @@ config.factory('dataService', ['$http', '$location', '$rootScope', '$window', '$
1014
1023
// Base response is no longer included with the piston
1015
1024
. then ( function ( response ) {
1016
1025
var data = response . data ;
1017
- if ( ! data . instance ) {
1018
- return dataService . loadInstance ( inst ) . then ( function ( instData ) {
1019
- const mergedData = Object . assign ( { } , data , instData ) ;
1020
- return Object . assign ( { } , response , { data : mergedData } ) ;
1021
- } ) ;
1022
- }
1023
-
1024
- if ( data . location ) {
1025
- setLocation ( data . location ) ;
1026
- }
1027
- if ( data . instance ) {
1028
- data . instance = setInstance ( data . instance ) ;
1026
+ if ( shouldSetInstance ) {
1027
+ if ( data . location ) {
1028
+ setLocation ( data . location ) ;
1029
+ }
1030
+ data . endpoint = si . uri ;
1031
+ if ( data . instance ) {
1032
+ data . instance = setInstance ( data . instance ) ;
1033
+ } else {
1034
+ return dataService . loadInstance ( inst ) . then ( function ( instData ) {
1035
+ const mergedData = Object . assign ( { } , data , instData ) ;
1036
+ return Object . assign ( { } , response , { data : mergedData } ) ;
1037
+ } ) ;
1038
+ }
1029
1039
}
1030
1040
return response ;
1031
1041
} )
@@ -1810,17 +1820,17 @@ function fixTime(timestamp) {
1810
1820
return timestamp ;
1811
1821
}
1812
1822
1813
- function utcToString ( timestamp ) {
1823
+ var utcToString = nanomemoize ( function utcToString ( timestamp ) {
1814
1824
return ( new Date ( fixTime ( timestamp ) ) ) . toLocaleString ( ) ;
1815
- }
1825
+ } ) ;
1816
1826
1817
- function utcToTimeString ( timestamp ) {
1827
+ var utcToTimeString = nanomemoize ( function utcToTimeString ( timestamp ) {
1818
1828
return ( new Date ( fixTime ( timestamp ) ) ) . toLocaleTimeString ( ) ;
1819
- }
1829
+ } ) ;
1820
1830
1821
- function utcToDateString ( timestamp ) {
1831
+ var utcToDateString = nanomemoize ( function utcToDateString ( timestamp ) {
1822
1832
return ( new Date ( fixTime ( timestamp ) ) ) . toLocaleDateString ( ) ;
1823
- }
1833
+ } ) ;
1824
1834
1825
1835
function timeSince ( time ) {
1826
1836
if ( ! time ) return "never" ;
@@ -1913,7 +1923,10 @@ function adjustTimeOffset(time) {
1913
1923
1914
1924
1915
1925
1916
- function renderString ( $sce , value ) {
1926
+ app . filter ( 'renderString' , [ '$sce' , function ( $sce ) {
1927
+ return renderString . bind ( null , $sce ) ;
1928
+ } ] ) ;
1929
+ var renderString = nanomemoize ( function renderString ( $sce , value ) {
1917
1930
var i = 0 ;
1918
1931
if ( ! value ) return '' ;
1919
1932
var meta = { type : null , options : { } } ;
@@ -2055,7 +2068,7 @@ function renderString($sce, value) {
2055
2068
var result = $sce . trustAsHtml ( meta . html ) ;
2056
2069
result . meta = meta ;
2057
2070
return result ;
2058
- } ;
2071
+ } ) ;
2059
2072
2060
2073
var wuIconForTwcCode = {
2061
2074
0 : 'tstorms' , // Tornado
@@ -2221,6 +2234,35 @@ function atou(str) {
2221
2234
return decodeURIComponent ( escape ( window . atob ( str ) ) ) ;
2222
2235
}
2223
2236
2237
+ // Split version parts for numeric and lexical comparison (e.g. v0.9.1ff < v0.10.1ff)
2238
+ function comparableVersion ( version ) {
2239
+ var parts = version . split ( '.' ) ;
2240
+ return [
2241
+ // Numeric major version, without v prefix
2242
+ + parts [ 0 ] . substr ( 1 ) ,
2243
+ // Numeric minor version
2244
+ + parts [ 1 ] ,
2245
+ // Hex build number remains a string
2246
+ parts [ 2 ] ,
2247
+ ] ;
2248
+ }
2249
+
2250
+ // Compare webCoRE version number format for sorting from oldest to newest
2251
+ function compareVersions ( a , b ) {
2252
+ var aParts = comparableVersion ( a ) ;
2253
+ var bParts = comparableVersion ( b ) ;
2254
+
2255
+ for ( var i = 0 ; i < aParts . length ; i ++ ) {
2256
+ if ( aParts [ i ] < bParts [ i ] ) {
2257
+ return - 1 ;
2258
+ }
2259
+ if ( aParts [ i ] > bParts [ i ] ) {
2260
+ return 1 ;
2261
+ }
2262
+ }
2263
+ return 0 ;
2264
+ }
2265
+
2224
2266
//document.documentElement.addEventListener('touchstart', function (event) {
2225
2267
// if (event.touches.length > 1) {
2226
2268
// event.preventDefault();
@@ -2308,4 +2350,6 @@ if (!String.prototype.endsWith) {
2308
2350
} ;
2309
2351
}
2310
2352
2311
- version = function ( ) { return 'v0.3.110.20191009' ; } ;
2353
+ // Minimum version to display as an optional upgrade
2354
+ minCoreVersion = 'v0.3.110.20191009' ;
2355
+ version = function ( ) { return 'v0.3.111.20210130' ; } ;
0 commit comments