Rearrange demo

Add contact autocompletion
This commit is contained in:
YNH Webdev
2013-09-15 15:25:13 +02:00
parent 251974fd2f
commit 647beea245
10 changed files with 100 additions and 116 deletions

View File

@@ -0,0 +1,50 @@
note
description: "Summary description for {CONTACT_AUTOCOMPLETION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
CONTACT_AUTOCOMPLETION
inherit
WSF_AUTOCOMPLETION
create
make
feature {NONE} -- Initialization
make ()
do
template := "<div class=%"clearfix%" style=%"min-width:250px%"><img src=%"http://api.randomuser.me/0.2/portraits/{{=img}}.jpg%" style=%"max-width:50px;margin-right:10px%" class=%"img-circle pull-left%"> <b>{{=value}}</b><br /><small>{{=company}}</small></div>";
list := <<["Zelma Hays","Applideck","women/13"],["Little Dixon","Centregy","men/20"],["Marta Fuentes","Papricut","women/11"],["Aileen Dillon","Neteria","women/9"],["Noel Melendez","Corporana","men/19"],["Gutierrez Francis","Capscreen","men/3"],["Valerie Weiss","Zizzle","women/9"],["Mabel Hammond","Pyramax","women/19"],["Mckay Logan","Providco","men/17"],["Hazel Colon","Translink","women/14"],["Margery Whitney","Tropoli","women/21"],["Saundra Neal","Geekmosis","women/20"],["Meghan Pittman","Micronaut","women/16"],["Adrienne Woodward","Mixers","women/8"],["Harriett Macdonald","Anarco","women/4"],["Velasquez Curtis","Zensus","men/4"],["Victoria Greene","Zorromop","women/10"],["Hood Barron","Kangle","men/2"],["Mccullough Cross","Kindaloo","men/15"],["Porter Hart","Kongle","men/15"],["Fox Bryant","Columella","men/17"],["Singleton Knapp","Marketoid","men/10"],["Gracie Lane","Solgan","women/15"],["Randall Cobb","Barkarama","men/7"],["Miranda Brooks","Earwax","men/1"],["Teresa Taylor","Stockpost","women/6"]>>
end
feature -- Implementation
autocompletion (input: STRING): JSON_ARRAY
local
o: JSON_OBJECT
do
create Result.make_array
across
list as c
loop
if attached {STRING} c.item.item (1) as value and attached {STRING} c.item.item (3) as img and attached {STRING} c.item.item (2) as company then
if value.as_lower.has_substring (input.as_lower) then
create o.make
o.put (create {JSON_STRING}.make_json (img), "img")
o.put (create {JSON_STRING}.make_json (value), "value")
o.put (create {JSON_STRING}.make_json (company), "company")
Result.add (o)
end
end
end
end
list: ITERABLE [TUPLE [STRING, STRING]]
end

View File

@@ -0,0 +1,48 @@
note
description: "Summary description for {FLAG_AUTOCOMPLETION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
FLAG_AUTOCOMPLETION
inherit
WSF_AUTOCOMPLETION
create
make
feature {NONE} -- Initialization
make (l: ITERABLE [TUPLE [STRING, STRING]])
do
template := "<img src=%"http://www.famfamfam.com/lab/icons/flags/icons/gif/{{=flag}}.gif%"> {{=value}}";
list := l
end
feature -- Implementation
autocompletion (input: STRING): JSON_ARRAY
local
o: JSON_OBJECT
do
create Result.make_array
across
list as c
loop
if attached {STRING} c.item.item (1) as first and attached {STRING} c.item.item (2) as second then
if second.as_lower.has_substring (input.as_lower) then
create o.make
o.put (create {JSON_STRING}.make_json (first), "flag")
o.put (create {JSON_STRING}.make_json (second), "value")
Result.add (o)
end
end
end
end
list: ITERABLE [TUPLE [STRING, STRING]]
end

View File

@@ -0,0 +1,72 @@
note
description: "Summary description for {GOOGLE_AUTOCOMPLETION}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
GOOGLE_AUTOCOMPLETION
inherit
WSF_AUTOCOMPLETION
create
make
feature {NONE} -- Initialization
make ()
do
template := "{{=value}}";
end
feature -- Implementation
autocompletion (input: STRING): JSON_ARRAY
local
o: JSON_OBJECT
l_result: INTEGER
l_curl_string: CURL_STRING
json_parser: JSON_PARSER
query_str: STRING
do
query_str := input
query_str.replace_substring_all (" ", "+")
curl_handle := curl_easy.init
create Result.make_array
if curl_handle /= default_pointer then
create l_curl_string.make_empty
curl_easy.setopt_string (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_url, "http://google.com/complete/search?client=chrome&q=" + query_str)
curl_easy.set_write_function (curl_handle)
curl_easy.setopt_integer (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_writedata, l_curl_string.object_id)
l_result := curl_easy.perform (curl_handle)
-- Always cleanup
curl_easy.cleanup (curl_handle)
create json_parser.make_parser (l_curl_string.out)
if attached {JSON_ARRAY} json_parser.parse_json as data and then attached {JSON_ARRAY} data.i_th (2) as list then
across
1 |..| list.count as c
loop
if attached {JSON_STRING} list.i_th (c.item) as row then
create o.make
o.put (create {JSON_STRING}.make_json (row.unescaped_string_32), "value")
Result.add (o)
end
end
end
end
end
feature {NONE} -- Implementation
curl_easy: CURL_EASY_EXTERNALS
once
create Result
end
curl_handle: POINTER;
-- cURL handle
end