Skip to content

Commit d6dbed0

Browse files
committed
Added Eiffel to JSON mapping to
GRID_PROPERTIES SHEET (WIP) SHEET_PROPERTIES SHEET_TYPE
1 parent 5766cdd commit d6dbed0

File tree

5 files changed

+106
-34
lines changed

5 files changed

+106
-34
lines changed

sheets/src/json/eg_sheets_json.e

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ feature -- Post
4747
end
4848
end
4949

50-
feature -- Get
50+
feature -- Get
5151

5252
get_from_id (a_spreadsheet_id: STRING_8; a_params: detachable EG_SPREADSHEET_PARAMETERS): detachable EG_SPREADSHEET
5353
note
@@ -460,6 +460,9 @@ feature {NONE} -- JSON To Eiffel
460460

461461
sheet_properties (a_json: JSON_VALUE): EG_SHEET_PROPERTIES
462462
-- Create an object `EG_SHEET_PROPERTIES` from a json representation `a_json`.
463+
local
464+
l_stype: EG_SHEET_TYPE
465+
l_grid_prop: EG_GRID_PROPERTIES
463466
do
464467
create Result
465468
if attached integer_value_from_json (a_json, "sheetId") as l_sheetId then
@@ -472,19 +475,23 @@ feature {NONE} -- JSON To Eiffel
472475
Result.set_index (l_index)
473476
end
474477
if attached string_value_from_json (a_json, "sheetType") as l_sheet_type then
478+
create l_stype
475479
if l_sheet_type.is_case_insensitive_equal ("GRID") then
476-
Result.sheet_type.set_grid
480+
l_stype.set_grid
477481
elseif l_sheet_type.is_case_insensitive_equal ("OBJECT") then
478-
Result.sheet_type.set_grid
482+
l_stype.set_grid
479483
end
484+
Result.set_sheet_type (l_stype)
480485
end
481486
if attached {JSON_OBJECT} json_value (a_json, "gridProperties") as l_grid_properties then
487+
create l_grid_prop
482488
if attached integer_value_from_json (l_grid_properties, "rowCount") as l_row_count then
483-
Result.grid_properties.set_row_count (l_row_count)
489+
l_grid_prop.set_row_count (l_row_count)
484490
end
485491
if attached integer_value_from_json (l_grid_properties, "columnCount") as l_column_count then
486-
Result.grid_properties.set_column_count (l_column_count)
492+
l_grid_prop.set_column_count (l_column_count)
487493
end
494+
Result.set_grid_properties (l_grid_prop)
488495
end
489496
if attached boolean_value_from_json (a_json, "hidden") as l_hidden then
490497
Result.set_hidden (l_hidden)

sheets/src/objects/eg_grid_properties.e

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,18 @@ feature -- Element change
103103
row_count_assigned: row_count = a_row_count
104104
end
105105

106+
feature -- Eiffel to JSON
107+
108+
to_json: JSON_OBJECT
109+
-- JSon representation of current object.
110+
do
111+
create Result.make_with_capacity (6)
112+
Result.put (create {JSON_NUMBER}.make_integer (row_count), "rowCount")
113+
Result.put (create {JSON_NUMBER}.make_integer (column_count), "columnCount")
114+
Result.put (create {JSON_NUMBER}.make_integer (frozen_row_count), "frozenRowCount")
115+
Result.put (create {JSON_NUMBER}.make_integer (frozen_column_count), "frozenColumnCount")
116+
Result.put (create {JSON_BOOLEAN}.make (hide_grid_lines), "hideGridlines")
117+
Result.put (create {JSON_BOOLEAN}.make (row_group_control_after), "rowGroupControlAfter")
118+
Result.put (create {JSON_BOOLEAN}.make (column_group_control_after), "columnGroupControlAfter")
119+
end
106120
end

sheets/src/objects/eg_sheet.e

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,12 @@ feature -- Element Change
378378
feature -- Eiffel to JSON
379379

380380
to_json: JSON_OBJECT
381+
-- Json representation of current object.
381382
do
382383
create Result.make_empty
384+
if attached properties as l_properties then
385+
Result.put (l_properties.to_json, "properties")
386+
end
387+
383388
end
384389
end

sheets/src/objects/eg_sheet_properties.e

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,13 @@ note
2828
class
2929
EG_SHEET_PROPERTIES
3030

31-
inherit
32-
33-
ANY
34-
redefine
35-
default_create
36-
end
37-
38-
create
39-
default_create
40-
41-
feature {NONE} -- Initialization
42-
43-
default_create
44-
do
45-
create title.make_empty
46-
create sheet_type
47-
create grid_properties
48-
ensure then
49-
sheet_id = 0
50-
not is_sheet_id_set
51-
not is_sheet_type_set
52-
end
53-
54-
5531
feature -- Access
5632

5733
sheet_id: INTEGER
5834
-- The ID of the sheet. Must be non-negative. This field cannot be changed once set.
5935
-- NATURAL?
6036

61-
title: STRING
37+
title: detachable STRING
6238
-- The name of the sheet.
6339

6440
index: INTEGER
@@ -68,10 +44,10 @@ feature -- Access
6844
-- For example, if there were 3 sheets (S1, S2, S3) in order to move S1 ahead of S2 the index would have to be set to 2.
6945
-- A sheet index update request is ignored if the requested index is identical to the sheets current index or if the requested new index is equal to the current sheet index + 1.
7046

