Migrate sidebar and settings components from BlazeComponent to Template

Convert sidebar, sidebarArchives, sidebarCustomFields, sidebarFilters,
sidebarSearches, and all settings panel components to use native Meteor
Template.onCreated/helpers/events pattern.
This commit is contained in:
Harry Adel 2026-03-08 11:01:21 +02:00
parent d3625db755
commit bae23f9ed8
12 changed files with 2937 additions and 3046 deletions

View file

@ -1,143 +1,178 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
import { AttachmentStorage } from '/models/attachments';
import { CardSearchPagedComponent } from '/client/lib/cardSearch';
import { CardSearchPaged } from '/client/lib/cardSearch';
import SessionData from '/models/usersessiondata';
import { QueryParams } from '/config/query-classes';
import { OPERATOR_LIMIT } from '/config/search-const';
const filesize = require('filesize');
BlazeComponent.extendComponent({
subscription: null,
showFilesReport: new ReactiveVar(false),
showBrokenCardsReport: new ReactiveVar(false),
showOrphanedFilesReport: new ReactiveVar(false),
showRulesReport: new ReactiveVar(false),
showCardsReport: new ReactiveVar(false),
showBoardsReport: new ReactiveVar(false),
sessionId: null,
// --- Shared helper functions (formerly AdminReport base class methods) ---
onCreated() {
this.error = new ReactiveVar('');
this.loading = new ReactiveVar(false);
this.sessionId = SessionData.getSessionId();
},
events() {
return [
{
'click a.js-report-broken': this.switchMenu,
'click a.js-report-files': this.switchMenu,
'click a.js-report-rules': this.switchMenu,
'click a.js-report-cards': this.switchMenu,
'click a.js-report-boards': this.switchMenu,
},
];
},
switchMenu(event) {
const target = $(event.target);
if (!target.hasClass('active')) {
this.loading.set(true);
this.showFilesReport.set(false);
this.showBrokenCardsReport.set(false);
this.showOrphanedFilesReport.set(false);
this.showRulesReport.set(false)
this.showBoardsReport.set(false);
this.showCardsReport.set(false);
if (this.subscription) {
this.subscription.stop();
}
$('.side-menu li.active').removeClass('active');
target.parent().addClass('active');
const targetID = target.data('id');
if ('report-broken' === targetID) {
this.showBrokenCardsReport.set(true);
this.subscription = Meteor.subscribe(
'brokenCards',
SessionData.getSessionId(),
() => {
this.loading.set(false);
},
);
} else if ('report-files' === targetID) {
this.showFilesReport.set(true);
this.subscription = Meteor.subscribe('attachmentsList', () => {
this.loading.set(false);
});
} else if ('report-rules' === targetID) {
this.subscription = Meteor.subscribe('rulesReport', () => {
this.showRulesReport.set(true);
this.loading.set(false);
});
} else if ('report-boards' === targetID) {
this.subscription = Meteor.subscribe('boardsReport', () => {
this.showBoardsReport.set(true);
this.loading.set(false);
});
} else if ('report-cards' === targetID) {
const qp = new QueryParams();
qp.addPredicate(OPERATOR_LIMIT, 300);
this.subscription = Meteor.subscribe(
'globalSearch',
this.sessionId,
qp.getParams(),
qp.text,
() => {
this.showCardsReport.set(true);
this.loading.set(false);
},
);
}
}
},
}).register('adminReports');
class AdminReport extends BlazeComponent {
collection;
results() {
// eslint-disable-next-line no-console
return this.collection.find();
}
yesOrNo(value) {
if (value) {
return TAPi18n.__('yes');
} else {
return TAPi18n.__('no');
}
}
resultsCount() {
return this.collection.find().count();
}
fileSize(size) {
let ret = "";
if (_.isNumber(size)) {
ret = filesize(size);
}
return ret;
}
abbreviate(text) {
if (text?.length > 30) {
return `${text.substr(0, 29)}...`;
}
return text;
function yesOrNo(value) {
if (value) {
return TAPi18n.__('yes');
} else {
return TAPi18n.__('no');
}
}
(class extends AdminReport {
collection = Attachments;
}.register('filesReport'));
function fileSizeHelper(size) {
let ret = "";
if (_.isNumber(size)) {
ret = filesize(size);
}
return ret;
}
(class extends AdminReport {
collection = Rules;
function abbreviate(text) {
if (text?.length > 30) {
return `${text.substr(0, 29)}...`;
}
return text;
}
function collectionResults(collection) {
return collection.find();
}
function collectionResultsCount(collection) {
return collection.find().count();
}
// --- adminReports template ---
Template.adminReports.onCreated(function () {
this.subscription = null;
this.showFilesReport = new ReactiveVar(false);
this.showBrokenCardsReport = new ReactiveVar(false);
this.showOrphanedFilesReport = new ReactiveVar(false);
this.showRulesReport = new ReactiveVar(false);
this.showCardsReport = new ReactiveVar(false);
this.showBoardsReport = new ReactiveVar(false);
this.sessionId = SessionData.getSessionId();
this.error = new ReactiveVar('');
this.loading = new ReactiveVar(false);
});
Template.adminReports.helpers({
showFilesReport() {
return Template.instance().showFilesReport;
},
showBrokenCardsReport() {
return Template.instance().showBrokenCardsReport;
},
showOrphanedFilesReport() {
return Template.instance().showOrphanedFilesReport;
},
showRulesReport() {
return Template.instance().showRulesReport;
},
showCardsReport() {
return Template.instance().showCardsReport;
},
showBoardsReport() {
return Template.instance().showBoardsReport;
},
loading() {
return Template.instance().loading;
},
});
Template.adminReports.events({
'click a.js-report-broken'(event) {
switchMenu(event, Template.instance());
},
'click a.js-report-files'(event) {
switchMenu(event, Template.instance());
},
'click a.js-report-rules'(event) {
switchMenu(event, Template.instance());
},
'click a.js-report-cards'(event) {
switchMenu(event, Template.instance());
},
'click a.js-report-boards'(event) {
switchMenu(event, Template.instance());
},
});
function switchMenu(event, tmpl) {
const target = $(event.target);
if (!target.hasClass('active')) {
tmpl.loading.set(true);
tmpl.showFilesReport.set(false);
tmpl.showBrokenCardsReport.set(false);
tmpl.showOrphanedFilesReport.set(false);
tmpl.showRulesReport.set(false);
tmpl.showBoardsReport.set(false);
tmpl.showCardsReport.set(false);
if (tmpl.subscription) {
tmpl.subscription.stop();
}
$('.side-menu li.active').removeClass('active');
target.parent().addClass('active');
const targetID = target.data('id');
if ('report-broken' === targetID) {
tmpl.showBrokenCardsReport.set(true);
tmpl.subscription = Meteor.subscribe(
'brokenCards',
SessionData.getSessionId(),
() => {
tmpl.loading.set(false);
},
);
} else if ('report-files' === targetID) {
tmpl.showFilesReport.set(true);
tmpl.subscription = Meteor.subscribe('attachmentsList', () => {
tmpl.loading.set(false);
});
} else if ('report-rules' === targetID) {
tmpl.subscription = Meteor.subscribe('rulesReport', () => {
tmpl.showRulesReport.set(true);
tmpl.loading.set(false);
});
} else if ('report-boards' === targetID) {
tmpl.subscription = Meteor.subscribe('boardsReport', () => {
tmpl.showBoardsReport.set(true);
tmpl.loading.set(false);
});
} else if ('report-cards' === targetID) {
const qp = new QueryParams();
qp.addPredicate(OPERATOR_LIMIT, 300);
tmpl.subscription = Meteor.subscribe(
'globalSearch',
tmpl.sessionId,
qp.getParams(),
qp.text,
() => {
tmpl.showCardsReport.set(true);
tmpl.loading.set(false);
},
);
}
}
}
// --- filesReport template ---
Template.filesReport.helpers({
results() {
return collectionResults(Attachments);
},
resultsCount() {
return collectionResultsCount(Attachments);
},
fileSize(size) {
return fileSizeHelper(size);
},
});
// --- rulesReport template ---
Template.rulesReport.helpers({
results() {
const rules = [];
@ -155,12 +190,27 @@ class AdminReport extends BlazeComponent {
// eslint-disable-next-line no-console
console.log('rows:', rules);
return rules;
}
}.register('rulesReport'));
},
resultsCount() {
return collectionResultsCount(Rules);
},
});
(class extends AdminReport {
collection = Boards;
// --- boardsReport template ---
Template.boardsReport.helpers({
results() {
return collectionResults(Boards);
},
resultsCount() {
return collectionResultsCount(Boards);
},
yesOrNo(value) {
return yesOrNo(value);
},
abbreviate(text) {
return abbreviate(text);
},
userNames(members) {
const ret = (members || [])
.map(_member => {
@ -169,7 +219,7 @@ class AdminReport extends BlazeComponent {
})
.join(", ");
return ret;
}
},
teams(memberTeams) {
const ret = (memberTeams || [])
.map(_memberTeam => {
@ -178,7 +228,7 @@ class AdminReport extends BlazeComponent {
})
.join(", ");
return ret;
}
},
orgs(orgs) {
const ret = (orgs || [])
.map(_orgs => {
@ -187,13 +237,21 @@ class AdminReport extends BlazeComponent {
})
.join(", ");
return ret;
}
}.register('boardsReport'));
},
});
// --- cardsReport template ---
(class extends AdminReport {
collection = Cards;
Template.cardsReport.helpers({
results() {
return collectionResults(Cards);
},
resultsCount() {
return collectionResultsCount(Cards);
},
abbreviate(text) {
return abbreviate(text);
},
userNames(userIds) {
const ret = (userIds || [])
.map(_userId => {
@ -201,13 +259,45 @@ class AdminReport extends BlazeComponent {
return _ret;
})
.join(", ");
return ret
}
}.register('cardsReport'));
return ret;
},
});
class BrokenCardsComponent extends CardSearchPagedComponent {
onCreated() {
super.onCreated();
}
}
BrokenCardsComponent.register('brokenCardsReport');
// --- brokenCardsReport template ---
Template.brokenCardsReport.onCreated(function () {
const search = new CardSearchPaged(this);
this.search = search;
});
Template.brokenCardsReport.helpers({
resultsCount() {
return Template.instance().search.resultsCount;
},
resultsHeading() {
return Template.instance().search.resultsHeading;
},
results() {
return Template.instance().search.results;
},
getSearchHref() {
return Template.instance().search.getSearchHref();
},
hasPreviousPage() {
return Template.instance().search.hasPreviousPage;
},
hasNextPage() {
return Template.instance().search.hasNextPage;
},
});
Template.brokenCardsReport.events({
'click .js-next-page'(evt, tpl) {
evt.preventDefault();
tpl.search.nextPage();
},
'click .js-previous-page'(evt, tpl) {
evt.preventDefault();
tpl.search.previousPage();
},
});

View file

@ -2,31 +2,31 @@ import { ReactiveCache } from '/imports/reactiveCache';
import Attachments, { fileStoreStrategyFactory } from '/models/attachments';
const filesize = require('filesize');
BlazeComponent.extendComponent({
subscription: null,
showMoveAttachments: new ReactiveVar(false),
sessionId: null,
Template.attachments.onCreated(function () {
this.subscription = null;
this.showMoveAttachments = new ReactiveVar(false);
this.sessionId = null;
this.error = new ReactiveVar('');
this.loading = new ReactiveVar(false);
});
onCreated() {
this.error = new ReactiveVar('');
this.loading = new ReactiveVar(false);
Template.attachments.helpers({
loading() {
return Template.instance().loading;
},
events() {
return [
{
'click a.js-move-attachments': this.switchMenu,
},
];
showMoveAttachments() {
return Template.instance().showMoveAttachments;
},
});
switchMenu(event) {
Template.attachments.events({
'click a.js-move-attachments'(event, tpl) {
const target = $(event.target);
if (!target.hasClass('active')) {
this.loading.set(true);
this.showMoveAttachments.set(false);
if (this.subscription) {
this.subscription.stop();
tpl.loading.set(true);
tpl.showMoveAttachments.set(false);
if (tpl.subscription) {
tpl.subscription.stop();
}
$('.side-menu li.active').removeClass('active');
@ -34,25 +34,30 @@ BlazeComponent.extendComponent({
const targetID = target.data('id');
if ('move-attachments' === targetID) {
this.showMoveAttachments.set(true);
this.subscription = Meteor.subscribe('attachmentsList', () => {
this.loading.set(false);
tpl.showMoveAttachments.set(true);
tpl.subscription = Meteor.subscribe('attachmentsList', () => {
tpl.loading.set(false);
});
}
}
},
}).register('attachments');
});
BlazeComponent.extendComponent({
Template.moveAttachments.onCreated(function () {
this.attachments = null;
});
Template.moveAttachments.helpers({
getBoardsWithAttachments() {
this.attachments = ReactiveCache.getAttachments();
this.attachmentsByBoardId = _.chain(this.attachments)
const tpl = Template.instance();
tpl.attachments = ReactiveCache.getAttachments();
const attachmentsByBoardId = _.chain(tpl.attachments)
.groupBy(fileObj => fileObj.meta.boardId)
.value();
const ret = Object.keys(this.attachmentsByBoardId)
const ret = Object.keys(attachmentsByBoardId)
.map(boardId => {
const boardAttachments = this.attachmentsByBoardId[boardId];
const boardAttachments = attachmentsByBoardId[boardId];
_.each(boardAttachments, _attachment => {
_attachment.flatVersion = Object.keys(_attachment.versions)
@ -72,71 +77,65 @@ BlazeComponent.extendComponent({
const ret = ReactiveCache.getBoard(boardId);
return ret;
},
events() {
return [
{
'click button.js-move-all-attachments-to-fs'(event) {
this.attachments.forEach(_attachment => {
Meteor.call('moveAttachmentToStorage', _attachment._id, "fs");
});
},
'click button.js-move-all-attachments-to-gridfs'(event) {
this.attachments.forEach(_attachment => {
Meteor.call('moveAttachmentToStorage', _attachment._id, "gridfs");
});
},
'click button.js-move-all-attachments-to-s3'(event) {
this.attachments.forEach(_attachment => {
Meteor.call('moveAttachmentToStorage', _attachment._id, "s3");
});
},
}
]
}
}).register('moveAttachments');
});
BlazeComponent.extendComponent({
events() {
return [
{
'click button.js-move-all-attachments-of-board-to-fs'(event) {
this.data().attachments.forEach(_attachment => {
Meteor.call('moveAttachmentToStorage', _attachment._id, "fs");
});
},
'click button.js-move-all-attachments-of-board-to-gridfs'(event) {
this.data().attachments.forEach(_attachment => {
Meteor.call('moveAttachmentToStorage', _attachment._id, "gridfs");
});
},
'click button.js-move-all-attachments-of-board-to-s3'(event) {
this.data().attachments.forEach(_attachment => {
Meteor.call('moveAttachmentToStorage', _attachment._id, "s3");
});
},
}
]
Template.moveAttachments.events({
'click button.js-move-all-attachments-to-fs'(event, tpl) {
tpl.attachments.forEach(_attachment => {
Meteor.call('moveAttachmentToStorage', _attachment._id, "fs");
});
},
}).register('moveBoardAttachments');
'click button.js-move-all-attachments-to-gridfs'(event, tpl) {
tpl.attachments.forEach(_attachment => {
Meteor.call('moveAttachmentToStorage', _attachment._id, "gridfs");
});
},
'click button.js-move-all-attachments-to-s3'(event, tpl) {
tpl.attachments.forEach(_attachment => {
Meteor.call('moveAttachmentToStorage', _attachment._id, "s3");
});
},
});
BlazeComponent.extendComponent({
Template.moveBoardAttachments.events({
'click button.js-move-all-attachments-of-board-to-fs'() {
const data = Template.currentData();
data.attachments.forEach(_attachment => {
Meteor.call('moveAttachmentToStorage', _attachment._id, "fs");
});
},
'click button.js-move-all-attachments-of-board-to-gridfs'() {
const data = Template.currentData();
data.attachments.forEach(_attachment => {
Meteor.call('moveAttachmentToStorage', _attachment._id, "gridfs");
});
},
'click button.js-move-all-attachments-of-board-to-s3'() {
const data = Template.currentData();
data.attachments.forEach(_attachment => {
Meteor.call('moveAttachmentToStorage', _attachment._id, "s3");
});
},
});
Template.moveAttachment.helpers({
fileSize(size) {
const ret = filesize(size);
return ret;
},
events() {
return [
{
'click button.js-move-storage-fs'(event) {
Meteor.call('moveAttachmentToStorage', this.data()._id, "fs");
},
'click button.js-move-storage-gridfs'(event) {
Meteor.call('moveAttachmentToStorage', this.data()._id, "gridfs");
},
'click button.js-move-storage-s3'(event) {
Meteor.call('moveAttachmentToStorage', this.data()._id, "s3");
},
}
]
});
Template.moveAttachment.events({
'click button.js-move-storage-fs'() {
const data = Template.currentData();
Meteor.call('moveAttachmentToStorage', data._id, "fs");
},
}).register('moveAttachment');
'click button.js-move-storage-gridfs'() {
const data = Template.currentData();
Meteor.call('moveAttachmentToStorage', data._id, "gridfs");
},
'click button.js-move-storage-s3'() {
const data = Template.currentData();
Meteor.call('moveAttachmentToStorage', data._id, "s3");
},
});

View file

@ -1,18 +1,18 @@
import { TAPi18n } from '/imports/i18n';
const filesize = require('filesize');
BlazeComponent.extendComponent({
onCreated() {
this.info = new ReactiveVar({});
Meteor.call('getStatistics', (error, ret) => {
if (!error && ret) {
this.info.set(ret);
}
});
},
Template.statistics.onCreated(function () {
this.info = new ReactiveVar({});
Meteor.call('getStatistics', (error, ret) => {
if (!error && ret) {
this.info.set(ret);
}
});
});
Template.statistics.helpers({
statistics() {
return this.info.get();
return Template.instance().info.get();
},
humanReadableTime(time) {
@ -47,4 +47,4 @@ BlazeComponent.extendComponent({
}
return ret;
},
}).register('statistics');
});

View file

@ -1,16 +1,12 @@
import { ReactiveCache } from '/imports/reactiveCache';
import LockoutSettings from '/models/lockoutSettings';
BlazeComponent.extendComponent({
onCreated() {
this.lockedUsers = new ReactiveVar([]);
this.isLoadingLockedUsers = new ReactiveVar(false);
Template.lockedUsersGeneral.onCreated(function () {
this.lockedUsers = new ReactiveVar([]);
this.isLoadingLockedUsers = new ReactiveVar(false);
// Don't load immediately to prevent unnecessary spinner
// The data will be loaded when the tab is selected in peopleBody.js switchMenu
},
refreshLockedUsers() {
// Store refreshLockedUsers on the instance so it can be called from event handlers
this.refreshLockedUsers = () => {
// Set loading state initially, but we'll hide it if no users are found
this.isLoadingLockedUsers.set(true);
@ -44,9 +40,54 @@ BlazeComponent.extendComponent({
this.lockedUsers.set(users);
this.isLoadingLockedUsers.set(false);
});
};
// Don't load immediately to prevent unnecessary spinner
// The data will be loaded when the tab is selected in peopleBody.js switchMenu
});
Template.lockedUsersGeneral.helpers({
knownFailuresBeforeLockout() {
return LockoutSettings.findOne('known-failuresBeforeLockout')?.value || 3;
},
unlockUser(event) {
knownLockoutPeriod() {
return LockoutSettings.findOne('known-lockoutPeriod')?.value || 60;
},
knownFailureWindow() {
return LockoutSettings.findOne('known-failureWindow')?.value || 15;
},
unknownFailuresBeforeLockout() {
return LockoutSettings.findOne('unknown-failuresBeforeLockout')?.value || 3;
},
unknownLockoutPeriod() {
return LockoutSettings.findOne('unknown-lockoutPeriod')?.value || 60;
},
unknownFailureWindow() {
return LockoutSettings.findOne('unknown-failureWindow')?.value || 15;
},
lockedUsers() {
return Template.instance().lockedUsers.get();
},
isLoadingLockedUsers() {
return Template.instance().isLoadingLockedUsers.get();
},
});
Template.lockedUsersGeneral.events({
'click button.js-refresh-locked-users'(event, tpl) {
tpl.refreshLockedUsers();
},
'click button#refreshLockedUsers'(event, tpl) {
tpl.refreshLockedUsers();
},
'click button.js-unlock-user'(event, tpl) {
const userId = $(event.currentTarget).data('user-id');
if (!userId) return;
@ -61,13 +102,12 @@ BlazeComponent.extendComponent({
if (result) {
alert(TAPi18n.__('accounts-lockout-user-unlocked'));
this.refreshLockedUsers();
tpl.refreshLockedUsers();
}
});
}
},
unlockAllUsers() {
'click button.js-unlock-all-users'(event, tpl) {
if (confirm(TAPi18n.__('accounts-lockout-confirm-unlock-all'))) {
Meteor.call('unlockAllUsers', (err, result) => {
if (err) {
@ -79,13 +119,12 @@ BlazeComponent.extendComponent({
if (result) {
alert(TAPi18n.__('accounts-lockout-user-unlocked'));
this.refreshLockedUsers();
tpl.refreshLockedUsers();
}
});
}
},
saveLockoutSettings() {
'click button.js-lockout-save'() {
// Get values from form
const knownFailuresBeforeLockout = parseInt($('#known-failures-before-lockout').val(), 10) || 3;
const knownLockoutPeriod = parseInt($('#known-lockout-period').val(), 10) || 60;
@ -128,48 +167,4 @@ BlazeComponent.extendComponent({
}
});
},
knownFailuresBeforeLockout() {
return LockoutSettings.findOne('known-failuresBeforeLockout')?.value || 3;
},
knownLockoutPeriod() {
return LockoutSettings.findOne('known-lockoutPeriod')?.value || 60;
},
knownFailureWindow() {
return LockoutSettings.findOne('known-failureWindow')?.value || 15;
},
unknownFailuresBeforeLockout() {
return LockoutSettings.findOne('unknown-failuresBeforeLockout')?.value || 3;
},
unknownLockoutPeriod() {
return LockoutSettings.findOne('unknown-lockoutPeriod')?.value || 60;
},
unknownFailureWindow() {
return LockoutSettings.findOne('unknown-failureWindow')?.value || 15;
},
lockedUsers() {
return this.lockedUsers.get();
},
isLoadingLockedUsers() {
return this.isLoadingLockedUsers.get();
},
events() {
return [
{
'click button.js-refresh-locked-users': this.refreshLockedUsers,
'click button#refreshLockedUsers': this.refreshLockedUsers,
'click button.js-unlock-user': this.unlockUser,
'click button.js-unlock-all-users': this.unlockAllUsers,
'click button.js-lockout-save': this.saveLockoutSettings,
},
];
},
}).register('lockedUsersGeneral');
});

View file

@ -1,4 +1,5 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { InfiniteScrolling } from '/client/lib/infiniteScrolling';
import LockoutSettings from '/models/lockoutSettings';
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
@ -8,139 +9,73 @@ const usersPerPage = 25;
let userOrgsTeamsAction = ""; //poosible actions 'addOrg', 'addTeam', 'removeOrg' or 'removeTeam' when adding or modifying a user
let selectedUserChkBoxUserIds = [];
BlazeComponent.extendComponent({
mixins() {
return [Mixins.InfiniteScrolling];
},
onCreated() {
this.error = new ReactiveVar('');
this.loading = new ReactiveVar(false);
this.orgSetting = new ReactiveVar(true);
this.teamSetting = new ReactiveVar(false);
this.peopleSetting = new ReactiveVar(false);
this.lockedUsersSetting = new ReactiveVar(false);
this.findOrgsOptions = new ReactiveVar({});
this.findTeamsOptions = new ReactiveVar({});
this.findUsersOptions = new ReactiveVar({});
this.numberOrgs = new ReactiveVar(0);
this.numberTeams = new ReactiveVar(0);
this.numberPeople = new ReactiveVar(0);
this.userFilterType = new ReactiveVar('all');
Template.people.onCreated(function () {
this.infiniteScrolling = new InfiniteScrolling();
this.page = new ReactiveVar(1);
this.loadNextPageLocked = false;
this.callFirstWith(null, 'resetNextPeak');
this.autorun(() => {
const limitOrgs = this.page.get() * orgsPerPage;
const limitTeams = this.page.get() * teamsPerPage;
const limitUsers = this.page.get() * usersPerPage;
this.error = new ReactiveVar('');
this.loading = new ReactiveVar(false);
this.orgSetting = new ReactiveVar(true);
this.teamSetting = new ReactiveVar(false);
this.peopleSetting = new ReactiveVar(false);
this.lockedUsersSetting = new ReactiveVar(false);
this.findOrgsOptions = new ReactiveVar({});
this.findTeamsOptions = new ReactiveVar({});
this.findUsersOptions = new ReactiveVar({});
this.numberOrgs = new ReactiveVar(0);
this.numberTeams = new ReactiveVar(0);
this.numberPeople = new ReactiveVar(0);
this.userFilterType = new ReactiveVar('all');
this.subscribe('org', this.findOrgsOptions.get(), limitOrgs, () => {
this.loadNextPageLocked = false;
const nextPeakBefore = this.callFirstWith(null, 'getNextPeak');
this.calculateNextPeak();
const nextPeakAfter = this.callFirstWith(null, 'getNextPeak');
if (nextPeakBefore === nextPeakAfter) {
this.callFirstWith(null, 'resetNextPeak');
}
this.page = new ReactiveVar(1);
this.loadNextPageLocked = false;
this.infiniteScrolling.resetNextPeak();
this.calculateNextPeak = () => {
const element = this.find('.main-body');
if (element) {
const altitude = element.scrollHeight;
this.infiniteScrolling.setNextPeak(altitude);
}
};
this.loadNextPage = () => {
if (this.loadNextPageLocked === false) {
this.page.set(this.page.get() + 1);
this.loadNextPageLocked = true;
}
};
this.filterOrg = () => {
const value = $('#searchOrgInput').first().val();
if (value !== '') {
const regex = new RegExp(value, 'i');
this.findOrgsOptions.set({
$or: [
{ orgDisplayName: regex },
{ orgShortName: regex },
],
});
} else {
this.findOrgsOptions.set({});
}
};
this.subscribe('team', this.findTeamsOptions.get(), limitTeams, () => {
this.loadNextPageLocked = false;
const nextPeakBefore = this.callFirstWith(null, 'getNextPeak');
this.calculateNextPeak();
const nextPeakAfter = this.callFirstWith(null, 'getNextPeak');
if (nextPeakBefore === nextPeakAfter) {
this.callFirstWith(null, 'resetNextPeak');
}
this.filterTeam = () => {
const value = $('#searchTeamInput').first().val();
if (value !== '') {
const regex = new RegExp(value, 'i');
this.findTeamsOptions.set({
$or: [
{ teamDisplayName: regex },
{ teamShortName: regex },
],
});
} else {
this.findTeamsOptions.set({});
}
};
this.subscribe('people', this.findUsersOptions.get(), limitUsers, () => {
this.loadNextPageLocked = false;
const nextPeakBefore = this.callFirstWith(null, 'getNextPeak');
this.calculateNextPeak();
const nextPeakAfter = this.callFirstWith(null, 'getNextPeak');
if (nextPeakBefore === nextPeakAfter) {
this.callFirstWith(null, 'resetNextPeak');
}
});
});
},
events() {
return [
{
'click #searchOrgButton'() {
this.filterOrg();
},
'keydown #searchOrgInput'(event) {
if (event.keyCode === 13 && !event.shiftKey) {
this.filterOrg();
}
},
'click #searchTeamButton'() {
this.filterTeam();
},
'keydown #searchTeamInput'(event) {
if (event.keyCode === 13 && !event.shiftKey) {
this.filterTeam();
}
},
'click #searchButton'() {
this.filterPeople();
},
'click #addOrRemoveTeam'(){
document.getElementById("divAddOrRemoveTeamContainer").style.display = 'block';
},
'keydown #searchInput'(event) {
if (event.keyCode === 13 && !event.shiftKey) {
this.filterPeople();
}
},
'change #userFilterSelect'(event) {
const filterType = $(event.target).val();
this.userFilterType.set(filterType);
this.filterPeople();
},
'click #unlockAllUsers'(event) {
event.preventDefault();
if (confirm(TAPi18n.__('accounts-lockout-confirm-unlock-all'))) {
Meteor.call('unlockAllUsers', (error) => {
if (error) {
console.error('Error unlocking all users:', error);
} else {
// Show a brief success message
const message = document.createElement('div');
message.className = 'unlock-all-success';
message.textContent = TAPi18n.__('accounts-lockout-all-users-unlocked');
document.body.appendChild(message);
// Remove the message after a short delay
setTimeout(() => {
if (message.parentNode) {
message.parentNode.removeChild(message);
}
}, 3000);
}
});
}
},
'click #newOrgButton'() {
Popup.open('newOrg');
},
'click #newTeamButton'() {
Popup.open('newTeam');
},
'click #newUserButton'() {
Popup.open('newUser');
},
'click a.js-org-menu': this.switchMenu,
'click a.js-team-menu': this.switchMenu,
'click a.js-people-menu': this.switchMenu,
'click a.js-locked-users-menu': this.switchMenu,
},
];
},
filterPeople() {
this.filterPeople = () => {
const value = $('#searchInput').first().val();
const filterType = this.userFilterType.get();
const currentTime = Number(new Date());
@ -184,72 +119,9 @@ BlazeComponent.extendComponent({
}
this.findUsersOptions.set(query);
},
loadNextPage() {
if (this.loadNextPageLocked === false) {
this.page.set(this.page.get() + 1);
this.loadNextPageLocked = true;
}
},
calculateNextPeak() {
const element = this.find('.main-body');
if (element) {
const altitude = element.scrollHeight;
this.callFirstWith(this, 'setNextPeak', altitude);
}
},
reachNextPeak() {
this.loadNextPage();
},
setError(error) {
this.error.set(error);
},
setLoading(w) {
this.loading.set(w);
},
orgList() {
const limitOrgs = this.page.get() * orgsPerPage;
const orgs = ReactiveCache.getOrgs(this.findOrgsOptions.get(), {
sort: { orgDisplayName: 1 },
limit: limitOrgs,
fields: { _id: true },
});
// Count only the items currently loaded to browser, not total from database
this.numberOrgs.set(orgs.length);
return orgs;
},
teamList() {
const limitTeams = this.page.get() * teamsPerPage;
const teams = ReactiveCache.getTeams(this.findTeamsOptions.get(), {
sort: { teamDisplayName: 1 },
limit: limitTeams,
fields: { _id: true },
});
// Count only the items currently loaded to browser, not total from database
this.numberTeams.set(teams.length);
return teams;
},
peopleList() {
const limitUsers = this.page.get() * usersPerPage;
const users = ReactiveCache.getUsers(this.findUsersOptions.get(), {
sort: { username: 1 },
limit: limitUsers,
fields: { _id: true },
});
// Count only the items currently loaded to browser, not total from database
this.numberPeople.set(users.length);
return users;
},
orgNumber() {
return this.numberOrgs.get();
},
teamNumber() {
return this.numberTeams.get();
},
peopleNumber() {
return this.numberPeople.get();
},
switchMenu(event) {
};
this.switchMenu = (event) => {
const target = $(event.target);
if (!target.hasClass('active')) {
$('.side-menu li.active').removeClass('active');
@ -269,8 +141,191 @@ BlazeComponent.extendComponent({
}
}
}
};
this.autorun(() => {
const limitOrgs = this.page.get() * orgsPerPage;
const limitTeams = this.page.get() * teamsPerPage;
const limitUsers = this.page.get() * usersPerPage;
this.subscribe('org', this.findOrgsOptions.get(), limitOrgs, () => {
this.loadNextPageLocked = false;
const nextPeakBefore = this.infiniteScrolling.getNextPeak();
this.calculateNextPeak();
const nextPeakAfter = this.infiniteScrolling.getNextPeak();
if (nextPeakBefore === nextPeakAfter) {
this.infiniteScrolling.resetNextPeak();
}
});
this.subscribe('team', this.findTeamsOptions.get(), limitTeams, () => {
this.loadNextPageLocked = false;
const nextPeakBefore = this.infiniteScrolling.getNextPeak();
this.calculateNextPeak();
const nextPeakAfter = this.infiniteScrolling.getNextPeak();
if (nextPeakBefore === nextPeakAfter) {
this.infiniteScrolling.resetNextPeak();
}
});
this.subscribe('people', this.findUsersOptions.get(), limitUsers, () => {
this.loadNextPageLocked = false;
const nextPeakBefore = this.infiniteScrolling.getNextPeak();
this.calculateNextPeak();
const nextPeakAfter = this.infiniteScrolling.getNextPeak();
if (nextPeakBefore === nextPeakAfter) {
this.infiniteScrolling.resetNextPeak();
}
});
});
});
Template.people.helpers({
loading() {
return Template.instance().loading;
},
}).register('people');
orgSetting() {
return Template.instance().orgSetting;
},
teamSetting() {
return Template.instance().teamSetting;
},
peopleSetting() {
return Template.instance().peopleSetting;
},
lockedUsersSetting() {
return Template.instance().lockedUsersSetting;
},
orgList() {
const tpl = Template.instance();
const limitOrgs = tpl.page.get() * orgsPerPage;
const orgs = ReactiveCache.getOrgs(tpl.findOrgsOptions.get(), {
sort: { orgDisplayName: 1 },
limit: limitOrgs,
fields: { _id: true },
});
// Count only the items currently loaded to browser, not total from database
tpl.numberOrgs.set(orgs.length);
return orgs;
},
teamList() {
const tpl = Template.instance();
const limitTeams = tpl.page.get() * teamsPerPage;
const teams = ReactiveCache.getTeams(tpl.findTeamsOptions.get(), {
sort: { teamDisplayName: 1 },
limit: limitTeams,
fields: { _id: true },
});
// Count only the items currently loaded to browser, not total from database
tpl.numberTeams.set(teams.length);
return teams;
},
peopleList() {
const tpl = Template.instance();
const limitUsers = tpl.page.get() * usersPerPage;
const users = ReactiveCache.getUsers(tpl.findUsersOptions.get(), {
sort: { username: 1 },
limit: limitUsers,
fields: { _id: true },
});
// Count only the items currently loaded to browser, not total from database
tpl.numberPeople.set(users.length);
return users;
},
orgNumber() {
return Template.instance().numberOrgs.get();
},
teamNumber() {
return Template.instance().numberTeams.get();
},
peopleNumber() {
return Template.instance().numberPeople.get();
},
});
Template.people.events({
'scroll .main-body'(event, tpl) {
tpl.infiniteScrolling.checkScrollPosition(event.currentTarget, () => {
tpl.loadNextPage();
});
},
'click #searchOrgButton'(event, tpl) {
tpl.filterOrg();
},
'keydown #searchOrgInput'(event, tpl) {
if (event.keyCode === 13 && !event.shiftKey) {
tpl.filterOrg();
}
},
'click #searchTeamButton'(event, tpl) {
tpl.filterTeam();
},
'keydown #searchTeamInput'(event, tpl) {
if (event.keyCode === 13 && !event.shiftKey) {
tpl.filterTeam();
}
},
'click #searchButton'(event, tpl) {
tpl.filterPeople();
},
'click #addOrRemoveTeam'(){
document.getElementById("divAddOrRemoveTeamContainer").style.display = 'block';
},
'keydown #searchInput'(event, tpl) {
if (event.keyCode === 13 && !event.shiftKey) {
tpl.filterPeople();
}
},
'change #userFilterSelect'(event, tpl) {
const filterType = $(event.target).val();
tpl.userFilterType.set(filterType);
tpl.filterPeople();
},
'click #unlockAllUsers'(event) {
event.preventDefault();
if (confirm(TAPi18n.__('accounts-lockout-confirm-unlock-all'))) {
Meteor.call('unlockAllUsers', (error) => {
if (error) {
console.error('Error unlocking all users:', error);
} else {
// Show a brief success message
const message = document.createElement('div');
message.className = 'unlock-all-success';
message.textContent = TAPi18n.__('accounts-lockout-all-users-unlocked');
document.body.appendChild(message);
// Remove the message after a short delay
setTimeout(() => {
if (message.parentNode) {
message.parentNode.removeChild(message);
}
}, 3000);
}
});
}
},
'click #newOrgButton'() {
Popup.open('newOrg');
},
'click #newTeamButton'() {
Popup.open('newTeam');
},
'click #newUserButton'() {
Popup.open('newUser');
},
'click a.js-org-menu'(event, tpl) {
tpl.switchMenu(event);
},
'click a.js-team-menu'(event, tpl) {
tpl.switchMenu(event);
},
'click a.js-people-menu'(event, tpl) {
tpl.switchMenu(event);
},
'click a.js-locked-users-menu'(event, tpl) {
tpl.switchMenu(event);
},
});
Template.orgRow.helpers({
orgData() {
@ -465,259 +520,201 @@ Template.newUserPopup.helpers({
},
});
BlazeComponent.extendComponent({
onCreated() {},
org() {
return ReactiveCache.getOrg(this.orgId);
Template.orgRow.events({
'click a.edit-org': Popup.open('editOrg'),
'click a.more-settings-org': Popup.open('settingsOrg'),
});
Template.teamRow.events({
'click a.edit-team': Popup.open('editTeam'),
'click a.more-settings-team': Popup.open('settingsTeam'),
});
Template.peopleRow.events({
'click a.edit-user': Popup.open('editUser'),
'click a.more-settings-user': Popup.open('settingsUser'),
'click .selectUserChkBox': function(ev){
if(ev.currentTarget){
if(ev.currentTarget.checked){
if(!selectedUserChkBoxUserIds.includes(ev.currentTarget.id)){
selectedUserChkBoxUserIds.push(ev.currentTarget.id);
}
}
else{
if(selectedUserChkBoxUserIds.includes(ev.currentTarget.id)){
let index = selectedUserChkBoxUserIds.indexOf(ev.currentTarget.id);
if(index > -1)
selectedUserChkBoxUserIds.splice(index, 1);
}
}
}
if(selectedUserChkBoxUserIds.length > 0)
document.getElementById("divAddOrRemoveTeam").style.display = 'block';
else
document.getElementById("divAddOrRemoveTeam").style.display = 'none';
},
events() {
return [
{
'click a.edit-org': Popup.open('editOrg'),
'click a.more-settings-org': Popup.open('settingsOrg'),
},
];
'click .js-toggle-active-status': function(ev) {
ev.preventDefault();
const userId = this.userId;
const user = ReactiveCache.getUser(userId);
if (!user) return;
// Toggle loginDisabled status
const isActive = !(user.loginDisabled === true);
// Update the user's active status
Users.update(userId, {
$set: {
loginDisabled: isActive
}
});
},
}).register('orgRow');
'click .js-toggle-lock-status': function(ev){
ev.preventDefault();
const userId = this.userId;
const user = ReactiveCache.getUser(userId);
BlazeComponent.extendComponent({
onCreated() {},
team() {
return ReactiveCache.getTeam(this.teamId);
if (!user) return;
// Check if user is currently locked
const isLocked = user.services &&
user.services['accounts-lockout'] &&
user.services['accounts-lockout'].unlockTime &&
user.services['accounts-lockout'].unlockTime > Number(new Date());
if (isLocked) {
// Unlock the user
Meteor.call('unlockUser', userId, (error) => {
if (error) {
console.error('Error unlocking user:', error);
}
});
} else {
// Lock the user - this is optional, you may want to only allow unlocking
// If you want to implement locking too, you would need a server method for it
// For now, we'll leave this as a no-op
}
},
events() {
return [
{
'click a.edit-team': Popup.open('editTeam'),
'click a.more-settings-team': Popup.open('settingsTeam'),
},
];
},
}).register('teamRow');
});
BlazeComponent.extendComponent({
onCreated() {},
user() {
return ReactiveCache.getUser(this.userId);
},
events() {
return [
{
'click a.edit-user': Popup.open('editUser'),
'click a.more-settings-user': Popup.open('settingsUser'),
'click .selectUserChkBox': function(ev){
if(ev.currentTarget){
if(ev.currentTarget.checked){
if(!selectedUserChkBoxUserIds.includes(ev.currentTarget.id)){
selectedUserChkBoxUserIds.push(ev.currentTarget.id);
}
}
else{
if(selectedUserChkBoxUserIds.includes(ev.currentTarget.id)){
let index = selectedUserChkBoxUserIds.indexOf(ev.currentTarget.id);
if(index > -1)
selectedUserChkBoxUserIds.splice(index, 1);
}
}
}
if(selectedUserChkBoxUserIds.length > 0)
document.getElementById("divAddOrRemoveTeam").style.display = 'block';
else
document.getElementById("divAddOrRemoveTeam").style.display = 'none';
},
'click .js-toggle-active-status': function(ev) {
ev.preventDefault();
const userId = this.userId;
const user = ReactiveCache.getUser(userId);
if (!user) return;
// Toggle loginDisabled status
const isActive = !(user.loginDisabled === true);
// Update the user's active status
Users.update(userId, {
$set: {
loginDisabled: isActive
}
});
},
'click .js-toggle-lock-status': function(ev){
ev.preventDefault();
const userId = this.userId;
const user = ReactiveCache.getUser(userId);
if (!user) return;
// Check if user is currently locked
const isLocked = user.services &&
user.services['accounts-lockout'] &&
user.services['accounts-lockout'].unlockTime &&
user.services['accounts-lockout'].unlockTime > Number(new Date());
if (isLocked) {
// Unlock the user
Meteor.call('unlockUser', userId, (error) => {
if (error) {
console.error('Error unlocking user:', error);
}
});
} else {
// Lock the user - this is optional, you may want to only allow unlocking
// If you want to implement locking too, you would need a server method for it
// For now, we'll leave this as a no-op
}
},
},
];
},
}).register('peopleRow');
BlazeComponent.extendComponent({
onCreated() {},
Template.modifyTeamsUsers.helpers({
teamsDatas() {
const ret = ReactiveCache.getTeams({}, {sort: { teamDisplayName: 1 }});
return ret;
},
events() {
return [
{
'click #cancelBtn': function(){
let selectedElt = document.getElementById("jsteamsUser");
document.getElementById("divAddOrRemoveTeamContainer").style.display = 'none';
},
'click #addTeamBtn': function(){
let selectedElt;
let selectedEltValue;
let selectedEltValueId;
let userTms = [];
let currentUser;
let currUserTeamIndex;
});
selectedElt = document.getElementById("jsteamsUser");
selectedEltValue = selectedElt.options[selectedElt.selectedIndex].text;
selectedEltValueId = selectedElt.options[selectedElt.selectedIndex].value;
Template.modifyTeamsUsers.events({
'click #cancelBtn': function(){
let selectedElt = document.getElementById("jsteamsUser");
document.getElementById("divAddOrRemoveTeamContainer").style.display = 'none';
},
'click #addTeamBtn': function(){
let selectedElt;
let selectedEltValue;
let selectedEltValueId;
let userTms = [];
let currentUser;
let currUserTeamIndex;
if(document.getElementById('addAction').checked){
for(let i = 0; i < selectedUserChkBoxUserIds.length; i++){
currentUser = ReactiveCache.getUser(selectedUserChkBoxUserIds[i]);
userTms = currentUser.teams;
if(userTms == undefined || userTms.length == 0){
userTms = [];
userTms.push({
"teamId": selectedEltValueId,
"teamDisplayName": selectedEltValue,
})
}
else if(userTms.length > 0)
{
currUserTeamIndex = userTms.findIndex(function(t){ return t.teamId == selectedEltValueId});
if(currUserTeamIndex == -1){
userTms.push({
"teamId": selectedEltValueId,
"teamDisplayName": selectedEltValue,
});
}
}
selectedElt = document.getElementById("jsteamsUser");
selectedEltValue = selectedElt.options[selectedElt.selectedIndex].text;
selectedEltValueId = selectedElt.options[selectedElt.selectedIndex].value;
Users.update(selectedUserChkBoxUserIds[i], {
$set:{
teams: userTms
}
});
}
if(document.getElementById('addAction').checked){
for(let i = 0; i < selectedUserChkBoxUserIds.length; i++){
currentUser = ReactiveCache.getUser(selectedUserChkBoxUserIds[i]);
userTms = currentUser.teams;
if(userTms == undefined || userTms.length == 0){
userTms = [];
userTms.push({
"teamId": selectedEltValueId,
"teamDisplayName": selectedEltValue,
})
}
else if(userTms.length > 0)
{
currUserTeamIndex = userTms.findIndex(function(t){ return t.teamId == selectedEltValueId});
if(currUserTeamIndex == -1){
userTms.push({
"teamId": selectedEltValueId,
"teamDisplayName": selectedEltValue,
});
}
else{
for(let i = 0; i < selectedUserChkBoxUserIds.length; i++){
currentUser = ReactiveCache.getUser(selectedUserChkBoxUserIds[i]);
userTms = currentUser.teams;
if(userTms !== undefined || userTms.length > 0)
{
currUserTeamIndex = userTms.findIndex(function(t){ return t.teamId == selectedEltValueId});
if(currUserTeamIndex != -1){
userTms.splice(currUserTeamIndex, 1);
}
}
}
Users.update(selectedUserChkBoxUserIds[i], {
$set:{
teams: userTms
}
});
}
Users.update(selectedUserChkBoxUserIds[i], {
$set:{
teams: userTms
}
document.getElementById("divAddOrRemoveTeamContainer").style.display = 'none';
},
},
];
},
}).register('modifyTeamsUsers');
BlazeComponent.extendComponent({
events() {
return [
{
'click a.new-org': Popup.open('newOrg'),
},
];
},
}).register('newOrgRow');
BlazeComponent.extendComponent({
events() {
return [
{
'click a.new-team': Popup.open('newTeam'),
},
];
},
}).register('newTeamRow');
BlazeComponent.extendComponent({
events() {
return [
{
'click a.new-user': Popup.open('newUser'),
},
];
},
}).register('newUserRow');
BlazeComponent.extendComponent({
events() {
return [
{
'click .allUserChkBox': function(ev){
selectedUserChkBoxUserIds = [];
const checkboxes = document.getElementsByClassName("selectUserChkBox");
if(ev.currentTarget){
if(ev.currentTarget.checked){
for (let i=0; i<checkboxes.length; i++) {
if (!checkboxes[i].disabled) {
selectedUserChkBoxUserIds.push(checkboxes[i].id);
checkboxes[i].checked = true;
}
}
}
else{
for (let i=0; i<checkboxes.length; i++) {
if (!checkboxes[i].disabled) {
checkboxes[i].checked = false;
}
}
}
});
}
}
else{
for(let i = 0; i < selectedUserChkBoxUserIds.length; i++){
currentUser = ReactiveCache.getUser(selectedUserChkBoxUserIds[i]);
userTms = currentUser.teams;
if(userTms !== undefined || userTms.length > 0)
{
currUserTeamIndex = userTms.findIndex(function(t){ return t.teamId == selectedEltValueId});
if(currUserTeamIndex != -1){
userTms.splice(currUserTeamIndex, 1);
}
}
if(selectedUserChkBoxUserIds.length > 0)
document.getElementById("divAddOrRemoveTeam").style.display = 'block';
else
document.getElementById("divAddOrRemoveTeam").style.display = 'none';
},
},
];
Users.update(selectedUserChkBoxUserIds[i], {
$set:{
teams: userTms
}
});
}
}
document.getElementById("divAddOrRemoveTeamContainer").style.display = 'none';
},
}).register('selectAllUser');
});
Template.newOrgRow.events({
'click a.new-org': Popup.open('newOrg'),
});
Template.newTeamRow.events({
'click a.new-team': Popup.open('newTeam'),
});
Template.newUserRow.events({
'click a.new-user': Popup.open('newUser'),
});
Template.selectAllUser.events({
'click .allUserChkBox': function(ev){
selectedUserChkBoxUserIds = [];
const checkboxes = document.getElementsByClassName("selectUserChkBox");
if(ev.currentTarget){
if(ev.currentTarget.checked){
for (let i=0; i<checkboxes.length; i++) {
if (!checkboxes[i].disabled) {
selectedUserChkBoxUserIds.push(checkboxes[i].id);
checkboxes[i].checked = true;
}
}
}
else{
for (let i=0; i<checkboxes.length; i++) {
if (!checkboxes[i].disabled) {
checkboxes[i].checked = false;
}
}
}
}
if(selectedUserChkBoxUserIds.length > 0)
document.getElementById("divAddOrRemoveTeam").style.display = 'block';
else
document.getElementById("divAddOrRemoveTeam").style.display = 'none';
},
});
Template.editOrgPopup.events({
submit(event, templateInstance) {

File diff suppressed because it is too large Load diff

View file

@ -1,111 +1,118 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { InfiniteScrolling } from '/client/lib/infiniteScrolling';
const translationsPerPage = 25;
BlazeComponent.extendComponent({
mixins() {
return [Mixins.InfiniteScrolling];
},
onCreated() {
this.error = new ReactiveVar('');
this.loading = new ReactiveVar(false);
this.translationSetting = new ReactiveVar(true);
this.findTranslationsOptions = new ReactiveVar({});
this.numberTranslations = new ReactiveVar(0);
Template.translation.onCreated(function () {
this.error = new ReactiveVar('');
this.loading = new ReactiveVar(false);
this.translationSetting = new ReactiveVar(true);
this.findTranslationsOptions = new ReactiveVar({});
this.numberTranslations = new ReactiveVar(0);
this.page = new ReactiveVar(1);
this.loadNextPageLocked = false;
this.callFirstWith(null, 'resetNextPeak');
this.autorun(() => {
const limitTranslations = this.page.get() * translationsPerPage;
this.page = new ReactiveVar(1);
this.loadNextPageLocked = false;
this.infiniteScrolling = new InfiniteScrolling();
this.subscribe('translation', this.findTranslationsOptions.get(), 0, () => {
this.loadNextPageLocked = false;
const nextPeakBefore = this.callFirstWith(null, 'getNextPeak');
this.calculateNextPeak();
const nextPeakAfter = this.callFirstWith(null, 'getNextPeak');
if (nextPeakBefore === nextPeakAfter) {
this.callFirstWith(null, 'resetNextPeak');
}
});
});
},
events() {
return [
{
'click #searchTranslationButton'() {
this.filterTranslation();
},
'keydown #searchTranslationInput'(event) {
if (event.keyCode === 13 && !event.shiftKey) {
this.filterTranslation();
}
},
'click #newTranslationButton'() {
Popup.open('newTranslation');
},
'click a.js-translation-menu': this.switchMenu,
},
];
},
filterTranslation() {
const value = $('#searchTranslationInput').first().val();
if (value === '') {
this.findTranslationsOptions.set({});
} else {
const regex = new RegExp(value, 'i');
this.findTranslationsOptions.set({
$or: [
{ language: regex },
{ text: regex },
{ translationText: regex },
],
});
}
},
loadNextPage() {
this.loadNextPage = () => {
if (this.loadNextPageLocked === false) {
this.page.set(this.page.get() + 1);
this.loadNextPageLocked = true;
}
},
calculateNextPeak() {
};
this.calculateNextPeak = () => {
const element = this.find('.main-body');
if (element) {
const altitude = element.scrollHeight;
this.callFirstWith(this, 'setNextPeak', altitude);
this.infiniteScrolling.setNextPeak(element.scrollHeight);
}
};
this.autorun(() => {
const limitTranslations = this.page.get() * translationsPerPage;
this.subscribe('translation', this.findTranslationsOptions.get(), 0, () => {
this.loadNextPageLocked = false;
const nextPeakBefore = this.infiniteScrolling.getNextPeak();
this.calculateNextPeak();
const nextPeakAfter = this.infiniteScrolling.getNextPeak();
if (nextPeakBefore === nextPeakAfter) {
this.infiniteScrolling.resetNextPeak();
}
});
});
});
Template.translation.helpers({
loading() {
return Template.instance().loading;
},
reachNextPeak() {
this.loadNextPage();
},
setError(error) {
this.error.set(error);
},
setLoading(w) {
this.loading.set(w);
translationSetting() {
return Template.instance().translationSetting;
},
translationList() {
const translations = ReactiveCache.getTranslations(this.findTranslationsOptions.get(), {
const tpl = Template.instance();
const translations = ReactiveCache.getTranslations(tpl.findTranslationsOptions.get(), {
sort: { modifiedAt: 1 },
fields: { _id: true },
});
this.numberTranslations.set(translations.length);
tpl.numberTranslations.set(translations.length);
return translations;
},
translationNumber() {
return this.numberTranslations.get();
return Template.instance().numberTranslations.get();
},
switchMenu(event) {
setError(error) {
Template.instance().error.set(error);
},
setLoading(w) {
Template.instance().loading.set(w);
},
});
Template.translation.events({
'click #searchTranslationButton'(event, tpl) {
_filterTranslation(tpl);
},
'keydown #searchTranslationInput'(event, tpl) {
if (event.keyCode === 13 && !event.shiftKey) {
_filterTranslation(tpl);
}
},
'click #newTranslationButton'() {
Popup.open('newTranslation');
},
'click a.js-translation-menu'(event, tpl) {
const target = $(event.target);
if (!target.hasClass('active')) {
$('.side-menu li.active').removeClass('active');
target.parent().addClass('active');
const targetID = target.data('id');
this.translationSetting.set('translation-setting' === targetID);
tpl.translationSetting.set('translation-setting' === targetID);
}
},
}).register('translation');
'scroll .main-body'(event, tpl) {
tpl.infiniteScrolling.checkScrollPosition(event.currentTarget, () => {
tpl.loadNextPage();
});
},
});
function _filterTranslation(tpl) {
const value = $('#searchTranslationInput').first().val();
if (value === '') {
tpl.findTranslationsOptions.set({});
} else {
const regex = new RegExp(value, 'i');
tpl.findTranslationsOptions.set({
$or: [
{ language: regex },
{ text: regex },
{ translationText: regex },
],
});
}
}
Template.translationRow.helpers({
translationData() {
@ -135,30 +142,20 @@ Template.newTranslationPopup.helpers({
},
});
BlazeComponent.extendComponent({
onCreated() {},
Template.translationRow.helpers({
translation() {
return ReactiveCache.getTranslation(this.translationId);
},
events() {
return [
{
'click a.edit-translation': Popup.open('editTranslation'),
'click a.more-settings-translation': Popup.open('settingsTranslation'),
},
];
},
}).register('translationRow');
});
BlazeComponent.extendComponent({
events() {
return [
{
'click a.new-translation': Popup.open('newTranslation'),
},
];
},
}).register('newTranslationRow');
Template.translationRow.events({
'click a.edit-translation': Popup.open('editTranslation'),
'click a.more-settings-translation': Popup.open('settingsTranslation'),
});
Template.newTranslationRow.events({
'click a.new-translation': Popup.open('newTranslation'),
});
Template.editTranslationPopup.events({
submit(event, templateInstance) {