Rearrange demo
Add contact autocompletion
This commit is contained in:
51
examples/widgetapp/googlenews/google_news.e
Normal file
51
examples/widgetapp/googlenews/google_news.e
Normal file
@@ -0,0 +1,51 @@
|
||||
note
|
||||
description: "Summary description for {GOOGLE_NEWS}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GOOGLE_NEWS
|
||||
|
||||
inherit
|
||||
|
||||
WSF_ENTITY
|
||||
|
||||
create
|
||||
make_from_json
|
||||
|
||||
feature {NONE}
|
||||
|
||||
make_from_json (json: JSON_OBJECT)
|
||||
do
|
||||
if attached {JSON_STRING} json.item (create {JSON_STRING}.make_json ("title")) as a_title then
|
||||
title := a_title.unescaped_string_32
|
||||
end
|
||||
if attached {JSON_STRING} json.item (create {JSON_STRING}.make_json ("content")) as a_content then
|
||||
content := a_content.unescaped_string_32
|
||||
end
|
||||
if attached {JSON_OBJECT} json.item (create {JSON_STRING}.make_json ("image")) as img and then attached {JSON_STRING} img.item (create {JSON_STRING}.make_json ("url")) as a_image then
|
||||
image := a_image.item
|
||||
end
|
||||
end
|
||||
|
||||
feature
|
||||
|
||||
title: detachable STRING
|
||||
|
||||
content: detachable STRING
|
||||
|
||||
image: detachable STRING
|
||||
|
||||
get (field: STRING): detachable ANY
|
||||
do
|
||||
if field.is_equal ("title") then
|
||||
Result := title
|
||||
elseif field.is_equal ("content") then
|
||||
Result := content
|
||||
elseif field.is_equal ("image") then
|
||||
Result := image
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
107
examples/widgetapp/googlenews/google_news_datasource.e
Normal file
107
examples/widgetapp/googlenews/google_news_datasource.e
Normal file
@@ -0,0 +1,107 @@
|
||||
note
|
||||
description: "Summary description for {GOOGLE_NEWS_DATASOURCE}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GOOGLE_NEWS_DATASOURCE
|
||||
|
||||
inherit
|
||||
|
||||
WSF_PAGABLE_DATASOURCE [GOOGLE_NEWS]
|
||||
redefine
|
||||
state,
|
||||
set_state
|
||||
end
|
||||
|
||||
create
|
||||
make_news
|
||||
|
||||
feature --States
|
||||
|
||||
state: JSON_OBJECT
|
||||
-- Return state which contains the current html and if there is an event handle attached
|
||||
do
|
||||
Result := Precursor
|
||||
Result.put (create {JSON_STRING}.make_json (query), create {JSON_STRING}.make_json ("query"))
|
||||
end
|
||||
|
||||
set_state (new_state: JSON_OBJECT)
|
||||
do
|
||||
Precursor (new_state)
|
||||
if attached {JSON_STRING} new_state.item (create {JSON_STRING}.make_json ("query")) as new_query then
|
||||
query := new_query.item
|
||||
end
|
||||
end
|
||||
|
||||
feature
|
||||
|
||||
make_news
|
||||
do
|
||||
page := 1
|
||||
page_size := 8
|
||||
query := "eiffel"
|
||||
end
|
||||
|
||||
data: ITERABLE [GOOGLE_NEWS]
|
||||
local
|
||||
list: LINKED_LIST [GOOGLE_NEWS]
|
||||
l_result: INTEGER
|
||||
l_curl_string: CURL_STRING
|
||||
json_parser: JSON_PARSER
|
||||
query_str: STRING
|
||||
do
|
||||
curl_handle := curl_easy.init
|
||||
create list.make
|
||||
row_count := 0
|
||||
if curl_handle /= default_pointer then
|
||||
create l_curl_string.make_empty
|
||||
query_str := query.out
|
||||
query_str.replace_substring_all (" ", "+")
|
||||
curl_easy.setopt_string (curl_handle, {CURL_OPT_CONSTANTS}.curlopt_url, "https://ajax.googleapis.com/ajax/services/search/news?v=1.0&q=" + query_str + "&rsz=" + page_size.out + "&start=" + (page_size * (page - 1)).out)
|
||||
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_OBJECT} json_parser.parse_json as sp then
|
||||
if attached {JSON_OBJECT} sp.item (create {JSON_STRING}.make_json ("responseData")) as responsedata and then attached {JSON_ARRAY} responsedata.item (create {JSON_STRING}.make_json ("results")) as results then
|
||||
if attached {JSON_OBJECT} responsedata.item (create {JSON_STRING}.make_json ("cursor")) as cursor and then attached {JSON_STRING} cursor.item (create {JSON_STRING}.make_json ("estimatedResultCount")) as count then
|
||||
row_count := count.item.to_integer.min (64)
|
||||
end
|
||||
across
|
||||
1 |..| results.count as c
|
||||
loop
|
||||
if attached {JSON_OBJECT} results.i_th (c.item) as j then
|
||||
list.extend (create {GOOGLE_NEWS}.make_from_json (j))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Result := list
|
||||
end
|
||||
|
||||
feature
|
||||
|
||||
set_query (q: STRING)
|
||||
do
|
||||
query := q
|
||||
end
|
||||
|
||||
query: STRING
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
curl_easy: CURL_EASY_EXTERNALS
|
||||
once
|
||||
create Result
|
||||
end
|
||||
|
||||
curl_handle: POINTER;
|
||||
-- cURL handle
|
||||
|
||||
end
|
||||
38
examples/widgetapp/googlenews/google_news_repeater.e
Normal file
38
examples/widgetapp/googlenews/google_news_repeater.e
Normal file
@@ -0,0 +1,38 @@
|
||||
note
|
||||
description: "Summary description for {GOOGLE_NEWS_REPEATER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
GOOGLE_NEWS_REPEATER
|
||||
|
||||
inherit
|
||||
|
||||
WSF_REPEATER_CONTROL [GOOGLE_NEWS]
|
||||
|
||||
create
|
||||
make_repeater
|
||||
|
||||
feature
|
||||
|
||||
render_item (item: GOOGLE_NEWS): STRING
|
||||
local
|
||||
body: STRING
|
||||
do
|
||||
Result := ""
|
||||
if attached item.image as image then
|
||||
Result.append (render_tag_with_tagname ("a", render_tag_with_tagname ("img", "", "style=%"max-width: 200px;%" src=%"" + image + "%"", "media-object"), "href=%"#%"", "pull-left"))
|
||||
end
|
||||
body := ""
|
||||
if attached item.title as title then
|
||||
body.append (render_tag_with_tagname ("h4", title, "", "media-heading"))
|
||||
end
|
||||
if attached item.content as content then
|
||||
body.append (content)
|
||||
end
|
||||
Result.append (render_tag_with_tagname ("div", body, "", "media-body"))
|
||||
Result := render_tag_with_tagname ("div", Result, "", "media") + "<hr />"
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user