Commit 8138fe2493ff8a3e03993a36df4d4bd47a92cdf8
Committed by
Heitor
1 parent
463e7a63
Exists in
colab
and in
4 other branches
Repository state polling JS refactored into its own class
Showing
5 changed files
with
21 additions
and
19 deletions
Show diff stats
app/assets/javascripts/application.js
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 = {} | ... | ... |
... | ... | @@ -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 | ... | ... |