omf_web 0.9.9 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +31 -0
  3. data/bin/omf_web_server.rb +157 -0
  4. data/doc/screenshot2.png +0 -0
  5. data/doc/widget_detail.png +0 -0
  6. data/example/demo/data_sources/downloads.rb +2 -1
  7. data/example/simple/README.md +12 -13
  8. data/example/simple/create_waveform.rb +29 -0
  9. data/example/simple/introduction.md +17 -0
  10. data/example/simple/sample.sq3 +0 -0
  11. data/example/simple/sample.sql +1008 -0
  12. data/example/simple/simple.yaml +62 -0
  13. data/example/simple/simple_dynamic.yaml +66 -0
  14. data/lib/irods4r/file.rb +15 -14
  15. data/lib/irods4r/icommands.rb +18 -18
  16. data/lib/irods4r.rb +9 -9
  17. data/lib/omf-web/config.ru +41 -16
  18. data/lib/omf-web/content/git_repository.rb +32 -31
  19. data/lib/omf-web/content/irods_repository.rb +34 -33
  20. data/lib/omf-web/content/repository.rb +48 -44
  21. data/lib/omf-web/data_source_proxy.rb +33 -22
  22. data/lib/omf-web/rack/session_authenticator.rb +48 -12
  23. data/lib/omf-web/rack/tab_mapper.rb +30 -36
  24. data/lib/omf-web/rack/websocket_handler.rb +26 -25
  25. data/lib/omf-web/session_store.rb +16 -13
  26. data/lib/omf-web/theme/abstract_page.rb +26 -22
  27. data/lib/omf-web/theme/bright/page.rb +84 -34
  28. data/lib/omf-web/theme/bright/stacked_renderer.rb +20 -19
  29. data/lib/omf-web/theme.rb +14 -9
  30. data/lib/omf-web/thin/runner.rb +38 -36
  31. data/lib/omf-web/thin/server.rb +255 -0
  32. data/lib/omf-web/version.rb +1 -1
  33. data/lib/omf-web/widget/data_widget.rb +6 -6
  34. data/lib/omf-web/widget/text/maruku/helpers.rb +33 -30
  35. data/lib/omf-web/widget/text/maruku/input/parse_block.rb +117 -117
  36. data/lib/omf-web/widget/text/maruku/output/to_html.rb +155 -154
  37. data/lib/omf-web/widget/text/maruku.rb +17 -16
  38. data/omf_web.gemspec +6 -2
  39. data/sample.sq3 +0 -0
  40. data/share/htdocs/graph/js/gauge.js +524 -0
  41. data/share/htdocs/vendor/VERSION_MAP.yaml +3 -3
  42. data/share/htdocs/vendor/backbone-1.0.0/backbone.js +1571 -0
  43. data/share/htdocs/vendor/d3-3.0/LICENSE.brewer.txt +38 -0
  44. data/share/htdocs/vendor/d3-3.0/colorbrewer.js +1 -0
  45. data/share/htdocs/vendor/d3-3.0/d3.js +8810 -0
  46. data/share/htdocs/vendor/d3-3.0/d3.min.js +5 -0
  47. data/share/htdocs/vendor/geo_json/Readme.txt +71 -0
  48. data/share/htdocs/vendor/geo_json/regions.json +41 -0
  49. data/share/htdocs/vendor/geo_json/switzerland.json +24 -0
  50. data/share/htdocs/vendor/geo_json/world.json +497 -0
  51. data/share/htdocs/vendor/nv_d3/js/nv.d3.js +8801 -4447
  52. data/share/htdocs/vendor/spin/jquery.spin.js +46 -0
  53. data/share/htdocs/vendor/spin/spin.js +349 -0
  54. data/share/htdocs/vendor/spin/spin.min.js +1 -0
  55. data/share/htdocs/vendor/underscore-1.4.4/underscore.js +1227 -0
  56. metadata +63 -48
  57. data/example/simple/data_sources/gimi31.sq3 +0 -0
  58. data/example/simple/data_sources/ping_source.rb +0 -56
  59. data/example/simple/simple_viz_server.rb +0 -39
  60. data/example/simple/widgets/charts_tab.yaml +0 -38
  61. data/share/.DS_Store +0 -0
  62. data/share/htdocs/.DS_Store +0 -0
  63. data/share/htdocs/vendor/backbone-0.5.3/backbone.js +0 -1158
  64. data/share/htdocs/vendor/underscore-1.2.1/underscore.js +0 -958
