further changes of gui

This commit is contained in:
dj2ls 2022-06-07 11:31:59 +02:00
parent 8e4a3f4d33
commit a4df21c0a2
3 changed files with 98 additions and 167 deletions

View file

@ -73,7 +73,7 @@ db.find({
// handle result
if (typeof(result) !== 'undefined') {
result.docs.forEach(function(item) {
console.log(item)
//console.log(item)
update_chat(item);
});
}
@ -179,14 +179,8 @@ db.post({
}).catch(function(err) {
console.log(err);
});
db.get(uuid, [{
attachments: true
}]).then(function(doc) {
// handle doc
update_chat(doc)
}).catch(function(err) {
console.log(err);
});
update_chat_obj_by_uuid(uuid);
});
// SEND MSG
@ -237,14 +231,9 @@ db.post({
}).catch(function(err) {
console.log(err);
});
db.get(uuid, [{
attachments: true
}]).then(function(doc) {
// handle doc
update_chat(doc)
}).catch(function(err) {
console.log(err);
});
update_chat_obj_by_uuid(uuid);
// scroll to bottom
var element = document.getElementById("message-container");
element.scrollTo(0, element.scrollHeight);
@ -274,7 +263,7 @@ ipcRenderer.on('return-selected-files', (event, arg) => {
`;
});
ipcRenderer.on('action-update-transmission-status', (event, arg) => {
console.log(arg.status);
//console.log(arg.status);
console.log(arg.uuid);
db.get(arg.uuid, {
attachments: true
@ -295,26 +284,22 @@ ipcRenderer.on('action-update-transmission-status', (event, arg) => {
_attachments: doc._attachments
});
}).then(function(response) {
// handle response
db.get(arg.uuid, [{
attachments: true
}]).then(function(doc) {
// handle doc
update_chat(doc);
}).catch(function(err) {
console.log(err);
});
update_chat_obj_by_uuid(arg.uuid);
}).catch(function(err) {
console.log(err);
});
});
ipcRenderer.on('action-new-msg-received', (event, arg) => {
console.log(arg.data)
var new_msg = arg.data;
new_msg.forEach(function(item) {
console.log(item)
let obj = new Object();
if (item.type == 'ping') {
//handle ping
if (item.ping == 'received') {
obj.timestamp = item.timestamp;
obj.dxcallsign = item.dxcallsign;
obj.dxgrid = item.dxgrid;
@ -324,38 +309,18 @@ ipcRenderer.on('action-new-msg-received', (event, arg) => {
obj.msg = 'null';
obj.status = item.status;
obj.snr = item.snr;
obj.type = item.type;
db.put({
_id: obj.uuid,
timestamp: obj.timestamp,
uuid: obj.uuid,
dxcallsign: obj.dxcallsign,
dxgrid: obj.dxgrid,
msg: obj.msg,
checksum: obj.checksum,
type: obj.type,
command: obj.command,
status: obj.status,
snr: obj.snr,
}).then(function(response) {
console.log("new database entry");
console.log(response);
}).catch(function(err) {
console.log(err);
});
db.get(item.uuid, {
attachments: true
}).then(function(doc) {
console.log(doc)
update_chat(doc);
obj.type = 'ping';
obj.filename = 'null';
obj.filetype = 'null';
obj.file = 'null';
}).catch(function(err) {
console.log(err);
});
add_obj_to_database(obj)
update_chat_obj_by_uuid(obj.uuid);
// Handle beacon
// handle beacon
} else if (item.beacon == 'received') {
obj.timestamp = item.timestamp;
obj.dxcallsign = item.dxcallsign;
@ -367,34 +332,13 @@ ipcRenderer.on('action-new-msg-received', (event, arg) => {
obj.status = item.status;
obj.snr = item.snr;
obj.type = 'beacon';
db.put({
_id: obj.uuid,
timestamp: obj.timestamp,
uuid: obj.uuid,
dxcallsign: obj.dxcallsign,
dxgrid: obj.dxgrid,
msg: obj.msg,
checksum: obj.checksum,
type: obj.type,
command: obj.command,
status: obj.status,
snr: obj.snr,
}).then(function(response) {
console.log("new database entry");
console.log(response);
}).catch(function(err) {
console.log(err);
});
db.get(item.uuid, {
attachments: true
}).then(function(doc) {
console.log(doc);
update_chat(doc);
}).catch(function(err) {
console.log(err);
});
obj.filename = 'null';
obj.filetype = 'null';
obj.file = 'null';
add_obj_to_database(obj);
update_chat_obj_by_uuid(obj.uuid);
// handle ARQ transmission
} else if (item.arq == 'received') {
@ -414,46 +358,20 @@ ipcRenderer.on('action-new-msg-received', (event, arg) => {
obj.filename = utf8.decode(splitted_data[5]);
obj.filetype = utf8.decode(splitted_data[6]);
obj.file = btoa(utf8.decode(splitted_data[7]));
db.put({
_id: obj.uuid,
timestamp: obj.timestamp,
uuid: obj.uuid,
dxcallsign: obj.dxcallsign,
dxgrid: obj.dxgrid,
msg: obj.msg,
checksum: obj.checksum,
type: obj.type,
command: obj.command,
status: obj.status,
snr: obj.snr,
_attachments: {
[obj.filename]: {
content_type: obj.filetype,
data: obj.file
}
}
}).then(function(response) {
console.log("new database entry");
console.log(response);
}).catch(function(err) {
console.log(err);
});
db.get(obj.uuid, {
attachments: true
}).then(function(doc) {
console.log(doc);
update_chat(doc);
}).catch(function(err) {
console.log(err);
});
add_obj_to_database(obj);
update_chat_obj_by_uuid(obj.uuid);
}
});
//window.location = window.location;
});
// Update chat list
update_chat = function(obj) {
//console.log(obj);
var dxcallsign = obj.dxcallsign;
var timestamp = dateFormat.format(obj.timestamp * 1000);
var timestampShort = dateFormatShort.format(obj.timestamp * 1000);
@ -471,7 +389,7 @@ update_chat = function(obj) {
}
try {
console.log(Object.keys(obj._attachments)[0].length)
//console.log(Object.keys(obj._attachments)[0].length)
if (typeof(obj._attachments) !== 'undefined' && Object.keys(obj._attachments)[0].length > 0) {
//var filename = obj._attachments;
var filename = Object.keys(obj._attachments)[0]
@ -558,7 +476,7 @@ update_chat = function(obj) {
// scroll to bottom
var element = document.getElementById("message-container");
console.log(element.scrollHeight)
//console.log(element.scrollHeight)
element.scrollTo(0, element.scrollHeight);
@ -642,16 +560,14 @@ update_chat = function(obj) {
if (obj.type == 'transmit') {
console.log('msg-' + obj._id + '-status')
if (obj.status == 'failed'){
var progressbar_bg = 'bg-danger';
} else {
var progressbar_bg = 'bg-primary';
}
//console.log('msg-' + obj._id + '-status')
if (obj.status == 'failed'){
var progressbar_bg = 'bg-danger';
} else {
var progressbar_bg = 'bg-primary';
}
var new_message = `
<div class="d-flex align-items-center"> <!-- max-width: 75%; w-75 -->
@ -703,7 +619,7 @@ update_chat = function(obj) {
document.getElementById(id).insertAdjacentHTML("beforeend", new_message);
var element = document.getElementById("message-container");
console.log(element.scrollHeight)
//console.log(element.scrollHeight)
@ -823,39 +739,7 @@ update_chat = function(obj) {
//window.location = window.location
}
function getObjByID(id) {
/*
{
"timestamp": 1648139683,
"dxcallsign": "DN2LS-0",
"dxgrid": "null",
"msg": "",
"checksum": "null",
"type": "transmit",
"status": "transmit",
"uuid": "5b72a46c-49cf-40d6-8936-a64c95bc3da7",
"_attachments": {
"CMakeLists.txt": {
"content_type": "text/plain",
"digest": "md5-Cdk6Ol6uuJ7Gj5lin9o4SQ==",
"length": 7802,
"revpos": 1,
"stub": true
}
},
"_id": "5b72a46c-49cf-40d6-8936-a64c95bc3da7",
"_rev": "1-6df2d7227c4f89f8a3a2b4978661dd79"
}
**/
db.get(id, {
attachments: true
}).then(function(doc) {
return obj
}).catch(function(err) {
console.log(err);
return false
});
}
function saveFileToFolder(id) {
db.get(id, {
@ -905,3 +789,44 @@ function get_icon_for_state(state) {
}
return status_icon;
};
update_chat_obj_by_uuid = function(uuid) {
db.get(uuid, {
attachments: true
}).then(function(doc) {
update_chat(doc)
//return doc
}).catch(function(err) {
console.log(err);
});
}
add_obj_to_database = function(obj){
db.put({
_id: obj.uuid,
timestamp: obj.timestamp,
uuid: obj.uuid,
dxcallsign: obj.dxcallsign,
dxgrid: obj.dxgrid,
msg: obj.msg,
checksum: obj.checksum,
type: obj.type,
command: obj.command,
status: obj.status,
snr: obj.snr,
_attachments: {
[obj.filename]: {
content_type: obj.filetype,
data: obj.file
}
}
}).then(function(response) {
console.log("new database entry");
console.log(response);
}).catch(function(err) {
console.log(err);
});
}

View file

@ -1933,6 +1933,8 @@ ipcRenderer.on('action-show-arq-toast-transmission-receiving', (event, data) =>
var toast = bootstrap.Toast.getOrCreateInstance(toastARQreceiving); // Returns a Bootstrap toast instance
toast.show();
});
/*
// TRANSMISSION STOPPED
if (arg.info[i] == "TRANSMISSION;STOPPED"){

View file

@ -1863,9 +1863,13 @@ class DATA:
self.send_data_to_socket_queue(
freedata="tnc-message",
ping="receiving",
ping="received",
uuid=str(uuid.uuid4()),
timestamp=int(time.time()),
mycallsign=str(self.mycallsign, "UTF-8"),
dxcallsign=str(static.DXCALLSIGN, "UTF-8"),
dxgrid=str(static.DXGRID, "UTF-8"),
snr=str(static.SNR)
)
# check if callsign ssid override
valid, mycallsign = helpers.check_callsign(self.mycallsign, data_in[1:4])