Moveing of objects
This commit is contained in:
parent
cfd5bfd719
commit
25bbc0c748
7 changed files with 167 additions and 16 deletions
25
node.go
25
node.go
|
|
@ -9,6 +9,9 @@ import (
|
|||
// Standard
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -120,7 +123,7 @@ func GetNodeRows(startNodeID, maxDepth int) (rows *sqlx.Rows, err error) { // {{
|
|||
SELECT
|
||||
COALESCE(n.parent_id, -1) AS parent_id,
|
||||
n.id,
|
||||
CONCAT(REPEAT(' ', ns.depth), n.name) AS name,
|
||||
n.name,
|
||||
n.type_id,
|
||||
t.name AS type_name,
|
||||
COALESCE(t.schema->>'icon', '') AS type_icon,
|
||||
|
|
@ -208,5 +211,25 @@ func DeleteNode(nodeID int) (err error) { // {{{
|
|||
}
|
||||
return
|
||||
} // }}}
|
||||
func MoveNodes(newParentID int, nodeIDs []int) (err error) {
|
||||
// TODO - implement a method to verify that a node isn't moved underneath itself.
|
||||
// Preferably using a stored procedure?
|
||||
|
||||
var nodeIDStr []string
|
||||
for _, n := range nodeIDs {
|
||||
nodeIDStr = append(nodeIDStr, strconv.Itoa(n))
|
||||
}
|
||||
|
||||
joinedIDs := strings.Join(nodeIDStr, ",")
|
||||
sql := fmt.Sprintf(
|
||||
`UPDATE node
|
||||
SET parent_id=$1
|
||||
WHERE id IN (%s)`,
|
||||
joinedIDs,
|
||||
)
|
||||
|
||||
_, err = db.Exec(sql, newParentID)
|
||||
return
|
||||
}
|
||||
|
||||
// vim: foldmethod=marker
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue