search a go
parent
9e73818af3
commit
3cbe7e629f
|
|
@ -325,7 +325,6 @@ func (server *Server) apiV0FilesIDPutHandler(w http.ResponseWriter, r *http.Requ
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) apiV0SearchHandler(w http.ResponseWriter, r *http.Request) error {
|
func (server *Server) apiV0SearchHandler(w http.ResponseWriter, r *http.Request) error {
|
||||||
// TODO case insensitive
|
|
||||||
query := r.URL.Query().Get("q")
|
query := r.URL.Query().Get("q")
|
||||||
queries := strings.Split(query, " ")
|
queries := strings.Split(query, " ")
|
||||||
if len(queries) == 0 {
|
if len(queries) == 0 {
|
||||||
|
|
@ -337,7 +336,7 @@ func (server *Server) apiV0SearchHandler(w http.ResponseWriter, r *http.Request)
|
||||||
for _, query := range queries {
|
for _, query := range queries {
|
||||||
if len(query) > 0 {
|
if len(query) > 0 {
|
||||||
query = unsafepattern.ReplaceAllString(query, ".")
|
query = unsafepattern.ReplaceAllString(query, ".")
|
||||||
patterns = append(patterns, regexp.MustCompile(query))
|
patterns = append(patterns, regexp.MustCompile("(?i)"+query))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(patterns) == 0 {
|
if len(patterns) == 0 {
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,12 @@
|
||||||
drawTree()
|
drawTree()
|
||||||
setInterval(drawTree, 100000)
|
setInterval(drawTree, 100000)
|
||||||
var queryF = getParameterByName("f")
|
var queryF = getParameterByName("f")
|
||||||
console.log("init query f:", queryF)
|
var queryQ = getParameterByName("q")
|
||||||
|
console.log("init query f:", queryF, "q:", queryQ)
|
||||||
if (queryF && queryF.length > 0) {
|
if (queryF && queryF.length > 0) {
|
||||||
drawFile(queryF)
|
drawFile(queryF)
|
||||||
|
} else if (queryQ && queryQ.length > 0) {
|
||||||
|
searchFilesFor(queryQ)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function getParameterByName(name, url = window.location.href) {
|
function getParameterByName(name, url = window.location.href) {
|
||||||
|
|
@ -70,6 +73,27 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function searchFiles() {
|
||||||
|
const q = document.getElementById("searchbox").value
|
||||||
|
searchFilesFor(q)
|
||||||
|
}
|
||||||
|
|
||||||
|
function searchFilesFor(q) {
|
||||||
|
http("GET", "/api/v0/search?q=" + q, (body, status) => {
|
||||||
|
var results = JSON.parse(body)
|
||||||
|
results.sort()
|
||||||
|
var innerHTML = "<ul>"
|
||||||
|
for (var result in results)
|
||||||
|
innerHTML += `<li><input type="button" onclick="drawFile('${results[result]}');" value="${results[result]}"</li>`
|
||||||
|
innerHTML += "</ul>"
|
||||||
|
if (!results || results.length == 0)
|
||||||
|
innerHTML = "no results"
|
||||||
|
disableMDE()
|
||||||
|
window.location.hash = "#?q="+q
|
||||||
|
document.getElementById("searchResults").innerHTML = innerHTML
|
||||||
|
})
|
||||||
|
}
|
||||||
var saveFeedbackInterval = null
|
var saveFeedbackInterval = null
|
||||||
function pushFile() {
|
function pushFile() {
|
||||||
const title = document.getElementById("title").innerHTML ? document.getElementById("title").innerHTML : ""
|
const title = document.getElementById("title").innerHTML ? document.getElementById("title").innerHTML : ""
|
||||||
|
|
@ -108,10 +132,12 @@
|
||||||
setMDE(pid + "/" + crypto.randomUUID().substr(0, 5), "", "")
|
setMDE(pid + "/" + crypto.randomUUID().substr(0, 5), "", "")
|
||||||
}
|
}
|
||||||
function enableMDE() {
|
function enableMDE() {
|
||||||
|
document.getElementById("searchResults").style.display = "none";
|
||||||
document.getElementById("article").style.display = "";
|
document.getElementById("article").style.display = "";
|
||||||
}
|
}
|
||||||
function disableMDE() {
|
function disableMDE() {
|
||||||
document.getElementById("article").style.display = "none";
|
document.getElementById("article").style.display = "none";
|
||||||
|
document.getElementById("searchResults").style.display = "";
|
||||||
}
|
}
|
||||||
function setMDE(id, title, body) {
|
function setMDE(id, title, body) {
|
||||||
if (id[0] == "/")
|
if (id[0] == "/")
|
||||||
|
|
@ -190,13 +216,16 @@
|
||||||
</header>
|
</header>
|
||||||
<body style="width: 90%; max-width: 1024px; margin: auto;" onload="init(); return false;">
|
<body style="width: 90%; max-width: 1024px; margin: auto;" onload="init(); return false;">
|
||||||
<div style="width: 100%; display: flex; flex-direction: column;">
|
<div style="width: 100%; display: flex; flex-direction: column;">
|
||||||
<div style="margin: 1em; display: flex; flex-direction: row;">
|
<form action="return false;" style="margin: 1em; display: flex; flex-direction: row;">
|
||||||
<input type="text" style="flex-grow: 1;" placeholder="todo"/>
|
<input type="text" id="searchbox" style="flex-grow: 1;" placeholder="todo"/>
|
||||||
<input type="submit" value="search"/>
|
<input type="submit" value="search" onclick="searchFiles(); return false;"/>
|
||||||
</div>
|
</form>
|
||||||
<div style="width: 100%; display: flex; flex-direction: row; flex-grow: 1;">
|
<div style="width: 100%; display: flex; flex-direction: row; flex-grow: 1;">
|
||||||
<div id="tree"></div>
|
<div id="tree"></div>
|
||||||
<article id="article" style="display: none; flex-grow: 1; margin-left: 1em;">
|
<div style="flex-grow: 1; margin-left: 1em;">
|
||||||
|
<article id="searchResults" style="display: none">
|
||||||
|
</article>
|
||||||
|
<article id="article" style="display: none">
|
||||||
<div>
|
<div>
|
||||||
<h1 style="display: flex; flex-direction: row;">
|
<h1 style="display: flex; flex-direction: row;">
|
||||||
<input type="submit" value="DELETE" onclick="deleteFile(); return false;" style="margin-left: 5%; margin-right: 5%"/>
|
<input type="submit" value="DELETE" onclick="deleteFile(); return false;" style="margin-left: 5%; margin-right: 5%"/>
|
||||||
|
|
@ -212,6 +241,7 @@
|
||||||
</article>
|
</article>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
<footer>
|
<footer>
|
||||||
<script>
|
<script>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue