Compare commits

...

2 Commits

Author SHA1 Message Date
acf0721ba5 Add some settings 2018-07-16 22:05:28 +02:00
633cfabbfd Remove unused init() function 2018-07-16 21:36:11 +02:00
3 changed files with 64 additions and 14 deletions

View File

@ -50,6 +50,7 @@ type settingsPage struct {
Session session
CurrentChannel microsub.Channel
CurrentSetting channelSetting
Channels []microsub.Channel
Feeds []microsub.Feed
@ -272,6 +273,11 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
for _, v := range page.Channels {
if v.UID == currentChannel {
page.CurrentChannel = v
if setting, e := h.Backend.Settings[v.UID]; e {
page.CurrentSetting = setting
} else {
page.CurrentSetting = channelSetting{}
}
break
}
}
@ -547,6 +553,26 @@ func (h *mainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
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 {
Channels map[string]microsub.Channel
Feeds map[string][]microsub.Feed
Settings map[string]channelSetting
NextUid int
Me string
TokenEndpoint string
@ -45,15 +46,18 @@ type memoryBackend struct {
quit chan struct{}
}
type channelSetting struct {
ExcludeRegex string
}
type Debug interface {
Debug()
}
func init() {
}
func (b *memoryBackend) Debug() {
fmt.Println(b.Channels)
fmt.Println(b.Feeds)
fmt.Println(b.Settings)
}
func (b *memoryBackend) load() error {

View File

@ -9,8 +9,6 @@
<body>
<section class="section">
<div class="container">
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item" href="/">
@ -50,18 +48,40 @@
</ul>
</nav>
<h2 class="subtitle">{{ $channel.Name }}</h2>
<h2 class="subtitle is-2">{{ $channel.Name }}</h2>
<div class="channel">
{{ range .Feeds }}
<div class="feed box">
<div class="name">
<a href="{{ .URL }}">{{ .URL }}</a>
<div class="columns">
<div class="column">
<h3 class="title is-4">Settings</h3>
<form action="/settings/channel" method="post">
<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 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>
{{ else }}
<div class="no-channels">No feeds</div>
{{ end }}
</div>
</div>
</div>
</section>