71-
sheet_type: EG_SHEET_TYPE
47+
sheet_type: detachable EG_SHEET_TYPE
7248
-- The type of sheet. Defaults to GRID . This field cannot be changed once set.
7349

74-
grid_properties: EG_GRID_PROPERTIES
50+
grid_properties: detachable EG_GRID_PROPERTIES
7551
-- Additional properties of the sheet if this sheet is a grid.
7652
-- (If the sheet is an object sheet, containing a chart or image, then this field will be absent.)
7753
-- When writing it is an error to set any grid properties on non-grid sheets.
@@ -100,6 +76,7 @@ feature -- Status Report
10076
feature -- Element Change
10177

10278
set_sheet_id (a_id: like sheet_id)
79+
-- Set `sheet_id` with `a_id`.
10380
require
10481
non_negative: a_id >=0
10582
not_id_set: not is_sheet_id_set
@@ -111,21 +88,24 @@ feature -- Element Change
11188
is_defined: is_sheet_id_set
11289
end
11390

114-
set_title (a_title: STRING)
91+
set_title (a_title: like title)
92+
-- Set `title` with `a_title`.
11593
do
11694
title := a_title
11795
ensure
11896
title_set: title = a_title
11997
end
12098

12199
set_index (a_index: like index)
100+
-- Set `index` with `a_index`.
122101
do
123102
index := a_index
124103
ensure
125104
index_set: index = a_index
126105
end
127106

128107
set_sheet_type (a_type: EG_SHEET_TYPE)
108+
-- Set `sheet_type` with `a_type`.
129109
require
130110
not_sheet_type: not is_sheet_type_set
131111
do
@@ -137,38 +117,89 @@ feature -- Element Change
137117
end
138118

139119
set_grid_properties (a_properties: like grid_properties)
120+
-- Set `grid_properties` with `a_properties`.
140121
do
141122
grid_properties := a_properties
142123
ensure
143124
grid_properties_set: grid_properties = a_properties
144125
end
145126

146127
set_hidden (a_val: BOOLEAN)
128+
-- Set `hidden` with `a_val`.
147129
do
148130
hidden := a_val
149131
ensure
150132
hidden_set: hidden = a_val
151133
end
152134

153135
set_tab_color (a_color: like tab_color)
136+
-- Set `tab_color` with `a_color`.
154137
do
155138
tab_color := a_color
156139
ensure
157140
tab_color_set: tab_color = a_color
158141
end
159142

160143
set_tab_color_style (a_color_style: like tab_color_style)
144+
-- Set `tab_color_style` with `a_color_style`.
161145
do
162146
tab_color_style := a_color_style
163147
ensure
164148
tab_color_style_set: tab_color_style = a_color_style
165149
end
166150

167151
set_right_to_left (a_val: BOOLEAN)
152+
-- Set `right_to_left` with `a_val`.
168153
do
169154
right_to_left := a_val
170155
ensure
171156
right_to_left_set: right_to_left = a_val
172157
end
173158

159+
feature -- Eiffel to JSON
160+
161+
to_json: JSON_OBJECT
162+
-- {
163+
-- "sheetId": integer,
164+
-- "title": string,
165+
-- "index": integer,
166+
-- "sheetType": enum (SheetType),
167+
-- "gridProperties": {
168+
-- object (GridProperties)
169+
-- },
170+
-- "hidden": boolean,
171+
-- "tabColor": {
172+
-- object (Color)
173+
-- },
174+
-- "tabColorStyle": {
175+
-- object (ColorStyle)
176+
-- },
177+
-- "rightToLeft": boolean
178+
-- }
179+
180+
do
181+
create Result.make
182+
if is_sheet_id_set then
183+
Result.put (create {JSON_NUMBER}.make_integer (sheet_id), "sheetId")
184+
end
185+
if attached title as l_title then
186+
Result.put (create {JSON_STRING}.make_from_string (l_title), "title")
187+
end
188+
Result.put (create {JSON_NUMBER}.make_integer (index), "index")
189+
if attached sheet_type as l_st then
190+
Result.put (l_st.to_json, "sheetType")
191+
end
192+
if attached grid_properties as l_gp then
193+
Result.put (l_gp.to_json, "gridProperties")
194+
end
195+
Result.put (create {JSON_BOOLEAN}.make (hidden), "hidden")
196+
if attached tab_color as l_tc then
197+
Result.put (l_tc.to_json, "tabColor")
198+
end
199+
if attached tab_color_style as l_tcs then
200+
Result.put (l_tcs.to_json, "tabColorStyle")
201+
end
202+
Result.put (create {JSON_BOOLEAN}.make (right_to_left), "rightToLeft")
203+
end
204+
174205
end

sheets/src/objects/eg_sheet_type.e

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,22 @@ feature -- Status Report
7474
do
7575
Result := a_value = sheet_type_unspecified or else
7676
a_value = grid or else
77-
a_value = object
77+
a_value = object
78+
end
79+
80+
81+
feature -- Eiffel to JSON
82+
83+
to_json: JSON_STRING
84+
-- JSon representation of current object.
85+
do
86+
if is_grid then
87+
Result := "GRID"
88+
elseif is_object then
89+
Result := "OBJECT"
90+
else
91+
Result := "SHEET_TYPE_UNSPECIFIED"
92+
end
7893
end
7994

8095
end

0 commit comments

Comments
 (0)