Skip to content

Commit

Permalink
Bug 1313719 : History view for scheduled rules (#207). r=bhearsum
Browse files Browse the repository at this point in the history
  • Loading branch information
NinadBhat authored and bhearsum committed Jan 10, 2017
1 parent 14410bb commit 0dcb442
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 8 deletions.
39 changes: 38 additions & 1 deletion ui/app/js/controllers/rule_scheduled_changes_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ function($scope, $routeParams, $location, $timeout, Rules, Search, $modal, $rout
$scope.loading = true;
$scope.failed = false;

$scope.sc_id = parseInt($routeParams.sc_id, 10);

function loadPage(newPage) {
Rules.getScheduledChangeHistory($scope.sc_id, $scope.pageSize, newPage)
.success(function(response) {
$scope.scheduled_changes = response.revisions;
$scope.scheduled_changes_rules_count = response.count;
})
.error(function() {
console.error(arguments);
$scope.failed = true;
})
.finally(function() {
$scope.loading = false;
});
}

if ($scope.sc_id) {
// history of a specific rule
$scope.$watch("currentPage", function(newPage) {
loadPage(newPage);
});
} else {
Rules.getScheduledChanges()
.success(function(response) {
// "when" is a unix timestamp, but it's much easier to work with Date objects,
Expand All @@ -22,12 +45,22 @@ function($scope, $routeParams, $location, $timeout, Rules, Search, $modal, $rout
.finally(function() {
$scope.loading = false;
});
}

$scope.$watch("ordering_str", function(value) {
$scope.ordering = value.value.split(",");
});

$scope.ordering_options = [

if ($scope.sc_id) {
$scope.ordering_options = [
{
text: "Data Version",
value: "-data_version"
},
];
} else {
$scope.ordering_options = [
{
text: "When",
value: "when"
Expand All @@ -37,6 +70,7 @@ function($scope, $routeParams, $location, $timeout, Rules, Search, $modal, $rout
value: "product,channel"
},
];
}

$scope.ordering_str = $scope.ordering_options[0];

Expand All @@ -56,6 +90,9 @@ function($scope, $routeParams, $location, $timeout, Rules, Search, $modal, $rout
$scope.state_str = $scope.state_filter[0];

$scope.filterBySelect = function(sc) {
if($scope.sc_id) {
return true;
}
if ($scope.state_str.value === "complete" && sc.complete) {
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions ui/app/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ angular.module("app").config(function($routeProvider, $locationProvider) {
reloadOnSearch: false
})

.when("/scheduled_changes/rules/:sc_id", {
templateUrl: "rule_scheduled_changes.html",
controller: "RuleScheduledChangesController",
reloadOnSearch: false
})

.when('/rules', {
templateUrl: 'rules.html',
controller: 'RulesController',
Expand Down
3 changes: 3 additions & 0 deletions ui/app/js/services/rules_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ angular.module("app").factory('Rules', function($http) {
data.csrf_token = csrf_token;
return $http.post("/api/scheduled_changes/rules", data);
},
getScheduledChangeHistory: function(sc_id, limit, page) {
return $http.get('/api/scheduled_changes/rules/' + sc_id + '/revisions?limit=' + limit + '&page=' + page);
},
updateScheduledChange: function(sc_id, data, csrf_token) {
data = jQuery.extend({}, data);
if (data.when === null) {
Expand Down
24 changes: 17 additions & 7 deletions ui/app/templates/rule_scheduled_changes.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<div loader ng-show="loading"></div>

<h2>
<span>Scheduled Rule Changes</span>
<span ng-show="!scheduled_changes_rules_count">Scheduled Rule Changes</span>
<span ng-show="scheduled_changes_rules_count">History for Scheduled Rule Change</span>

<span class="count">
({{ filtered_items.length | number:0 }}
<span>found)</span>
</span>

<button class="btn btn-primary btn-xs" ng-click="openNewScheduledRuleChangeModal()">
<button ng-show="!scheduled_changes_rules_count" class="btn btn-primary btn-xs" ng-click="openNewScheduledRuleChangeModal()">
Add a new Scheduled Rule Change
<i class="glyphicon glyphicon-plus"></i>
</button>
<a href="/rules/scheduled_changes" class="btn btn-primary btn-xs"
ng-show="scheduled_changes_rules_count">
All Scheduled Changes
<i class="glyphicon glyphicon-arrow-left"></i>
</a>

</h2>

Expand All @@ -27,7 +33,7 @@ <h2>
</div>
</div>
<div class="col-sm-6 text-right">
<div class="row">
<div ng-show="!scheduled_changes_rules_count" class="row">
<label>State:</label>
<select ng-model="state_str" name="state_filter" ng-options="o.text for o in state_filter track by o.value">
</select>
Expand All @@ -47,9 +53,10 @@ <h2>

<h3 class="panel-title">
<div style="float: right">
<button class="btn btn-default btn-xs" ng-click="openUpdateModal(sc)">Update</button>
<button class="btn btn-default btn-xs" ng-click="openDeleteModal(sc)">Delete</button>
<a class="btn btn-default btn-xs" ng-href="/scheduled_changes/rules/{{ sc.sc_id }}">History</a>
<i ng-if=" scheduled_changes_rules_count && $first && (currentPage == 1)">Current</i>
<button ng-show="!scheduled_changes_rules_count" class="btn btn-default btn-xs" ng-click="openUpdateModal(sc)">Update</button>
<button ng-show="!scheduled_changes_rules_count" class="btn btn-default btn-xs" ng-click="openDeleteModal(sc)">Delete</button>
<a ng-show="!scheduled_changes_rules_count" class="btn btn-default btn-xs" ng-href="/scheduled_changes/rules/{{ sc.sc_id }}">History</a>
</div>

<i title="Product" ng-show="!sc.product">no product</i>
Expand Down Expand Up @@ -140,7 +147,10 @@ <h5 title="Data Version">
</dl>

</div>

<div class="panel-footer" ng-show="scheduled_changes_rules_count">
Changed by <code>{{ sc.changed_by }}</code>
<span moment="sc.timestamp"></span>
</div>
</div>


Expand Down

0 comments on commit 0dcb442

Please sign in to comment.