From ccf10c8d425b28c75cb9ce66c50c943f8825b783 Mon Sep 17 00:00:00 2001 From: jan Date: Sun, 27 Dec 2015 21:24:57 +0100 Subject: =?UTF-8?q?alter=20und=20updated=5Fat=20f=C3=BCr=20gril=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit diff --git a/assets/css/gril.css b/assets/css/gril.css index 409ef51..e22364a 100644 --- a/assets/css/gril.css +++ b/assets/css/gril.css @@ -1,4 +1,8 @@ h1 > small { padding-left: 8px; font-size: 50%; +} + +.card-title { + font-size: 36px !important; } \ No newline at end of file diff --git a/views/gril.html b/views/gril.html index 3983061..f3b7148 100644 --- a/views/gril.html +++ b/views/gril.html @@ -16,6 +16,38 @@ {{ $tag }} {{ end }} +
+
+
+ {{ if $gril.Age.Valid }} +
+
+
+ {{ $gril.Age.Value }} +

years old

+
+
+
+ {{ end }} + {{ if $gril.Birthday.Valid }} +
+
+
+ {{ $gril.Birthday.Value}} +

birthday

+
+
+
+ {{ end }} +
+
+
+ {{ $gril.UpdatedAt.Format "Jan 02, 2006" }} +

last updated

