mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Prettified Code!
This commit is contained in:
parent
68e10bad3e
commit
08cb8bb785
|
@ -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",
|
||||
|
@ -153,15 +148,13 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||
];
|
||||
|
||||
// add initial entry for own callsign and grid
|
||||
if(document.getElementById("user_info_callsign").value !== config.mycall){
|
||||
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({
|
||||
selector: {
|
||||
|
@ -169,19 +162,17 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||
},
|
||||
})
|
||||
.then(function (result) {
|
||||
if (typeof(result.docs[0]) !== "undefined") {
|
||||
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,13 +1010,13 @@ update_chat = function (obj) {
|
|||
//document.getElementById(id).className = message_class;
|
||||
}
|
||||
|
||||
//Delete message event listener
|
||||
if (
|
||||
//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)
|
||||
|
@ -1034,20 +1028,20 @@ if (
|
|||
attachments: true,
|
||||
})
|
||||
.then(function (doc) {
|
||||
db.remove(doc._id,doc._rev,function (err) {
|
||||
db.remove(doc._id, doc._rev, function (err) {
|
||||
if (err) console.log("Error removing item " + 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();
|
||||
};
|
||||
}
|
||||
|
||||
// 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,41 +1388,27 @@ function atob_FD(data) {
|
|||
return Buffer.from(data, "base64").toString("utf-8");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function returnObjFromCallsign(database, callsign) {
|
||||
|
||||
users
|
||||
.find(
|
||||
{
|
||||
.find({
|
||||
selector: {
|
||||
user_info_callsign: callsign,
|
||||
},
|
||||
}
|
||||
)
|
||||
.then(
|
||||
|
||||
function (result) {
|
||||
if (typeof(result.docs[0]) !== "undefined") {
|
||||
})
|
||||
.then(function (result) {
|
||||
if (typeof result.docs[0] !== "undefined") {
|
||||
return result.docs[0];
|
||||
} else {
|
||||
return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function createChatIndex(){
|
||||
db.createIndex({
|
||||
function createChatIndex() {
|
||||
db.createIndex({
|
||||
index: {
|
||||
fields: [
|
||||
"timestamp",
|
||||
|
@ -1445,7 +1425,7 @@ db.createIndex({
|
|||
"_attachments",
|
||||
],
|
||||
},
|
||||
})
|
||||
})
|
||||
.then(function (result) {
|
||||
// handle result
|
||||
console.log(result);
|
||||
|
@ -1453,12 +1433,10 @@ db.createIndex({
|
|||
.catch(function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function createUserIndex(){
|
||||
|
||||
users
|
||||
function createUserIndex() {
|
||||
users
|
||||
.createIndex({
|
||||
index: {
|
||||
fields: [
|
||||
|
@ -1480,25 +1458,24 @@ users
|
|||
.then(function (result) {
|
||||
// handle result
|
||||
console.log(result);
|
||||
return true
|
||||
return true;
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.log(err);
|
||||
return false
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function updateAllChat(clear){
|
||||
if (clear == true)
|
||||
{
|
||||
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,12 +1502,13 @@ function updateAllChat(clear){
|
|||
.then(async function (result) {
|
||||
// handle result async
|
||||
if (typeof result !== "undefined") {
|
||||
for (const item of result.docs)
|
||||
{
|
||||
for (const item of result.docs) {
|
||||
//await otherwise history will not be in chronological order
|
||||
await db.get(item._id, {
|
||||
await db
|
||||
.get(item._id, {
|
||||
attachments: true,
|
||||
}).then(function (item_with_attachments) {
|
||||
})
|
||||
.then(function (item_with_attachments) {
|
||||
update_chat(item_with_attachments);
|
||||
});
|
||||
}
|
||||
|
@ -1546,5 +1521,4 @@ function updateAllChat(clear){
|
|||
.catch(function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -421,7 +421,8 @@ client.on("data", function (socketdata) {
|
|||
break;
|
||||
default:
|
||||
ipcRenderer.send("request-update-transmission-status", {
|
||||
data: [data], });
|
||||
data: [data],
|
||||
});
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -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>
|
||||
>
|
||||
<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">
|
||||
|
@ -136,7 +134,9 @@
|
|||
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
|
||||
type="button"
|
||||
|
@ -144,17 +144,28 @@
|
|||
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">
|
||||
<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">
|
||||
<input
|
||||
checked="true"
|
||||
type="checkbox"
|
||||
class="form-check-input"
|
||||
id="chkMessage"
|
||||
/>
|
||||
<label class="form-check-label" for="chkMessage">
|
||||
Messages
|
||||
</label>
|
||||
|
@ -162,7 +173,11 @@
|
|||
</div>
|
||||
<div class="mb-1">
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" id="chkPing">
|
||||
<input
|
||||
type="checkbox"
|
||||
class="form-check-input"
|
||||
id="chkPing"
|
||||
/>
|
||||
<label class="form-check-label" for="chkPing">
|
||||
Pings
|
||||
</label>
|
||||
|
@ -170,7 +185,12 @@
|
|||
</div>
|
||||
<div class="mb-1">
|
||||
<div class="form-check">
|
||||
<input checked="true" type="checkbox" class="form-check-input" id="chkPingAck">
|
||||
<input
|
||||
checked="true"
|
||||
type="checkbox"
|
||||
class="form-check-input"
|
||||
id="chkPingAck"
|
||||
/>
|
||||
<label class="form-check-label" for="chkPingAck">
|
||||
Ping-Acks
|
||||
</label>
|
||||
|
@ -178,16 +198,20 @@
|
|||
</div>
|
||||
<div class="mb-1">
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" id="chkBeacon">
|
||||
<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>
|
||||
|
||||
<button type="button" class="btn btn-primary" id="btnFilter">
|
||||
Refresh
|
||||
</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<hr class="m-0" />
|
||||
|
@ -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,12 +301,9 @@
|
|||
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
|
||||
|
@ -293,7 +316,6 @@
|
|||
/>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="input-group input-group-sm mb-1">
|
||||
<span class="input-group-text w-25">Name</span>
|
||||
<input
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue