isMiniScreen and showDesktopDragHandles centralized in class Utils

- a lot of same code everywhere in many files, this is against the
  concept "don't repeat yourself"
This commit is contained in:
Martin Filser 2021-10-13 13:49:15 +02:00
parent cbc6463019
commit b9178cfcb6
12 changed files with 14 additions and 126 deletions

View file

@ -191,21 +191,11 @@ BlazeComponent.extendComponent({
}); });
this.autorun(() => { this.autorun(() => {
let showDesktopDragHandles = false; if (Utils.isMiniScreenOrShowDesktopDragHandles()) {
currentUser = Meteor.user();
if (currentUser) {
showDesktopDragHandles = (currentUser.profile || {})
.showDesktopDragHandles;
} else if (window.localStorage.getItem('showDesktopDragHandles')) {
showDesktopDragHandles = true;
} else {
showDesktopDragHandles = false;
}
if (Utils.isMiniScreen() || showDesktopDragHandles) {
$swimlanesDom.sortable({ $swimlanesDom.sortable({
handle: '.js-swimlane-header-handle', handle: '.js-swimlane-header-handle',
}); });
} else if (!Utils.isMiniScreen() && !showDesktopDragHandles) { } else if (!Utils.isMiniScreen() && !Utils.isShowDesktopDragHandles()) {
$swimlanesDom.sortable({ $swimlanesDom.sortable({
handle: '.swimlane-header', handle: '.swimlane-header',
}); });

View file

@ -3,13 +3,9 @@ template(name="minicard")
class="{{#if isLinkedCard}}linked-card{{/if}}" class="{{#if isLinkedCard}}linked-card{{/if}}"
class="{{#if isLinkedBoard}}linked-board{{/if}}" class="{{#if isLinkedBoard}}linked-board{{/if}}"
class="minicard-{{colorClass}}") class="minicard-{{colorClass}}")
if isMiniScreen if isMiniScreenOrShowDesktopDragHandles
.handle .handle
.fa.fa-arrows .fa.fa-arrows
unless isMiniScreen
if showDesktopDragHandles
.handle
.fa.fa-arrows
if cover if cover
.minicard-cover(style="background-image: url('{{cover.url}}');") .minicard-cover(style="background-image: url('{{cover.url}}');")
if labels if labels

View file

@ -75,16 +75,6 @@ BlazeComponent.extendComponent({
}).register('minicard'); }).register('minicard');
Template.minicard.helpers({ Template.minicard.helpers({
showDesktopDragHandles() {
currentUser = Meteor.user();
if (currentUser) {
return (currentUser.profile || {}).showDesktopDragHandles;
} else if (window.localStorage.getItem('showDesktopDragHandles')) {
return true;
} else {
return false;
}
},
hiddenMinicardLabelText() { hiddenMinicardLabelText() {
currentUser = Meteor.user(); currentUser = Meteor.user();
if (currentUser) { if (currentUser) {

View file

@ -117,22 +117,11 @@ BlazeComponent.extendComponent({
}); });
this.autorun(() => { this.autorun(() => {
let showDesktopDragHandles = false; if (Utils.isMiniScreenOrShowDesktopDragHandles()) {
currentUser = Meteor.user();
if (currentUser) {
showDesktopDragHandles = (currentUser.profile || {})
.showDesktopDragHandles;
} else if (window.localStorage.getItem('showDesktopDragHandles')) {
showDesktopDragHandles = true;
} else {
showDesktopDragHandles = false;
}
if (Utils.isMiniScreen() || showDesktopDragHandles) {
$cards.sortable({ $cards.sortable({
handle: '.handle', handle: '.handle',
}); });
} else if (!Utils.isMiniScreen() && !showDesktopDragHandles) { } else if (!Utils.isMiniScreen() && !Utils.isShowDesktopDragHandles()) {
$cards.sortable({ $cards.sortable({
handle: '.minicard', handle: '.minicard',
}); });
@ -178,19 +167,6 @@ BlazeComponent.extendComponent({
}, },
}).register('list'); }).register('list');
Template.list.helpers({
showDesktopDragHandles() {
currentUser = Meteor.user();
if (currentUser) {
return (currentUser.profile || {}).showDesktopDragHandles;
} else if (window.localStorage.getItem('showDesktopDragHandles')) {
return true;
} else {
return false;
}
},
});
Template.miniList.events({ Template.miniList.events({
'click .js-select-list'() { 'click .js-select-list'() {
const listId = this._id; const listId = this._id;

View file

@ -44,7 +44,7 @@ template(name="listHeader")
a.js-add-card.fa.fa-plus.list-header-plus-icon(title="{{_ 'add-card-to-top-of-list'}}") a.js-add-card.fa.fa-plus.list-header-plus-icon(title="{{_ 'add-card-to-top-of-list'}}")
a.fa.fa-navicon.js-open-list-menu(title="{{_ 'listActionPopup-title'}}") a.fa.fa-navicon.js-open-list-menu(title="{{_ 'listActionPopup-title'}}")
if currentUser.isBoardAdmin if currentUser.isBoardAdmin
if showDesktopDragHandles if isShowDesktopDragHandles
a.list-header-handle.handle.fa.fa-arrows.js-list-handle a.list-header-handle.handle.fa.fa-arrows.js-list-handle
template(name="editListTitleForm") template(name="editListTitleForm")

View file

@ -122,18 +122,7 @@ BlazeComponent.extendComponent({
Template.listHeader.helpers({ Template.listHeader.helpers({
isBoardAdmin() { isBoardAdmin() {
return Meteor.user().isBoardAdmin(); return Meteor.user().isBoardAdmin();
}, }
showDesktopDragHandles() {
currentUser = Meteor.user();
if (currentUser) {
return (currentUser.profile || {}).showDesktopDragHandles;
} else if (window.localStorage.getItem('showDesktopDragHandles')) {
return true;
} else {
return false;
}
},
}); });
Template.listActionPopup.helpers({ Template.listActionPopup.helpers({

View file

@ -26,7 +26,7 @@ template(name="swimlaneFixedHeader")
a.fa.fa-plus.js-open-add-swimlane-menu.swimlane-header-plus-icon(title="{{_ 'add-swimlane'}}") a.fa.fa-plus.js-open-add-swimlane-menu.swimlane-header-plus-icon(title="{{_ 'add-swimlane'}}")
a.fa.fa-navicon.js-open-swimlane-menu(title="{{_ 'swimlaneActionPopup-title'}}") a.fa.fa-navicon.js-open-swimlane-menu(title="{{_ 'swimlaneActionPopup-title'}}")
unless isMiniScreen unless isMiniScreen
if showDesktopDragHandles if isShowDesktopDragHandles
a.swimlane-header-handle.handle.fa.fa-arrows.js-swimlane-header-handle a.swimlane-header-handle.handle.fa.fa-arrows.js-swimlane-header-handle
if isMiniScreen if isMiniScreen
a.swimlane-header-miniscreen-handle.handle.fa.fa-arrows.js-swimlane-header-handle a.swimlane-header-miniscreen-handle.handle.fa.fa-arrows.js-swimlane-header-handle

View file

@ -28,19 +28,6 @@ BlazeComponent.extendComponent({
}, },
}).register('swimlaneHeader'); }).register('swimlaneHeader');
Template.swimlaneHeader.helpers({
showDesktopDragHandles() {
currentUser = Meteor.user();
if (currentUser) {
return (currentUser.profile || {}).showDesktopDragHandles;
} else if (window.localStorage.getItem('showDesktopDragHandles')) {
return true;
} else {
return false;
}
},
});
Template.swimlaneFixedHeader.helpers({ Template.swimlaneFixedHeader.helpers({
isBoardAdmin() { isBoardAdmin() {
return Meteor.user().isBoardAdmin(); return Meteor.user().isBoardAdmin();

View file

@ -95,22 +95,11 @@ function initSortable(boardComponent, $listsDom) {
//} //}
boardComponent.autorun(() => { boardComponent.autorun(() => {
let showDesktopDragHandles = false; if (Utils.isMiniScreenOrShowDesktopDragHandles) {
currentUser = Meteor.user();
if (currentUser) {
showDesktopDragHandles = (currentUser.profile || {})
.showDesktopDragHandles;
} else if (window.localStorage.getItem('showDesktopDragHandles')) {
showDesktopDragHandles = true;
} else {
showDesktopDragHandles = false;
}
if (Utils.isMiniScreen() || showDesktopDragHandles) {
$listsDom.sortable({ $listsDom.sortable({
handle: '.js-list-handle', handle: '.js-list-handle',
}); });
} else if (!Utils.isMiniScreen() && !showDesktopDragHandles) { } else if (!Utils.isMiniScreen() && !Utils.isShowDesktopDragHandles()) {
$listsDom.sortable({ $listsDom.sortable({
handle: '.js-list-header', handle: '.js-list-header',
}); });
@ -172,19 +161,8 @@ BlazeComponent.extendComponent({
// the user will legitimately expect to be able to select some text with // the user will legitimately expect to be able to select some text with
// his mouse. // his mouse.
let showDesktopDragHandles = false;
currentUser = Meteor.user();
if (currentUser) {
showDesktopDragHandles = (currentUser.profile || {})
.showDesktopDragHandles;
} else if (window.localStorage.getItem('showDesktopDragHandles')) {
showDesktopDragHandles = true;
} else {
showDesktopDragHandles = false;
}
const noDragInside = ['a', 'input', 'textarea', 'p'].concat( const noDragInside = ['a', 'input', 'textarea', 'p'].concat(
Utils.isMiniScreen() || showDesktopDragHandles Utils.isMiniScreenOrShowDesktopDragHandles()
? ['.js-list-handle', '.js-swimlane-header-handle'] ? ['.js-list-handle', '.js-swimlane-header-handle']
: ['.js-list-header'], : ['.js-list-header'],
); );
@ -264,16 +242,6 @@ BlazeComponent.extendComponent({
}).register('addListForm'); }).register('addListForm');
Template.swimlane.helpers({ Template.swimlane.helpers({
showDesktopDragHandles() {
currentUser = Meteor.user();
if (currentUser) {
return (currentUser.profile || {}).showDesktopDragHandles;
} else if (window.localStorage.getItem('showDesktopDragHandles')) {
return true;
} else {
return false;
}
},
canSeeAddList() { canSeeAddList() {
return Meteor.user().isBoardAdmin(); return Meteor.user().isBoardAdmin();
/* /*

View file

@ -134,7 +134,7 @@ template(name="changeSettingsPopup")
a.js-toggle-desktop-drag-handles a.js-toggle-desktop-drag-handles
i.fa.fa-arrows i.fa.fa-arrows
| {{_ 'show-desktop-drag-handles'}} | {{_ 'show-desktop-drag-handles'}}
if showDesktopDragHandles if isShowDesktopDragHandles
i.fa.fa-check i.fa.fa-check
unless currentUser.isWorker unless currentUser.isWorker
li li

View file

@ -259,16 +259,6 @@ Template.changeLanguagePopup.events({
}); });
Template.changeSettingsPopup.helpers({ Template.changeSettingsPopup.helpers({
showDesktopDragHandles() {
currentUser = Meteor.user();
if (currentUser) {
return (currentUser.profile || {}).showDesktopDragHandles;
} else if (window.localStorage.getItem('showDesktopDragHandles')) {
return true;
} else {
return false;
}
},
hiddenSystemMessages() { hiddenSystemMessages() {
currentUser = Meteor.user(); currentUser = Meteor.user();
if (currentUser) { if (currentUser) {

View file

@ -248,6 +248,8 @@ Utils = {
const currentUser = Meteor.user(); const currentUser = Meteor.user();
if (currentUser) { if (currentUser) {
return (currentUser.profile || {}).showDesktopDragHandles; return (currentUser.profile || {}).showDesktopDragHandles;
} else if (window.localStorage.getItem('showDesktopDragHandles')) {
return true;
} else { } else {
return false; return false;
} }