rhoconnect 3.1.2 → 3.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (248) hide show
  1. data/CHANGELOG.md +14 -2
  2. data/CREDITS +151 -10
  3. data/Gemfile +16 -5
  4. data/Gemfile.lock +58 -23
  5. data/Rakefile +70 -50
  6. data/bench/bench_runner.rb +2 -2
  7. data/bench/benchapp/Gemfile +6 -0
  8. data/bench/benchapp/Gemfile.lock +5 -0
  9. data/bench/benchapp/config.ru +2 -0
  10. data/bench/lib/bench/cli.rb +2 -0
  11. data/bench/lib/bench/distr_runner.rb +3 -2
  12. data/bench/lib/bench/runner.rb +1 -1
  13. data/bench/lib/bench.rb +10 -1
  14. data/bench/run_bench.sh +1 -1
  15. data/bench/scripts/test_query_script.rb +2 -1
  16. data/bench/spec/bench_spec_helper.rb +1 -0
  17. data/bin/rhoconnect +9 -27
  18. data/bin/rhoconnect-benchmark +10 -1
  19. data/commands/commands/dtach_commands/dtach_about.rb +6 -0
  20. data/commands/commands/dtach_commands/dtach_install.rb +30 -0
  21. data/commands/commands/redis_commands/redis_about.rb +6 -0
  22. data/commands/commands/redis_commands/redis_attach.rb +6 -0
  23. data/commands/commands/redis_commands/redis_download.rb +33 -0
  24. data/commands/commands/redis_commands/redis_install.rb +26 -0
  25. data/commands/commands/redis_commands/redis_make.rb +9 -0
  26. data/commands/commands/redis_commands/redis_restart.rb +7 -0
  27. data/commands/commands/redis_commands/redis_runner.rb +67 -0
  28. data/commands/commands/redis_commands/redis_start.rb +6 -0
  29. data/commands/commands/redis_commands/redis_startbg.rb +6 -0
  30. data/commands/commands/redis_commands/redis_stop.rb +6 -0
  31. data/commands/commands/rhoconnect/attach.rb +7 -0
  32. data/commands/commands/rhoconnect/clean_start.rb +9 -0
  33. data/commands/commands/rhoconnect/config.rb +15 -0
  34. data/commands/commands/rhoconnect/console.rb +15 -0
  35. data/commands/commands/rhoconnect/console_helper.rb +3 -0
  36. data/commands/commands/rhoconnect/create_user.rb +18 -0
  37. data/commands/commands/rhoconnect/delete_device.rb +9 -0
  38. data/commands/commands/rhoconnect/delete_user.rb +8 -0
  39. data/commands/commands/rhoconnect/flushdb.rb +14 -0
  40. data/commands/commands/rhoconnect/get_token.rb +25 -0
  41. data/commands/commands/rhoconnect/reset.rb +16 -0
  42. data/commands/commands/rhoconnect/reset_refresh.rb +11 -0
  43. data/commands/commands/rhoconnect/restart.rb +7 -0
  44. data/commands/commands/rhoconnect/secret.rb +11 -0
  45. data/commands/commands/rhoconnect/set_admin_password.rb +26 -0
  46. data/commands/commands/rhoconnect/spec.rb +15 -0
  47. data/commands/commands/rhoconnect/start.rb +18 -0
  48. data/commands/commands/rhoconnect/startbg.rb +34 -0
  49. data/commands/commands/rhoconnect/startdebug.rb +35 -0
  50. data/commands/commands/rhoconnect/stop.rb +11 -0
  51. data/commands/commands/rhoconnect/war.rb +32 -0
  52. data/commands/commands/rhoconnect/web.rb +7 -0
  53. data/commands/execute.rb +35 -0
  54. data/commands/generators/app.rb +6 -0
  55. data/commands/generators/source.rb +6 -0
  56. data/commands/utilities/dtach_installed.rb +10 -0
  57. data/doc/benchmarks-running.txt +5 -0
  58. data/doc/command-line.txt +216 -27
  59. data/doc/heroku-addon.txt +1 -1
  60. data/doc/preparing-production.txt +20 -1
  61. data/doc/public/cli.txt +191 -0
  62. data/doc/push-backend-setup.txt +148 -0
  63. data/doc/push-client-setup.txt +61 -0
  64. data/doc/push-server-setup.txt +91 -0
  65. data/doc/push.txt +8 -137
  66. data/doc/rest-api.txt +96 -0
  67. data/doc/settings.txt +1 -1
  68. data/doc/supported-platforms.txt +2 -1
  69. data/doc/tutorial.txt +6 -4
  70. data/examples/simple/Gemfile +39 -0
  71. data/examples/simple/Rakefile +7 -12
  72. data/examples/simple/config.ru +16 -31
  73. data/examples/simple/settings/settings.yml +5 -4
  74. data/examples/simple/sources/product.rb +51 -0
  75. data/generators/templates/application/Gemfile +7 -0
  76. data/generators/templates/application/Rakefile +5 -18
  77. data/generators/templates/application/config.ru +11 -19
  78. data/install.sh +24 -49
  79. data/installer/unix-like/create_texts.rb +71 -123
  80. data/installer/unix-like/post_install.sh +3 -0
  81. data/installer/unix-like/post_uninstall.sh +2 -0
  82. data/installer/unix-like/pre_install.sh +5 -3
  83. data/installer/unix-like/pre_uninstall.sh +14 -6
  84. data/installer/unix-like/rho_connect_install_checkers.rb +1 -1
  85. data/installer/unix-like/rho_connect_install_constants.rb +6 -10
  86. data/installer/unix-like/rho_connect_install_debian.rb +2 -2
  87. data/installer/unix-like/rho_connect_install_dnd.rb +2 -5
  88. data/installer/unix-like/rho_connect_install_installers.rb +15 -23
  89. data/installer/unix-like/rho_connect_install_yum.rb +2 -2
  90. data/installer/utils/constants.rb +4 -4
  91. data/installer/utils/create_sha1.rb +1 -1
  92. data/installer/utils/nix_install_test.rb +32 -31
  93. data/installer/utils/nix_installation.rake +1 -1
  94. data/installer/utils/package_upload/repos.rake +34 -30
  95. data/installer/utils/package_upload/s3_upload.rb +3 -3
  96. data/lib/rhoconnect/api/source/fast_delete.rb +10 -0
  97. data/lib/rhoconnect/api/source/fast_insert.rb +10 -0
  98. data/lib/rhoconnect/api/source/fast_update.rb +10 -0
  99. data/lib/rhoconnect/api/source/get_source_params.rb +1 -1
  100. data/lib/rhoconnect/api/source/list_sources.rb +2 -2
  101. data/lib/rhoconnect/api/source/save_adapter.rb +1 -1
  102. data/lib/rhoconnect/api/source/update_source_params.rb +6 -0
  103. data/lib/rhoconnect/async.rb +82 -0
  104. data/lib/rhoconnect/bulk_data/bulk_data.rb +5 -1
  105. data/lib/rhoconnect/client_sync.rb +18 -3
  106. data/lib/rhoconnect/console/rhoconnect_api.rb +2 -2
  107. data/lib/rhoconnect/console/server.rb +5 -32
  108. data/lib/rhoconnect/console.rb +2 -2
  109. data/lib/rhoconnect/graph_helper.rb +225 -0
  110. data/lib/rhoconnect/jobs/bulk_data_job.rb +24 -2
  111. data/lib/rhoconnect/server.rb +31 -11
  112. data/lib/rhoconnect/source.rb +10 -5
  113. data/lib/rhoconnect/source_sync.rb +32 -2
  114. data/lib/rhoconnect/tasks.rb +19 -108
  115. data/lib/rhoconnect/test_methods.rb +20 -0
  116. data/lib/rhoconnect/utilities.rb +118 -0
  117. data/lib/rhoconnect/version.rb +1 -1
  118. data/lib/rhoconnect/web-console/controllers/admins.js +245 -0
  119. data/lib/rhoconnect/web-console/models/adapter.js +53 -0
  120. data/lib/rhoconnect/web-console/models/client.js +105 -0
  121. data/lib/rhoconnect/web-console/models/doc.js +113 -0
  122. data/lib/rhoconnect/web-console/models/session.js +40 -0
  123. data/lib/rhoconnect/web-console/models/source.js +115 -0
  124. data/lib/rhoconnect/web-console/models/stats.js +84 -0
  125. data/lib/rhoconnect/web-console/models/user.js +111 -0
  126. data/lib/rhoconnect/web-console/public/backbone.js +1432 -0
  127. data/lib/rhoconnect/web-console/public/bootstrap.css +3990 -0
  128. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/excanvas.min.js +0 -0
  129. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.barRenderer.min.js +0 -0
  130. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.canvasAxisLabelRenderer.js +0 -0
  131. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.canvasAxisTickRenderer.js +0 -0
  132. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.canvasTextRenderer.js +0 -0
  133. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.categoryAxisRenderer.min.js +0 -0
  134. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.cursor.js +0 -0
  135. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.dateAxisRenderer.js +0 -0
  136. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.dateAxisRenderer.min.js +0 -0
  137. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jqplot.pointLabels.min.js +0 -0
  138. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jquery-1.4.2.min.js +0 -0
  139. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jquery.jqplot.min.css +0 -0
  140. data/lib/rhoconnect/{console/app → web-console}/public/jqplot/jquery.jqplot.min.js +0 -0
  141. data/lib/rhoconnect/web-console/public/jquery-1.7.1.min.js +154 -0
  142. data/lib/rhoconnect/web-console/public/rhoconnect-web.js +15 -0
  143. data/lib/rhoconnect/web-console/public/underscore.js +999 -0
  144. data/lib/rhoconnect/web-console/server.rb +55 -0
  145. data/lib/rhoconnect/web-console/templates/index.erb +90 -0
  146. data/lib/rhoconnect/web-console/templates/jqplot.erb +60 -0
  147. data/lib/rhoconnect/web-console/views/api_token.js +16 -0
  148. data/lib/rhoconnect/web-console/views/doc.js +63 -0
  149. data/lib/rhoconnect/web-console/views/edit_user.js +43 -0
  150. data/lib/rhoconnect/web-console/views/home.js +56 -0
  151. data/lib/rhoconnect/web-console/views/index.js +63 -0
  152. data/lib/rhoconnect/web-console/views/new_ping.js +58 -0
  153. data/lib/rhoconnect/web-console/views/new_user.js +29 -0
  154. data/lib/rhoconnect/web-console/views/server_doc.js +103 -0
  155. data/lib/rhoconnect/web-console/views/set_adapter.js +38 -0
  156. data/lib/rhoconnect/web-console/views/settings.js +53 -0
  157. data/lib/rhoconnect/web-console/views/show_device.js +56 -0
  158. data/lib/rhoconnect/web-console/views/show_user.js +38 -0
  159. data/lib/rhoconnect/web-console/views/source_docs.js +30 -0
  160. data/lib/rhoconnect/web-console/views/stats.js +69 -0
  161. data/lib/rhoconnect/web-console/views/users.js +20 -0
  162. data/lib/rhoconnect.rb +2 -1
  163. data/rhoconnect.gemspec +3 -1
  164. data/spec/api/application/rhoconnect_api_spec.rb +3 -5
  165. data/spec/api/source/fast_delete_spec.rb +27 -0
  166. data/spec/api/source/fast_insert_spec.rb +28 -0
  167. data/spec/api/source/fast_update_spec.rb +51 -0
  168. data/spec/api/source/get_source_params_spec.rb +1 -0
  169. data/spec/api/source/update_source_params_spec.rb +24 -0
  170. data/spec/async_spec.rb +19 -0
  171. data/spec/client_sync_spec.rb +19 -2
  172. data/spec/javascripts/PlayerSpec.js +58 -0
  173. data/spec/javascripts/admins_routes_spec.js +117 -0
  174. data/spec/javascripts/admins_spec.js +27 -0
  175. data/spec/javascripts/doc_view_spec.js +37 -0
  176. data/spec/javascripts/edit_user_view_spec.js +44 -0
  177. data/spec/javascripts/helpers/SpecHelper.js +9 -0
  178. data/spec/javascripts/helpers/jasmine-jquery.js +305 -0
  179. data/spec/javascripts/helpers/jasmine-sinon.js +43 -0
  180. data/spec/javascripts/helpers/sinon-1.3.2.js +3551 -0
  181. data/spec/javascripts/home_view_spec.js +39 -0
  182. data/spec/javascripts/index_view_spec.js +42 -0
  183. data/spec/javascripts/new_ping_view_spec.js +48 -0
  184. data/spec/javascripts/new_user_view_spec.js +42 -0
  185. data/spec/javascripts/server_doc_view_spec.js +39 -0
  186. data/spec/javascripts/set_adapter_view_spec.js +32 -0
  187. data/spec/javascripts/show_device_view_spec.js +41 -0
  188. data/spec/javascripts/show_user_view_spec.js +46 -0
  189. data/spec/javascripts/source_docs_view_spec.js +36 -0
  190. data/spec/javascripts/support/jasmine.yml +79 -0
  191. data/spec/javascripts/support/jasmine_config.rb +23 -0
  192. data/spec/javascripts/support/jasmine_runner.rb +32 -0
  193. data/spec/javascripts/users_view_spec.js +35 -0
  194. data/spec/jobs/bulk_data_job_spec.rb +10 -2
  195. data/spec/perf/bulk_data_perf_spec.rb +1 -0
  196. data/spec/server/server_spec.rb +3 -1
  197. data/spec/source_sync_spec.rb +14 -1
  198. data/spec/spec_helper.rb +51 -0
  199. data/spec/store_spec.rb +6 -0
  200. data/spec/test_methods_spec.rb +11 -0
  201. data/tasks/redis.rake +3 -1
  202. metadata +172 -64
  203. data/doc/contributing.txt +0 -60
  204. data/lib/rhoconnect/console/app/helpers/auth_helper.rb +0 -22
  205. data/lib/rhoconnect/console/app/helpers/extensions.rb +0 -19
  206. data/lib/rhoconnect/console/app/helpers/helpers.rb +0 -57
  207. data/lib/rhoconnect/console/app/public/ThickBox.css +0 -649
  208. data/lib/rhoconnect/console/app/public/home.css +0 -431
  209. data/lib/rhoconnect/console/app/public/images/foot_logo_rhoconnect.png +0 -0
  210. data/lib/rhoconnect/console/app/public/images/header_halo.jpg +0 -0
  211. data/lib/rhoconnect/console/app/public/images/land_separator.gif +0 -0
  212. data/lib/rhoconnect/console/app/public/images/landing_header.jpg +0 -0
  213. data/lib/rhoconnect/console/app/public/images/logo_rhoconnect.png +0 -0
  214. data/lib/rhoconnect/console/app/public/images/tabs_separator.png +0 -0
  215. data/lib/rhoconnect/console/app/public/main.css +0 -7
  216. data/lib/rhoconnect/console/app/public/reset.css +0 -76
  217. data/lib/rhoconnect/console/app/public/style.css +0 -2201
  218. data/lib/rhoconnect/console/app/public/text.txt +0 -0
  219. data/lib/rhoconnect/console/app/routes/adapter.rb +0 -28
  220. data/lib/rhoconnect/console/app/routes/auth.rb +0 -29
  221. data/lib/rhoconnect/console/app/routes/client.rb +0 -31
  222. data/lib/rhoconnect/console/app/routes/docs.rb +0 -145
  223. data/lib/rhoconnect/console/app/routes/heroku.rb +0 -19
  224. data/lib/rhoconnect/console/app/routes/home.rb +0 -63
  225. data/lib/rhoconnect/console/app/routes/timing.rb +0 -242
  226. data/lib/rhoconnect/console/app/routes/user.rb +0 -122
  227. data/lib/rhoconnect/console/app/views/adapter.erb +0 -16
  228. data/lib/rhoconnect/console/app/views/client.erb +0 -30
  229. data/lib/rhoconnect/console/app/views/content.erb +0 -14
  230. data/lib/rhoconnect/console/app/views/doc.erb +0 -8
  231. data/lib/rhoconnect/console/app/views/docdata.erb +0 -28
  232. data/lib/rhoconnect/console/app/views/docs.erb +0 -30
  233. data/lib/rhoconnect/console/app/views/edituser.erb +0 -13
  234. data/lib/rhoconnect/console/app/views/headermenu.erb +0 -40
  235. data/lib/rhoconnect/console/app/views/home.erb +0 -24
  236. data/lib/rhoconnect/console/app/views/index.erb +0 -58
  237. data/lib/rhoconnect/console/app/views/jqplot.erb +0 -52
  238. data/lib/rhoconnect/console/app/views/layout.erb +0 -153
  239. data/lib/rhoconnect/console/app/views/login.erb +0 -26
  240. data/lib/rhoconnect/console/app/views/newuser.erb +0 -17
  241. data/lib/rhoconnect/console/app/views/ping.erb +0 -40
  242. data/lib/rhoconnect/console/app/views/result.erb +0 -11
  243. data/lib/rhoconnect/console/app/views/rightboxlinks.erb +0 -15
  244. data/lib/rhoconnect/console/app/views/select_doc.erb +0 -17
  245. data/lib/rhoconnect/console/app/views/upload_doc.erb +0 -23
  246. data/lib/rhoconnect/console/app/views/user.erb +0 -29
  247. data/lib/rhoconnect/console/app/views/users.erb +0 -19
  248. data/lib/rhoconnect/server/views/index.erb +0 -13
