The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Rocket.Chat/app/ui-utils/client/lib/TabBar.js

84 lines
1.7 KiB

Move some ui function to ui-utils (#13123) * Move rocketchat settings to specific package * WIP: Move models from rocketchat-lib to a specific package (server) * Move function from rocketchat:lib to rocketchat:utils to use it in rocketchat:models * Move client models from rocketchat:lib to rocketchat:models * Fix lint * Move rocketchat.info from lib to utils * Remove directly dependency between lib and migrations * Move statistics Model to rocketchat:models * Create rocketchat:metrics to be able to depacking rocketchat callbacks * Move callbacks to specific package * Remove unused dependency * Move rocketchat-notifications to a specific package * Move rocketchat-promises to a specific package * remove directly dependency from metrics and models * Move CachedCollection from lib to models * Move ui models/collections from ui to models * Move authorization client/ui models to rocketchat:models to be able to remove lib dependency * Creation of rocketchat:ui-utils to help decouple rocketchat:lib and rocketchat:authz * Move some common functions to rocketchat:utils * Change imports to dynamic imports to avoid directly dependency between some packages * Move authz models to rocketchat:models * Remove directly dependency between rocketchat:authz and rocketchat:lib * Move some functions from rocketchat:lib to rocketchat:utils * Add functions to settings package * Convert rocketchat:file-upload to main module structure * Import FileUpload where it is being used * Remove FileUpload and fileUploadHandler from globals eslintrc * Move some functions to rocketchat:ui-utils * Remove directly dependency between rocketchat:authorization and rocketchat:ui-utils * Remove dependency between lazy-load and lib * Change imports of renderMessageBody from ui-message to ui-utils * Add import of main ready from ui-utils * Convert rocketchat-ui-sidenav to main module structure * Add imports of toolbarSearch from ui-sidenav * Remove toolbarSearch from eslintrc globals * Move CachedCollection to a specific package * Change imports of CachedCollection to new package * Move some functions to rocketchat:ui-utils * Remove directly dependency between tooltip and lib * Remove directly dependency between settings and metrics * Move some settings client function from lib to settings * Convert rocketchat-ui-master to main module structure * Remove directly dependency between rocketchat:e2e and rocketchat:lib * Fix wrong import and lint * Convert rocketchat-webrtc to main module structure * Fix missing export * Remove directly dependency between rocketchat:emoji and lib * Add emoji dependencies inside RocketChat namespace * Merge branch 'develop' into globals/move-rocketchat-callbacks * Move some functions to utils * Fix lint * Move some ui functions to ui-utils * Fix import missed objects inside RocketChat namespace * Fix lint * Revert commented test file * Fix lint * Remove old code * Remove old code * Use openedRoom * Remove old code * Change import to a local file instead from package * import emoji in message properties * Move message properties to ui-utils package * Fix lint * Move openedRoom to RoomManager * Fix console errors
7 years ago
import _ from 'underscore';
import { ReactiveVar } from 'meteor/reactive-var';
export const TabBar = new (class TabBar {
get size() {
return this._size.get();
}
set size(s) {
this._size.set(s);
}
constructor() {
this.buttons = new ReactiveVar({});
this._size = new ReactiveVar(4);
this.extraGroups = {};
}
show() {
$('.flex-tab-bar').show();
}
hide() {
$('.flex-tab-bar').hide();
}
addButton(config) {
if (!config || !config.id) {
return false;
}
const btns = this.buttons.curValue;
btns[config.id] = config;
if (this.extraGroups[config.id]) {
btns[config.id].groups = _.union((btns[config.id].groups || []), this.extraGroups[config.id]);
}
this.buttons.set(btns);
}
removeButton(id) {
const btns = this.buttons.curValue;
delete btns[id];
this.buttons.set(btns);
}
updateButton(id, config) {
const btns = this.buttons.curValue;
if (btns[id]) {
btns[id] = _.extend(btns[id], config);
this.buttons.set(btns);
}
}
getButtons() {
const buttons = _.toArray(this.buttons.get()).filter((button) => !button.condition || button.condition());
return _.sortBy(buttons, 'order');
}
getButton(id) {
return _.findWhere(this.buttons.get(), { id });
}
addGroup(id, groups) {
const btns = this.buttons.curValue;
if (btns[id]) {
btns[id].groups = _.union((btns[id].groups || []), groups);
this.buttons.set(btns);
} else {
this.extraGroups[id] = _.union((this.extraGroups[id] || []), groups);
}
}
removeGroup(id, groups) {
const btns = this.buttons.curValue;
if (btns[id]) {
btns[id].groups = _.difference((btns[id].groups || []), groups);
this.buttons.set(btns);
} else {
this.extraGroups[id] = _.difference((this.extraGroups[id] || []), groups);
}
}
});