mirror of https://github.com/zulip/zulip.git
Extract color_data.js.
This code is pretty distinct from all the color-picking UI, and we want to get it to 100% coverage and optimize it more.
This commit is contained in:
parent
5ef86b6d22
commit
6035304619
|
@ -38,6 +38,7 @@
|
|||
"buddy_list": false,
|
||||
"channel": false,
|
||||
"click_handlers": false,
|
||||
"color_data": false,
|
||||
"colorspace": false,
|
||||
"common": false,
|
||||
"components": false,
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
global.stub_out_jquery();
|
||||
|
||||
zrequire('stream_color');
|
||||
zrequire('color_data');
|
||||
|
||||
run_test('pick_color', () => {
|
||||
var used_colors = ["#76ce90", "#fae589"];
|
||||
|
@ -8,7 +6,7 @@ run_test('pick_color', () => {
|
|||
// Colors are assigned randomly, so this test is a little vague and brittle,
|
||||
// but we can verify a few things, like not reusing colors and making sure
|
||||
// the color has length 7.
|
||||
var color = stream_color.pick_color(used_colors);
|
||||
var color = color_data.pick_color(used_colors);
|
||||
assert.notEqual(color, "#76ce90");
|
||||
assert.notEqual(color, "#fae589");
|
||||
assert.equal(color.length, 7);
|
|
@ -8,6 +8,8 @@ set_global('$', function () {
|
|||
|
||||
set_global('blueslip', global.make_zblueslip());
|
||||
|
||||
set_global('color_data', {});
|
||||
|
||||
zrequire('util');
|
||||
zrequire('hash_util');
|
||||
zrequire('topic_data');
|
||||
|
@ -609,7 +611,7 @@ run_test('create_sub', () => {
|
|||
color: '#76ce90',
|
||||
};
|
||||
|
||||
global.stream_color.pick_color = function () {
|
||||
color_data.pick_color = function () {
|
||||
return '#bd86e5';
|
||||
};
|
||||
|
||||
|
|
|
@ -219,7 +219,7 @@ run_test('marked_subscribed', () => {
|
|||
// Test assigning generated color
|
||||
with_overrides(function (override) {
|
||||
frontend.color = undefined;
|
||||
override('stream_color.pick_color', function () {
|
||||
override('color_data.pick_color', function () {
|
||||
return 'green';
|
||||
});
|
||||
var warnings = 0;
|
||||
|
|
|
@ -23,7 +23,7 @@ exports.initialize = function () {
|
|||
var recipient_and_topic = $('#display_recipient').html();
|
||||
var stream_name = recipient_and_topic.split('-')[0];
|
||||
var topic = recipient_and_topic.split('-')[1];
|
||||
var recipient_color = stream_color.pick_color([]);
|
||||
var recipient_color = color_data.pick_color([]);
|
||||
current_message_group.message_containers = [];
|
||||
current_message_group.show_date_separator = false;
|
||||
current_message_group.display_recipient = stream_name;
|
||||
|
|
|
@ -94,6 +94,7 @@ import "js/transmit.js";
|
|||
import "js/zcommand.js";
|
||||
import "js/compose.js";
|
||||
import "js/upload.js";
|
||||
import "js/color_data.js";
|
||||
import "js/stream_color.js";
|
||||
import "js/stream_data.js";
|
||||
import "js/topic_data.js";
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
var color_data = (function () {
|
||||
|
||||
var exports = {};
|
||||
|
||||
// Auto-assigned colors should be from the default palette so it's easy to undo
|
||||
// changes, so if that palette changes, change these colors.
|
||||
var stream_assignment_colors = [
|
||||
"#76ce90", "#fae589", "#a6c7e5", "#e79ab5",
|
||||
"#bfd56f", "#f4ae55", "#b0a5fd", "#addfe5",
|
||||
"#f5ce6e", "#c2726a", "#94c849", "#bd86e5",
|
||||
"#ee7e4a", "#a6dcbf", "#95a5fd", "#53a063",
|
||||
"#9987e1", "#e4523d", "#c2c2c2", "#4f8de4",
|
||||
"#c6a8ad", "#e7cc4d", "#c8bebf", "#a47462",
|
||||
];
|
||||
|
||||
exports.pick_color = function (used_colors) {
|
||||
var colors = _.shuffle(stream_assignment_colors);
|
||||
var used_color_hash = {};
|
||||
|
||||
_.each(used_colors, function (color) {
|
||||
used_color_hash[color] = true;
|
||||
});
|
||||
|
||||
var color = _.find(colors, function (color) {
|
||||
return !_.has(used_color_hash, color);
|
||||
});
|
||||
|
||||
if (color) {
|
||||
return color;
|
||||
}
|
||||
|
||||
// All available colors were used.
|
||||
return colors[0];
|
||||
};
|
||||
|
||||
return exports;
|
||||
|
||||
}());
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = color_data;
|
||||
}
|
||||
window.color_data = color_data;
|
|
@ -3,41 +3,10 @@ var stream_color = (function () {
|
|||
var exports = {};
|
||||
|
||||
exports.default_color = "#c2c2c2";
|
||||
// Auto-assigned colors should be from the default palette so it's easy to undo
|
||||
// changes, so if that palette changes, change these colors.
|
||||
var stream_assignment_colors = [
|
||||
"#76ce90", "#fae589", "#a6c7e5", "#e79ab5",
|
||||
"#bfd56f", "#f4ae55", "#b0a5fd", "#addfe5",
|
||||
"#f5ce6e", "#c2726a", "#94c849", "#bd86e5",
|
||||
"#ee7e4a", "#a6dcbf", "#95a5fd", "#53a063",
|
||||
"#9987e1", "#e4523d", "#c2c2c2", "#4f8de4",
|
||||
"#c6a8ad", "#e7cc4d", "#c8bebf", "#a47462",
|
||||
];
|
||||
|
||||
// Classes which could be returned by get_color_class.
|
||||
exports.color_classes = 'dark_background';
|
||||
|
||||
exports.pick_color = function (used_colors) {
|
||||
var colors = _.shuffle(stream_assignment_colors);
|
||||
var used_color_hash = {};
|
||||
|
||||
_.each(used_colors, function (color) {
|
||||
used_color_hash[color] = true;
|
||||
});
|
||||
|
||||
var color = _.find(colors, function (color) {
|
||||
return !_.has(used_color_hash, color);
|
||||
});
|
||||
|
||||
if (color) {
|
||||
return color;
|
||||
}
|
||||
|
||||
// All available colors were used.
|
||||
return colors[0];
|
||||
};
|
||||
|
||||
|
||||
function update_table_stream_color(table, stream_name, color) {
|
||||
// This is ugly, but temporary, as the new design will make it
|
||||
// so that we only have color in the headers.
|
||||
|
|
|
@ -465,7 +465,7 @@ exports.create_sub_from_server_data = function (stream_name, attrs) {
|
|||
|
||||
if (!sub.color) {
|
||||
var used_colors = exports.get_colors();
|
||||
sub.color = stream_color.pick_color(used_colors);
|
||||
sub.color = color_data.pick_color(used_colors);
|
||||
}
|
||||
|
||||
exports.update_calculated_fields(sub);
|
||||
|
|
|
@ -4,7 +4,7 @@ var exports = {};
|
|||
|
||||
function get_color() {
|
||||
var used_colors = stream_data.get_colors();
|
||||
var color = stream_color.pick_color(used_colors);
|
||||
var color = color_data.pick_color(used_colors);
|
||||
return color;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue