diff --git a/area.go b/area.go index 0a2a642..a001f00 100644 --- a/area.go +++ b/area.go @@ -10,13 +10,13 @@ import ( ) type Area struct { - ID int + ID int Name string Sections []Section } -func AreaRetrieve() (areas []Area, err error) {// {{{ +func AreaRetrieve() (areas []Area, err error) { // {{{ areas = []Area{} row := service.Db.Conn.QueryRow(` SELECT @@ -32,7 +32,7 @@ func AreaRetrieve() (areas []Area, err error) {// {{{ ) ) AS sections FROM area a - INNER JOIN section s ON s.area_id = a.id + LEFT JOIN section s ON s.area_id = a.id GROUP BY a.id, a.name ) jsonsections`, @@ -51,12 +51,20 @@ func AreaRetrieve() (areas []Area, err error) {// {{{ return } + return +} // }}} +func AreaCreate(name string) (err error) {// {{{ + _, err = service.Db.Conn.Exec(`INSERT INTO area(name) VALUES($1)`, name) + return +}// }}} +func AreaRename(id int, name string) (err error) {// {{{ + _, err = service.Db.Conn.Exec(`UPDATE area SET name=$2 WHERE id=$1`, id, name) return }// }}} -func (a Area) SortedSections() []Section {// {{{ - sort.SliceStable(a.Sections, func (i, j int) bool { +func (a Area) SortedSections() []Section { // {{{ + sort.SliceStable(a.Sections, func(i, j int) bool { return a.Sections[i].Name < a.Sections[j].Name }) return a.Sections -}// }}} +} // }}} diff --git a/main.go b/main.go index 60e1317..465bcee 100644 --- a/main.go +++ b/main.go @@ -97,6 +97,13 @@ func main() { // {{{ } service.Register("/", false, false, staticHandler) + + service.Register("/area/new/{name}", false, false, areaNew) + service.Register("/area/rename/{id}/{name}", false, false, areaRename) + + service.Register("/section/new/{areaID}/{name}", false, false, sectionNew) + service.Register("/section/rename/{id}/{name}", false, false, sectionRename) + service.Register("/problems", false, false, pageProblems) service.Register("/problem/acknowledge/{id}", false, false, pageProblemAcknowledge) service.Register("/problem/unacknowledge/{id}", false, false, pageProblemUnacknowledge) @@ -276,6 +283,77 @@ func pageIndex(w http.ResponseWriter, _ *http.Request, _ *session.T) { // {{{ page.Render(w) } // }}} +func areaNew(w http.ResponseWriter, r *http.Request, _ *session.T) { // {{{ + name := r.PathValue("name") + err := AreaCreate(name) + if err != nil { + httpError(w, we.Wrap(err).Log()) + return + } + + w.Header().Add("Location", "/configuration") + w.WriteHeader(302) + return +} // }}} +func areaRename(w http.ResponseWriter, r *http.Request, _ *session.T) { // {{{ + idStr := r.PathValue("id") + id, err := strconv.Atoi(idStr) + if err != nil { + httpError(w, we.Wrap(err).Log()) + return + } + + name := r.PathValue("name") + err = AreaRename(id, name) + if err != nil { + httpError(w, we.Wrap(err).Log()) + return + } + + w.Header().Add("Location", "/configuration") + w.WriteHeader(302) + return +} // }}} + +func sectionNew(w http.ResponseWriter, r *http.Request, _ *session.T) { // {{{ + idStr := r.PathValue("areaID") + areaID, err := strconv.Atoi(idStr) + if err != nil { + httpError(w, we.Wrap(err).Log()) + return + } + + name := r.PathValue("name") + err = SectionCreate(areaID, name) + if err != nil { + httpError(w, we.Wrap(err).Log()) + return + } + + w.Header().Add("Location", "/configuration") + w.WriteHeader(302) + return +} // }}} +func sectionRename(w http.ResponseWriter, r *http.Request, _ *session.T) { // {{{ + idStr := r.PathValue("id") + id, err := strconv.Atoi(idStr) + if err != nil { + httpError(w, we.Wrap(err).Log()) + return + } + + name := r.PathValue("name") + err = SectionRename(id, name) + if err != nil { + httpError(w, we.Wrap(err).Log()) + return + } + + w.Header().Add("Location", "/configuration") + w.WriteHeader(302) + return +} // }}} + func pageProblems(w http.ResponseWriter, _ *http.Request, _ *session.T) { // {{{ page := Page{ LAYOUT: "main", diff --git a/section.go b/section.go index 2cf9193..b86f5c0 100644 --- a/section.go +++ b/section.go @@ -21,3 +21,12 @@ func (s *Section) SortedTriggers() []Trigger { return s.Triggers } + +func SectionCreate(areaID int, name string) (err error) {// {{{ + _, err = service.Db.Conn.Exec(`INSERT INTO section(area_id, name) VALUES($1, $2)`, areaID, name) + return +}// }}} +func SectionRename(id int, name string) (err error) {// {{{ + _, err = service.Db.Conn.Exec(`UPDATE section SET name=$2 WHERE id=$1`, id, name) + return +}// }}} diff --git a/static/css/datapoints.css b/static/css/datapoints.css index 8230ed8..35f613e 100644 --- a/static/css/datapoints.css +++ b/static/css/datapoints.css @@ -32,9 +32,11 @@ h2 { h1 { font-size: 1.5em; color: #fb4934; + font-weight: 500; } h2 { font-size: 1.25em; + font-weight: 500; } a { color: #fabd2f; diff --git a/static/css/main.css b/static/css/main.css index cf2c7e5..f3d5d59 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -32,9 +32,11 @@ h2 { h1 { font-size: 1.5em; color: #fb4934; + font-weight: 500; } h2 { font-size: 1.25em; + font-weight: 500; } a { color: #fabd2f; diff --git a/static/css/problems.css b/static/css/problems.css index 48d1c30..5b6316c 100644 --- a/static/css/problems.css +++ b/static/css/problems.css @@ -32,9 +32,11 @@ h2 { h1 { font-size: 1.5em; color: #fb4934; + font-weight: 500; } h2 { font-size: 1.25em; + font-weight: 500; } a { color: #fabd2f; @@ -98,7 +100,7 @@ label { #problems-list, #acknowledged-list { display: grid; - grid-template-columns: repeat(5, min-content); + grid-template-columns: repeat(6, min-content); grid-gap: 4px 16px; margin-bottom: 32px; } diff --git a/static/css/theme.css b/static/css/theme.css index bfc6ab6..68c59d9 100644 --- a/static/css/theme.css +++ b/static/css/theme.css @@ -32,9 +32,11 @@ h2 { h1 { font-size: 1.5em; color: #fb4934; + font-weight: 500; } h2 { font-size: 1.25em; + font-weight: 500; } a { color: #fabd2f; diff --git a/static/css/trigger_edit.css b/static/css/trigger_edit.css index 0beff8f..af41402 100644 --- a/static/css/trigger_edit.css +++ b/static/css/trigger_edit.css @@ -32,9 +32,11 @@ h2 { h1 { font-size: 1.5em; color: #fb4934; + font-weight: 500; } h2 { font-size: 1.25em; + font-weight: 500; } a { color: #fabd2f; diff --git a/static/less/main.less b/static/less/main.less index 16fdb92..54e54ae 100644 --- a/static/less/main.less +++ b/static/less/main.less @@ -37,7 +37,7 @@ margin-bottom: 32px; div { - font-weight: 500; + font-weight: @bold; font-size: 1.5em; color: @color1; } diff --git a/static/less/problems.less b/static/less/problems.less index f66f9c9..6e6a395 100644 --- a/static/less/problems.less +++ b/static/less/problems.less @@ -2,7 +2,7 @@ #problems-list, #acknowledged-list { display: grid; - grid-template-columns: repeat(5, min-content); + grid-template-columns: repeat(6, min-content); grid-gap: 4px 16px; margin-bottom: 32px; diff --git a/static/less/theme.less b/static/less/theme.less index dd0c723..513db5f 100644 --- a/static/less/theme.less +++ b/static/less/theme.less @@ -59,10 +59,12 @@ h2 { h1 { font-size: 1.5em; color: @color1; + font-weight: @bold; } h2 { font-size: 1.25em; + font-weight: @bold; } a { diff --git a/views/pages/configuration.gotmpl b/views/pages/configuration.gotmpl index b4e8601..d65b27d 100644 --- a/views/pages/configuration.gotmpl +++ b/views/pages/configuration.gotmpl @@ -1,16 +1,71 @@ {{ define "page" }} + {{ block "page_label" . }}{{end}}