@@ -0,0 +1,118 @@
1
+ require 'json'
2
+
3
+ module Utilities
4
+ # Prints the command to be issued and then issues it to system
5
+ def cmd(cmd)
6
+ puts cmd
7
+ system cmd
8
+ end #cmd
9
+
10
+ def redis_home
11
+ ENV['REDIS_HOME'] || File.join($redis_dest,$redis_ver)
12
+ end
13
+
14
+ def mk_bin_dir(bin_dir)
15
+ begin
16
+ mkdir_p bin_dir unless File.exists?(bin_dir)
17
+ rescue
18
+ puts "Can't create #{bin_dir}, maybe you need to run command as root?"
19
+ exit 1
20
+ end
21
+ end
22
+
23
+ def post(path,params)
24
+ req = Net::HTTP.new($host,$port)
25
+ resp = req.post(path, params.to_json, 'Content-Type' => 'application/json')
26
+ print_resp(resp, resp.is_a?(Net::HTTPSuccess) ? true : false)
27
+ end
28
+
29
+ def print_resp(resp,success=true)
30
+ if success
31
+ puts "=> OK"
32
+ else
33
+ puts "=> FAILED"
34
+ end
35
+ puts "=> " + resp.body if resp and resp.body and resp.body.length > 0
36
+ end
37
+
38
+ def archive(path)
39
+ File.join(path,File.basename(path))+'.zip'
40
+ end
41
+
42
+ def ask(msg)
43
+ print msg
44
+ STDIN.gets.chomp
45
+ end
46
+
47
+ def load_settings(file)
48
+ begin
49
+ $settings = YAML.load_file(file)
50
+ rescue Exception => e
51
+ puts "Error opening settings file #{file}: #{e}."
52
+ puts e.backtrace.join("\n")
53
+ raise e
54
+ end
55
+ end
56
+
57
+ def rhoconnect_socket
58
+ '/tmp/rhoconnect.dtach'
59
+ end
60
+
61
+ def rhoconnect_pid
62
+ if windows?
63
+ Dir.mkdir 'C:/TMP' unless File.directory? 'C:/TMP'
64
+ 'C:/TMP/rhoconnect.pid'
65
+ else
66
+ '/tmp/rhoconnect.pid'
67
+ end
68
+ end
69
+
70
+ def windows?
71
+ RUBY_PLATFORM =~ /(win|w)32$/
72
+ end
73
+
74
+ def ruby19?
75
+ RUBY_VERSION =~ /1.9/
76
+ end
77
+
78
+ def jruby?
79
+ defined?(JRUBY_VERSION)
80
+ end
81
+
82
+ def thin?
83
+ begin
84
+ require 'thin'
85
+ 'rackup -s thin'
86
+ rescue LoadError
87
+ nil
88
+ end
89
+ end
90
+
91
+ def mongrel?
92
+ begin
93
+ require 'mongrel'
94
+ 'rackup -s mongrel'
95
+ rescue LoadError
96
+ nil
97
+ end
98
+ end
99
+
100
+ def report_missing_server
101
+ msg =<<-EOF
102
+ Could not find 'thin' or 'mongrel' on your system. Please install one:
103
+ gem install thin
104
+ or
105
+ gem install mongrel
106
+ EOF
107
+ puts msg
108
+ exit 1
109
+ end
110
+
111
+ # def jetty_rackup?
112
+ # 'jruby -S jetty-rackup'
113
+ # end
114
+
115
+ def trinidad?
116
+ 'jruby -S trinidad -p 9292 -r config.ru'
117
+ end
118
+ end #Utilities
@@ -1,3 +1,3 @@
1
1
  module Rhoconnect
