omf_web 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/bin/omf_web_server +18 -0
  2. data/example/bridge/README.md +7 -0
  3. data/example/bridge/data_sources/sensor-sqlite.rb +15 -15
  4. data/example/bridge/htdocs/graph/js/bridge.js +35 -45
  5. data/example/bridge/htdocs/graph/js/event_line_chart.js +20 -18
  6. data/example/bridge/htdocs/graph/js/event_table.js +26 -28
  7. data/example/bridge/viz_server.rb +5 -9
  8. data/example/demo/demo_viz_server.rb +2 -2
  9. data/example/demo/widgets/linked_graphs_tab.yaml +9 -32
  10. data/example/openflow-gec15/code_tab.yaml +7 -12
  11. data/example/openflow-gec15/dashboard_tab.yaml +11 -12
  12. data/example/openflow-gec15/exp_source.rb +26 -26
  13. data/example/openflow-gec15/of_viz_server.rb +7 -7
  14. data/example/simple/simple.yaml +2 -1
  15. data/example/simple/simple_dynamic.yaml +1 -1
  16. data/example/web_rtc/web_rtc.yaml +54 -0
  17. data/example/web_rtc/webrtc-exp_1381786573.sq3 +0 -0
  18. data/lib/omf-web/config.ru +1 -1
  19. data/lib/omf-web/content/content_proxy.rb +2 -2
  20. data/lib/omf-web/content/file_repository.rb +11 -53
  21. data/lib/omf-web/content/git_repository.rb +1 -1
  22. data/lib/omf-web/content/irods_repository.rb +1 -1
  23. data/lib/omf-web/content/repository.rb +5 -3
  24. data/lib/omf-web/content/static_repository.rb +25 -11
  25. data/lib/omf-web/data_source_proxy.rb +3 -3
  26. data/lib/omf-web/rack/content_handler.rb +2 -2
  27. data/lib/omf-web/rack/session_authenticator.rb +3 -3
  28. data/lib/omf-web/rack/tab_mapper.rb +2 -2
  29. data/lib/omf-web/rack/update_handler.rb +2 -2
  30. data/lib/omf-web/rack/websocket_handler.rb +3 -3
  31. data/lib/omf-web/rack/widget_mapper.rb +2 -2
  32. data/lib/omf-web/session_store.rb +2 -2
  33. data/lib/omf-web/theme/abstract_page.rb +15 -24
  34. data/lib/omf-web/theme/bright/code_renderer.rb +24 -30
  35. data/lib/omf-web/theme/bright/data_renderer.rb +7 -5
  36. data/lib/omf-web/theme/bright/page.rb +2 -1
  37. data/lib/omf-web/theme/bright/widget_chrome.rb +16 -14
  38. data/lib/omf-web/theme.rb +1 -1
  39. data/lib/omf-web/thin/logging.rb +18 -13
  40. data/lib/omf-web/thin/runner.rb +2 -2
  41. data/lib/omf-web/thin/server.rb +105 -27
  42. data/lib/omf-web/version.rb +1 -1
  43. data/lib/omf-web/widget/abstract_widget.rb +3 -3
  44. data/lib/omf-web/widget/data_widget.rb +1 -0
  45. data/lib/omf-web/widget/text/maruku.rb +1 -1
  46. data/lib/omf-web/widget.rb +22 -22
  47. data/lib/omf_web.rb +1 -1
  48. data/omf_web.gemspec +18 -15
  49. data/share/htdocs/graph/js/abstract_chart.js +69 -68
  50. data/share/htdocs/graph/js/abstract_nv_chart.js +35 -33
  51. data/share/htdocs/graph/js/abstract_widget.js +61 -62
  52. data/share/htdocs/graph/js/axis.js +30 -25
  53. data/share/htdocs/graph/js/barchart_brush.js +23 -21
  54. data/share/htdocs/graph/js/code_mirror.js +35 -33
  55. data/share/htdocs/graph/js/discrete_bar_chart.js +27 -30
  56. data/share/htdocs/graph/js/histogram2.js +37 -47
  57. data/share/htdocs/graph/js/line_chart3.js +36 -30
  58. data/share/htdocs/graph/js/line_chart_with_focus.js +10 -9
  59. data/share/htdocs/graph/js/multi_barchart.js +33 -30
  60. data/share/htdocs/graph/js/network2.js +98 -97
  61. data/share/htdocs/graph/js/pie_chart2.js +25 -23
  62. data/share/htdocs/graph/js/scatter_plot.js +38 -36
  63. data/share/htdocs/graph/js/table2.js +60 -54
  64. data/share/htdocs/js/app.js +43 -0
  65. data/share/htdocs/js/{data_source2.js → data_source3.js} +44 -73
  66. data/share/htdocs/js/data_source_repo.js +42 -0
  67. data/share/htdocs/require/nv_d3.js +2 -0
  68. data/share/htdocs/theme/abstract/abstract.js +4 -4
  69. data/share/htdocs/vendor/VERSION_MAP.yaml +2 -0
  70. data/share/htdocs/vendor/require-2.1.8/require.js +2053 -0
  71. data/share/htdocs/vendor/require-2.1.8/require.min.js +36 -0
  72. data/share/htdocs/vendor/require-css-0.0.7/.gitignore +1 -0
  73. data/share/htdocs/vendor/require-css-0.0.7/LICENSE +10 -0
  74. data/share/htdocs/vendor/require-css-0.0.7/README.md +231 -0
  75. data/share/htdocs/vendor/require-css-0.0.7/bower.json +5 -0
  76. data/share/htdocs/vendor/require-css-0.0.7/css-builder.js +251 -0
  77. data/share/htdocs/vendor/require-css-0.0.7/css.js +436 -0
  78. data/share/htdocs/vendor/require-css-0.0.7/normalize.js +138 -0
  79. data/share/htdocs/vendor/require-css-0.0.7/package.json +5 -0
  80. data/share/htdocs/vendor/spin/jquery.spin.js +6 -4
  81. metadata +100 -74
  82. checksums.yaml +0 -7
  83. data/bin/omf_web_demo +0 -3
  84. data/bin/omf_web_demo.sh +0 -7
  85. data/bin/omf_web_server.rb +0 -157
  86. data/lib/omf_common/lobject.rb +0 -187
  87. data/lib/omf_common/log4r_outputter.rb +0 -69
  88. data/sample.sq3 +0 -0
  89. data/share/htdocs/js/data_source.js +0 -173
  90. data/share/htdocs/js/require3.js +0 -292
