-
Notifications
You must be signed in to change notification settings - Fork 2
CJ Browser update #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,10 +43,12 @@ feature -- Change | |
v: EV_VERTICAL_BOX | ||
hb: EV_HORIZONTAL_BOX | ||
lab: EV_LABEL | ||
tf: EV_TEXT_FIELD | ||
-- tf: EV_TEXT_FIELD | ||
tf: EV_TEXT | ||
tf_passwd: EV_PASSWORD_FIELD | ||
but: EV_BUTTON | ||
table: HASH_TABLE [EV_TEXT_FIELD, STRING_32] | ||
but_delete: detachable EV_BUTTON | ||
table: HASH_TABLE [EV_TEXT_COMPONENT, STRING_32] | ||
is_creation: BOOLEAN | ||
is_password: BOOLEAN | ||
do | ||
|
@@ -110,15 +112,23 @@ feature -- Change | |
else | ||
create but.make_with_text ("Update") | ||
but.select_actions.extend (agent on_post (coll, tpl, table, False)) | ||
create but_delete.make_with_text ("Delete") | ||
but_delete.select_actions.extend (agent on_delete (coll, tpl, table)) | ||
|
||
end | ||
|
||
v.extend (create {EV_CELL}) | ||
v.extend (but) | ||
if but_delete /= Void then | ||
v.extend (but_delete) | ||
v.disable_item_expand (but_delete) | ||
|
||
end | ||
v.disable_item_expand (but) | ||
-- FIXME | ||
end | ||
|
||
on_post (coll: CJ_COLLECTION; tpl: CJ_TEMPLATE; table: HASH_TABLE [EV_TEXT_FIELD, STRING_32]; is_creation: BOOLEAN) | ||
on_post (coll: CJ_COLLECTION; tpl: CJ_TEMPLATE; table: HASH_TABLE [EV_TEXT_COMPONENT, STRING_32]; is_creation: BOOLEAN) | ||
local | ||
ctx: HTTP_CLIENT_REQUEST_CONTEXT | ||
l_href: STRING_8 | ||
|
@@ -147,6 +157,33 @@ feature -- Change | |
-- dlg.focus_out_actions.extend (agent dlg.destroy_and_exit_if_last) | ||
end | ||
|
||
on_delete (coll: CJ_COLLECTION; tpl: CJ_TEMPLATE; table: HASH_TABLE [EV_TEXT_COMPONENT, STRING_32]) | ||
local | ||
ctx: HTTP_CLIENT_REQUEST_CONTEXT | ||
l_href: STRING_8 | ||
dlg: EV_INFORMATION_DIALOG | ||
resp: CJ_CLIENT_RESPONSE | ||
do | ||
create ctx.make | ||
across | ||
tpl.data as c | ||
loop | ||
if attached table.item (c.item.name) as tf then | ||
c.item.set_value (tf.text) | ||
end | ||
end | ||
if attached coll.items as l_items and then attached l_items.first as first_item then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a comment, usually when we call .first ... we should first check that the list is not empty, otherwise the precondition is violated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code is now fixed in the new branch, not yet pushed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, you can push right away, no need to go via pull request for this one. On Wed, Apr 9, 2014 at 4:12 PM, jvelilla notifications@github.com wrote:
|
||
l_href := first_item.href | ||
resp := cj_client.delete(l_href, Void ) | ||
else | ||
l_href := coll.href | ||
resp := cj_client.delete (l_href, Void) | ||
end | ||
create dlg.make_with_text ("Result") | ||
dlg.set_text (resp.http_response) | ||
dlg.show | ||
end | ||
|
||
invariant | ||
widget_attached: widget /= Void | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ feature {NONE} -- Initialization | |
-- Initialize `Current'. | ||
do | ||
create {LIBCURL_HTTP_CLIENT_SESSION} client.make (a_service) --"http://jfiat.dyndns.org:8190") | ||
client.set_timeout (25) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should have a preference/config file for that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree |
||
end | ||
|
||
feature -- Access | ||
|
@@ -71,6 +72,7 @@ feature -- Access | |
if l_ctx = Void then | ||
create l_ctx.make | ||
end | ||
l_ctx.add_header ("Accept", "application/vnd.collection+json") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it make sense to specialize the "vnd.collection+json.my_version" for a specific api There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe,but I'm not sure. |
||
l_ctx.add_header ("Content-Type", "application/vnd.collection+json") | ||
|
||
if attached cj_template_to_json (tpl) as j then | ||
|
@@ -112,6 +114,8 @@ feature -- Access | |
create l_ctx.make | ||
end | ||
l_ctx.add_header ("Content-Type", "application/vnd.collection+json") | ||
l_ctx.add_header ("Accept", "application/vnd.collection+json") | ||
|
||
|
||
if attached cj_template_to_json (tpl) as j then | ||
d := "{ %"template%": " + j.representation + " }" | ||
|
@@ -151,6 +155,8 @@ feature -- Access | |
create l_ctx.make | ||
end | ||
l_ctx.add_header ("Content-Type", "application/vnd.collection+json") | ||
l_ctx.add_header ("Accept", "application/vnd.collection+json") | ||
|
||
|
||
if attached q.data as q_data then | ||
across | ||
|
@@ -185,6 +191,41 @@ feature -- Access | |
end | ||
|
||
|
||
delete (a_path: READABLE_STRING_GENERAL; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): CJ_CLIENT_RESPONSE | ||
local | ||
l_http_response: STRING_8 | ||
j_body: like json | ||
l_formatted_body: detachable STRING_8 | ||
col: detachable CJ_COLLECTION | ||
l_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT | ||
l_url: STRING_8 | ||
do | ||
create l_http_response.make_empty | ||
l_ctx := ctx | ||
if l_ctx = Void then | ||
create l_ctx.make | ||
end | ||
l_ctx.add_header ("Accept", "application/vnd.collection+json") | ||
l_url := a_path.to_string_8 | ||
if attached client.delete (l_url, l_ctx) as g_response then | ||
l_url := g_response.url | ||
l_http_response.append ("Status: " + g_response.status.out + "%N") | ||
l_http_response.append (g_response.raw_header) | ||
if attached g_response.body as l_body then | ||
l_http_response.append ("%N%N") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are we also building the response manually for the other? and so on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we are doing it by hand, so I think it's a good idea to move this responsability into a new class |
||
l_http_response.append (l_body) | ||
if attached json (l_body) as j then | ||
j_body := j | ||
col := cj_collection (j) | ||
end | ||
else | ||
l_formatted_body := Void | ||
end | ||
end | ||
create Result.make (l_url, l_http_response, j_body, col) | ||
end | ||
|
||
|
||
feature {NONE} -- Implementation | ||
|
||
shared_ejson: SHARED_EJSON | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should use STRING_TABLE (not critical)