support custom first day of week
This commit is contained in:
@@ -50,6 +50,7 @@ func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Erro
|
||||
Nickname: userRegisterReq.Nickname,
|
||||
Password: userRegisterReq.Password,
|
||||
DefaultCurrency: userRegisterReq.DefaultCurrency,
|
||||
FirstDayOfWeek: userRegisterReq.FirstDayOfWeek,
|
||||
}
|
||||
|
||||
err = a.users.CreateUser(user)
|
||||
@@ -158,6 +159,14 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs
|
||||
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 {
|
||||
return nil, errs.ErrNothingWillBeUpdated
|
||||
}
|
||||
|
||||
+36
-14
@@ -10,6 +10,21 @@ const (
|
||||
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
|
||||
type User struct {
|
||||
Uid int64 `xorm:"PK"`
|
||||
@@ -21,6 +36,7 @@ type User struct {
|
||||
Rands string `xorm:"VARCHAR(10) NOT NULL"`
|
||||
Type UserType `xorm:"TINYINT NOT NULL"`
|
||||
DefaultCurrency string `xorm:"VARCHAR(3) NOT NULL"`
|
||||
FirstDayOfWeek WeekDay `xorm:"TINYINT NOT NULL"`
|
||||
IsAdmin bool `xorm:"NOT NULL"`
|
||||
Deleted 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
|
||||
type UserBasicInfo struct {
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Nickname string `json:"nickname"`
|
||||
DefaultCurrency string `json:"defaultCurrency"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Nickname string `json:"nickname"`
|
||||
DefaultCurrency string `json:"defaultCurrency"`
|
||||
FirstDayOfWeek WeekDay `json:"firstDayOfWeek"`
|
||||
}
|
||||
|
||||
// UserLoginRequest represents all parameters of user login request
|
||||
@@ -46,20 +63,22 @@ type UserLoginRequest struct {
|
||||
|
||||
// UserRegisterRequest represents all parameters of user registering request
|
||||
type UserRegisterRequest struct {
|
||||
Username string `json:"username" binding:"required,notBlank,max=32,validUsername"`
|
||||
Email string `json:"email" binding:"required,notBlank,max=100,validEmail"`
|
||||
Nickname string `json:"nickname" binding:"required,notBlank,max=64"`
|
||||
Password string `json:"password" binding:"required,min=6,max=128"`
|
||||
DefaultCurrency string `json:"defaultCurrency" binding:"required,len=3,validCurrency"`
|
||||
Username string `json:"username" binding:"required,notBlank,max=32,validUsername"`
|
||||
Email string `json:"email" binding:"required,notBlank,max=100,validEmail"`
|
||||
Nickname string `json:"nickname" binding:"required,notBlank,max=64"`
|
||||
Password string `json:"password" binding:"required,min=6,max=128"`
|
||||
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
|
||||
type UserProfileUpdateRequest struct {
|
||||
Email string `json:"email" binding:"omitempty,notBlank,max=100,validEmail"`
|
||||
Nickname string `json:"nickname" binding:"omitempty,notBlank,max=64"`
|
||||
Password string `json:"password" 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"`
|
||||
Email string `json:"email" binding:"omitempty,notBlank,max=100,validEmail"`
|
||||
Nickname string `json:"nickname" binding:"omitempty,notBlank,max=64"`
|
||||
Password string `json:"password" binding:"omitempty,min=6,max=128"`
|
||||
OldPassword string `json:"oldPassword" binding:"omitempty,min=6,max=128"`
|
||||
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
|
||||
@@ -75,6 +94,7 @@ type UserProfileResponse struct {
|
||||
Nickname string `json:"nickname"`
|
||||
Type UserType `json:"type"`
|
||||
DefaultCurrency string `json:"defaultCurrency"`
|
||||
FirstDayOfWeek WeekDay `json:"firstDayOfWeek"`
|
||||
LastLoginAt int64 `json:"lastLoginAt"`
|
||||
}
|
||||
|
||||
@@ -85,6 +105,7 @@ func (u User) ToUserBasicInfo() *UserBasicInfo {
|
||||
Email: u.Email,
|
||||
Nickname: u.Nickname,
|
||||
DefaultCurrency: u.DefaultCurrency,
|
||||
FirstDayOfWeek: u.FirstDayOfWeek,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +117,7 @@ func (u User) ToUserProfileResponse() *UserProfileResponse {
|
||||
Nickname: u.Nickname,
|
||||
Type: u.Type,
|
||||
DefaultCurrency: u.DefaultCurrency,
|
||||
FirstDayOfWeek: u.FirstDayOfWeek,
|
||||
LastLoginAt: u.LastLoginUnixTime,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +194,10 @@ func (s *UserService) UpdateUser(user *models.User) (keyProfileUpdated bool, err
|
||||
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
|
||||
updateCols = append(updateCols, "updated_unix_time")
|
||||
|
||||
|
||||
@@ -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 = {
|
||||
All: {
|
||||
type: 0,
|
||||
@@ -50,5 +81,6 @@ const allDateRanges = {
|
||||
};
|
||||
|
||||
export default {
|
||||
allWeekDays: allWeekDays,
|
||||
allDateRanges: allDateRanges,
|
||||
};
|
||||
|
||||
+6
-4
@@ -81,13 +81,14 @@ export default {
|
||||
}
|
||||
});
|
||||
},
|
||||
register: ({ username, email, nickname, password, defaultCurrency }) => {
|
||||
register: ({ username, email, nickname, password, defaultCurrency, firstDayOfWeek }) => {
|
||||
return axios.post('register.json', {
|
||||
username,
|
||||
email,
|
||||
nickname,
|
||||
password,
|
||||
defaultCurrency
|
||||
defaultCurrency,
|
||||
firstDayOfWeek
|
||||
});
|
||||
},
|
||||
logout: () => {
|
||||
@@ -128,13 +129,14 @@ export default {
|
||||
getProfile: () => {
|
||||
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', {
|
||||
email,
|
||||
nickname,
|
||||
password,
|
||||
oldPassword,
|
||||
defaultCurrency
|
||||
defaultCurrency,
|
||||
firstDayOfWeek
|
||||
});
|
||||
},
|
||||
get2FAStatus: () => {
|
||||
|
||||
+20
-9
@@ -110,13 +110,24 @@ function getTodayLastUnixTime() {
|
||||
return moment.unix(getTodayFirstUnixTime()).add(1, 'days').subtract(1, 'seconds').unix();
|
||||
}
|
||||
|
||||
function getThisWeekFirstUnixTime() {
|
||||
function getThisWeekFirstUnixTime(firstDayOfWeek) {
|
||||
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() {
|
||||
return moment.unix(getThisWeekFirstUnixTime()).add(7, 'days').subtract(1, 'seconds').unix();
|
||||
function getThisWeekLastUnixTime(firstDayOfWeek) {
|
||||
return moment.unix(getThisWeekFirstUnixTime(firstDayOfWeek)).add(7, 'days').subtract(1, 'seconds').unix();
|
||||
}
|
||||
|
||||
function getThisMonthFirstUnixTime() {
|
||||
@@ -163,7 +174,7 @@ function getShiftedDateRange(minTime, maxTime, scale) {
|
||||
};
|
||||
}
|
||||
|
||||
function getDateRangeByDateType(dateType) {
|
||||
function getDateRangeByDateType(dateType, firstDayOfWeek) {
|
||||
let maxTime = 0;
|
||||
let minTime = 0;
|
||||
|
||||
@@ -183,11 +194,11 @@ function getDateRangeByDateType(dateType) {
|
||||
maxTime = getUnixTimeBeforeUnixTime(getTodayLastUnixTime(), 1, 'days');
|
||||
minTime = getUnixTimeBeforeUnixTime(getTodayFirstUnixTime(), 29, 'days');
|
||||
} else if (dateType === dateTimeConstants.allDateRanges.ThisWeek.type) { // This week
|
||||
maxTime = getThisWeekLastUnixTime();
|
||||
minTime = getThisWeekFirstUnixTime();
|
||||
maxTime = getThisWeekLastUnixTime(firstDayOfWeek);
|
||||
minTime = getThisWeekFirstUnixTime(firstDayOfWeek);
|
||||
} else if (dateType === dateTimeConstants.allDateRanges.LastWeek.type) { // Last week
|
||||
maxTime = getUnixTimeBeforeUnixTime(getThisWeekLastUnixTime(), 7, 'days');
|
||||
minTime = getUnixTimeBeforeUnixTime(getThisWeekFirstUnixTime(), 7, 'days');
|
||||
maxTime = getUnixTimeBeforeUnixTime(getThisWeekLastUnixTime(firstDayOfWeek), 7, 'days');
|
||||
minTime = getUnixTimeBeforeUnixTime(getThisWeekFirstUnixTime(firstDayOfWeek), 7, 'days');
|
||||
} else if (dateType === dateTimeConstants.allDateRanges.ThisMonth.type) { // This month
|
||||
maxTime = getThisMonthLastUnixTime();
|
||||
minTime = getThisMonthFirstUnixTime();
|
||||
|
||||
+17
-7
@@ -6,6 +6,7 @@ export default {
|
||||
},
|
||||
'default': {
|
||||
'currency': 'USD',
|
||||
'firstDayOfWeek': 'Sunday'
|
||||
},
|
||||
'format': {
|
||||
'date': {
|
||||
@@ -35,25 +36,32 @@ export default {
|
||||
},
|
||||
'datetime': {
|
||||
'Monday': {
|
||||
'short': 'Mon'
|
||||
'short': 'Mon',
|
||||
'long': 'Monday'
|
||||
},
|
||||
'Tuesday': {
|
||||
'short': 'Tue'
|
||||
'short': 'Tue',
|
||||
'long': 'Tuesday'
|
||||
},
|
||||
'Wednesday': {
|
||||
'short': 'Wed'
|
||||
'short': 'Wed',
|
||||
'long': 'Wednesday'
|
||||
},
|
||||
'Thursday': {
|
||||
'short': 'Thu'
|
||||
'short': 'Thu',
|
||||
'long': 'Thursday'
|
||||
},
|
||||
'Friday': {
|
||||
'short': 'Fri'
|
||||
'short': 'Fri',
|
||||
'long': 'Friday'
|
||||
},
|
||||
'Saturday': {
|
||||
'short': 'Sat'
|
||||
'short': 'Sat',
|
||||
'long': 'Saturday'
|
||||
},
|
||||
'Sunday': {
|
||||
'short': 'Sun'
|
||||
'short': 'Sun',
|
||||
'long': 'Sunday'
|
||||
},
|
||||
'January': {
|
||||
'long': 'January'
|
||||
@@ -420,6 +428,7 @@ export default {
|
||||
'nickname': 'Nickname',
|
||||
'oldPassword': 'Current Password',
|
||||
'defaultCurrency': 'Default Currency',
|
||||
'firstDayOfWeek': 'First Day of Week',
|
||||
'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': 'First Day of Week',
|
||||
'Log In': 'Log In',
|
||||
'Don\'t have an account?': 'Don\'t have an account?',
|
||||
'Create an account': 'Create an account',
|
||||
|
||||
+17
-7
@@ -6,6 +6,7 @@ export default {
|
||||
},
|
||||
'default': {
|
||||
'currency': 'CNY',
|
||||
'firstDayOfWeek': 'Monday'
|
||||
},
|
||||
'format': {
|
||||
'date': {
|
||||
@@ -35,25 +36,32 @@ export default {
|
||||
},
|
||||
'datetime': {
|
||||
'Monday': {
|
||||
'short': '周一'
|
||||
'short': '周一',
|
||||
'long': '星期一'
|
||||
},
|
||||
'Tuesday': {
|
||||
'short': '周二'
|
||||
'short': '周二',
|
||||
'long': '星期二'
|
||||
},
|
||||
'Wednesday': {
|
||||
'short': '周三'
|
||||
'short': '周三',
|
||||
'long': '星期三'
|
||||
},
|
||||
'Thursday': {
|
||||
'short': '周四'
|
||||
'short': '周四',
|
||||
'long': '星期四'
|
||||
},
|
||||
'Friday': {
|
||||
'short': '周五'
|
||||
'short': '周五',
|
||||
'long': '星期五'
|
||||
},
|
||||
'Saturday': {
|
||||
'short': '周六'
|
||||
'short': '周六',
|
||||
'long': '星期六'
|
||||
},
|
||||
'Sunday': {
|
||||
'short': '周日'
|
||||
'short': '周日',
|
||||
'long': '星期日'
|
||||
},
|
||||
'January': {
|
||||
'long': '1月'
|
||||
@@ -420,6 +428,7 @@ export default {
|
||||
'nickname': '昵称',
|
||||
'oldPassword': '当前密码',
|
||||
'defaultCurrency': '默认货币',
|
||||
'firstDayOfWeek': '每周第一天',
|
||||
'name': '名称',
|
||||
'category': '分类',
|
||||
'type': '类型',
|
||||
@@ -520,6 +529,7 @@ export default {
|
||||
'Nickname': '昵称',
|
||||
'Your nickname': '你的昵称',
|
||||
'Default Currency': '默认货币',
|
||||
'First Day of Week': '每周第一天',
|
||||
'Log In': '登录',
|
||||
'Don\'t have an account?': '还没有账号?',
|
||||
'Create an account': '创建新账号',
|
||||
|
||||
@@ -64,6 +64,7 @@ import {
|
||||
resetState,
|
||||
currentUserNickname,
|
||||
currentUserDefaultCurrency,
|
||||
currentUserFirstDayOfWeek,
|
||||
} from './user.js';
|
||||
|
||||
import {
|
||||
@@ -191,6 +192,7 @@ const stores = {
|
||||
// user
|
||||
currentUserNickname,
|
||||
currentUserDefaultCurrency,
|
||||
currentUserFirstDayOfWeek,
|
||||
|
||||
// exchange rates
|
||||
exchangeRatesLastUpdateDate,
|
||||
|
||||
+9
-2
@@ -133,7 +133,8 @@ export function register(context, { user }) {
|
||||
password: user.password,
|
||||
email: user.email,
|
||||
nickname: user.nickname,
|
||||
defaultCurrency: user.defaultCurrency
|
||||
defaultCurrency: user.defaultCurrency,
|
||||
firstDayOfWeek: user.firstDayOfWeek
|
||||
}).then(response => {
|
||||
const data = response.data;
|
||||
|
||||
@@ -234,7 +235,8 @@ export function updateUserProfile(context, { profile, currentPassword }) {
|
||||
oldPassword: currentPassword,
|
||||
email: profile.email,
|
||||
nickname: profile.nickname,
|
||||
defaultCurrency: profile.defaultCurrency
|
||||
defaultCurrency: profile.defaultCurrency,
|
||||
firstDayOfWeek: profile.firstDayOfWeek
|
||||
}).then(response => {
|
||||
const data = response.data;
|
||||
|
||||
@@ -342,3 +344,8 @@ export function currentUserDefaultCurrency(state) {
|
||||
const userInfo = state.currentUserInfo || {};
|
||||
return userInfo.defaultCurrency || null;
|
||||
}
|
||||
|
||||
export function currentUserFirstDayOfWeek(state) {
|
||||
const userInfo = state.currentUserInfo || {};
|
||||
return utils.isNumber(userInfo.firstDayOfWeek) ? userInfo.firstDayOfWeek : null;
|
||||
}
|
||||
|
||||
+43
-29
@@ -173,9 +173,10 @@ export default {
|
||||
const self = this;
|
||||
|
||||
return {
|
||||
dateRange: self.getCurrentDateRange(),
|
||||
loading: true,
|
||||
showAmountInHomePage: this.$settings.isShowAmountInHomePage()
|
||||
todayFirstUnixTime: self.$utilities.getTodayFirstUnixTime(),
|
||||
todayLastUnixTime: self.$utilities.getTodayLastUnixTime(),
|
||||
showAmountInHomePage: self.$settings.isShowAmountInHomePage()
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -185,6 +186,39 @@ export default {
|
||||
defaultCurrency() {
|
||||
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() {
|
||||
if (!this.$store.state.transactionOverview || !this.$store.state.transactionOverview.thisMonth) {
|
||||
return {
|
||||
@@ -221,14 +255,16 @@ export default {
|
||||
onPageAfterIn() {
|
||||
this.showAmountInHomePage = this.$settings.isShowAmountInHomePage();
|
||||
|
||||
const newDateRange = this.getCurrentDateRange();
|
||||
let dateChanged = false;
|
||||
|
||||
if (newDateRange.today.startTime !== this.dateRange.today.startTime ||
|
||||
newDateRange.today.endTime !== this.dateRange.today.endTime) {
|
||||
this.dateRange = newDateRange;
|
||||
if (this.todayFirstUnixTime !== this.$utilities.getTodayFirstUnixTime()) {
|
||||
dateChanged = true;
|
||||
|
||||
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);
|
||||
}
|
||||
},
|
||||
@@ -256,28 +292,6 @@ export default {
|
||||
toggleShowAmountInHomePage() {
|
||||
this.showAmountInHomePage = !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: {
|
||||
|
||||
@@ -92,6 +92,18 @@
|
||||
:value="currency.code">{{ currency.displayName }}</option>
|
||||
</select>
|
||||
</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-card-content>
|
||||
</f7-card>
|
||||
@@ -185,7 +197,8 @@ export default {
|
||||
confirmPassword: '',
|
||||
email: '',
|
||||
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,
|
||||
presetCategories: {
|
||||
@@ -206,6 +219,9 @@ export default {
|
||||
allCurrencies() {
|
||||
return this.$locale.getAllCurrencies();
|
||||
},
|
||||
allWeekDays() {
|
||||
return this.$constants.datetime.allWeekDays;
|
||||
},
|
||||
currentLocale: {
|
||||
get: function () {
|
||||
return this.$i18n.locale;
|
||||
|
||||
@@ -233,6 +233,17 @@ export default {
|
||||
|
||||
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() {
|
||||
return this.$store.state.transactionStatisticsFilter;
|
||||
},
|
||||
@@ -389,7 +400,7 @@ export default {
|
||||
const self = this;
|
||||
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', {
|
||||
dateType: dateRange ? dateRange.dateType : undefined,
|
||||
@@ -455,7 +466,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
const dateRange = this.$utilities.getDateRangeByDateType(dateType);
|
||||
const dateRange = this.$utilities.getDateRangeByDateType(dateType, this.firstDayOfWeek);
|
||||
|
||||
if (!dateRange) {
|
||||
return;
|
||||
@@ -499,7 +510,7 @@ export default {
|
||||
}
|
||||
|
||||
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) {
|
||||
newDateType = dateRangeType.type;
|
||||
|
||||
@@ -392,6 +392,17 @@ export default {
|
||||
|
||||
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() {
|
||||
return this.$store.state.transactionsFilter;
|
||||
},
|
||||
@@ -425,7 +436,7 @@ export default {
|
||||
const self = this;
|
||||
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 &&
|
||||
query.dateType === self.$constants.datetime.allDateRanges.Custom.type.toString() &&
|
||||
@@ -535,7 +546,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
const dateRange = this.$utilities.getDateRangeByDateType(dateType);
|
||||
const dateRange = this.$utilities.getDateRangeByDateType(dateType, this.firstDayOfWeek);
|
||||
|
||||
if (!dateRange) {
|
||||
return;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<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-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-card-content>
|
||||
</f7-card>
|
||||
@@ -74,6 +75,17 @@
|
||||
</select>
|
||||
</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>
|
||||
</f7-card-content>
|
||||
@@ -99,12 +111,14 @@ export default {
|
||||
confirmPassword: '',
|
||||
email: '',
|
||||
nickname: '',
|
||||
defaultCurrency: ''
|
||||
defaultCurrency: '',
|
||||
firstDayOfWeek: 0
|
||||
},
|
||||
oldProfile: {
|
||||
email: '',
|
||||
nickname: '',
|
||||
defaultCurrency: ''
|
||||
defaultCurrency: '',
|
||||
firstDayOfWeek: 0
|
||||
},
|
||||
currentPassword: '',
|
||||
loading: true,
|
||||
@@ -116,6 +130,9 @@ export default {
|
||||
allCurrencies() {
|
||||
return this.$locale.getAllCurrencies();
|
||||
},
|
||||
allWeekDays() {
|
||||
return this.$constants.datetime.allWeekDays;
|
||||
},
|
||||
inputIsNotChanged() {
|
||||
return !!this.inputIsNotChangedProblemMessage;
|
||||
},
|
||||
@@ -128,7 +145,8 @@ export default {
|
||||
} else if (!this.newProfile.password && !this.newProfile.confirmPassword &&
|
||||
this.newProfile.email === this.oldProfile.email &&
|
||||
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';
|
||||
} else if (!this.newProfile.password && this.newProfile.confirmPassword) {
|
||||
return 'Password cannot be empty';
|
||||
@@ -162,10 +180,12 @@ export default {
|
||||
self.oldProfile.email = profile.email;
|
||||
self.oldProfile.nickname = profile.nickname;
|
||||
self.oldProfile.defaultCurrency = profile.defaultCurrency;
|
||||
self.oldProfile.firstDayOfWeek = profile.firstDayOfWeek;
|
||||
|
||||
self.newProfile.email = self.oldProfile.email
|
||||
self.newProfile.nickname = self.oldProfile.nickname;
|
||||
self.newProfile.defaultCurrency = self.oldProfile.defaultCurrency;
|
||||
self.newProfile.firstDayOfWeek = self.oldProfile.firstDayOfWeek;
|
||||
|
||||
self.loading = false;
|
||||
}).catch(error => {
|
||||
|
||||
Reference in New Issue
Block a user