@@ -6,14 +6,23 @@ module OMF::Web::Theme
6
6
  class AbstractPage < Erector::Widget
7
7
 
8
8
  depends_on :js, '/resource/vendor/stacktrace/stacktrace.js'
9
+
10
+ depends_on :js, '/resource/vendor/require/require.js'
11
+ depends_on :js, '/resource/js/app.js'
12
+
13
+
9
14
  depends_on :js, '/resource/vendor/jquery/jquery.js'
10
- #depends_on :js, '/resource/js/stacktrace.js'
11
15
  depends_on :js, '/resource/vendor/underscore/underscore.js'
12
16
  depends_on :js, '/resource/vendor/backbone/backbone.js'
13
- depends_on :js, "/resource/js/require3.js"
14
17
 
18
+ # depends_on :js, "/resource/js/require3.js"
19
+ #
15
20
  depends_on :js, "/resource/theme/abstract/abstract.js"
16
- depends_on :js, "/resource/js/data_source2.js"
21
+ # depends_on :js, "/resource/js/data_source2.js"
22
+ depends_on :script, %{
23
+ // ABSTRACT PAGE
24
+ if (typeof(OML) == "undefined") OML = {};
25
+ }
17
26
 
18
27
  attr_reader :opts
19
28
 
@@ -29,15 +38,6 @@ module OMF::Web::Theme
29
38
  end
30
39
 
31
40
  def content
32
- javascript %{
33
- if (typeof(LW) == "undefined") LW = {};
34
- LW.session_id = OML.session_id = '#{Thread.current["sessionID"]}';
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']);
39
- //L.provide('jquery.ui', ['vendor/jquery-ui/js/jquery-ui.min.js']);
40
- }
41
41
  end
