diff --git a/main.go b/main.go
index bdab704..bf38b3f 100644
--- a/main.go
+++ b/main.go
@@ -76,6 +76,7 @@ func main() {// {{{
http.HandleFunc("/node/delete", nodeDelete)
http.HandleFunc("/node/upload", nodeUpload)
http.HandleFunc("/node/download", nodeDownload)
+ http.HandleFunc("/node/search", nodeSearch)
http.HandleFunc("/key/retrieve", keyRetrieve)
http.HandleFunc("/key/create", keyCreate)
http.HandleFunc("/key/counter", keyCounter)
@@ -549,6 +550,36 @@ func nodeFiles(w http.ResponseWriter, r *http.Request) {// {{{
"Files": files,
})
}// }}}
+func nodeSearch(w http.ResponseWriter, r *http.Request) {// {{{
+ log.Println("/node/search")
+ var err error
+ var session Session
+ var nodes []Node
+
+ if session, _, err = ValidateSession(r, true); err != nil {
+ responseError(w, err)
+ return
+ }
+
+ req := struct {
+ Search string
+ }{}
+ if err = parseRequest(r, &req); err != nil {
+ responseError(w, err)
+ return
+ }
+
+ nodes, err = session.SearchNodes(req.Search)
+ if err != nil {
+ responseError(w, err)
+ return
+ }
+
+ responseData(w, map[string]interface{}{
+ "OK": true,
+ "Nodes": nodes,
+ })
+}// }}}
func keyRetrieve(w http.ResponseWriter, r *http.Request) {// {{{
log.Println("/key/retrieve")
diff --git a/node.go b/node.go
index 50302df..0881dda 100644
--- a/node.go
+++ b/node.go
@@ -373,5 +373,38 @@ func (session Session) DeleteNode(nodeID int) (err error) {// {{{
)
return
}// }}}
+func (session Session) SearchNodes(search string) (nodes []Node, err error) {// {{{
+ nodes = []Node{}
+ var rows *sqlx.Rows
+ rows, err = db.Queryx(`
+ SELECT
+ id,
+ user_id,
+ COALESCE(parent_id, 0) AS parent_id,
+ name,
+ updated
+ FROM node
+ WHERE
+ crypto_key_id IS NULL AND
+ content ~* $1
+ ORDER BY
+ updated DESC
+ `, search)
+ if err != nil {
+ return
+ }
+ defer rows.Close()
+
+ for rows.Next() {
+ node := Node{}
+ node.Complete = false
+ if err = rows.StructScan(&node); err != nil {
+ return
+ }
+ nodes = append(nodes, node)
+ }
+
+ return
+}// }}}
// vim: foldmethod=marker
diff --git a/static/css/search.css b/static/css/search.css
new file mode 100644
index 0000000..ddec298
--- /dev/null
+++ b/static/css/search.css
@@ -0,0 +1,29 @@
+/*
+@theme_gradient: linear-gradient(to right, #009fff, #ec2f4b);
+@theme_gradient: linear-gradient(to right, #f5af19, #f12711);
+@theme_gradient: linear-gradient(to right, #fdc830, #f37335);
+@theme_gradient: linear-gradient(to right, #8a2387, #e94057, #f27121);
+@theme_gradient: linear-gradient(to right, #659999, #f4791f);
+*/
+#search {
+ padding: 16px;
+ color: #333;
+}
+#search h2 {
+ margin-bottom: 8px;
+}
+#search input[type=text] {
+ font-size: 1em;
+}
+#search button {
+ display: block;
+ margin-top: 8px;
+}
+#search .matches .matched-node {
+ cursor: pointer;
+ margin-top: 6px;
+}
+#search .matches .matched-node:before {
+ content: "•";
+ margin-right: 6px;
+}
diff --git a/static/index.html b/static/index.html
index 979ac37..cead4f0 100644
--- a/static/index.html
+++ b/static/index.html
@@ -5,6 +5,7 @@
+