Purge progress indication.

This commit is contained in:
Kevin Gaudin 2013-05-08 17:51:46 +02:00
parent 694d6ef431
commit 05913786ac
4 changed files with 49 additions and 12 deletions

View File

@ -19,7 +19,7 @@
You should have received a copy of the GNU General Public License
along with Acralyzer. If not, see <http://www.gnu.org/licenses/>.
-->
<title>Acralyzer</title>
<title>Acralyzer / {{acralyzer.app}}</title>
<meta charset="utf-8">
<link rel="alternate" type="application/rss+xml" href="{{rsslink}}" title="Latest Crash Reports">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

View File

@ -1,10 +1,18 @@
<tabs>
<pane heading="Reports">
<div>
<button ng-click="purgeDays()">Purge</button> reports older than <input ng-model="daysToKeep" class="input-mini"/> days.
<button ng-click="purgeDays(daysToKeep)" ng-disabled="purgingByDays || purgingByAppVersionCode">
<span ng-hide="purgingByDays">Purge</span>
<span ng-show="purgingByDays"><img src="img/polling.gif"/> Purging</span>
</button>
{{nbReportsByDaysToPurge}} reports older than <input ng-model="daysToKeep" class="input-mini"/> days.
</div>
<div>
<button ng-click="purgeVersion(selectedVersion)">Purge</button> reports from apps older than version <select ng-model="selectedVersion" class="input-mini" ng-options="code.value as code.label for code in appVersionCodes"></select>.
<button ng-click="purgeVersion(selectedVersion)" ng-disabled="purgingByDays || purgingByAppVersionCode">
<span ng-hide="purgingByAppVersionCode">Purge</span>
<span ng-show="purgingByAppVersionCode"><img src="img/polling.gif"/> Purging</span>
</button>
{{nbReportsByAppVersionCodeToPurge}} reports from apps older than version <select ng-model="selectedVersion" class="input-mini" ng-options="code.value as code.label for code in appVersionCodes"></select>.
</div>
</pane>
<pane heading="Users">

View File

@ -32,6 +32,10 @@
$scope.daysToKeep = 90;
$scope.selectedVersion = "";
$scope.appVersionCodes = [];
$scope.purgingByDays = false;
$scope.purgingByAppVersionCode = false;
$scope.nbReportsByDaysToPurge = "";
$scope.nbReportsByAppVersionCodeToPurge = "";
ReportsStore.appVersionCodesList(function(data){
$scope.appVersionCodes.length = 0;
@ -40,13 +44,20 @@
}
});
$scope.purgeDays = function() {
var deadline = moment().subtract('days', $scope.daysToKeep);
console.log("Purge reports older than " + $scope.daysToKeep);
$scope.purgeDays = function(daysToKeep) {
$scope.purgingByDays = true;
var deadline = moment().subtract('days', daysToKeep);
console.log("Purge reports older than " + daysToKeep);
console.log("key will be: " + deadline.format("[[]YYYY,M,d[]]"));
ReportsStore.purgeReportsOlderThan(deadline.year(), deadline.month(), deadline.date(),
function(nbReports) {
// Intermediate callback
$scope.nbReportsByDaysToPurge = nbReports;
},
function(data) {
// Success callback
$scope.purgingByDays = false;
$scope.nbReportsByDaysToPurge = "";
$notify.success({
desktop: true,
timeout: 10000,
@ -57,6 +68,8 @@
},
function(){
// Failure callback
$scope.purgingByDays = false;
$scope.nbReportsByDaysToPurge = "";
$notify.success({
desktop: true,
timeout: 10000,
@ -69,11 +82,19 @@
};
$scope.purgeVersion = function(selectedVersion) {
$scope.purgingByAppVersionCode = true;
console.log("Purge reports from version " + selectedVersion + " and older.");
console.log(selectedVersion);
ReportsStore.purgeReportsFromAppVersionCodeAndBelow(selectedVersion,
function(nbReports) {
// Intermediate callback
$scope.nbReportsByAppVersionCodeToPurge = nbReports;
},
function(data) {
// Success callback
ReportsStore.appVersionCodesList();
$scope.purgingByAppVersionCode = false;
$scope.nbReportsByAppVersionCodeToPurge = "";
$notify.success({
desktop: true,
timeout: 10000,
@ -84,6 +105,8 @@
},
function(){
// Failure callback
$scope.purgingByAppVersionCode = false;
$scope.nbReportsByAppVersionCodeToPurge = "";
$notify.success({
desktop: true,
timeout: 10000,

View File

@ -170,17 +170,20 @@
* @param year Year of the oldest report to keep.
* @param month Month of the oldest report to keep.
* @param day Day of the oldest report to keep.
* @param cb Success callback (angular $http callback).
* @param intermediateCallback function called when the number of reports to purge is received. The number of
* reports is provided as the first function parameter.
* @param finalCallback Success callback (angular $http callback).
* @param errorHandler Failure callback (angular $http callback).
* @returns {*}
*/
ReportsStore.purgeReportsOlderThan = function(year, month, day, cb, errorHandler) {
ReportsStore.purgeReportsOlderThan = function(year, month, day, intermediateCallback, finalCallback, errorHandler) {
var result;
// This callback purges reports that will be retrieved by the request below
var additionalCallback = function(data) {
var docsToPurge = [];
console.log(data.rows.length + " reports to purge.");
intermediateCallback(data.rows.length);
for(var i = 0; i < data.rows.length; i++) {
var doc = data.rows[i].doc;
doc._deleted = true;
@ -188,7 +191,7 @@
}
console.log("Deleting " + docsToPurge.length + "reports.");
$http.post("/" + ReportsStore.dbName + "/_bulk_docs", { docs: docsToPurge })
.success(cb);
.success(finalCallback);
};
// Fetch old reports to purge them via the previously defined callback
@ -206,17 +209,20 @@
/**
* Purge all reports from app older than given version code.
* @param version Application version code
* @param cb Success callback (angular $http callback).
* @param intermediateCallback function called when the number of reports to purge is received. The number of
* reports is provided as the first function parameter.
* @param finalCallback Success callback (angular $http callback).
* @param errorHandler Failure callback (angular $http callback).
* @returns {*}
*/
ReportsStore.purgeReportsFromAppVersionCodeAndBelow = function(version, cb, errorHandler) {
ReportsStore.purgeReportsFromAppVersionCodeAndBelow = function(version, intermediateCallback, finalCallback, errorHandler) {
var result;
// This callback purges reports that will be retrieved by the request below
var additionalCallback = function(data) {
var docsToPurge = [];
console.log(data.rows.length + " reports to purge.");
intermediateCallback(data.rows.length);
for(var i = 0; i < data.rows.length; i++) {
var doc = data.rows[i].doc;
doc._deleted = true;
@ -224,7 +230,7 @@
}
console.log("Deleting " + docsToPurge.length + "reports.");
$http.post("/" + ReportsStore.dbName + "/_bulk_docs", { docs: docsToPurge })
.success(cb);
.success(finalCallback);
};
// Fetch old reports to purge them via the previously defined callback