2
- VERSION = '3.1.2'
2
+ VERSION = '3.2.0.beta1'
3
3
  end
@@ -0,0 +1,245 @@
1
+ App.Controllers.Admins = Backbone.Router.extend({
2
+
3
+ routes: {
4
+ "login" : "login",
5
+ "logout" : "logout",
6
+ "" : "index",
7
+ "home" : "index",
8
+ "sources/:id" : "show_source_1",
9
+ "sources/:id/:user_id/:doctype/:client_id" : "show_source",
10
+ "doc/:dbkey/:source_id" : "get_doc",
11
+ "docselect" : "server_doc",
12
+ "adapter" : "adapter",
13
+ "settings" : "settings",
14
+ "users" : "users",
15
+ "users/new" : "new_user",
16
+ "user/:id" : "show_user",
17
+ "user/newping/:id" : "new_ping",
18
+ "users/newping" : "new_ping_all",
19
+ "device/:device_id/:user_id" : "user_device",
20
+ "change_admin" : "change_admin",
21
+ "stats" : "stats"
22
+ },
23
+
24
+ logout: function() {
25
+ var session = new Session();
26
+ session.setAuthenticated(false);
27
+ session.setApiKey(null);
28
+ this.set_nav('info_home');
29
+ this.set_log('login');
30
+ new App.Views.Index
31
+ },
32
+
33
+ index: function(){
34
+ var session = new Session();
35
+ var token = $('input#token').val();
36
+ if(token){
37
+ session.setAuthenticated(true);
38
+ session.setApiKey(token);
39
+ $('#nav_menu').css('display','none')
40
+ }
41
+ this.set_nav('info_home');
42
+ if(session.getAuthenticated() == 'true'){
43
+ this.set_log('logout');
44
+ new App.Views.Home({model: new Source()})
45
+ }
46
+ else
47
+ new App.Views.Index
48
+ },
49
+
50
+ show_source_1: function(id){
51
+ var session = new Session();
52
+ if(session.getAuthenticated() == 'true'){
53
+ this.set_log('logout');
54
+ source = new Source();
55
+ source.set("source_id",id);
56
+ new App.Views.SourceDocs({model: source })
57
+ }
58
+ else
59
+ new App.Views.Index
60
+ },
61
+
62
+ show_source: function(id,user,doctype,client_id){
63
+ var session = new Session();
64
+ if(session.getAuthenticated() == 'true'){
65
+ this.set_log('logout');
66
+ source = new Source();
67
+ source.set("source_id",id);
68
+ source.set("user_id",user);
69
+ source.set("doctype",doctype);
70
+ source.set('client_id',client_id)
71
+ new App.Views.SourceDocs({model: source })
72
+ }
73
+ else
74
+ new App.Views.Index
75
+ },
76
+
77
+ get_doc: function(dbkey,source_id){
78
+ var session = new Session();
79
+ if(session.getAuthenticated() == 'true'){
80
+ this.set_log('logout');
81
+ doc = new Doc();
82
+ doc.set("dbkey",dbkey);
83
+ new App.Views.Doc({model: doc })
84
+ }
85
+ else
86
+ new App.Views.Index
87
+ },
88
+
89
+ server_doc: function(){
90
+ var session = new Session();
91
+ if(session.getAuthenticated() == 'true'){
92
+ this.set_log('logout');
93
+ this.set_nav('server_doc');
94
+ doc = new Doc();
95
+ new App.Views.ServerDoc({model: doc })
96
+ }
97
+ else
98
+ new App.Views.Index
99
+ },
100
+
101
+ settings: function(){
102
+ var session = new Session();
103
+ if(session.getAuthenticated() == 'true'){
104
+ this.set_log('logout');
105
+ this.set_nav('settings');
106
+ //adapter = new Adapter();
107
+ new App.Views.Settings()
108
+ }
109
+ else
110
+ new App.Views.Index
111
+ },
112
+
113
+ adapter: function(){
114
+ var session = new Session();
115
+ if(session.getAuthenticated() == 'true'){
116
+ this.set_log('logout');
117
+ this.set_nav('adapter');
118
+ adapter = new Adapter();
119
+ new App.Views.SetAdapter({model: adapter })
120
+ }
121
+ else
122
+ new App.Views.Index
123
+ },
124
+
125
+ users: function(){
126
+ var session = new Session();
127
+ if(session.getAuthenticated() == 'true'){
128
+ this.set_log('logout');
129
+ this.set_nav('users');
130
+ user = new User();
131
+ new App.Views.Users({model: user })
132
+ }
133
+ else
134
+ new App.Views.Index
135
+ },
136
+
137
+ new_user: function(){
138
+ var session = new Session();
139
+ if(session.getAuthenticated() == 'true'){
140
+ this.set_log('logout');
141
+ this.set_nav('users');
142
+ user = new User();
143
+ new App.Views.NewUser({model: user })
144
+ }
145
+ else
146
+ new App.Views.Index
147
+ },
148
+
149
+ show_user: function(id){
150
+ var session = new Session();
151
+ if(session.getAuthenticated() == 'true'){
152
+ this.set_log('logout');
153
+ this.set_nav('users');
154
+ user = new User();
155
+ user.set('name', id);
156
+ new App.Views.ShowUser({model: user })
157
+ }
158
+ else
159
+ new App.Views.Index
160
+ },
161
+
162
+ user_device: function(device_id,user_id){
163
+ var session = new Session();
164
+ if(session.getAuthenticated() == 'true'){
165
+ this.set_log('logout');
166
+ this.set_nav('users');
167
+ client = new Client();
168
+ client.set('device_id', device_id);
169
+ client.set('user_id', user_id);
170
+ new App.Views.ShowDevice({model: client })
171
+ }
172
+ else
173
+ new App.Views.Index
174
+ },
175
+
176
+ new_ping: function(id){
177
+ var session = new Session();
178
+ if(session.getAuthenticated() == 'true'){
179
+ this.set_log('logout');
180
+ this.set_nav('users');
181
+ user = new User();
182
+ user.set('name', id);
183
+ new App.Views.NewPing({model: user })
184
+ }
185
+ else
186
+ new App.Views.Index
187
+ },
188
+
189
+ new_ping_all: function(){
190
+ var session = new Session();
191
+ if(session.getAuthenticated() == 'true'){
192
+ this.set_log('logout');
193
+ this.set_nav('users');
194
+ user = new User();
195
+ new App.Views.NewPing({model: user })
196
+ }
197
+ else
198
+ new App.Views.Index
199
+ },
200
+
201
+ change_admin: function(){
202
+ var session = new Session();
203
+ if(session.getAuthenticated() == 'true'){
204
+ this.set_log('logout');
205
+ new App.Views.EditUser()
206
+ }
207
+ else
208
+ new App.Views.Index
209
+ },
210
+
211
+ stats: function(){
212
+ //hide route if stats not enabled
213
+ if($("#stats").length > 0){
214
+ var session = new Session();
215
+ if(session.getAuthenticated() == 'true'){
216
+ this.set_log('logout');
217
+ this.set_nav('stats');
218
+ stats = new Stats();
219
+ new App.Views.Stats({model : stats})
220
+ }
221
+ else
222
+ new App.Views.Index;
223
+ }
224
+ },
225
+
226
+ set_nav: function(tab){
227
+ $('#info_home').attr('class','');
228
+ $('#server_doc').attr('class','');
229
+ $('#users').attr('class','');
230
+ $('#settings').attr('class','');
231
+ $('#stats').attr('class','');
232
+ $('#'+tab).attr('class','active');
233
+ },
234
+
235
+ set_log: function(state){
236
+ if(state == 'login'){
237
+ $('a#logout').css('display','none');
238
+ $('a#login').css('display','block');
239
+ }
240
+ else{
241
+ $('a#logout').css('display','block');
242
+ $('a#login').css('display','none');
243
+ }
244
+ }
245
+ });
@@ -0,0 +1,53 @@
1
+ var Adapter = Backbone.Model.extend({
2
+
3
+ defaults: {
4
+ domain: null,
5
+ backend_url: null,
6
+ api_token: null
7
+ },
8
+
9
+ initialize: function(){
10
+ var session = new Session();
11
+ this.set('api_token', session.getApiKey())
12
+ },
13
+
14
+ set_adapter: function(adapter_url){
15
+ $.ajax({
16
+ type: 'POST',
17
+ url: '/api/source/save_adapter',
18
+ data: {api_token : this.get('api_token'), adapter_url : adapter_url},
19
+ success: function(model, resp){
20
+ $(".setadapter-status")[0].firstChild.className = "label label-success";
21
+ $(".setadapter-status")[0].firstChild.innerHTML = "success";
22
+ },
23
+ error: function(resp){
24
+ if(resp.status == 422){
25
+ new App.Views.Index()
26
+ }
27
+ $(".setadapter-status")[0].firstChild.className = "label label-important";
28
+ $(".setadapter-status")[0].firstChild.innerHTML = "error";
29
+ }
30
+ })
31
+ },
32
+
33
+ get_adapter: function(){
34
+ $.ajax({
35
+ type: 'POST',
36
+ url: '/api/source/get_adapter',
37
+ data: {api_token : this.get('api_token')},
38
+ success: function(resp){
39
+ var r = JSON.parse(resp);
40
+ if(r.adapter_url)
41
+ $('#input_adapter').val(r.adapter_url);
42
+ },
43
+ error: function(resp){
44
+ if(resp.status == 422){
45
+ new App.Views.Index()
46
+ }
47
+ $(".setadapter-status")[0].firstChild.className = "label label-important";
48
+ $(".setadapter-status")[0].firstChild.innerHTML = "error";
49
+ }
50
+ })
51
+ }
52
+
53
+ });
@@ -0,0 +1,105 @@
1
+ var Client = Backbone.Model.extend({
2
+
3
+ defaults: {
4
+ api_token: null,
5
+ client_id: null
6
+ },
7
+
8
+ initialize: function(){
9
+ var session = new Session();
10
+ this.set('api_token', session.getApiKey())
11
+ },
12
+
13
+ get_clients: function(user_id){
14
+ $.ajax({
15
+ type: 'POST',
16
+ url: '/api/client/list_clients',
17
+ data: {api_token : this.get('api_token'), user_id : user_id},
18
+ success: function(resp){
19
+ var r = JSON.parse(resp)
20
+ data = ""
21
+ $.each(r,function(index,value){
22
+ data += "<tr><td><a href='#device/"+value+"/"+user_id+"'>"+value+"</a></td></tr>";
23
+ })
24
+ $('#device-table tr:last').after(data);
25
+ },
26
+ error: function(resp){
27
+ if(resp.status == 422){
28
+ new App.Views.Index()
29
+ }
30
+ $('#showuser-alert')[0].innerHTML = resp.responseText;
31
+ $('#showuser-alert').css('display','block');
32
+ }
33
+ })
34
+ },
35
+
36
+ list_client_docs: function(client_id,source_id){
37
+ $.ajax({
38
+ type: 'POST',
39
+ url: '/api/client/list_client_docs',
40
+ data: {api_token : this.get('api_token'), client_id : client_id, source_id : source_id},
41
+ success: function(resp){
42
+ var r = JSON.parse(resp)
43
+ data = ""
44
+ $.each(r,function(index,value){
45
+ data += "<tr><td><a href='#doc/"+value+"/source_id="+source_id+"'>"+value+"</a></td></tr>";
46
+ })
47
+ $('#sourcedocs-table tr:last').after(data);
48
+ },
49
+ error: function(resp){
50
+ if(resp.status == 422){
51
+ new App.Views.Index()
52
+ }
53
+ $('#showdevice-alert')[0].innerHTML = resp.responseText;
54
+ $('#showdevice-alert').css('display','block');
55
+ }
56
+ })
57
+ },
58
+
59
+ get_client_params: function(client_id){
60
+ $.ajax({
61
+ type: 'POST',
62
+ url: '/api/client/get_client_params',
63
+ data: {api_token : this.get('api_token'),client_id : client_id},
64
+ success: function(resp){
65
+ var r = JSON.parse(resp)
66
+ data = "";
67
+ $.each(r, function(index,value){
68
+ if(value.value != null && value.value != "")
69
+ data += "<tr><td width='25%'>" + value.name + "</td><td>" + value.value + "</td></tr>"
70
+ })
71
+
72
+ $('#deviceattr-table tr:last').after(data);
73
+ },
74
+ error: function(resp){
75
+ if(resp.status == 422){
76
+ new App.Views.Index()
77
+ }
78
+ $('#showdevice-alert')[0].innerHTML = resp.responseText;
79
+ $('#showdevice-alert').css('display','block');
80
+ }
81
+ })
82
+ }
83
+
84
+ // get_device: function(device_id){
85
+ // $.ajax({
86
+ // type: 'POST',
87
+ // url: '/api/client/get_client_params',
88
+ // data: {api_token : this.get('api_token'), client_id : device_id},
89
+ // success: function(resp){
90
+ // var r = JSON.parse(resp)
91
+ // data = "";
92
+ // $.each(r, function(index,value){
93
+ // if(value.value != null && value.value != "")
94
+ // data += "<tr><td>" + value.name + "</td><td>" + value.value + "</td></tr>"
95
+ // })
96
+ //
97
+ // $('#device-table tr:last').after(data);
98
+ // },
99
+ // error: function(resp){
100
+ // $('#showdevice-alert')[0].innerHTML = resp.responseText;
101
+ // $('#showdevice-alert').css('display','block');
102
+ // }
103
+ // })
104
+ // }
105
+ })
@@ -0,0 +1,113 @@
1
+ var Doc = Backbone.Model.extend({
2
+
3
+ defaults: {
4
+ api_token: null,
5
+ dockey: null,
6
+ dbkey: null
7
+ },
8
+
9
+ initialize: function(){
10
+ var session = new Session();
11
+ this.set('api_token', session.getApiKey())
12
+ },
13
+
14
+ methodUrl: {
15
+ 'create': '/api/admin/get_license_info'
16
+ },
17
+
18
+ sync: function(method, model, options) {
19
+ if (model.methodUrl && model.methodUrl[method.toLowerCase()]) {
20
+ options = options || {};
21
+ options.url = model.methodUrl[method.toLowerCase()];
22
+ // if(method == 'read'){
23
+ // options.url += "?api_token=" + this.get('api_token')
24
+ // }
25
+ }
26
+ Backbone.sync(method, model, options);
27
+ },
28
+
29
+ get_doc: function(dbkey,d_type){
30
+ self = this;
31
+ var session = new Session();
32
+ var dt = 'hash';
33
+ if(dbkey.search(/token/i) > 0 || dbkey.search(/size/i) > 0 || d_type == 'string'){
34
+ dt = 'string';
35
+ }
36
+ this.set('dbkey',dbkey);
37
+ $.ajax({
38
+ type: 'POST',
39
+ url: '/api/source/get_db_doc',
40
+ data: {api_token : session.getApiKey, doc : dbkey, data_type : dt},
41
+ success: function(resp){
42
+ var data = ""
43
+ r = self.formatJson(resp)
44
+ if(resp != ''){
45
+ data += "<tr><th colspan=3><h3 style='display:inline'>Data</h3><span class='pull-right'>" +
46
+ "<a id='clear' class='btn btn-danger'>clear document</a></span></th></tr>" +
47
+ "<tr><td id='doc_data'>" + r+ "</td></tr>";
48
+ }
49
+ else{
50
+ data += "<tr><th>Document is Empty</th></tr>";
51
+ }
52
+ $('#docdata-table tr:last').after(data);
53
+ $(".query-status")[0].firstChild.className = "label label-success";
54
+ $(".query-status")[0].firstChild.innerHTML = "success";
55
+ },
56
+ error: function(resp){
57
+ if(resp.status == 422){
58
+ new App.Views.Index()
59
+ }
60
+ $('#docalert')[0].innerHTML = resp.responseText;
61
+ $('#docalert').css('display','block');
62
+ $(".query-status")[0].firstChild.className = "label label-important";
63
+ $(".query-status")[0].firstChild.innerHTML = "error";
64
+ }
65
+ })
66
+ },
67
+
68
+ formatJson: function(val) {
69
+ var retval = '';
70
+ var str = val;
71
+ var pos = 0;
72
+ var strLen = str.length;
73
+ var indentStr = '&nbsp;&nbsp;&nbsp;&nbsp;';
74
+ var newLine = '<br />';
75
+ var char = '';
76
+
77
+
78
+ for (var i=0; i<strLen; i++) {
79
+ char = str.substring(i,i+1);
80
+
81
+ if (char == '}' || char == ']') {
82
+ retval = retval + newLine;
83
+ pos = pos - 1;
84
+
85
+ for (var j=0; j<pos; j++) {
86
+
87
+ retval = retval + indentStr;
88
+
89
+ }
90
+
91
+ }
92
+
93
+ retval = retval + char;
94
+
95
+ if (char == '{' || char == '[' || char == ',') {
96
+ retval = retval + newLine;
97
+
98
+ if (char == '{' || char == '[') {
99
+ pos = pos + 1;
100
+ }
101
+
102
+ for (var k=0; k<pos; k++) {
103
+ retval = retval + indentStr;
104
+ }
105
+ }
106
+ }
107
+
108
+ return retval;
109
+
110
+ }
111
+
112
+
113
+ })
@@ -0,0 +1,40 @@
1
+ var Session = Backbone.Model.extend({
2
+
3
+ setApiKey: function(apiKey) {
4
+ window.sessionStorage.setItem('apiKey', apiKey)
5
+ },
6
+
7
+ setAuthenticated: function(value) {
8
+ window.sessionStorage.setItem('authenticated', value)
9
+ },
10
+
11
+ getApiKey: function() {
12
+ return window.sessionStorage.getItem('apiKey')
13
+ },
14
+
15
+ getAuthenticated: function() {
16
+ return window.sessionStorage.getItem('authenticated')
17
+ },
18
+
19
+ reset: function() {
20
+ $(".reset-status")[0].firstChild.className = "label label-warning";
21
+ $(".reset-status")[0].firstChild.innerHTML = "loading...";
22
+ $(".reset-status").css("visibility","visible");
23
+ $.ajax({
24
+ type: 'POST',
25
+ url: '/api/admin/reset',
26
+ data: {api_token : this.getApiKey()},
27
+ success: function(){
28
+ $(".reset-status")[0].firstChild.className = "label label-success";
29
+ $(".reset-status")[0].firstChild.innerHTML = "success";
30
+ //router.navigate("#", true);
31
+ },
32
+ error: function(resp){
33
+ $(".reset-status")[0].firstChild.className = "label label-danger";
34
+ $(".reset-status")[0].firstChild.innerHTML = "error";
35
+ $('#home-alert')[0].innerHTML = resp.responseText;
36
+ $('#home-alert').css('display','block');
37
+ }
38
+ })
39
+ }
40
+ });