Add Archive, archived Mangas dont get updated

This commit is contained in:
Pablu23
2024-06-08 20:57:20 +02:00
parent 05ca6c9b1b
commit 48b2e6787b
5 changed files with 72 additions and 10 deletions

View File

@@ -7,6 +7,7 @@ type Manga struct {
Thumbnail []byte
LastChapterNum string
Chapters []Chapter
Enabled bool
//`gorm:"foreignkey:MangaID"`
}
@@ -16,6 +17,7 @@ func NewManga(id int, title string, timeStampUnix int64) Manga {
Title: title,
TimeStampUnix: timeStampUnix,
LastChapterNum: "",
Enabled: true,
}
}

View File

@@ -20,6 +20,21 @@ import (
"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) {
s.UpdateMangaList()
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)
}
func (s *Server) HandleMenu(w http.ResponseWriter, _ *http.Request) {
tmpl := template.Must(view.GetViewTemplate(view.Menu))
func (s *Server) HandleArchive(w http.ResponseWriter, r *http.Request) {
var all []*database.Manga
_ = s.DbMgr.Db.Preload("Chapters").Find(&all)
l := len(all)
mangaViewModels := make([]view.MangaViewModel, l)
counter := 0
_ = s.DbMgr.Db.Preload("Chapters").Where("enabled = 0").Find(&all)
var tmp []database.Setting
s.DbMgr.Db.Find(&tmp)
@@ -79,8 +90,32 @@ func (s *Server) HandleMenu(w http.ResponseWriter, _ *http.Request) {
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
for _, manga := range all {
for _, manga := range mangas {
title := cases.Title(language.English, cases.Compact).String(strings.Replace(manga.Title, "-", " ", -1))
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)"),
Url: latestChapter.Url,
ThumbnailUrl: thumbnail,
Enabled: manga.Enabled,
}
counter++
}
@@ -147,6 +183,7 @@ func (s *Server) HandleMenu(w http.ResponseWriter, _ *http.Request) {
menuViewModel := view.MenuViewModel{
Settings: settings,
Mangas: mangaViewModels,
Archive: archive,
}
err := tmpl.Execute(w, menuViewModel)

View File

@@ -78,6 +78,8 @@ func (s *Server) RegisterRoutes() {
s.mux.HandleFunc("POST /setting/", s.HandleSetting)
s.mux.HandleFunc("GET /setting/set/{setting}/{value}", s.HandleSettingSet)
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 {
@@ -116,7 +118,7 @@ func (s *Server) Start() error {
func (s *Server) UpdateMangaList() {
var all []*database.Manga
s.DbMgr.Db.Find(&all)
s.DbMgr.Db.Where("enabled = 1").Find(&all)
for _, m := range all {
err, updated := s.UpdateLatestAvailableChapter(m)
if err != nil {

View File

@@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8">
<title>Main Menu</title>
<title>{{if .Archive}}Archive{{else}}Main Menu{{end}}</title>
<style>
body {
@@ -128,7 +128,7 @@
</style>
</head>
<body class="{{(index .Settings "theme").Value}}">
<body class='{{(index .Settings "theme").Value}}'>
<form method="post" action="/new/">
<label>
New Sub Url
@@ -137,11 +137,23 @@
<input type="submit" value="Open" class="button-36">
</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">
<button class="button-36">
Update Chapters
</button>
</a>
{{end}}
<form method="post" action="/setting/">
<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/last">Last Accessed</a></th>
<th>Link</th>
<th>Disable/Enable</th>
<th>Delete</th>
</tr>
{{range .Mangas}}
@@ -178,6 +191,12 @@
</button>
</a>
</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>
<form method="post" action="/delete">
<input type="hidden" name="mangaId" value="{{.ID}}">

View File

@@ -20,9 +20,11 @@ type MangaViewModel struct {
LastTime string
Url string
ThumbnailUrl string
Enabled bool
}
type MenuViewModel struct {
Archive bool
Settings map[string]database.Setting
Mangas []MangaViewModel
}