@@ -9,10 +9,10 @@ require 'omf-web/session_store'
9
9
  require 'omf-web/widget'
10
10
  require 'omf-web/theme'
11
11
 
12
-
13
- module OMF::Web::Rack
12
+
13
+ module OMF::Web::Rack
14
14
  class TabMapper < OMF::Common::LObject
15
-
15
+
16
16
 
17
17
  def initialize(opts = {})
18
18
  @opts = opts
@@ -20,38 +20,31 @@ module OMF::Web::Rack
20
20
  @tabs = {}
21
21
  find_tabs()
22
22
  end
23
-
23
+
24
24
  def find_tabs()
25
25
  tabs = OMF::Web::Widget.toplevel_widgets(@opts[:use_tabs])
26
- @enabled_tabs = {}
27
- tabs.each do |t|
26
+ @enabled_tabs = {}
27
+ tabs.each do |t|
28
28
  name = t[:id].to_sym
29
- @enabled_tabs[name] = t
29
+ @enabled_tabs[name] = t
30
30
  end
31
31
  @opts[:tabs] = tabs
32
32
  end
33
-
33
+
34
34
  def call(env)
35
35
  #puts env.keys.inspect
36
36
 
37
37
  req = ::Rack::Request.new(env)
38
- #puts "COOKIES>>>> #{req.cookies.inspect}"
39
- #req.cookies['user'] = 'booo'
40
-
41
- # sessionID = req.params['sid']
42
- # if sessionID.nil? || sessionID.empty?
43
- # sessionID = "s#{(rand * 10000000).to_i}"
44
- # end
45
- # Thread.current["sessionID"] = sessionID
46
-
47
- OMF::Web::Theme.require 'page'
38
+ debug "Requesting #{req.path}"
39
+
40
+ OMF::Web::Theme.require 'page'
48
41
  body, headers = render_page(req)
49
42
  if headers.kind_of? String
50
43
  headers = {"Content-Type" => headers}
51
44
  end
52
- [200, headers, [body]] # required for ruby > 1.9.2
45
+ [200, headers, [body]] # required for ruby > 1.9.2
53
46
  end
54
-
47
+
55
48
  def _component_name(path)
56
49
  unless comp_name = path[1]
57
50
  comp_name = ((@opts[:tabs] || [])[0] || {})[:id]
@@ -60,17 +53,18 @@ module OMF::Web::Rack
60
53
  #puts "PATH: #{path} - #{comp_name}"
61
54
  comp_name
62
55
  end
63
-
56
+
64
57
  def render_card(req)
65
58
  #puts ">>>> REQ: #{req.path_info}::#{req.inspect}"
66
-
59
+
67
60
  opts = @opts.dup
68
61
  opts[:prefix] = req.script_name
69
- opts[:request] = req
62
+ opts[:request] = req
70
63
  opts[:path] = req.path_info
71
64
 
72
65
  path = req.path_info.split('/')
73
66
  unless comp_name = _component_name(path)
67
+ puts ">>>>> #{path} - #{opts[:tabs]}"
74
68
  return render_no_card(opts)
75
69
  end
76
70
  opts[:component_name] = comp_name.to_sym
@@ -82,24 +76,24 @@ module OMF::Web::Rack
82
76
  return render_unknown_card(comp_name, opts)
83
77
  end
84
78
  opts[:tab] = tab_id = tab[:id]
85
-
79
+
86
80
  widget = find_top_widget(tab, req)
87
81
  OMF::Web::Theme.require 'page'
88
82
  page = OMF::Web::Theme::Page.new(widget, opts)
89
83
  [page.to_html, 'text/html']
90
84
  end
91
-
92
-
85
+
86
+
93
87
  def find_top_widget(tab, req)
