Add Archive, archived Mangas dont get updated
This commit is contained in:
@@ -7,6 +7,7 @@ type Manga struct {
|
|||||||
Thumbnail []byte
|
Thumbnail []byte
|
||||||
LastChapterNum string
|
LastChapterNum string
|
||||||
Chapters []Chapter
|
Chapters []Chapter
|
||||||
|
Enabled bool
|
||||||
//`gorm:"foreignkey:MangaID"`
|
//`gorm:"foreignkey:MangaID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ func NewManga(id int, title string, timeStampUnix int64) Manga {
|
|||||||
Title: title,
|
Title: title,
|
||||||
TimeStampUnix: timeStampUnix,
|
TimeStampUnix: timeStampUnix,
|
||||||
LastChapterNum: "",
|
LastChapterNum: "",
|
||||||
|
Enabled: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,21 @@ import (
|
|||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (s *Server) HandleDisable(w http.ResponseWriter, r *http.Request) {
|
||||||
|
id := r.PostFormValue("mangaId")
|
||||||
|
var manga database.Manga
|
||||||
|
s.DbMgr.Db.Where("id = ?", id).First(&manga)
|
||||||
|
|
||||||
|
if manga.Enabled {
|
||||||
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
|
} else {
|
||||||
|
http.Redirect(w, r, "/archive", http.StatusFound)
|
||||||
|
}
|
||||||
|
|
||||||
|
manga.Enabled = !manga.Enabled
|
||||||
|
s.DbMgr.Db.Save(&manga)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) HandleUpdate(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) HandleUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
s.UpdateMangaList()
|
s.UpdateMangaList()
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
@@ -64,13 +79,9 @@ func (s *Server) HandleNew(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Redirect(w, r, "/current/", http.StatusFound)
|
http.Redirect(w, r, "/current/", http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) HandleMenu(w http.ResponseWriter, _ *http.Request) {
|
func (s *Server) HandleArchive(w http.ResponseWriter, r *http.Request) {
|
||||||
tmpl := template.Must(view.GetViewTemplate(view.Menu))
|
|
||||||
var all []*database.Manga
|
var all []*database.Manga
|
||||||
_ = s.DbMgr.Db.Preload("Chapters").Find(&all)
|
_ = s.DbMgr.Db.Preload("Chapters").Where("enabled = 0").Find(&all)
|
||||||
l := len(all)
|
|
||||||
mangaViewModels := make([]view.MangaViewModel, l)
|
|
||||||
counter := 0
|
|
||||||
|
|
||||||
var tmp []database.Setting
|
var tmp []database.Setting
|
||||||
s.DbMgr.Db.Find(&tmp)
|
s.DbMgr.Db.Find(&tmp)
|
||||||
@@ -79,8 +90,32 @@ func (s *Server) HandleMenu(w http.ResponseWriter, _ *http.Request) {
|
|||||||
settings[m.Name] = m
|
settings[m.Name] = m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.ViewMenu(w, all, settings, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) HandleMenu(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
var all []*database.Manga
|
||||||
|
_ = s.DbMgr.Db.Preload("Chapters").Where("enabled = 1").Find(&all)
|
||||||
|
|
||||||
|
var tmp []database.Setting
|
||||||
|
s.DbMgr.Db.Find(&tmp)
|
||||||
|
settings := make(map[string]database.Setting)
|
||||||
|
for _, m := range tmp {
|
||||||
|
settings[m.Name] = m
|
||||||
|
}
|
||||||
|
|
||||||
|
s.ViewMenu(w, all, settings, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) ViewMenu(w http.ResponseWriter, mangas []*database.Manga, settings map[string]database.Setting, archive bool) {
|
||||||
|
tmpl := template.Must(view.GetViewTemplate(view.Menu))
|
||||||
|
|
||||||
|
l := len(mangas)
|
||||||
|
mangaViewModels := make([]view.MangaViewModel, l)
|
||||||
|
counter := 0
|
||||||
|
|
||||||
//TODO: Change all this to be more performant
|
//TODO: Change all this to be more performant
|
||||||
for _, manga := range all {
|
for _, manga := range mangas {
|
||||||
title := cases.Title(language.English, cases.Compact).String(strings.Replace(manga.Title, "-", " ", -1))
|
title := cases.Title(language.English, cases.Compact).String(strings.Replace(manga.Title, "-", " ", -1))
|
||||||
|
|
||||||
thumbnail, updated, err := s.LoadThumbnail(manga)
|
thumbnail, updated, err := s.LoadThumbnail(manga)
|
||||||
@@ -117,6 +152,7 @@ func (s *Server) HandleMenu(w http.ResponseWriter, _ *http.Request) {
|
|||||||
LastTime: time.Unix(manga.TimeStampUnix, 0).Format("15:04 (02-01-06)"),
|
LastTime: time.Unix(manga.TimeStampUnix, 0).Format("15:04 (02-01-06)"),
|
||||||
Url: latestChapter.Url,
|
Url: latestChapter.Url,
|
||||||
ThumbnailUrl: thumbnail,
|
ThumbnailUrl: thumbnail,
|
||||||
|
Enabled: manga.Enabled,
|
||||||
}
|
}
|
||||||
counter++
|
counter++
|
||||||
}
|
}
|
||||||
@@ -147,6 +183,7 @@ func (s *Server) HandleMenu(w http.ResponseWriter, _ *http.Request) {
|
|||||||
menuViewModel := view.MenuViewModel{
|
menuViewModel := view.MenuViewModel{
|
||||||
Settings: settings,
|
Settings: settings,
|
||||||
Mangas: mangaViewModels,
|
Mangas: mangaViewModels,
|
||||||
|
Archive: archive,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := tmpl.Execute(w, menuViewModel)
|
err := tmpl.Execute(w, menuViewModel)
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ func (s *Server) RegisterRoutes() {
|
|||||||
s.mux.HandleFunc("POST /setting/", s.HandleSetting)
|
s.mux.HandleFunc("POST /setting/", s.HandleSetting)
|
||||||
s.mux.HandleFunc("GET /setting/set/{setting}/{value}", s.HandleSettingSet)
|
s.mux.HandleFunc("GET /setting/set/{setting}/{value}", s.HandleSettingSet)
|
||||||
s.mux.HandleFunc("GET /update", s.HandleUpdate)
|
s.mux.HandleFunc("GET /update", s.HandleUpdate)
|
||||||
|
s.mux.HandleFunc("POST /disable", s.HandleDisable)
|
||||||
|
s.mux.HandleFunc("GET /archive", s.HandleArchive)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Start() error {
|
func (s *Server) Start() error {
|
||||||
@@ -116,7 +118,7 @@ func (s *Server) Start() error {
|
|||||||
|
|
||||||
func (s *Server) UpdateMangaList() {
|
func (s *Server) UpdateMangaList() {
|
||||||
var all []*database.Manga
|
var all []*database.Manga
|
||||||
s.DbMgr.Db.Find(&all)
|
s.DbMgr.Db.Where("enabled = 1").Find(&all)
|
||||||
for _, m := range all {
|
for _, m := range all {
|
||||||
err, updated := s.UpdateLatestAvailableChapter(m)
|
err, updated := s.UpdateLatestAvailableChapter(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Main Menu</title>
|
<title>{{if .Archive}}Archive{{else}}Main Menu{{end}}</title>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
@@ -128,7 +128,7 @@
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="{{(index .Settings "theme").Value}}">
|
<body class='{{(index .Settings "theme").Value}}'>
|
||||||
<form method="post" action="/new/">
|
<form method="post" action="/new/">
|
||||||
<label>
|
<label>
|
||||||
New Sub Url
|
New Sub Url
|
||||||
@@ -137,11 +137,23 @@
|
|||||||
<input type="submit" value="Open" class="button-36">
|
<input type="submit" value="Open" class="button-36">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<a href='{{if .Archive}}/{{else}}/archive{{end}}'>
|
||||||
|
<button class="button-36">
|
||||||
|
{{if .Archive}}
|
||||||
|
To Main Menu
|
||||||
|
{{else}}
|
||||||
|
To Archive
|
||||||
|
{{end}}
|
||||||
|
</button>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
{{if not .Archive}}
|
||||||
<a href="/update">
|
<a href="/update">
|
||||||
<button class="button-36">
|
<button class="button-36">
|
||||||
Update Chapters
|
Update Chapters
|
||||||
</button>
|
</button>
|
||||||
</a>
|
</a>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
<form method="post" action="/setting/">
|
<form method="post" action="/setting/">
|
||||||
<label for="theme">Theme</label>
|
<label for="theme">Theme</label>
|
||||||
@@ -159,6 +171,7 @@
|
|||||||
<th><a href="setting/set/order/chapter">Current Chapter</a></th>
|
<th><a href="setting/set/order/chapter">Current Chapter</a></th>
|
||||||
<th><a href="setting/set/order/last">Last Accessed</a></th>
|
<th><a href="setting/set/order/last">Last Accessed</a></th>
|
||||||
<th>Link</th>
|
<th>Link</th>
|
||||||
|
<th>Disable/Enable</th>
|
||||||
<th>Delete</th>
|
<th>Delete</th>
|
||||||
</tr>
|
</tr>
|
||||||
{{range .Mangas}}
|
{{range .Mangas}}
|
||||||
@@ -178,6 +191,12 @@
|
|||||||
</button>
|
</button>
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<form method="post" action="/disable">
|
||||||
|
<input type="hidden" name="mangaId" value="{{.ID}}">
|
||||||
|
<input type="submit" class="button-delete" value="{{if .Enabled}}Disable{{else}}Enable{{end}}">
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<form method="post" action="/delete">
|
<form method="post" action="/delete">
|
||||||
<input type="hidden" name="mangaId" value="{{.ID}}">
|
<input type="hidden" name="mangaId" value="{{.ID}}">
|
||||||
|
|||||||
@@ -20,9 +20,11 @@ type MangaViewModel struct {
|
|||||||
LastTime string
|
LastTime string
|
||||||
Url string
|
Url string
|
||||||
ThumbnailUrl string
|
ThumbnailUrl string
|
||||||
|
Enabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type MenuViewModel struct {
|
type MenuViewModel struct {
|
||||||
|
Archive bool
|
||||||
Settings map[string]database.Setting
|
Settings map[string]database.Setting
|
||||||
Mangas []MangaViewModel
|
Mangas []MangaViewModel
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user