Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
AStAPrint Admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AStA
AStAPrint Admin
Commits
d811760c
Commit
d811760c
authored
2 years ago
by
Leon Tappe
Browse files
Options
Downloads
Patches
Plain Diff
refactor printer details and add delete button
parent
126c046f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/pages/printer_details/printer_details_page.dart
+46
-87
46 additions, 87 deletions
lib/pages/printer_details/printer_details_page.dart
lib/util.dart
+14
-0
14 additions, 0 deletions
lib/util.dart
with
60 additions
and
87 deletions
lib/pages/printer_details/printer_details_page.dart
+
46
−
87
View file @
d811760c
...
...
@@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:http/http.dart'
as
http
;
import
'/util.dart'
;
import
'/widgets/cool_card.dart'
;
import
'toner_indicator.dart'
;
...
...
@@ -38,7 +39,10 @@ class _PrinterDetailsPageState extends State<PrinterDetailsPage> {
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'Details zum Drucker
${widget.printer.hostname}
'
)),
appBar:
AppBar
(
title:
Text
(
'Details zum Drucker
${widget.printer.hostname}
'
),
actions:
[
IconButton
(
onPressed:
_onDelete
,
icon:
Icon
(
Icons
.
delete_forever_rounded
))],
),
body:
Center
(
child:
ConstrainedBox
(
constraints:
BoxConstraints
(
maxWidth:
1024.0
),
...
...
@@ -113,19 +117,7 @@ class _PrinterDetailsPageState extends State<PrinterDetailsPage> {
width:
256.0
,
child:
TextFormField
(
autovalidateMode:
AutovalidateMode
.
onUserInteraction
,
validator:
(
input
)
{
final
parts
=
input
.
split
(
'.'
);
if
(
parts
.
length
!=
4
)
{
return
'Eine IP muss im Format aaa.bbb.ccc.ddd vorliegen'
;
}
if
(
parts
.
map
((
e
)
=
>
int
.
tryParse
(
e
))
.
contains
(
null
))
{
return
'Eine IP muss aus natürlichen Zahlen bestehen'
;
}
return
null
;
},
validator:
validateIp
,
textAlign:
TextAlign
.
end
,
initialValue:
_printer
.
ip
??
''
,
decoration:
InputDecoration
(
border:
InputBorder
.
none
),
...
...
@@ -208,71 +200,6 @@ class _PrinterDetailsPageState extends State<PrinterDetailsPage> {
),
),
),
/* CheckboxListTile(
title: Text('Toner überwachen'),
value: _printer.watchToner,
onChanged: (bool input) {
setState(() {
_dirty = true;
_printer.watchToner = input;
});
_onSaveWatchers();
},
),
CheckboxListTile(
title: Text('Papierfach 1 überwachen'),
value: _printer.watchTray1,
onChanged: (bool input) {
setState(() {
_dirty = true;
_printer.watchTray1 = input;
});
_onSaveWatchers();
},
),
CheckboxListTile(
title: Text('Papierfach 2 überwachen'),
value: _printer.watchTray2,
onChanged: (bool input) {
setState(() {
_dirty = true;
_printer.watchTray2 = input;
});
_onSaveWatchers();
},
),
CheckboxListTile(
title: Text('Papierfach 3 überwachen'),
value: _printer.watchTray3,
onChanged: (bool input) {
setState(() {
_dirty = true;
_printer.watchTray3 = input;
});
_onSaveWatchers();
},
),
ListTile(
title: Text('Überwachungsintervall'),
trailing: SizedBox(
width: 256.0,
child: TextFormField(
validator: (input) =>
int.tryParse(input) == null ? 'Nur Zahlen erlaubt' : null,
autovalidateMode: AutovalidateMode.onUserInteraction,
textAlign: TextAlign.end,
initialValue: _printer.watchInterval.toString() ?? '',
decoration:
InputDecoration(border: InputBorder.none, suffixText: 'Sekunden'),
onChanged: (String input) => setState(() {
_dirty = true;
_printer.watchInterval =
int.tryParse(input) ?? _printer.watchInterval;
}),
onFieldSubmitted: (_) => _onSaveWatcherInterval(),
),
),
), */
],
),
CoolCard
(
...
...
@@ -356,19 +283,19 @@ class _PrinterDetailsPageState extends State<PrinterDetailsPage> {
ListTile
(
title:
Text
(
'Papierfach 1'
),
trailing:
Text
(
_printer
.
status
.
tray1
.
toString
(),
(
_printer
.
status
.
tray1
??
0
)
.
toString
(),
style:
Theme
.
of
(
context
)
.
textTheme
.
subtitle1
,
)),
ListTile
(
title:
Text
(
'Papierfach 2'
),
trailing:
Text
(
_printer
.
status
.
tray2
.
toString
(),
(
_printer
.
status
.
tray2
??
0
)
.
toString
(),
style:
Theme
.
of
(
context
)
.
textTheme
.
subtitle1
,
)),
ListTile
(
title:
Text
(
'Papierfach 3'
),
trailing:
Text
(
_printer
.
status
.
tray3
.
toString
(),
(
_printer
.
status
.
tray3
??
0
)
.
toString
(),
style:
Theme
.
of
(
context
)
.
textTheme
.
subtitle1
,
)),
ListTile
(
...
...
@@ -388,9 +315,10 @@ class _PrinterDetailsPageState extends State<PrinterDetailsPage> {
color:
Colors
.
pink
,
)),
ListTile
(
title:
Text
(
'Gelb'
),
trailing:
TonerIndicator
(
value:
_printer
.
status
.
tonerY
,
color:
Colors
.
yellow
)),
title:
Text
(
'Gelb'
),
trailing:
TonerIndicator
(
value:
_printer
.
status
.
tonerY
,
color:
Colors
.
yellow
),
),
ListTile
(
title:
Text
(
'Schwarz'
),
trailing:
TonerIndicator
(
...
...
@@ -450,9 +378,14 @@ class _PrinterDetailsPageState extends State<PrinterDetailsPage> {
printersBloc
=
BlocProvider
.
of
<
PrintersBloc
>(
context
);
printQueueBloc
=
PrintQueueBloc
(
http
.
Client
());
_printerListener
=
printersBloc
.
stream
.
listen
((
PrintersState
state
)
{
_printerListener
=
printersBloc
.
stream
.
where
((
e
)
=
>
e
.
isResult
)
.
listen
((
PrintersState
state
)
{
final
results
=
state
.
value
.
where
((
Printer
e
)
=
>
e
.
deviceId
==
widget
.
printer
.
deviceId
);
if
(
results
.
isEmpty
)
{
ScaffoldMessenger
.
of
(
context
)
.
showSnackBar
(
const
SnackBar
(
content:
Text
(
'Der Drucker konnte nicht gefunden werden'
)));
}
setState
(()
{
_printer
=
state
.
value
.
singleWhere
((
Printer
e
)
=
>
e
.
deviceId
==
widget
.
printer
.
deviceId
)
;
_printer
=
results
.
first
;
});
});
...
...
@@ -472,6 +405,32 @@ class _PrinterDetailsPageState extends State<PrinterDetailsPage> {
printQueueBloc
.
onRefresh
();
}
Future
<
void
>
_onDelete
()
async
{
final
result
=
await
showDialog
<
bool
>(
context:
context
,
builder:
(
BuildContext
context
)
=
>
AlertDialog
(
title:
Text
(
'Wirklich löschen?'
),
content:
Text
(
'Der Drucker
${_printer.deviceId}
kann danach nicht wiederhergestellt werden.'
),
actions:
[
MaterialButton
(
onPressed:
()
=
>
Navigator
.
of
(
context
)
.
pop
(
true
),
child:
Text
(
'Löschen'
),
),
ElevatedButton
(
onPressed:
()
=
>
Navigator
.
of
(
context
)
.
pop
(
false
),
child:
Text
(
'Abbrechen'
),
)
],
));
if
(
result
==
null
)
return
;
printersBloc
.
onDeletePrinter
(
_printer
.
deviceId
);
Navigator
.
of
(
context
)
.
pop
();
}
void
_onEmptyQueue
()
{
printQueueBloc
.
onCancelJobs
();
}
...
...
This diff is collapsed.
Click to expand it.
lib/util.dart
+
14
−
0
View file @
d811760c
...
...
@@ -69,5 +69,19 @@ String validateEmail(String value) {
return
'Bitte gebe eine richtige E-Mail Adresse ein'
;
}
String
validateIp
(
String
input
)
{
final
parts
=
input
.
split
(
'.'
);
if
(
parts
.
length
!=
4
)
{
return
'Eine IP muss im Format aaa.bbb.ccc.ddd vorliegen'
;
}
if
(
parts
.
map
((
e
)
=
>
int
.
tryParse
(
e
))
.
contains
(
null
))
{
return
'Eine IP muss aus natürlichen Zahlen bestehen'
;
}
return
null
;
}
String
validatePassword
(
String
input
)
=
>
input
.
length
>
5
?
null
:
'Das Passwort muss aus mindestens 6 Zeichen bestehen'
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment