mirror of
https://github.com/lxsang/antos-frontend.git
synced 2025-07-21 00:09:45 +02:00
add search mechanism to API
This commit is contained in:
@ -42,8 +42,9 @@ self.OS.API =
|
||||
# the handler object could be a any remote or local handle to
|
||||
# fetch user data, used by the API to make requests
|
||||
# handlers are defined in /src/handlers
|
||||
handler: { }
|
||||
handler: {}
|
||||
shared: {} # shared libraries
|
||||
searchHandler:{}
|
||||
#request a user data
|
||||
mid: () ->
|
||||
return _courrier.getMID()
|
||||
@ -208,6 +209,19 @@ self.OS.API =
|
||||
command: "cache", args: { paths: _OS.setting.system.pkgpaths }
|
||||
}, 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) ->
|
||||
err = undefined
|
||||
try
|
||||
@ -215,5 +229,4 @@ self.OS.API =
|
||||
catch e
|
||||
err = e
|
||||
return "" if not err
|
||||
return err
|
||||
|
||||
return err
|
@ -41,4 +41,18 @@
|
||||
apilink: "https://apis.google.com/js/api.js"
|
||||
DISCOVERY_DOCS: ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"]
|
||||
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>
|
||||
<ul ref = "mlist">
|
||||
<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>
|
||||
<ul if = {item.complex} class = "complex-content">
|
||||
<li each = {ctn,j in item.detail} class = {ctn.class}>{ctn.text}</li>
|
||||
@ -50,6 +50,24 @@
|
||||
return self.items.length
|
||||
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.items.push(e)
|
||||
|
Reference in New Issue
Block a user