From 2c95bf356d95f88b15720321554ddd39b45655a4 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Mar 05 2018 16:24:16 +0000 Subject: Reduce duplication in stats JS The code for asynchronous retrieval of data and processing it can be shared both for commits and authors. --- diff --git a/pagure/static/issues_stats.js b/pagure/static/issues_stats.js index 06bae32..4c1f9cf 100644 --- a/pagure/static/issues_stats.js +++ b/pagure/static/issues_stats.js @@ -91,16 +91,6 @@ function show_commits_authors(data) { _b.show(); } -function commits_authors(url, _data) { - $.post( url, _data ) - .done(function(data) { - wait_for_task(data.url, show_commits_authors); - }) - .fail(function(data) { - }) -}; - - function show_commits_history(data) { var _b = $("#data_stats"); @@ -160,11 +150,9 @@ function show_commits_history(data) { _b.show(); } -function commits_history (url, _data) { - $.post( url, _data ) +function process_async(url, _data, callback) { + $.post(url, _data) .done(function(data) { - wait_for_task(data.url, show_commits_history); - }) - .fail(function(data) { + wait_for_task(data.url, callback); }) } diff --git a/pagure/templates/repo_stats.html b/pagure/templates/repo_stats.html index 7b6fae8..17aa328 100644 --- a/pagure/templates/repo_stats.html +++ b/pagure/templates/repo_stats.html @@ -134,7 +134,7 @@ commits_authors_call = function() { username: "{{ username or '' }}", namespace: "{{ g.repo.namespace or '' }}", } - commits_authors(_stats_url, data); + process_async(_stats_url, data, show_commits_authors); }; commits_history_call = function() { @@ -155,7 +155,7 @@ commits_history_call = function() { username: "{{ username or '' }}", namespace: "{{ g.repo.namespace or '' }}", } - commits_history(_stats_url, data); + process_async(_stats_url, data, show_commits_history); }; toggle_forks = function() {