Skip to content

Commit

Permalink
First version of new listeningIP option (#29)
Browse files Browse the repository at this point in the history
* Initial commit

* First running version

* Update version
  • Loading branch information
marcelGoerentz authored Aug 24, 2024
1 parent a5a8755 commit 9882637
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 51 deletions.
26 changes: 26 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,31 @@
</div>
</div>

<div class="modal fade" id="ip_selection">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">IP selection</h3>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="card text-bg-dark mb-3">
<div class="card-body" id="checkbox_container">
Select one or more IP(s). If none has been selected then Threadfin will bind to all of them!
<table id="checkboxTable">
<!-- Checkboxes will be added automatically -->
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<div class="modal fade" id="server_information">
<div class="modal-dialog modal-xl">
<div class="modal-content">
Expand Down Expand Up @@ -95,6 +120,7 @@ <h3 class="modal-title">Server Information</h3>
</div>
</div>
</div>

<nav class="navbar navbar-expand-lg sticky-top navbar-dark bg-black">
<div class="container-fluid">
<a class="navbar-brand" href="/web">
Expand Down
35 changes: 18 additions & 17 deletions src/struct-webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,24 @@ type RequestStruct struct {
// ResponseStruct : Antworten an den Client (WEB)
type ResponseStruct struct {
ClientInfo struct {
ARCH string `json:"arch"`
Branch string `json:"branch,omitempty"`
DVR string `json:"DVR"`
EpgSource string `json:"epgSource"`
Errors int `json:"errors"`
M3U string `json:"m3u-url,required"`
OS string `json:"os"`
Streams string `json:"streams"`
ActiveClients int `json:"activeClients"`
TotalClients int `json:"totalClients"`
ActivePlaylist int `json:"activePlaylist"`
TotalPlaylist int `json:"totalPlaylist"`
UUID string `json:"uuid"`
Version string `json:"version"`
Warnings int `json:"warnings"`
XEPGCount int64 `json:"xepg"`
XML string `json:"xepg-url,required"`
ARCH string `json:"arch"`
Branch string `json:"branch,omitempty"`
DVR string `json:"DVR"`
EpgSource string `json:"epgSource"`
Errors int `json:"errors"`
M3U string `json:"m3u-url"`
OS string `json:"os"`
Streams string `json:"streams"`
ActiveClients int `json:"activeClients"`
TotalClients int `json:"totalClients"`
ActivePlaylist int `json:"activePlaylist"`
TotalPlaylist int `json:"totalPlaylist"`
SystemIPs []string `json:"systemIPs"`
UUID string `json:"uuid"`
Version string `json:"version"`
Warnings int `json:"warnings"`
XEPGCount int64 `json:"xepg"`
XML string `json:"xepg-url"`
} `json:"clientInfo,omitempty"`

Data struct {
Expand Down
62 changes: 32 additions & 30 deletions src/webUI.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ func setDefaultResponseData(response ResponseStruct, data bool) (defaults Respon
defaults.ClientInfo.ActivePlaylist = getActivePlaylistCount()
defaults.ClientInfo.TotalClients = Settings.Tuner
defaults.ClientInfo.TotalPlaylist = totalPlaylistCount
defaults.ClientInfo.SystemIPs = System.IPAddressesList
defaults.Notification = System.Notification
defaults.Log = WebScreenLog

Expand Down
4 changes: 2 additions & 2 deletions threadfin.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ var GitHub = GitHubStruct{Branch: "Main", User: "marcelGoerentz", Repo: "Threadf
const Name = "Threadfin"

// Version : Version, die Build Nummer wird in der main func geparst.
const Version = "1.3.4-beta"
const Version = "1.4.0-beta"

// DBVersion : Datanbank Version
const DBVersion = "0.5.0"

// APIVersion : API Version
const APIVersion = "1.3.4-beta"
const APIVersion = "1.4.0-beta"

var homeDirectory = fmt.Sprintf("%s%s.%s%s", src.GetUserHomeDirectory(), string(os.PathSeparator), strings.ToLower(Name), string(os.PathSeparator))
var samplePath = fmt.Sprintf("%spath%sto%sthreadfin%s", string(os.PathSeparator), string(os.PathSeparator), string(os.PathSeparator), string(os.PathSeparator))
Expand Down
62 changes: 61 additions & 1 deletion ts/menu_ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,66 @@ function PageReady() {

getNewestReleaseFromGithub()

setCheckboxes()

return
}

async function setCheckboxes() {
var content: PopupContent = new PopupContent()
var table = document.getElementById("checkboxTable")
await new Promise(f => setTimeout(f, 1000));
if ("clientInfo" in SERVER) {
let listeningIp: string = SERVER['settings']['listeningIp']
var listeningIpArray = listeningIp.split(";")
let systemnIPs: Array<string> = SERVER["clientInfo"]["systemIPs"]
systemnIPs.forEach((ipAddress, index) => {
if (!ipAddress.includes('169.254')) {
var tr = document.createElement('tr')
var tdLeft = document.createElement('td')
var tdRight = document.createElement('td')

var checkbox = content.createCheckbox(ipAddress, 'ipCheckbox' + index)
checkbox.checked = false
listeningIpArray.forEach(element => {
if (element === ipAddress) {
checkbox.checked = true
return;
}
});
var label = document.createElement("label")
label.setAttribute("for", "ipCheckbox" + index)
label.innerHTML = ipAddress
tdLeft.appendChild(checkbox)
tdRight.appendChild(label)
tr.appendChild(tdLeft)
tr.appendChild(tdRight)
table.appendChild(tr)
}
});
var checkbox_container = document.getElementById("checkbox_container")
var input = content.createInput("button", "buttonSave", "{{.button.save}}")
input.setAttribute("onclick", 'javascript: saveBindingIPs()')
input.setAttribute('data-bs-target', '#ip_selection')
input.setAttribute("data-bs-toggle" , "modal")
checkbox_container.appendChild(input)
}
}

function saveBindingIPs() {
var checkboxTable = document.getElementById('checkboxTable')
var checkboxList = checkboxTable.querySelectorAll('input')
var listeningIPs: string[] = []
checkboxList.forEach(checkbox => {
if (checkbox.checked) {
listeningIPs.push(checkbox.name)
}
});
var listeningIp = document.getElementById('listeningIp')
listeningIp.setAttribute('value', listeningIPs.join(';') + ";")
listeningIp.setAttribute('class', 'changed')
}

function createLayout() {

// Client Info
Expand Down Expand Up @@ -1242,10 +1299,13 @@ class PopupContent extends PopupWindow {
return input
}

createCheckbox(name: string): any {
createCheckbox(name: string, id: string = ''): any {
var input = document.createElement("INPUT")

input.setAttribute("type", "checkbox")
if (id != '') {
input.setAttribute("id", id)
}
input.setAttribute("name", name)
return input
}
Expand Down
4 changes: 3 additions & 1 deletion ts/settings_ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ class SettingsCategory {
case "listeningIp":
var tdLeft = document.createElement("TD")
tdLeft.innerHTML = "{{.settings.listeningIp.title}}" + ":"

var tdRight = document.createElement("TD")
var input = content.createInput("text", "listeningIp", data)
input.setAttribute("id", settingsKey)
input.setAttribute("placeholder", "{{.settings.listeningIp.placeholder}}")
input.setAttribute("onchange", "javascript: this.className = 'changed'")
input.setAttribute('data-bs-target', '#ip_selection')
input.setAttribute("data-bs-toggle" , "modal")
tdRight.appendChild(input)

setting.appendChild(tdLeft)
Expand Down

0 comments on commit 9882637

Please sign in to comment.