1
+ using Fluxor ;
2
+ using Fluxor . Blazor . Web . Components ;
1
3
using MassaK . Plugin . Abstractions . Enums ;
4
+ using ScalesDesktop . Source . Shared . Models ;
5
+ using ScalesDesktop . Source . Shared . Services . Stores ;
2
6
using TscZebra . Plugin . Abstractions . Enums ;
3
7
using TscZebra . Plugin . Abstractions . Exceptions ;
4
8
using Ws . Desktop . Models ;
9
13
10
14
namespace ScalesDesktop . Source . Features ;
11
15
12
- public sealed partial class LabelPrint : ComponentBase , IAsyncDisposable
16
+ public sealed partial class LabelPrint : FluxorComponent
13
17
{
14
18
# region Injects
15
19
16
20
[ Inject ] private IStringLocalizer < WsDataResources > WsDataLocalizer { get ; set ; } = default ! ;
17
21
[ Inject ] private IStringLocalizer < ApplicationResources > Localizer { get ; set ; } = default ! ;
18
22
[ Inject ] private IToastService ToastService { get ; set ; } = default ! ;
19
23
[ Inject ] private PrinterService PrinterService { get ; set ; } = default ! ;
20
- [ Inject ] private ScalesService ScalesService { get ; set ; } = default ! ;
21
- [ Inject ] private LabelContext LabelContext { get ; set ; } = default ! ;
22
24
[ Inject ] private IJSRuntime JsRuntime { get ; set ; } = default ! ;
23
25
[ Inject ] private IDesktopApi DesktopApi { get ; set ; } = default ! ;
24
26
[ Inject ] private ArmApi ArmApi { get ; set ; } = default ! ;
27
+ [ Inject ] private IState < PrinterState > PrinterState { get ; set ; } = default ! ;
28
+ [ Inject ] private IState < WeightState > WeightState { get ; set ; } = default ! ;
29
+ [ Inject ] private IState < ScalesState > ScalesState { get ; set ; } = default ! ;
30
+ [ Inject ] private IState < PluState > PluState { get ; set ; } = default ! ;
25
31
26
32
#endregion
27
33
28
34
[ Parameter , EditorRequired ] public ArmValue Arm { get ; set ; } = default ! ;
35
+ [ Parameter , EditorRequired ] public WeightKneadingModel KneadingModel { get ; set ; } = default ! ;
29
36
30
37
private bool IsButtonClicked { get ; set ; }
31
-
32
38
private const int ButtonCooldownDelay = 500 ;
33
39
34
- protected override void OnInitialized ( )
35
- {
36
- PrinterService . StatusChanged += StateHasChanged ;
37
- ScalesService . StatusChanged += StateHasChanged ;
38
- ScalesService . WeightChanged += StateHasChanged ;
39
- }
40
-
41
40
protected override async Task OnAfterRenderAsync ( bool firstRender )
42
41
{
43
42
if ( ! firstRender ) return ;
@@ -68,15 +67,15 @@ private async Task PrintLabelAsync()
68
67
69
68
CreateWeightLabelDto createDto = new ( )
70
69
{
71
- Kneading = LabelContext . KneadingModel . KneadingCount ,
72
- ProductDt = GetProductDt ( LabelContext . KneadingModel . ProductDate ) ,
73
- WeightNet = LabelContext . KneadingModel . NetWeight ,
74
- WeightTare = LabelContext . Plu ? . TareWeight ?? 0
70
+ Kneading = KneadingModel . KneadingCount ,
71
+ ProductDt = GetProductDt ( KneadingModel . ProductDate ) ,
72
+ WeightNet = KneadingModel . NetWeight ,
73
+ WeightTare = PluState . Value . Plu ? . TareWeight ?? 0
75
74
} ;
76
75
77
76
try
78
77
{
79
- WeightLabel label = await DesktopApi . CreatePluWeightLabel ( Arm . Id , LabelContext . Plu ! . Id , createDto ) ;
78
+ WeightLabel label = await DesktopApi . CreatePluWeightLabel ( Arm . Id , PluState . Value . Plu ! . Id , createDto ) ;
80
79
ArmApi . UpdateArmCounter ( label . ArmCounter ) ;
81
80
await PrinterService . PrintZplAsync ( label . Zpl ) ;
82
81
}
@@ -109,21 +108,21 @@ private async Task PrintLabelAsync()
109
108
110
109
private async Task < bool > ValidatePrinterStatus ( )
111
110
{
112
- PrinterStatus printerStatus = await PrinterService . GetStatusAsync ( ) ;
113
- if ( printerStatus is PrinterStatus . Ready or PrinterStatus . Busy ) return true ;
111
+ await PrinterService . RequestStatusAsync ( ) ;
112
+ if ( PrinterState . Value . Status is PrinterStatus . Ready or PrinterStatus . Busy ) return true ;
114
113
PrintPrinterStatusMessage ( ) ;
115
114
return false ;
116
115
}
117
116
118
117
private bool ValidateScalesStatus ( )
119
118
{
120
- if ( ! ScalesService . IsStable )
119
+ if ( ! WeightState . Value . IsStable )
121
120
{
122
121
ToastService . ShowWarning ( Localizer [ "ScalesStatusUnstable" ] ) ;
123
122
return false ;
124
123
}
125
124
126
- if ( LabelContext . KneadingModel . NetWeight >= 0 ) return true ;
125
+ if ( KneadingModel . NetWeight >= 0 ) return true ;
127
126
ToastService . ShowWarning ( Localizer [ "ScalesStatusTooLight" ] ) ;
128
127
return false ;
129
128
}
@@ -132,7 +131,7 @@ private static DateTime GetProductDt(DateTime time) =>
132
131
new ( time . Year , time . Month , time . Day , DateTime . Now . Hour , DateTime . Now . Minute , DateTime . Now . Second ) ;
133
132
134
133
private void PrintPrinterStatusMessage ( ) =>
135
- ToastService . ShowWarning ( PrinterService . Status switch
134
+ ToastService . ShowWarning ( PrinterState . Value . Status switch
136
135
{
137
136
PrinterStatus . Disconnected => Localizer [ "PrinterStatusIsForceDisconnected" ] ,
138
137
PrinterStatus . Paused => Localizer [ "PrinterStatusPaused" ] ,
@@ -143,16 +142,10 @@ private void PrintPrinterStatusMessage() =>
143
142
} ) ;
144
143
145
144
private bool GetPrintLabelDisabledStatus ( ) =>
146
- LabelContext . Plu == null || ScalesService . Status != MassaKStatus . Ready ;
145
+ PluState . Value . Plu == null || ScalesState . Value . Status != MassaKStatus . Ready ;
147
146
148
- # region Event Subscribe and Unsubscribe
149
-
150
- public async ValueTask DisposeAsync ( )
147
+ public new async ValueTask DisposeAsync ( )
151
148
{
152
- PrinterService . StatusChanged -= StateHasChanged ;
153
- ScalesService . StatusChanged -= StateHasChanged ;
154
- ScalesService . WeightChanged -= StateHasChanged ;
155
-
156
149
try
157
150
{
158
151
await JsRuntime . InvokeVoidAsync ( "unsubscribeMiddleMouseClickEvent" ) ;
@@ -162,6 +155,4 @@ public async ValueTask DisposeAsync()
162
155
// pass
163
156
}
164
157
}
165
-
166
- # endregion
167
158
}
0 commit comments