support hide/unhide account
This commit is contained in:
@@ -161,6 +161,7 @@ func startWebServer(c *cli.Context) error {
|
||||
// Accounts
|
||||
apiV1Route.GET("/accounts/list.json", bindApi(api.Accounts.AccountListHandler))
|
||||
apiV1Route.POST("/accounts/add.json", bindApi(api.Accounts.AccountCreateHandler))
|
||||
apiV1Route.POST("/accounts/hide.json", bindApi(api.Accounts.AccountHideHandler))
|
||||
apiV1Route.POST("/accounts/move.json", bindApi(api.Accounts.AccountMoveHandler))
|
||||
apiV1Route.POST("/accounts/delete.json", bindApi(api.Accounts.AccountDeleteHandler))
|
||||
}
|
||||
|
||||
+23
-2
@@ -124,6 +124,27 @@ func (a *AccountsApi) AccountCreateHandler(c *core.Context) (interface{}, *errs.
|
||||
return accountInfoResp, nil
|
||||
}
|
||||
|
||||
func (a *AccountsApi) AccountHideHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var accountHideReq models.AccountHideRequest
|
||||
err := c.ShouldBindJSON(&accountHideReq)
|
||||
|
||||
if err != nil {
|
||||
log.WarnfWithRequestId(c, "[accounts.AccountHideHandler] parse request failed, because %s", err.Error())
|
||||
return nil, errs.NewIncompleteOrIncorrectSubmissionError(err)
|
||||
}
|
||||
|
||||
uid := c.GetCurrentUid()
|
||||
err = a.accounts.HideAccount(uid, []int64{accountHideReq.Id}, accountHideReq.Hidden)
|
||||
|
||||
if err != nil {
|
||||
log.ErrorfWithRequestId(c, "[accounts.AccountHideHandler] failed to hide account \"id:%d\" for user \"uid:%d\", because %s", accountHideReq.Id, uid, err.Error())
|
||||
return nil, errs.Or(err, errs.ErrOperationFailed)
|
||||
}
|
||||
|
||||
log.InfofWithRequestId(c, "[accounts.AccountHideHandler] user \"uid:%d\" has hidden account \"id:%d\"", uid, accountHideReq.Id)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (a *AccountsApi) AccountMoveHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var accountMoveReq models.AccountMoveRequest
|
||||
err := c.ShouldBindJSON(&accountMoveReq)
|
||||
@@ -171,11 +192,11 @@ func (a *AccountsApi) AccountDeleteHandler(c *core.Context) (interface{}, *errs.
|
||||
err = a.accounts.DeleteAccounts(uid, []int64{accountDeleteReq.Id})
|
||||
|
||||
if err != nil {
|
||||
log.ErrorfWithRequestId(c, "[accounts.AccountDeleteHandler] failed to delete account \"id:%s\" for user \"uid:%d\", because %s", accountDeleteReq.Id, uid, err.Error())
|
||||
log.ErrorfWithRequestId(c, "[accounts.AccountDeleteHandler] failed to delete account \"id:%d\" for user \"uid:%d\", because %s", accountDeleteReq.Id, uid, err.Error())
|
||||
return nil, errs.Or(err, errs.ErrOperationFailed)
|
||||
}
|
||||
|
||||
log.InfofWithRequestId(c, "[accounts.AccountDeleteHandler] user \"uid:%d\" has deleted account \"id:%s\"", uid, accountDeleteReq.Id)
|
||||
log.InfofWithRequestId(c, "[accounts.AccountDeleteHandler] user \"uid:%d\" has deleted account \"id:%d\"", uid, accountDeleteReq.Id)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,11 @@ type AccountCreateRequest struct {
|
||||
SubAccounts []*AccountCreateRequest `json:"subAccounts" binding:"omitempty"`
|
||||
}
|
||||
|
||||
type AccountHideRequest struct {
|
||||
Id int64 `json:"id,string" binding:"required,min=1"`
|
||||
Hidden bool `json:"hidden"`
|
||||
}
|
||||
|
||||
type AccountMoveRequest struct {
|
||||
NewDisplayOrders []*AccountNewDisplayOrderRequest `json:"newDisplayOrders"`
|
||||
}
|
||||
|
||||
@@ -122,6 +122,29 @@ func (s *AccountService) CreateAccounts(mainAccount *models.Account, childrenAcc
|
||||
})
|
||||
}
|
||||
|
||||
func (s *AccountService) HideAccount(uid int64, ids []int64, hidden bool) error {
|
||||
if uid <= 0 {
|
||||
return errs.ErrUserIdInvalid
|
||||
}
|
||||
|
||||
now := time.Now().Unix()
|
||||
|
||||
updateModel := &models.Account{
|
||||
Hidden: hidden,
|
||||
UpdatedUnixTime: now,
|
||||
}
|
||||
|
||||
return s.UserDataDB(uid).DoTransaction(func(sess *xorm.Session) error {
|
||||
deletedRows, err := sess.Cols("hidden", "updated_unix_time").In("account_id", ids).Where("uid=? AND deleted=?", uid, false).Update(updateModel)
|
||||
|
||||
if deletedRows < 1 {
|
||||
return errs.ErrAccountNotFound
|
||||
}
|
||||
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func (s *AccountService) ModifyAccountDisplayOrders(uid int64, accounts []*models.Account) error {
|
||||
if uid <= 0 {
|
||||
return errs.ErrUserIdInvalid
|
||||
|
||||
@@ -174,6 +174,12 @@ export default {
|
||||
subAccounts
|
||||
});
|
||||
},
|
||||
hideAccount: ({ id, hidden }) => {
|
||||
return axios.post('v1/accounts/hide.json', {
|
||||
id,
|
||||
hidden
|
||||
});
|
||||
},
|
||||
moveAccount: ({ newDisplayOrders }) => {
|
||||
return axios.post('v1/accounts/move.json', {
|
||||
newDisplayOrders,
|
||||
|
||||
@@ -324,6 +324,8 @@ export default {
|
||||
'Account currency cannot be empty': 'Account currency cannot be empty',
|
||||
'You have added a new account': 'You have added a new account',
|
||||
'Unable to add account': 'Unable to add account',
|
||||
'Unable to hide this account': 'Unable to hide this account',
|
||||
'Unable to unhide this account': 'Unable to unhide this account',
|
||||
'Unable to move account': 'Unable to move account',
|
||||
'Are you sure you want to delete this account?': 'Are you sure you want to delete this account?',
|
||||
'Unable to delete this account': 'Unable to delete this account',
|
||||
|
||||
@@ -324,6 +324,8 @@ export default {
|
||||
'Account currency cannot be empty': '账户货币不能为空',
|
||||
'You have added a new account': '您已经添加新账户',
|
||||
'Unable to add account': '无法添加账户',
|
||||
'Unable to hide this account': '无法隐藏账户',
|
||||
'Unable to unhide this account': '无法取消隐藏账户',
|
||||
'Unable to move account': '无法移动账户',
|
||||
'Are you sure you want to delete this account?': '您确定要删除该账户吗?',
|
||||
'Unable to delete this account': '无法删除该账户',
|
||||
|
||||
@@ -55,7 +55,12 @@
|
||||
:title="account.name" :after="account.balance | currency(account.currency)"
|
||||
link="#" swipeout @taphold.native="setSortable()"
|
||||
>
|
||||
<f7-swipeout-actions right>
|
||||
<f7-swipeout-actions left v-if="sortable">
|
||||
<f7-swipeout-button :color="account.hidden ? 'blue' : 'gray'" class="padding-left padding-right" @click="hide(account, !account.hidden)">
|
||||
<f7-icon :f7="account.hidden ? 'eye' : 'eye_slash'"></f7-icon>
|
||||
</f7-swipeout-button>
|
||||
</f7-swipeout-actions>
|
||||
<f7-swipeout-actions right v-if="!sortable">
|
||||
<f7-swipeout-button color="orange" :text="$t('Edit')" @click="edit(account)"></f7-swipeout-button>
|
||||
<f7-swipeout-button color="red" class="padding-left padding-right" @click="remove(account)">
|
||||
<f7-icon f7="trash"></f7-icon>
|
||||
@@ -278,6 +283,43 @@ export default {
|
||||
},
|
||||
edit() {
|
||||
|
||||
},
|
||||
hide(account, hidden) {
|
||||
const self = this;
|
||||
|
||||
self.$showLoading();
|
||||
|
||||
self.$services.hideAccount({
|
||||
id: account.id,
|
||||
hidden: hidden
|
||||
}).then(response => {
|
||||
self.$hideLoading();
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
if (hidden) {
|
||||
self.$toast('Unable to hide this account');
|
||||
} else {
|
||||
self.$toast('Unable to unhide this account');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
account.hidden = hidden;
|
||||
}).catch(error => {
|
||||
self.$hideLoading();
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
} else if (!error.processed) {
|
||||
if (hidden) {
|
||||
self.$toast('Unable to hide this account');
|
||||
} else {
|
||||
self.$toast('Unable to unhide this account');
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
remove(account) {
|
||||
const self = this;
|
||||
|
||||
Reference in New Issue
Block a user