Skip to content

Commit 8d7041c

Browse files
authored
Merge pull request #7 from jvelilla/eg_sheets
Eg sheets mapping Eiffel to JSON wip
2 parents a899c75 + e937da7 commit 8d7041c

20 files changed

+816
-223
lines changed

sheets/src/json/eg_sheets_json.e

Lines changed: 142 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ feature {NONE} -- JSON To Eiffel
111111
-- Create an object `EG_SPREADSHEET_PROPERTIES` from a json representation `a_json`.
112112
local
113113
l_cell_format: EG_CELL_FORMAT
114+
l_ri: EG_RECALCULATION_INTERVAL
114115
do
115116
create Result
116117
if attached string_value_from_json (a_json, "title") as l_title then
@@ -120,83 +121,194 @@ feature {NONE} -- JSON To Eiffel
120121
Result.set_locale (l_locale)
121122
end
122123
if attached string_value_from_json (a_json, "autoRecalc") as l_auto_recalc then
124+
create l_ri
123125
if l_auto_recalc.is_case_insensitive_equal ("ON_CHANGE") then
124-
Result.auto_recalc.set_on_change
126+
l_ri.set_on_change
125127
elseif l_auto_recalc.is_case_insensitive_equal ("MINUTE") then
126-
Result.auto_recalc.set_minute
128+
l_ri.set_minute
127129
elseif l_auto_recalc.is_case_insensitive_equal ("HOUR") then
128-
Result.auto_recalc.set_hour
130+
l_ri.set_hour
129131
end
132+
Result.set_auto_recalc (l_ri)
130133
end
131134
if attached string_value_from_json (a_json, "timeZone") as l_time_zone then
132135
Result.set_time_zone (l_time_zone)
133136
end
134137
if attached {JSON_OBJECT} json_value (a_json, "defaultFormat") as l_default_format then
138+
Result.set_default_format (cell_format (l_default_format))
135139
end
140+
if attached {JSON_OBJECT} json_value (a_json, "iterativeCalculationSettings") as iterativeCalculationSettings then
141+
-- Result.set_iterative_calculation_settings (a_iterative_calculation_settings: [like iterative_calculation_settings] detachable EG_ITERATIVE_CALCULATION_SETTINGS)
142+
end
143+
if attached {JSON_OBJECT} json_value (a_json, "spreadsheetTheme") as l_spreadsheet then
144+
Result.set_spreadsheet_theme (spreadsheet_theme (l_spreadsheet))
145+
end
146+
end
147+
148+
spreadsheet_theme (a_json: JSON_VALUE): EG_SPREADSHEET_THEME
149+
-- Create an object `EG_SPREADSHEET_THEME` from a json representation `a_json`.
150+
do
151+
create Result
152+
if attached string_value_from_json (a_json, "primaryFontFamily") as l_primary_font then
153+
Result.set_primary_font_family (l_primary_font)
154+
end
155+
if attached {JSON_ARRAY} json_value (a_json, "themeColors") as l_theme_colors then
156+
across l_theme_colors as ic loop
157+
Result.force_theme_color (theme_color_pair (ic.item))
158+
end
159+
end
160+
end
161+
162+
theme_color_pair (a_json: JSON_VALUE): EG_THEME_COLOR_PAIR
163+
local
164+
l_tc: EG_THEME_COLOR
165+
do
166+
create Result
167+
if attached string_value_from_json (a_json, "colorType") as l_color_type then
168+
create l_tc
169+
if l_color_type.is_case_insensitive_equal ("TEXT") then
170+
l_tc.set_text
171+
elseif l_color_type.is_case_insensitive_equal ("BACKGROUND") then
172+
l_tc.set_background
173+
elseif l_color_type.is_case_insensitive_equal ("ACCENT1") then
174+
l_tc.set_accent1
175+
elseif l_color_type.is_case_insensitive_equal ("ACCENT2") then
176+
l_tc.set_accent2
177+
elseif l_color_type.is_case_insensitive_equal ("ACCENT3") then
178+
l_tc.set_accent3
179+
elseif l_color_type.is_case_insensitive_equal ("ACCENT4") then
180+
l_tc.set_accent4
181+
elseif l_color_type.is_case_insensitive_equal ("ACCENT5") then
182+
l_tc.set_accent5
183+
elseif l_color_type.is_case_insensitive_equal ("ACCENT6") then
184+
l_tc.set_accent6
185+
elseif l_color_type.is_case_insensitive_equal ("LINK") then
186+
l_tc.set_link
187+
end
188+
Result.set_color_type (l_tc)
189+
end
190+
if attached {JSON_OBJECT} json_value (a_json, "color") as l_color then
191+
Result.set_color (eg_color_style (l_color))
192+
end
193+
136194
end
137195

