From 8e14459cff4da1391f536dfbc6441abb21e9c215 Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Wed, 22 Apr 2020 14:44:08 +0200 Subject: Implement option to change the first day of week in user settings Implements #2535. --- client/components/main/popup.styl | 4 ++++ client/components/users/userHeader.jade | 11 ++++++++++ client/components/users/userHeader.js | 37 +++++++++++++++++++++++++++++++++ client/lib/datepicker.js | 11 +++++++++- i18n/en.i18n.json | 10 ++++++++- models/users.js | 20 ++++++++++++++++++ public/api/wekan.yml | 4 ++++ 7 files changed, 95 insertions(+), 2 deletions(-) diff --git a/client/components/main/popup.styl b/client/components/main/popup.styl index 023cba3d..f1db3927 100644 --- a/client/components/main/popup.styl +++ b/client/components/main/popup.styl @@ -135,6 +135,10 @@ $popupWidth = 300px margin-bottom: 8px .pop-over-list + li + display: block + clear: both + li > a clear: both cursor: pointer diff --git a/client/components/users/userHeader.jade b/client/components/users/userHeader.jade index 1cd9da6b..3747d882 100644 --- a/client/components/users/userHeader.jade +++ b/client/components/users/userHeader.jade @@ -117,6 +117,17 @@ template(name="changeSettingsPopup") | {{_ 'show-cards-minimum-count'}} input#show-cards-count-at.inline-input.left(type="number" value="#{showCardsCountAt}" min="0" max="99" onkeydown="return false") input.js-apply-show-cards-at.left(type="submit" value="{{_ 'apply'}}") + li + label.bold + i.fa.fa-calendar + | {{_ 'start-day-of-week'}} + select#start-day-of-week.inline-input.left + each day in weekDays startDayOfWeek + if day.isSelected + option(selected="true", value="#{day.value}") #{day.name} + else + option(value="#{day.value}") #{day.name} + input.js-apply-start-day-of-week.left(type="submit" value="{{_ 'apply'}}") template(name="userDeletePopup") unless currentUser.isWorker diff --git a/client/components/users/userHeader.js b/client/components/users/userHeader.js index cd315bd6..5298e99a 100644 --- a/client/components/users/userHeader.js +++ b/client/components/users/userHeader.js @@ -224,6 +224,27 @@ Template.changeSettingsPopup.helpers({ return cookies.get('limitToShowCardsCount'); } }, + weekDays(startDay) { + return [ + TAPi18n.__('sunday'), + TAPi18n.__('monday'), + TAPi18n.__('tuesday'), + TAPi18n.__('wednesday'), + TAPi18n.__('thursday'), + TAPi18n.__('friday'), + TAPi18n.__('saturday'), + ].map(function(day, index) { + return { name: day, value: index, isSelected: index === startDay }; + }); + }, + startDayOfWeek() { + currentUser = Meteor.user(); + if (currentUser) { + return currentUser.getStartDayOfWeek(); + } else { + return cookies.get('startDayOfWeek'); + } + }, }); Template.changeSettingsPopup.events({ @@ -263,4 +284,20 @@ Template.changeSettingsPopup.events({ Popup.back(); } }, + 'click .js-apply-start-day-of-week'(event, templateInstance) { + event.preventDefault(); + const startDay = parseInt( + templateInstance.$('#start-day-of-week').val(), + 10, + ); + if (!isNaN(startDay)) { + currentUser = Meteor.user(); + if (currentUser) { + Meteor.call('changeStartDayOfWeek', startDay); + } else { + cookies.set('startDayOfWeek', startDay); + } + Popup.back(); + } + }, }); diff --git a/client/lib/datepicker.js b/client/lib/datepicker.js index 1c02c2ff..aa05310c 100644 --- a/client/lib/datepicker.js +++ b/client/lib/datepicker.js @@ -10,13 +10,22 @@ DatePicker = BlazeComponent.extendComponent({ this.defaultTime = defaultTime; }, + startDayOfWeek() { + const currentUser = Meteor.user(); + if (currentUser) { + return currentUser.getStartDayOfWeek(); + } else { + return 1; + } + }, + onRendered() { const $picker = this.$('.js-datepicker') .datepicker({ todayHighlight: true, todayBtn: 'linked', language: TAPi18n.getLanguage(), - weekStart: 1, + weekStart: this.startDayOfWeek(), }) .on( 'changeDate', diff --git a/i18n/en.i18n.json b/i18n/en.i18n.json index 18a0680b..864d60ce 100644 --- a/i18n/en.i18n.json +++ b/i18n/en.i18n.json @@ -777,5 +777,13 @@ "mark-all-as-read": "Mark all as read", "remove-all-read": "Remove all read", "allow-rename": "Allow Rename", - "allowRenamePopup-title": "Allow Rename" + "allowRenamePopup-title": "Allow Rename", + "start-day-of-week": "Set day of the week start", + "monday": "Monday", + "tuesday": "Tuesday", + "wednesday": "Wednesday", + "thursday": "Thursday", + "friday": "Friday", + "saturday": "Saturday", + "sunday": "Sunday" } diff --git a/models/users.js b/models/users.js index f4b7329a..f4f4f38e 100644 --- a/models/users.js +++ b/models/users.js @@ -190,6 +190,13 @@ Users.attachSchema( type: Number, optional: true, }, + 'profile.startDayOfWeek': { + /** + * startDayOfWeek field of the user + */ + type: Number, + optional: true, + }, 'profile.starredBoards': { /** * list of starred board IDs @@ -521,6 +528,11 @@ Users.helpers({ return profile.language || 'en'; }, + getStartDayOfWeek() { + const profile = this.profile || {}; + return profile.startDayOfWeek || 1; + }, + getTemplatesBoardId() { return (this.profile || {}).templatesBoardId; }, @@ -652,6 +664,10 @@ Users.mutations({ return { $set: { 'profile.showCardsCountAt': limit } }; }, + setStartDayOfWeek(startDay) { + return { $set: { 'profile.startDayOfWeek': startDay } }; + }, + setBoardView(view) { return { $set: { @@ -682,6 +698,10 @@ Meteor.methods({ check(limit, Number); Meteor.user().setShowCardsCountAt(limit); }, + changeStartDayOfWeek(startDay) { + check(startDay, Number); + Meteor.user().setStartDayOfWeek(startDay); + }, }); if (Meteor.isServer) { diff --git a/public/api/wekan.yml b/public/api/wekan.yml index 6dccbe7f..8cd4acfa 100644 --- a/public/api/wekan.yml +++ b/public/api/wekan.yml @@ -2544,6 +2544,10 @@ definitions: description: | showCardCountAt field of the user type: number + startDayOfWeek: + description: | + startDayOfWeek field of the user + type: number starredBoards: description: | list of starred board IDs -- cgit v1.2.3-1-g7c22