Commit 8138fe2493ff8a3e03993a36df4d4bd47a92cdf8

Authored by Rafael Manzo
Committed by Heitor
1 parent 463e7a63

Repository state polling JS refactored into its own class

app/assets/javascripts/application.js
... ... @@ -16,6 +16,7 @@
16 16 //= require twitter/bootstrap
17 17 //= require turbolinks
18 18 //= require modules
  19 +//= require repository
19 20 //= require Chart
20 21 //= require_tree .
21 22 //= require colorpicker
... ...
app/assets/javascripts/repository.js.coffee
1   -class Module.Repository
2   - constructor: (@project_id, @repository_id) ->
3   -
4   - poll_state: (last_state) ->
5   - $.post '/projects/' + @project_id + '/repositories/' + @repository_id + '/state',
6   - last_state: last_state
7   -
8   - schedule_poll_state: (last_state) ->
9   - context = this
10   - call = () ->
11   - context.poll_state(last_state)
12   -
13   - setTimeout( call, 15000 ) # Delays in 15s the next call
14   -
15   - @set_loader: (loading_html) ->
16   - $('div#processing_information').html(loading_html)
  1 +@Repository = {}
... ...
app/assets/javascripts/repository/state.js.coffee 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +class Repository.State
  2 + constructor: (@project_id, @repository_id) ->
  3 +
  4 + poll_state: (last_state) ->
  5 + $.post '/projects/' + @project_id + '/repositories/' + @repository_id + '/state',
  6 + last_state: last_state
  7 +
  8 + schedule_poll_state: (last_state) ->
  9 + context = this
  10 + call = () ->
  11 + context.poll_state(last_state)
  12 +
  13 + setTimeout( call, 15000 ) # Delays in 15s the next call
  14 +
  15 + @set_loader: (loading_html) ->
  16 + $('div#processing_information').html(loading_html)
0 17 \ No newline at end of file
... ...
app/views/repositories/reload_processing.js.erb
... ... @@ -7,6 +7,6 @@ current_path = current_path_splited.join("/");
7 7 // This if prevents it from updating the repository's state after the user leaves its page
8 8 if(current_path == '<%= project_repository_path(project_id: @repository.project_id, id: @repository, locale: nil) %>'){
9 9 $('div#processing_information').html('<%= escape_javascript(render partial: "processing_information") %>');
10   - repository = new Module.Repository(<%= @repository.project_id %>, <%= @repository.id %>)
  10 + repository = new Repository.State(<%= @repository.project_id %>, <%= @repository.id %>)
11 11 repository.schedule_poll_state('<%= @processing.state %>')
12 12 }
... ...
app/views/repositories/show.html.erb
... ... @@ -47,7 +47,7 @@
47 47 <%= select_tag(:month, options_for_select(month_options), :style => "width:55px; margin-top:5px") %>
48 48 <%= label_tag :year, t("year") %>:
49 49 <%= select_tag(:year, options_for_select(year_options), :style => "width:70px; margin-top:5px") %>
50   - <%= submit_tag(t('search'), class: 'btn btn-info', style: 'margin-bottom:5px', onClick: "Module.Repository.set_loader('#{image_tag 'loader.gif'} Loading data. Please, wait.')") %>
  50 + <%= submit_tag(t('search'), class: 'btn btn-info', style: 'margin-bottom:5px', onClick: "Repository.State.set_loader('#{image_tag 'loader.gif'} Loading data. Please, wait.')") %>
51 51 </p>
52 52 <% end %>
53 53  
... ... @@ -71,7 +71,7 @@
71 71 </div>
72 72 <script type="text/javascript">
73 73 $(document).ready(function () {
74   - (new Module.Repository(<%= @repository.project_id %>, <%= @repository.id %>)).poll_state('')
  74 + (new Repository.State(<%= @repository.project_id %>, <%= @repository.id %>)).poll_state('')
75 75 });
76 76  
77 77 //Loads the accordion
... ...