add search mechanism to API

This commit is contained in:
Xuan Sang LE 2018-03-03 13:44:52 +01:00
parent 685301e793
commit 35c068ede8
6 changed files with 88 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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) ->

View File

@ -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,9 +26,41 @@ 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) ->
($ @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

View File

@ -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;