Commit 167b14cd authored by Leon Tappe's avatar Leon Tappe 🔥
Browse files

refactor models

parent 2c31b2d1
export 'src/admins/admins_bloc.dart';
export 'src/admins/admins_events.dart';
export 'src/admins/admins_state.dart';
export 'src/models/admin.dart';
export 'src/models/admin_sort.dart';
export 'src/dispatcher/dispatcher_bloc.dart';
export 'src/dispatcher/dispatcher_events.dart';
export 'src/dispatcher/dispatcher_state.dart';
export 'src/models/dispatcher_task.dart';
\ No newline at end of file
export 'src/models/dispatcher_task.dart';
export 'src/journal/journal_bloc.dart';
export 'src/journal/journal_events.dart';
export 'src/journal/journal_state.dart';
export 'src/models/transaction.dart';
export 'src/journal_token/journal_token_bloc.dart';
export 'src/journal_token/journal_token_events.dart';
export 'src/journal_token/journal_token_state.dart';
export 'src/models/journal_token.dart';
export 'src/models/print_queue_task.dart';
export 'src/print_queue/print_queue_bloc.dart';
export 'src/print_queue/print_queue_events.dart';
export 'src/print_queue/print_queue_state.dart';
export 'src/models/print_queue_task.dart';
export 'src/printers/printers_bloc.dart';
export 'src/printers/printers_events.dart';
export 'src/printers/printers_state.dart';
export 'src/models/printer.dart';
export 'src/models/printer_counter.dart';
export 'src/models/printer_details.dart';
export 'src/models/printer_queue.dart';
export 'src/models/printer_status.dart';
export 'src/models/printer_sort.dart';
export 'src/models/printer_watch_options.dart';
export 'src/models/printer.dart';
export 'src/printers/printers_bloc.dart';
export 'src/printers/printers_events.dart';
export 'src/printers/printers_state.dart';
......@@ -5,6 +5,7 @@ import 'package:http/http.dart' as http;
import 'package:logging/logging.dart';
import '../../admins.dart';
import '../models/enums.dart';
import '../network_exception.dart';
class AdminsBloc extends Bloc<AdminsEvent, AdminsState> {
......@@ -94,7 +95,7 @@ class AdminsBloc extends Bloc<AdminsEvent, AdminsState> {
void onSetAdminPassword(int id, String password) => add(SetAdminPassword(id, password));
void onSortAdmins(AdminSortParam param, AdminSortDirection direction) =>
void onSortAdmins(AdminSortParam param, SortDirection direction) =>
add(SortAdmins(param, direction));
void onStart(String token) => add(InitAdmins(token));
......@@ -200,12 +201,12 @@ class AdminsBloc extends Bloc<AdminsEvent, AdminsState> {
});
}
void _sortAdmins(AdminSortParam param, AdminSortDirection direction) {
void _sortAdmins(AdminSortParam param, SortDirection direction) {
_log.finer('_sortAdmins: $param $direction');
switch (param) {
case AdminSortParam.login:
{
if (direction == AdminSortDirection.ascending) {
if (direction == SortDirection.ascending) {
_admins.sort((a, b) => a.login.compareTo(b.login));
} else {
_admins.sort((a, b) => b.login.compareTo(a.login));
......@@ -215,7 +216,7 @@ class AdminsBloc extends Bloc<AdminsEvent, AdminsState> {
case AdminSortParam.firstName:
{
if (direction == AdminSortDirection.ascending) {
if (direction == SortDirection.ascending) {
_admins.sort((a, b) => a.firstName.compareTo(b.firstName));
} else {
_admins.sort((a, b) => b.firstName.compareTo(a.firstName));
......@@ -225,7 +226,7 @@ class AdminsBloc extends Bloc<AdminsEvent, AdminsState> {
case AdminSortParam.lastName:
{
if (direction == AdminSortDirection.ascending) {
if (direction == SortDirection.ascending) {
_admins.sort((a, b) => a.lastName.compareTo(b.lastName));
} else {
_admins.sort((a, b) => b.lastName.compareTo(a.lastName));
......
import '../models/admin_sort.dart';
import '../models/enums.dart';
class AddAdmin extends AdminsEvent {
final String firstName;
......@@ -21,6 +21,17 @@ class AddAdmin extends AdminsEvent {
abstract class AdminsEvent {}
class DeleteAdmin extends AdminsEvent {
final int id;
DeleteAdmin(this.id);
Map<String, dynamic> toMap() => <String, dynamic>{'id': id};
@override
String toString() => toMap().toString();
}
class InitAdmins extends AdminsEvent {
final String token;
......@@ -32,6 +43,8 @@ class InitAdmins extends AdminsEvent {
String toString() => toMap().toString();
}
class RefreshAdmins extends AdminsEvent {}
class SetAdminPassword extends AdminsEvent {
final int id;
final String password;
......@@ -47,6 +60,18 @@ class SetAdminPassword extends AdminsEvent {
String toString() => toMap().toString();
}
class SortAdmins extends AdminsEvent {
final AdminSortParam param;
final SortDirection direction;
SortAdmins(this.param, this.direction);
Map<String, dynamic> toMap() => <String, dynamic>{'param': param, 'direction': direction};
@override
String toString() => toMap().toString();
}
class UpdateAdmin extends AdminsEvent {
final int id;
final String login;
......@@ -65,28 +90,3 @@ class UpdateAdmin extends AdminsEvent {
@override
String toString() => toMap().toString();
}
class DeleteAdmin extends AdminsEvent {
final int id;
DeleteAdmin(this.id);
Map<String, dynamic> toMap() => <String, dynamic>{'id': id};
@override
String toString() => toMap().toString();
}
class SortAdmins extends AdminsEvent {
final AdminSortParam param;
final AdminSortDirection direction;
SortAdmins(this.param, this.direction);
Map<String, dynamic> toMap() => <String, dynamic>{'param': param, 'direction': direction};
@override
String toString() => toMap().toString();
}
class RefreshAdmins extends AdminsEvent {}
\ No newline at end of file
......@@ -4,7 +4,7 @@ import 'package:bloc/bloc.dart';
import 'package:http/http.dart';
import 'package:logging/logging.dart';
import '../models/journal_sort.dart';
import '../models/enums.dart';
import '../models/transaction.dart';
import '../network_exception.dart';
import 'journal_events.dart';
......@@ -52,12 +52,12 @@ class JournalBloc extends Bloc<JournalEvent, JournalState> {
event.withoutReceipt,
);
_journal.add(Transaction(
event.userId,
event.adminId,
event.value,
event.annotation,
null,
DateTime.now(),
userId: event.userId,
adminId: event.adminId,
value: event.value,
description: event.annotation,
printTransaction: null,
timestamp: DateTime.now(),
));
emit(JournalState.result(_journal));
} on NetworkException catch (e) {
......@@ -214,11 +214,11 @@ class JournalBloc extends Bloc<JournalEvent, JournalState> {
);
}
void _sortJournal(JournalSortParam param, JournalSortDirection direction) {
void _sortJournal(JournalSortParam param, SortDirection direction) {
switch (param) {
case JournalSortParam.value:
{
if (direction == JournalSortDirection.ascending) {
if (direction == SortDirection.ascending) {
_journal.sort((a, b) => a.value.compareTo(b.value));
_journalFiltered.sort((a, b) => a.value.compareTo(b.value));
} else {
......@@ -230,7 +230,7 @@ class JournalBloc extends Bloc<JournalEvent, JournalState> {
case JournalSortParam.userId:
{
if (direction == JournalSortDirection.ascending) {
if (direction == SortDirection.ascending) {
_journal.sort((a, b) => a.userId.compareTo(b.userId));
_journalFiltered.sort((a, b) => a.userId.compareTo(b.userId));
} else {
......@@ -242,7 +242,7 @@ class JournalBloc extends Bloc<JournalEvent, JournalState> {
case JournalSortParam.adminId:
{
if (direction == JournalSortDirection.ascending) {
if (direction == SortDirection.ascending) {
_journal.sort((a, b) => a.adminId.compareTo(b.adminId));
_journalFiltered.sort((a, b) => a.adminId.compareTo(b.adminId));
} else {
......@@ -254,7 +254,7 @@ class JournalBloc extends Bloc<JournalEvent, JournalState> {
case JournalSortParam.description:
{
if (direction == JournalSortDirection.ascending) {
if (direction == SortDirection.ascending) {
_journal.sort((a, b) => a.description.compareTo(b.description));
_journalFiltered.sort((a, b) => a.description.compareTo(b.description));
} else {
......@@ -266,7 +266,7 @@ class JournalBloc extends Bloc<JournalEvent, JournalState> {
case JournalSortParam.timestamp:
{
if (direction == JournalSortDirection.ascending) {
if (direction == SortDirection.ascending) {
_journal.sort((a, b) => a.timestamp.compareTo(b.timestamp));
_journalFiltered.sort((a, b) => a.timestamp.compareTo(b.timestamp));
} else {
......
import '../models/enums.dart';
import '../models/transaction.dart';
import '../models/journal_sort.dart';
class AddTransaction extends JournalEvent {
final int userId;
......@@ -26,21 +26,6 @@ class AddTransaction extends JournalEvent {
String toString() => toMap().toString();
}
class InitJournal extends JournalEvent {
final String token;
InitJournal(this.token);
Map<String, dynamic> toMap() => <String, dynamic>{'token': token};
@override
String toString() => toMap().toString();
}
abstract class JournalEvent {}
class RefreshJournal extends JournalEvent {}
class FilterJournal extends JournalEvent {
final Transaction filter;
......@@ -59,12 +44,27 @@ class FuzzyFilterJournal extends JournalEvent {
String toString() => '[FuzzyFilterJournal filter: $filter]';
}
class InitJournal extends JournalEvent {
final String token;
InitJournal(this.token);
Map<String, dynamic> toMap() => <String, dynamic>{'token': token};
@override
String toString() => toMap().toString();
}
abstract class JournalEvent {}
class RefreshJournal extends JournalEvent {}
class SortJournal extends JournalEvent {
final JournalSortParam param;
final JournalSortDirection direction;
final SortDirection direction;
SortJournal(this.param, this.direction);
@override
String toString() => '[SortJournal param: $param, direction: $direction]';
}
\ No newline at end of file
}
......@@ -20,7 +20,7 @@ class Admin {
);
}
Map<String, dynamic> toMap() => <String, dynamic>{
Map<String, dynamic> get toMap => <String, dynamic>{
'id': id,
'first_name': firstName,
'last_name': lastName,
......@@ -28,5 +28,5 @@ class Admin {
};
@override
String toString() => toMap().toString();
String toString() => '[Admin $toMap]';
}
enum AdminSortParam {
firstName,
lastName,
login
}
enum AdminSortDirection {
ascending,
descending
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ class DispatcherTask {
keep: map['keep'] as bool,
);
Map<String, dynamic> toMap() => <String, dynamic>{
Map<String, dynamic> get toMap => <String, dynamic>{
'isUploading': isUploading,
'filename': filename,
'uid': uid,
......@@ -30,5 +30,5 @@ class DispatcherTask {
};
@override
String toString() => toMap().toString();
String toString() => '[DispatcherTask $toMap]';
}
enum AdminSortParam { firstName, lastName, login }
enum JournalSortParam { value, userId, adminId, description, timestamp }
enum PrinterSortParam {
hostname,
ip,
community,
mac,
location,
description,
deviceId,
hasA3,
coinOperated
}
enum SortDirection { ascending, descending }
......@@ -42,7 +42,7 @@ class JobOptions {
displayName: options['displayname'] as String,
);
Map<String, dynamic> toMap() => <String, dynamic>{
Map<String, dynamic> get toMap => <String, dynamic>{
'color': color,
'duplex': duplex,
'copies': copies,
......@@ -57,7 +57,7 @@ class JobOptions {
};
@override
String toString() => toMap().toString();
String toString() => '[JobOptions $toMap]';
}
enum NupPageOrder { rightThenDown, downThenRight, leftThenDown, downThenLeft }
enum JournalSortParam {
value,
userId,
adminId,
description,
timestamp
}
enum JournalSortDirection {
ascending,
descending
}
\ No newline at end of file
......@@ -7,20 +7,27 @@ class JournalToken {
final String created;
final String updated;
JournalToken(
this.id, this.value, this.content, this.used, this.usedBy, this.created, this.updated);
JournalToken({
this.id,
this.value,
this.content,
this.used,
this.usedBy,
this.created,
this.updated,
});
factory JournalToken.fromMap(Map<dynamic, dynamic> map) => JournalToken(
map['id'] as int,
map['value'] as int,
map['content'] as String,
map['used'] as bool,
map['used_by'] as int,
map['created'] as String,
map['updated'] as String,
id: map['id'] as int,
value: map['value'] as int,
content: map['content'] as String,
used: map['used'] as bool,
usedBy: map['used_by'] as int,
created: map['created'] as String,
updated: map['updated'] as String,
);
Map<String, dynamic> toMap() => <String, dynamic>{
Map<String, dynamic> get toMap => <String, dynamic>{
'id': id,
'value': value,
'content': content,
......@@ -29,7 +36,7 @@ class JournalToken {
'created': created,
'updated': updated,
};
@override
String toString() => toMap().toString();
String toString() => '[JournalToken $toMap]';
}
......@@ -2,15 +2,15 @@ class PrintQueueTask {
final String uid;
final int userId;
PrintQueueTask(this.uid, this.userId);
PrintQueueTask({this.uid, this.userId});
factory PrintQueueTask.fromMap(Map<String, dynamic> task) => PrintQueueTask(
task['uid'] as String,
task['user_id'] as int,
uid: task['uid'] as String,
userId: task['user_id'] as int,
);
Map<String, dynamic> toMap() => <String, dynamic>{'uid': uid, 'user_id': userId};
Map<String, dynamic> get toMap => <String, dynamic>{'uid': uid, 'user_id': userId};
@override
String toString() => toMap().toString();
String toString() => '[PrintQueueTask $toMap]';
}
......@@ -7,7 +7,7 @@ class PrintTransaction {
final int deviceId;
final JobOptions options;
PrintTransaction(this.pages, this.colored, this.score, this.deviceId, this.options);
PrintTransaction({this.pages, this.colored, this.score, this.deviceId, this.options});
factory PrintTransaction.fromMap(Map<String, dynamic> map) {
JobOptions newOptions;
......@@ -18,11 +18,11 @@ class PrintTransaction {
}
return PrintTransaction(
map['pages'] as int,
map['colored'] as int,
map['score'] as int,
map['deviceId'] as int,
newOptions,
pages: map['pages'] as int,
colored: map['colored'] as int,
score: map['score'] as int,
deviceId: map['device_id'] as int,
options: newOptions,
);
}
......@@ -31,7 +31,7 @@ class PrintTransaction {
'colored': colored,
'score': score,
'device_id': deviceId,
'options': options.toMap(),
'options': options.toMap,
};
@override
......
import 'printer_counter.dart';
import 'printer_status.dart';
import 'printer_queue.dart';
import 'printer_status.dart';
class Printer {
final int id;
......@@ -80,7 +80,7 @@ class Printer {
);
}
Map<String, dynamic> toMap() => <String, dynamic>{
Map<String, dynamic> get toMap => <String, dynamic>{
'id': id,
'hostname': hostname,
'ip': ip,
......@@ -102,5 +102,5 @@ class Printer {
};
@override
String toString() => toMap().toString();
String toString() => '[Printer $toMap]';
}
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