mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-12-28 10:18:21 +01:00
add search mechanism to API
This commit is contained in:
parent
685301e793
commit
35c068ede8
@ -42,8 +42,9 @@ self.OS.API =
|
|||||||
# the handler object could be a any remote or local handle to
|
# the handler object could be a any remote or local handle to
|
||||||
# fetch user data, used by the API to make requests
|
# fetch user data, used by the API to make requests
|
||||||
# handlers are defined in /src/handlers
|
# handlers are defined in /src/handlers
|
||||||
handler: { }
|
handler: {}
|
||||||
shared: {} # shared libraries
|
shared: {} # shared libraries
|
||||||
|
searchHandler:{}
|
||||||
#request a user data
|
#request a user data
|
||||||
mid: () ->
|
mid: () ->
|
||||||
return _courrier.getMID()
|
return _courrier.getMID()
|
||||||
@ -208,6 +209,19 @@ self.OS.API =
|
|||||||
command: "cache", args: { paths: _OS.setting.system.pkgpaths }
|
command: "cache", args: { paths: _OS.setting.system.pkgpaths }
|
||||||
}, f
|
}, f
|
||||||
|
|
||||||
|
search: (text) ->
|
||||||
|
r = []
|
||||||
|
|
||||||
|
for k, v of _API.searchHandler
|
||||||
|
ret = _API.searchHandler[k](text)
|
||||||
|
if ret.length > 0
|
||||||
|
ret.unshift { text: k, class: "search-header", dataid: "header" }
|
||||||
|
r = r.concat ret
|
||||||
|
return r
|
||||||
|
|
||||||
|
onsearch: (name, fn) ->
|
||||||
|
_API.searchHandler[name] = fn unless _API.searchHandler[name]
|
||||||
|
|
||||||
throwe: (n) ->
|
throwe: (n) ->
|
||||||
err = undefined
|
err = undefined
|
||||||
try
|
try
|
||||||
@ -216,4 +230,3 @@ self.OS.API =
|
|||||||
err = e
|
err = e
|
||||||
return "" if not err
|
return "" if not err
|
||||||
return err
|
return err
|
||||||
|
|
||||||
|
@ -42,3 +42,17 @@
|
|||||||
DISCOVERY_DOCS: ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"]
|
DISCOVERY_DOCS: ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"]
|
||||||
SCOPES: 'https://www.googleapis.com/auth/drive'
|
SCOPES: 'https://www.googleapis.com/auth/drive'
|
||||||
} unless _OS.setting.VFS.gdrive
|
} unless _OS.setting.VFS.gdrive
|
||||||
|
|
||||||
|
#search for app
|
||||||
|
_API.onsearch "Applications", (t) ->
|
||||||
|
ar = []
|
||||||
|
term = new RegExp t, "i"
|
||||||
|
for k, v of _OS.setting.system.packages when v.app
|
||||||
|
if (v.name.match term) or (v.description and v.description.match term)
|
||||||
|
ar.push v
|
||||||
|
else if v.mimes
|
||||||
|
for m in v.mimes
|
||||||
|
if t.match (new RegExp m, "g")
|
||||||
|
ar.push v
|
||||||
|
break
|
||||||
|
return ar
|
@ -4,7 +4,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<ul ref = "mlist">
|
<ul ref = "mlist">
|
||||||
<li each={item,i in items } class={selected: parent._autoselect(item,i)} ondblclick = {parent._dbclick} onclick = {parent._select} oncontextmenu = {parent._select}>
|
<li each={item,i in items } class={selected: parent._autoselect(item,i)} ondblclick = {parent._dbclick} onclick = {parent._select} oncontextmenu = {parent._select}>
|
||||||
<afx-label color = {item.color} iconclass = {item.iconclass} icon = {item.icon} text = {item.text}></afx-label>
|
<afx-label class = {item.class} color = {item.color} iconclass = {item.iconclass} icon = {item.icon} text = {item.text}></afx-label>
|
||||||
<i if = {item.closable} class = "closable" click = {parent._remove}></i>
|
<i if = {item.closable} class = "closable" click = {parent._remove}></i>
|
||||||
<ul if = {item.complex} class = "complex-content">
|
<ul if = {item.complex} class = "complex-content">
|
||||||
<li each = {ctn,j in item.detail} class = {ctn.class}>{ctn.text}</li>
|
<li each = {ctn,j in item.detail} class = {ctn.class}>{ctn.text}</li>
|
||||||
@ -50,6 +50,24 @@
|
|||||||
return self.items.length
|
return self.items.length
|
||||||
return self[k]
|
return self[k]
|
||||||
}
|
}
|
||||||
|
self.root.selectNext = function()
|
||||||
|
{
|
||||||
|
var idx = self.selidx + 1
|
||||||
|
if(idx >= self.items.length) return;
|
||||||
|
if(self.selidx != -1)
|
||||||
|
self.items[self.selidx].selected =false
|
||||||
|
self.items[idx].selected =true
|
||||||
|
self.update()
|
||||||
|
}
|
||||||
|
self.root.selectPrev = function()
|
||||||
|
{
|
||||||
|
var idx = self.selidx - 1
|
||||||
|
if(idx < 0) return;
|
||||||
|
if(self.selidx != -1)
|
||||||
|
self.items[self.selidx].selected =false
|
||||||
|
self.items[idx].selected =true
|
||||||
|
self.update()
|
||||||
|
}
|
||||||
self.root.push = function(e,u)
|
self.root.push = function(e,u)
|
||||||
{
|
{
|
||||||
self.items.push(e)
|
self.items.push(e)
|
||||||
|
@ -9,8 +9,7 @@ class Calendar extends this.OS.GUI.BaseService
|
|||||||
me = @
|
me = @
|
||||||
@watch 1000, () ->
|
@watch 1000, () ->
|
||||||
now = new Date
|
now = new Date
|
||||||
me.text = "#{now.getDate()}/#{(now.getMonth()+1)}/#{now.getFullYear()} " +
|
me.text = now.toString()
|
||||||
"#{now.getHours()}:#{now.getMinutes()}:#{now.getSeconds()}"
|
|
||||||
me.update()
|
me.update()
|
||||||
|
|
||||||
awake: (e) ->
|
awake: (e) ->
|
||||||
|
@ -8,6 +8,7 @@ class SpotlightDialog extends this.OS.GUI.BaseDialog
|
|||||||
main: () ->
|
main: () ->
|
||||||
me = @
|
me = @
|
||||||
@height = ($ @scheme).css("height")
|
@height = ($ @scheme).css("height")
|
||||||
|
@container = @find "container"
|
||||||
($ @scheme).css("height", "45px")
|
($ @scheme).css("height", "45px")
|
||||||
#fn = (e) ->
|
#fn = (e) ->
|
||||||
# if e.keyCode is 27
|
# if e.keyCode is 27
|
||||||
@ -25,9 +26,41 @@ class SpotlightDialog extends this.OS.GUI.BaseDialog
|
|||||||
($ @searchbox).focus()
|
($ @searchbox).focus()
|
||||||
($ @searchbox).keyup (e) ->
|
($ @searchbox).keyup (e) ->
|
||||||
me.search e
|
me.search e
|
||||||
|
@container.set "onlistdbclick", (e)->
|
||||||
|
return if e.data.dataid and e.data.dataid is "header"
|
||||||
|
me._gui.openWith e.data
|
||||||
|
me.handler(e) if me.handler
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
search: (e) ->
|
search: (e) ->
|
||||||
($ @scheme).css("height", @height)
|
switch e.which
|
||||||
|
when 37
|
||||||
|
e.preventDefault()
|
||||||
|
when 38
|
||||||
|
@container.selectPrev()
|
||||||
|
e.preventDefault()
|
||||||
|
when 39
|
||||||
|
e.preventDefault()
|
||||||
|
when 40
|
||||||
|
@container.selectNext()
|
||||||
|
e.preventDefault()
|
||||||
|
when 13
|
||||||
|
e.preventDefault()
|
||||||
|
sel = @container.get "selected"
|
||||||
|
return unless sel
|
||||||
|
return if sel.dataid and sel.dataid is "header"
|
||||||
|
@._gui.openWith sel
|
||||||
|
@.handler(e) if @.handler
|
||||||
|
else
|
||||||
|
text = @searchbox.value
|
||||||
|
($ @scheme).css("height", "45px")
|
||||||
|
return unless text.length > 3
|
||||||
|
result = @_api.search text
|
||||||
|
return if result.length is 0
|
||||||
|
@container.set "items", result
|
||||||
|
($ @scheme).css("height", @height)
|
||||||
|
|
||||||
|
|
||||||
this.OS.register "SpotlightDialog", SpotlightDialog
|
this.OS.register "SpotlightDialog", SpotlightDialog
|
||||||
|
|
||||||
|
@ -85,7 +85,9 @@ afx-app-window[data-id = "spotlight-win"] .afx-window-content{
|
|||||||
afx-app-window[data-id = "spotlight-win"] afx-list-view[data-id="container"]{
|
afx-app-window[data-id = "spotlight-win"] afx-list-view[data-id="container"]{
|
||||||
border-top:1px solid #cacaca;
|
border-top:1px solid #cacaca;
|
||||||
}
|
}
|
||||||
|
afx-app-window[data-id = "spotlight-win"] afx-list-view[data-id="container"] afx-label.search-header{
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
afx-app-window[data-id = "spotlight-win"] afx-resizer{
|
afx-app-window[data-id = "spotlight-win"] afx-resizer{
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
border-left: 1px solid #cacaca;
|
border-left: 1px solid #cacaca;
|
||||||
|
Loading…
Reference in New Issue
Block a user