42
42
 
43
43
  def render_flash
@@ -82,28 +82,19 @@ module OMF::Web::Theme
82
82
  data_source_widgets.each do |w|
83
83
  w.collect_data_sources(dss)
84
84
  end
85
- #puts ">>>>>>>>>>> #{dss.inspect}"
86
- # dsh = {}
87
- # dss.each do |ds|
88
- # name = ds[:name].to_s
89
- # dsh[name] = ds.merge(dsh[name] || {})
90
- # end
91
-
92
- #puts ">>>> #{dsh.inspect}"
93
85
  return if dss.empty?
94
86
 
95
87
  js = dss.map do |ds|
96
88
  render_data_source(ds)
97
89
  end
98
90
 
99
- # js = dsh.values.to_a.collect do |ds|
100
- # render_data_source(ds)
101
- # end
102
91
  # Calling 'javascript' doesn't seem to work here. No idea why, so let's do it by hand
103
92
  %{
104
93
  <script type="text/javascript">
105
94
  // <![CDATA[
106
- #{js.join("\n")}
95
+ require(['omf/data_source_repo'], function(ds) {
96
+ #{js.join("\n")}
97
+ });
107
98
  // ]]>
108
99
  </script>
109
100
  }
@@ -5,16 +5,16 @@ require 'omf-web/theme/abstract_page'
5
5
  module OMF::Web::Theme
6
6
 
7
7
  class CodeRenderer < Erector::Widget
8
-
8
+
9
9
  #depends_on :css, "/resource/css/coderay.css"
10
-
10
+
11
11
  # This maps the content's mime type to a different mode supported
12
12
  # CodeMirror
13
13
  #
14
14
  MODE_MAPPER = {
15
15
  :markup => :markdown
16
16
  }
17
-
17
+
18
18
  def initialize(widget, content, mode, opts)
19
19
  super opts
20
20
  @widget = widget
@@ -22,9 +22,9 @@ module OMF::Web::Theme
22
22
  @mode = MODE_MAPPER[mode.to_sym] || mode
23
23
  @opts = opts
24
24
  end
25
-
25
+
26
26
  def content()
27
-
27
+
28
28
  base_id = "cm#{self.object_id}"
29
29
  edit_id = base_id + '_e'
30
30
  mode = @mode
@@ -35,16 +35,16 @@ module OMF::Web::Theme
35
35
  opts.delete :top_level
36
36
  opts.delete :priority
37
37
  opts.merge!(
38
- :base_el => "#" + base_id,
39
- :edit_el => '#' + edit_id,
40
- :content => @content.to_s,
38
+ :base_el => "#" + base_id,
39
+ :edit_el => '#' + edit_id,
40
+ :content => @content.to_s,
41
41
  :mode => mode,
42
42
  :content_id => @widget.content_id,
43
43
  :save_url => @widget.update_url
44
44
  )
45
45
 
46
46
  div :id => base_id, :class => "codemirror_widget" do
47
-
47
+
48
48
  js_toolbar = []
49
49
  div :class => "codemirror_toolbar_container widget-toolbar" do
50
50
  ol :class => "codemirror_toolbar" do
@@ -60,53 +60,47 @@ module OMF::Web::Theme
60
60
  OML.widgets.#{base_id}.on_#{name}_pressed();
61
61
  return false;
62
62
  });
63
- }
63
+ }
64
64
  end
65
65
  end
66
66
  end
67
-
67
+
68
68
  ['codemirror', 'util/dialog'].each do |f|
69
- link :href => "/resource/vendor/codemirror/lib/#{f}.css",
69
+ link :href => "/resource/vendor/codemirror/lib/#{f}.css",
70
70
  :media => "all", :rel => "stylesheet", :type => "text/css"
71
71
  end
72
72
 
73
73
  ['codemirror', 'util/dialog', 'util/searchcursor', 'util/search', 'util/loadmode'].each do |f|
74
74
  script :src => "/resource/vendor/codemirror/lib/#{f}.js"