94
88
  sid = req.params['sid']
95
89
  tab_id = tab[:id]
96
- @tabs[tab_id] ||= OMF::Web::Widget.create_widget(tab_id)
97
- #inst = OMF::Web::SessionStore[tab_id, :tab]
90
+ @tabs[tab_id] ||= OMF::Web::Widget.create_widget(tab_id)
91
+ #inst = OMF::Web::SessionStore[tab_id, :tab]
98
92
  end
99
-
93
+
100
94
  def render_unknown_card(comp_name, popts)
101
95
  #popts[:active_id] = 'unknown'
102
- popts[:flash] = {:alert => %{Unknonw component '#{comp_name}'. To select any of the available
96
+ popts[:flash] = {:alert => %{Unknonw component '#{comp_name}'. To select any of the available
103
97
  components, please click on one of the tabs above.}}
104
98
 
105
99
  [OMF::Web::Theme::Page.new(nil, popts).to_html, 'text/html']
@@ -108,18 +102,18 @@ module OMF::Web::Rack
108
102
  def render_no_card(popts)
109
103
  popts[:active_id] = 'unknown'
110
104
  popts[:flash] = {:alert => %{There are no components defined for this site.}}
111
- popts[:tabs] = []
105
+ popts[:tabs] = []
112
106
  [OMF::Web::Theme::Page.new(nil, popts).to_html, 'text/html']
113
107
  end
114
-
108
+
115
109
  def render_page(req)
116
110
  render_card(req)
117
111
  end
118
-
112
+
119
113
  end # Tab Mapper
120
-
114
+
121
115
  end # OMF:Common::Web2
122
116
 
123
117
 
124
-
125
-
118
+
119
+
@@ -1,22 +1,23 @@
1
1
 
2
+
2
3
  require 'rack/websocket'
3
4
  require 'omf_common/lobject'
4
5
  require 'omf-web/session_store'
5
6
  require 'thread'
6
7
 
7
8
  module OMF::Web::Rack
8
-
9
+
9
10
  class WebsocketHandler < ::Rack::WebSocket::Application
10
11
  include OMF::Common::Loggable
11
- extend OMF::Common::Loggable
12
-
13
- MESSAGE_DELAY = 0.5 # Delay in pushing action message to browser
14
- # after receiving a 'on_change' from monitored data proxy
15
-
12
+ extend OMF::Common::Loggable
13
+
14
+ MESSAGE_DELAY = 0.5 # Delay in pushing action message to browser
15
+ # after receiving a 'on_change' from monitored data proxy
16
+
16
17
  def on_open(env)
17
18
  #puts ">>>>> OPEN"
18
- end
19
-
19
+ end
20
+
20
21
  def on_message(env, msg_s)
21
22
  begin
22
23
  req = ::Rack::Request.new(env)
@@ -41,7 +42,7 @@ module OMF::Web::Rack
41
42
  send_data({type: 'reply', status: 'exception', err_msg: ex.to_s}.to_json)
42
43
  end
43
44
  end
44
-
45
+
45
46
  def on_close(env)
46
47
  begin
47
48
  debug "client disconnected"
@@ -51,29 +52,29 @@ module OMF::Web::Rack
51
52
  error(ex)
52
53
  end
53
54
  end
54
-
55
+
55
56
  def on_register_data_source(args, context)
56
57
  dsp = find_data_source(args)
57
58
  return unless dsp # should define appropriate exception
58
59
  debug "Received registration for datasource proxy '#{dsp}'"
59
60
  send_data({type: 'reply', status: 'ok'}.to_json)
60
-
61
+
61
62
  mutex = Mutex.new
62
63
  semaphore = ConditionVariable.new
63
64
  action_queue = {}
64
-
65
+
65
66
  dsp.on_changed(args['offset']) do |action, rows|
66
67
  mutex.synchronize do
67
68
  (action_queue[action] ||= []).concat(rows)
68
69
  semaphore.signal
69
70
  end
70
71
  end
71
-
72
+
72
73
  # Send the rows in a separate thread, waiting a bit after the first one arriving
73
74
  # to 'bunch' things into more manageable number of messages
74
75
  Thread.new do
75
- begin
76
- loop do
76
+ begin
77
+ loop do
77
78
  # Now lets send them
78
79
  mutex.synchronize do
79
80
  action_queue.each do |action, rows|
@@ -86,14 +87,14 @@ module OMF::Web::Rack
86
87
  action: action
87
88
  #offset: offset
88
89
  }
89
- send_data(msg.to_json)
90
+ send_data(msg.to_json.force_encoding("UTF-8"))
90
91
  rows.clear
91
92
  end
92
93
 
93
94
  # wait until there is more to send
94
95
  semaphore.wait(mutex)
95
96
  end
96
-
97
+
97
98
  # OK, there is something to do, but let's wait a bit, maybe there is more
98
99
  sleep MESSAGE_DELAY
99
100
  end
@@ -102,19 +103,19 @@ module OMF::Web::Rack
102
103
  debug "#{ex.backtrace.join("\n")}"
103
104
  end
104
105
  end
105
-
106
+
106
107
  end
107
-
108
+
108
109
  # args {"slice"=>{"col_name"=>"id", "col_value"=>"e8..."}, "ds_name"=>"individual_link"}}
109
110
  def on_request_slice(args, context)
110
111
  dsp = find_data_source(args)
111
112
  return unless dsp # should define appropriate exception
112
-
113
+
113
114
  sargs = args['slice']
114
115
  col_name = sargs['col_name']
115
116
  col_value = sargs['col_value']
116
117
  debug "Creating slice '#{col_name}:#{col_value}' data source '#{dsp}'"
117
-
118
+
118
119
  if old_sdsp = context[:sliced_datasource]
119
120
  return if old_sdsp[:column_name] == col_name
120
121
  old_sdsp[:dsp].release
@@ -129,8 +130,8 @@ module OMF::Web::Rack
129
130
  action: action
130
131
  #offset: offset
131
132
  }
