Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ vireo.controller('FieldPredicatesController', function ($controller, $timeout, $

$scope.selectFieldPredicate = function(index) {
$scope.resetFieldPredicates();
var filtereFieldPredicates = $filter('filter')($scope.fieldPredicates, $scope.dragAndDropTextFilterValue[$scope.dragAndDropSelectedFilter]);
// Filter exactly the way draganddroplist renders the list, otherwise the index
// handed back by the list does not point at the predicate the user acted on.
var filtereFieldPredicates = $filter('filter')($scope.fieldPredicates, $scope.dragAndDropTextFilterValue);
$scope.modalData = filtereFieldPredicates[index];
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,24 @@ vireo.controller("SubmissionListController", function (NgTableParams, $controlle
column.status = !column.status ? 'previouslyDisabled' : undefined;
};

// Keyboard accessible equivalent of dragging a column to a new position. See issue #1674.
var moveInList = function(list, index, offset) {
var destination = index + offset;

if (destination < 0 || destination >= list.length) {
return;
}

list.splice(destination, 0, list.splice(index, 1)[0]);
updateChange(true);
};

$scope.moveColumn = moveInList;

var moveFilterColumn = function(index, offset) {
moveInList(filterColumns.userFilterColumns, index, offset);
};

$scope.displayedColumnOptions = createDisplayedColumnOptions();

$scope.disabledColumnOptions = createDisabledColumnOptions();
Expand Down Expand Up @@ -1073,6 +1091,7 @@ vireo.controller("SubmissionListController", function (NgTableParams, $controlle
"filterColumns": filterColumns,
"disableFilter": disableFilter,
"enableFilter": enableFilter,
"moveFilterColumn": moveFilterColumn,
"displayedFilterColumnOptions": displayedFilterColumnOptions,
"disabledFilterColumnOptions": disabledFilterColumnOptions,
"saveUserFilters": $scope.saveUserFilters,
Expand Down
56 changes: 56 additions & 0 deletions src/main/webapp/app/directives/dragAndDropListDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ vireo.directive("draganddroplist", function($filter) {
'selectedFilter': '=?',
'textFilterValue': '=?',
'passiveFilter': '=?',
'allowRemove': '=?',
'isEditable': '&',
},
controller: function($scope) {
Expand All @@ -37,6 +38,61 @@ vireo.directive("draganddroplist", function($filter) {
if(typeof $scope.itemView == 'undefined') {
$scope.itemView = 'views/directives/dragAndDropItem.html';
}

// Keyboard accessible alternatives to the drag gestures. Drag and drop cannot be
// the only way to reorder or remove an item. See issue #1674.

$scope.itemControlsView = 'views/directives/dragAndDropItemControls.html';

$scope.canReorder = function () {
return !!($scope.listeners && $scope.listeners.canReorder && $scope.listeners.canReorder());
};

// Lists whose items are deleted somewhere other than the trash can (the embargo
// tables delete from their edit modal) opt out with allow-remove="false".
$scope.canRemove = function () {
if ($scope.allowRemove === false) {
return false;
}
return !!($scope.listeners && $scope.listeners.canRemove && $scope.listeners.canRemove());
};

$scope.moveUp = function (index) {
$scope.listeners.moveItem($scope.scopeValue, index, index - 1);
};

$scope.moveDown = function (index) {
$scope.listeners.moveItem($scope.scopeValue, index, index + 1);
};

$scope.removeItem = function (index) {
$scope.listeners.removeAt(index);
};

// Used to give each control an accessible name that identifies the row it acts on,
// so "Remove" is announced as "Remove Masters of Science" rather than just "Remove".
$scope.itemLabel = function (item) {
var parts = [];

if (item) {
angular.forEach($scope.properties, function (property) {
var value = item[property];
if (angular.isString(value) || angular.isNumber(value)) {
parts.push(value);
} else if (value && angular.isString(value.name)) {
parts.push(value.name);
}
});
}

if (parts.length > 0) {
return parts.join(' ');
}

// The table list view passes column headings rather than item keys as
// properties, so fall back to whatever the item calls itself.
return (item && (item.name || item.label || item.gloss)) || 'this item';
};
},
link: function($scope, elem, attr) {
$scope.properties = angular.fromJson(attr.properties);
Expand Down
53 changes: 53 additions & 0 deletions src/main/webapp/app/directives/keyboardClickableDirective.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Makes a non interactive element that carries an ng-click reachable and operable
* from the keyboard, without changing how it looks. Adds a tab stop and a button
* role when the element does not already declare them, and activates the element
* on Enter or Space the way a native button would.
*
* Use it on clickable spans, images and list items. Native controls (button, a[href],
* input, select, textarea) already do this and do not need the attribute.
*/
vireo.directive("keyboardClickable", function () {

var ENTER = 13;
var SPACE = 32;

return {
restrict: 'A',
link: function ($scope, element, attrs) {

if (attrs.tabindex === undefined) {
element.attr('tabindex', '0');
}

if (attrs.role === undefined) {
element.attr('role', 'button');
}

var isDisabled = function () {
return element.attr('disabled') !== undefined || element.hasClass('disabled');
};

var onKeydown = function (event) {
if (event.which !== ENTER && event.which !== SPACE) {
return;
}

if (isDisabled()) {
return;
}

// Space scrolls the page by default and Enter may submit a surrounding form.
event.preventDefault();

element[0].click();
};

element.on('keydown', onKeydown);

$scope.$on('$destroy', function () {
element.off('keydown', onKeydown);
});
}
};
});
51 changes: 51 additions & 0 deletions src/main/webapp/app/factories/dragAndDropListenerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ vireo.factory('DragAndDropListenerFactory', function($q, ModalService) {
});
};

var relocate = function(list, from, to) {
list.splice(to, 0, list.splice(from, 1)[0]);
};

var dragControls = {
getListener: function () {
return listener;
Expand Down Expand Up @@ -115,6 +119,53 @@ vireo.factory('DragAndDropListenerFactory', function($q, ModalService) {
});
}
},

// Keyboard accessible equivalents of the drag gestures above. These drive the
// per item controls rendered by the draganddroplist directive so that reordering
// and removal never require a pointer. See issue #1674.

canReorder: function() {
return angular.isFunction(listener.reorder);
},

canRemove: function() {
return angular.isFunction(listener.select) && !!listener.confirm.remove.modal;
},

// Mirrors dropping an item on the trash can: select it, then hand off to the
// same confirmation modal the drag gesture opens.
removeAt: function(index) {
if(!dragControls.canRemove()) {
return;
}
original = angular.copy(listener.model);
listener.select(index);
updateRequest();
ModalService.openModal(listener.confirm.remove.modal);
},

// Mirrors dragging an item to a new slot. The list passed in is the rendered
// list, which is what the sortable mutates and what the reorder end points
// expect positions against.
moveItem: function(list, from, to) {
if(!dragControls.canReorder() || !angular.isArray(list)) {
return $q.when();
}
if(from === to || to < 0 || to >= list.length) {
return $q.when();
}
original = angular.copy(listener.model);
relocate(list, from, to);
updateRequest();
return listener.reorder(from + 1, to + 1).then(function(res) {
var message = angular.fromJson(res.body);
if (message.meta.status !== "SUCCESS") {
relocate(list, to, from);
angular.extend(listener.model, original);
}
});
},

containerPositioning: 'relative',
containment: drag.container
};
Expand Down
43 changes: 42 additions & 1 deletion src/main/webapp/app/resources/styles/sass/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,9 @@ h4 {
background: #efefef;
border: dashed thick #fefefe;
padding-top: 35px;
padding-bottom: 10px;
width: 250px;
height: 150px;
min-height: 150px;
color: #696969;
border-radius: 5px;
transition: all 0.35s ease-in;
Expand Down Expand Up @@ -742,6 +743,13 @@ h4 {
cursor: pointer;
}

/* The drop zone is also operable from the keyboard through this button, which opens the
file picker, so the focus has to be visible. */
.upload-drop-zone .invisible-button:focus {
outline: 2px solid #337ab7;
outline-offset: 2px;
}

.upload-drop-zone.dragging .glyphicon-upload,
.upload-drop-zone.reject .glyphicon-ban-circle {
transition: all 0.35s ease-in;
Expand Down Expand Up @@ -1482,6 +1490,39 @@ input[type=color]:focus {
display: inline-block;
}

/* The move buttons are a keyboard alternative to dragging, so unlike the hint arrows
they stay visible rather than waiting for a hover. See issue #1674. */
.displayed-column,
.disabled-column {
display: flex;
align-items: center;
}

.displayed-column > [as-sortable-item-handle],
.disabled-column > [as-sortable-item-handle] {
flex: 1 1 auto;
min-width: 0;
}

.displayed-column > .item-controls,
.disabled-column > .item-controls {
flex: 0 0 auto;
margin-left: 8px;
}

.displayed-column .item-controls .glyphicon,
.disabled-column .item-controls .glyphicon {
display: inline-block;
}

.displayed-column .item-controls .item-control:focus,
.disabled-column .item-controls .item-control:focus,
.displayed-column [as-sortable-item-handle]:focus,
.disabled-column [as-sortable-item-handle]:focus {
outline: 2px solid #337ab7;
outline-offset: 2px;
}

.column-background {
list-style-type: none;
margin: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,55 @@
.as-sortable-placeholder {
border: 1px solid #dcdcdc;
}

/********************************************************
* Keyboard accessible alternatives to the drag gestures *
********************************************************/

.list-dragdrop > li > .list-dragdrop-item,
.list-dragdrop > li > .item-controls-wrapper {
display: inline-block;
vertical-align: middle;
}

.list-dragdrop > li > .item-controls-wrapper {
margin-left: 8px;
}

.item-controls {
white-space: nowrap;
}

.item-controls .item-control {
color: #666666;
}

.item-controls .item-control-remove {
color: #a94442;
}

.item-controls .item-control[disabled] {
opacity: 0.35;
}

/* The edit pencil used to appear only while the row was hovered, which put it out of
reach of the keyboard. It is always rendered now and leans on colour for emphasis. */
.edit-setting-icon {
color: #999999;
margin-left: 6px;
}

.list-dragdrop > li:hover .edit-setting-icon,
.list-dragdrop > li:focus-within .edit-setting-icon,
.edit-setting-icon:hover,
.edit-setting-icon:focus {
color: #333333;
}

/* Every control reached by tabbing needs to show where the focus is. */
.item-controls .item-control:focus,
.edit-setting-icon:focus,
[keyboard-clickable]:focus {
outline: 2px solid #337ab7;
outline-offset: 2px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ <h3>Default Embargoes</h3>
<draganddroplist
dragging="dragging"
scope-value="defaultEmbargoes"
properties='["System", "Name", "Description", "Display", "# of Months", "Edit"]'
properties='["System", "Name", "Description", "Display", "# of Months", "Edit", "Order"]'
list-view='views/directives/dragAndDropTable.html'
allow-remove="false"
item-view='views/directives/dragAndDropEmbargo.html'
sort-label="default"
listeners='dragControlListenersDefault'
Expand Down Expand Up @@ -39,8 +40,9 @@ <h3>ProQuest Embargoes</h3>
<draganddroplist
dragging="dragging"
scope-value="proquestEmbargoes"
properties='["System", "Name", "Description", "Display", "# of Months", "Edit"]'
properties='["System", "Name", "Description", "Display", "# of Months", "Edit", "Order"]'
list-view='views/directives/dragAndDropTable.html'
allow-remove="false"
item-view='views/directives/dragAndDropEmbargo.html'
sort-label="proquest"
listeners='dragControlListenersProquest'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<span ng-repeat="property in properties" class="repeated-span">
<span ng-show="!item.isEntityProperty" class="glyphicon glyphicon-user"></span>
<span ng-show="item.isEntityProperty" class="glyphicon glyphicon-globe"></span> {{ item[property] }}</span>
<span ng-if="!item.isEntityProperty" ng-show="isMouseHover" class="glyphicon glyphicon-pencil edit-setting-icon" ng-click="edit({index:item.position})"></span>
<span ng-if="!item.isEntityProperty" class="glyphicon glyphicon-pencil edit-setting-icon" ng-click="edit({index:item.position})" keyboard-clickable aria-label="Edit {{ itemLabel(item) }}"></span>
</div>
Loading
Loading