Class: Glib::JsonUi::PageHelper::Page

Inherits:
Object
  • Object
show all
Includes:
Default
Defined in:
app/helpers/glib/json_ui/page_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Default

#default_accepts

Constructor Details

#initialize(json, context) ⇒ Page

Returns a new instance of Page.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/helpers/glib/json_ui/page_helper.rb', line 102

def initialize(json, context)
  @json = json
  @context = context

  @view_builder = ViewBuilder.new(json, self, true)
  @sview_builder = ViewBuilder.new(json, self, false)
  @action_builder = ActionBuilder.new(json, self, false)
  @menu_builder = MenuBuilder.new(json, self)

  @list_section_builder = ListBuilders::Section.new(json, self, ListBuilders::ListTemplate.new(json, self))
  @tree_section_builder = ListBuilders::Section.new(json, self, ListBuilders::TreeTemplate.new(json, self))
  @drawer_content_builder = ListBuilders::Section.new(json, self, @menu_builder)
  @table_section_builder = TableBuilders::Section.new(json, self, TableBuilders::Template.new(json, self))
  # @split_content_builder = SplitBuilders::Content.new(json, self, @view_builder)

  # TODO: Deprecate
  # For generic `body` builder. For others, use content_builder()
  # @generic_content_builder = GenericBuilders::Content.new(json, self, @view_builder)
end

Instance Attribute Details

#action_builderObject (readonly)

Returns the value of attribute action_builder.



96
97
98
# File 'app/helpers/glib/json_ui/page_helper.rb', line 96

def action_builder
  @action_builder
end

#contextObject (readonly)

Returns the value of attribute context.



96
97
98
# File 'app/helpers/glib/json_ui/page_helper.rb', line 96

def context
  @context
end

#current_formObject

See Panels::Form



100
101
102
# File 'app/helpers/glib/json_ui/page_helper.rb', line 100

def current_form
  @current_form
end

#drawer_content_builderObject (readonly)

Returns the value of attribute drawer_content_builder.



97
98
99
# File 'app/helpers/glib/json_ui/page_helper.rb', line 97

def drawer_content_builder
  @drawer_content_builder
end

#jsonObject (readonly)

Returns the value of attribute json.



96
97
98
# File 'app/helpers/glib/json_ui/page_helper.rb', line 96

def json
  @json
end

#list_section_builderObject (readonly)

Returns the value of attribute list_section_builder.



97
98
99
# File 'app/helpers/glib/json_ui/page_helper.rb', line 97

def list_section_builder
  @list_section_builder
end

Returns the value of attribute menu_builder.



96
97
98
# File 'app/helpers/glib/json_ui/page_helper.rb', line 96

def menu_builder
  @menu_builder
end

#sview_builderObject (readonly)

Returns the value of attribute sview_builder.



96
97
98
# File 'app/helpers/glib/json_ui/page_helper.rb', line 96

def sview_builder
  @sview_builder
end

#table_section_builderObject (readonly)

Returns the value of attribute table_section_builder.



97
98
99
# File 'app/helpers/glib/json_ui/page_helper.rb', line 97

def table_section_builder
  @table_section_builder
end

#tree_section_builderObject (readonly)

Returns the value of attribute tree_section_builder.



97
98
99
# File 'app/helpers/glib/json_ui/page_helper.rb', line 97

def tree_section_builder
  @tree_section_builder
end

#view_builderObject (readonly)

Returns the value of attribute view_builder.



96
97
98
# File 'app/helpers/glib/json_ui/page_helper.rb', line 96

def view_builder
  @view_builder
end

Instance Method Details

#actionCable(options = {}) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'app/helpers/glib/json_ui/page_helper.rb', line 134

def actionCable(options = {})
  json.actionCable do
    if (on_error = options[:onError])
      json.onError do
        on_error.call(@action_builder)
      end
    end

    if (on_open = options[:onOpen])
      json.onOpen do
        on_open.call(@action_builder)
      end
    end

    if (on_close = options[:onClose])
      json.onClose do
        on_close.call(@action_builder)
      end
    end

    json.channels options[:channels]
  end
end

#body(options = {}) ⇒ Object



226
227
228
229
230
# File 'app/helpers/glib/json_ui/page_helper.rb', line 226

def body(options = {})
  json.body do
    vertical_content(options)
  end
end

#bodyFooter(options = {}) ⇒ Object



208
209
210
211
212
# File 'app/helpers/glib/json_ui/page_helper.rb', line 208

def bodyFooter(options = {})
  json.bodyFooter do
    vertical_content(options)
  end
end

#containerStyleClasses(styleClasses) ⇒ Object



175
176
177
# File 'app/helpers/glib/json_ui/page_helper.rb', line 175

def containerStyleClasses(styleClasses)
  json.containerStyleClasses styleClasses
end

#content_builder(panelNames) ⇒ Object



158
159
160
161
162
163
# File 'app/helpers/glib/json_ui/page_helper.rb', line 158

def content_builder(panelNames)
  # NOTE: Can potentially be cached
  builder = GenericBuilders::Content.new(json, self, @view_builder)
  builder.definePanels(panelNames)
  builder
end

#data(options = {}) ⇒ Object



