Class: ICFS::Web::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/icfs/web/client.rb

Overview

Web Client

Instance Method Summary collapse

Constructor Details

#initialize(css, js) ⇒ Client

New instance

Parameters:

  • css (String)

    the URL for the stylesheet

  • js (String)

    the URL for the javascript



34
35
36
37
# File 'lib/icfs/web/client.rb', line 34

def initialize(css, js)
  @css = css.freeze
  @js = js.freeze
end

Instance Method Details

#call(env) ⇒ Object

A Rack call

Parameters:

  • env (Hash)

    the Rack environment



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/icfs/web/client.rb', line 45

def call(env)

  # grab the path components
  path = env['PATH_INFO']
  if path.empty?
    cmps = ['']
  else
    cmps = path.split('/', -1)
    cmps.shift if cmps[0].empty?
    cmps = [''] if cmps.empty?
  end
  env['icfs.cmps'] = cmps

  # reset
  env['icfs'].reset

  case cmps[0]

  # search
  when 'case_search'
    return _call_search(env,
      'Case Search',
      'Case Search',
      QueryCase,
      ListCase,
      :case_search,
      Proc.new{|qu, txt| _a_case_search(env, qu, txt) }
    )

  when 'entry_search'
    return _call_search(env,
      'Entry Search',
      'Entry Search',
      QueryEntry,
      ListEntry,
      :entry_search,
      Proc.new{|qu, txt| _a_entry_search(env, qu, txt) }
    )

  when 'log_search'
    return _call_search(env,
      'Log Search',
      'Log Search',
      QueryLog,
      ListLog,
      :log_search,
      Proc.new{|qu, txt| _a_log_search(env, qu, txt) }
    )

  when 'action_search'
    return _call_search(env,
      'Action Search',
      'Action Search',
      QueryAction,
      ListAction,
      :action_search,
      Proc.new{|qu, txt| _a_action_search(env, qu, txt) }
    )

  when 'index_search'
    return _call_search(env,
      'Index Search',
      'Index Search',
      QueryIndex,
      ListIndex,
      :index_search,
      Proc.new{|qu, txt| _a_index_search(env, qu, txt) }
    )

  when 'index_lookup'; return _call_index_lookup(env)

  # aggregations
  when 'stats'
    return _call_search(env,
      'Stats Search',
      'Stats Search',
      QueryStats,
      ListStats,
      :stats,
      nil
    )

  when 'case_tags'
    return _call_search(env,
      'Case Tags',
      'Case Tags Search',
      QueryCaseTags,
      ListCaseTags,
      :case_tags,
      nil
    )

  when 'entry_tags'
    return _call_search(env,
      'Entry Tags',
      'Entry Tag Search',
      QueryEntryTags,
      ListEntryTags,
      :entry_tags,
      nil
    )

  when 'action_tags'
    return _call_search(env,
      'Action Tags',
      'Action Tag Search',
      QueryActionTags,
      ListActionTags,
      :action_tags,
      nil
    )

  when 'index_tags'
    return _call_search(env,
      'Index Tags',
      'Index Tag Search',
      QueryIndexTags,
      ListIndexTags,
      :index_tags,
      nil
    )

  # forms
  when 'case_create'; return _call_case_create(env)
  when 'case_edit'; return _call_case_edit(env)
  when 'entry_edit'; return _call_entry_edit(env)
  when 'index_edit'; return _call_index_edit(env)
  when 'action_edit'; return _call_action_edit(env)
  when 'config_edit'; return _call_config_edit(env)

  # view
  when 'home', ''; return _call_home(env)
  when 'case'; return _call_case(env)
  when 'entry'; return _call_entry(env)
  when 'log'; return _call_log(env)
  when 'action'; return _call_action(env)
  when 'index'; return _call_index(env)
  when 'file'; return _call_file(env)

  # info page
  when 'info'; return _call_info(env)

  # not supported path
  else
    env['icfs.page'] = 'Invalid'
    raise(Error::NotFound, 'Invalid request')
  end

rescue Error::NotFound => e
  return _resp_notfound( env, 'Not found: %s' %
    Rack::Utils.escape_html(e.message) )

rescue Error::Perms => e
  return _resp_forbidden( env, 'Forbidden: %s' %
    Rack::Utils.escape_html(e.message) )

rescue Error::Conflict => e
  return _resp_conflict( env, 'Conflict: %s' %
    Rack::Utils.escape_html(e.message) )

rescue Error::Value => e
  return _resp_badreq( env, 'Invalid values: %s' %
    Rack::Utils.escape_html(e.message) )

rescue Error::Interface => e
  return _resp_badreq(env, Rack::Utils.escape_html(e.message))

end