Skip to content

Commit

Permalink
Add option to mark parents as gone upon creation
Browse files Browse the repository at this point in the history
  • Loading branch information
codesoap committed Aug 7, 2024
1 parent 6d9f77f commit 23d5bfa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/mycolog/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ func addCreatedComponents(r *http.Request, ct store.ComponentType) (int64, error
if err != nil {
return 0, err
}
if r.FormValue("parentsGone") == "true" {
if err = db.MarkComponentsAsGone(parents); err != nil {
return 0, err
}
}
component := store.Component{
Type: ct,
Species: species,
Expand Down
5 changes: 5 additions & 0 deletions cmd/mycolog/tmpl/add.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ <h1>Add created {{$typeName}}</h1>
<label for="amount">Amount (create multiple components at once)</label>
<input type="number" name="amount" class="pure-input-1" value="1"
autocomplete="off" onchange="registerChange()" min="1" max="10">
<label for="parentsGone" class="pure-checkbox">
<input id="parentsGone" name="parentsGone" type="checkbox" autocomplete="off"
value="true" onchange="registerChange()"{{if .Grow}} checked{{end}}>
Mark parents as gone
</label>
<a href="{{$abortLink}}" class="pure-button">Abort</a>
<button type="submit" class="pure-button pure-button-primary">
Add {{$typeName}}
Expand Down
16 changes: 16 additions & 0 deletions store/modifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ func (db DB) UpdateComponent(id int64, createdAt time.Time, notes string, gone b
return err
}

// MarkComponentsAsGone sets gone to "true" for the components with the
// given IDs.
func (db DB) MarkComponentsAsGone(ids []int64) error {
if len(ids) == 0 {
return nil
}
query := `UPDATE component SET gone = 1 ` +
`WHERE id IN (` + strings.Repeat("?, ", len(ids)-1) + `?)`
args := make([]any, len(ids))
for i := range ids {
args[i] = ids[i]
}
_, err := db.Exec(query, args...)
return err
}

// AttachGrowInfo adds or updates an entry to the grow table.
// yield is the total yield of a grow in milligrams.
func (db DB) AttachGrowInfo(compID int64, yield *int, yieldComment string) error {
Expand Down

0 comments on commit 23d5bfa

Please sign in to comment.