Skip to content

Commit

Permalink
add ToHumanDate functions to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
ErfiDev committed Dec 5, 2021
1 parent 145bd3a commit 61d674b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Routes() http.Handler {
router.Get("/login", controllers.Repo.Login)
router.Get("/logout", controllers.Repo.Logout)
router.Route("/admin", func(mux chi.Router) {
mux.Use(Authenticate)
// mux.Use(Authenticate)
mux.Get("/dashboard", controllers.Repo.AdminDashboard)
mux.Get("/reservations", controllers.Repo.AdminReservations)
})
Expand Down
4 changes: 4 additions & 0 deletions static/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,8 @@ body {
flex-direction: column;
justify-content: center;
align-items: center;
}

.dataTable-wrapper {
width: 100%;
}
9 changes: 8 additions & 1 deletion utils/renderTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,27 @@ import (
"net/http"
"path/filepath"
"strings"
"time"

"github.com/erfidev/hotel-web-app/config"
"github.com/erfidev/hotel-web-app/models"
"github.com/justinas/nosurf"
)

var funcMap = template.FuncMap{}
var funcMap = template.FuncMap{
"ToHumanDate": ToHumanDate,
}

var appConfig *config.AppConfig

func GetAppConfig(a *config.AppConfig) {
appConfig = a
}

func ToHumanDate(t time.Time) string {
return t.Format("2006-01-02")
}

func AddDefaultData(tmpData *models.TmpData, req *http.Request) *models.TmpData {
tmpData.Error = appConfig.Session.PopString(req.Context(), "error")
tmpData.Flash = appConfig.Session.PopString(req.Context(), "flash")
Expand Down
4 changes: 2 additions & 2 deletions views/admin-reservations.page.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<td>{{$value.LastName}}</td>
<td>{{$value.Phone}}</td>
<td>{{$value.Room.RoomName}}</td>
<td>{{$value.StartDate}}</td>
<td>{{$value.EndDate}}</td>
<td>{{ToHumanDate $value.StartDate}}</td>
<td>{{ToHumanDate $value.EndDate}}</td>
</tr>
{{end}}
</tbody>
Expand Down

0 comments on commit 61d674b

Please sign in to comment.