mirror of https://github.com/muety/wakapi.git
feat: introduce newsbox for front page (resolve #393)
This commit is contained in:
parent
99a3e8f5da
commit
373d969734
|
@ -30,6 +30,7 @@ const (
|
||||||
KeyLatestTotalTime = "latest_total_time"
|
KeyLatestTotalTime = "latest_total_time"
|
||||||
KeyLatestTotalUsers = "latest_total_users"
|
KeyLatestTotalUsers = "latest_total_users"
|
||||||
KeyLastImportImport = "last_import"
|
KeyLastImportImport = "last_import"
|
||||||
|
KeyNewsbox = "newsbox"
|
||||||
|
|
||||||
SimpleDateFormat = "2006-01-02"
|
SimpleDateFormat = "2006-01-02"
|
||||||
SimpleDateTimeFormat = "2006-01-02 15:04:05"
|
SimpleDateTimeFormat = "2006-01-02 15:04:05"
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
package view
|
package view
|
||||||
|
|
||||||
|
type Newsbox struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Text string `json:"text"`
|
||||||
|
}
|
||||||
|
|
||||||
type HomeViewModel struct {
|
type HomeViewModel struct {
|
||||||
Success string
|
Success string
|
||||||
Error string
|
Error string
|
||||||
TotalHours int
|
TotalHours int
|
||||||
TotalUsers int
|
TotalUsers int
|
||||||
|
Newsbox *Newsbox
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HomeViewModel) WithSuccess(m string) *HomeViewModel {
|
func (s *HomeViewModel) WithSuccess(m string) *HomeViewModel {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/gorilla/schema"
|
"github.com/gorilla/schema"
|
||||||
|
@ -10,6 +11,7 @@ import (
|
||||||
"github.com/muety/wakapi/services"
|
"github.com/muety/wakapi/services"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -49,23 +51,29 @@ func (h *HomeHandler) GetIndex(w http.ResponseWriter, r *http.Request) {
|
||||||
func (h *HomeHandler) buildViewModel(r *http.Request) *view.HomeViewModel {
|
func (h *HomeHandler) buildViewModel(r *http.Request) *view.HomeViewModel {
|
||||||
var totalHours int
|
var totalHours int
|
||||||
var totalUsers int
|
var totalUsers int
|
||||||
|
var newsbox view.Newsbox
|
||||||
|
|
||||||
if t, err := h.keyValueSrvc.GetString(conf.KeyLatestTotalTime); err == nil && t != nil && t.Value != "" {
|
if kv, err := h.keyValueSrvc.GetString(conf.KeyLatestTotalTime); err == nil && kv != nil && kv.Value != "" {
|
||||||
if d, err := time.ParseDuration(t.Value); err == nil {
|
if d, err := time.ParseDuration(kv.Value); err == nil {
|
||||||
totalHours = int(d.Hours())
|
totalHours = int(d.Hours())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if t, err := h.keyValueSrvc.GetString(conf.KeyLatestTotalUsers); err == nil && t != nil && t.Value != "" {
|
if kv, err := h.keyValueSrvc.GetString(conf.KeyLatestTotalUsers); err == nil && kv != nil && kv.Value != "" {
|
||||||
if d, err := strconv.Atoi(t.Value); err == nil {
|
if d, err := strconv.Atoi(kv.Value); err == nil {
|
||||||
totalUsers = d
|
totalUsers = d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if kv, err := h.keyValueSrvc.GetString(conf.KeyNewsbox); err == nil && kv != nil && kv.Value != "" {
|
||||||
|
json.NewDecoder(strings.NewReader(kv.Value)).Decode(&newsbox)
|
||||||
|
}
|
||||||
|
|
||||||
return &view.HomeViewModel{
|
return &view.HomeViewModel{
|
||||||
Success: r.URL.Query().Get("success"),
|
Success: r.URL.Query().Get("success"),
|
||||||
Error: r.URL.Query().Get("error"),
|
Error: r.URL.Query().Get("error"),
|
||||||
TotalHours: totalHours,
|
TotalHours: totalHours,
|
||||||
TotalUsers: totalUsers,
|
TotalUsers: totalUsers,
|
||||||
|
Newsbox: &newsbox,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,22 @@ body {
|
||||||
@apply font-semibold text-gray-400 hover:text-gray-300;
|
@apply font-semibold text-gray-400 hover:text-gray-300;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.newsbox {
|
||||||
|
@apply px-4 py-2 border-2 border-red-700 bg-gray-850 rounded-md text-white border-green-700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.newsbox-default {
|
||||||
|
@apply border-green-700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.newsbox-warning {
|
||||||
|
@apply border-yellow-600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.newsbox-danger {
|
||||||
|
@apply border-red-700;
|
||||||
|
}
|
||||||
|
|
||||||
::-webkit-calendar-picker-indicator {
|
::-webkit-calendar-picker-indicator {
|
||||||
filter: invert(1);
|
filter: invert(1);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -2,6 +2,11 @@ module.exports = {
|
||||||
purge: {
|
purge: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
mode: 'all',
|
mode: 'all',
|
||||||
content: ['./views/*.tpl.html']
|
content: ['./views/*.tpl.html'],
|
||||||
}
|
safelist: [
|
||||||
|
'newsbox-default',
|
||||||
|
'newsbox-warning',
|
||||||
|
'newsbox-danger',
|
||||||
|
]
|
||||||
|
},
|
||||||
}
|
}
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
{{ template "alerts.tpl.html" . }}
|
{{ template "alerts.tpl.html" . }}
|
||||||
|
|
||||||
<div class="absolute flex top-0 right-0 mr-8 mt-10 py-2">
|
<div class="absolute flex top-0 right-0 mr-4 mt-10 py-2">
|
||||||
<div class="mx-1">
|
<div class="mx-1">
|
||||||
<a href="login" class="btn-primary">
|
<a href="login" class="btn-primary">
|
||||||
<span class="iconify inline" data-icon="fluent:key-24-filled"></span> Login</a>
|
<span class="iconify inline" data-icon="fluent:key-24-filled"></span> Login</a>
|
||||||
|
@ -18,6 +18,12 @@
|
||||||
|
|
||||||
<main class="mt-10 px-4 md:px-10 lg:px-24 flex-grow flex justify-center w-full">
|
<main class="mt-10 px-4 md:px-10 lg:px-24 flex-grow flex justify-center w-full">
|
||||||
<div class="flex flex-col text-white">
|
<div class="flex flex-col text-white">
|
||||||
|
{{ if and .Newsbox .Newsbox.Text }}
|
||||||
|
<div class="mb-14 -mt-4 newsbox newsbox-{{ .Newsbox.Type }}">
|
||||||
|
{{ .Newsbox.Text | htmlSafe }}
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
<h1 class="text-8xl font-semibold antialiased text-center mb-10 leading-snug">Keep Track of<br><span
|
<h1 class="text-8xl font-semibold antialiased text-center mb-10 leading-snug">Keep Track of<br><span
|
||||||
class="text-green-700">Your</span> Coding Time</h1>
|
class="text-green-700">Your</span> Coding Time</h1>
|
||||||
<p class="text-center text-gray-500 text-xl my-2">Wakapi is an open-source tool that helps you keep track of the
|
<p class="text-center text-gray-500 text-xl my-2">Wakapi is an open-source tool that helps you keep track of the
|
||||||
|
|
Loading…
Reference in New Issue