Skip to content

Commit

Permalink
Revert "Bug 1121631 - Implement moustrap shortcuts"
Browse files Browse the repository at this point in the history
  • Loading branch information
edmorley committed Jan 21, 2015
1 parent 918dd85 commit a8e784b
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 125 deletions.
1 change: 0 additions & 1 deletion ui/index.html
Expand Up @@ -46,7 +46,6 @@
<script src="vendor/bootstrap.js"></script>
<script src="vendor/angular/angular-sanitize.min.js"></script>
<script src="vendor/angular-local-storage.min.js"></script>
<script src="vendor/mousetrap.min.js"></script>
<script src="vendor/underscore-min.js"></script>
<script src="vendor/resizer.js"></script>

Expand Down
167 changes: 70 additions & 97 deletions ui/js/controllers/main.js
Expand Up @@ -37,17 +37,10 @@ treeherder.controller('MainCtrl', [
ThResultSetModel.setSelectedJob($rootScope.repoName);
};

// Disable single key shortcuts in specified shortcut events
$scope.allowKeys = function() {
Mousetrap.unbind(['i', 'j', 'n', 'k', 'p', 'space', 'u', 'r', 'c']);
};

// Process shortcut events
$scope.processKeyboardInput = function(ev) {
$scope.processKeyboardInput = function(ev){

/* If the user is in an editable element or pressing shift
* then disable keyboard events, unless otherwise enabled
* in inputs by the 'mousetrap' class in markup */
// If the user is in an editable element or the user is pressing
// shift, then disable keyboard events
var activeElement = document.activeElement;
if (activeElement.tagName === 'INPUT' ||
activeElement.tagName === 'SELECT' ||
Expand All @@ -56,101 +49,81 @@ treeherder.controller('MainCtrl', [
return;
}

// Shortcut: toggle display in-progress jobs (pending/running)
Mousetrap.bind('i', function() {
$scope.toggleInProgress();
if (!$scope.$$phase) {
$scope.$digest();
}
});

// Shortcut: highlight next unclassified failure
Mousetrap.bind(['j', 'n'], function() {
$rootScope.$emit(thEvents.selectNextUnclassifiedFailure);
});

// Shortcut: highlight previous unclassified failure
Mousetrap.bind(['k', 'p'], function() {
$rootScope.$emit(thEvents.selectPreviousUnclassifiedFailure);
});

// Shortcut: pin selected job to pinboard
Mousetrap.bind('space', function(ev) {
// If a job is selected add it otherwise
// let the browser handle the spacebar
if ($scope.selectedJob) {
// Prevent page down propagating to the jobs panel
ev.preventDefault();
$rootScope.$emit(thEvents.jobPin, $rootScope.selectedJob);
if (!$scope.$$phase) {
$scope.$digest();
// test for key modifiers to allow browser shortcuts eg.
// console, new/private browsing window, history, print
if (!ev.metaKey && !ev.shiftKey && !ev.ctrlKey) {
if (ev.keyCode === 73) {
// toggle display in-progress jobs(pending/running), key:i
$scope.toggleInProgress();

} else if ((ev.keyCode === 74) || (ev.keyCode === 78)) {
//Highlight next unclassified failure keys:j/n
$rootScope.$emit(
thEvents.selectNextUnclassifiedFailure
);

} else if ((ev.keyCode === 75) || (ev.keyCode === 80)) {
//Highlight previous unclassified failure keys:k/p
$rootScope.$emit(
thEvents.selectPreviousUnclassifiedFailure
);

} else if (ev.keyCode === 32) {
// If a job is selected add it otherwise
// let the browser handle the spacebar
if ($scope.selectedJob) {
// Pin selected job to pinboard, key:[spacebar]
// and prevent page down propagating to the jobs panel
ev.preventDefault();
$rootScope.$emit(thEvents.jobPin, $rootScope.selectedJob);
}
}
});

// Shortcut: display only unclassified failures
Mousetrap.bind('u', function() {
$scope.toggleUnclassifiedFailures();
if (!$scope.$$phase) {
$scope.$digest();
}
});

// Shortcut: pin selected job to pinboard and add a related bug
Mousetrap.bind('r', function(ev) {
if ($scope.selectedJob) {
$rootScope.$emit(thEvents.addRelatedBug,
$rootScope.selectedJob);

// Prevent shortcut key overflow during focus
ev.preventDefault();
$rootScope.$broadcast('focus-this', "related-bug-input");
$scope.allowKeys();
if (!$scope.$$phase) {
$scope.$digest();
} else if (ev.keyCode === 85) {
// Display only unclassified failures, keys:u
$scope.toggleUnclassifiedFailures();

} else if (ev.keyCode === 82) {
// Pin selected job to pinboard and add a related bug, key:r
if ($scope.selectedJob) {
$rootScope.$emit(thEvents.addRelatedBug,
$rootScope.selectedJob);

// Prevent shortcut key overflow during focus
ev.preventDefault();
$rootScope.$broadcast('focus-this', "related-bug-input");
}
}
});

// Shortcut: pin selected job to pinboard and enter classification
Mousetrap.bind('c', function(ev) {
if ($scope.selectedJob) {
$rootScope.$emit(thEvents.jobPin, $rootScope.selectedJob);

// Prevent shortcut key overflow during focus
ev.preventDefault();
$rootScope.$broadcast('focus-this', "classification-comment");
$scope.allowKeys();
if (!$scope.$$phase) {
$scope.$digest();

} else if (ev.keyCode === 67) {
// Pin selected job to pinboard and enter classification
// key:c
if ($scope.selectedJob) {
$rootScope.$emit(thEvents.jobPin, $rootScope.selectedJob);

// Prevent shortcut key overflow during focus
ev.preventDefault();
$rootScope.$broadcast('focus-this', "classification-comment");
}
}
});

// Shortcut: escape closes any open panels and clears selected job
Mousetrap.bind('escape', function() {
$scope.setFilterPanelShowing(false);
$scope.setSettingsPanelShowing(false);
$scope.setSheriffPanelShowing(false);
$scope.closeJob();
if (!$scope.$$phase) {
$scope.$digest();
}
});

// Shortcut: clear the pinboard
Mousetrap.bind('ctrl+shift+u', function() {
$rootScope.$emit(thEvents.clearPinboard);
if (!$scope.$$phase) {
$scope.$digest();
} else if (ev.keyCode === 27) {
// Escape closes any open panels and clears the selected job
$scope.setFilterPanelShowing(false);
$scope.setSettingsPanelShowing(false);
$scope.setSheriffPanelShowing(false);
$scope.closeJob();
}
});

// Shortcut: save pinboard classification and related bugs
Mousetrap.bind('ctrl+enter', function() {
$rootScope.$emit(thEvents.saveClassification);
});
// Clear the pinboard: Ctrl+Shift+u
} else if (!ev.metaKey && !ev.altKey && ev.shiftKey && ev.ctrlKey) {
if ((ev.keyCode === 85) && $scope.selectedJob) {
$rootScope.$emit(thEvents.clearPinboard);
}

// Save pinboard classification and related bugs: Ctrl+Enter
} else if (!ev.metaKey && !ev.altKey && !ev.shiftKey && ev.ctrlKey) {
if ((ev.keyCode === 13) && $scope.selectedJob) {
$rootScope.$emit(thEvents.saveClassification);
}
}
};

$scope.repoModel = ThRepositoryModel;
Expand Down
6 changes: 3 additions & 3 deletions ui/partials/main/thPinboardPanel.html
Expand Up @@ -13,7 +13,7 @@
<!-- Related bugs -->
<div id="pinboard-related-bugs">
<div class="content">
<a ng-click="toggleEnterBugNumber(!enteringBugNumber)"
<a ng-click="toggleEnterBugNumber()"
class="click-able-icon"
title="Add a related bug">
<i class="fa fa-plus-square add-related-bugs-icon"></i>
Expand All @@ -26,7 +26,7 @@
class="add-related-bugs-form">
<input id="related-bug-input"
type="number"
class="add-related-bugs-input mousetrap"
class="add-related-bugs-input"
ng-model="$parent.newEnteredBugNumber"
placeholder="enter bug number"
focus-me="focusInput">
Expand All @@ -49,7 +49,7 @@
<div class="classification-comment-container">
<input id="classification-comment"
type="text"
class="form-control add-classification-input mousetrap"
class="form-control add-classification-input"
ng-model="classification.note"
focus-this blur-this></input>
<span class="pinboard-preload-txt classification-comment-preload-txt"
Expand Down
27 changes: 12 additions & 15 deletions ui/plugins/pinboard.js
Expand Up @@ -20,7 +20,7 @@ treeherder.controller('PinboardCtrl', [

$rootScope.$on(thEvents.addRelatedBug, function(event, job) {
$scope.pinJob(job);
$scope.toggleEnterBugNumber(true);
$scope.toggleEnterBugNumber();
});

$rootScope.$on(thEvents.saveClassification, function(event) {
Expand Down Expand Up @@ -73,7 +73,6 @@ treeherder.controller('PinboardCtrl', [
$scope.classification.who = $scope.user.email;
var classification = $scope.classification;
thPinboard.save(classification);
$scope.completeClassification();
$scope.classification = thPinboard.createNewClassification();
} else {
thNotify.send("must be logged in to save job classifications", "danger");
Expand Down Expand Up @@ -105,26 +104,24 @@ treeherder.controller('PinboardCtrl', [
return thPinboard.hasRelatedBugs();
};

$scope.toggleEnterBugNumber = function(tf) {
$scope.enteringBugNumber = tf;
$scope.focusInput = tf;
$scope.toggleEnterBugNumber = function() {
$scope.enteringBugNumber = !$scope.enteringBugNumber;
$scope.focusInput = $scope.enteringBugNumber;
};

$scope.completeClassification = function() {
$rootScope.$broadcast('blur-this', "classification-comment");
};

$scope.saveEnteredBugNumber = function() {
if ($scope.enteringBugNumber) {
if (!$scope.newEnteredBugNumber) {
$scope.toggleEnterBugNumber(false);
} else {
$log.debug("new bug number to be saved: ",
$scope.newEnteredBugNumber);
thPinboard.addBug({id:$scope.newEnteredBugNumber});
$scope.toggleEnterBugNumber(false);
$scope.newEnteredBugNumber = "";
}
if (!$scope.newEnteredBugNumber) {
$scope.toggleEnterBugNumber();
} else {
$log.debug("new bug number to be saved: ",
$scope.newEnteredBugNumber);
thPinboard.addBug({id:$scope.newEnteredBugNumber});
$scope.toggleEnterBugNumber();
$scope.newEnteredBugNumber = "";
}
};

Expand Down
9 changes: 0 additions & 9 deletions ui/vendor/mousetrap.min.js

This file was deleted.

0 comments on commit a8e784b

Please sign in to comment.