Skip to content

Commit

Permalink
feat: adding home page listing.
Browse files Browse the repository at this point in the history
  • Loading branch information
puni9869 committed Nov 9, 2024
1 parent 3765c1c commit fc49186
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
3 changes: 2 additions & 1 deletion config/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"sqlite": {
"type": "sqlite",
"databaseName": "pinmyblogs",
"fileName": "data.dat"
"fileName": "data.dat",
"logSql": true
}
},
"enableSsl": false,
Expand Down
15 changes: 12 additions & 3 deletions server/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,38 @@ import (
func AddWeblink(c *gin.Context) {
log := logger.NewLogger()
var err error

session := sessions.Default(c)
currentlyLoggedIn := session.Get(middlewares.Userkey)
var requestBody forms.WeblinkRequest
// Handle the error for url validation like form validator
requestBody := middlewares.GetForm(c).(*forms.WeblinkRequest)
ctx := middlewares.GetContext(c)
if ctx["Tag_HasError"] == true || ctx["Url_HasError"] == true {
log.WithError(err).Error("Bad request body")
c.JSON(http.StatusBadRequest, gin.H{"Status": "NOT_OK", "Errors": ctx})
return
}

db := database.Db()
url := models.Url{WebLink: requestBody.Url,
IsActive: true, IsDeleted: false,
CreatedBy: currentlyLoggedIn.(string), Tag: requestBody.Tag,
}
db.Save(&url)
go spider.ScrapeUrl(&url)

log.Info("Requested to add %s in tag: %s ", requestBody.Url, requestBody.Tag)
c.JSON(http.StatusCreated, gin.H{"Status": "OK", "Message": "Weblink Added."})
}

func Home(c *gin.Context) {
c.HTML(http.StatusOK, "home.tmpl", nil)
log := logger.NewLogger()
session := sessions.Default(c)
currentlyLoggedIn := session.Get(middlewares.Userkey)
var urls []models.Url
db := database.Db()
result := db.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})
}

func Favourite(c *gin.Context) {
Expand Down
10 changes: 5 additions & 5 deletions templates/home/url_actions.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{define "home/url_actions"}}
<div class="flex flex-row align-start items-start select-none gap-x-1">
<span id="move-to-pinned" class="hover:bg-gray-100 rounded p-1 group cursor-pointer">
<span id="move-to-pinned" 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">
<path stroke-linecap="round" stroke-width="2" stroke-linejoin="round" d="M6 6h.008v.008H6V6Z" />
<path
Expand All @@ -11,7 +11,7 @@
/>
</svg>
</span>
<span id="move-to-favourite" class="hover:bg-gray-100 rounded p-1 group cursor-pointer">
<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">
<path
stroke-linecap="round"
Expand All @@ -21,7 +21,7 @@
/>
</svg>
</span>
<span id="move-to-archive" class="hover:bg-gray-100 rounded p-1 group cursor-pointer">
<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">
<path
stroke-linecap="round"
Expand All @@ -32,7 +32,7 @@
</svg>
</span>

<span id="move-to-trash" class="hover:bg-gray-100 rounded p-1 group cursor-pointer">
<span id="move-to-trash" 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">
<path
stroke-linecap="round"
Expand All @@ -43,7 +43,7 @@
</svg>
</span>

<span id="share" class="hover:bg-gray-100 rounded p-1 group cursor-pointer">
<span id="share" 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">
<path
stroke-linecap="round"
Expand Down
8 changes: 3 additions & 5 deletions templates/home/url_container.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
<div class="border-t-2 border-gray-200"></div>
<!-- component url_row -->
<div class="bg-gray-200 h-fit flex flex-col items-center justify-start">
{{template "home/url_row" .}}
{{template "home/url_row" .}}
{{template "home/url_row" .}}
{{template "home/url_row" .}}
{{template "home/url_row" .}}
{{range .Urls}}
{{template "home/url_row" .}}
{{end}}
</div>
</div>
</div>
Expand Down
16 changes: 8 additions & 8 deletions templates/home/url_row.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
<div class="pb-1 pt-2 flex flex-col rounded-sm bg-white shadow px-3 w-full cursor-pointer mb-1">
<!-- Title -->
<div class="text-black-500 hover:text-indigo-500">
<p class="font-medium text-2xl cursor-pointer">Deploy a Django App Using Gunicorn to App Platform</p>
<p class="font-medium text-xl cursor-pointer">{{.WebLink}}</p>
</div>
<!-- Link -->
<div class="text-gray-500 hover:text-indigo-400">
<a class="font-sm text-xs cursor-pointer style-none" href="https://www.instapaper.com/u" target="_blank">https://www.instapaper.com/u</a>
<div class="text-gray-500 hover:text-indigo-400 overflow-hidden">
<a class="font-sm text-xs cursor-pointer style-none" href="{{.WebLink}}" target="_blank">{{.WebLink}}</a>
</div>

<!-- Description -->
<div class="mb-2 w-3/4 h-10 overflow-hidden">
<p class="text-sm text-gray-700 font-light max-w-full overflow-hidden text-ellipsis">
The app to App Platform using a Gunicorn HTTP server.Build a Python app using Django and then deploy the app to App Platform using a Gunicorn HTTP server.
</p>
</div>
{{if .Summary}}
<div class="mb-2 w-3/4 h-10 overflow-hidden">
<p class="text-sm text-gray-700 font-light max-w-full overflow-hidden text-ellipsis"></p>
</div>
{{end}}

<!-- Icon -->
{{template "home/url_actions" .}}
Expand Down

0 comments on commit fc49186

Please sign in to comment.