138196
cell_format (a_json: JSON_OBJECT): EG_CELL_FORMAT
139197
-- Create an object `EG_CELL_FORMAT` from a json representation `a_json`
198+
local
199+
l_vl: EG_VERTICAL_ALIGN
200+
l_ws: EG_WRAP_STRATEGY
201+
l_hl: EG_HORIZONTAL_ALIGN
202+
l_td: EG_TEXT_DIRECTION
203+
l_hyper: EG_HYPERLINK_DISPLAY_TYPE
140204
do
141205
create Result
206+
if attached {JSON_OBJECT} json_value (a_json, "numberFormat") as l_number_format then
207+
Result.set_number_format (Void)
208+
end
142209

143210
if attached {JSON_OBJECT} json_value (a_json, "backgroundColor") as l_background_color then
144211
Result.set_background_color (eg_color (l_background_color))
145212
end
213+
if attached {JSON_OBJECT} json_value (a_json, "backgroundColorStyle") as l_background_color_style then
214+
Result.set_background_color_style (eg_color_style (l_background_color_style))
215+
end
216+
if attached {JSON_OBJECT} json_value (a_json, "borders") as l_borders then
217+
Result.set_borders (Void)
218+
end
146219
if attached {JSON_OBJECT} json_value (a_json, "padding") as l_padding then
147220
Result.set_padding (padding (l_padding))
148221
end
222+
if attached string_value_from_json (a_json, "horizontalAlignment") as l_alignment then
223+
create l_hl
224+
if l_alignment.is_case_insensitive_equal ("LEFT") then
225+
l_hl.set_left
226+
elseif l_alignment.is_case_insensitive_equal ("CENTER") then
227+
l_hl.set_center
228+
elseif l_alignment.is_case_insensitive_equal ("RIGHT") then
229+
l_hl.set_right
230+
end
231+
Result.set_horizontal_alignment (l_hl)
232+
end
149233
if attached string_value_from_json (a_json, "verticalAlignment") as l_alignment then
234+
create l_vl
150235
if l_alignment.is_case_insensitive_equal ("BOTTOM") then
151-
Result.vertical_alignment.set_bottom
236+
l_vl.set_bottom
152237
elseif l_alignment.is_case_insensitive_equal ("MIDDLE") then
153-
Result.vertical_alignment.set_middle
238+
l_vl.set_middle
154239
elseif l_alignment.is_case_insensitive_equal ("TOP") then
155-
Result.vertical_alignment.set_top
240+
l_vl.set_top
156241
end
242+
Result.set_vertical_alignment (l_vl)
157243
end
158244
if attached string_value_from_json (a_json, "wrapStrategy") as l_wrap_strategy then
245+
create l_ws
159246
if l_wrap_strategy.is_case_insensitive_equal ("OVERFLOW_CELL") then
160-
Result.wrap_strategy.set_overflow_cell
247+
l_ws.set_overflow_cell
161248
end
162249
if l_wrap_strategy.is_case_insensitive_equal ("LEGACY_WRAP") then
163-
Result.wrap_strategy.set_legacy_wrap
250+
l_ws.set_legacy_wrap
164251
elseif l_wrap_strategy.is_case_insensitive_equal ("CLIP") then
165-
Result.wrap_strategy.set_clip
252+
l_ws.set_clip
166253
elseif l_wrap_strategy.is_case_insensitive_equal ("WRAP") then
167-
Result.wrap_strategy.set_wrap
254+
l_ws.set_wrap
168255
end
256+
Result.set_wrap_strategy (l_ws)
257+
end
258+
if attached string_value_from_json (a_json, "textDirection") as l_text_direction then
259+
create l_td
260+
if l_text_direction.is_case_insensitive_equal ("LEFT_TO_RIGHT") then
261+
l_td.set_left_to_right
262+
end
263+
if l_text_direction.is_case_insensitive_equal ("RIGHT_TO_LEFT") then
264+
l_td.set_right_to_left
265+
end
266+
Result.set_text_direction (l_td)
169267
end
170268
if attached {JSON_OBJECT} json_value (a_json, "textFormat") as l_text_format then
171269
Result.set_text_format (text_format (l_text_format))
172270
end
173-
if attached {JSON_OBJECT} json_value (a_json, "backgroundColorStyle") as l_background_color_style then
174-
Result.set_background_color_style (eg_color_style (l_background_color_style))
271+
if attached string_value_from_json (a_json, "hyperlinkDisplayType") as hyperlink then
272+
create l_hyper
273+
if hyperlink.is_case_insensitive_equal ("LINKED") then
274+
l_hyper.set_linked
275+
end
276+
if hyperlink.is_case_insensitive_equal ("PLAIN_TEXT") then
277+
l_hyper.set_plain_text
278+
end
279+
Result.set_hyperlink_display_type (l_hyper)
280+
end
281+
if attached {JSON_OBJECT} json_value (a_json, "textRotation") as l_text_rotation then
282+
Result.set_text_rotation (text_rotation (l_text_rotation))
283+
end
284+
end
285+
286+
text_rotation (a_json: JSON_OBJECT): EG_TEXT_ROTATION
287+
-- Create an object `EG_TEXT_ROTATION` from a json representation.
288+
do
289+
create Result
290+
if attached integer_value_from_json (a_json, "angle") as l_val then
291+
Result.set_angle (l_val)
292+
end
293+
if attached boolean_value_from_json (a_json, "vertical") as l_val then
294+
Result.set_vertical (l_val)
175295
end
176296
end
177297

