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
@@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
16 | //= require twitter/bootstrap | 16 | //= require twitter/bootstrap |
17 | //= require turbolinks | 17 | //= require turbolinks |
18 | //= require modules | 18 | //= require modules |
19 | +//= require repository | ||
19 | //= require Chart | 20 | //= require Chart |
20 | //= require_tree . | 21 | //= require_tree . |
21 | //= require colorpicker | 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 = {} |
@@ -0,0 +1,16 @@ | @@ -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 | \ No newline at end of file | 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,6 +7,6 @@ current_path = current_path_splited.join("/"); | ||
7 | // This if prevents it from updating the repository's state after the user leaves its page | 7 | // This if prevents it from updating the repository's state after the user leaves its page |
8 | if(current_path == '<%= project_repository_path(project_id: @repository.project_id, id: @repository, locale: nil) %>'){ | 8 | if(current_path == '<%= project_repository_path(project_id: @repository.project_id, id: @repository, locale: nil) %>'){ |
9 | $('div#processing_information').html('<%= escape_javascript(render partial: "processing_information") %>'); | 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 | repository.schedule_poll_state('<%= @processing.state %>') | 11 | repository.schedule_poll_state('<%= @processing.state %>') |
12 | } | 12 | } |
app/views/repositories/show.html.erb
@@ -47,7 +47,7 @@ | @@ -47,7 +47,7 @@ | ||
47 | <%= select_tag(:month, options_for_select(month_options), :style => "width:55px; margin-top:5px") %> | 47 | <%= select_tag(:month, options_for_select(month_options), :style => "width:55px; margin-top:5px") %> |
48 | <%= label_tag :year, t("year") %>: | 48 | <%= label_tag :year, t("year") %>: |
49 | <%= select_tag(:year, options_for_select(year_options), :style => "width:70px; margin-top:5px") %> | 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 | </p> | 51 | </p> |
52 | <% end %> | 52 | <% end %> |
53 | 53 | ||
@@ -71,7 +71,7 @@ | @@ -71,7 +71,7 @@ | ||
71 | </div> | 71 | </div> |
72 | <script type="text/javascript"> | 72 | <script type="text/javascript"> |
73 | $(document).ready(function () { | 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 | //Loads the accordion | 77 | //Loads the accordion |