Summary:
Ref T10333. When workboards are ordered (for example, by priority), add headers to the various groups. Major goals are:
- Allow users to drag-and-drop to set values that no cards currently have: for example, you can change a card priority to "normal" by dragging it under the "normal" header, even if no other cards in the column are currently "Normal".
- Make future orderings more useful, particularly "order by assignee". We don't really have room to put the username on every card and it would create a fair amount of clutter, but we can put usernames in these headers and then reference them with just the profile picture. This also allows you to assign to users who are not currently assigned anything in a given column.
- Make the drag-and-drop behavior more obvious by showing what it will do more clearly (see T8135).
- Make things a little easier to scan in general: because space on cards is limited, some information isn't conveyed very clearly (for example, priority information is currently conveyed //only// through color, which can be hard to pick out visually and is probably not functional for users who need vision accommodations).
- Maybe do "swimlanes": this is pretty much a "swimlanes" UI if we add whitespace at the bottom of each group so that the headers line up across all the columns (e.g., "Normal" is at the same y-axis position in every column as you scroll down the page). Not sold on this being useful, but it's just a UI adjustment if we do want to try it.
NOTE: This only makes these headers work for display.
They aren't yet recognized as targets by the drag list UI, so you can't drag cards into an empty group. I'll tackle that in a followup.
Test Plan: {F6257686}
Reviewers: amckinley
Reviewed By: amckinley
Maniphest Tasks: T10333
Differential Revision: https://secure.phabricator.com/D20247
378 lines
8.9 KiB
JavaScript
378 lines
8.9 KiB
JavaScript
/**
|
|
* @provides javelin-workboard-column
|
|
* @requires javelin-install
|
|
* javelin-workboard-card
|
|
* javelin-workboard-header
|
|
* @javelin
|
|
*/
|
|
|
|
JX.install('WorkboardColumn', {
|
|
|
|
construct: function(board, phid, root) {
|
|
this._board = board;
|
|
this._phid = phid;
|
|
this._root = root;
|
|
|
|
this._panel = JX.DOM.findAbove(root, 'div', 'workpanel');
|
|
this._pointsNode = JX.DOM.find(this._panel, 'span', 'column-points');
|
|
|
|
this._pointsContentNode = JX.DOM.find(
|
|
this._panel,
|
|
'span',
|
|
'column-points-content');
|
|
|
|
this._cards = {};
|
|
this._headers = {};
|
|
this._objects = [];
|
|
this._naturalOrder = [];
|
|
},
|
|
|
|
members: {
|
|
_phid: null,
|
|
_root: null,
|
|
_board: null,
|
|
_cards: null,
|
|
_headers: null,
|
|
_naturalOrder: null,
|
|
_panel: null,
|
|
_pointsNode: null,
|
|
_pointsContentNode: null,
|
|
_dirty: true,
|
|
_objects: null,
|
|
|
|
getPHID: function() {
|
|
return this._phid;
|
|
},
|
|
|
|
getRoot: function() {
|
|
return this._root;
|
|
},
|
|
|
|
getCards: function() {
|
|
return this._cards;
|
|
},
|
|
|
|
getCard: function(phid) {
|
|
return this._cards[phid];
|
|
},
|
|
|
|
getBoard: function() {
|
|
return this._board;
|
|
},
|
|
|
|
setNaturalOrder: function(order) {
|
|
this._naturalOrder = order;
|
|
return this;
|
|
},
|
|
|
|
getPointsNode: function() {
|
|
return this._pointsNode;
|
|
},
|
|
|
|
getPointsContentNode: function() {
|
|
return this._pointsContentNode;
|
|
},
|
|
|
|
getWorkpanelNode: function() {
|
|
return this._panel;
|
|
},
|
|
|
|
newCard: function(phid) {
|
|
var card = new JX.WorkboardCard(this, phid);
|
|
|
|
this._cards[phid] = card;
|
|
this._naturalOrder.push(phid);
|
|
|
|
return card;
|
|
},
|
|
|
|
removeCard: function(phid) {
|
|
var card = this._cards[phid];
|
|
delete this._cards[phid];
|
|
|
|
for (var ii = 0; ii < this._naturalOrder.length; ii++) {
|
|
if (this._naturalOrder[ii] == phid) {
|
|
this._naturalOrder.splice(ii, 1);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return card;
|
|
},
|
|
|
|
addCard: function(card, after) {
|
|
var phid = card.getPHID();
|
|
|
|
card.setColumn(this);
|
|
this._cards[phid] = card;
|
|
|
|
var index = 0;
|
|
|
|
if (after) {
|
|
for (var ii = 0; ii < this._naturalOrder.length; ii++) {
|
|
if (this._naturalOrder[ii] == after) {
|
|
index = ii + 1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (index > this._naturalOrder.length) {
|
|
this._naturalOrder.push(phid);
|
|
} else {
|
|
this._naturalOrder.splice(index, 0, phid);
|
|
}
|
|
|
|
return this;
|
|
},
|
|
|
|
getCardNodes: function() {
|
|
var cards = this.getCards();
|
|
|
|
var nodes = [];
|
|
for (var k in cards) {
|
|
nodes.push(cards[k].getNode());
|
|
}
|
|
|
|
return nodes;
|
|
},
|
|
|
|
getCardPHIDs: function() {
|
|
return JX.keys(this.getCards());
|
|
},
|
|
|
|
getPointLimit: function() {
|
|
return JX.Stratcom.getData(this.getRoot()).pointLimit;
|
|
},
|
|
|
|
markForRedraw: function() {
|
|
this._dirty = true;
|
|
},
|
|
|
|
isMarkedForRedraw: function() {
|
|
return this._dirty;
|
|
},
|
|
|
|
getHeader: function(key) {
|
|
if (!this._headers[key]) {
|
|
this._headers[key] = new JX.WorkboardHeader(this, key);
|
|
}
|
|
return this._headers[key];
|
|
},
|
|
|
|
_getCardHeaderKey: function(card, order) {
|
|
switch (order) {
|
|
case 'priority':
|
|
return 'priority(' + card.getPriority() + ')';
|
|
default:
|
|
return null;
|
|
}
|
|
},
|
|
|
|
redraw: function() {
|
|
var board = this.getBoard();
|
|
var order = board.getOrder();
|
|
|
|
var list;
|
|
var has_headers;
|
|
if (order == 'natural') {
|
|
list = this._getCardsSortedNaturally();
|
|
has_headers = false;
|
|
} else {
|
|
list = this._getCardsSortedByKey(order);
|
|
has_headers = true;
|
|
}
|
|
|
|
var ii;
|
|
var objects = [];
|
|
|
|
var header_keys = [];
|
|
var seen_headers = {};
|
|
if (has_headers) {
|
|
var header_templates = board.getHeaderTemplatesForOrder(order);
|
|
for (var k in header_templates) {
|
|
header_keys.push(header_templates[k].getHeaderKey());
|
|
}
|
|
header_keys.reverse();
|
|
}
|
|
|
|
for (ii = 0; ii < list.length; ii++) {
|
|
var card = list[ii];
|
|
|
|
// If a column has a "High" priority card and a "Low" priority card,
|
|
// we need to add the "Normal" header in between them. This allows
|
|
// you to change priority to "Normal" even if there are no "Normal"
|
|
// cards in a column.
|
|
|
|
if (has_headers) {
|
|
var header_key = this._getCardHeaderKey(card, order);
|
|
if (!seen_headers[header_key]) {
|
|
while (header_keys.length) {
|
|
var next = header_keys.pop();
|
|
|
|
var header = this.getHeader(next);
|
|
objects.push(header);
|
|
seen_headers[header_key] = true;
|
|
|
|
if (next === header_key) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
objects.push(card);
|
|
}
|
|
|
|
this._objects = objects;
|
|
|
|
var content = [];
|
|
for (ii = 0; ii < this._objects.length; ii++) {
|
|
var object = this._objects[ii];
|
|
|
|
var node = object.getNode();
|
|
content.push(node);
|
|
}
|
|
|
|
JX.DOM.setContent(this.getRoot(), content);
|
|
|
|
this._redrawFrame();
|
|
|
|
this._dirty = false;
|
|
},
|
|
|
|
compareHandler: function(src_list, src_node, dst_list, dst_node) {
|
|
var board = this.getBoard();
|
|
var order = board.getOrder();
|
|
|
|
var src_phid = JX.Stratcom.getData(src_node).objectPHID;
|
|
var dst_phid = JX.Stratcom.getData(dst_node).objectPHID;
|
|
|
|
var u_vec = board.getOrderVector(src_phid, order);
|
|
var v_vec = board.getOrderVector(dst_phid, order);
|
|
|
|
return board.compareVectors(u_vec, v_vec);
|
|
},
|
|
|
|
setIsDropTarget: function(is_target) {
|
|
var node = this.getWorkpanelNode();
|
|
JX.DOM.alterClass(node, 'workboard-column-drop-target', is_target);
|
|
},
|
|
|
|
_getCardsSortedNaturally: function() {
|
|
var list = [];
|
|
|
|
for (var ii = 0; ii < this._naturalOrder.length; ii++) {
|
|
var phid = this._naturalOrder[ii];
|
|
list.push(this.getCard(phid));
|
|
}
|
|
|
|
return list;
|
|
},
|
|
|
|
_getCardsSortedByKey: function(order) {
|
|
var cards = this.getCards();
|
|
|
|
var list = [];
|
|
for (var k in cards) {
|
|
list.push(cards[k]);
|
|
}
|
|
|
|
list.sort(JX.bind(this, this._sortCards, order));
|
|
|
|
return list;
|
|
},
|
|
|
|
_sortCards: function(order, u, v) {
|
|
var board = this.getBoard();
|
|
var u_vec = board.getOrderVector(u.getPHID(), order);
|
|
var v_vec = board.getOrderVector(v.getPHID(), order);
|
|
|
|
return board.compareVectors(u_vec, v_vec);
|
|
},
|
|
|
|
_redrawFrame: function() {
|
|
var cards = this.getCards();
|
|
var board = this.getBoard();
|
|
|
|
var points = {};
|
|
var count = 0;
|
|
var decimal_places = 0;
|
|
for (var phid in cards) {
|
|
var card = cards[phid];
|
|
|
|
var card_points;
|
|
if (board.getPointsEnabled()) {
|
|
card_points = card.getPoints();
|
|
} else {
|
|
card_points = 1;
|
|
}
|
|
|
|
if (card_points !== null) {
|
|
var status = card.getStatus();
|
|
if (!points[status]) {
|
|
points[status] = 0;
|
|
}
|
|
points[status] += card_points;
|
|
|
|
// Count the number of decimal places in the point value with the
|
|
// most decimal digits. We'll use the same precision when rendering
|
|
// the point sum. This avoids rounding errors and makes the display
|
|
// a little more consistent.
|
|
var parts = card_points.toString().split('.');
|
|
if (parts[1]) {
|
|
decimal_places = Math.max(decimal_places, parts[1].length);
|
|
}
|
|
}
|
|
|
|
count++;
|
|
}
|
|
|
|
var total_points = 0;
|
|
for (var k in points) {
|
|
total_points += points[k];
|
|
}
|
|
total_points = total_points.toFixed(decimal_places);
|
|
|
|
var limit = this.getPointLimit();
|
|
|
|
var display_value;
|
|
if (limit !== null && limit !== 0) {
|
|
display_value = total_points + ' / ' + limit;
|
|
} else {
|
|
display_value = total_points;
|
|
}
|
|
|
|
if (board.getPointsEnabled()) {
|
|
display_value = count + ' | ' + display_value;
|
|
}
|
|
|
|
var over_limit = ((limit !== null) && (total_points > limit));
|
|
|
|
var content_node = this.getPointsContentNode();
|
|
var points_node = this.getPointsNode();
|
|
|
|
JX.DOM.setContent(content_node, display_value);
|
|
|
|
var is_empty = !this.getCardPHIDs().length;
|
|
var panel = JX.DOM.findAbove(this.getRoot(), 'div', 'workpanel');
|
|
JX.DOM.alterClass(panel, 'project-panel-empty', is_empty);
|
|
JX.DOM.alterClass(panel, 'project-panel-over-limit', over_limit);
|
|
|
|
var color_map = {
|
|
'phui-tag-disabled': (total_points === 0),
|
|
'phui-tag-blue': (total_points > 0 && !over_limit),
|
|
'phui-tag-red': (over_limit)
|
|
};
|
|
|
|
for (var c in color_map) {
|
|
JX.DOM.alterClass(points_node, c, !!color_map[c]);
|
|
}
|
|
|
|
JX.DOM.show(points_node);
|
|
}
|
|
|
|
}
|
|
|
|
});
|