Skip to content

Commit

Permalink
feat: listing update for is_fav, is_archived, is_deleted pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
puni9869 committed Nov 9, 2024
1 parent 799c5dd commit 54c05ce
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 13 deletions.
57 changes: 51 additions & 6 deletions server/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,66 @@ func Home(c *gin.Context) {
currentlyLoggedIn := session.Get(middlewares.Userkey)
var urls []models.Url
db := database.Db()
result := db.Where(&models.Url{CreatedBy: currentlyLoggedIn.(string), IsActive: true, IsDeleted: false, IsArchived: false}).Order("updated_at desc").Limit(100).Find(&urls)
log.WithField("result", result.RowsAffected).Info("" + currentlyLoggedIn.(string))
c.HTML(http.StatusOK, "home.tmpl", gin.H{"HasError": false, "Urls": urls})
result := db.Where("created_by =? and is_active = ? and is_deleted = ?", currentlyLoggedIn.(string), true, false).
Order("updated_at desc").
Limit(100).
Find(&urls)
if result.RowsAffected > 0 {
log.WithField("resultCount", result.RowsAffected).Info("Fetching the result")
}

c.HTML(http.StatusOK, "home.tmpl", gin.H{"HasError": false, "Urls": urls, "Count": result.RowsAffected})
}

func Favourite(c *gin.Context) {
c.HTML(http.StatusOK, "favourite.tmpl", nil)
log := logger.NewLogger()
session := sessions.Default(c)
currentlyLoggedIn := session.Get(middlewares.Userkey)
var urls []models.Url
db := database.Db()
result := db.Where("created_by =? and is_active = ? and is_deleted = ? and is_fav =? ", currentlyLoggedIn.(string), true, false, true).
Order("updated_at desc").
Limit(100).
Find(&urls)
if result.RowsAffected > 0 {
log.WithField("resultCount", result.RowsAffected).Info("Fetching the result")
}

c.HTML(http.StatusOK, "favourite.tmpl", gin.H{"HasError": false, "Urls": urls, "Count": result.RowsAffected})
}

func Archived(c *gin.Context) {
c.HTML(http.StatusOK, "archived.tmpl", nil)
log := logger.NewLogger()
session := sessions.Default(c)
currentlyLoggedIn := session.Get(middlewares.Userkey)
var urls []models.Url
db := database.Db()
result := db.Where("created_by =? and is_active = ? and is_deleted = ? and is_archived =? ", currentlyLoggedIn.(string), true, false, true).
Order("updated_at desc").
Limit(100).
Find(&urls)
if result.RowsAffected > 0 {
log.WithField("resultCount", result.RowsAffected).Info("Fetching the result")
}

c.HTML(http.StatusOK, "archived.tmpl", gin.H{"HasError": false, "Urls": urls, "Count": result.RowsAffected})
}

func Trash(c *gin.Context) {
c.HTML(http.StatusOK, "trash.tmpl", nil)
log := logger.NewLogger()
session := sessions.Default(c)
currentlyLoggedIn := session.Get(middlewares.Userkey)
var urls []models.Url
db := database.Db()
result := db.Where("created_by =? and is_active = ? and is_deleted = ?", currentlyLoggedIn.(string), true, true).
Order("updated_at desc").
Limit(100).
Find(&urls)
if result.RowsAffected > 0 {
log.WithField("resultCount", result.RowsAffected).Info("Fetching the result")
}

c.HTML(http.StatusOK, "trash.tmpl", gin.H{"HasError": false, "Urls": urls, "Count": result.RowsAffected})
}

func Favicon(c *gin.Context) {
Expand Down
7 changes: 6 additions & 1 deletion templates/home/archived.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
<div class="flex flex-row py-3 px-2 bg-white border-l-2 border-r-2 border-gray-200">
{{template "layout/nav_bar_opener" .}}
{{template "widget/search" .}}
{{template "widget/add_link" .}}
</div>
{{template "widget/no_data" .}}
{{if (gt .Count 0)}}
{{template "home/url_container" .}}
{{else}}
{{template "widget/no_data" .}}
{{end}}
</main>
</div>
{{template "footer" .}}
8 changes: 6 additions & 2 deletions templates/home/favourite.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
<div class="flex flex-row py-3 px-2 bg-white border-l-2 border-r-2 border-gray-200">
{{template "layout/nav_bar_opener" .}}
{{template "widget/search" .}}
{{template "widget/add_link" .}}
</div>
{{template "home/url_container" .}}
{{template "widget/pagination" .}}
{{if (gt .Count 0)}}
{{template "home/url_container" .}}
{{else}}
{{template "widget/no_data" .}}
{{end}}
</main>
</div>
{{template "footer" .}}
6 changes: 5 additions & 1 deletion templates/home/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
{{template "widget/search" .}}
{{template "widget/add_link" .}}
</div>
{{template "home/url_container" .}}
{{if (gt .Count 0)}}
{{template "home/url_container" .}}
{{else}}
{{template "widget/no_data" .}}
{{end}}
</main>
</div>
{{template "footer" .}}
7 changes: 6 additions & 1 deletion templates/home/trash.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
<div class="flex flex-row py-3 px-2 bg-white border-l-2 border-r-2 border-gray-200">
{{template "layout/nav_bar_opener" .}}
{{template "widget/search" .}}
{{template "widget/add_link" .}}
</div>
{{template "widget/no_data" .}}
{{if (gt .Count 0)}}
{{template "home/url_container" .}}
{{else}}
{{template "widget/no_data" .}}
{{end}}
</main>
</div>
{{template "footer" .}}
4 changes: 2 additions & 2 deletions templates/home/url_actions.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</svg>
</span>
<span id="move-to-favourite" data-id="{{.ID}}" class="hover:bg-gray-100 rounded p-1 group cursor-pointer">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-gray-500 group-hover:text-indigo-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-gray-500 group-hover:text-indigo-500" fill="{{if .IsFav}}black{{else}}none{{end}}" viewBox="0 0 24 24" stroke="currentColor">
<path
stroke-linecap="round"
stroke-linejoin="round"
Expand All @@ -22,7 +22,7 @@
</svg>
</span>
<span id="move-to-archive" data-id="{{.ID}}" class="hover:bg-gray-100 rounded p-1 group cursor-pointer">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-gray-500 group-hover:text-indigo-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-gray-500 group-hover:text-indigo-500" fill="{{if .IsArchived}}black{{else}}none{{end}}" viewBox="0 0 24 24" stroke="currentColor">
<path
stroke-linecap="round"
stroke-linejoin="round"
Expand Down

0 comments on commit 54c05ce

Please sign in to comment.