@@ -5,15 +5,30 @@ $(function () {
55
66 self . settings = params [ 0 ] ;
77 self . analytics = params [ 1 ] ;
8+ self . userSettings = params [ 2 ] ;
9+ self . loginState = params [ 3 ] ;
810
911 self . PREFILTER = gettext ( "pre-filter" ) ;
12+ self . PREFILTER_WARNING_TITLE = gettext (
13+ "Pre-Filter capacity reached 70%"
14+ ) ;
15+ self . PREFILTER_WARNING_TEXT = gettext (
16+ "At this level, we highly recommend having a visual check on the pre-filter to make sure the estimation is representing the fill level of your filter. This heavily depends on the material you are processing with your device."
17+ ) ;
1018 self . CARBON_FILTER = gettext ( "main filter" ) ;
19+ self . CARBON_FILTER_WARNING_TITLE = gettext (
20+ "Main-Filter capacity reached 70%"
21+ ) ;
22+ self . CARBON_FILTER_WARNING_TEXT = gettext (
23+ "At this level, we highly recommend to have a visual check on the main-filter to make sure the estimation is representing the fill level of your filter. This heavily depends on the material you are processing with your device."
24+ ) ;
1125 self . LASER_HEAD = gettext ( "laser head" ) ;
1226 self . GANTRY = gettext ( "mechanics" ) ;
1327 self . PREFILTER_LIFESPAN = 40 ;
1428 self . CARBON_FILTER_LIFESPAN = 280 ;
1529 self . LASER_HEAD_LIFESPAN = 40 ;
1630 self . GANTRY_LIFESPAN = 100 ;
31+ self . WARN_IF_CRITICAL_PERCENT = 70 ;
1732 self . WARN_IF_USED_PERCENT = 100 ;
1833
1934 self . totalUsage = ko . observable ( 0 ) ;
@@ -56,42 +71,37 @@ $(function () {
5671 return Math . floor ( self . gantryUsage ( ) / 3600 ) ;
5772 } ) ;
5873
74+ self . optimizeParameterPercentageValues = function ( val ) {
75+ return Math . min ( roundDownToNearest10 ( val ) , 100 ) ;
76+ } ;
5977 self . prefilterPercent = ko . computed ( function ( ) {
60- return Math . min (
61- Math . floor (
62- ( self . prefilterUsageHours ( ) / self . PREFILTER_LIFESPAN ) * 100
63- ) ,
64- 100
78+ return self . optimizeParameterPercentageValues (
79+ ( self . prefilterUsageHours ( ) / self . PREFILTER_LIFESPAN ) * 100
6580 ) ;
6681 } ) ;
6782 self . carbonFilterPercent = ko . computed ( function ( ) {
68- return Math . min (
69- Math . floor (
70- ( self . carbonFilterUsageHours ( ) /
71- self . CARBON_FILTER_LIFESPAN ) *
72- 100
73- ) ,
74- 100
83+ return self . optimizeParameterPercentageValues (
84+ ( self . carbonFilterUsageHours ( ) / self . CARBON_FILTER_LIFESPAN ) *
85+ 100
7586 ) ;
7687 } ) ;
7788 self . laserHeadPercent = ko . computed ( function ( ) {
78- return Math . min (
79- Math . floor (
80- ( self . laserHeadUsageHours ( ) / self . LASER_HEAD_LIFESPAN ) *
81- 100
82- ) ,
83- 100
89+ return self . optimizeParameterPercentageValues (
90+ ( self . laserHeadUsageHours ( ) / self . LASER_HEAD_LIFESPAN ) * 100
8491 ) ;
8592 } ) ;
8693 self . gantryPercent = ko . computed ( function ( ) {
87- return Math . min (
88- Math . floor (
89- ( self . gantryUsageHours ( ) / self . GANTRY_LIFESPAN ) * 100
90- ) ,
91- 100
94+ return self . optimizeParameterPercentageValues (
95+ ( self . gantryUsageHours ( ) / self . GANTRY_LIFESPAN ) * 100
9296 ) ;
9397 } ) ;
9498
99+ self . prefilterShowEarlyWarning = ko . computed ( function ( ) {
100+ return self . prefilterPercent ( ) >= self . WARN_IF_CRITICAL_PERCENT ;
101+ } ) ;
102+ self . carbonFilterShowEarlyWarning = ko . computed ( function ( ) {
103+ return self . carbonFilterPercent ( ) >= self . WARN_IF_CRITICAL_PERCENT ;
104+ } ) ;
95105 self . prefilterShowWarning = ko . computed ( function ( ) {
96106 return self . prefilterPercent ( ) >= self . WARN_IF_USED_PERCENT ;
97107 } ) ;
@@ -113,6 +123,12 @@ $(function () {
113123 self . gantryShowWarning ( )
114124 ) ;
115125 } ) ;
126+ self . needsprefilterEarlyWarning = ko . computed ( function ( ) {
127+ return self . prefilterShowEarlyWarning ( ) ;
128+ } ) ;
129+ self . needsCarbonFilterEarlyWarning = ko . computed ( function ( ) {
130+ return self . carbonFilterShowEarlyWarning ( ) ;
131+ } ) ;
116132
117133 self . componentResetQuestion = ko . computed ( function ( ) {
118134 if ( self . componentToReset ( ) === self . PREFILTER ) {
@@ -131,7 +147,31 @@ $(function () {
131147 self . loadUsageValues ( ) ;
132148 } ;
133149
134- self . onStartupComplete = function ( ) {
150+ self . onUserLoggedIn = function ( user ) {
151+ if (
152+ self . needsprefilterEarlyWarning ( ) &&
153+ ! user ?. settings ?. mrbeam ?. filterWarnings ?. prefilter
154+ ) {
155+ self . notifyFilterWarning (
156+ self . PREFILTER_WARNING_TITLE ,
157+ self . PREFILTER_WARNING_TEXT
158+ ) ;
159+ self . saveUserSettings ( {
160+ prefilter : true ,
161+ } ) ;
162+ }
163+ if (
164+ self . needsCarbonFilterEarlyWarning ( ) &&
165+ ! user ?. settings ?. mrbeam ?. filterWarnings ?. carbonFilter
166+ ) {
167+ self . notifyFilterWarning (
168+ self . CARBON_FILTER_WARNING_TITLE ,
169+ self . CARBON_FILTER_WARNING_TEXT
170+ ) ;
171+ self . saveUserSettings ( {
172+ carbonFilter : true ,
173+ } ) ;
174+ }
135175 if ( self . needsMaintenance ( ) ) {
136176 self . notifyMaintenanceRequired ( ) ;
137177 }
@@ -159,6 +199,11 @@ $(function () {
159199 } ;
160200
161201 self . resetPrefilterUsage = function ( ) {
202+ // Set the warning message key to false so that it will show again when the value reaches 70%
203+ self . saveUserSettings ( {
204+ prefilter : false ,
205+ } ) ;
206+
162207 // Reset all existing click listeners (in case the user exited the "are you sure" modal before without clicking on Yes)
163208 $ ( "#reset_counter_are_you_sure" ) . off ( "click" ) ;
164209
@@ -187,6 +232,11 @@ $(function () {
187232 } ;
188233
189234 self . resetCarbonFilterUsage = function ( ) {
235+ // Set the warning message key to false so that it will show again when the value reaches 70%
236+ self . saveUserSettings ( {
237+ carbonFilter : false ,
238+ } ) ;
239+
190240 // Reset all existing click listeners (in case the user exited the "are you sure" modal before without clicking on Yes)
191241 $ ( "#reset_counter_are_you_sure" ) . off ( "click" ) ;
192242
@@ -317,8 +367,7 @@ $(function () {
317367 ) ,
318368 {
319369 br : "<br>" ,
320- open :
321- '<a href=\'#\' data-toggle="tab" id="settings_maintenance_link" style="font-weight:bold">' ,
370+ open : '<a href=\'#\' data-toggle="tab" id="settings_maintenance_link" style="font-weight:bold">' ,
322371 close : "</a>" ,
323372 }
324373 ) ,
@@ -346,6 +395,39 @@ $(function () {
346395 } ) ;
347396 } ;
348397
398+ self . notifyFilterWarning = function (
399+ NotificationTitle ,
400+ NotificationText
401+ ) {
402+ new PNotify ( {
403+ title : NotificationTitle ,
404+ text : NotificationText ,
405+ type : "warn" ,
406+ hide : false ,
407+ } ) ;
408+ } ;
409+
410+ self . saveUserSettings = function ( earlyWarningShown ) {
411+ // save to user settings
412+ if ( self . loginState ?. currentUser ( ) ) {
413+ let mrbSettings = self . loginState . currentUser ( ) . settings . mrbeam ;
414+ if ( ! ( "filterWarnings" in mrbSettings ) ) {
415+ mrbSettings . filterWarnings = { } ;
416+ }
417+ if ( "prefilter" in earlyWarningShown ) {
418+ mrbSettings . filterWarnings . prefilter =
419+ earlyWarningShown . prefilter ;
420+ } else if ( "carbonFilter" in earlyWarningShown ) {
421+ mrbSettings . filterWarnings . carbonFilter =
422+ earlyWarningShown . carbonFilter ;
423+ }
424+ let userName = self . loginState . currentUser ( ) . name ;
425+ self . userSettings . updateSettings ( userName , {
426+ mrbeam : mrbSettings ,
427+ } ) ;
428+ }
429+ } ;
430+
349431 self . updateSettingsAbout = function ( ) {
350432 $ ( "#settings_mrbeam_about_support_total_usage_hours" ) . html (
351433 self . totalUsageHours ( )
@@ -358,7 +440,12 @@ $(function () {
358440 Maintenance ,
359441
360442 // e.g. loginStateViewModel, settingsViewModel, ...
361- [ "settingsViewModel" , "analyticsViewModel" ] ,
443+ [
444+ "settingsViewModel" ,
445+ "analyticsViewModel" ,
446+ "userSettingsViewModel" ,
447+ "loginStateViewModel" ,
448+ ] ,
362449
363450 // e.g. #settings_plugin_mrbeam, #tab_plugin_mrbeam, ...
364451 [ "#settings_maintenance" ] , // This is important!
0 commit comments