Commit b1fdeec0 authored by Leon Tappe's avatar Leon Tappe 🔥
Browse files

update printer stuff to be more sane

parent b8765a9f
import 'print_queue_task.dart';
import 'printer_counter.dart';
import 'printer_queue.dart';
import 'printer_status.dart';
class Printer {
......@@ -21,7 +21,7 @@ class Printer {
PrinterStatus status;
PrinterCounter counter;
PrinterQueue queue;
PrintQueueTask queue;
Printer({
this.id,
......@@ -66,7 +66,7 @@ class Printer {
counter: map['counter'] != null
? PrinterCounter.fromMap(map['counter'] as Map<String, dynamic>)
: null,
queue: map['queue'] as PrinterQueue,
queue: map['queue'] != null ? PrintQueueTask.fromMap(map['queue']) : null,
);
Map<String, dynamic> get toMap => <String, dynamic>{
......@@ -75,15 +75,15 @@ class Printer {
'ip': ip,
'community': community,
'mac': mac,
'deviceId': deviceId,
'device_id': deviceId,
'location': location,
'hasA3': hasA3,
'coinOperated': coinOperated,
'has_a3': hasA3,
'coin_operated': coinOperated,
'description': description,
'watchToner': watchToner,
'watchTray1': watchTray1,
'watchTray2': watchTray2,
'watchTray3': watchTray3,
'watch_toner': watchToner,
'watch_tray1': watchTray1,
'watch_tray2': watchTray2,
'watch_tray3': watchTray3,
'watchInterval': watchInterval,
'status': status,
'counter': counter,
......
class PrinterQueue {
int userId;
String uid;
PrinterQueue({this.userId, this.uid});
factory PrinterQueue.fromMap(Map<String, dynamic> map) => PrinterQueue(
userId: map['user_id'] as int,
uid: map['uid'] as String,
);
Map<String, dynamic> get toMap => <String, dynamic>{
'userId': userId,
'uid': uid,
};
@override
String toString() => '[PrinterQueue $toMap]';
}
......@@ -29,9 +29,9 @@ class PrinterStatus {
tonerM: map['toner_m'] as int,
tonerY: map['toner_y'] as int,
tonerK: map['toner_k'] as int,
tray1: map['tray1'] as int,
tray2: map['tray2'] as int,
tray3: map['tray3'] as int,
tray1: map['tray_1'] as int,
tray2: map['tray_2'] as int,
tray3: map['tray_3'] as int,
);
Map<String, dynamic> get toMap => <String, dynamic>{
......@@ -41,9 +41,9 @@ class PrinterStatus {
'toner_m': tonerM,
'toner_y': tonerY,
'toner_k': tonerK,
'tray1': tray1,
'tray2': tray2,
'tray3': tray3,
'tray_1': tray1,
'tray_2': tray2,
'tray_3': tray3,
};
@override
......
......@@ -28,7 +28,7 @@ class PrintQueueBloc extends Bloc<PrintQueueEvent, PrintQueueState> {
on<GetQueue>((GetQueue event, Emitter<PrintQueueState> emit) async {
emit(PrintQueueState.busy());
try {
emit(PrintQueueState.result(await _getQueue(event.deviceId)));
emit(PrintQueueState.result((await _getQueue(event.deviceId)) ?? []));
} on NetworkException catch (e) {
emit(PrintQueueState.exception(e));
}
......@@ -98,9 +98,10 @@ class PrintQueueBloc extends Bloc<PrintQueueEvent, PrintQueueState> {
if (response.statusCode == 200) {
if (response.body != null) {
return (json.decode(response.body) as List)
?.map<PrintQueueTask>(
(dynamic value) => PrintQueueTask.fromMap(value as Map<String, dynamic>))
?.toList() ?? [];
?.map<PrintQueueTask>(
(dynamic value) => PrintQueueTask.fromMap(value as Map<String, dynamic>))
?.toList() ??
[];
} else {
return [];
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment