forked from matrix/element-web
Initial pass at handling room tags that don't have an order element, but need one manual ordering
This commit is contained in:
parent
cf8164bcc3
commit
1c812b340d
|
@ -149,11 +149,33 @@ var RoomSubList = React.createClass({
|
|||
return this.tsOfNewestEvent(roomB) - this.tsOfNewestEvent(roomA);
|
||||
},
|
||||
|
||||
manualComparator: function(roomA, roomB) {
|
||||
if (!roomA.tags[this.props.tagName] || !roomB.tags[this.props.tagName]) return 0;
|
||||
var a = roomA.tags[this.props.tagName].order;
|
||||
var b = roomB.tags[this.props.tagName].order;
|
||||
return a == b ? this.recentsComparator(roomA, roomB) : ( a > b ? 1 : -1);
|
||||
lexicographicalComparator: function(roomA, roomB) {
|
||||
return roomA.name > roomB.name ? 1 : -1;
|
||||
},
|
||||
|
||||
// Generates the manual comparator using the given list
|
||||
manualComparator: function(list) {
|
||||
var self = this;
|
||||
var roomList = list;
|
||||
|
||||
return function(roomA, roomB) {
|
||||
if (!roomA.tags[self.props.tagName] || !roomB.tags[self.props.tagName]) return 0;
|
||||
|
||||
// Make sure the room tag has an order element, if not set it to be the bottom
|
||||
var a = roomA.tags[self.props.tagName].order;
|
||||
var b = roomB.tags[self.props.tagName].order;
|
||||
|
||||
if (a === undefined) {
|
||||
a = (self._getHighestOrder(roomList) + 1.0) / 2.0;
|
||||
roomA.tags[self.props.tagName].order = a;
|
||||
};
|
||||
if (b === undefined) {
|
||||
b = (self._getHighestOrder(roomList) + 1.0) / 2.0;
|
||||
roomB.tags[self.props.tagName].order = b;
|
||||
};
|
||||
|
||||
return a == b ? self.lexicographicalComparator(roomA, roomB) : ( a > b ? 1 : -1);
|
||||
}
|
||||
},
|
||||
|
||||
sortList: function(list, order) {
|
||||
|
@ -161,13 +183,30 @@ var RoomSubList = React.createClass({
|
|||
if (order === undefined) order = this.props.order;
|
||||
var comparator;
|
||||
list = list || [];
|
||||
if (order === "manual") comparator = this.manualComparator;
|
||||
if (order === "manual") comparator = this.manualComparator(list);
|
||||
if (order === "recent") comparator = this.recentsComparator;
|
||||
|
||||
//if (debug) console.log("sorting list for sublist " + this.props.label + " with length " + list.length + ", this.props.list = " + this.props.list);
|
||||
this.setState({ sortedList: list.sort(comparator) });
|
||||
},
|
||||
|
||||
// Finds the highest (lowest position) order of a room in a manual ordered list
|
||||
// room.tag[tagname].order
|
||||
_getHighestOrder: function(list) {
|
||||
var order = 0.0;
|
||||
if (this.props.order === "manual") {
|
||||
var self = this;
|
||||
list.forEach(function(room) {
|
||||
if (room.tags.hasOwnProperty(self.props.tagName)) {
|
||||
if (order < room.tags[self.props.tagName].order) {
|
||||
order = room.tags[self.props.tagName].order;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
return order;
|
||||
},
|
||||
|
||||
moveRoomTile: function(room, atIndex) {
|
||||
if (debug) console.log("moveRoomTile: id " + room.roomId + ", atIndex " + atIndex);
|
||||
//console.log("moveRoomTile before: " + JSON.stringify(this.state.rooms));
|
||||
|
|
|
@ -39,8 +39,6 @@ module.exports = React.createClass({
|
|||
},
|
||||
|
||||
_toggleTag: function(tagNameOn, tagNameOff) {
|
||||
console.log("DEBUG: _toggleTag");
|
||||
console.log("tagNameOn: " + tagNameOn + " tagNameOff: " + tagNameOff);
|
||||
var self = this;
|
||||
const roomId = this.props.room.roomId;
|
||||
var cli = MatrixClientPeg.get();
|
||||
|
@ -62,6 +60,8 @@ module.exports = React.createClass({
|
|||
}
|
||||
|
||||
if (tagNameOn !== null && tagNameOn !== undefined) {
|
||||
// If the tag ordering meta data is required, it is added by
|
||||
// the RoomSubList when it sorts its rooms
|
||||
cli.setRoomTag(roomId, tagNameOn, {}).finally(function() {
|
||||
// Close the context menu
|
||||
if (self.props.onFinished) {
|
||||
|
|
Loading…
Reference in New Issue