Commit e8c0d45dd295290c1180cf549a9e16de04249816

Authored by Rafael Manzo
1 parent d9a9294a

JS routes are now generated insted of being harcoded

If set, RAILS_RELATIVE_URL_ROOT would break all the AJAX requests.
CHANGELOG.rdoc
... ... @@ -4,6 +4,7 @@ Prezento is the web interface for Mezuro.
4 4  
5 5 == Unreleased
6 6  
  7 +Fixed hardcoded routes on JS files by using generated ones
7 8  
8 9 == v0.8.1 - 01/09/2015
9 10  
... ...
Gemfile
... ... @@ -63,6 +63,9 @@ gem 'google-analytics-rails', '~> 0.0.6'
63 63 # Browser language detection
64 64 gem 'http_accept_language'
65 65  
  66 +# Routes for JS files
  67 +gem 'js-routes', '~> 1.1.0'
  68 +
66 69 group :test do
67 70 # Easier test writing
68 71 gem "shoulda-matchers", '~> 2.8.0'
... ...
Gemfile.lock
... ... @@ -154,6 +154,9 @@ GEM
154 154 thor (>= 0.14, < 2.0)
155 155 jquery-ui-rails (5.0.5)
156 156 railties (>= 3.2.16)
  157 + js-routes (1.1.0)
  158 + railties (>= 3.2)
  159 + sprockets-rails
157 160 json (1.8.3)
158 161 kalibro_client (1.3.0)
159 162 activesupport (>= 2.2.1)
... ... @@ -351,6 +354,7 @@ DEPENDENCIES
351 354 jbuilder (~> 2.0)
352 355 jquery-rails
353 356 jquery-ui-rails (~> 5.0.0)
  357 + js-routes (~> 1.1.0)
354 358 kalibro_client (~> 1.3.0)
355 359 konacha
356 360 mocha
... ... @@ -375,4 +379,4 @@ DEPENDENCIES
375 379 web-console (~> 2.0.0)
376 380  
377 381 BUNDLED WITH
378   - 1.10.5
  382 + 1.10.6
... ...
app/assets/javascripts/application.js
... ... @@ -18,5 +18,6 @@
18 18 //= require modules
19 19 //= require repository
20 20 //= require Chart
  21 +//= require js-routes
21 22 //= require_tree .
22 23 //= require colorpicker
... ...
app/assets/javascripts/module/graphic.js.coffee
... ... @@ -8,7 +8,7 @@ class Module.Graphic
8 8 drawer.slideUp('slow')
9 9  
10 10 load: ->
11   - $.post '/modules/' + @module_id + '/metric_history',
  11 + $.post Routes.module_metric_history_path(@module_id),
12 12 {
13 13 metric_name: @metric_name,
14 14 container: @container
... ...
app/assets/javascripts/module/tree.js.coffee
... ... @@ -2,4 +2,4 @@ class Module.Tree
2 2 @load: (loading_html, module_id) ->
3 3 $('div#module_tree').html(loading_html)
4 4 $('div#metric_results').html(loading_html)
5   - $.post '/modules/'+module_id+'/tree'
6 5 \ No newline at end of file
  6 + $.post Routes.module_tree_path(module_id)
... ...
app/assets/javascripts/repository/branch.js.coffee
... ... @@ -47,7 +47,7 @@ class Repository.Branch
47 47 scm_type = $("#repository_scm_type").val()
48 48  
49 49 context = this
50   - @request = $.get '/repository_branches',
  50 + @request = $.get Routes.repository_branches_path(),
51 51 {'url': address, 'scm_type': scm_type},
52 52 (data) ->
53 53 unless data["errors"]
... ...
app/assets/javascripts/repository/state.js.coffee
... ... @@ -2,7 +2,7 @@ class Repository.State
2 2 constructor: (@repository_id) ->
3 3  
4 4 poll_state: (last_state) ->
5   - $.get('/repositories/' + @repository_id + '/state',
  5 + $.get(Routes.repository_state_path(@repository_id),
6 6 last_state: last_state)
7 7  
8 8 schedule_poll_state: (last_state) ->
... ...
config/initializers/jsroutes.rb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +JsRoutes.setup do |config|
  2 + config.prefix = Mezuro::Application.config.relative_url_root
  3 +end
0 4 \ No newline at end of file
... ...
config/routes.rb
... ... @@ -37,8 +37,8 @@ Rails.application.routes.draw do
37 37 end
38 38  
39 39 # Modules
40   - post '/modules/:id/metric_history' => 'modules#metric_history'
41   - post '/modules/:id/tree' => 'modules#load_module_tree'
  40 + post '/modules/:id/metric_history' => 'modules#metric_history', as: 'module_metric_history'
  41 + post '/modules/:id/tree' => 'modules#load_module_tree', as: 'module_tree'
42 42  
43 43 # Tutorials
44 44 get '/tutorials/:name' => 'tutorials#view', as: 'tutorials'
... ...
spec/javascripts/spec_helper.js.coffee
1 1 #= require jquery
2 2 #= require sinon
  3 +#= require js-routes
3 4  
4 5 #= require modules
5 6 #= require repository
6 7 \ No newline at end of file
... ...