Skip to content

Commit

Permalink
bug 1285975: product/channel filter not updated after adding/editting (
Browse files Browse the repository at this point in the history
…#188). r=bhearsum
  • Loading branch information
njirap authored and bhearsum committed Dec 19, 2016
1 parent aa444df commit a23096f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 7 deletions.
20 changes: 18 additions & 2 deletions ui/app/js/controllers/rule_edit_controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*global sweetAlert */
angular.module('app').controller('RuleEditCtrl',
function ($scope, $modalInstance, CSRF, Rules, Releases, rule) {
function ($scope, $modalInstance, CSRF, Rules, Releases, rule, pr_ch_options) {

$scope.names = [];
Releases.getNames().then(function(names) {
Expand All @@ -21,6 +21,7 @@ function ($scope, $modalInstance, CSRF, Rules, Releases, rule) {
$scope.rule = angular.copy(rule);

$scope.saving = false;
$scope.pr_ch_options = pr_ch_options;

$scope.saveChanges = function () {
$scope.saving = true;
Expand All @@ -31,7 +32,22 @@ function ($scope, $modalInstance, CSRF, Rules, Releases, rule) {
.success(function(response) {
$scope.rule.data_version = response.new_data_version;
angular.copy($scope.rule, $scope.original_rule);
$scope.saving = false;

if(rule.product) {
// The first entry is special, and we want to avoid it getting sorted later.
first_entry = $scope.pr_ch_options.shift();
if($scope.products.indexOf(rule.product) === -1) {
$scope.pr_ch_options.push(rule.product);
if(rule.channel) {
$scope.pr_ch_options.push(rule.product + "," + rule.channel);
}
}
else if($scope.channels.indexOf(rule.channel) === -1) {
$scope.pr_ch_options.push(rule.product + "," + rule.channel);
}
$scope.pr_ch_options.sort().unshift(first_entry);
}

$modalInstance.close();
})
.error(function(response) {
Expand Down
19 changes: 18 additions & 1 deletion ui/app/js/controllers/rule_new_controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('app').controller('NewRuleCtrl',
function($scope, $http, $modalInstance, CSRF, Releases, Rules, rules, rule) {
function($scope, $http, $modalInstance, CSRF, Releases, Rules, rules, rule, pr_ch_options) {

$scope.names = [];
Releases.getNames().then(function(names) {
Expand All @@ -20,6 +20,7 @@ function($scope, $http, $modalInstance, CSRF, Releases, Rules, rules, rule) {
$scope.rule = rule;
$scope.errors = {};
$scope.saving = false;
$scope.pr_ch_options = pr_ch_options;

$scope.saveChanges = function () {
$scope.saving = true;
Expand All @@ -33,6 +34,22 @@ function($scope, $http, $modalInstance, CSRF, Releases, Rules, rules, rule) {
$scope.rule.data_version = 1;
$scope.rule.rule_id = parseInt(response, 10);
$scope.rules.push($scope.rule);

if(rule.product) {
// The first entry is special, and we want to avoid it getting sorted later.
first_entry = $scope.pr_ch_options.shift();
if($scope.products.indexOf(rule.product) === -1) {
$scope.pr_ch_options.push(rule.product);
if(rule.channel) {
$scope.pr_ch_options.push(rule.product + "," + rule.channel);
}
}
else if($scope.channels.indexOf(rule.channel) === -1) {
$scope.pr_ch_options.push(rule.product + "," + rule.channel);
}
$scope.pr_ch_options.sort().unshift(first_entry);
}

$modalInstance.close();
})
.error(function(response, status) {
Expand Down
19 changes: 16 additions & 3 deletions ui/app/js/controllers/rules_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ function($scope, $routeParams, $location, $timeout, Rules, Search, $modal, $rout
$scope.failed = false;

$scope.rule_id = parseInt($routeParams.id, 10);
$scope.pr_ch_options = ["All rules"];
$scope.pr_ch_options = [];

$scope.currentPage = 1;
$scope.pageSize = 20;
$scope.maxSize = 10;
$scope.rules = [];
$scope.pr_ch_filter = "";

function loadPage(newPage) {
Rules.getHistory($scope.rule_id, $scope.pageSize, newPage)
Expand Down Expand Up @@ -54,6 +55,10 @@ function($scope, $routeParams, $location, $timeout, Rules, Search, $modal, $rout
}
});
});
})
.finally(function() {
$scope.pr_ch_options.sort().unshift("All rules");
$scope.pr_ch_filter = $scope.pr_ch_options[0];
});
});
})
Expand Down Expand Up @@ -98,7 +103,6 @@ function($scope, $routeParams, $location, $timeout, Rules, Search, $modal, $rout
];
}
$scope.ordering_str = $scope.ordering_options[0];
$scope.pr_ch_filter = $scope.pr_ch_options[0];

$scope.filters = {
search: $location.hash(),
Expand Down Expand Up @@ -126,7 +130,7 @@ function($scope, $routeParams, $location, $timeout, Rules, Search, $modal, $rout
$scope.removeFilterSearchWord = Search.removeFilterSearchWord;

$scope.filterBySelect = function(rule) {
if ($scope.pr_ch_selected[0] === "All rules") {
if ($scope.pr_ch_selected[0].toLowerCase() === "all rules") {
return true;
}
else if ($scope.pr_ch_selected && $scope.pr_ch_selected.length > 1) {
Expand All @@ -152,6 +156,9 @@ function($scope, $routeParams, $location, $timeout, Rules, Search, $modal, $rout
// },
rule: function () {
return rule;
},
pr_ch_options: function() {
return $scope.pr_ch_options;
}
}
});
Expand Down Expand Up @@ -212,6 +219,9 @@ function($scope, $routeParams, $location, $timeout, Rules, Search, $modal, $rout
update_type: 'minor',
_duplicate: false,
};
},
pr_ch_options: function() {
return $scope.pr_ch_options;
}
}
});
Expand All @@ -234,6 +244,9 @@ function($scope, $routeParams, $location, $timeout, Rules, Search, $modal, $rout
copy._duplicate = true;
return copy;
},
pr_ch_options: function() {
return $scope.pr_ch_options;
}
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/rules.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h2>
<div class="row">
<label>Product/Channel filter:</label>
<select ng-model="pr_ch_filter" name="pr_ch_filter"
ng-options="pr_ch_pair for pr_ch_pair in pr_ch_options.sort() track by pr_ch_pair">
ng-options="pr_ch_pair for pr_ch_pair in pr_ch_options track by pr_ch_pair">
</select>
</div>
<div class="row">
Expand Down
2 changes: 2 additions & 0 deletions ui/spec/controllers/rule_edit_controller_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("controller: RuleEditCtrl", function() {
"distVersion": null,
"whitelist": null
};
var pr_ch_options = ['GMP'];

beforeEach(inject(function($controller, $rootScope, $location, $modal, Rules, Releases, $httpBackend) {
this.$location = $location;
Expand All @@ -44,6 +45,7 @@ describe("controller: RuleEditCtrl", function() {
Rules: Rules,
Releases: Releases,
rule: rule,
pr_ch_options: pr_ch_options,
});
}));

Expand Down
2 changes: 2 additions & 0 deletions ui/spec/controllers/rule_new_controller_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ describe("controller: NewRuleController", function() {
update_type: 'minor',
_duplicate: false,
};
var pr_ch_options = ['GMP'];

beforeEach(inject(function($controller, $rootScope, $location, $modal, Rules, Releases, $httpBackend) {
this.$location = $location;
Expand All @@ -140,6 +141,7 @@ describe("controller: NewRuleController", function() {
Releases: Releases,
rules: rules,
rule: rule,
pr_ch_options: pr_ch_options,
});
}));

Expand Down

0 comments on commit a23096f

Please sign in to comment.