Erweiterungen
This commit is contained in:
1 parent
279f6cb868
commit
5b3dead325
14 files changed
+113
-51
No files matched your search
@@ -210,7 +210,7 @@ class _AssignedJobsPageState extends State<AssignedJobsPage> {
|
|||||||
MqttCore.instance.publishPayloadMessage("job", message.toJson());
|
MqttCore.instance.publishPayloadMessage("job", message.toJson());
|
||||||
|
|
||||||
job.state = 9;
|
job.state = 9;
|
||||||
MyApp.isarInstance.writeTxnSync(() => {MyApp.isarInstance.jobs.putSync(job)});
|
await MyApp.isarInstance.writeTxn(() async => { await MyApp.isarInstance.jobs.put(job)});
|
||||||
|
|
||||||
_entries = await _createListEntries();
|
_entries = await _createListEntries();
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import 'package:stadtbote/model/message.dart';
|
|||||||
import 'package:stadtbote/model/session_status.dart';
|
import 'package:stadtbote/model/session_status.dart';
|
||||||
import 'package:stadtbote/model/status.dart';
|
import 'package:stadtbote/model/status.dart';
|
||||||
import 'package:stadtbote/popups/infos_popup.dart';
|
import 'package:stadtbote/popups/infos_popup.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/device_log.dart';
|
import 'package:stadtbote/protocoll_messages/device_log_response.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/logout_message.dart';
|
import 'package:stadtbote/protocoll_messages/logout_message.dart';
|
||||||
import 'package:stadtbote/tools/message_service.dart';
|
import 'package:stadtbote/tools/message_service.dart';
|
||||||
import 'package:stadtbote/tools/messages/job_deleted_message.dart';
|
import 'package:stadtbote/tools/messages/job_deleted_message.dart';
|
||||||
@@ -394,7 +394,7 @@ class _MainPageState extends State<MainPage> {
|
|||||||
void _test() async {
|
void _test() async {
|
||||||
var logEintries = await MyApp.isarInstance.logEntrys.where().findAll();
|
var logEintries = await MyApp.isarInstance.logEntrys.where().findAll();
|
||||||
|
|
||||||
var deviceLog = DeviceLog();
|
var deviceLog = DeviceLogResponse();
|
||||||
deviceLog.entries = logEintries;
|
deviceLog.entries = logEintries;
|
||||||
|
|
||||||
var json = jsonEncode(deviceLog.toJson());
|
var json = jsonEncode(deviceLog.toJson());
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ class _MessagesPageState extends State<MessagesPage> {
|
|||||||
message.mssg.read = true;
|
message.mssg.read = true;
|
||||||
message.mssg.id = await sbmessage.Message.getNextId();
|
message.mssg.id = await sbmessage.Message.getNextId();
|
||||||
|
|
||||||
MyApp.isarInstance.writeTxnSync(() {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
MyApp.isarInstance.messages.putSync(message.mssg);
|
await MyApp.isarInstance.messages.put(message.mssg);
|
||||||
});
|
});
|
||||||
|
|
||||||
MqttCore.instance.publishPayloadMessage('mssg', message.toJson());
|
MqttCore.instance.publishPayloadMessage('mssg', message.toJson());
|
||||||
@@ -140,8 +140,8 @@ class _MessagesPageState extends State<MessagesPage> {
|
|||||||
_messages.sort((a, b) => b.createdAt! > a.createdAt! ? 1 : 0);
|
_messages.sort((a, b) => b.createdAt! > a.createdAt! ? 1 : 0);
|
||||||
|
|
||||||
message.read = true;
|
message.read = true;
|
||||||
MyApp.isarInstance.writeTxnSync(() {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
MyApp.isarInstance.messages.putSync(message);
|
await MyApp.isarInstance.messages.put(message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,8 +179,8 @@ class _MessagesPageState extends State<MessagesPage> {
|
|||||||
),
|
),
|
||||||
const SizedBox(width: 20),
|
const SizedBox(width: 20),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: getDefaultButton('Ja', () => {
|
child: getDefaultButton('Ja', () async => {
|
||||||
MyApp.isarInstance.writeTxnSync(() => {MyApp.isarInstance.messages.deleteSync(int.parse(message.id))}),
|
await MyApp.isarInstance.writeTxnSync(() async => { await MyApp.isarInstance.messages.delete(int.parse(message.id))}),
|
||||||
|
|
||||||
_fetchMessages(),
|
_fetchMessages(),
|
||||||
|
|
||||||
|
|||||||
@@ -500,6 +500,7 @@ class _TaskListPageState extends State<TaskListPage> {
|
|||||||
MqttCore.instance.publishPayloadMessage("fin_tour", finTourMessage.toJson());
|
MqttCore.instance.publishPayloadMessage("fin_tour", finTourMessage.toJson());
|
||||||
|
|
||||||
widget.tour.state = Constants.stateFinishedNotConfirmed;
|
widget.tour.state = Constants.stateFinishedNotConfirmed;
|
||||||
|
|
||||||
await MyApp.isarInstance.writeTxn(() async {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
await MyApp.isarInstance.jobs.put(widget.job);
|
await MyApp.isarInstance.jobs.put(widget.job);
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -18,8 +18,8 @@ import 'package:stadtbote/tools/connection_status.dart';
|
|||||||
import 'package:stadtbote/tools/message_service.dart';
|
import 'package:stadtbote/tools/message_service.dart';
|
||||||
import 'package:stadtbote/tools/messages/job_received_message.dart';
|
import 'package:stadtbote/tools/messages/job_received_message.dart';
|
||||||
import 'package:stadtbote/tools/messages/update_badges_message.dart';
|
import 'package:stadtbote/tools/messages/update_badges_message.dart';
|
||||||
|
import 'package:stadtbote/tools/mqtt_core.dart';
|
||||||
|
|
||||||
import 'tools/mqtt_core.dart';
|
|
||||||
import 'content_views/main_page.dart';
|
import 'content_views/main_page.dart';
|
||||||
import 'content_views/utils/content_view_widget.dart';
|
import 'content_views/utils/content_view_widget.dart';
|
||||||
import 'content_views/utils/widget_stack.dart';
|
import 'content_views/utils/widget_stack.dart';
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ Future<void> showAcceptJobsPopup(BuildContext context, List<Job> jobs, Function
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendAnswer(Job job, int item) {
|
_sendAnswer(Job job, int item) async {
|
||||||
var currentPosition = MyApp.currentPosition;
|
var currentPosition = MyApp.currentPosition;
|
||||||
|
|
||||||
var message = AcceptJobMessage();
|
var message = AcceptJobMessage();
|
||||||
@@ -229,5 +229,5 @@ _sendAnswer(Job job, int item) {
|
|||||||
MqttCore.instance.publishPayloadMessage("job", message.toJson());
|
MqttCore.instance.publishPayloadMessage("job", message.toJson());
|
||||||
|
|
||||||
job.state = 9;
|
job.state = 9;
|
||||||
MyApp.isarInstance.writeTxnSync(() => {MyApp.isarInstance.jobs.putSync(job)});
|
await MyApp.isarInstance.writeTxn(() async => { await MyApp.isarInstance.jobs.put(job)});
|
||||||
}
|
}
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import 'package:json_annotation/json_annotation.dart';
|
|
||||||
import 'package:stadtbote/model/log_entry.dart';
|
|
||||||
|
|
||||||
part 'device_log.g.dart';
|
|
||||||
|
|
||||||
@JsonSerializable()
|
|
||||||
class DeviceLog {
|
|
||||||
late List<LogEntry> entries;
|
|
||||||
|
|
||||||
DeviceLog();
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => _$DeviceLogToJson(this);
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
|
|
||||||
part of 'device_log.dart';
|
|
||||||
|
|
||||||
// **************************************************************************
|
|
||||||
// JsonSerializableGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
DeviceLog _$DeviceLogFromJson(Map<String, dynamic> json) => DeviceLog()
|
|
||||||
..entries = (json['entries'] as List<dynamic>)
|
|
||||||
.map((e) => LogEntry.fromJson(e as Map<String, dynamic>))
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
Map<String, dynamic> _$DeviceLogToJson(DeviceLog instance) => <String, dynamic>{
|
|
||||||
'entries': instance.entries,
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import 'dart:core';
|
||||||
|
|
||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
|
part 'device_log_request.g.dart';
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class DeviceLogRequest {
|
||||||
|
late DateTime startDateTime;
|
||||||
|
|
||||||
|
late DateTime endDateTime;
|
||||||
|
|
||||||
|
DeviceLogRequest();
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$DeviceLogRequestToJson(this);
|
||||||
|
|
||||||
|
factory DeviceLogRequest.fromJson(Map<String, dynamic> json) => _$DeviceLogRequestFromJson(json);
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'device_log_request.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonSerializableGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
DeviceLogRequest _$DeviceLogRequestFromJson(Map<String, dynamic> json) =>
|
||||||
|
DeviceLogRequest()
|
||||||
|
..startDateTime = DateTime.parse(json['startDateTime'] as String)
|
||||||
|
..endDateTime = DateTime.parse(json['endDateTime'] as String);
|
||||||
|
|
||||||
|
Map<String, dynamic> _$DeviceLogRequestToJson(DeviceLogRequest instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'startDateTime': instance.startDateTime.toIso8601String(),
|
||||||
|
'endDateTime': instance.endDateTime.toIso8601String(),
|
||||||
|
};
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
import 'package:stadtbote/model/log_entry.dart';
|
||||||
|
|
||||||
|
part 'device_log_response.g.dart';
|
||||||
|
|
||||||
|
@JsonSerializable()
|
||||||
|
class DeviceLogResponse {
|
||||||
|
late List<LogEntry> entries;
|
||||||
|
|
||||||
|
DeviceLogResponse();
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => _$DeviceLogResponseToJson(this);
|
||||||
|
|
||||||
|
factory DeviceLogResponse.fromJson(Map<String, dynamic> json) => _$DeviceLogResponseFromJson(json);
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'device_log_response.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonSerializableGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
DeviceLogResponse _$DeviceLogResponseFromJson(Map<String, dynamic> json) =>
|
||||||
|
DeviceLogResponse()
|
||||||
|
..entries = (json['entries'] as List<dynamic>)
|
||||||
|
.map((e) => LogEntry.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
Map<String, dynamic> _$DeviceLogResponseToJson(DeviceLogResponse instance) =>
|
||||||
|
<String, dynamic>{
|
||||||
|
'entries': instance.entries,
|
||||||
|
};
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:archive/archive.dart';
|
||||||
import 'package:device_info_plus/device_info_plus.dart';
|
import 'package:device_info_plus/device_info_plus.dart';
|
||||||
import 'package:isar/isar.dart';
|
import 'package:isar/isar.dart';
|
||||||
import 'package:mqtt_client/mqtt_client.dart';
|
import 'package:mqtt_client/mqtt_client.dart';
|
||||||
@@ -13,7 +15,8 @@ import 'package:stadtbote/model/status.dart';
|
|||||||
import 'package:stadtbote/protocoll_messages/acknowledge_job.dart';
|
import 'package:stadtbote/protocoll_messages/acknowledge_job.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/bootstrap_request.dart';
|
import 'package:stadtbote/protocoll_messages/bootstrap_request.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/bootstrap_response_payload.dart';
|
import 'package:stadtbote/protocoll_messages/bootstrap_response_payload.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/device_log.dart';
|
import 'package:stadtbote/protocoll_messages/device_log_request.dart';
|
||||||
|
import 'package:stadtbote/protocoll_messages/device_log_response.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/device_object.dart';
|
import 'package:stadtbote/protocoll_messages/device_object.dart';
|
||||||
import 'package:stadtbote/model/job.dart';
|
import 'package:stadtbote/model/job.dart';
|
||||||
import 'package:stadtbote/model/message.dart';
|
import 'package:stadtbote/model/message.dart';
|
||||||
@@ -133,13 +136,22 @@ class MqttCore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
publishBinary(String topic, List<int> data) {
|
||||||
|
var buffer = Uint8Buffer();
|
||||||
|
buffer.addAll(data);
|
||||||
|
|
||||||
|
_mqttClient.publishMessage(topic, MqttQos.exactlyOnce, buffer);
|
||||||
|
|
||||||
|
Util.logInfo("binary message send to $topic");
|
||||||
|
}
|
||||||
|
|
||||||
publishText(String topic, String text) {
|
publishText(String topic, String text) {
|
||||||
var buffer = Uint8Buffer();
|
var buffer = Uint8Buffer();
|
||||||
buffer.addAll(utf8.encode(text));
|
buffer.addAll(utf8.encode(text));
|
||||||
|
|
||||||
_mqttClient.publishMessage(topic, MqttQos.exactlyOnce, buffer);
|
_mqttClient.publishMessage(topic, MqttQos.exactlyOnce, buffer);
|
||||||
|
|
||||||
Util.logInfo("message\n$text\nsend to $topic");
|
//Util.logInfo("message\n$text\nsend to $topic");
|
||||||
}
|
}
|
||||||
|
|
||||||
publishPayloadMessage(String topic, Map<String, dynamic> payload) {
|
publishPayloadMessage(String topic, Map<String, dynamic> payload) {
|
||||||
@@ -274,8 +286,8 @@ class MqttCore {
|
|||||||
for (var foundJobData in payloadData) {
|
for (var foundJobData in payloadData) {
|
||||||
Job newJob = Job.fromJson(foundJobData);
|
Job newJob = Job.fromJson(foundJobData);
|
||||||
|
|
||||||
MyApp.isarInstance.writeTxnSync(() async {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
MyApp.isarInstance.jobs.putSync(newJob);
|
await MyApp.isarInstance.jobs.put(newJob);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (newJob.state == Constants.stateAssigned) {
|
if (newJob.state == Constants.stateAssigned) {
|
||||||
@@ -325,12 +337,21 @@ class MqttCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _messageDeviceLogReceived(payloadData) async {
|
void _messageDeviceLogReceived(payloadData) async {
|
||||||
var logEintries = await MyApp.isarInstance.logEntrys.where().findAll();
|
var deviceLogRequest = DeviceLogRequest.fromJson(payloadData);
|
||||||
|
|
||||||
var deviceLog = DeviceLog();
|
var logEintries = await MyApp.isarInstance.logEntrys.filter().timeGreaterThan(deviceLogRequest.startDateTime).findAll();
|
||||||
|
|
||||||
|
var deviceLog = DeviceLogResponse();
|
||||||
deviceLog.entries = logEintries;
|
deviceLog.entries = logEintries;
|
||||||
|
|
||||||
MqttCore.instance.publishPayloadMessage("device_log", deviceLog.toJson());
|
//MqttCore.instance.publishPayloadMessage("device_log", deviceLog.toJson());
|
||||||
|
|
||||||
|
var json = jsonEncode(deviceLog.toJson());
|
||||||
|
var stringBytes = utf8.encode(json);
|
||||||
|
var gzipBytes = GZipEncoder().encode(stringBytes);
|
||||||
|
|
||||||
|
var topic = "/log/${_toServerTopic.replaceAll("/app/", "").replaceAll("/to_server", "")}";
|
||||||
|
publishBinary(topic, gzipBytes!);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _startReconnectTimer() {
|
void _startReconnectTimer() {
|
||||||
|
|||||||
+3
-3
@@ -86,14 +86,14 @@ class Util {
|
|||||||
pattern.allMatches(text).forEach((match) => debugPrint(match.group(0)));
|
pattern.allMatches(text).forEach((match) => debugPrint(match.group(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _persistLogMessage(String text, LogEntrySeverityEnum severity) {
|
static void _persistLogMessage(String text, LogEntrySeverityEnum severity) async {
|
||||||
var logEntry = LogEntry();
|
var logEntry = LogEntry();
|
||||||
logEntry.time = DateTime.now();
|
logEntry.time = DateTime.now();
|
||||||
logEntry.text = text;
|
logEntry.text = text;
|
||||||
logEntry.severity = severity;
|
logEntry.severity = severity;
|
||||||
|
|
||||||
MyApp.isarInstance.writeTxnSync(() {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
MyApp.isarInstance.logEntrys.putSync(logEntry);
|
await MyApp.isarInstance.logEntrys.put(logEntry);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user