178298
eg_color (a_json: JSON_OBJECT): EG_COLOR
179299
-- Create an object `EG_COLOR` from a json rerpesentation `a_json`.
180300
do
181301
create Result
182-
if attached integer_value_from_json (a_json, "red") as l_val then
183-
Result.set_red (l_val)
184-
elseif attached real_value_from_json (a_json, "red") as l_val then
302+
if attached real_value_from_json (a_json, "red") as l_val then
185303
Result.set_red (l_val)
186304
end
187-
if attached integer_value_from_json (a_json, "green") as l_val then
188-
Result.set_green (l_val)
189-
elseif attached real_value_from_json (a_json, "green") as l_val then
305+
if attached real_value_from_json (a_json, "green") as l_val then
190306
Result.set_green (l_val)
191307
end
192-
if attached integer_value_from_json (a_json, "blue") as l_val then
193-
Result.set_blue (l_val)
194-
elseif attached real_value_from_json (a_json, "blue") as l_val then
308+
if attached real_value_from_json (a_json, "blue") as l_val then
195309
Result.set_blue (l_val)
196310
end
197-
if attached integer_value_from_json (a_json, "alpha") as l_val then
198-
Result.set_alpha (l_val)
199-
elseif attached real_value_from_json (a_json, "alpha") as l_val then
311+
if attached real_value_from_json (a_json, "alpha") as l_val then
200312
Result.set_alpha (l_val)
201313
end
202314
end
@@ -409,6 +521,8 @@ feature {NONE} -- JSON To Eiffel
409521

410522
eg_developer_metadata (a_json: JSON_VALUE): EG_DEVELOPER_METADATA
411523
-- Create an object `EG_DEVELOPER_METADATA` from a json representation `a_json`.
524+
local
525+
l_vs: EG_DEVELOPER_METADATA_VISIBILITY
412526
do
413527
create Result
414528
if attached integer_value_from_json (a_json, "metadataId") as l_metadata_id then
@@ -424,11 +538,13 @@ feature {NONE} -- JSON To Eiffel
424538
Result.set_location (developer_metadata_location (l_location))
425539
end
426540
if attached string_value_from_json (a_json, "visibility") as l_visibility then
541+
create l_vs
427542
if l_visibility.is_case_insensitive_equal ("DOCUMENT") then
428-
Result.visibility.set_document
543+
l_vs.set_document
429544
elseif l_visibility.is_case_insensitive_equal ("PROJECT") then
430-
Result.visibility.set_project
545+
l_vs.set_project
431546
end
547+
Result.set_visibility (l_vs)
432548
end
433549
end
434550

0 commit comments

Comments
 (0)