Skip to content

Commit

Permalink
Bug 1111697 - remove $.deparam use on MainCtrl and jobfilters
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Dawson committed Dec 16, 2014
1 parent 318e79c commit c2766ad
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 83 deletions.
1 change: 0 additions & 1 deletion ui/index.html
Expand Up @@ -38,7 +38,6 @@

<!-- build:js js/index.min.js -->
<script src="vendor/jquery-2.0.3.js"></script>
<script src="vendor/jquery.deparam.js"></script>
<script src="vendor/angular/angular.js"></script>
<script src="vendor/angular/angular-route.js"></script>
<script src="vendor/angular/angular-resource.js"></script>
Expand Down
45 changes: 18 additions & 27 deletions ui/js/controllers/main.js
Expand Up @@ -98,7 +98,7 @@ treeherder.controller('MainCtrl', [

// Ctrl+Enter saves pinboard classification and related bugs
} else if (!ev.metaKey && !ev.altKey && !ev.shiftKey && ev.ctrlKey) {
if ((ev.keyCode == 13) && $scope.selectedJob) {
if ((ev.keyCode === 13) && $scope.selectedJob) {
$rootScope.$emit(thEvents.saveClassification);
}
}
Expand Down Expand Up @@ -193,46 +193,37 @@ treeherder.controller('MainCtrl', [

};

/**
* Extract the params from the querystring of this url that should
* trigger a reload of the page, because it requires new data from
* the repo
* @param urlStr a full Url as a string
* @returns Object containing only the params in ``reloadFields``
*/
var getTriggerParams = function(urlStr) {
var tokens = urlStr.split("?");
var triggerParams = {};

if (tokens.length > 1) {
triggerParams = _.pick(
$.deparam(tokens[1]),
ThResultSetModel.reloadOnChangeParameters
);
}

return triggerParams;
var getNewReloadTriggerParams = function() {
return _.pick(
$location.search(),
ThResultSetModel.reloadOnChangeParameters
);
};

$scope.cachedReloadTriggerParams = getNewReloadTriggerParams();

// reload the page if certain params were changed in the URL. For
// others, such as filtering, just re-filter without reload.
$rootScope.$on('$locationChangeSuccess', function(ev, newUrl, oldUrl) {
$rootScope.$on('$locationChangeSuccess', function() {

// used to test for display of watched-repo-navbar
$rootScope.locationPath = $location.path().replace('/', '');

// used to avoid bad urls when the app redirects internally
$rootScope.urlBasePath = $location.absUrl().split('?')[0];

$log.debug("check for reload", "newUrl=", newUrl, "oldUrl=", oldUrl);

var oldParams = getTriggerParams(oldUrl);
var newParams = getTriggerParams(newUrl);
var newReloadTriggerParams = getNewReloadTriggerParams();
// if we are just setting the repo to the default because none was
// set initially, then don't reload the page.
var defaulting = newParams.repo === thDefaultRepo && !oldParams.repo;
if (!_.isEqual(oldParams, newParams) && !defaulting) {
var defaulting = newReloadTriggerParams.repo === thDefaultRepo &&
!$scope.cachedReloadTriggerParams.repo;

if (!defaulting && $scope.cachedReloadTriggerParams &&
!_.isEqual(newReloadTriggerParams, $scope.cachedReloadTriggerParams)) {

$window.location.reload();
} else {
$scope.cachedReloadTriggerParams = newReloadTriggerParams;
}
});

Expand Down
36 changes: 12 additions & 24 deletions ui/js/services/jobfilters.js
Expand Up @@ -113,45 +113,32 @@ treeherder.factory('thJobFilters', [
var cachedResultStatusFilters = {};
var cachedClassifiedStateFilters = {};
var cachedFieldFilters = {};
var cachedFilterParams;

/**
* Checks for a filter change and, if detected, updates the cached filter
* values from the query string. Then publishes the global event
* to re-render jobs.
*/
$rootScope.$on('$locationChangeSuccess', function(ev, newUrl, oldUrl) {
$rootScope.$on('$locationChangeSuccess', function() {

$log.debug("check for refilter", "newUrl=", newUrl, "oldUrl=", oldUrl);
var newFilterParams = getNewFilterParams();

var oldFilters = _getFilterParams(oldUrl);
var newFilters = _getFilterParams(newUrl);
if (!_.isEqual(oldFilters, newFilters)) {
if (!_.isEqual(cachedFilterParams, newFilterParams)) {
cachedFilterParams = newFilterParams;
_refreshFilterCaches();
$rootScope.$emit(thEvents.globalFilterChanged);
}

});

/**
* Take a url string and extract all the query string params that
* begin with the filter prefix.
*
* @param urlStr a full Url as a string
* @returns Object containing only the params with the PREFIX
*/
var _getFilterParams = function(urlStr) {
var tokens = urlStr.split("?");
var getNewFilterParams = function() {
var filterParams = {};

if (tokens.length > 1) {
var qsParams = $.deparam(tokens[1]);
_.each(qsParams, function (value, field) {
if (_startsWith(field, PREFIX)) {
filterParams[field] = value;
}
});
}

_.each($location.search(), function (value, field) {
if (_startsWith(field, PREFIX)) {
filterParams[field] = value;
}
});
return filterParams;
};

Expand Down Expand Up @@ -557,6 +544,7 @@ treeherder.factory('thJobFilters', [
};

// initialize caches on initial load
cachedFilterParams = getNewFilterParams();
_refreshFilterCaches();

/*********************************
Expand Down
31 changes: 0 additions & 31 deletions ui/vendor/jquery.deparam.js

This file was deleted.

0 comments on commit c2766ad

Please sign in to comment.