Skip to content

Commit 502b8eb

Browse files
committed
Add Delete support.
Proof of concept: using ev_text instead of text field.
1 parent cc4c4ed commit 502b8eb

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

src/cj_client_proxy.e

+6
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,10 @@ feature -- Execution
5959
Result := client.update_with_template (a_path, tpl, adapted_context (ctx))
6060
end
6161

62+
63+
delete (a_path: READABLE_STRING_GENERAL; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): CJ_CLIENT_RESPONSE
64+
do
65+
Result := client.delete (a_path, adapted_context (ctx))
66+
end
67+
6268
end

src/cj_template_tool.e

+40-3
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ feature -- Change
4343
v: EV_VERTICAL_BOX
4444
hb: EV_HORIZONTAL_BOX
4545
lab: EV_LABEL
46-
tf: EV_TEXT_FIELD
46+
-- tf: EV_TEXT_FIELD
47+
tf: EV_TEXT
4748
tf_passwd: EV_PASSWORD_FIELD
4849
but: EV_BUTTON
49-
table: HASH_TABLE [EV_TEXT_FIELD, STRING_32]
50+
but_delete: detachable EV_BUTTON
51+
table: HASH_TABLE [EV_TEXT_COMPONENT, STRING_32]
5052
is_creation: BOOLEAN
5153
is_password: BOOLEAN
5254
do
@@ -110,15 +112,23 @@ feature -- Change
110112
else
111113
create but.make_with_text ("Update")
112114
but.select_actions.extend (agent on_post (coll, tpl, table, False))
115+
create but_delete.make_with_text ("Delete")
116+
but_delete.select_actions.extend (agent on_delete (coll, tpl, table))
117+
113118
end
114119

115120
v.extend (create {EV_CELL})
116121
v.extend (but)
122+
if but_delete /= Void then
123+
v.extend (but_delete)
124+
v.disable_item_expand (but_delete)
125+
126+
end
117127
v.disable_item_expand (but)
118128
-- FIXME
119129
end
120130

121-
on_post (coll: CJ_COLLECTION; tpl: CJ_TEMPLATE; table: HASH_TABLE [EV_TEXT_FIELD, STRING_32]; is_creation: BOOLEAN)
131+
on_post (coll: CJ_COLLECTION; tpl: CJ_TEMPLATE; table: HASH_TABLE [EV_TEXT_COMPONENT, STRING_32]; is_creation: BOOLEAN)
122132
local
123133
ctx: HTTP_CLIENT_REQUEST_CONTEXT
124134
l_href: STRING_8
@@ -147,6 +157,33 @@ feature -- Change
147157
-- dlg.focus_out_actions.extend (agent dlg.destroy_and_exit_if_last)
148158
end
149159

160+
on_delete (coll: CJ_COLLECTION; tpl: CJ_TEMPLATE; table: HASH_TABLE [EV_TEXT_COMPONENT, STRING_32])
161+
local
162+
ctx: HTTP_CLIENT_REQUEST_CONTEXT
163+
l_href: STRING_8
164+
dlg: EV_INFORMATION_DIALOG
165+
resp: CJ_CLIENT_RESPONSE
166+
do
167+
create ctx.make
168+
across
169+
tpl.data as c
170+
loop
171+
if attached table.item (c.item.name) as tf then
172+
c.item.set_value (tf.text)
173+
end
174+
end
175+
if attached coll.items as l_items and then attached l_items.first as first_item then
176+
l_href := first_item.href
177+
resp := cj_client.delete(l_href, Void )
178+
else
179+
l_href := coll.href
180+
resp := cj_client.delete (l_href, Void)
181+
end
182+
create dlg.make_with_text ("Result")
183+
dlg.set_text (resp.http_response)
184+
dlg.show
185+
end
186+
150187
invariant
151188
widget_attached: widget /= Void
152189

src/kernel/cj_client.e

+35
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,41 @@ feature -- Access
185185
end
186186

187187

188+
delete (a_path: READABLE_STRING_GENERAL; ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT): CJ_CLIENT_RESPONSE
189+
local
190+
l_http_response: STRING_8
191+
j_body: like json
192+
l_formatted_body: detachable STRING_8
193+
col: detachable CJ_COLLECTION
194+
l_ctx: detachable HTTP_CLIENT_REQUEST_CONTEXT
195+
l_url: STRING_8
196+
do
197+
create l_http_response.make_empty
198+
l_ctx := ctx
199+
if l_ctx = Void then
200+
create l_ctx.make
201+
end
202+
l_ctx.add_header ("Accept", "application/vnd.collection+json")
203+
l_url := a_path.to_string_8
204+
if attached client.delete (l_url, l_ctx) as g_response then
205+
l_url := g_response.url
206+
l_http_response.append ("Status: " + g_response.status.out + "%N")
207+
l_http_response.append (g_response.raw_header)
208+
if attached g_response.body as l_body then
209+
l_http_response.append ("%N%N")
210+
l_http_response.append (l_body)
211+
if attached json (l_body) as j then
212+
j_body := j
213+
col := cj_collection (j)
214+
end
215+
else
216+
l_formatted_body := Void
217+
end
218+
end
219+
create Result.make (l_url, l_http_response, j_body, col)
220+
end
221+
222+
188223
feature {NONE} -- Implementation
189224

190225
shared_ejson: SHARED_EJSON

0 commit comments

Comments
 (0)