132
- send_data(msg.to_json)
133
- #
133
+ send_data(msg.to_json.force_encoding("UTF-8"))
134
+ #
134
135
  # do |new_rows, offset|
135
136
  # msg = {
136
137
  # type: 'datasource_update',
@@ -141,7 +142,7 @@ module OMF::Web::Rack
141
142
  # send_data(msg.to_json)
142
143
  end
143
144
  end
144
-
145
+
145
146
  def find_data_source(args)
146
147
  ds_name = args['ds_name']
147
148
  unless dsp = OMF::Web::DataSourceProxy[ds_name]
@@ -153,5 +154,5 @@ module OMF::Web::Rack
153
154
  end
154
155
 
155
156
  end # WebsocketHandler
156
-
157
+
157
158
  end # module
@@ -3,18 +3,18 @@ require 'omf_common/lobject'
3
3
 
4
4
 
5
5
  module OMF::Web
6
-
6
+
7
7
  # Keeps session state.
8
8
  #
9
9
  # TODO: Implement cleanup thread
10
10
  #
11
11
  class SessionStore < OMF::Common::LObject
12
12
  @@sessions = {}
13
-
13
+
14
14
  def self.[](key, domain)
15
15
  self.session["#{domain}:#{key}"]
16
16
  end
17
-
17
+
18
18
  def self.[]=(key, domain, value)
19
19
  self.session["#{domain}:#{key}"] = value
20
20
  end
@@ -25,30 +25,33 @@ module OMF::Web
25
25
  #puts "STORE>> #{sid} = #{session[:content].keys.inspect}"
26
26
  session[:ts] = Time.now
27
27
  session[:content]
28
- end
29
-
28
+ end
29
+
30
30
  def self.session_id
31
31
  sid = Thread.current["sessionID"]
32
- unless sid
33
- raise "Missing session id 'sid'"
34
- end
32
+ raise "Missing session id 'sid'" if sid.nil?
33
+ sid
35
34
  end
36
-
35
+
37
36
  def self.find_tab_from_path(comp_path)
38
37
  sid = comp_path.shift
39
38
  unless session = self.session(sid)
40
39
  raise "Can't find session '#{sid}', may have timed out"
41
40
  end
