Prettified Code!

This commit is contained in:
DJ2LS 2023-02-20 17:55:21 +00:00 committed by GitHub Action
parent 68e10bad3e
commit 08cb8bb785
4 changed files with 360 additions and 377 deletions

View File

@ -67,9 +67,8 @@ var db = new PouchDB(chatDB);
var users = new PouchDB(userDB);
/* -------- CREATE DATABASE INDEXES */
createChatIndex()
createUserIndex()
createChatIndex();
createUserIndex();
/*
// REMOTE SYNC ATTEMPTS
@ -113,17 +112,16 @@ db.sync('http://172.20.10.4:5984/jojo', {
});
*/
var dxcallsigns = new Set();
var chatFilter = [{type:'newchat'}, {type:'received'}, {type:'transmit'}, {type:'ping-ack'}]
var chatFilter = [
{ type: "newchat" },
{ type: "received" },
{ type: "transmit" },
{ type: "ping-ack" },
];
updateAllChat(false);
// WINDOW LISTENER
window.addEventListener("DOMContentLoaded", () => {
// theme selector
@ -136,9 +134,6 @@ window.addEventListener("DOMContentLoaded", () => {
document.getElementById("bootstrap_theme").href = theme_path;
}
const userInfoFields = [
"user_info_callsign",
"user_info_gridsquare",
@ -152,15 +147,13 @@ window.addEventListener("DOMContentLoaded", () => {
"user_info_comments",
];
// add initial entry for own callsign and grid
if(document.getElementById("user_info_callsign").value !== config.mycall){
let obj = new Object();
obj.user_info_callsign = config.mycall;
obj.user_info_gridsquare = config.mygrid;
// add initial entry for own callsign and grid
if (document.getElementById("user_info_callsign").value !== config.mycall) {
let obj = new Object();
obj.user_info_callsign = config.mycall;
obj.user_info_gridsquare = config.mygrid;
addUserToDatabaseIfNotExists(obj);
}
}
users
.find({
@ -169,19 +162,17 @@ window.addEventListener("DOMContentLoaded", () => {
},
})
.then(function (result) {
if (typeof(result.docs[0]) !== "undefined") {
// handle result
userInfoFields.forEach(function (elem) {
document.getElementById(elem).value = result.docs[0][elem];
});
if (typeof result.docs[0] !== "undefined") {
// handle result
userInfoFields.forEach(function (elem) {
document.getElementById(elem).value = result.docs[0][elem];
});
}
})
.catch(function (err) {
console.log(err);
});
// user info bulk event listener for saving settings
userInfoFields.forEach(function (elem) {
try {
@ -192,7 +183,7 @@ window.addEventListener("DOMContentLoaded", () => {
userInfoFields.forEach(function (subelem) {
obj[subelem] = document.getElementById(subelem).value;
});
console.log(obj)
console.log(obj);
addUserToDatabaseIfNotExists(obj);
});
} catch (e) {
@ -202,12 +193,16 @@ window.addEventListener("DOMContentLoaded", () => {
});
//Add event listener for filter apply button
document.getElementById("btnFilter").addEventListener("click",() => {
chatFilter=[{type:'newchat'}];
if (document.getElementById('chkMessage').checked == true) chatFilter.push({type:'received'},{type:'transmit'});
if (document.getElementById('chkPing').checked == true) chatFilter.push({type:'ping'});
if (document.getElementById('chkPingAck').checked == true) chatFilter.push({type:'ping-ack'});
if (document.getElementById('chkBeacon').checked == true) chatFilter.push({type:'beacon'});
document.getElementById("btnFilter").addEventListener("click", () => {
chatFilter = [{ type: "newchat" }];
if (document.getElementById("chkMessage").checked == true)
chatFilter.push({ type: "received" }, { type: "transmit" });
if (document.getElementById("chkPing").checked == true)
chatFilter.push({ type: "ping" });
if (document.getElementById("chkPingAck").checked == true)
chatFilter.push({ type: "ping-ack" });
if (document.getElementById("chkBeacon").checked == true)
chatFilter.push({ type: "beacon" });
updateAllChat(true);
});
@ -277,12 +272,11 @@ window.addEventListener("DOMContentLoaded", () => {
});
document.addEventListener("keyup", function (event) {
// Number 13 == Enter
if (event.keyCode === 13
&& !event.shiftKey
&& document.activeElement.id == 'chatModuleMessage'
if (
event.keyCode === 13 &&
!event.shiftKey &&
document.activeElement.id == "chatModuleMessage"
) {
// Cancel the default action, if needed
event.preventDefault();
@ -1016,38 +1010,38 @@ update_chat = function (obj) {
//document.getElementById(id).className = message_class;
}
//Delete message event listener
if (
document.getElementById("del-msg-" + obj._id) &&
!document
.getElementById("del-msg-" + obj._id)
.hasAttribute("listenerOnClick")
) {
// set Attribute to determine if we already created an EventListener for this element
document
.getElementById("del-msg-" + obj._id)
.setAttribute("listenerOnClick", "true");
document
.getElementById("del-msg-" + obj._id)
.addEventListener("click", () => {
db.get(obj._id, {
attachments: true,
})
.then(function (doc) {
db.remove(doc._id,doc._rev,function (err) {
if (err) console.log("Error removing item " + err);
//Delete message event listener
if (
document.getElementById("del-msg-" + obj._id) &&
!document
.getElementById("del-msg-" + obj._id)
.hasAttribute("listenerOnClick")
) {
// set Attribute to determine if we already created an EventListener for this element
document
.getElementById("del-msg-" + obj._id)
.setAttribute("listenerOnClick", "true");
document
.getElementById("del-msg-" + obj._id)
.addEventListener("click", () => {
db.get(obj._id, {
attachments: true,
})
.then(function (doc) {
db.remove(doc._id, doc._rev, function (err) {
if (err) console.log("Error removing item " + err);
});
})
})
.catch(function (err) {
console.log(err);
})
.catch(function (err) {
console.log(err);
});
document.getElementById("msg-" + obj._id).remove();
document.getElementById("msg-" + obj._id + "-control-area").remove();
console.log("Removed message " + obj._id.toString());
})
//scrollMessagesToBottom();
};
document.getElementById("msg-" + obj._id).remove();
document.getElementById("msg-" + obj._id + "-control-area").remove();
console.log("Removed message " + obj._id.toString());
});
//scrollMessagesToBottom();
}
// CREATE SAVE TO FOLDER EVENT LISTENER
if (
@ -1283,7 +1277,7 @@ addUserToDatabaseIfNotExists = function (obj) {
"user_info_website",
"user_info_comments",
*/
console.log(obj)
console.log(obj);
users
.find({
selector: {
@ -1394,111 +1388,94 @@ function atob_FD(data) {
return Buffer.from(data, "base64").toString("utf-8");
}
function returnObjFromCallsign(database, callsign) {
users
.find(
{
selector: {
user_info_callsign: callsign,
},
}
)
.then(
function (result) {
if (typeof(result.docs[0]) !== "undefined") {
return result.docs[0];
} else {
return false
}
}
)
.catch(function (err) {
console.log(err);
});
users
.find({
selector: {
user_info_callsign: callsign,
},
})
.then(function (result) {
if (typeof result.docs[0] !== "undefined") {
return result.docs[0];
} else {
return false;
}
})
.catch(function (err) {
console.log(err);
});
}
function createChatIndex(){
db.createIndex({
index: {
fields: [
"timestamp",
"uuid",
"dxcallsign",
"dxgrid",
"msg",
"checksum",
"type",
"command",
"status",
"percent",
"bytesperminute",
"_attachments",
],
},
})
.then(function (result) {
// handle result
console.log(result);
})
.catch(function (err) {
console.log(err);
});
}
function createUserIndex(){
users
.createIndex({
function createChatIndex() {
db.createIndex({
index: {
fields: [
"timestamp",
"user_info_callsign",
"user_info_gridsquare",
"user_info_name",
"user_info_age",
"user_info_location",
"user_info_radio",
"user_info_antenna",
"user_info_email",
"user_info_website",
"user_info_comments",
"uuid",
"dxcallsign",
"dxgrid",
"msg",
"checksum",
"type",
"command",
"status",
"percent",
"bytesperminute",
"_attachments",
],
},
})
.then(function (result) {
// handle result
console.log(result);
return true
})
.catch(function (err) {
console.log(err);
return false
});
.then(function (result) {
// handle result
console.log(result);
})
.catch(function (err) {
console.log(err);
});
}
function updateAllChat(clear){
if (clear == true)
{
function createUserIndex() {
users
.createIndex({
index: {
fields: [
"timestamp",
"user_info_callsign",
"user_info_gridsquare",
"user_info_name",
"user_info_age",
"user_info_location",
"user_info_radio",
"user_info_antenna",
"user_info_email",
"user_info_website",
"user_info_comments",
"_attachments",
],
},
})
.then(function (result) {
// handle result
console.log(result);
return true;
})
.catch(function (err) {
console.log(err);
return false;
});
}
function updateAllChat(clear) {
if (clear == true) {
filetype = "";
file = "";
filename = "";
callsign_counter = 0;
selected_callsign = "";
dxcallsigns=new Set();
document.getElementById("list-tab").innerHTML="";
document.getElementById("nav-tabContent").innerHTML="";
dxcallsigns = new Set();
document.getElementById("list-tab").innerHTML = "";
document.getElementById("nav-tabContent").innerHTML = "";
//document.getElementById("list-tab").childNodes.remove();
//document.getElementById("nav-tab-content").childrenNodes.remove();
}
@ -1506,17 +1483,14 @@ function updateAllChat(clear){
//We can't rely on the default index existing before we get here...... :'(
db.createIndex({
index: {
fields: [
{"timestamp":"asc"},
],
fields: [{ timestamp: "asc" }],
},
})
.then(function (result) {
// handle result
db.find({
selector: {
$and: [{timestamp: {$exists:true}},
{$or:chatFilter}],
$and: [{ timestamp: { $exists: true } }, { $or: chatFilter }],
//$or: chatFilter
},
sort: [
@ -1528,15 +1502,16 @@ function updateAllChat(clear){
.then(async function (result) {
// handle result async
if (typeof result !== "undefined") {
for (const item of result.docs)
{
//await otherwise history will not be in chronological order
await db.get(item._id, {
for (const item of result.docs) {
//await otherwise history will not be in chronological order
await db
.get(item._id, {
attachments: true,
}).then(function (item_with_attachments) {
})
.then(function (item_with_attachments) {
update_chat(item_with_attachments);
});
}
}
}
})
.catch(function (err) {
@ -1546,5 +1521,4 @@ function updateAllChat(clear){
.catch(function (err) {
console.log(err);
});
}

View File

@ -1575,7 +1575,7 @@ ipcRenderer.on("action-update-transmission-status", (event, arg) => {
" (comp: " +
formatBytes(arq_bytes_per_minute_compressed, 1) +
")</strong>";
document.getElementById("transmission_timeleft").innerHTML = time_left;
document.getElementById("transmission_timeleft").innerHTML = time_left;
connectedStation(data);
});

View File

@ -421,9 +421,10 @@ client.on("data", function (socketdata) {
break;
default:
ipcRenderer.send("request-update-transmission-status", {
data: [data], });
data: [data],
});
break;
}
}
break;
case "received":

View File

@ -67,27 +67,25 @@
<i class="bi bi-pencil-square" style="font-size: 1.2rem"></i>
</button>
<button
type="button"
id="userModalButton"
data-bs-toggle="modal"
data-bs-target="#userModal"
class="btn btn-sm btn-primary ms-2"
><i class="bi bi-person" style="font-size: 1.2rem"></i></button>
<button
>
<i class="bi bi-person" style="font-size: 1.2rem"></i>
</button>
<button
type="button"
id="sharedFolderButton"
data-bs-toggle="modal"
data-bs-target="#sharedFolderModal"
class="btn btn-sm btn-primary"
><i class="bi bi-files" style="font-size: 1.2rem"></i></button>
>
<i class="bi bi-files" style="font-size: 1.2rem"></i>
</button>
</div>
</div>
<hr class="m-2" />
<div class="overflow-auto vh-100">
@ -111,83 +109,109 @@
Ping
</button>
<button
id="chatSettingsDropDown"
type="button"
class="btn btn-outline-secondary dropdown-toggle"
data-bs-toggle="dropdown"
aria-expanded="false"
>
<i class="bi bi-three-dots-vertical"></i>
</button>
<ul class="dropdown-menu" aria-labelledby="chatSettingsDropDown">
<li>
<a
class="dropdown-item bg-danger text-white"
id="delete_selected_chat"
href="#"
>Delete chat</a
>
</li>
</ul>
id="chatSettingsDropDown"
type="button"
class="btn btn-outline-secondary dropdown-toggle"
data-bs-toggle="dropdown"
aria-expanded="false"
>
<i class="bi bi-three-dots-vertical"></i>
</button>
<ul class="dropdown-menu" aria-labelledby="chatSettingsDropDown">
<li>
<a
class="dropdown-item bg-danger text-white"
id="delete_selected_chat"
href="#"
>Delete chat</a
>
</li>
</ul>
<button
<button
type="button"
id="userModalDXButton"
data-bs-toggle="modal"
data-bs-target="#userModalDX"
class="btn btn-sm btn-secondary"
><i class="bi bi-person" style="font-size: 1.2rem"></i></button>
>
<i class="bi bi-person" style="font-size: 1.2rem"></i>
</button>
<button
<button
type="button"
id="sharedFolderDXButton"
data-bs-toggle="modal"
data-bs-target="#sharedFolderModalDX"
class="btn btn-sm btn-secondary"
><i class="bi bi-files" style="font-size: 1.2rem"></i></button>
>
<i class="bi bi-files" style="font-size: 1.2rem"></i>
</button>
<button type="button" class="btn btn-small btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" data-bs-auto-close="outside">
<i class="bi bi-funnel-fill"></i>
<button
type="button"
class="btn btn-small btn-primary dropdown-toggle"
data-bs-toggle="dropdown"
aria-expanded="false"
data-bs-auto-close="outside"
>
<i class="bi bi-funnel-fill"></i>
</button>
<form class="dropdown-menu p-4" id="frmFilter">
<div class="mb-1">
<div class="form-check">
<input
checked="true"
type="checkbox"
class="form-check-input"
id="chkMessage"
/>
<label class="form-check-label" for="chkMessage">
Messages
</label>
</div>
</div>
<div class="mb-1">
<div class="form-check">
<input
type="checkbox"
class="form-check-input"
id="chkPing"
/>
<label class="form-check-label" for="chkPing">
Pings
</label>
</div>
</div>
<div class="mb-1">
<div class="form-check">
<input
checked="true"
type="checkbox"
class="form-check-input"
id="chkPingAck"
/>
<label class="form-check-label" for="chkPingAck">
Ping-Acks
</label>
</div>
</div>
<div class="mb-1">
<div class="form-check">
<input
type="checkbox"
class="form-check-input"
id="chkBeacon"
/>
<label class="form-check-label" for="chkBeacon">
Beacons
</label>
</div>
</div>
<button type="button" class="btn btn-primary" id="btnFilter">
Refresh
</button>
<form class="dropdown-menu p-4" id="frmFilter">
<div class="mb-1">
<div class="form-check">
<input checked="true" type="checkbox" class="form-check-input" id="chkMessage">
<label class="form-check-label" for="chkMessage">
Messages
</label>
</div>
</div>
<div class="mb-1">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="chkPing">
<label class="form-check-label" for="chkPing">
Pings
</label>
</div>
</div>
<div class="mb-1">
<div class="form-check">
<input checked="true" type="checkbox" class="form-check-input" id="chkPingAck">
<label class="form-check-label" for="chkPingAck">
Ping-Acks
</label>
</div>
</div>
<div class="mb-1">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="chkBeacon">
<label class="form-check-label" for="chkBeacon">
Beacons
</label>
</div>
</div>
<button type="button" class="btn btn-primary" id="btnFilter">Refresh</button>
</form>
</form>
</div>
</div>
<hr class="m-0" />
@ -256,8 +280,8 @@
</div>
</div>
</div>
<!-- user modal -->
<div
<!-- user modal -->
<div
class="modal fade"
id="userModal"
tabindex="-1"
@ -267,7 +291,9 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="userModalLabel">My station info</h1>
<h1 class="modal-title fs-5" id="userModalLabel">
My station info
</h1>
<button
type="button"
@ -275,128 +301,124 @@
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body">
<div class="container-fluid">
<div class="input-group input-group-sm mb-1">
<span class="input-group-text w-25">Callsign</span>
<input
type="text"
class="form-control"
placeholder="Callsign"
id="user_info_callsign"
aria-label="Name"
aria-describedby="basic-addon1"
/>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text w-25">Name</span>
<input
type="text"
class="form-control"
placeholder="Name"
id="user_info_name"
aria-label="Name"
aria-describedby="basic-addon1"
/>
<span class="input-group-text w-25">Callsign</span>
<input
type="text"
class="form-control"
placeholder="Callsign"
id="user_info_callsign"
aria-label="Name"
aria-describedby="basic-addon1"
/>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text w-25">Age</span>
<input
type="text"
class="form-control"
placeholder="Age"
id="user_info_age"
aria-label="Name"
aria-describedby="basic-addon1"
/>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text w-25">Gridsquare</span>
<input
type="text"
class="form-control"
placeholder="Gridsquare"
id="user_info_gridsquare"
aria-label="Name"
aria-describedby="basic-addon1"
/>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text w-25">Location</span>
<input
type="text"
class="form-control"
placeholder="Location"
id="user_info_location"
aria-label="Name"
aria-describedby="basic-addon1"
/>
<span class="input-group-text w-25">Name</span>
<input
type="text"
class="form-control"
placeholder="Name"
id="user_info_name"
aria-label="Name"
aria-describedby="basic-addon1"
/>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text w-25">Radio</span>
<input
type="text"
class="form-control"
placeholder="Radio"
id="user_info_radio"
aria-label="Name"
aria-describedby="basic-addon1"
/>
<span class="input-group-text w-25">Age</span>
<input
type="text"
class="form-control"
placeholder="Age"
id="user_info_age"
aria-label="Name"
aria-describedby="basic-addon1"
/>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text w-25">Gridsquare</span>
<input
type="text"
class="form-control"
placeholder="Gridsquare"
id="user_info_gridsquare"
aria-label="Name"
aria-describedby="basic-addon1"
/>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text w-25">Location</span>
<input
type="text"
class="form-control"
placeholder="Location"
id="user_info_location"
aria-label="Name"
aria-describedby="basic-addon1"
/>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text w-25">Antenna</span>
<input
type="text"
class="form-control"
placeholder="Antenna"
id="user_info_antenna"
aria-label="Name"
aria-describedby="basic-addon1"
/>
<span class="input-group-text w-25">Radio</span>
<input
type="text"
class="form-control"
placeholder="Radio"
id="user_info_radio"
aria-label="Name"
aria-describedby="basic-addon1"
/>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text w-25">Email</span>
<input
type="text"
class="form-control"
placeholder="Email"
id="user_info_email"
aria-label="Name"
aria-describedby="basic-addon1"
/>
<span class="input-group-text w-25">Antenna</span>
<input
type="text"
class="form-control"
placeholder="Antenna"
id="user_info_antenna"
aria-label="Name"
aria-describedby="basic-addon1"
/>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text w-25">Website</span>
<input
type="text"
class="form-control"
placeholder="Website"
id="user_info_website"
aria-label="Name"
aria-describedby="basic-addon1"
/>
<span class="input-group-text w-25">Email</span>
<input
type="text"
class="form-control"
placeholder="Email"
id="user_info_email"
aria-label="Name"
aria-describedby="basic-addon1"
/>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text w-25">Website</span>
<input
type="text"
class="form-control"
placeholder="Website"
id="user_info_website"
aria-label="Name"
aria-describedby="basic-addon1"
/>
</div>
<div class="input-group input-group-sm mb-1">
<span class="input-group-text w-25">Comments</span>
<input
type="text"
class="form-control"
placeholder="Comments"
id="user_info_comments"
aria-label="Name"
aria-describedby="basic-addon1"
/>
<span class="input-group-text w-25">Comments</span>
<input
type="text"
class="form-control"
placeholder="Comments"
id="user_info_comments"
aria-label="Name"
aria-describedby="basic-addon1"
/>
</div>
</div>
<div class="modal-footer">
@ -412,8 +434,8 @@
</div>
</div>
</div>
<!-- dx user modal -->
<div
<!-- dx user modal -->
<div
class="modal fade"
id="userModalDX"
tabindex="-1"
@ -431,15 +453,9 @@
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body">
<div class="container-fluid">
Future feature... be patient :-)
</div>
<div class="container-fluid">Future feature... be patient :-)</div>
<div class="modal-footer">
<button
type="button"
@ -455,7 +471,7 @@
</div>
<!-- user shared folder -->
<div
<div
class="modal fade"
id="sharedFolderModal"
tabindex="-1"
@ -465,7 +481,9 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="sharedFolderModalLabel">My Shared folder</h1>
<h1 class="modal-title fs-5" id="sharedFolderModalLabel">
My Shared folder
</h1>
<button
type="button"
@ -473,15 +491,9 @@
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body">
<div class="container-fluid">
Future feature... be patient :-)
</div>
<div class="container-fluid">Future feature... be patient :-)</div>
<div class="modal-footer">
<button
type="button"
@ -497,7 +509,7 @@
</div>
<!-- dx user shared folder -->
<div
<div
class="modal fade"
id="sharedFolderModalDX"
tabindex="-1"
@ -507,7 +519,9 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="sharedFolderModalDXLabel">Shared folder</h1>
<h1 class="modal-title fs-5" id="sharedFolderModalDXLabel">
Shared folder
</h1>
<button
type="button"
@ -515,15 +529,9 @@
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body">
<div class="container-fluid">
Future feature... be patient :-)
</div>
<div class="container-fluid">Future feature... be patient :-)</div>
<div class="modal-footer">
<button
type="button"