Added area deletion
This commit is contained in:
parent
72f23b9c4d
commit
b83adad7c8
61
area.go
61
area.go
@ -2,9 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
// External
|
||||
re "git.gibonuddevalla.se/go/wrappederror"
|
||||
werr "git.gibonuddevalla.se/go/wrappederror"
|
||||
|
||||
// Standard
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"sort"
|
||||
)
|
||||
@ -41,7 +42,7 @@ func AreaRetrieve() (areas []Area, err error) { // {{{
|
||||
var jsonData []byte
|
||||
err = row.Scan(&jsonData)
|
||||
if err != nil {
|
||||
err = re.Wrap(err)
|
||||
err = werr.Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -51,7 +52,7 @@ func AreaRetrieve() (areas []Area, err error) { // {{{
|
||||
|
||||
err = json.Unmarshal(jsonData, &areas)
|
||||
if err != nil {
|
||||
err = re.Wrap(err)
|
||||
err = werr.Wrap(err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -65,6 +66,60 @@ 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 AreaDelete(id int) (err error) { // {{{
|
||||
var trx *sql.Tx
|
||||
trx, err = service.Db.Conn.Begin()
|
||||
if err != nil {
|
||||
err = werr.Wrap(err).WithData(id)
|
||||
}
|
||||
|
||||
_, err = trx.Exec(`
|
||||
DELETE
|
||||
FROM trigger t
|
||||
USING section s
|
||||
WHERE
|
||||
t.section_id = s.id AND
|
||||
s.area_id = $1
|
||||
`,
|
||||
id,
|
||||
)
|
||||
if err != nil {
|
||||
err2 := trx.Rollback()
|
||||
if err2 != nil {
|
||||
return werr.Wrap(err2).WithData(err)
|
||||
}
|
||||
return werr.Wrap(err).WithData(id)
|
||||
}
|
||||
|
||||
_, err = trx.Exec(`DELETE FROM public.section WHERE area_id = $1`, id)
|
||||
if err != nil {
|
||||
err2 := trx.Rollback()
|
||||
if err2 != nil {
|
||||
return werr.Wrap(err2).WithData(err)
|
||||
}
|
||||
return werr.Wrap(err).WithData(id)
|
||||
}
|
||||
|
||||
_, err = trx.Exec(`DELETE FROM public.area WHERE id = $1`, id)
|
||||
if err != nil {
|
||||
err2 := trx.Rollback()
|
||||
if err2 != nil {
|
||||
return werr.Wrap(err2).WithData(err)
|
||||
}
|
||||
return werr.Wrap(err).WithData(id)
|
||||
}
|
||||
|
||||
err = trx.Commit()
|
||||
if err != nil {
|
||||
err2 := trx.Rollback()
|
||||
if err2 != nil {
|
||||
return werr.Wrap(err2).WithData(err)
|
||||
}
|
||||
return werr.Wrap(err).WithData(id)
|
||||
}
|
||||
|
||||
return nil
|
||||
} // }}}
|
||||
|
||||
func (a Area) SortedSections() []Section { // {{{
|
||||
sort.SliceStable(a.Sections, func(i, j int) bool {
|
||||
|
38
main.go
38
main.go
@ -122,9 +122,11 @@ func main() { // {{{
|
||||
|
||||
service.Register("/area/new/{name}", false, false, areaNew)
|
||||
service.Register("/area/rename/{id}/{name}", false, false, areaRename)
|
||||
service.Register("/area/delete/{id}", false, false, areaDelete)
|
||||
|
||||
service.Register("/section/new/{areaID}/{name}", false, false, sectionNew)
|
||||
service.Register("/section/rename/{id}/{name}", false, false, sectionRename)
|
||||
service.Register("/section/delete/{id}", false, false, sectionDelete)
|
||||
|
||||
service.Register("/problems", false, false, pageProblems)
|
||||
service.Register("/problem/acknowledge/{id}", false, false, pageProblemAcknowledge)
|
||||
@ -399,6 +401,24 @@ func areaRename(w http.ResponseWriter, r *http.Request, _ *session.T) { // {{{
|
||||
w.WriteHeader(302)
|
||||
return
|
||||
} // }}}
|
||||
func areaDelete(w http.ResponseWriter, r *http.Request, _ *session.T) { // {{{
|
||||
idStr := r.PathValue("id")
|
||||
id, err := strconv.Atoi(idStr)
|
||||
if err != nil {
|
||||
httpError(w, werr.Wrap(err).WithData(idStr).Log())
|
||||
return
|
||||
}
|
||||
|
||||
err = AreaDelete(id)
|
||||
if err != nil {
|
||||
httpError(w, werr.Wrap(err).WithData(id).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")
|
||||
@ -438,6 +458,24 @@ func sectionRename(w http.ResponseWriter, r *http.Request, _ *session.T) { // {{
|
||||
w.WriteHeader(302)
|
||||
return
|
||||
} // }}}
|
||||
func sectionDelete(w http.ResponseWriter, r *http.Request, _ *session.T) { // {{{
|
||||
idStr := r.PathValue("id")
|
||||
id, err := strconv.Atoi(idStr)
|
||||
if err != nil {
|
||||
httpError(w, werr.Wrap(err).WithData(idStr).Log())
|
||||
return
|
||||
}
|
||||
|
||||
err = SectionDelete(id)
|
||||
if err != nil {
|
||||
httpError(w, werr.Wrap(err).WithData(id).Log())
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Add("Location", "/configuration")
|
||||
w.WriteHeader(302)
|
||||
return
|
||||
} // }}}
|
||||
|
||||
func pageProblems(w http.ResponseWriter, _ *http.Request, _ *session.T) { // {{{
|
||||
page := Page{
|
||||
|
15
section.go
15
section.go
@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
// External
|
||||
werr "git.gibonuddevalla.se/go/wrappederror"
|
||||
|
||||
// Standard
|
||||
"sort"
|
||||
)
|
||||
@ -30,3 +33,15 @@ func SectionRename(id int, name string) (err error) {// {{{
|
||||
_, err = service.Db.Conn.Exec(`UPDATE section SET name=$2 WHERE id=$1`, id, name)
|
||||
return
|
||||
} // }}}
|
||||
func SectionDelete(id int) (err error) { // {{{
|
||||
_, err = service.Db.Conn.Exec(`DELETE FROM public.trigger WHERE section_id = $1`, id)
|
||||
if err != nil {
|
||||
return werr.Wrap(err).WithData(id)
|
||||
}
|
||||
|
||||
_, err = service.Db.Conn.Exec(`DELETE FROM public.section WHERE id = $1`, id)
|
||||
if err != nil {
|
||||
return werr.Wrap(err).WithData(id)
|
||||
}
|
||||
return
|
||||
} // }}}
|
||||
|
130
static/css/configuration.css
Normal file
130
static/css/configuration.css
Normal file
@ -0,0 +1,130 @@
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
*,
|
||||
*:before,
|
||||
*:after {
|
||||
box-sizing: inherit;
|
||||
}
|
||||
*:focus {
|
||||
outline: none;
|
||||
}
|
||||
[onClick] {
|
||||
cursor: pointer;
|
||||
}
|
||||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
body {
|
||||
background: #282828;
|
||||
font-family: sans-serif;
|
||||
font-weight: 300;
|
||||
color: #d5c4a1;
|
||||
font-size: 11pt;
|
||||
}
|
||||
h1,
|
||||
h2 {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
h1:first-child,
|
||||
h2:first-child {
|
||||
margin-top: 0px;
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.5em;
|
||||
color: #fb4934;
|
||||
font-weight: 800;
|
||||
}
|
||||
h2 {
|
||||
font-size: 1.25em;
|
||||
color: #b8bb26;
|
||||
font-weight: 800;
|
||||
}
|
||||
a {
|
||||
color: #3f9da1;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
b {
|
||||
font-weight: 800;
|
||||
}
|
||||
input[type="text"],
|
||||
textarea,
|
||||
select {
|
||||
font-family: monospace;
|
||||
background: #202020;
|
||||
color: #d5c4a1;
|
||||
padding: 4px 8px;
|
||||
border: none;
|
||||
font-size: 1em;
|
||||
line-height: 1.5em;
|
||||
}
|
||||
button {
|
||||
background: #202020;
|
||||
color: #d5c4a1;
|
||||
padding: 8px 32px;
|
||||
border: 1px solid #535353;
|
||||
font-size: 1em;
|
||||
height: 3em;
|
||||
}
|
||||
button:focus {
|
||||
background: #333;
|
||||
}
|
||||
.line {
|
||||
grid-column: 1 / -1;
|
||||
border-bottom: 1px solid #4e4e4e;
|
||||
}
|
||||
span.date {
|
||||
color: #d5c4a1;
|
||||
font-weight: 800;
|
||||
}
|
||||
span.time {
|
||||
font-size: 0.9em;
|
||||
color: #d5c4a1;
|
||||
}
|
||||
span.seconds {
|
||||
display: none;
|
||||
}
|
||||
label {
|
||||
user-select: none;
|
||||
}
|
||||
.description {
|
||||
border: 1px solid #737373;
|
||||
color: #3f9da1;
|
||||
background: #202020;
|
||||
padding: 4px 8px;
|
||||
margin-top: 8px;
|
||||
white-space: nowrap;
|
||||
width: min-content;
|
||||
border-radius: 8px;
|
||||
}
|
||||
#areas .area > .name {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr min-content;
|
||||
grid-gap: 0px 16px;
|
||||
align-items: center;
|
||||
padding-left: 16px;
|
||||
padding-right: 8px;
|
||||
}
|
||||
#areas .area > .name img {
|
||||
margin-top: 3px;
|
||||
margin-bottom: 4px;
|
||||
height: 16px;
|
||||
}
|
||||
#areas .area .section.configuration {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr min-content;
|
||||
grid-gap: 0 16px;
|
||||
margin-top: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
#areas .area .section.configuration:last-child {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
#areas .area .section.configuration img {
|
||||
height: 16px;
|
||||
}
|
@ -182,10 +182,6 @@ label {
|
||||
margin-top: 12px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
#areas .area .section.configuration {
|
||||
margin-top: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
#areas .area .section:last-child {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
67
static/images/delete_white.svg
Normal file
67
static/images/delete_white.svg
Normal file
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="16.000025"
|
||||
height="18"
|
||||
viewBox="0 0 4.2333398 4.7625001"
|
||||
version="1.1"
|
||||
id="svg8"
|
||||
inkscape:version="1.3.2 (1:1.3.2+202311252150+091e20ef0f)"
|
||||
sodipodi:docname="delete_white.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/">
|
||||
<defs
|
||||
id="defs2" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="32"
|
||||
inkscape:cx="10.203125"
|
||||
inkscape:cy="7.03125"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
units="px"
|
||||
inkscape:window-width="2190"
|
||||
inkscape:window-height="1404"
|
||||
inkscape:window-x="1463"
|
||||
inkscape:window-y="16"
|
||||
inkscape:window-maximized="0"
|
||||
inkscape:showpageshadow="true"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d6d6d6"
|
||||
showborder="true" />
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(-214.57708,-116.15208)">
|
||||
<title
|
||||
id="title1">trash-can-outline</title>
|
||||
<path
|
||||
d="m 215.9,116.15208 v 0.26459 h -1.32292 v 0.52916 h 0.26459 v 3.43959 a 0.52916667,0.52916667 0 0 0 0.52916,0.52916 h 2.64584 a 0.52916667,0.52916667 0 0 0 0.52916,-0.52916 v -3.43959 h 0.26459 v -0.52916 h -1.32292 v -0.26459 H 215.9 m -0.52917,0.79375 h 2.64584 v 3.43959 h -2.64584 v -3.43959 M 215.9,117.475 v 2.38125 h 0.52917 V 117.475 H 215.9 m 1.05833,0 v 2.38125 h 0.52917 V 117.475 Z"
|
||||
id="path1"
|
||||
style="fill:#ffffff;fill-opacity:1;stroke-width:0.264583" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.3 KiB |
38
static/less/configuration.less
Normal file
38
static/less/configuration.less
Normal file
@ -0,0 +1,38 @@
|
||||
@import 'theme.less';
|
||||
|
||||
#areas {
|
||||
.area {
|
||||
& > .name {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr min-content;
|
||||
grid-gap: 0px 16px;
|
||||
align-items: center;
|
||||
padding-left: 16px;
|
||||
padding-right: 8px;
|
||||
|
||||
img {
|
||||
margin-top: 3px;
|
||||
margin-bottom: 4px;
|
||||
height: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.section.configuration {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr min-content;
|
||||
grid-gap: 0 16px;
|
||||
|
||||
margin-top: 8px;
|
||||
margin-bottom: 8px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
img {
|
||||
height: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -94,11 +94,6 @@
|
||||
margin-top: 12px;
|
||||
margin-bottom: 20px;
|
||||
|
||||
&.configuration {
|
||||
margin-top: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
{{ define "page" }}
|
||||
{{ $version := .VERSION }}
|
||||
<link rel="stylesheet" type="text/css" href="/css/{{ .VERSION }}/configuration.css">
|
||||
<script type="text/javascript">
|
||||
function newArea() {
|
||||
let name = prompt("Area name")
|
||||
@ -47,6 +49,18 @@
|
||||
}
|
||||
location.href = `/section/rename/${id}/${newName.trim()}`
|
||||
}
|
||||
|
||||
function deleteArea(id, name) {
|
||||
if (!confirm(`Are you sure you want to delete '${name}'?\nEverything in it will be deleted!`))
|
||||
return
|
||||
location.href = `/area/delete/${id}`
|
||||
}
|
||||
|
||||
function deleteSection(id, name) {
|
||||
if (!confirm(`Are you sure you want to delete '${name}'?\nEverything in it will be deleted!`))
|
||||
return
|
||||
location.href = `/section/delete/${id}`
|
||||
}
|
||||
</script>
|
||||
|
||||
{{ block "page_label" . }}{{end}}
|
||||
@ -58,14 +72,21 @@
|
||||
<div id="areas">
|
||||
{{ range .Data.Areas }}
|
||||
<div class="area">
|
||||
<div class="name" onclick="renameArea({{ .ID }}, {{ .Name }})">{{ .Name }}</div>
|
||||
<div class="name">
|
||||
<div onclick="renameArea({{ .ID }}, '{{ .Name }}')">{{ .Name }}</div>
|
||||
<img class="delete" src="/images/{{ $version }}/delete_white.svg" onclick="deleteArea({{ .ID }}, '{{ .Name }}')">
|
||||
</div>
|
||||
|
||||
<div style="margin: 8px 16px">
|
||||
<a href="#" onclick="newSection({{ .ID }})">Create</a>
|
||||
</div>
|
||||
{{ range .SortedSections }}
|
||||
{{ if eq .ID 0 }}
|
||||
{{ continue }}
|
||||
{{ end }}
|
||||
<div class="section configuration">
|
||||
<div class="name" onclick="renameSection({{ .ID }}, {{ .Name }})">{{ .Name }}</div>
|
||||
<img src="/images/{{ $version }}/delete.svg" onclick="deleteSection({{ .ID }}, '{{ .Name }}')">
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
@ -38,6 +38,9 @@
|
||||
<div class="area">
|
||||
<div class="name">{{ .Name }}</div>
|
||||
{{ range .SortedSections }}
|
||||
{{ if eq .ID 0 }}
|
||||
{{ continue }}
|
||||
{{ end }}
|
||||
<div class="section">
|
||||
<div class="create">
|
||||
<div class="name">{{ .Name }}</div>
|
||||
|
Loading…
Reference in New Issue
Block a user