Search working

Former-commit-id: 968264159ae078bee3ad9be3d5996b7760d28378 [formerly 7f1c96ac435ca9e8c53568c833acefd88e25c1b8] [formerly 2cfc462e4bea9110429add93121e12479c39d0e6 [formerly da3f043cfd]]
Former-commit-id: 1074083560c0f7d451011617d39350b754516dfa [formerly 0edd1dc392bb57295d47219da9c1acc7eead4761]
Former-commit-id: a651c40fd4a4892c9dd2f72cbe6653b53809be38
pull/726/head
Henrique Dias 2017-07-03 18:07:14 +01:00
parent 009916d954
commit 869cd562e7
2 changed files with 52 additions and 35 deletions

View File

@ -13,7 +13,7 @@
<div> <div>
<span v-if="search.length === 0 && commands.length === 0">{{ text() }}</span> <span v-if="search.length === 0 && commands.length === 0">{{ text() }}</span>
<ul v-else-if="search.length > 0"> <ul v-else-if="search.length > 0">
<li v-for="s in search"><a :href="'./' + s">./{{ s }}</a></li> <li v-for="s in search"><router-link :to="'./' + s">./{{ s }}</router-link></li>
</ul> </ul>
<ul v-else-if="commands.length > 0"> <ul v-else-if="commands.length > 0">
<li v-for="c in commands">{{ c }}</li> <li v-for="c in commands">{{ c }}</li>
@ -27,6 +27,7 @@
<script> <script>
import { mapState } from 'vuex' import { mapState } from 'vuex'
import url from '@/utils/url' import url from '@/utils/url'
import api from '@/utils/api'
export default { export default {
name: 'search', name: 'search',
@ -89,49 +90,41 @@ export default {
}, },
submit: function (event) { submit: function (event) {
this.ongoing = true this.ongoing = true
let uri = window.location.host + window.location.pathname
let path = this.$route.path
if (this.$store.state.req.kind !== 'listing') { if (this.$store.state.req.kind !== 'listing') {
uri = url.removeLastDir(uri) + '/' path = url.removeLastDir(path) + '/'
} }
uri = `${(this.$store.state.ssl ? 'wss:' : 'ws:')}//${uri}`
if (this.supported() && this.user.allowCommands) { if (this.supported() && this.user.allowCommands) {
let conn = new window.WebSocket(`${uri}?command=true`) api.command(path, this.value,
(event) => {
conn.onopen = () => conn.send(this.value)
conn.onmessage = (event) => {
this.commands.push(event.data) this.commands.push(event.data)
this.scrollable.scrollTop = this.scrollable.scrollHeight this.scrollable.scrollTop = this.scrollable.scrollHeight
} },
(event) => {
conn.onclose = (event) => {
this.ongoing = false this.ongoing = false
this.scrollable.scrollTop = this.scrollable.scrollHeight this.scrollable.scrollTop = this.scrollable.scrollHeight
this.$store.commit('setReload', true) this.$store.commit('setReload', true)
} }
)
return return
} }
let conn = new window.WebSocket(`${uri}?search=true`) api.search(path, this.value,
(event) => {
conn.onopen = () => conn.send(this.value)
conn.onmessage = (event) => {
let url = event.data let url = event.data
if (url[0] === '/') url = url.substring(1) if (url[0] === '/') url = url.substring(1)
this.search.push(url) this.search.push(url)
this.scrollable.scrollTop = this.scrollable.scrollHeight this.scrollable.scrollTop = this.scrollable.scrollHeight
} },
(event) => {
conn.onclose = () => {
this.ongoing = false this.ongoing = false
this.scrollable.scrollTop = this.scrollable.scrollHeight this.scrollable.scrollTop = this.scrollable.scrollHeight
} }
)
} }
} }
} }

View File

@ -119,10 +119,34 @@ function checksum (url, algo) {
}) })
} }
function command (url, command, onmessage, onclose) {
let protocol = (store.state.ssl ? 'wss:' : 'ws:')
url = removePrefix(url)
url = `${protocol}//${window.location.hostname}${store.state.baseURL}/api/command${url}?token=${store.state.jwt}`
let conn = new window.WebSocket(url)
conn.onopen = () => conn.send(command)
conn.onmessage = onmessage
conn.onclose = onclose
}
function search (url, search, onmessage, onclose) {
let protocol = (store.state.ssl ? 'wss:' : 'ws:')
url = removePrefix(url)
url = `${protocol}//${window.location.hostname}${store.state.baseURL}/api/search${url}?token=${store.state.jwt}`
let conn = new window.WebSocket(url)
conn.onopen = () => conn.send(search)
conn.onmessage = onmessage
conn.onclose = onclose
}
export default { export default {
delete: rm, delete: rm,
fetch, fetch,
checksum, checksum,
move, move,
put put,
command,
search
} }