272
273
274
# File 'app/helpers/glib/json_ui/page_helper.rb', line 272

def data(options = {})
  options[:content].call(ViewBuilder.new(json, self, false))
end

#filePaster(options = {}) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
# File 'app/helpers/glib/json_ui/page_helper.rb', line 122

def filePaster(options = {})
    json.filePaster do
      json.accepts default_accepts(options[:accepts])
      json.directUploadUrl options[:directUploadUrl]
      json.url options[:url]
      json.inputName options[:inputName]
      json.strategy options[:strategy]
      json.storagePrefix options[:storagePrefix]
      json. options[:metadata]
    end
end


220
221
222
223
224
# File 'app/helpers/glib/json_ui/page_helper.rb', line 220

def footer(options = {})
  json.footer do
    vertical_content(options)
  end
end

#form(options = {}) ⇒ Object



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'app/helpers/glib/json_ui/page_helper.rb', line 256

def form(options = {})
  form = Glib::JsonUi::ViewBuilder::Panels::Form.new(json, self)
  form.childViews(->(view_builder) { })
  panel_options = options.slice!(:url, :method, :local, :onSubmit, :paramNameForFormData, :model, :onChange, :onChangeAndLoad, :autoValidate, :disableDirtyCheck)

  json.fullPageForm do
    json.view 'panels/fullPageForm'
    form.props(options)
  end

  # So that the containing fields have context (e.g. can use form's model for naming).
  self.current_form = form
  scroll panel_options
  self.current_form = nil
end

#header(options = {}) ⇒ Object



214
215
216
217
218
# File 'app/helpers/glib/json_ui/page_helper.rb', line 214

def header(options = {})
  json.header do
    vertical_content(options)
  end
end

#leftDrawer(options = {}) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'app/helpers/glib/json_ui/page_helper.rb', line 179

def leftDrawer(options = {})
  json.leftDrawer do
    [:styleClasses, :backgroundColor, :drawerWidth].each do |name|
      if (value = options.delete(name))
        json.set! name, value
      end
    end
    if options[:body]
      json.set!(:body) { options[:body].call(sview_builder) }
    end
    options[:content]&.call drawer_content_builder
  end
end

#list(options = {}) ⇒ Object



232
233
234
235
236
237
238
# File 'app/helpers/glib/json_ui/page_helper.rb', line 232

def list(options = {})
  json.body do
    json.childViews do
      @view_builder.add_view('panels_list', options.reverse_merge(width: 'matchParent'))
    end
  end
end


193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'app/helpers/glib/json_ui/page_helper.rb', line 193

def navBar(options = {})
  json.navBar do
    # json.leftItems do
    #   options[:leftItems]&.call @menu_builder
    # end
    # json.logoUrl "http://localhost:3000/assets/logo_dark-02d9b6a91fdbf22515da7b921d31367b70696214415f6789d2f90232e4a287b7.svg"

    # json.rightItems do
    #   options[:rightItems]&.call @menu_builder
    # end

    @view_builder.add_singleton_view('appBar', options)
  end
end

#on(options = {}) ⇒ Object



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'app/helpers/glib/json_ui/page_helper.rb', line 298

def on(options = {})
  if (on_load = options[:load])
    json.onLoad do
      on_load.call @action_builder
    end
  end

  if (on_rerender = options[:reRender])
    json.onRerender do
      on_rerender.call @action_builder
    end
  end

  if (on_unload = options[:unload])
    json.onUnload do
      on_unload.call @action_builder
    end
  end

  if (on_refocus = options[:refocus])
    json.onRefocus do
      on_refocus.call @action_builder
    end
  end

  if (on_foreground = options[:foreground])
    json.onForeground do
      on_foreground.call @action_builder
    end
  end
end

#scroll(options = {}) ⇒ Object



248
249
250
251
252
253
254
# File 'app/helpers/glib/json_ui/page_helper.rb', line 248

def scroll(options = {})
  json.body do
    json.childViews do
      @view_builder.add_view('panels_scroll', options.reverse_merge(width: 'matchParent'))
    end
  end
end

#table(options = {}) ⇒ Object



240
241
242
243
244
245
246
# File 'app/helpers/glib/json_ui/page_helper.rb', line 240

def table(options = {})
  json.body do
    json.childViews do
      @view_builder.add_view('panels_table', options.reverse_merge(width: 'matchParent'))
    end
  end
end

#template(template) ⇒ Object

def rightNavButtons

json.rightNavButtons do
  yield @menu_builder
end

end



171
172
173
# File 'app/helpers/glib/json_ui/page_helper.rb', line 171

def template(template)
  json.template template
end

#vertical_content(options) ⇒ Object



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'app/helpers/glib/json_ui/page_helper.rb', line 276

def vertical_content(options)
  # TODO: try disabling this
  # options = options.reverse_merge(width: 'matchParent')

  if (styleClass = options.delete(:styleClass))
    json.styleClasses [styleClass]
  end

  [:styleClasses, :padding, :backgroundColor, :width, :height].each do |name|
    if (value = options.delete(name))
      json.set! name, value
    end
  end
  json.childViews do
    if (childViews = options.delete(:childViews))
      childViews.call @view_builder
    end
  end

  raise "Invalid properties: #{options.keys}" if options.size > 0
end