Class: WAB::UI::RestFlow

Inherits:
Flow show all
Defined in:
lib/wab/ui/rest_flow.rb

Overview

A Flow controller that builds up a set of displays and provides those display descriptions when a read is called. The REST UI is built based on the template and list_paths provided in the initializer.

The display can be modified or subclassing by changing the View, Create, and Update classes.

Instance Attribute Summary

Attributes inherited from Flow

#displays, #entry

Attributes inherited from Controller

#shell

Instance Method Summary collapse

Methods inherited from Flow

#add_display, #get_display, #read

Methods inherited from Controller

#handle

Constructor Details

#initialize(shell, template, list_paths) ⇒ RestFlow

Creae a new instance based on the record template and path for the list display.

shell

shell containing the instancec

template

and example object with default values

list_paths

paths to values for the list display

Raises:



19
20
21
22
23
24
25
26
27
# File 'lib/wab/ui/rest_flow.rb', line 19

def initialize(shell, template, list_paths)
  super(shell)
  kind = template[:kind]
  raise WAB::ParseError.new('kind field missing from object template') if kind.nil?
  add_list(kind, template, list_paths)
  add_view(kind, template)
  add_create(kind, template)
  add_update(kind, template)
end

Instance Method Details

#add_create(kind, template) ⇒ Object

Adds an object creation specification.

kind

the type of record to create the list for

template

and example object with default values



63
64
65
66
67
68
69
70
# File 'lib/wab/ui/rest_flow.rb', line 63

def add_create(kind, template)
  id = "#{kind}.create"
  transitions = {
    save: "#{kind}.view",
    cancel: "#{kind}.list",
  }
  add_display(Create.new(kind, id, template, transitions))
end

#add_list(kind, template, list_paths) ⇒ Object

Add a listdisplay to the spec delivered to the UI.

kind

the type of record to create the list for

template

and example object with default values

list_paths

paths to values for the list display



34
35
36
37
38
39
40
41
42
43
# File 'lib/wab/ui/rest_flow.rb', line 34

def add_list(kind, template, list_paths)
  id = "#{kind}.list"
  transitions = {
    create: "#{kind}.create",
    view: "#{kind}.view",
    edit: "#{kind}.update",
    delete: id,
  }
  add_display(List.new(kind, id, template, list_paths, transitions), true)
end

#add_update(kind, template) ⇒ Object

Adds an object update specification.

kind

the type of record to create the list for

template

and example object with default values



76
77
78
79
80
81
82
83
84
85
# File 'lib/wab/ui/rest_flow.rb', line 76

def add_update(kind, template)
  id = "#{kind}.update"
  transitions = {
    save: "#{kind}.view",
    cancel: "#{kind}.view",
    list: "#{kind}.list",
    delete: "#{kind}.list",
  }
  add_display(Update.new(kind, id, template, transitions))
end

#add_view(kind, template) ⇒ Object

Adds an object view specification.

kind

the type of record to create the list for

template

and example object with default values



49
50
51
52
53
54
55
56
57
# File 'lib/wab/ui/rest_flow.rb', line 49

def add_view(kind, template)
  id = "#{kind}.view"
  transitions = {
    edit: "#{kind}.update",
    list: "#{kind}.list",
    delete: "#{kind}.list",
  }
  add_display(View.new(kind, id, template, transitions))
end