11/*jshint esversion: 6 */ 
22
33function  nrF ( )  { 
4-     Alpine . data ( 'numberRangeFilter' ,  ( wire ,  filterKey ,  parentElementPath ,  filterConfig ,  childElementRoot )  =>  ( { 
5-         allFilters : wire . entangle ( 'appliedFilters' ,   false ) , 
4+     Alpine . data ( 'numberRangeFilter' ,  ( wire ,  filterKey ,  dataTableFingerprint ,   parentElementPath ,  filterConfig ,  childElementRoot )  =>  ( { 
5+         allFilters : wire . entangle ( 'appliedFilters' ) , 
66        originalMin : 0 , 
77        originalMax : 100 , 
88        filterMin : 0 , 
99        filterMax : 100 , 
1010        currentMin : 0 , 
1111        currentMax : 100 , 
1212        hasUpdate : false , 
13-         wireValues : wire . entangle ( 'appliedFilters.'  +  filterKey ,  false ) , 
13+         listeners : [ ] , 
14+         wireValues : null , 
1415        defaultMin : filterConfig [ 'minRange' ] , 
1516        defaultMax : filterConfig [ 'maxRange' ] , 
1617        restrictUpdates : false , 
1718        initialiseStyles ( ) 
1819        { 
1920            let  numRangeFilterContainer  =  document . getElementById ( parentElementPath ) ; 
2021            numRangeFilterContainer . style . setProperty ( '--value-a' ,  this . wireValues [ 'min' ]  ??  this . filterMin ) ; 
21-             numRangeFilterContainer . style . setProperty ( '--text-value-a' ,  JSON . stringify ( this . wireValues [ 'min' ]  ??  this . filterMin ) ) ; 
22+             numRangeFilterContainer . style . setProperty ( '--text-value-a' ,  '"' + JSON . stringify ( this . wireValues [ 'min' ]  ??  this . filterMin ) + '"' ) ; 
2223            numRangeFilterContainer . style . setProperty ( '--value-b' ,  this . wireValues [ 'max' ]  ??  this . filterMax ) ; 
2324            numRangeFilterContainer . style . setProperty ( '--text-value-b' ,  JSON . stringify ( this . wireValues [ 'max' ]  ??  this . filterMax ) ) ; 
2425        } , 
2526        updateStyles ( filterMin ,  filterMax )  { 
27+             let  tmpFilterMin  =  parseInt ( filterMin ) ; 
28+             let  tmpFilterMax  =  parseInt ( filterMax ) ; 
29+ 
2630            let  numRangeFilterContainer  =  document . getElementById ( parentElementPath ) ; 
27-             numRangeFilterContainer . style . setProperty ( '--value-a' ,  filterMin ) ; 
28-             numRangeFilterContainer . style . setProperty ( '--text-value-a' ,  JSON . stringify ( filterMin ) ) ; 
29-             numRangeFilterContainer . style . setProperty ( '--value-b' ,  filterMax ) ; 
30-             numRangeFilterContainer . style . setProperty ( '--text-value-b' ,  JSON . stringify ( filterMax ) ) ; 
31+             numRangeFilterContainer . style . setProperty ( '--value-a' ,  tmpFilterMin ) ; 
32+             numRangeFilterContainer . style . setProperty ( '--text-value-a' ,  '"' + JSON . stringify ( tmpFilterMin ) + '"' ) ; 
33+             numRangeFilterContainer . style . setProperty ( '--value-b' ,  tmpFilterMax ) ; 
34+             numRangeFilterContainer . style . setProperty ( '--text-value-b' ,  '"' + JSON . stringify ( tmpFilterMax ) + '"' ) ; 
3135        } , 
3236        setupWire ( )  { 
33-             if  ( this . wireValues  !==  undefined )  { 
37+             if  ( this . wireValues  !==  null )  { 
3438                this . filterMin  =  this . originalMin  =  ( this . wireValues [ 'min' ]  !==  undefined )  ? this . wireValues [ 'min' ]  : this . defaultMin ; 
3539                this . filterMax  =  this . originalMax  =  ( this . wireValues [ 'max' ]  !==  undefined )  ? this . wireValues [ 'max' ]  : this . defaultMax ; 
3640            }  else  { 
@@ -57,17 +61,64 @@ function nrF() {
5761            } 
5862            this . updateStyles ( this . filterMin , this . filterMax ) ; 
5963        } , 
64+         changeMin ( value ) 
65+         { 
66+             this . filterMin  =  value ; 
67+             let  numRangeFilterContainer  =  document . getElementById ( parentElementPath ) ; 
68+             numRangeFilterContainer . style . setProperty ( '--value-a' ,  value ) ; 
69+             numRangeFilterContainer . style . setProperty ( '--text-value-a' ,  JSON . stringify ( value ) ) ; 
70+         } , 
71+         changeMax ( value ) 
72+         { 
73+             this . filterMax  =  value ; 
74+             let  numRangeFilterContainer  =  document . getElementById ( parentElementPath ) ; 
75+             numRangeFilterContainer . style . setProperty ( '--value-b' ,  value ) ; 
76+             numRangeFilterContainer . style . setProperty ( '--text-value-b' ,  JSON . stringify ( value ) ) ; 
77+         } , 
6078        updateWireable ( )  { 
6179            if  ( this . hasUpdate )  { 
6280                this . hasUpdate  =  false ; 
6381                this . wireValues  =  {  'min' : this . filterMin ,  'max' : this . filterMax  } ; 
6482                wire . set ( 'appliedFilters.'  +  filterKey ,  this . wireValues ) ; 
6583            } 
6684        } , 
85+         toggleStatusWithReset ( ) 
86+         { 
87+             this . filterMin  =  this . defaultMin ; 
88+             this . filterMax  =  this . defaultMax ; 
89+             this . updateStyles ( this . filterMin , this . filterMax ) ; 
90+             wire . call ( 'resetFilter' , filterKey ) ; 
91+         } , 
6792        init ( )  { 
93+             this . wireValues =  wire . get ( 'appliedFilters.'  +  filterKey )  ??  {  'min' : this . filterMin ,  'max' : this . filterMax  } ; 
6894            this . initialiseStyles ( ) ; 
6995            this . setupWire ( ) ; 
7096            this . $watch ( 'allFilters' ,  value  =>  this . setupWire ( ) ) ; 
97+             this . listeners . push ( 
98+                 Livewire . on ( 'clear-filters' ,  ( detail )  =>  { 
99+ 
100+                     if ( detail . dataTableFingerprint  ==  dataTableFingerprint  &&  detail . filterKey  ==  filterKey )  {  
101+                         this . wireValues  =  {  'min' : this . defaultMin ,  'max' : this . defaultMax  } ; 
102+                         this . updateStyles ( this . defaultMin ,  this . defaultMax ) ; 
103+ 
104+                     } 
105+             } ) ) ; 
106+             this . listeners . push ( 
107+ 
108+                 Livewire . on ( 'filter-was-set' ,  ( detail )  =>  { 
109+ 
110+                     if ( detail . dataTableFingerprint  ==  dataTableFingerprint  &&  detail . filterKey  ==  filterKey )  {  
111+                         this . wireValues  =  {  'min' : this . defaultMin ,  'max' : this . defaultMax  } ; 
112+                         this . updateStyles ( this . defaultMin ,  this . defaultMax ) ; 
113+ 
114+                     } 
115+                 } ) 
116+             ) ; 
117+         } , 
118+         destroy ( )  { 
119+             this . listeners . forEach ( ( listener )  =>  { 
120+                 listener ( ) ; 
121+             } ) ; 
71122        } , 
72123    } ) ) ; 
73124} 
0 commit comments