From 3eb8e61b195f0daeba1be94bc930ebe759842c88 Mon Sep 17 00:00:00 2001 From: Akhil Gupta Date: Fri, 19 Feb 2021 11:27:36 +0530 Subject: [PATCH 1/2] working on tags --- db/db.go | 2 +- db/dbfunctions.go | 26 ++++++++++++++++++++++++++ db/podcast.go | 9 +++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/db/db.go b/db/db.go index e866dc8..0d3f703 100644 --- a/db/db.go +++ b/db/db.go @@ -35,7 +35,7 @@ func Init() (*gorm.DB, error) { //Migrate Database func Migrate() { - DB.AutoMigrate(&Podcast{}, &PodcastItem{}, &Setting{}, &Migration{}, &JobLock{}) + DB.AutoMigrate(&Podcast{}, &PodcastItem{}, &Setting{}, &Migration{}, &JobLock{}, &Tag{}) RunMigrations() } diff --git a/db/dbfunctions.go b/db/dbfunctions.go index 6d92eaf..cbbf52d 100644 --- a/db/dbfunctions.go +++ b/db/dbfunctions.go @@ -236,3 +236,29 @@ func UnlockMissedJobs() { } } } + +func GetAllTags(sorting string) (*[]Tag, error) { + var tags []Tag + if sorting == "" { + sorting = "created_at" + } + result := DB.Debug().Order(sorting).Find(&tags) + return &tags, result.Error +} + +func GetTagById(id string) (*Tag, error) { + var tag Tag + result := DB.Preload(clause.Associations). + First(&tag, "id=?", id) + + return &tag, result.Error +} + +func CreateTag(tag *Tag) error { + tx := DB.Omit("Podcasts").Create(&tag) + return tx.Error +} +func UpdateTag(tag *Tag) error { + tx := DB.Omit("Podcast").Save(&tag) + return tx.Error +} diff --git a/db/podcast.go b/db/podcast.go index 54bc557..42e5606 100644 --- a/db/podcast.go +++ b/db/podcast.go @@ -21,6 +21,8 @@ type Podcast struct { PodcastItems []PodcastItem + Tag []*Tag `gorm:"many2many:podcast_tags;"` + DownloadedEpisodesCount int `gorm:"-"` DownloadingEpisodesCount int `gorm:"-"` AllEpisodesCount int `gorm:"-"` @@ -85,6 +87,13 @@ type JobLock struct { Duration int } +type Tag struct { + Base + Label string + Description string `gorm:"type:text"` + Podcasts []*Podcast `gorm:"many2many:podcast_tags;"` +} + func (lock *JobLock) IsLocked() bool { return lock != nil && lock.Date != time.Time{} } From 2211a35171ba47bc2c63c855eaf1aa04534f7537 Mon Sep 17 00:00:00 2001 From: Akhil Gupta Date: Sun, 21 Feb 2021 07:03:38 +0530 Subject: [PATCH 2/2] tags first level complete --- client/index.html | 254 ++++++++++++++++++++++++++++++++++++-- client/scripts.html | 18 +++ controllers/podcast.go | 77 ++++++++++++ db/dbfunctions.go | 21 +++- db/podcast.go | 2 +- main.go | 6 + model/errors.go | 8 ++ service/podcastService.go | 19 +++ 8 files changed, 390 insertions(+), 15 deletions(-) diff --git a/client/index.html b/client/index.html index 53f9aae..72b6a21 100644 --- a/client/index.html +++ b/client/index.html @@ -53,6 +53,15 @@ transition-timing-function: ease-in-out; } + .grid .tags{ + font-size: 0.85em; + padding-bottom: 10px; + display: inline-block; + } + + .mobile.tags{ + margin-bottom: 10px; + } .alignRight{ text-align: right; @@ -60,7 +69,38 @@ .alignLeft{ text-align: left; } - + .tag-editor{ + position: absolute; + border:1px solid; + padding: 10px; + width: 300px; + } + + .tag-editor a.pill{ + margin-right: 5px; + background: blue; + border-radius: 5px; + padding: 2px 5px; + text-decoration: none; + display: inline-block; + margin-bottom: 5px; + } + + a.pill i{ + background-color: inherit; + margin-right: 2px; + } + + .tag-editor .available a.pill{ + background: green; + } + .tag-editor .existing a.pill{ + background: palevioletred; + } + + .tag-editor>div{ + margin-bottom: 15px;; + } @@ -81,6 +121,14 @@ + +