1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 17:28:51 +02:00
phorge-phorge/webroot/rsrc/js/application/projects/WorkboardColumn.js
epriestley 0bf3519045 Rewrite workboards to have way more bugs
Summary:
Ref T4900. Briefly:

  - Much more layout and rendering is now done in Javascript.
  - This should otherwise be identical to the behavior at HEAD, except that:
    - editing a task and removing the current board from it no longer removes the task; and
    - points still don't work.

However, this can now plausibly support realtime workboard updates and other complex state-based behaviors like points calculations in a future change.

Test Plan:
  - Changed card covers.
  - Moved cards.
  - Sorted board by priority and natural.
  - Added new cards.
  - Edited cards in place.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T4900

Differential Revision: https://secure.phabricator.com/D15234
2016-02-10 13:08:38 -08:00

177 lines
3.4 KiB
JavaScript

/**
* @provides javelin-workboard-column
* @requires javelin-install
* javelin-workboard-card
* @javelin
*/
JX.install('WorkboardColumn', {
construct: function(board, phid, root) {
this._board = board;
this._phid = phid;
this._root = root;
this._cards = {};
this._naturalOrder = [];
},
members: {
_phid: null,
_root: null,
_board: null,
_cards: null,
_naturalOrder: 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;
},
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());
},
redraw: function() {
var order = this.getBoard().getOrder();
var list;
if (order == 'natural') {
list = this._getCardsSortedNaturally();
} else {
list = this._getCardsSortedByKey(order);
}
var content = [];
for (var ii = 0; ii < list.length; ii++) {
var node = list[ii].getNode();
content.push(node);
}
JX.DOM.setContent(this.getRoot(), content);
},
_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 ud = this.getBoard().getOrderVector(u.getPHID(), order);
var vd = this.getBoard().getOrderVector(v.getPHID(), order);
for (var ii = 0; ii < ud.length; ii++) {
if (ud[ii] > vd[ii]) {
return 1;
}
if (ud[ii] < vd[ii]) {
return -1;
}
}
return 0;
}
}
});