Moved to draft
This commit is contained in:
79
draft/library/wsf_js_widget/kernel/grid/wsf_datasource.e
Normal file
79
draft/library/wsf_js_widget/kernel/grid/wsf_datasource.e
Normal file
@@ -0,0 +1,79 @@
|
||||
note
|
||||
description: "Summary description for {WSF_DATASOURCE}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_DATASOURCE [G -> WSF_ENTITY]
|
||||
|
||||
feature --Event handling
|
||||
|
||||
set_on_update_agent (f: PROCEDURE [ANY, TUPLE])
|
||||
--Set update listener
|
||||
do
|
||||
on_update_agent := f
|
||||
end
|
||||
|
||||
update
|
||||
--Trigger update listener
|
||||
do
|
||||
if attached on_update_agent as a then
|
||||
a.call (Void)
|
||||
end
|
||||
end
|
||||
|
||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
|
||||
state: JSON_OBJECT
|
||||
-- Return state which contains the current sort_column and sort_direction
|
||||
do
|
||||
create Result.make
|
||||
if attached sort_column as a_sort_column then
|
||||
Result.put (create {JSON_STRING}.make_json (a_sort_column), "sort_column")
|
||||
else
|
||||
Result.put (create {JSON_NULL}, "sort_column")
|
||||
end
|
||||
Result.put (create {JSON_BOOLEAN}.make_boolean (sort_direction), "sort_direction")
|
||||
end
|
||||
|
||||
set_state (new_state: JSON_OBJECT)
|
||||
-- Restore sort_column and sort_direction from json
|
||||
do
|
||||
if attached {JSON_STRING} new_state.item ("sort_column") as new_sort_column then
|
||||
sort_column := new_sort_column.unescaped_string_32 -- Implicit Conversion !
|
||||
elseif attached {JSON_NULL} new_state.item ("sort_column") as new_sort_column then
|
||||
sort_column := Void
|
||||
end
|
||||
if attached {JSON_BOOLEAN} new_state.item ("sort_direction") as new_sort_direction then
|
||||
sort_direction := new_sort_direction.item
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Change
|
||||
|
||||
set_sort_column (a_sort_column: like sort_column)
|
||||
-- Set the column by which the data should be sorted
|
||||
do
|
||||
sort_column := a_sort_column
|
||||
end
|
||||
|
||||
set_sort_direction (a_sort_direction: like sort_direction)
|
||||
-- Set the sorting direction
|
||||
do
|
||||
sort_direction := a_sort_direction
|
||||
end
|
||||
|
||||
feature -- Properties
|
||||
|
||||
sort_column: detachable STRING
|
||||
|
||||
sort_direction: BOOLEAN
|
||||
|
||||
data: ITERABLE [G]
|
||||
deferred
|
||||
end
|
||||
|
||||
on_update_agent: detachable PROCEDURE [ANY, TUPLE]
|
||||
|
||||
end
|
||||
16
draft/library/wsf_js_widget/kernel/grid/wsf_entity.e
Normal file
16
draft/library/wsf_js_widget/kernel/grid/wsf_entity.e
Normal file
@@ -0,0 +1,16 @@
|
||||
note
|
||||
description: "Summary description for {WSF_ENTITY}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_ENTITY
|
||||
|
||||
feature -- Access
|
||||
|
||||
item (a_field: READABLE_STRING_GENERAL): detachable ANY
|
||||
-- Value for field item `a_field'.
|
||||
deferred
|
||||
end
|
||||
|
||||
end
|
||||
44
draft/library/wsf_js_widget/kernel/grid/wsf_grid_column.e
Normal file
44
draft/library/wsf_js_widget/kernel/grid/wsf_grid_column.e
Normal file
@@ -0,0 +1,44 @@
|
||||
note
|
||||
description: "Summary description for {WSF_GRID_COLUMN}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_GRID_COLUMN
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_header, a_field: STRING)
|
||||
do
|
||||
header := a_header
|
||||
field_name := a_field
|
||||
sorting_name := a_field
|
||||
end
|
||||
|
||||
feature -- Render
|
||||
|
||||
render_column (e: WSF_ENTITY): STRING
|
||||
-- Return the rendered column cell for a specific entity (row)
|
||||
do
|
||||
if attached e.item (field_name) as data then
|
||||
Result := data.out
|
||||
else
|
||||
Result := "[VOID]"
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Properties
|
||||
|
||||
header: STRING
|
||||
|
||||
sortable: BOOLEAN
|
||||
|
||||
sorting_name: STRING
|
||||
|
||||
field_name: STRING
|
||||
|
||||
end
|
||||
73
draft/library/wsf_js_widget/kernel/grid/wsf_grid_control.e
Normal file
73
draft/library/wsf_js_widget/kernel/grid/wsf_grid_control.e
Normal file
@@ -0,0 +1,73 @@
|
||||
note
|
||||
description: "Summary description for {WSF_GRID_CONTROL}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_GRID_CONTROL [G -> WSF_ENTITY]
|
||||
|
||||
inherit
|
||||
|
||||
WSF_REPEATER_CONTROL [G]
|
||||
redefine
|
||||
render
|
||||
end
|
||||
|
||||
create
|
||||
make_grid
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make_grid (n: STRING; a_columns: ITERABLE [WSF_GRID_COLUMN]; a_datasource: WSF_DATASOURCE [G])
|
||||
do
|
||||
make_repeater (n, a_datasource)
|
||||
columns := a_columns
|
||||
end
|
||||
|
||||
feature -- Render
|
||||
|
||||
render_item (item: G): STRING
|
||||
-- Render table row
|
||||
do
|
||||
Result := ""
|
||||
across
|
||||
columns as c
|
||||
loop
|
||||
Result.append (render_tag_with_tagname ("td", c.item.render_column (item), "", ""))
|
||||
end
|
||||
Result := render_tag_with_tagname ("tr", Result, "", "")
|
||||
end
|
||||
|
||||
render_header: STRING
|
||||
-- Render table header
|
||||
do
|
||||
Result := ""
|
||||
across
|
||||
columns as c
|
||||
loop
|
||||
Result.append (render_tag_with_tagname ("th", c.item.header, "", ""))
|
||||
end
|
||||
Result := render_tag_with_tagname ("thead", render_tag_with_tagname ("tr", Result, "", ""), "", "")
|
||||
end
|
||||
|
||||
render: STRING
|
||||
-- Render entre table and subcontrols
|
||||
local
|
||||
table: STRING
|
||||
do
|
||||
table := render_tag_with_tagname ("table", render_header + render_tag_with_tagname ("tbody", render_body, "", ""), "", "table table-striped")
|
||||
Result := ""
|
||||
across
|
||||
controls as c
|
||||
loop
|
||||
Result.append (c.item.render)
|
||||
end
|
||||
Result := render_tag (table + Result, "")
|
||||
end
|
||||
|
||||
feature -- Properties
|
||||
|
||||
columns: ITERABLE [WSF_GRID_COLUMN]
|
||||
|
||||
end
|
||||
@@ -0,0 +1,41 @@
|
||||
note
|
||||
description: "Summary description for {WSF_GRID_IMAGE_COLUMN}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_GRID_IMAGE_COLUMN
|
||||
|
||||
inherit
|
||||
|
||||
WSF_GRID_COLUMN
|
||||
rename
|
||||
make as make_column
|
||||
redefine
|
||||
render_column
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_header, a_field: STRING)
|
||||
do
|
||||
make_column (a_header, a_field)
|
||||
end
|
||||
|
||||
feature -- Render
|
||||
|
||||
render_column (e: WSF_ENTITY): STRING
|
||||
-- Return the rendered column image cell for a specific entity (row)
|
||||
do
|
||||
if attached e.item (field_name) as data then
|
||||
Result := "<img src=%"" + data.out + "%" />"
|
||||
else
|
||||
Result := "[VOID]"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,84 @@
|
||||
note
|
||||
description: "Summary description for {WSF_PAGABLE}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_PAGABLE_DATASOURCE [G -> WSF_ENTITY]
|
||||
|
||||
inherit
|
||||
|
||||
WSF_DATASOURCE [G]
|
||||
redefine
|
||||
state,
|
||||
set_state,
|
||||
update
|
||||
end
|
||||
|
||||
feature --Event handling
|
||||
|
||||
set_on_update_page_agent (f: PROCEDURE [ANY, TUPLE])
|
||||
--Set paging update listener
|
||||
do
|
||||
on_update_page_agent := f
|
||||
end
|
||||
|
||||
update
|
||||
--Trigger update listeners
|
||||
do
|
||||
Precursor
|
||||
if attached on_update_page_agent as a then
|
||||
a.call (Void)
|
||||
end
|
||||
end
|
||||
|
||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
|
||||
state: JSON_OBJECT
|
||||
-- Return state which contains the current page, page_size and row_count
|
||||
do
|
||||
Result := Precursor
|
||||
Result.put (create {JSON_NUMBER}.make_integer (page), "page")
|
||||
Result.put (create {JSON_NUMBER}.make_integer (page_size), "page_size")
|
||||
Result.put (create {JSON_NUMBER}.make_integer (row_count), "row_count")
|
||||
end
|
||||
|
||||
set_state (new_state: JSON_OBJECT)
|
||||
-- Restore page, page_size and row_count from json
|
||||
do
|
||||
Precursor (new_state)
|
||||
if attached {JSON_NUMBER} new_state.item ("page") as new_page then
|
||||
page := new_page.item.to_integer
|
||||
end
|
||||
if attached {JSON_NUMBER} new_state.item ("page_size") as new_page_size then
|
||||
page_size := new_page_size.item.to_integer
|
||||
end
|
||||
if attached {JSON_NUMBER} new_state.item ("row_count") as new_row_count then
|
||||
row_count := new_row_count.item.to_integer
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Change
|
||||
|
||||
set_page (p: INTEGER)
|
||||
do
|
||||
page := p.min (page_count).max (1)
|
||||
end
|
||||
|
||||
feature -- Properties
|
||||
|
||||
page: INTEGER
|
||||
|
||||
page_size: INTEGER
|
||||
|
||||
row_count: INTEGER
|
||||
|
||||
page_count: INTEGER
|
||||
do
|
||||
Result := (row_count / page_size).ceiling
|
||||
end
|
||||
|
||||
on_update_page_agent: detachable PROCEDURE [ANY, TUPLE]
|
||||
|
||||
end
|
||||
@@ -0,0 +1,96 @@
|
||||
note
|
||||
description: "Summary description for {WSF_PAGINATION}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
WSF_PAGINATION_CONTROL [G -> WSF_ENTITY]
|
||||
|
||||
inherit
|
||||
|
||||
WSF_CONTROL
|
||||
|
||||
create
|
||||
make_paging
|
||||
|
||||
feature {NONE}
|
||||
|
||||
make_paging (n: STRING; ds: WSF_PAGABLE_DATASOURCE [G])
|
||||
do
|
||||
make_control (n, "ul")
|
||||
add_class ("pagination")
|
||||
datasource := ds
|
||||
datasource.set_on_update_page_agent (agent update)
|
||||
end
|
||||
|
||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
|
||||
state: JSON_OBJECT
|
||||
-- Return empty
|
||||
do
|
||||
create Result.make
|
||||
end
|
||||
|
||||
set_state (new_state: JSON_OBJECT)
|
||||
-- There is no state to restore states
|
||||
do
|
||||
end
|
||||
|
||||
update
|
||||
-- Send new renederd control to client on update
|
||||
do
|
||||
state_changes.replace (create {JSON_STRING}.make_json (render), "_html")
|
||||
end
|
||||
|
||||
feature --Event handling
|
||||
|
||||
handle_callback (cname: STRING; event: STRING; event_parameter: detachable STRING)
|
||||
-- Handle goto/next/prev events
|
||||
do
|
||||
if Current.control_name.same_string (cname) then
|
||||
if event.same_string ("next") then
|
||||
datasource.set_page (datasource.page + 1)
|
||||
elseif event.same_string ("prev") then
|
||||
datasource.set_page (datasource.page - 1)
|
||||
elseif event.same_string ("goto") then
|
||||
if attached event_parameter as p and then attached p.to_integer as i then
|
||||
datasource.set_page (i)
|
||||
end
|
||||
end
|
||||
datasource.update
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Render
|
||||
|
||||
render: STRING
|
||||
-- Render paging control
|
||||
local
|
||||
paging_start: INTEGER
|
||||
paging_end: INTEGER
|
||||
cssclass: STRING
|
||||
do
|
||||
Result := render_tag_with_tagname ("li", render_tag_with_tagname ("a", "«", "href=%"#%" data-nr=%"prev%"", ""), "", "")
|
||||
paging_start := (datasource.page - 4).max (1)
|
||||
paging_end := (paging_start + 8).min (datasource.page_count)
|
||||
paging_start := (paging_end - 8).max (1)
|
||||
across
|
||||
paging_start |..| paging_end as n
|
||||
loop
|
||||
if n.item = datasource.page then
|
||||
cssclass := "active"
|
||||
else
|
||||
cssclass := ""
|
||||
end
|
||||
Result.append (render_tag_with_tagname ("li", render_tag_with_tagname ("a", n.item.out, "href=%"#%" data-nr=%"" + n.item.out + "%"", ""), "", cssclass))
|
||||
end
|
||||
Result.append (render_tag_with_tagname ("li", render_tag_with_tagname ("a", "»", "href=%"#%" data-nr=%"next%"", ""), "", ""))
|
||||
Result := render_tag (Result, "")
|
||||
end
|
||||
|
||||
feature -- Properties
|
||||
|
||||
datasource: WSF_PAGABLE_DATASOURCE [G]
|
||||
|
||||
end
|
||||
@@ -0,0 +1,97 @@
|
||||
note
|
||||
description: "Summary description for {WSF_REPEATER_CONTROL}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
deferred class
|
||||
WSF_REPEATER_CONTROL [G -> WSF_ENTITY]
|
||||
|
||||
inherit
|
||||
|
||||
WSF_MULTI_CONTROL [WSF_STATELESS_CONTROL]
|
||||
redefine
|
||||
set_state,
|
||||
state,
|
||||
render
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make_repeater (n: STRING; a_datasource: WSF_DATASOURCE [G])
|
||||
do
|
||||
make_multi_control (n)
|
||||
datasource := a_datasource
|
||||
datasource.set_on_update_agent (agent update)
|
||||
if attached {WSF_PAGABLE_DATASOURCE [G]} a_datasource as ds then
|
||||
create pagination_control.make_paging (n + "_paging", ds)
|
||||
add_control (pagination_control)
|
||||
end
|
||||
end
|
||||
|
||||
feature {WSF_PAGE_CONTROL, WSF_CONTROL} -- State management
|
||||
|
||||
update
|
||||
-- Send new renederd control to client on update
|
||||
do
|
||||
state_changes.replace (create {JSON_STRING}.make_json (render_body), "_body")
|
||||
state_changes.replace (datasource.state, "datasource")
|
||||
end
|
||||
|
||||
set_state (new_state: JSON_OBJECT)
|
||||
-- Restore datasource state from json
|
||||
do
|
||||
if attached {JSON_OBJECT} new_state.item ("datasource") as datasource_state then
|
||||
datasource.set_state (datasource_state)
|
||||
end
|
||||
end
|
||||
|
||||
state: JSON_OBJECT
|
||||
-- Return state which contains the current datasource state
|
||||
do
|
||||
create Result.make
|
||||
Result.put (datasource.state, "datasource")
|
||||
end
|
||||
|
||||
|
||||
feature -- Rendering
|
||||
|
||||
render_item (item: G): STRING
|
||||
--Render item
|
||||
deferred
|
||||
end
|
||||
|
||||
render_body: STRING
|
||||
--Render Body
|
||||
do
|
||||
Result := ""
|
||||
across
|
||||
datasource.data as entity
|
||||
loop
|
||||
Result.append (render_item (entity.item))
|
||||
end
|
||||
end
|
||||
|
||||
render: STRING
|
||||
--Render repeater inclusive paging if paging is available
|
||||
local
|
||||
content: STRING
|
||||
do
|
||||
content := render_tag_with_tagname ("div", render_body, "", "repeater_content")
|
||||
Result := ""
|
||||
across
|
||||
controls as c
|
||||
loop
|
||||
Result := c.item.render + Result
|
||||
end
|
||||
-- Fix generator name since the user will extend this class to define item_render
|
||||
Result := render_tag_with_generator_name ("WSF_REPEATER_CONTROL", content + Result, "")
|
||||
end
|
||||
|
||||
feature -- Properties
|
||||
|
||||
datasource: WSF_DATASOURCE [G]
|
||||
|
||||
pagination_control: detachable WSF_PAGINATION_CONTROL [G]
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user