support custom first day of week

This commit is contained in:
MaysWind
2021-01-31 20:09:03 +08:00
parent e06fba3f8b
commit 61267af634
15 changed files with 262 additions and 81 deletions
+9
View File
@@ -50,6 +50,7 @@ func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Erro
Nickname: userRegisterReq.Nickname, Nickname: userRegisterReq.Nickname,
Password: userRegisterReq.Password, Password: userRegisterReq.Password,
DefaultCurrency: userRegisterReq.DefaultCurrency, DefaultCurrency: userRegisterReq.DefaultCurrency,
FirstDayOfWeek: userRegisterReq.FirstDayOfWeek,
} }
err = a.users.CreateUser(user) err = a.users.CreateUser(user)
@@ -158,6 +159,14 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs
anythingUpdate = true anythingUpdate = true
} }
if userUpdateReq.FirstDayOfWeek != nil && *userUpdateReq.FirstDayOfWeek != user.FirstDayOfWeek {
user.FirstDayOfWeek = *userUpdateReq.FirstDayOfWeek
userNew.FirstDayOfWeek = *userUpdateReq.FirstDayOfWeek
anythingUpdate = true
} else {
userNew.FirstDayOfWeek = models.WEEKDAY_INVALID;
}
if !anythingUpdate { if !anythingUpdate {
return nil, errs.ErrNothingWillBeUpdated return nil, errs.ErrNothingWillBeUpdated
} }
+36 -14
View File
@@ -10,6 +10,21 @@ const (
USER_TYPE_SUPER_ADMIN UserType = 127 USER_TYPE_SUPER_ADMIN UserType = 127
) )
// WeekDay represents week day
type WeekDay byte
// Week days
const (
WEEKDAY_SUNDAY WeekDay = 0
WEEKDAY_MONDAY WeekDay = 1
WEEKDAY_TUESDAY WeekDay = 2
WEEKDAY_WEDNESDAY WeekDay = 3
WEEKDAY_THURSDAY WeekDay = 4
WEEKDAY_FRIDAY WeekDay = 5
WEEKDAY_SATURDAY WeekDay = 6
WEEKDAY_INVALID WeekDay = 255
)
// User represents user data stored in database // User represents user data stored in database
type User struct { type User struct {
Uid int64 `xorm:"PK"` Uid int64 `xorm:"PK"`
@@ -21,6 +36,7 @@ type User struct {
Rands string `xorm:"VARCHAR(10) NOT NULL"` Rands string `xorm:"VARCHAR(10) NOT NULL"`
Type UserType `xorm:"TINYINT NOT NULL"` Type UserType `xorm:"TINYINT NOT NULL"`
DefaultCurrency string `xorm:"VARCHAR(3) NOT NULL"` DefaultCurrency string `xorm:"VARCHAR(3) NOT NULL"`
FirstDayOfWeek WeekDay `xorm:"TINYINT NOT NULL"`
IsAdmin bool `xorm:"NOT NULL"` IsAdmin bool `xorm:"NOT NULL"`
Deleted bool `xorm:"NOT NULL"` Deleted bool `xorm:"NOT NULL"`
EmailVerified bool `xorm:"NOT NULL"` EmailVerified bool `xorm:"NOT NULL"`
@@ -32,10 +48,11 @@ type User struct {
// UserBasicInfo represents a view-object of user basic info // UserBasicInfo represents a view-object of user basic info
type UserBasicInfo struct { type UserBasicInfo struct {
Username string `json:"username"` Username string `json:"username"`
Email string `json:"email"` Email string `json:"email"`
Nickname string `json:"nickname"` Nickname string `json:"nickname"`
DefaultCurrency string `json:"defaultCurrency"` DefaultCurrency string `json:"defaultCurrency"`
FirstDayOfWeek WeekDay `json:"firstDayOfWeek"`
} }
// UserLoginRequest represents all parameters of user login request // UserLoginRequest represents all parameters of user login request
@@ -46,20 +63,22 @@ type UserLoginRequest struct {
// UserRegisterRequest represents all parameters of user registering request // UserRegisterRequest represents all parameters of user registering request
type UserRegisterRequest struct { type UserRegisterRequest struct {
Username string `json:"username" binding:"required,notBlank,max=32,validUsername"` Username string `json:"username" binding:"required,notBlank,max=32,validUsername"`
Email string `json:"email" binding:"required,notBlank,max=100,validEmail"` Email string `json:"email" binding:"required,notBlank,max=100,validEmail"`
Nickname string `json:"nickname" binding:"required,notBlank,max=64"` Nickname string `json:"nickname" binding:"required,notBlank,max=64"`
Password string `json:"password" binding:"required,min=6,max=128"` Password string `json:"password" binding:"required,min=6,max=128"`
DefaultCurrency string `json:"defaultCurrency" binding:"required,len=3,validCurrency"` DefaultCurrency string `json:"defaultCurrency" binding:"required,len=3,validCurrency"`
FirstDayOfWeek WeekDay `json:"firstDayOfWeek" binding:"min=0,max=6"`
} }
// UserProfileUpdateRequest represents all parameters of user updating profile request // UserProfileUpdateRequest represents all parameters of user updating profile request
type UserProfileUpdateRequest struct { type UserProfileUpdateRequest struct {
Email string `json:"email" binding:"omitempty,notBlank,max=100,validEmail"` Email string `json:"email" binding:"omitempty,notBlank,max=100,validEmail"`
Nickname string `json:"nickname" binding:"omitempty,notBlank,max=64"` Nickname string `json:"nickname" binding:"omitempty,notBlank,max=64"`
Password string `json:"password" binding:"omitempty,min=6,max=128"` Password string `json:"password" binding:"omitempty,min=6,max=128"`
OldPassword string `json:"oldPassword" binding:"omitempty,min=6,max=128"` OldPassword string `json:"oldPassword" binding:"omitempty,min=6,max=128"`
DefaultCurrency string `json:"defaultCurrency" binding:"required,len=3,validCurrency"` DefaultCurrency string `json:"defaultCurrency" binding:"omitempty,len=3,validCurrency"`
FirstDayOfWeek *WeekDay `json:"firstDayOfWeek" binding:"omitempty,min=0,max=6"`
} }
// UserProfileUpdateResponse represents the data returns to frontend after updating profile // UserProfileUpdateResponse represents the data returns to frontend after updating profile
@@ -75,6 +94,7 @@ type UserProfileResponse struct {
Nickname string `json:"nickname"` Nickname string `json:"nickname"`
Type UserType `json:"type"` Type UserType `json:"type"`
DefaultCurrency string `json:"defaultCurrency"` DefaultCurrency string `json:"defaultCurrency"`
FirstDayOfWeek WeekDay `json:"firstDayOfWeek"`
LastLoginAt int64 `json:"lastLoginAt"` LastLoginAt int64 `json:"lastLoginAt"`
} }
@@ -85,6 +105,7 @@ func (u User) ToUserBasicInfo() *UserBasicInfo {
Email: u.Email, Email: u.Email,
Nickname: u.Nickname, Nickname: u.Nickname,
DefaultCurrency: u.DefaultCurrency, DefaultCurrency: u.DefaultCurrency,
FirstDayOfWeek: u.FirstDayOfWeek,
} }
} }
@@ -96,6 +117,7 @@ func (u User) ToUserProfileResponse() *UserProfileResponse {
Nickname: u.Nickname, Nickname: u.Nickname,
Type: u.Type, Type: u.Type,
DefaultCurrency: u.DefaultCurrency, DefaultCurrency: u.DefaultCurrency,
FirstDayOfWeek: u.FirstDayOfWeek,
LastLoginAt: u.LastLoginUnixTime, LastLoginAt: u.LastLoginUnixTime,
} }
} }
+4
View File
@@ -194,6 +194,10 @@ func (s *UserService) UpdateUser(user *models.User) (keyProfileUpdated bool, err
updateCols = append(updateCols, "default_currency") updateCols = append(updateCols, "default_currency")
} }
if models.WEEKDAY_SUNDAY <= user.FirstDayOfWeek && user.FirstDayOfWeek <= models.WEEKDAY_SATURDAY {
updateCols = append(updateCols, "first_day_of_week")
}
user.UpdatedUnixTime = now user.UpdatedUnixTime = now
updateCols = append(updateCols, "updated_unix_time") updateCols = append(updateCols, "updated_unix_time")
+32
View File
@@ -1,3 +1,34 @@
const allWeekDays = {
Sunday: {
type: 0,
name: 'Sunday'
},
Monday: {
type: 1,
name: 'Monday'
},
Tuesday: {
type: 2,
name: 'Tuesday'
},
Wednesday: {
type: 3,
name: 'Wednesday'
},
Thursday: {
type: 4,
name: 'Thursday'
},
Friday: {
type: 5,
name: 'Friday'
},
Saturday: {
type: 6,
name: 'Saturday'
}
};
const allDateRanges = { const allDateRanges = {
All: { All: {
type: 0, type: 0,
@@ -50,5 +81,6 @@ const allDateRanges = {
}; };
export default { export default {
allWeekDays: allWeekDays,
allDateRanges: allDateRanges, allDateRanges: allDateRanges,
}; };
+6 -4
View File
@@ -81,13 +81,14 @@ export default {
} }
}); });
}, },
register: ({ username, email, nickname, password, defaultCurrency }) => { register: ({ username, email, nickname, password, defaultCurrency, firstDayOfWeek }) => {
return axios.post('register.json', { return axios.post('register.json', {
username, username,
email, email,
nickname, nickname,
password, password,
defaultCurrency defaultCurrency,
firstDayOfWeek
}); });
}, },
logout: () => { logout: () => {
@@ -128,13 +129,14 @@ export default {
getProfile: () => { getProfile: () => {
return axios.get('v1/users/profile/get.json'); return axios.get('v1/users/profile/get.json');
}, },
updateProfile: ({ email, nickname, password, oldPassword, defaultCurrency }) => { updateProfile: ({ email, nickname, password, oldPassword, defaultCurrency, firstDayOfWeek }) => {
return axios.post('v1/users/profile/update.json', { return axios.post('v1/users/profile/update.json', {
email, email,
nickname, nickname,
password, password,
oldPassword, oldPassword,
defaultCurrency defaultCurrency,
firstDayOfWeek
}); });
}, },
get2FAStatus: () => { get2FAStatus: () => {
+20 -9
View File
@@ -110,13 +110,24 @@ function getTodayLastUnixTime() {
return moment.unix(getTodayFirstUnixTime()).add(1, 'days').subtract(1, 'seconds').unix(); return moment.unix(getTodayFirstUnixTime()).add(1, 'days').subtract(1, 'seconds').unix();
} }
function getThisWeekFirstUnixTime() { function getThisWeekFirstUnixTime(firstDayOfWeek) {
const today = moment.unix(getTodayFirstUnixTime()); const today = moment.unix(getTodayFirstUnixTime());
return today.subtract(today.day(), 'days').unix();
if (!isNumber(firstDayOfWeek)) {
firstDayOfWeek = 0;
}
let dayOfWeek = today.day() - firstDayOfWeek;
if (dayOfWeek < 0) {
dayOfWeek += 7;
}
return today.subtract(dayOfWeek, 'days').unix();
} }
function getThisWeekLastUnixTime() { function getThisWeekLastUnixTime(firstDayOfWeek) {
return moment.unix(getThisWeekFirstUnixTime()).add(7, 'days').subtract(1, 'seconds').unix(); return moment.unix(getThisWeekFirstUnixTime(firstDayOfWeek)).add(7, 'days').subtract(1, 'seconds').unix();
} }
function getThisMonthFirstUnixTime() { function getThisMonthFirstUnixTime() {
@@ -163,7 +174,7 @@ function getShiftedDateRange(minTime, maxTime, scale) {
}; };
} }
function getDateRangeByDateType(dateType) { function getDateRangeByDateType(dateType, firstDayOfWeek) {
let maxTime = 0; let maxTime = 0;
let minTime = 0; let minTime = 0;
@@ -183,11 +194,11 @@ function getDateRangeByDateType(dateType) {
maxTime = getUnixTimeBeforeUnixTime(getTodayLastUnixTime(), 1, 'days'); maxTime = getUnixTimeBeforeUnixTime(getTodayLastUnixTime(), 1, 'days');
minTime = getUnixTimeBeforeUnixTime(getTodayFirstUnixTime(), 29, 'days'); minTime = getUnixTimeBeforeUnixTime(getTodayFirstUnixTime(), 29, 'days');
} else if (dateType === dateTimeConstants.allDateRanges.ThisWeek.type) { // This week } else if (dateType === dateTimeConstants.allDateRanges.ThisWeek.type) { // This week
maxTime = getThisWeekLastUnixTime(); maxTime = getThisWeekLastUnixTime(firstDayOfWeek);
minTime = getThisWeekFirstUnixTime(); minTime = getThisWeekFirstUnixTime(firstDayOfWeek);
} else if (dateType === dateTimeConstants.allDateRanges.LastWeek.type) { // Last week } else if (dateType === dateTimeConstants.allDateRanges.LastWeek.type) { // Last week
maxTime = getUnixTimeBeforeUnixTime(getThisWeekLastUnixTime(), 7, 'days'); maxTime = getUnixTimeBeforeUnixTime(getThisWeekLastUnixTime(firstDayOfWeek), 7, 'days');
minTime = getUnixTimeBeforeUnixTime(getThisWeekFirstUnixTime(), 7, 'days'); minTime = getUnixTimeBeforeUnixTime(getThisWeekFirstUnixTime(firstDayOfWeek), 7, 'days');
} else if (dateType === dateTimeConstants.allDateRanges.ThisMonth.type) { // This month } else if (dateType === dateTimeConstants.allDateRanges.ThisMonth.type) { // This month
maxTime = getThisMonthLastUnixTime(); maxTime = getThisMonthLastUnixTime();
minTime = getThisMonthFirstUnixTime(); minTime = getThisMonthFirstUnixTime();
+17 -7
View File
@@ -6,6 +6,7 @@ export default {
}, },
'default': { 'default': {
'currency': 'USD', 'currency': 'USD',
'firstDayOfWeek': 'Sunday'
}, },
'format': { 'format': {
'date': { 'date': {
@@ -35,25 +36,32 @@ export default {
}, },
'datetime': { 'datetime': {
'Monday': { 'Monday': {
'short': 'Mon' 'short': 'Mon',
'long': 'Monday'
}, },
'Tuesday': { 'Tuesday': {
'short': 'Tue' 'short': 'Tue',
'long': 'Tuesday'
}, },
'Wednesday': { 'Wednesday': {
'short': 'Wed' 'short': 'Wed',
'long': 'Wednesday'
}, },
'Thursday': { 'Thursday': {
'short': 'Thu' 'short': 'Thu',
'long': 'Thursday'
}, },
'Friday': { 'Friday': {
'short': 'Fri' 'short': 'Fri',
'long': 'Friday'
}, },
'Saturday': { 'Saturday': {
'short': 'Sat' 'short': 'Sat',
'long': 'Saturday'
}, },
'Sunday': { 'Sunday': {
'short': 'Sun' 'short': 'Sun',
'long': 'Sunday'
}, },
'January': { 'January': {
'long': 'January' 'long': 'January'
@@ -420,6 +428,7 @@ export default {
'nickname': 'Nickname', 'nickname': 'Nickname',
'oldPassword': 'Current Password', 'oldPassword': 'Current Password',
'defaultCurrency': 'Default Currency', 'defaultCurrency': 'Default Currency',
'firstDayOfWeek': 'First Day of Week',
'name': 'Name', 'name': 'Name',
'category': 'Category', 'category': 'Category',
'type': 'Type', 'type': 'Type',
@@ -520,6 +529,7 @@ export default {
'Nickname': 'Nickname', 'Nickname': 'Nickname',
'Your nickname': 'Your nickname', 'Your nickname': 'Your nickname',
'Default Currency': 'Default Currency', 'Default Currency': 'Default Currency',
'First Day of Week': 'First Day of Week',
'Log In': 'Log In', 'Log In': 'Log In',
'Don\'t have an account?': 'Don\'t have an account?', 'Don\'t have an account?': 'Don\'t have an account?',
'Create an account': 'Create an account', 'Create an account': 'Create an account',
+17 -7
View File
@@ -6,6 +6,7 @@ export default {
}, },
'default': { 'default': {
'currency': 'CNY', 'currency': 'CNY',
'firstDayOfWeek': 'Monday'
}, },
'format': { 'format': {
'date': { 'date': {
@@ -35,25 +36,32 @@ export default {
}, },
'datetime': { 'datetime': {
'Monday': { 'Monday': {
'short': '周一' 'short': '周一',
'long': '星期一'
}, },
'Tuesday': { 'Tuesday': {
'short': '周二' 'short': '周二',
'long': '星期二'
}, },
'Wednesday': { 'Wednesday': {
'short': '周三' 'short': '周三',
'long': '星期三'
}, },
'Thursday': { 'Thursday': {
'short': '周四' 'short': '周四',
'long': '星期四'
}, },
'Friday': { 'Friday': {
'short': '周五' 'short': '周五',
'long': '星期五'
}, },
'Saturday': { 'Saturday': {
'short': '周六' 'short': '周六',
'long': '星期六'
}, },
'Sunday': { 'Sunday': {
'short': '周日' 'short': '周日',
'long': '星期日'
}, },
'January': { 'January': {
'long': '1月' 'long': '1月'
@@ -420,6 +428,7 @@ export default {
'nickname': '昵称', 'nickname': '昵称',
'oldPassword': '当前密码', 'oldPassword': '当前密码',
'defaultCurrency': '默认货币', 'defaultCurrency': '默认货币',
'firstDayOfWeek': '每周第一天',
'name': '名称', 'name': '名称',
'category': '分类', 'category': '分类',
'type': '类型', 'type': '类型',
@@ -520,6 +529,7 @@ export default {
'Nickname': '昵称', 'Nickname': '昵称',
'Your nickname': '你的昵称', 'Your nickname': '你的昵称',
'Default Currency': '默认货币', 'Default Currency': '默认货币',
'First Day of Week': '每周第一天',
'Log In': '登录', 'Log In': '登录',
'Don\'t have an account?': '还没有账号?', 'Don\'t have an account?': '还没有账号?',
'Create an account': '创建新账号', 'Create an account': '创建新账号',
+2
View File
@@ -64,6 +64,7 @@ import {
resetState, resetState,
currentUserNickname, currentUserNickname,
currentUserDefaultCurrency, currentUserDefaultCurrency,
currentUserFirstDayOfWeek,
} from './user.js'; } from './user.js';
import { import {
@@ -191,6 +192,7 @@ const stores = {
// user // user
currentUserNickname, currentUserNickname,
currentUserDefaultCurrency, currentUserDefaultCurrency,
currentUserFirstDayOfWeek,
// exchange rates // exchange rates
exchangeRatesLastUpdateDate, exchangeRatesLastUpdateDate,
+9 -2
View File
@@ -133,7 +133,8 @@ export function register(context, { user }) {
password: user.password, password: user.password,
email: user.email, email: user.email,
nickname: user.nickname, nickname: user.nickname,
defaultCurrency: user.defaultCurrency defaultCurrency: user.defaultCurrency,
firstDayOfWeek: user.firstDayOfWeek
}).then(response => { }).then(response => {
const data = response.data; const data = response.data;
@@ -234,7 +235,8 @@ export function updateUserProfile(context, { profile, currentPassword }) {
oldPassword: currentPassword, oldPassword: currentPassword,
email: profile.email, email: profile.email,
nickname: profile.nickname, nickname: profile.nickname,
defaultCurrency: profile.defaultCurrency defaultCurrency: profile.defaultCurrency,
firstDayOfWeek: profile.firstDayOfWeek
}).then(response => { }).then(response => {
const data = response.data; const data = response.data;
@@ -342,3 +344,8 @@ export function currentUserDefaultCurrency(state) {
const userInfo = state.currentUserInfo || {}; const userInfo = state.currentUserInfo || {};
return userInfo.defaultCurrency || null; return userInfo.defaultCurrency || null;
} }
export function currentUserFirstDayOfWeek(state) {
const userInfo = state.currentUserInfo || {};
return utils.isNumber(userInfo.firstDayOfWeek) ? userInfo.firstDayOfWeek : null;
}
+43 -29
View File
@@ -173,9 +173,10 @@ export default {
const self = this; const self = this;
return { return {
dateRange: self.getCurrentDateRange(),
loading: true, loading: true,
showAmountInHomePage: this.$settings.isShowAmountInHomePage() todayFirstUnixTime: self.$utilities.getTodayFirstUnixTime(),
todayLastUnixTime: self.$utilities.getTodayLastUnixTime(),
showAmountInHomePage: self.$settings.isShowAmountInHomePage()
}; };
}, },
computed: { computed: {
@@ -185,6 +186,39 @@ export default {
defaultCurrency() { defaultCurrency() {
return this.$store.getters.currentUserDefaultCurrency || this.$t('default.currency'); return this.$store.getters.currentUserDefaultCurrency || this.$t('default.currency');
}, },
firstDayOfWeek() {
if (this.$utilities.isNumber(this.$store.getters.currentUserFirstDayOfWeek)) {
return this.$store.getters.currentUserFirstDayOfWeek;
}
if (this.$constants.datetime.allWeekDays[this.$t('default.firstDayOfWeek')]) {
return this.$constants.datetime.allWeekDays[this.$t('default.firstDayOfWeek')].type;
}
return 0;
},
dateRange() {
const self = this;
return {
today: {
startTime: self.todayFirstUnixTime,
endTime: self.todayLastUnixTime
},
thisWeek: {
startTime: self.$utilities.getThisWeekFirstUnixTime(self.firstDayOfWeek),
endTime: self.$utilities.getThisWeekLastUnixTime(self.firstDayOfWeek)
},
thisMonth: {
startTime: self.$utilities.getThisMonthFirstUnixTime(),
endTime: self.$utilities.getThisMonthLastUnixTime()
},
thisYear: {
startTime: self.$utilities.getThisYearFirstUnixTime(),
endTime: self.$utilities.getThisYearLastUnixTime()
}
};
},
thisMonthAmount() { thisMonthAmount() {
if (!this.$store.state.transactionOverview || !this.$store.state.transactionOverview.thisMonth) { if (!this.$store.state.transactionOverview || !this.$store.state.transactionOverview.thisMonth) {
return { return {
@@ -221,14 +255,16 @@ export default {
onPageAfterIn() { onPageAfterIn() {
this.showAmountInHomePage = this.$settings.isShowAmountInHomePage(); this.showAmountInHomePage = this.$settings.isShowAmountInHomePage();
const newDateRange = this.getCurrentDateRange(); let dateChanged = false;
if (newDateRange.today.startTime !== this.dateRange.today.startTime || if (this.todayFirstUnixTime !== this.$utilities.getTodayFirstUnixTime()) {
newDateRange.today.endTime !== this.dateRange.today.endTime) { dateChanged = true;
this.dateRange = newDateRange;
this.todayFirstUnixTime = this.$utilities.getTodayFirstUnixTime();
this.todayLastUnixTime = this.$utilities.getTodayLastUnixTime();
} }
if (this.$store.state.transactionOverviewStateInvalid && !this.loading) { if ((dateChanged || this.$store.state.transactionOverviewStateInvalid) && !this.loading) {
this.reload(null); this.reload(null);
} }
}, },
@@ -256,28 +292,6 @@ export default {
toggleShowAmountInHomePage() { toggleShowAmountInHomePage() {
this.showAmountInHomePage = !this.showAmountInHomePage; this.showAmountInHomePage = !this.showAmountInHomePage;
this.$settings.setShowAmountInHomePage(this.showAmountInHomePage); this.$settings.setShowAmountInHomePage(this.showAmountInHomePage);
},
getCurrentDateRange() {
const self = this;
return {
today: {
startTime: self.$utilities.getTodayFirstUnixTime(),
endTime: self.$utilities.getTodayLastUnixTime()
},
thisWeek: {
startTime: self.$utilities.getThisWeekFirstUnixTime(),
endTime: self.$utilities.getThisWeekLastUnixTime()
},
thisMonth: {
startTime: self.$utilities.getThisMonthFirstUnixTime(),
endTime: self.$utilities.getThisMonthLastUnixTime()
},
thisYear: {
startTime: self.$utilities.getThisYearFirstUnixTime(),
endTime: self.$utilities.getThisYearLastUnixTime()
}
};
} }
}, },
filters: { filters: {
+17 -1
View File
@@ -92,6 +92,18 @@
:value="currency.code">{{ currency.displayName }}</option> :value="currency.code">{{ currency.displayName }}</option>
</select> </select>
</f7-list-item> </f7-list-item>
<f7-list-item
:key="currentLocale + '_firstDayOfWeek'"
:title="$t('First Day of Week')"
smart-select :smart-select-params="{ openIn: 'popup', closeOnSelect: true, popupCloseLinkText: $t('Close'), scrollToSelectedItem: true }"
>
<select v-model="user.firstDayOfWeek">
<option v-for="weekDay in allWeekDays"
:key="weekDay.type"
:value="weekDay.type">{{ `datetime.${weekDay.name}.long` | localized }}</option>
</select>
</f7-list-item>
</f7-list> </f7-list>
</f7-card-content> </f7-card-content>
</f7-card> </f7-card>
@@ -185,7 +197,8 @@ export default {
confirmPassword: '', confirmPassword: '',
email: '', email: '',
nickname: '', nickname: '',
defaultCurrency: self.$t('default.currency') defaultCurrency: self.$t('default.currency'),
firstDayOfWeek: self.$constants.datetime.allWeekDays[self.$t('default.firstDayOfWeek')] ? self.$constants.datetime.allWeekDays[self.$t('default.firstDayOfWeek')].type : 0
}, },
submitting: false, submitting: false,
presetCategories: { presetCategories: {
@@ -206,6 +219,9 @@ export default {
allCurrencies() { allCurrencies() {
return this.$locale.getAllCurrencies(); return this.$locale.getAllCurrencies();
}, },
allWeekDays() {
return this.$constants.datetime.allWeekDays;
},
currentLocale: { currentLocale: {
get: function () { get: function () {
return this.$i18n.locale; return this.$i18n.locale;
+14 -3
View File
@@ -233,6 +233,17 @@ export default {
return this.$store.getters.currentUserDefaultCurrency || this.$t('default.currency'); return this.$store.getters.currentUserDefaultCurrency || this.$t('default.currency');
}, },
firstDayOfWeek() {
if (this.$utilities.isNumber(this.$store.getters.currentUserFirstDayOfWeek)) {
return this.$store.getters.currentUserFirstDayOfWeek;
}
if (this.$constants.datetime.allWeekDays[this.$t('default.firstDayOfWeek')]) {
return this.$constants.datetime.allWeekDays[this.$t('default.firstDayOfWeek')].type;
}
return 0;
},
query() { query() {
return this.$store.state.transactionStatisticsFilter; return this.$store.state.transactionStatisticsFilter;
}, },
@@ -389,7 +400,7 @@ export default {
const self = this; const self = this;
const router = self.$f7router; const router = self.$f7router;
const dateRange = self.$utilities.getDateRangeByDateType(self.query.dateType); const dateRange = self.$utilities.getDateRangeByDateType(self.query.dateType, self.firstDayOfWeek);
self.$store.dispatch('initTransactionStatisticsFilter', { self.$store.dispatch('initTransactionStatisticsFilter', {
dateType: dateRange ? dateRange.dateType : undefined, dateType: dateRange ? dateRange.dateType : undefined,
@@ -455,7 +466,7 @@ export default {
return; return;
} }
const dateRange = this.$utilities.getDateRangeByDateType(dateType); const dateRange = this.$utilities.getDateRangeByDateType(dateType, this.firstDayOfWeek);
if (!dateRange) { if (!dateRange) {
return; return;
@@ -499,7 +510,7 @@ export default {
} }
const dateRangeType = this.$constants.datetime.allDateRanges[dateRangeField]; const dateRangeType = this.$constants.datetime.allDateRanges[dateRangeField];
const dateRange = this.$utilities.getDateRangeByDateType(dateRangeType.type); const dateRange = this.$utilities.getDateRangeByDateType(dateRangeType.type, this.firstDayOfWeek);
if (dateRange && dateRange.minTime === newDateRange.minTime && dateRange.maxTime === newDateRange.maxTime) { if (dateRange && dateRange.minTime === newDateRange.minTime && dateRange.maxTime === newDateRange.maxTime) {
newDateType = dateRangeType.type; newDateType = dateRangeType.type;
+13 -2
View File
@@ -392,6 +392,17 @@ export default {
return this.$store.getters.currentUserDefaultCurrency || this.$t('default.currency'); return this.$store.getters.currentUserDefaultCurrency || this.$t('default.currency');
}, },
firstDayOfWeek() {
if (this.$utilities.isNumber(this.$store.getters.currentUserFirstDayOfWeek)) {
return this.$store.getters.currentUserFirstDayOfWeek;
}
if (this.$constants.datetime.allWeekDays[this.$t('default.firstDayOfWeek')]) {
return this.$constants.datetime.allWeekDays[this.$t('default.firstDayOfWeek')].type;
}
return 0;
},
query() { query() {
return this.$store.state.transactionsFilter; return this.$store.state.transactionsFilter;
}, },
@@ -425,7 +436,7 @@ export default {
const self = this; const self = this;
const query = self.$f7route.query; const query = self.$f7route.query;
let dateRange = self.$utilities.getDateRangeByDateType(query.dateType ? parseInt(query.dateType) : undefined); let dateRange = self.$utilities.getDateRangeByDateType(query.dateType ? parseInt(query.dateType) : undefined, self.firstDayOfWeek);
if (!dateRange && if (!dateRange &&
query.dateType === self.$constants.datetime.allDateRanges.Custom.type.toString() && query.dateType === self.$constants.datetime.allDateRanges.Custom.type.toString() &&
@@ -535,7 +546,7 @@ export default {
return; return;
} }
const dateRange = this.$utilities.getDateRangeByDateType(dateType); const dateRange = this.$utilities.getDateRangeByDateType(dateType, this.firstDayOfWeek);
if (!dateRange) { if (!dateRange) {
return; return;
+23 -3
View File
@@ -16,6 +16,7 @@
<f7-list-input label="E-mail" placeholder="Your email address"></f7-list-input> <f7-list-input label="E-mail" placeholder="Your email address"></f7-list-input>
<f7-list-input label="Nickname" placeholder="Your nickname"></f7-list-input> <f7-list-input label="Nickname" placeholder="Your nickname"></f7-list-input>
<f7-list-item title="Default Currency" after="Currency"></f7-list-item> <f7-list-item title="Default Currency" after="Currency"></f7-list-item>
<f7-list-item title="First Day of Week" after="Week Day"></f7-list-item>
</f7-list> </f7-list>
</f7-card-content> </f7-card-content>
</f7-card> </f7-card>
@@ -74,6 +75,17 @@
</select> </select>
</f7-list-item> </f7-list-item>
<f7-list-item
:title="$t('First Day of Week')"
smart-select :smart-select-params="{ openIn: 'popup', closeOnSelect: true, popupCloseLinkText: $t('Close'), scrollToSelectedItem: true }"
>
<select autocomplete="transaction-currency" v-model="newProfile.firstDayOfWeek">
<option v-for="weekDay in allWeekDays"
:key="weekDay.type"
:value="weekDay.type">{{ `datetime.${weekDay.name}.long` | localized }}</option>
</select>
</f7-list-item>
<f7-list-item class="lab-list-item-error-info" v-if="inputIsInvalid" :footer="$t(inputInvalidProblemMessage)"></f7-list-item> <f7-list-item class="lab-list-item-error-info" v-if="inputIsInvalid" :footer="$t(inputInvalidProblemMessage)"></f7-list-item>
</f7-list> </f7-list>
</f7-card-content> </f7-card-content>
@@ -99,12 +111,14 @@ export default {
confirmPassword: '', confirmPassword: '',
email: '', email: '',
nickname: '', nickname: '',
defaultCurrency: '' defaultCurrency: '',
firstDayOfWeek: 0
}, },
oldProfile: { oldProfile: {
email: '', email: '',
nickname: '', nickname: '',
defaultCurrency: '' defaultCurrency: '',
firstDayOfWeek: 0
}, },
currentPassword: '', currentPassword: '',
loading: true, loading: true,
@@ -116,6 +130,9 @@ export default {
allCurrencies() { allCurrencies() {
return this.$locale.getAllCurrencies(); return this.$locale.getAllCurrencies();
}, },
allWeekDays() {
return this.$constants.datetime.allWeekDays;
},
inputIsNotChanged() { inputIsNotChanged() {
return !!this.inputIsNotChangedProblemMessage; return !!this.inputIsNotChangedProblemMessage;
}, },
@@ -128,7 +145,8 @@ export default {
} else if (!this.newProfile.password && !this.newProfile.confirmPassword && } else if (!this.newProfile.password && !this.newProfile.confirmPassword &&
this.newProfile.email === this.oldProfile.email && this.newProfile.email === this.oldProfile.email &&
this.newProfile.nickname === this.oldProfile.nickname && this.newProfile.nickname === this.oldProfile.nickname &&
this.newProfile.defaultCurrency === this.oldProfile.defaultCurrency) { this.newProfile.defaultCurrency === this.oldProfile.defaultCurrency &&
this.newProfile.firstDayOfWeek === this.oldProfile.firstDayOfWeek) {
return 'Nothing has been modified'; return 'Nothing has been modified';
} else if (!this.newProfile.password && this.newProfile.confirmPassword) { } else if (!this.newProfile.password && this.newProfile.confirmPassword) {
return 'Password cannot be empty'; return 'Password cannot be empty';
@@ -162,10 +180,12 @@ export default {
self.oldProfile.email = profile.email; self.oldProfile.email = profile.email;
self.oldProfile.nickname = profile.nickname; self.oldProfile.nickname = profile.nickname;
self.oldProfile.defaultCurrency = profile.defaultCurrency; self.oldProfile.defaultCurrency = profile.defaultCurrency;
self.oldProfile.firstDayOfWeek = profile.firstDayOfWeek;
self.newProfile.email = self.oldProfile.email self.newProfile.email = self.oldProfile.email
self.newProfile.nickname = self.oldProfile.nickname; self.newProfile.nickname = self.oldProfile.nickname;
self.newProfile.defaultCurrency = self.oldProfile.defaultCurrency; self.newProfile.defaultCurrency = self.oldProfile.defaultCurrency;
self.newProfile.firstDayOfWeek = self.oldProfile.firstDayOfWeek;
self.loading = false; self.loading = false;
}).catch(error => { }).catch(error => {