75
75
  end
76
-
76
+
77
77
  #script :src => "/resource/vendor/codemirror/mode/xml/xml.js"
78
78
  #script :src => "/resource/vendor/codemirror/mode/#{mode}/#{mode}.js"
79
79
 
80
80
  # Div where the text should go
81
81
  div :id => edit_id, :class => "codemirror_edit" #, :style => 'height:100%'
82
-
82
+
83
83
  render_widget_creation(base_id, opts)
84
84
  javascript(%{
85
85
  #{js_toolbar.join("\n");}
86
86
  })
87
-
88
- end
87
+
88
+ end
89
89
  end
90
-
90
+
91
91
  def render_widget_creation(base_id, opts)
92
- link :href => "/resource/theme/bright/css/codemirror.css",
92
+ link :href => "/resource/theme/bright/css/codemirror.css",
93
93
  :media => "all", :rel => "stylesheet", :type => "text/css"
94
-
94
+
95
95
  javascript(%{
96
- L.require('#OML.code_mirror', 'graph/js/code_mirror', function() {
97
- OML.widgets.#{base_id} = new OML.code_mirror(#{opts.to_json});
96
+ require(['graph/code_mirror'], function(Graph) {
97
+ var w = OML.widgets.#{base_id} = new Graph(#{opts.to_json});
98
+ var i = 0;
98
99
  });
99
100
  })
101
+
100
102
  end
101
103
 
102
- # def content2()
103
- # link :href => "/resource/css/coderay.css",
104
- # :media => "all", :rel => "stylesheet", :type => "text/css"
105
- # div :class => "oml_code CodeRay" do
106
- # rawtext(@content.html :line_numbers => :inline, :tab_width => 2, :wrap => :div)
107
- # end
108
- # end
109
-
110
104
  end
111
-
105
+
112
106
  end
@@ -3,24 +3,26 @@ require 'omf-web/theme/abstract_page'
3
3
  module OMF::Web::Theme
4
4
 
5
5
  class DataRenderer < Erector::Widget
6
-
6
+
7
7
  def initialize(widget, opts)
8
8
  super opts
9
9
  @base_id = widget.dom_id
10
10
  @js_class = opts[:js_class]
11
11
  @js_url = opts[:js_url]
12
+ @js_module = opts[:js_module]
12
13
  @wopts = opts.dup
13
- end
14
+ end
14
15
 
15
16
  def content()
16
17
  div :id => @base_id, :class => "#{@js_class.gsub('.', '_').downcase}" do
17
18
  javascript(%{
18
- L.require('\##@js_class', '#@js_url', function() {
19
- OML.widgets.#{@base_id} = new #{@js_class}(#{@wopts.to_json});
19
+ require(['#@js_module'], function(Graph) {
20
+ var w = OML.widgets.#{@base_id} = new Graph(#{@wopts.to_json});
21
+ var i = 0;
20
22
  });
21
23
  })
22
24
  end
23
25
  end
24
-
26
+
25
27
  end
26
28
  end
@@ -8,7 +8,8 @@ module OMF::Web::Theme
8
8
  depends_on :css, "/resource/theme/bright/css/bright.css"
9
9
 
10
10
  depends_on :script, %{
11
- OML.session_id = '#{Thread.current["sessionID"]}'
11
+ if (typeof(OML) == "undefined") OML = {};
12
+ //OML.session_id = '#{Thread.current["sessionID"]}'
12
13
  OML.show_widget = function(opts) {
13
14
  var prefix = opts.inner_class;
14
15
  var index = opts.index;
@@ -2,22 +2,22 @@ require 'omf-web/theme/abstract_page'
2
2
 
3
3
  module OMF::Web::Theme
4
4
  class WidgetChrome < Erector::Widget
5
-
5
+
6
6
  def initialize(widget, inside_component, opts)
7
7
  super opts
8
8
  @widget = widget
9
9
  @inside_component = inside_component
10
10
  @opts = opts
11
- end
12
-
11
+ end
12
+
13
13
  def render_card_body
14
14
  rawtext @widget.content.to_html
15
15
  end
16
-
16
+
17
17
  def content
18
18
  render_widget(@widget)
19
19
  end
20
-
20
+
21
21
  def render_widget(widget)
22
22
  wid = "w#{widget.object_id}_c"
23
23
  div :class => :widget_container, :id => wid do
@@ -28,7 +28,7 @@ module OMF::Web::Theme
28
28
  render_widget_info(widget)
29
29
  render_widget_body(widget)
30
30
  render_widget_footer(widget)
31
- end
31
+ end
32
32
  end
33
33
  end
34
34
 
@@ -41,7 +41,7 @@ module OMF::Web::Theme
41
41
 
42
42
  def render_tools_menu
43
43
  menu = @opts[:menu] || {}
44
- span :class => 'widget_tools_menu', :style => 'float:right' do
44
+ span :class => 'widget_tools_menu', :style => 'float:right' do
45
45
  ol :class => :widget_tools_menu do
46
46
  menu.each do |m|
47
47
  lopts = {}
@@ -57,17 +57,19 @@ module OMF::Web::Theme
57
57
  a :id => "w#{object_id}_info_a", :href => "#" do
58
58
  span 'Info' , :class => :widget_tools_menu
59
59
  end
60
- end
61
- end
60
+ end
61
+ end
62
62
  end
63
- js = menu.map do |m|
63
+ js = menu.map do |m|
64
64
  %{
65
65
  $('\##{m[:id]}_a').click(function(){
66
66
  return #{m[:js_function]}(#{m.to_json});
67
67
  });
68
- }
68
+ }
69
69
  end
70
- javascript js.join("\n")
70
+ javascript %{
71
+ #{js.join("\n")}
72
+ }
71
73
  end
72
74
 
73
75
  def render_widget_info(widget)
@@ -75,7 +77,7 @@ module OMF::Web::Theme
75
77
  wp = "w#{object_id}"
76
78
  div :id => "#{wp}_info", :class => 'widget_info', :style => 'display:none' do
77
79
  text widget_info
78
- end
80
+ end
79
81
  javascript %{
80
82
  $('\##{wp}_info_a').click(function(){
81
83
  $('\##{wp}_info').slideToggle("slow");
@@ -95,7 +97,7 @@ module OMF::Web::Theme
95
97
 
96
98
  def render_widget_footer(widget)
97
99
  # NOTHING
98
- end
100
+ end
99
101
 
100
102
  end # class widget
101
103
  end # OMF::Web::Theme
data/lib/omf-web/theme.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
 
3
3
  module OMF::Web::Theme
4
- extend OMF::Common::Loggable
4
+ extend OMF::Base::Loggable
5
5
 
6
6
  DEFAULT_THEME = 'omf-web/theme/bright'
7
7
  @@search_order = [DEFAULT_THEME] # default theme
@@ -1,18 +1,18 @@
1
- require 'omf_common/lobject'
1
+ require 'omf_base/lobject'
2
2
 
3
3
  module Thin
4
- # Overwrite thin's logging mix-in to work more nicely
4
+ # Overwrite thin's logging mix-in to work more nicely
5
5
  # with log4r
6
6
  #
7
7
  module Logging
8
8
  class << self
9
9
  attr_writer :trace, :debug, :silent
10
-
10
+
11
11
  def trace?; !@silent && @trace end
12
12
  def debug?; !@silent && @debug end
13
13
  def silent?; @silent end
14
14
  end
15
-
15
+
16
16
  # # Global silencer methods
17
17
  # def silent
18
18
  # Logging.silent?
@@ -20,33 +20,38 @@ module Thin
20
20
  # def silent=(value)
21
21
  # Logging.silent = value
22
22
  # end
23
-
23
+
24
24
  # Log a message to the console
25
25
  def log(msg)
26
- (@logger ||= OMF::Common::LObject.new(self.class)).info(msg)
26
+ (@logger ||= OMF::Base::LObject.new(self.class)).info(msg)
27
27
  end
28
28
  module_function :log
29
29
  public :log
30
-
30
+
31
31
  # Log a message to the console if tracing is activated
32
32
  def trace(msg=nil)
33
- return unless msg
34
- (@logger ||= OMF::Common::LObject.new(self.class)).debug(msg)
33
+ ### DO NOT COMMIT!!!! Can't figure out where tracing is switched on
34
+ return
35
+ #####
36
+
37
+
38
+ return unless msg
39
+ (@logger ||= OMF::Base::LObject.new(self.class)).debug(msg)
35
40
  end
36
41
  module_function :trace
37
42
  public :trace
38
-
43
+
39
44
  # Log a message to the console if debugging is activated
40
45
  def debug(msg=nil)
41
46
  return unless msg
42
- (@logger ||= OMF::Common::LObject.new(self.class)).debug(msg)
47
+ (@logger ||= OMF::Base::LObject.new(self.class)).debug(msg)
43
48
  end
44
49
  module_function :debug
45
50
  public :debug
46
-
51
+
47
52
  # Log an error backtrace if debugging is activated
48
53
  def log_error(e = $!)
49
- (@logger ||= OMF::Common::LObject.new(self.class)).error(e)
54
+ (@logger ||= OMF::Base::LObject.new(self.class)).error(e)
50
55
  end
51
56
  module_function :log_error
52
57
  public :log_error
@@ -15,7 +15,7 @@ end
15
15
 
16
16
  module OMF::Web
17
17
  class Runner < Thin::Runner
18
- include OMF::Common::Loggable
18
+ include OMF::Base::Loggable
19
19
 
20
20
  @@instance = nil
21
21
 
@@ -89,7 +89,7 @@ module OMF::Web
89
89
  # Change the name of the root logger so we can apply different logging
90
90
  # policies depending on environment.
91
91
  #
92
- OMF::Common::Loggable.set_environment @options[:environment]
92
+ OMF::Base::Loggable.set_environment @options[:environment]
93
93
 
94
94
  if css = opts[:include_css]
95
95
  require 'omf-web/theme'
@@ -1,5 +1,5 @@
1
1
  require 'json'
2
- require 'omf_common/lobject'
2
+ require 'omf_base/lobject'
3
3
  require 'omf_web'
4
4
 
5
5
  module OMF::Web
@@ -9,17 +9,16 @@ module OMF::Web
9
9
  # USAGE:
10
10
  #
11
11
  #
12
- class Server < OMF::Common::LObject
12
+ class Server < OMF::Base::LObject
13
13
 
14
14
  def self.start(server_name, description, top_dir, opts = {})
15
15
  self.new(server_name, description, top_dir, opts)
16
16
  end
17
17
 
18
18
  def initialize(server_name, description, top_dir, opts)
19
- OMF::Common::Loggable.init_log server_name
20
-
19
+ OMF::Base::Loggable.init_log(server_name)
20
+ #OMF::Base::Loggable.init_log server_name
21
21
  opts = {
22
- static_dirs_pre: ["#{top_dir}/htdocs"],
23
22
  handlers: {
24
23
  pre_parse: lambda do |p, runner|
25
24
  p.on("--config CONF_FILE", "File holding description of web site") {|f| runner.options[:omf_config_file] = f}
@@ -32,8 +31,10 @@ module OMF::Web
32
31
  }
33
32
  }.merge(opts)
34
33
 
34
+ @server_name = server_name
35
35
  @top_dir = top_dir
36
36
  @databases = {}
37
+ @omsp_endpoints = {}
37
38
 
38
39
  OMF::Web.start(opts)
39
40
  end
@@ -49,9 +50,15 @@ module OMF::Web
49
50
  abort
50
51
  end
51
52
 
52
- @top_dir ||= File.dirname(cf)
53
+ @cfg_dir = File.dirname(cf)
54
+ opts[:static_dirs].insert(0, File.absolute_path(File.join(@cfg_dir, 'htdocs')))
55
+ @top_dir ||= @cfg_dir
53
56
  cfg = _rec_sym_keys(YAML.load_file(cf))
54
57
 
58
+ if log_opts = cfg[:logging]
59
+ # TODO: Deal with custom logging option
60
+ end
61
+
55
62
  (cfg[:server] || {}).each do |k, v|
56
63
  k = k.to_sym
57
64
  case k
@@ -82,29 +89,41 @@ module OMF::Web
82
89
  puts "Missing id in datasource configuration"
83
90
  abort
84
91
  end
85
- case type = config[:type] || 'database'
86
- when 'database'
87
- load_database(config)
88
- when 'file'
92
+ if config[:database]
93
+ load_database(id, config)
94
+ elsif config[:file]
89
95
  load_datasource_file(id, config)
96
+ elsif config[:omsp]
97
+ load_omsp_endpoint(id, config)
90
98
  else
91
- abort "Unknown datasource type '#{type}'."
99
+ abort "Unknown datasource type - #{config}"
92
100
  end
93
101
  end
94
102
 
95
- def load_database(config)
96
- unless table_name = config[:table]
97
- puts "Missing 'table' in datasource configuration '#{id}'"
98
- abort
99
- end
103
+ def load_database(id, config)
100
104
  unless db_cfg = config[:database]
101
- puts "Missing database configuration in datasource '#{id}'"
105
+ puts "Missing database configuration in datasource '#{config}'"
102
106
  abort
103
107
  end
104
108
  db = get_database(db_cfg)
105
- unless table = db.create_table(table_name)
106
- puts "Can't find table '#{table_name}' in database '#{db}'"
107
- abort
109
+ if query_s = config[:query]
110
+ unless schema = config[:schema]
111
+ puts "Missing schema configuration in datasource '#{config}'"
112
+ abort
113
+ end
114
+ require 'omf_oml/schema'
115
+ config[:schema] = OMF::OML::OmlSchema.create(schema)
116
+ table = db.create_table(id, config)
117
+ else
118
+ unless table_name = config.delete(:table)
119
+ puts "Missing 'table' in datasource configuration '#{config}'"
120
+ abort
121
+ end
122
+ config[:name] = id
123
+ unless table = db.create_table(table_name, config)
124
+ puts "Can't find table '#{table_name}' in database '#{db_cfg}'"
125
+ abort
126
+ end
108
127
  end
109
128
  OMF::Web.register_datasource table, name: id
110
129
  end
@@ -120,25 +139,30 @@ module OMF::Web
120
139
  puts "Database '#{config}' not defined - (#{@databases.keys})"
121
140
  abort
122
141
  end
123
- unless id = config[:id]
142
+ unless id = config.delete(:id)
124
143
  puts "Missing id in database configuration"
125
144
  abort
126
145
  end
146
+ if db = @databases[id.to_s] # already known
147
+ return db
148
+ end
149
+
127
150
  # unless id = config[:id]
128
151
  # puts "Database '#{config}' not defined - (#{@databases.keys})"
129
152
  # abort
130
153
  # end
131
- unless url = config[:url]
154
+ unless url = config.delete(:url)
132
155
  puts "Missing URL for database '#{id}'"
133
156
  abort
134
157
  end
135
- if url.start_with?('sqlite://') && ! url.start_with?('sqlite:///')
158
+ if url.start_with?('sqlite:') && ! url.start_with?('sqlite:/')
136
159
  # inject top dir
137
- url.insert('sqlite://'.length, @top_dir + '/')
160
+ url.insert('sqlite:'.length, '//' + @cfg_dir + '/')
138
161
  end
139
- puts "URL: #{url}"
162
+ config[:check_interval] ||= 3.0
163
+ puts "URL: #{url} - #{config}"
140
164
  begin
141
- return @databases[id] = OMF::OML::OmlSqlSource.new(url, :check_interval => 3.0)
165
+ return @databases[id] = OMF::OML::OmlSqlSource.new(url, config)
142
166
  rescue Exception => ex
143
167
  puts "Can't connect to database '#{id}' - #{ex}"
144
168
  abort
@@ -174,6 +198,17 @@ module OMF::Web
174
198
  OMF::Web.register_datasource ds, name: name
175
199
  end
176
200
 
201
+ def load_omsp_endpoint(id, config)
202
+ oconfig = config[:omsp]
203
+ unless port = oconfig[:port]
204
+ puts "Need port in OMSP definition '#{oconfig}' - datasource '#{id}'"
205
+ abort
206
+ end
207
+ ep = @omsp_endpoints[port] ||= OmspEndpointProxy.new(port)
208
+ ep.add_datasource(id, config)
209
+ end
210
+
211
+
177
212
  def load_repository(config)
178
213
  unless id = config[:id]
179
214
  puts "Missing id in respository configuration"
@@ -221,7 +256,7 @@ module OMF::Web
221
256
  # This class simulates a DataSource to transfer a JSON file as a database with one row and column
222
257
 
223
258
 
224
- class JSONDataSource < OMF::Common::LObject
259
+ class JSONDataSource < OMF::Base::LObject
225
260
 
226
261
  def initialize(file)
227
262
  raw = File.read(file)
@@ -251,5 +286,48 @@ module OMF::Web
251
286
  # do nothing
252
287
  end
253
288
  end
289
+
290
+ # This class manages an OMSP Endpoint and all the related
291
+ # data sources
292
+ #
293
+ class OmspEndpointProxy < OMF::Base::LObject
294
+ def initialize(port)
295
+ @streams = {}
296
+ @sources = {}
297
+ @tables = {}
298
+ require 'omf_oml/endpoint'
299
+ @ep = OMF::OML::OmlEndpoint.new(port)
300
+ @ep.on_new_stream() do |name, stream|
301
+ _on_new_stream(name, stream)
302
+ end
303
+ Thread.new do # delay starting up endpoint, can't use EM yet
304
+ sleep 2
305
+ @ep.run(false)
306
+ end
307
+ end
308
+
309
+ def add_datasource(name, config)
310
+ stream_name = config[:omsp][:stream_name] || name
311
+ config.delete(:omsp)
312
+ (@sources[stream_name.to_s] ||= []) << config
313
+ end
314
+
315
+ def _on_new_stream(name, stream)
316
+ debug "New stream: #{name}-#{stream}"
317
+ (@sources[name] || []).each do |tdef|
318
+ puts "TDEF: #{tdef}"
319
+ tname = tdef.dup.delete(:id)
320
+ unless table = @tables[tname]
321
+ table = @tables[tname] = stream.create_table(tname, tdef)
322
+ OMF::Web.register_datasource table
323
+ puts "ADDED: #{table}"
324
+ else
325
+ warn "Looks like reconnection, should reconnect to table as well"
326
+ end
327
+ end
328
+ end
329
+
330
+ end # class OmspEndpointProxy
331
+
254
332
  end # class
255
333
  end # module
@@ -1,7 +1,7 @@
1
1
 
2
2
  module OMF
3
3
  module Web
4
- VERSION = '1.0.0'
4
+ VERSION = '1.2.0'
5
5
  # Used for finding the example directory
6
6
  TOP_DIR = File.dirname(File.dirname(File.dirname(__FILE__)))
7
7
  end
@@ -1,14 +1,14 @@
1
1
 
2
2
  require 'erector'
3
- require 'omf_common/lobject'
3
+ require 'omf_base/lobject'
4
4
 
5
5
  module OMF::Web::Widget
6
6
 
7
7
  # Maintains the context for a particular code rendering within a specific session.
8
8
  #
9
9
  class AbstractWidget < Erector::Widget
10
- extend OMF::Common::Loggable
11
- include OMF::Common::Loggable
10
+ extend OMF::Base::Loggable
11
+ include OMF::Base::Loggable
12
12
 
13
13
  attr_reader :widget_id, :widget_type, :name, :opts
14
14
 
@@ -25,6 +25,7 @@ module OMF::Web::Widget
25
25
  raise "Missing widget option ':viz_type' for widget '#{name}' (#{opts.inspect})"
26
26
  end
27
27
  name = opts[:name] ||= 'Unknown'
28
+ opts[:js_module] = "graph/#{vizType}"
28
29
  opts[:js_url] = "graph/js/#{vizType}.js"
29
30
  opts[:js_class] = "OML.#{vizType}"
30
31
  opts[:base_el] = "\##{dom_id}"