42
41
  tid = comp_path.shift.to_sym
43
- unless tab_inst = session[tid]
44
- raise "Can't find tab '#{tid}'"
42
+ unless tab_inst = session[tid]
43
+ raise "Can't find tab '#{tid}'"
45
44
  end
46
45
  {:sid => sid, :tab_inst => tab_inst, :sub_path => comp_path}
47
46
  end
47
+
48
+ def self.find_across_sessions(&block)
49
+ @@sessions.values.map { |v| v[:content] }.find(&block)
50
+ end
48
51
  end # SessionStore
49
52
 
50
53
  end # OMF:Web
51
54
 
52
55
 
53
-
54
-
56
+
57
+
@@ -4,40 +4,45 @@ require 'omf-web/data_source_proxy'
4
4
 
5
5
  module OMF::Web::Theme
6
6
  class AbstractPage < Erector::Widget
7
-
7
+
8
8
  depends_on :js, '/resource/vendor/stacktrace/stacktrace.js'
9
9
  depends_on :js, '/resource/vendor/jquery/jquery.js'
10
10
  #depends_on :js, '/resource/js/stacktrace.js'
11
11
  depends_on :js, '/resource/vendor/underscore/underscore.js'
12
- depends_on :js, '/resource/vendor/backbone/backbone.js'
12
+ depends_on :js, '/resource/vendor/backbone/backbone.js'
13
13
  depends_on :js, "/resource/js/require3.js"
14
14
 
15
15
  depends_on :js, "/resource/theme/abstract/abstract.js"
16
- depends_on :js, "/resource/js/data_source2.js"
16
+ depends_on :js, "/resource/js/data_source2.js"
17
17
 
18
18
  attr_reader :opts
19
-
19
+
20
+ def self.add_depends_on(type, url)
21
+ depends_on type.to_sym, url
22
+ end
23
+
20
24
  def initialize(widget, opts)
21
25
  #puts "KEYS>>>>> #{opts.keys.inspect}"
22
26
  super opts
23
27
  @widget = widget
24
28
  @opts = opts
25
29
  end
26
-
30
+
27
31
  def content
28
32
  javascript %{
29
33
  if (typeof(LW) == "undefined") LW = {};
30
34
  LW.session_id = OML.session_id = '#{Thread.current["sessionID"]}';
31
-
32
- L.provide('jquery', ['vendor/jquery/jquery.js']);
33
- //L.provide('jquery.periodicalupdater', ['vendor/jquery/jquery.periodicalupdater.js']);
35
+
36
+ //L.provide('jquery', ['vendor/jquery/jquery.js']);
37
+ L.already_loaded('/resource/vendor/jquery/jquery.js');
38
+ //L.provide('jquery.periodicalupdater', ['vendor/jquery/jquery.periodicalupdater.js']);
34
39
  //L.provide('jquery.ui', ['vendor/jquery-ui/js/jquery-ui.min.js']);
35
- }
40
+ }
36
41
  end
37
42
 
38
43
  def render_flash
39
44
  return unless @flash
40
- if @flash[:notice]
45
+ if @flash[:notice]
41
46
  div :class => 'flash_notice flash' do
42
47
  text @flash[:notice]
43
48
  end
@@ -55,7 +60,7 @@ module OMF::Web::Theme
55
60
  end
56
61
  end
57
62
  end # render_flesh
58
-
63
+
59
64
  # Return an array of widgets to collect data sources from
60
65
  #
61
66
  def data_source_widgets
@@ -66,13 +71,13 @@ module OMF::Web::Theme
66
71
  [@widget]
67
72
  # end
68
73
  end
69
-
74
+
70
75
  def render_data_sources
71
76
  return unless @widget
72
-
77
+
73
78
  require 'omf_oml/table'
74
79
  require 'set'
75
-
80
+
76
81
  dss = Set.new
77
82
  data_source_widgets.each do |w|
78
83
  w.collect_data_sources(dss)
@@ -86,11 +91,11 @@ module OMF::Web::Theme
86
91
 
87
92
  #puts ">>>> #{dsh.inspect}"
