animal avatars in kanban cursors

pull/1/head
ansuz 3 years ago
parent a701522c61
commit 8a1f6d66cf

@ -46,6 +46,7 @@ define([
var animal_avatars = {}; var animal_avatars = {};
MT.getCursorAvatar = function (cursor) { MT.getCursorAvatar = function (cursor) {
var uid = cursor.uid; var uid = cursor.uid;
// TODO it would be nice to have "{0} is editing" instead of just their name
var html = '<span class="cp-cursor-avatar">'; var html = '<span class="cp-cursor-avatar">';
if (cursor.avatar && avatars[cursor.avatar]) { if (cursor.avatar && avatars[cursor.avatar]) {
html += (cursor.avatar && avatars[cursor.avatar]) || ''; html += (cursor.avatar && avatars[cursor.avatar]) || '';
@ -100,7 +101,7 @@ define([
return ANIMALS[seed % ANIMALS.length]; return ANIMALS[seed % ANIMALS.length];
}; };
var getPrettyInitials = function (name) { var getPrettyInitials = MT.getPrettyInitials = function (name) {
var parts = name.split(/\s+/); var parts = name.split(/\s+/);
var text; var text;
if (parts.length > 1) { if (parts.length > 1) {

@ -159,6 +159,14 @@
margin-right: 5px; margin-right: 5px;
.tools_unselectable(); .tools_unselectable();
cursor: default; cursor: default;
&.cp-cursor.cp-tippy-html {
background-color: var(--red);
// XXX figure out how to inherit this from avatar.less
font-size: 11px; // 20px / 1.8 as per avatar.less..
&.animal {
font-size: 14px; // 20px / 1.8 * (6/5)...
}
}
} }
} }
.kanban-item { .kanban-item {

@ -59,7 +59,7 @@ define([
verbose = function () {}; // comment out to enable verbose logging verbose = function () {}; // comment out to enable verbose logging
var onRedraw = Util.mkEvent(); var onRedraw = Util.mkEvent();
var onCursorUpdate = Util.mkEvent(); var onCursorUpdate = Util.mkEvent();
var remoteCursors = {}; // XXX var remoteCursors = {};
var setValueAndCursor = function (input, val, _cursor) { var setValueAndCursor = function (input, val, _cursor) {
if (!input) { return; } if (!input) { return; }
@ -95,18 +95,27 @@ define([
var getAvatar = function (cursor, noClear) { var getAvatar = function (cursor, noClear) {
// Tippy // Tippy
var html = MT.getCursorAvatar(cursor); // XXX var html = MT.getCursorAvatar(cursor);
var l = Util.getFirstCharacter(cursor.name || Messages.anonymous); var name = UI.getDisplayName(cursor.name);
var l;
var animal = '';
if (cursor.name === Messages.anonymous && typeof(cursor.uid) === 'string') {
l = MT.getPseudorandomAnimal(cursor.uid);
animal = '.animal';
} else {
l = MT.getPrettyInitials(name);
}
var text = ''; var text = '';
if (cursor.color) { if (cursor.color) {
text = 'color:'+getTextColor(cursor.color)+';'; text = 'background-color:' + cursor.color + '; color:'+getTextColor(cursor.color)+';';
} }
var avatar = h('span.cp-cursor.cp-tippy-html', { // XXX var avatar = h('span.cp-cursor.cp-tippy-html' + animal, {
style: "background-color: " + (cursor.color || 'red') + ";"+text, style: text,
'data-cptippy-html': true, 'data-cptippy-html': true,
title: html, // XXX "{0} is editing" title: html,
}, l); }, l);
if (!noClear) { if (!noClear) {
cursor.clear = function () { cursor.clear = function () {
@ -852,7 +861,7 @@ define([
getAvatar: getAvatar, getAvatar: getAvatar,
openLink: openLink, openLink: openLink,
getTags: getExistingTags, getTags: getExistingTags,
cursors: remoteCursors, // XXX cursors: remoteCursors,
boards: boards, boards: boards,
_boards: Util.clone(boards), _boards: Util.clone(boards),
}); });
@ -1062,6 +1071,7 @@ define([
var kanban; var kanban;
var $container = $('#cp-app-kanban-content'); var $container = $('#cp-app-kanban-content');
var myData = framework._.cpNfInner.metadataMgr.getUserData();
var privateData = framework._.cpNfInner.metadataMgr.getPrivateData(); var privateData = framework._.cpNfInner.metadataMgr.getPrivateData();
if (!privateData.isEmbed) { if (!privateData.isEmbed) {
mkHelpMenu(framework); mkHelpMenu(framework);
@ -1101,7 +1111,7 @@ define([
$container.find('.kanban-edit-item').remove(); $container.find('.kanban-edit-item').remove();
}); });
var getCursor = function () { // XXX var getCursor = function () {
if (!kanban || !kanban.inEditMode) { return; } if (!kanban || !kanban.inEditMode) { return; }
try { try {
var id = kanban.inEditMode; var id = kanban.inEditMode;
@ -1204,7 +1214,7 @@ define([
var remoteContent = newContent.content; var remoteContent = newContent.content;
if (Sortify(currentContent) !== Sortify(remoteContent)) { if (Sortify(currentContent) !== Sortify(remoteContent)) {
var cursor = getCursor(); // XXX var cursor = getCursor();
verbose("Content is different.. Applying content"); verbose("Content is different.. Applying content");
kanban.options.boards = remoteContent; kanban.options.boards = remoteContent;
updateBoards(framework, kanban, remoteContent); updateBoards(framework, kanban, remoteContent);
@ -1261,11 +1271,13 @@ define([
}); });
var myCursor = {}; var myCursor = {};
onCursorUpdate.reg(function (data) { // XXX onCursorUpdate.reg(function (data) {
console.log('onCursorUpdate', data);
myCursor = data; myCursor = data;
myCursor.uid = myData.uid;
framework.updateCursor(); framework.updateCursor();
}); });
framework.onCursorUpdate(function (data) { // XXX framework.onCursorUpdate(function (data) {
if (!data) { return; } if (!data) { return; }
if (data.reset) { if (data.reset) {
Object.keys(remoteCursors).forEach(function (id) { Object.keys(remoteCursors).forEach(function (id) {
@ -1293,9 +1305,8 @@ define([
if (!cursor.item && !cursor.board) { return; } if (!cursor.item && !cursor.board) { return; }
// Add new cursor // Add new cursor
var avatar = getAvatar(cursor); // XXX var avatar = getAvatar(cursor);
var $item = $('.kanban-item[data-eid="'+cursor.item+'"]'); var $item = $('.kanban-item[data-eid="'+cursor.item+'"]');
var $board = $('.kanban-board[data-id="'+cursor.board+'"]');
if ($item.length) { if ($item.length) {
remoteCursors[id] = cursor; remoteCursors[id] = cursor;
$item.find('.cp-kanban-cursors').append(avatar); $item.find('.cp-kanban-cursors').append(avatar);

Loading…
Cancel
Save