Add Answer model and fix active funcmap
This commit is contained in:
parent
c485bd119e
commit
94da7ad65f
8 changed files with 67 additions and 16 deletions
|
@ -47,7 +47,7 @@ func loginHandler() http.Handler {
|
|||
session.Values["token"] = token
|
||||
session.Save(r, w)
|
||||
r.Method = "GET"
|
||||
http.Redirect(w, r, "/teachers?format=html&tpl_layout=base&tpl_content=teachers", http.StatusSeeOther)
|
||||
http.Redirect(w, r, "/questions?format=html&tpl_layout=base&tpl_content=questions", http.StatusSeeOther)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
1
main.go
1
main.go
|
@ -27,6 +27,7 @@ var (
|
|||
|
||||
models = []interface{}{
|
||||
&orm.Question{},
|
||||
&orm.Answer{},
|
||||
}
|
||||
)
|
||||
|
||||
|
|
45
orm/answer.go
Normal file
45
orm/answer.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package orm
|
||||
|
||||
import (
|
||||
"github.com/jinzhu/gorm"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Answer struct {
|
||||
gorm.Model
|
||||
|
||||
Text string
|
||||
Correct bool
|
||||
|
||||
QuestionID uint
|
||||
}
|
||||
|
||||
func (a *Answer) GetID() uint { return a.ID }
|
||||
|
||||
func (a *Answer) String() string {
|
||||
return a.Text
|
||||
}
|
||||
|
||||
func (a *Answer) Create(args map[string]string, r *http.Request) (interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (a *Answer) Read(args map[string]string, r *http.Request) (interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (a *Answer) ReadAll(args map[string]string, r *http.Request) (interface{}, error) {
|
||||
var questions []*Question
|
||||
if err := DB().Order("created_at").Find(&questions).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return questions, nil
|
||||
}
|
||||
|
||||
func (a *Answer) Update(args map[string]string, r *http.Request) (interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (a *Answer) Delete(args map[string]string, r *http.Request) (interface{}, error) {
|
||||
return nil, nil
|
||||
}
|
|
@ -4,7 +4,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
@ -44,9 +43,13 @@ var (
|
|||
)
|
||||
|
||||
func modelName(value interface{}) string {
|
||||
if t := reflect.TypeOf(value); t.Kind() == reflect.Ptr {
|
||||
t := reflect.TypeOf(value)
|
||||
switch t.Kind() {
|
||||
case reflect.Ptr:
|
||||
return t.Elem().Name()
|
||||
} else {
|
||||
case reflect.Slice:
|
||||
return strings.Replace(t.Elem().String(), "*orm.", "", -1)
|
||||
default:
|
||||
return t.Name()
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +63,6 @@ func pluralize(text string) string {
|
|||
}
|
||||
|
||||
func active(value string, model interface{}) string {
|
||||
log.Println(pluralize(lower(modelName(model))))
|
||||
if value == pluralize(lower(modelName(model))) {
|
||||
return "active"
|
||||
}
|
||||
|
|
|
@ -12,14 +12,18 @@
|
|||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-lg fixed-top navbar-dark bg-primary">
|
||||
<a class="navbar-brand" href="/teachers?{{query "tpl_layout" "base" "tpl_content" "teachers"}}">OEF</a>
|
||||
<a class="navbar-brand" href="/teachers?{{query "tpl_layout" "base" "tpl_content" "teachers"}}">
|
||||
<span class="fa fa-landmark"></span>
|
||||
OEF 2020
|
||||
</a>
|
||||
<button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div id="navbar" class="collapse navbar-collapse">
|
||||
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<a class="nav-item nav-link {{.Data|active "questions"}}" href="{{all "Question"}}">Domande</a>
|
||||
<a class="nav-item nav-link {{.Data|active "questions"}}" href="{{all "Question"}}">Domande</a>
|
||||
<a class="nav-item nav-link {{.Data|active "answers"}}" href="{{all "Answers"}}">Risposte</a>
|
||||
</ul>
|
||||
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="/styles.css" />
|
||||
<title>karmen</title>
|
||||
<title>OEF 2020</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
{{ define "content" }}
|
||||
<div class="container">
|
||||
<h1 class="text-center karmen-title">
|
||||
<span class="fa fa-glasses"></span>
|
||||
karmen
|
||||
<small>Behind the scenes she is.</small>
|
||||
<span class="fa fa-landmark"></span>
|
||||
OEF 2020
|
||||
<small>La piattaforma di gara</small>
|
||||
</h1>
|
||||
<div class="login">
|
||||
<form action="/login" method="post">
|
||||
|
@ -20,9 +20,8 @@
|
|||
{{if .Options.Get "failed"}}
|
||||
<p class="text-center text-danger">Autenticazione fallita!</p>
|
||||
{{end}}
|
||||
<p class="text-center">Sviluppato con <span class="glyphicon glyphicon-heart" aria-hidden="true"></span> da <a href="https://github.com/remogatto">Andrea
|
||||
Fazzi</a> per il <a href="https://www.carducci-dante.gov.it">Liceo
|
||||
"Carducci-Dante"</a> di Trieste</p>
|
||||
<p class="text-center">Sviluppata da <a href="https://github.com/remogatto">Andrea
|
||||
Fazzi</a> per le <a href="https://www.olimpiadi-economiaefinanza.it">Olimpiadi di Economia e Finanza</a></p>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
<div class="container">
|
||||
{{$options := `
|
||||
title: "Questions"
|
||||
buttonTitle: "Crea nuovo Question"
|
||||
title: "Domande"
|
||||
buttonTitle: "Crea nuova domanda"
|
||||
`}}
|
||||
|
||||
{{template "read_all_header" dict "options" ($options | yaml) "lengthData" (len .Data) "modelPath" (create "Question")}}
|
||||
|
|
Loading…
Reference in a new issue