88
93
  return if dss.empty?
89
-
94
+
90
95
  js = dss.map do |ds|
91
96
  render_data_source(ds)
92
97
  end
93
-
98
+
94
99
  # js = dsh.values.to_a.collect do |ds|
95
100
  # render_data_source(ds)
96
101
  # end
@@ -103,7 +108,7 @@ module OMF::Web::Theme
103
108
  </script>
104
109
  }
105
110
  end
106
-
111
+
107
112
  def render_data_source(ds)
108
113
  dspa = OMF::Web::DataSourceProxy.for_source(ds)
109
114
  dspa.collect do |dsp|
@@ -111,7 +116,7 @@ module OMF::Web::Theme
111
116
  dsp.to_javascript(ds)
112
117
  end.join("\n")
113
118
  end
114
-
119
+
115
120
  def render_additional_headers
116
121
  #"\n\n<link href='/resource/css/incoming.css' media='all' rel='stylesheet' type='text/css' />\n"
117
122
  end
@@ -119,9 +124,9 @@ module OMF::Web::Theme
119
124
  def collect_data_sources(dsa)
120
125
  dsa
121
126
  end
122
-
127
+
123
128
  def to_html(opts = {})
124
- page_title = @title # context may get screwed up below, so put title into scope
129
+ page_title = @page_title # context may get screwed up below, so put title into scope
125
130
  b = super
126
131
  if @opts[:request].params.key?('embedded')
127
132
  b
@@ -141,9 +146,8 @@ module OMF::Web::Theme
141
146
  end
142
147
  end
143
148
  end
144
- r.to_html(opts)
149
+ r.to_html(opts)
145
150
  end
146
151
  end
147
152
  end # class AbstractPage
148
153
  end # OMF::Web::Theme
149
-
@@ -1,37 +1,37 @@
1
1
  require 'omf-web/theme/abstract_page'
2
- require 'omf-web/rack/session_authenticator'
2
+ require 'omf-web/rack/session_authenticator'
3
3
 
4
4
  module OMF::Web::Theme
5
5
  class Page < OMF::Web::Theme::AbstractPage
6
-
6
+
7
7
  depends_on :css, '/resource/theme/bright/css/reset-fonts-grids.css'
8
8
  depends_on :css, "/resource/theme/bright/css/bright.css"
9
-
9
+
10
10
  depends_on :script, %{
11
11
  OML.session_id = '#{Thread.current["sessionID"]}'
12
12
  OML.show_widget = function(opts) {
13
13
  var prefix = opts.inner_class;
14
14
  var index = opts.index;
15
15
  var widget_id = opts.widget_id;
16
-
16
+
17
17
  $('.' + prefix).hide();
18
18
  $('#' + prefix + '_' + index).show();
19
-
19
+
20
20
  var current = $('#' + prefix + '_l_' + index);
21
21
  current.addClass('current');
22
22
  current.siblings().removeClass('current');
23
-
23
+
24
24
  // May be a bit overkill, but this should shake out the widgets hidden so far
25
- OHUB.trigger('layout.resize', {});
26
-
25
+ OHUB.trigger('layout.resize', {});
26
+
27
27
  return false;
28
28
  };
29
29
  }
30
-
30
+
31
31
  # def initialize(widget, opts)
32
32
  # super
33
33
  # end
34
-
34
+
35
35
  def content
36
36
  super
37
37
  @renderer = @widget.content
@@ -42,8 +42,8 @@ module OMF::Web::Theme
42
42
  render_top_line
43
43
  end
44
44
  if @renderer.render? :title
45
- h1 @page_title || 'Missing :page_title'
46
- end
45
+ render_title
46
+ end
47
47
  end
48
48
  end
49
49
  div :id => 'bd' do
@@ -56,19 +56,19 @@ module OMF::Web::Theme
56
56
  end
57
57
  end
58
58
  end
59
-
59
+
60
60
  def render_top_line
61
61
  div :id => :top_line do
62
62
  render_tab_menu
63
63
  render_tools_menu
64
64
  end
65
65
  end
66
-
66
+
67
67
  def render_tab_menu
