Skip to content

Commit

Permalink
Merge pull request #213 from mozilla/bug-1074539-reload-on-redirect
Browse files Browse the repository at this point in the history
bug 1066324 and bug 1074539 - bad page reload gives error
  • Loading branch information
camd committed Sep 30, 2014
2 parents 5a9ce25 + 442fe3a commit dd869ae
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 29 deletions.
2 changes: 1 addition & 1 deletion ui/index.html
Expand Up @@ -40,7 +40,7 @@

<!-- build:js js/index.min.js -->
<script src="vendor/jquery-2.0.3.js"></script>
<script src="vendor/jquery.ba-bbq.min.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
8 changes: 4 additions & 4 deletions ui/js/controllers/jobs.js
Expand Up @@ -2,12 +2,12 @@

treeherder.controller('JobsCtrl', [
'$scope', '$http', '$rootScope', '$routeParams', 'ThLog', '$cookies',
'localStorageService', 'thUrl', 'ThRepositoryModel',
'localStorageService', 'thUrl', 'ThRepositoryModel', 'thDefaultRepo',
'ThResultSetModel', 'thResultStatusList', '$location', 'thEvents',
'ThJobModel',
function JobsCtrl(
$scope, $http, $rootScope, $routeParams, ThLog, $cookies,
localStorageService, thUrl, ThRepositoryModel,
localStorageService, thUrl, ThRepositoryModel, thDefaultRepo,
ThResultSetModel, thResultStatusList, $location, thEvents, ThJobModel) {

var $log = new ThLog(this.constructor.name);
Expand All @@ -23,8 +23,8 @@ treeherder.controller('JobsCtrl', [
$routeParams.repo !== "") {
$rootScope.repoName = $routeParams.repo;
} else {
$rootScope.repoName = "mozilla-central";
$location.search("repo", "mozilla-central");
$rootScope.repoName = thDefaultRepo;
$location.search("repo", $rootScope.repoName);
}

ThResultSetModel.addRepository($scope.repoName);
Expand Down
19 changes: 13 additions & 6 deletions ui/js/controllers/main.js
Expand Up @@ -5,11 +5,13 @@ treeherder.controller('MainCtrl', [
'localStorageService', 'ThRepositoryModel', 'thPinboard',
'thClassificationTypes', 'thEvents', '$interval', '$window',
'ThExclusionProfileModel', 'thJobFilters', 'ThResultSetModel',
'thDefaultRepo',
function MainController(
$scope, $rootScope, $routeParams, $location, ThLog,
localStorageService, ThRepositoryModel, thPinboard,
thClassificationTypes, thEvents, $interval, $window,
ThExclusionProfileModel, thJobFilters, ThResultSetModel) {
ThExclusionProfileModel, thJobFilters, ThResultSetModel,
thDefaultRepo) {

var $log = new ThLog("MainCtrl");

Expand Down Expand Up @@ -205,12 +207,17 @@ treeherder.controller('MainCtrl', [
// when the app redirects internally
$rootScope.urlBasePath = $location.absUrl().split('?')[0];

// give the page a way to determine which nav toolbar to show
// 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) {
$log.debug("reload", "newUrl=", newUrl, "oldUrl=", oldUrl);

if (!_.isEqual(getTriggerParams(oldUrl),
getTriggerParams(newUrl))) {
$log.debug("check for reload", "newUrl=", newUrl, "oldUrl=", oldUrl);

var oldParams = getTriggerParams(oldUrl);
var newParams = getTriggerParams(newUrl);
// 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) {
$window.location.reload();
} else {
thJobFilters.buildFiltersFromQueryString();
Expand Down
2 changes: 2 additions & 0 deletions ui/js/values.js
Expand Up @@ -48,3 +48,5 @@ treeherder.value("thRepoGroupOrder", {
"taskcluster": 5,
"qa automation tests": 6
});

treeherder.value("thDefaultRepo", "mozilla-central");
18 changes: 0 additions & 18 deletions ui/vendor/jquery.ba-bbq.min.js

This file was deleted.

20 changes: 20 additions & 0 deletions ui/vendor/jquery.deparam.js
@@ -0,0 +1,20 @@
/**
* jQuery.deparam - The oposite of jQuery param. Creates an object of query string parameters.
*
* Credits for the idea and Regex:
* http://stevenbenner.com/2010/03/javascript-regex-trick-parse-a-query-string-into-an-object/
*/
(function($){
$.deparam = $.deparam || function(uri){
if(uri === undefined){
uri = window.location.search;
}
var queryString = {};
uri.replace(
new RegExp(
"([^?=&]+)(=([^&#]*))?", "g"),
function($0, $1, $2, $3) { queryString[$1] = $3; }
);
return queryString;
};
})(jQuery);

0 comments on commit dd869ae

Please sign in to comment.