Add some settings

This commit is contained in:
Peter Stuifzand 2018-07-16 22:05:28 +02:00
parent 633cfabbfd
commit acf0721ba5
3 changed files with 64 additions and 11 deletions

View File

@ -50,6 +50,7 @@ type settingsPage struct {
Session session Session session
CurrentChannel microsub.Channel CurrentChannel microsub.Channel
CurrentSetting channelSetting
Channels []microsub.Channel Channels []microsub.Channel
Feeds []microsub.Feed Feeds []microsub.Feed
@ -272,6 +273,11 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
for _, v := range page.Channels { for _, v := range page.Channels {
if v.UID == currentChannel { if v.UID == currentChannel {
page.CurrentChannel = v page.CurrentChannel = v
if setting, e := h.Backend.Settings[v.UID]; e {
page.CurrentSetting = setting
} else {
page.CurrentSetting = channelSetting{}
}
break break
} }
} }
@ -547,6 +553,26 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
return return
} else if r.URL.Path == "/settings/channel" {
defer h.Backend.save()
uid := r.FormValue("uid")
//name := r.FormValue("name")
excludeRegex := r.FormValue("exclude_regex")
if setting, e := h.Backend.Settings[uid]; e {
setting.ExcludeRegex = excludeRegex
h.Backend.Settings[uid] = setting
} else {
setting = channelSetting{
ExcludeRegex: excludeRegex,
}
h.Backend.Settings[uid] = setting
}
h.Backend.Debug()
http.Redirect(w, r, "/settings", 302)
return
} }
} }

View File

@ -37,6 +37,7 @@ import (
type memoryBackend struct { type memoryBackend struct {
Channels map[string]microsub.Channel Channels map[string]microsub.Channel
Feeds map[string][]microsub.Feed Feeds map[string][]microsub.Feed
Settings map[string]channelSetting
NextUid int NextUid int
Me string Me string
TokenEndpoint string TokenEndpoint string
@ -45,12 +46,18 @@ type memoryBackend struct {
quit chan struct{} quit chan struct{}
} }
type channelSetting struct {
ExcludeRegex string
}
type Debug interface { type Debug interface {
Debug() Debug()
} }
func (b *memoryBackend) Debug() { func (b *memoryBackend) Debug() {
fmt.Println(b.Channels) fmt.Println(b.Channels)
fmt.Println(b.Feeds)
fmt.Println(b.Settings)
} }
func (b *memoryBackend) load() error { func (b *memoryBackend) load() error {

View File

@ -9,8 +9,6 @@
<body> <body>
<section class="section"> <section class="section">
<div class="container"> <div class="container">
<nav class="navbar" role="navigation" aria-label="main navigation"> <nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand"> <div class="navbar-brand">
<a class="navbar-item" href="/"> <a class="navbar-item" href="/">
@ -50,18 +48,40 @@
</ul> </ul>
</nav> </nav>
<h2 class="subtitle">{{ $channel.Name }}</h2> <h2 class="subtitle is-2">{{ $channel.Name }}</h2>
<div class="channel"> <div class="columns">
{{ range .Feeds }} <div class="column">
<div class="feed box"> <h3 class="title is-4">Settings</h3>
<div class="name"> <form action="/settings/channel" method="post">
<a href="{{ .URL }}">{{ .URL }}</a> <input type="hidden" name="uid" value="{{ .CurrentChannel.UID }}" />
<div class="field">
<div class="control">
<label class="label">Exclude regex</label>
<input type="text" class="input" name="exclude_regex" value="{{ .CurrentSetting.ExcludeRegex }}" placeholder="enter regex to block" />
</div>
</div> </div>
<div class="field">
<button type="submit" class="button is-primary">Save</button>
</div>
</form>
</div>
<div class="column">
<h3 class="title is-4">Channels</h3>
<div class="channel">
{{ range .Feeds }}
<div class="feed box">
<div class="name">
<a href="{{ .URL }}">{{ .URL }}</a>
</div>
</div>
{{ else }}
<div class="no-channels">No feeds</div>
{{ end }}
</div> </div>
{{ else }} </div>
<div class="no-channels">No feeds</div>
{{ end }}
</div> </div>
</div> </div>
</section> </section>