+
+
+
+
-- cgit v0.10.1 From 0746d945a61ca3dc7588a1f7a2c320ca8a06e198 Mon Sep 17 00:00:00 2001 From: jan Date: Sun, 27 Dec 2015 21:29:50 +0100 Subject: =?UTF-8?q?dashboard=20auch=20f=C3=BCr=20nicht=20eingeloggte=20ben?= =?UTF-8?q?utzer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit diff --git a/dashboard.go b/dashboard.go index 63dcdfc..0ca38ef 100644 --- a/dashboard.go +++ b/dashboard.go @@ -7,11 +7,7 @@ import ( ) func viewDashboard(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { - user, err := app.Charakterin.GetUserFromRequest(r) - if err != nil { - http.Redirect(w, r, "/", 302) - return - } + user, _ := app.Charakterin.GetUserFromRequest(r) var categories []grilist.DashboardCategory diff --git a/main.go b/main.go index dacdfe1..6dec94c 100644 --- a/main.go +++ b/main.go @@ -19,12 +19,6 @@ import ( var app *grilist.Grilist func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { - _, err := app.Charakterin.GetUserFromRequest(r) - if err != nil { - http.Redirect(w, r, "/login", 302) - return - } - http.Redirect(w, r, "/dashboard", 302) } diff --git a/modules/lists/lists.go b/modules/lists/lists.go index a7e822a..154bf74 100644 --- a/modules/lists/lists.go +++ b/modules/lists/lists.go @@ -177,29 +177,33 @@ func rowsToCard(rows *sql.Rows) []frontend.Card { func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { var categories []grilist.DashboardCategory - // Listen des Benutzers - rows, err := m.g.DB.Query(`SELECT id, name, description FROM grilist.lists WHERE user_id = $1`, user.ID) + // Neue Listen + rows, err := m.g.DB.Query(`SELECT id, name, description FROM grilist.lists ORDER BY id DESC LIMIT 5`) if err != nil { log.Println(err) - return []grilist.DashboardCategory{} + return categories } defer rows.Close() categories = append(categories, grilist.DashboardCategory{ - Title: "Meine Listen", + Title: "Neueste Listen", Cards: rowsToCard(rows), }) - // Neue Listen - rows, err = m.g.DB.Query(`SELECT id, name, description FROM grilist.lists ORDER BY id DESC LIMIT 5`) + if user == nil { + return categories + } + + // Listen des Benutzers + rows, err = m.g.DB.Query(`SELECT id, name, description FROM grilist.lists WHERE user_id = $1`, user.ID) if err != nil { log.Println(err) - return categories + return []grilist.DashboardCategory{} } defer rows.Close() categories = append(categories, grilist.DashboardCategory{ - Title: "Neueste Listen", + Title: "Meine Listen", Cards: rowsToCard(rows), }) diff --git a/views/navbar.html b/views/navbar.html index c4bbace..70911e4 100644 --- a/views/navbar.html +++ b/views/navbar.html @@ -6,6 +6,9 @@ {{ if .user }}
  • {{ .user.Name }}
  • Ausloggen
  • + {{ else }} +
  • Einloggen
  • +
  • Registrieren
  • {{ end }} -- cgit v0.10.1 From 0891a94767cafc13307482cd0c4f76db3bcc3b5e Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 28 Dec 2015 11:36:00 +0100 Subject: =?UTF-8?q?'html'=20template=20func=20zum=20rendern=20von=20HTML?= =?UTF-8?q?=20in=20templates.=20wird=20im=20dashboard=20verwendet=20f?= =?UTF-8?q?=C3=BCr=20mehr=20dynamik.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit diff --git a/frontend/renderer.go b/frontend/renderer.go index e9b9931..a3aa83d 100644 --- a/frontend/renderer.go +++ b/frontend/renderer.go @@ -7,8 +7,9 @@ import ( // Action ist die Aktion auf einer Card. type Action struct { - Name string - Link string + Name string + Link string + Disabled bool } // Card ist eine Karte im Materialize-Design. @@ -41,8 +42,14 @@ func (r *Renderer) SetDefaultData(data map[string]interface{}) { // New erstellt einen neuen Renderer und sucht alle Templates aus dem gegebenen pfad. func New(path string) *Renderer { + // Custom Template Funcs + funcMap := template.FuncMap{ + "html": func(in string) template.HTML { + return template.HTML(in) + }, + } r := &Renderer{ - template.Must(template.ParseGlob(path + "/*")), + template.Must(template.ParseGlob(path + "/*")).Funcs(funcMap), make(map[string]interface{}), } diff --git a/modules/lists/lists.go b/modules/lists/lists.go index 154bf74..47501c2 100644 --- a/modules/lists/lists.go +++ b/modules/lists/lists.go @@ -143,32 +143,30 @@ func (m *Module) FromID(id int) (*List, error) { return lists[0], nil } -func mkCard(title, description string, actions ...frontend.Action) frontend.Card { - card := frontend.Card{ - Title: title, - Description: description, - Size: "medium", - } - - for _, action := range actions { - card.Actions = append(card.Actions, action) - } - - return card -} - -func rowsToCard(rows *sql.Rows) []frontend.Card { +func listsToCards(lists []*List) []frontend.Card { var cards []frontend.Card - for rows.Next() { - var id int - var title, description string - if err := rows.Scan(&id, &title, &description); err != nil { - log.Println("error scanning row", err) - continue + for _, list := range lists { + s := "s" + if len(list.Grils) == 1 { + s = "" } - - cards = append(cards, mkCard(title, description, frontend.Action{"anguckieren", fmt.Sprintf("/list/%d", id)})) + cards = append(cards, frontend.Card{ + Title: list.Name, + Description: list.Description, + Size: "medium", + Actions: []frontend.Action{ + frontend.Action{ + Name: "anguckieren", + Link: fmt.Sprintf("/list/%d", list.ID), + }, + frontend.Action{ + Name: fmt.Sprintf(`%d gril%s`, len(list.Grils), s), + Link: "#", + Disabled: true, + }, + }, + }) } return cards } @@ -178,16 +176,15 @@ func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.Dashboar var categories []grilist.DashboardCategory // Neue Listen - rows, err := m.g.DB.Query(`SELECT id, name, description FROM grilist.lists ORDER BY id DESC LIMIT 5`) + lists, err := m.getLists(`1=1 ORDER BY id DESC LIMIT 5`) if err != nil { log.Println(err) return categories } - defer rows.Close() categories = append(categories, grilist.DashboardCategory{ Title: "Neueste Listen", - Cards: rowsToCard(rows), + Cards: listsToCards(lists), }) if user == nil { @@ -195,16 +192,15 @@ func (m *Module) ProvideDashboardData(user *charakterin.User) []grilist.Dashboar } // Listen des Benutzers - rows, err = m.g.DB.Query(`SELECT id, name, description FROM grilist.lists WHERE user_id = $1`, user.ID) + lists, err = m.getLists(`user_id = $1`, user.ID) if err != nil { log.Println(err) - return []grilist.DashboardCategory{} + return categories } - defer rows.Close() categories = append(categories, grilist.DashboardCategory{ Title: "Meine Listen", - Cards: rowsToCard(rows), + Cards: listsToCards(lists), }) return categories diff --git a/views/dashboard.html b/views/dashboard.html index f2d410d..0551285 100644 --- a/views/dashboard.html +++ b/views/dashboard.html @@ -16,12 +16,16 @@
    - {{ $card.Title }} -

    {{ $card.Description }}

    + {{ $card.Title | html }} +

    {{ $card.Description | html }}

    {{ range $action := $card.Actions }} - {{ $action.Name }} + {{ if $action.Disabled }} + {{ $action.Name | html }} + {{ else }} + {{ $action.Name | html }} + {{ end }} {{ end }}
    -- cgit v0.10.1 From 647c105dadfa58af6cfa80d3f359d43cfa5d5cf2 Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 28 Dec 2015 12:23:30 +0100 Subject: anzeige im gril view, in wie vielen listen das gril vorkommt diff --git a/assets/css/gril.css b/assets/css/gril.css index e22364a..5b5bd84 100644 --- a/assets/css/gril.css +++ b/assets/css/gril.css @@ -3,6 +3,11 @@ h1 > small { font-size: 50%; } -.card-title { +.card-title.big { font-size: 36px !important; +} + +.card-content.center-big { + padding-top: 9px; + padding-bottom: 9px; } \ No newline at end of file diff --git a/modules/grils/gril.go b/modules/grils/gril.go index 9fd3be5..edf25a9 100644 --- a/modules/grils/gril.go +++ b/modules/grils/gril.go @@ -23,4 +23,5 @@ type Gril struct { Tags []string ForeignIDs map[DataSource]int UpdatedAt time.Time + Lists []int } diff --git a/modules/grils/grils.go b/modules/grils/grils.go index e2eb543..a38f41f 100644 --- a/modules/grils/grils.go +++ b/modules/grils/grils.go @@ -74,6 +74,26 @@ func (m *GrilsModule) getGrils(whereClause string, params ...interface{}) ([]*Gr return grils, nil } +func (m *GrilsModule) GetListsOfGril(gril *Gril) error { + rows, err := m.g.DB.Query(`SELECT list_id FROM grilist.lists_grils WHERE gril_id = $1`, gril.ID) + if err != nil { + return err + } + + defer rows.Close() + for rows.Next() { + var listID int + if err := rows.Scan(&listID); err != nil { + log.Println(err) + continue + } + + gril.Lists = append(gril.Lists, listID) + } + + return nil +} + func (m *GrilsModule) ProvideDashboardData(user *charakterin.User) []grilist.DashboardCategory { var categories []grilist.DashboardCategory @@ -137,6 +157,10 @@ func (m *GrilsModule) viewGril(w http.ResponseWriter, r *http.Request, p httprou return } + if err := m.GetListsOfGril(gril); err != nil { + log.Println(err) + } + data := m.g.Renderer.DefaultData() data["user"] = user data["gril"] = gril diff --git a/views/gril.html b/views/gril.html index f3b7148..c7ecbdc 100644 --- a/views/gril.html +++ b/views/gril.html @@ -19,22 +19,32 @@

    - {{ if $gril.Age.Valid }} + {{ if $gril.Birthday.Valid }}
    - {{ $gril.Age.Value }} -

    years old

    + {{ $gril.Birthday.Value}} +

    geburtstag

    - {{ end }} - {{ if $gril.Birthday.Valid }} + {{ else if $gril.Age.Valid }}
    - {{ $gril.Birthday.Value}} -

    birthday

    + {{ $gril.Age.Value }} +

    jahre alt

    +
    +
    +
    + {{ end }} + {{ if $gril.Lists }} +
    +
    +
    +

    in

    + {{ len $gril.Lists}} +

    liste{{ if ne (len $gril.Lists) 1 }}n{{ end }}

    @@ -42,8 +52,8 @@
    - {{ $gril.UpdatedAt.Format "Jan 02, 2006" }} -

    last updated

    + {{ $gril.UpdatedAt.Format "Jan 02, 2006" }} +

    aktualisiert

    -- cgit v0.10.1