68
68
  ol :id => :tab_menu do
69
69
  @tabs.each do |h|
70
70
  lopts = h[:id] == @tab ? {:class => :current} : {}
71
- li lopts do
71
+ li lopts do
72
72
  #a :href => "#{@prefix}/#{h[:id]}?sid=#{Thread.current["sessionID"]}" do
73
73
  a :href => "#{@prefix}/#{h[:id]}" do
74
74
  span h[:name], :class => :tab_text
@@ -77,38 +77,88 @@ module OMF::Web::Theme
77
77
  end
78
78
  end
79
79
  end
80
-
80
+
81
+ # def render_tools_menu
82
+ # div :id => :tools_menu do
83
+ # render_authentication
84
+ # end
85
+ # end
86
+
81
87
  def render_tools_menu
82
- div :id => :tools_menu do
83
- render_authentication
88
+ ol :id => :tools_menu do
89
+ render_tools_menu_authenticate
84
90
  end
85
91
  end
86
-
87
- def render_authentication
88
- if OMF::Web::Rack::SessionAuthenticator.active?
89
- if OMF::Web::Rack::SessionAuthenticator.authenticated?
90
- # text OMF::Web::Rack::Session[:name]
91
- # text ' | '
92
- a 'Log out', :href => '/logout'
92
+
93
+ def render_tools_menu_authenticate
94
+ if user = OMF::Web::Rack::SessionAuthenticator.user()
95
+ puts "USER>>>>> #{user}"
96
+ li do
97
+ a href: '#', class: 'user' do
98
+ i class: "icon-user icon-white"
99
+ text user[:name]
100
+ end
101
+ end
102
+ li id: 'logout_li' do
103
+ a id: 'logout_a', href: '#', class: 'logout' do
104
+ i class: "icon-off icon-white"
105
+ text 'Log out'
106
+ end
107
+ end
108
+ am = "render_tools_menu_authenticate_#{user[:method]}".to_sym
109
+ puts "METHOD>>>>> #{am}"
110
+ if respond_to?(am)
111
+ send(am, user)
93
112
  else
94
- a 'Log in', :href => '/tab/login'
113
+ javascript %{
114
+ $('#logout_a').href = '/auth/logout'
115
+ }
95
116
  end
96
117
  end
97
-
98
-
99
118
  end
100
-
119
+
120
+ def render_tools_menu_authenticate_persona(user)
121
+ javascript %{
122
+ $('#logout_li').hide();
123
+ $.getScript("https://login.persona.org/include.js")
124
+ .done(function(script, textStatus) {
125
+ $('#logout_li').show();
126
+ $('#logout_a').click(function() {
127
+ navigator.id.logout();
128
+ })
129
+ navigator.id.watch({
130
+ loggedInUser: '#{user}',
131
+ onlogin: function(assertion) {},
132
+ onlogout: function() {
133
+ $.ajax({
134
+ type: 'POST',
135
+ url: '/auth/logout',
136
+ success: function(res, status, xhr) {
137
+ window.location = '/';
138
+ },
139
+ error: function(xhr, status, err) { alert("Logout failure: " + err); }
140
+ });
141
+ }
142
+ })
143
+ });
144
+ }
145
+ end
146
+
147
+ def render_title
148
+ h1 @page_title || 'Missing :page_title'
149
+ end
150
+
101
151
  def render_body
102
152
  render_flash
103
153
  render_card_body
104
154
  end
105
-
155
+
106
156
  def render_card_body
107
157
  return unless @widget
108
158
  Thread.current["top_renderer"] = self
109
159
  rawtext @renderer.to_html
110
160
  end
111
-
161
+
112
162
  def render_footer
113
163
  if @footer_right.is_a? Proc
114
164
  widget(Erector.inline(&@footer_right))
@@ -122,11 +172,11 @@ module OMF::Web::Theme
122
172
  else
123
173
  text @footer_left || 'Brought to you by the TEMPO Team'
124
174
  end
125
-
175
+
126
176
  end
127
-
128
177
 
129
-
178
+
179
+
130
180
 
131
181
  end # class Page
132
182
  end # OMF::Web::Theme