added peer save in backend

This commit is contained in:
vadym 2021-09-22 23:27:21 +03:00
parent b1098ad1ee
commit 9dc7b7adbf
2 changed files with 36 additions and 16 deletions

View file

@ -109,6 +109,16 @@
message.value = ""; message.value = "";
info.className = "notification is-primary is-hidden"; info.className = "notification is-primary is-hidden";
//todo save peers //todo save peers
var peers = document.querySelectorAll('*[id^="peer-"]');
var peer_list = [];
for (i = 0; i < peers.length; ++i) {
var p = peers[i];
if (p.checked) {
var peerURL = p.parentElement.parentElement.firstChild.innerText;
peer_list.push(peerURL);
}
}
savePeers(JSON.stringify(peer_list));
}; };
}; };
@ -129,11 +139,13 @@ function add_table(peerList) {
// creates a <table> element and a <tbody> element // creates a <table> element and a <tbody> element
var tbl = document.createElement("table"); var tbl = document.createElement("table");
tbl.setAttribute('id', "peer_list");
//tbl.setAttribute('cellpadding', '10'); //tbl.setAttribute('cellpadding', '10');
var tblBody = document.createElement("tbody"); var tblBody = document.createElement("tbody");
// creating all cells // creating all cells
for (var c in peerList) { for (var c in peerList) {
let counter = 1;
for (peer in peerList[c]){ for (peer in peerList[c]){
// creates a table row // creates a table row
var row = document.createElement("tr"); var row = document.createElement("tr");
@ -143,6 +155,7 @@ function add_table(peerList) {
var peerSelect = document.createElement("td"); var peerSelect = document.createElement("td");
var chk = document.createElement('input'); var chk = document.createElement('input');
chk.setAttribute('type', 'checkbox'); chk.setAttribute('type', 'checkbox');
chk.setAttribute('id', "peer-"+counter);
peerSelect.appendChild(chk); peerSelect.appendChild(chk);
row.appendChild(peerAddress); row.appendChild(peerAddress);
row.appendChild(peerSelect); row.appendChild(peerSelect);
@ -222,7 +235,6 @@ function add_table(peerList) {
<body onload="onLoad();"> <body onload="onLoad();">
<div style="padding:3px; max-height: 250px;"> <div style="padding:3px; max-height: 250px;">
<div class="box"> <div class="box">
<div style="z-index: 9;" class="box stack-top notification is-primary is-hidden" id="notification_window"> <div style="z-index: 9;" class="box stack-top notification is-primary is-hidden" id="notification_window">
<button class="delete" id="info_close"></button> <button class="delete" id="info_close"></button>
<p style="padding:3px; max-height: 250px; overflow-y: auto;" id="info_window"></p> <p style="padding:3px; max-height: 250px; overflow-y: auto;" id="info_window"></p>

View file

@ -2,12 +2,13 @@ package main
import ( import (
"github.com/webview/webview" "github.com/webview/webview"
"encoding/json"
"path/filepath" "path/filepath"
"io/ioutil" "io/ioutil"
"os/exec"
"net/url" "net/url"
"runtime" "runtime"
"strings" "strings"
"os/exec"
"log" "log"
"fmt" "fmt"
"os" "os"
@ -28,6 +29,12 @@ func main() {
log.Println("page loaded") log.Println("page loaded")
go run(w) go run(w)
}) })
w.Bind("savePeers", func(peer_list string) {
//log.Println("peers saved ", peer_list)
var peers []string
_ = json.Unmarshal([]byte(peer_list), &peers)
log.Printf("Unmarshaled: %v", peers)
})
dat, err := ioutil.ReadFile(path+"/index.html") dat, err := ioutil.ReadFile(path+"/index.html")
w.Navigate("data:text/html,"+url.QueryEscape(string(dat))) w.Navigate("data:text/html,"+url.QueryEscape(string(dat)))
w.Run() w.Run()
@ -107,7 +114,8 @@ func get_peers(w webview.WebView, riv_ctrl_path string){
m=append(m, r) m=append(m, r)
} }
} }
for k := range m { // Loop for k := range m {
// Loop
fmt.Println(k) fmt.Println(k)
} }
inner_html := strings.Join(m[:], "<br>") inner_html := strings.Join(m[:], "<br>")