mirror of
https://github.com/lxsang/antos-frontend.git
synced 2024-12-27 17:58:22 +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
|
||||
# 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
|
||||
@ -216,4 +230,3 @@ self.OS.API =
|
||||
err = e
|
||||
return "" if not err
|
||||
return err
|
||||
|
||||
|
@ -42,3 +42,17 @@
|
||||
DISCOVERY_DOCS: ["https://www.googleapis.com/discovery/v1/apis/drive/v3/rest"]
|
||||
SCOPES: 'https://www.googleapis.com/auth/drive'
|
||||
} 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)
|
||||
|
@ -9,8 +9,7 @@ class Calendar extends this.OS.GUI.BaseService
|
||||
me = @
|
||||
@watch 1000, () ->
|
||||
now = new Date
|
||||
me.text = "#{now.getDate()}/#{(now.getMonth()+1)}/#{now.getFullYear()} " +
|
||||
"#{now.getHours()}:#{now.getMinutes()}:#{now.getSeconds()}"
|
||||
me.text = now.toString()
|
||||
me.update()
|
||||
|
||||
awake: (e) ->
|
||||
|
@ -8,6 +8,7 @@ class SpotlightDialog extends this.OS.GUI.BaseDialog
|
||||
main: () ->
|
||||
me = @
|
||||
@height = ($ @scheme).css("height")
|
||||
@container = @find "container"
|
||||
($ @scheme).css("height", "45px")
|
||||
#fn = (e) ->
|
||||
# if e.keyCode is 27
|
||||
@ -25,10 +26,42 @@ class SpotlightDialog extends this.OS.GUI.BaseDialog
|
||||
($ @searchbox).focus()
|
||||
($ @searchbox).keyup (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) ->
|
||||
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
|
||||
|
||||
class Spotlight extends this.OS.GUI.BaseService
|
||||
|
@ -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"]{
|
||||
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{
|
||||
background-color: transparent;
|
||||
border-left: 1px solid #cacaca;
|
||||
|
Loading…
Reference in New Issue
Block a user