create transaction template and modify template name in edit dialog

This commit is contained in:
MaysWind
2024-07-31 23:59:37 +08:00
parent b0b330903c
commit a03df7ed36
12 changed files with 236 additions and 366 deletions
-1
View File
@@ -324,7 +324,6 @@ func startWebServer(c *cli.Context) error {
apiV1Route.GET("/transaction/templates/list.json", bindApi(api.TransactionTemplates.TemplateListHandler)) apiV1Route.GET("/transaction/templates/list.json", bindApi(api.TransactionTemplates.TemplateListHandler))
apiV1Route.GET("/transaction/templates/get.json", bindApi(api.TransactionTemplates.TemplateGetHandler)) apiV1Route.GET("/transaction/templates/get.json", bindApi(api.TransactionTemplates.TemplateGetHandler))
apiV1Route.POST("/transaction/templates/add.json", bindApi(api.TransactionTemplates.TemplateCreateHandler)) apiV1Route.POST("/transaction/templates/add.json", bindApi(api.TransactionTemplates.TemplateCreateHandler))
apiV1Route.POST("/transaction/templates/modify_name.json", bindApi(api.TransactionTemplates.TemplateModifyNameHandler))
apiV1Route.POST("/transaction/templates/modify.json", bindApi(api.TransactionTemplates.TemplateModifyHandler)) apiV1Route.POST("/transaction/templates/modify.json", bindApi(api.TransactionTemplates.TemplateModifyHandler))
apiV1Route.POST("/transaction/templates/hide.json", bindApi(api.TransactionTemplates.TemplateHideHandler)) apiV1Route.POST("/transaction/templates/hide.json", bindApi(api.TransactionTemplates.TemplateHideHandler))
apiV1Route.POST("/transaction/templates/move.json", bindApi(api.TransactionTemplates.TemplateMoveHandler)) apiV1Route.POST("/transaction/templates/move.json", bindApi(api.TransactionTemplates.TemplateMoveHandler))
+37 -51
View File
@@ -36,6 +36,11 @@ func (a *TransactionTemplatesApi) TemplateListHandler(c *core.Context) (any, *er
return nil, errs.NewIncompleteOrIncorrectSubmissionError(err) return nil, errs.NewIncompleteOrIncorrectSubmissionError(err)
} }
if templateListReq.TemplateType < models.TRANSACTION_TEMPLATE_TYPE_NORMAL || templateListReq.TemplateType > models.TRANSACTION_TEMPLATE_TYPE_NORMAL {
log.WarnfWithRequestId(c, "[transaction_templates.TemplateListHandler] template type invalid, type is %d", templateListReq.TemplateType)
return nil, errs.ErrTransactionTemplateTypeInvalid
}
uid := c.GetCurrentUid() uid := c.GetCurrentUid()
templates, err := a.templates.GetAllTemplatesByUid(c, uid, templateListReq.TemplateType) templates, err := a.templates.GetAllTemplatesByUid(c, uid, templateListReq.TemplateType)
@@ -90,6 +95,16 @@ func (a *TransactionTemplatesApi) TemplateCreateHandler(c *core.Context) (any, *
return nil, errs.NewIncompleteOrIncorrectSubmissionError(err) return nil, errs.NewIncompleteOrIncorrectSubmissionError(err)
} }
if templateCreateReq.TemplateType < models.TRANSACTION_TEMPLATE_TYPE_NORMAL || templateCreateReq.TemplateType > models.TRANSACTION_TEMPLATE_TYPE_NORMAL {
log.WarnfWithRequestId(c, "[transaction_templates.TemplateCreateHandler] template type invalid, type is %d", templateCreateReq.TemplateType)
return nil, errs.ErrTransactionTemplateTypeInvalid
}
if templateCreateReq.Type <= models.TRANSACTION_TYPE_MODIFY_BALANCE || templateCreateReq.Type > models.TRANSACTION_TYPE_TRANSFER {
log.WarnfWithRequestId(c, "[transaction_templates.TemplateCreateHandler] transaction type invalid, type is %d", templateCreateReq.Type)
return nil, errs.ErrTransactionTypeInvalid
}
uid := c.GetCurrentUid() uid := c.GetCurrentUid()
maxOrderId, err := a.templates.GetMaxDisplayOrder(c, uid, templateCreateReq.TemplateType) maxOrderId, err := a.templates.GetMaxDisplayOrder(c, uid, templateCreateReq.TemplateType)
@@ -139,50 +154,6 @@ func (a *TransactionTemplatesApi) TemplateCreateHandler(c *core.Context) (any, *
return templateResp, nil return templateResp, nil
} }
// TemplateModifyNameHandler updates the name of an existed transaction template by request parameters for current user
func (a *TransactionTemplatesApi) TemplateModifyNameHandler(c *core.Context) (any, *errs.Error) {
var templateModifyReq models.TransactionTemplateModifyNameRequest
err := c.ShouldBindJSON(&templateModifyReq)
if err != nil {
log.WarnfWithRequestId(c, "[transaction_templates.TemplateModifyNameHandler] parse request failed, because %s", err.Error())
return nil, errs.NewIncompleteOrIncorrectSubmissionError(err)
}
uid := c.GetCurrentUid()
template, err := a.templates.GetTemplateByTemplateId(c, uid, templateModifyReq.Id)
if err != nil {
log.ErrorfWithRequestId(c, "[transaction_templates.TemplateModifyNameHandler] failed to get template \"id:%d\" for user \"uid:%d\", because %s", templateModifyReq.Id, uid, err.Error())
return nil, errs.Or(err, errs.ErrOperationFailed)
}
if templateModifyReq.Name == template.Name {
return nil, errs.ErrNothingWillBeUpdated
}
newTemplate := &models.TransactionTemplate{
TemplateId: template.TemplateId,
Uid: template.Uid,
Name: templateModifyReq.Name,
}
err = a.templates.ModifyTemplateName(c, newTemplate)
if err != nil {
log.ErrorfWithRequestId(c, "[transaction_templates.TemplateModifyNameHandler] failed to update template \"id:%d\" for user \"uid:%d\", because %s", templateModifyReq.Id, uid, err.Error())
return nil, errs.Or(err, errs.ErrOperationFailed)
}
log.InfofWithRequestId(c, "[transaction_templates.TemplateModifyNameHandler] user \"uid:%d\" has updated template \"id:%d\" successfully", uid, templateModifyReq.Id)
serverUtcOffset := utils.GetServerTimezoneOffsetMinutes()
template.Name = newTemplate.Name
templateResp := template.ToTransactionTemplateInfoResponse(serverUtcOffset)
return templateResp, nil
}
// TemplateModifyHandler saves an existed transaction template by request parameters for current user // TemplateModifyHandler saves an existed transaction template by request parameters for current user
func (a *TransactionTemplatesApi) TemplateModifyHandler(c *core.Context) (any, *errs.Error) { func (a *TransactionTemplatesApi) TemplateModifyHandler(c *core.Context) (any, *errs.Error) {
var templateModifyReq models.TransactionTemplateModifyRequest var templateModifyReq models.TransactionTemplateModifyRequest
@@ -193,6 +164,11 @@ func (a *TransactionTemplatesApi) TemplateModifyHandler(c *core.Context) (any, *
return nil, errs.NewIncompleteOrIncorrectSubmissionError(err) return nil, errs.NewIncompleteOrIncorrectSubmissionError(err)
} }
if templateModifyReq.Type <= models.TRANSACTION_TYPE_MODIFY_BALANCE || templateModifyReq.Type > models.TRANSACTION_TYPE_TRANSFER {
log.WarnfWithRequestId(c, "[transaction_templates.TemplateModifyHandler] transaction type invalid, type is %d", templateModifyReq.Type)
return nil, errs.ErrTransactionTypeInvalid
}
uid := c.GetCurrentUid() uid := c.GetCurrentUid()
template, err := a.templates.GetTemplateByTemplateId(c, uid, templateModifyReq.Id) template, err := a.templates.GetTemplateByTemplateId(c, uid, templateModifyReq.Id)
@@ -204,6 +180,7 @@ func (a *TransactionTemplatesApi) TemplateModifyHandler(c *core.Context) (any, *
newTemplate := &models.TransactionTemplate{ newTemplate := &models.TransactionTemplate{
TemplateId: template.TemplateId, TemplateId: template.TemplateId,
Uid: uid, Uid: uid,
Name: templateModifyReq.Name,
Type: templateModifyReq.Type, Type: templateModifyReq.Type,
CategoryId: templateModifyReq.CategoryId, CategoryId: templateModifyReq.CategoryId,
AccountId: templateModifyReq.SourceAccountId, AccountId: templateModifyReq.SourceAccountId,
@@ -215,7 +192,8 @@ func (a *TransactionTemplatesApi) TemplateModifyHandler(c *core.Context) (any, *
Comment: templateModifyReq.Comment, Comment: templateModifyReq.Comment,
} }
if newTemplate.Type == template.Type && if newTemplate.Name == template.Name &&
newTemplate.Type == template.Type &&
newTemplate.CategoryId == template.CategoryId && newTemplate.CategoryId == template.CategoryId &&
newTemplate.AccountId == template.AccountId && newTemplate.AccountId == template.AccountId &&
newTemplate.TagIds == template.TagIds && newTemplate.TagIds == template.TagIds &&
@@ -237,7 +215,7 @@ func (a *TransactionTemplatesApi) TemplateModifyHandler(c *core.Context) (any, *
log.InfofWithRequestId(c, "[transaction_templates.TemplateModifyHandler] user \"uid:%d\" has updated template \"id:%d\" successfully", uid, templateModifyReq.Id) log.InfofWithRequestId(c, "[transaction_templates.TemplateModifyHandler] user \"uid:%d\" has updated template \"id:%d\" successfully", uid, templateModifyReq.Id)
serverUtcOffset := utils.GetServerTimezoneOffsetMinutes() serverUtcOffset := utils.GetServerTimezoneOffsetMinutes()
newTemplate.Name = template.Name newTemplate.TemplateType = template.TemplateType
newTemplate.DisplayOrder = template.DisplayOrder newTemplate.DisplayOrder = template.DisplayOrder
newTemplate.Hidden = template.Hidden newTemplate.Hidden = template.Hidden
templateResp := newTemplate.ToTransactionTemplateInfoResponse(serverUtcOffset) templateResp := newTemplate.ToTransactionTemplateInfoResponse(serverUtcOffset)
@@ -326,10 +304,18 @@ func (a *TransactionTemplatesApi) TemplateDeleteHandler(c *core.Context) (any, *
func (a *TransactionTemplatesApi) createNewTemplateModel(uid int64, templateCreateReq *models.TransactionTemplateCreateRequest, order int32) *models.TransactionTemplate { func (a *TransactionTemplatesApi) createNewTemplateModel(uid int64, templateCreateReq *models.TransactionTemplateCreateRequest, order int32) *models.TransactionTemplate {
return &models.TransactionTemplate{ return &models.TransactionTemplate{
Uid: uid, Uid: uid,
TemplateType: templateCreateReq.TemplateType, TemplateType: templateCreateReq.TemplateType,
Name: templateCreateReq.Name, Name: templateCreateReq.Name,
Type: models.TRANSACTION_TYPE_EXPENSE, Type: templateCreateReq.Type,
DisplayOrder: order, CategoryId: templateCreateReq.CategoryId,
AccountId: templateCreateReq.SourceAccountId,
TagIds: strings.Join(templateCreateReq.TagIds, ","),
Amount: templateCreateReq.SourceAmount,
RelatedAccountId: templateCreateReq.DestinationAccountId,
RelatedAccountAmount: templateCreateReq.DestinationAmount,
HideAmount: templateCreateReq.HideAmount,
Comment: templateCreateReq.Comment,
DisplayOrder: order,
} }
} }
+3 -2
View File
@@ -4,6 +4,7 @@ import "net/http"
// Error codes related to transaction templates // Error codes related to transaction templates
var ( var (
ErrTransactionTemplateIdInvalid = NewNormalError(NormalSubcategoryTemplate, 0, http.StatusBadRequest, "transaction template id is invalid") ErrTransactionTemplateIdInvalid = NewNormalError(NormalSubcategoryTemplate, 0, http.StatusBadRequest, "transaction template id is invalid")
ErrTransactionTemplateNotFound = NewNormalError(NormalSubcategoryTemplate, 1, http.StatusBadRequest, "transaction template not found") ErrTransactionTemplateNotFound = NewNormalError(NormalSubcategoryTemplate, 1, http.StatusBadRequest, "transaction template not found")
ErrTransactionTemplateTypeInvalid = NewNormalError(NormalSubcategoryTemplate, 2, http.StatusBadRequest, "transaction template type is invalid")
) )
+15 -5
View File
@@ -39,7 +39,7 @@ type TransactionTemplate struct {
// TransactionTemplateListRequest represents all parameters of transaction template list request // TransactionTemplateListRequest represents all parameters of transaction template list request
type TransactionTemplateListRequest struct { type TransactionTemplateListRequest struct {
TemplateType TransactionTemplateType `form:"templateType" binding:"required,min=1,max=1"` TemplateType TransactionTemplateType `form:"templateType"`
} }
// TransactionTemplateGetRequest represents all parameters of transaction template getting request // TransactionTemplateGetRequest represents all parameters of transaction template getting request
@@ -49,9 +49,18 @@ type TransactionTemplateGetRequest struct {
// TransactionTemplateCreateRequest represents all parameters of transaction template creation request // TransactionTemplateCreateRequest represents all parameters of transaction template creation request
type TransactionTemplateCreateRequest struct { type TransactionTemplateCreateRequest struct {
TemplateType TransactionTemplateType `json:"templateType" binding:"required,min=1,max=1"` TemplateType TransactionTemplateType `json:"templateType"`
Name string `json:"name" binding:"required,notBlank,max=32"` Name string `json:"name" binding:"required,notBlank,max=32"`
ClientSessionId string `json:"clientSessionId"` Type TransactionType `json:"type" binding:"required"`
CategoryId int64 `json:"categoryId,string" binding:"required,min=1"`
SourceAccountId int64 `json:"sourceAccountId,string" binding:"required,min=1"`
DestinationAccountId int64 `json:"destinationAccountId,string" binding:"min=0"`
SourceAmount int64 `json:"sourceAmount" binding:"min=-99999999999,max=99999999999"`
DestinationAmount int64 `json:"destinationAmount" binding:"min=-99999999999,max=99999999999"`
HideAmount bool `json:"hideAmount"`
TagIds []string `json:"tagIds"`
Comment string `json:"comment" binding:"max=255"`
ClientSessionId string `json:"clientSessionId"`
} }
// TransactionTemplateModifyNameRequest represents all parameters of transaction template name modification request // TransactionTemplateModifyNameRequest represents all parameters of transaction template name modification request
@@ -63,8 +72,9 @@ type TransactionTemplateModifyNameRequest struct {
// TransactionTemplateModifyRequest represents all parameters of transaction template modification request // TransactionTemplateModifyRequest represents all parameters of transaction template modification request
type TransactionTemplateModifyRequest struct { type TransactionTemplateModifyRequest struct {
Id int64 `json:"id,string" binding:"required,min=1"` Id int64 `json:"id,string" binding:"required,min=1"`
Name string `json:"name" binding:"required,notBlank,max=32"`
Type TransactionType `json:"type" binding:"required"` Type TransactionType `json:"type" binding:"required"`
CategoryId int64 `json:"categoryId,string"` CategoryId int64 `json:"categoryId,string" binding:"required,min=1"`
SourceAccountId int64 `json:"sourceAccountId,string" binding:"required,min=1"` SourceAccountId int64 `json:"sourceAccountId,string" binding:"required,min=1"`
DestinationAccountId int64 `json:"destinationAccountId,string" binding:"min=0"` DestinationAccountId int64 `json:"destinationAccountId,string" binding:"min=0"`
SourceAmount int64 `json:"sourceAmount" binding:"min=-99999999999,max=99999999999"` SourceAmount int64 `json:"sourceAmount" binding:"min=-99999999999,max=99999999999"`
+1 -22
View File
@@ -125,28 +125,7 @@ func (s *TransactionTemplateService) ModifyTemplate(c *core.Context, template *m
template.UpdatedUnixTime = time.Now().Unix() template.UpdatedUnixTime = time.Now().Unix()
return s.UserDataDB(template.Uid).DoTransaction(c, func(sess *xorm.Session) error { return s.UserDataDB(template.Uid).DoTransaction(c, func(sess *xorm.Session) error {
updatedRows, err := sess.ID(template.TemplateId).Cols("type", "category_id", "account_id", "tag_ids", "amount", "related_account_id", "related_account_amount", "hide_amount", "comment", "updated_unix_time").Where("uid=? AND deleted=?", template.Uid, false).Update(template) updatedRows, err := sess.ID(template.TemplateId).Cols("name", "type", "category_id", "account_id", "tag_ids", "amount", "related_account_id", "related_account_amount", "hide_amount", "comment", "updated_unix_time").Where("uid=? AND deleted=?", template.Uid, false).Update(template)
if err != nil {
return err
} else if updatedRows < 1 {
return errs.ErrTransactionTemplateNotFound
}
return err
})
}
// ModifyTemplateName updates the name of an existed transaction template model to database
func (s *TransactionTemplateService) ModifyTemplateName(c *core.Context, template *models.TransactionTemplate) error {
if template.Uid <= 0 {
return errs.ErrUserIdInvalid
}
template.UpdatedUnixTime = time.Now().Unix()
return s.UserDataDB(template.Uid).DoTransaction(c, func(sess *xorm.Session) error {
updatedRows, err := sess.ID(template.TemplateId).Cols("name", "updated_unix_time").Where("uid=? AND deleted=?", template.Uid, false).Update(template)
if err != nil { if err != nil {
return err return err
+12 -8
View File
@@ -523,22 +523,26 @@ export default {
getTransactionTemplate: ({ id }) => { getTransactionTemplate: ({ id }) => {
return axios.get('v1/transaction/templates/get.json?id=' + id); return axios.get('v1/transaction/templates/get.json?id=' + id);
}, },
addTransactionTemplate: ({ templateType, name, clientSessionId }) => { addTransactionTemplate: ({ templateType, name, type, categoryId, sourceAccountId, destinationAccountId, sourceAmount, destinationAmount, hideAmount, tagIds, comment, clientSessionId }) => {
return axios.post('v1/transaction/templates/add.json', { return axios.post('v1/transaction/templates/add.json', {
templateType, templateType,
name, name,
type,
categoryId,
sourceAccountId,
destinationAccountId,
sourceAmount,
destinationAmount,
hideAmount,
tagIds,
comment,
clientSessionId clientSessionId
}); });
}, },
modifyTransactionNameTemplate: ({ id, name }) => { modifyTransactionTemplate: ({ id, name, type, categoryId, sourceAccountId, destinationAccountId, sourceAmount, destinationAmount, hideAmount, tagIds, comment }) => {
return axios.post('v1/transaction/templates/modify_name.json', {
id,
name
});
},
modifyTransactionTemplate: ({ id, type, categoryId, sourceAccountId, destinationAccountId, sourceAmount, destinationAmount, hideAmount, tagIds, comment }) => {
return axios.post('v1/transaction/templates/modify.json', { return axios.post('v1/transaction/templates/modify.json', {
id, id,
name,
type, type,
categoryId, categoryId,
sourceAccountId, sourceAccountId,
+6 -1
View File
@@ -702,6 +702,9 @@ export default {
'transaction tag is in use and cannot be deleted': 'Transaction tag is in use and it cannot be deleted', 'transaction tag is in use and cannot be deleted': 'Transaction tag is in use and it cannot be deleted',
'transaction tag index not found': 'Transaction tag index is not found', 'transaction tag index not found': 'Transaction tag index is not found',
'data export not allowed': 'User data export is not allowed', 'data export not allowed': 'User data export is not allowed',
'transaction template id is invalid': 'Transaction template ID is invalid',
'transaction template not found': 'Transaction template is not found',
'transaction template type is invalid': 'Transaction template type is invalid',
'query items cannot be blank': 'There are no query items', 'query items cannot be blank': 'There are no query items',
'query items too much': 'There are too many query items', 'query items too much': 'There are too many query items',
'query items have invalid item': 'There is invalid item in query items', 'query items have invalid item': 'There is invalid item in query items',
@@ -738,6 +741,7 @@ export default {
'month': 'Month', 'month': 'Month',
'page': 'Page Index', 'page': 'Page Index',
'count': 'Count', 'count': 'Count',
'templateType': 'Template Type',
'comment': 'Description', 'comment': 'Description',
}, },
'parameterizedError': { 'parameterizedError': {
@@ -788,7 +792,6 @@ export default {
'Show': 'Show', 'Show': 'Show',
'Hide': 'Hide', 'Hide': 'Hide',
'Version': 'Version', 'Version': 'Version',
'Modify Name': 'Modify Name',
'Edit': 'Edit', 'Edit': 'Edit',
'Remove': 'Remove', 'Remove': 'Remove',
'Delete': 'Delete', 'Delete': 'Delete',
@@ -1021,6 +1024,7 @@ export default {
'Transactions': 'Transactions', 'Transactions': 'Transactions',
'Add Transaction': 'Add Transaction', 'Add Transaction': 'Add Transaction',
'Edit Transaction': 'Edit Transaction', 'Edit Transaction': 'Edit Transaction',
'Add Transaction Template': 'Add Transaction Template',
'Edit Transaction Template': 'Edit Transaction Template', 'Edit Transaction Template': 'Edit Transaction Template',
'Modify Balance': 'Modify Balance', 'Modify Balance': 'Modify Balance',
'Expense Amount': 'Expense Amount', 'Expense Amount': 'Expense Amount',
@@ -1278,6 +1282,7 @@ export default {
'Template list has been updated': 'Template list has been updated', 'Template list has been updated': 'Template list has been updated',
'Unable to add template': 'Unable to add template', 'Unable to add template': 'Unable to add template',
'Unable to save template': 'Unable to save template', 'Unable to save template': 'Unable to save template',
'You have added a new template': 'You have added a new template',
'Unable to move template': 'Unable to move template', 'Unable to move template': 'Unable to move template',
'Unable to retrieve template': 'Unable to retrieve template', 'Unable to retrieve template': 'Unable to retrieve template',
'Unable to hide this template': 'Unable to hide this template', 'Unable to hide this template': 'Unable to hide this template',
+6 -1
View File
@@ -702,6 +702,9 @@ export default {
'transaction tag is in use and cannot be deleted': '交易标签正在被使用,无法删除', 'transaction tag is in use and cannot be deleted': '交易标签正在被使用,无法删除',
'transaction tag index not found': '交易标签索引不存在', 'transaction tag index not found': '交易标签索引不存在',
'data export not allowed': '不允许用户数据导出', 'data export not allowed': '不允许用户数据导出',
'transaction template id is invalid': '交易模板ID无效',
'transaction template not found': '交易模板不存在',
'transaction template type is invalid': '交易模板类型无效',
'query items cannot be blank': '请求项目不能为空', 'query items cannot be blank': '请求项目不能为空',
'query items too much': '请求项目过多', 'query items too much': '请求项目过多',
'query items have invalid item': '请求项目中有非法项目', 'query items have invalid item': '请求项目中有非法项目',
@@ -738,6 +741,7 @@ export default {
'month': '月份', 'month': '月份',
'page': '页码索引', 'page': '页码索引',
'count': '数量', 'count': '数量',
'templateType': '模板类型',
'comment': '描述', 'comment': '描述',
}, },
'parameterizedError': { 'parameterizedError': {
@@ -788,7 +792,6 @@ export default {
'Show': '显示', 'Show': '显示',
'Hide': '隐藏', 'Hide': '隐藏',
'Version': '版本', 'Version': '版本',
'Modify Name': '修改名称',
'Edit': '编辑', 'Edit': '编辑',
'Remove': '移除', 'Remove': '移除',
'Delete': '删除', 'Delete': '删除',
@@ -1021,6 +1024,7 @@ export default {
'Transactions': '交易', 'Transactions': '交易',
'Add Transaction': '添加交易', 'Add Transaction': '添加交易',
'Edit Transaction': '编辑交易', 'Edit Transaction': '编辑交易',
'Add Transaction Template': '添加交易模板',
'Edit Transaction Template': '编辑交易模板', 'Edit Transaction Template': '编辑交易模板',
'Modify Balance': '修改余额', 'Modify Balance': '修改余额',
'Expense Amount': '支出金额', 'Expense Amount': '支出金额',
@@ -1278,6 +1282,7 @@ export default {
'Template list has been updated': '模板列表已更新', 'Template list has been updated': '模板列表已更新',
'Unable to add template': '无法添加模板', 'Unable to add template': '无法添加模板',
'Unable to save template': '无法保存模板', 'Unable to save template': '无法保存模板',
'You have added a new template': '您已经添加新模板',
'Unable to move template': '无法移动模板', 'Unable to move template': '无法移动模板',
'Unable to retrieve template': '无法获取模板', 'Unable to retrieve template': '无法获取模板',
'Unable to hide this template': '无法隐藏该模板', 'Unable to hide this template': '无法隐藏该模板',
+35 -61
View File
@@ -129,13 +129,6 @@ export const useTransactionTemplatesStore = defineStore('transactionTemplates',
} }
}, },
actions: { actions: {
generateNewTransactionTemplateModel(templateType) {
return {
id: '',
templateType: templateType,
name: ''
};
},
updateTransactionTemplateListInvalidState(templateType, invalidState) { updateTransactionTemplateListInvalidState(templateType, invalidState) {
this.transactionTemplateListStatesInvalid[templateType] = invalidState; this.transactionTemplateListStatesInvalid[templateType] = invalidState;
}, },
@@ -217,59 +210,12 @@ export const useTransactionTemplatesStore = defineStore('transactionTemplates',
}); });
}); });
}, },
saveTemplateName({ template }) { saveTemplateContent({ template, isEdit, clientSessionId }) {
const self = this;
return new Promise((resolve, reject) => {
let promise = null;
if (!template.id) {
promise = services.addTransactionTemplate(template);
} else {
promise = services.modifyTransactionNameTemplate(template);
}
promise.then(response => {
const data = response.data;
if (!data || !data.success || !data.result) {
if (!template.id) {
reject({ message: 'Unable to add template' });
} else {
reject({ message: 'Unable to save template' });
}
return;
}
if (!template.id) {
addTemplateToTransactionTemplateList(self, template.templateType, data.result);
} else {
updateTemplateInTransactionTemplateList(self, template.templateType, data.result);
}
resolve(data.result);
}).catch(error => {
logger.error('failed to save template', error);
if (error.response && error.response.data && error.response.data.errorMessage) {
reject({ error: error.response.data });
} else if (!error.processed) {
if (!template.id) {
reject({ message: 'Unable to add template' });
} else {
reject({ message: 'Unable to save template' });
}
} else {
reject(error);
}
});
});
},
modifyTemplateContent({ template }) {
const self = this; const self = this;
const submitTemplate = { const submitTemplate = {
id: template.id, templateType: template.templateType,
name: template.name,
type: template.type, type: template.type,
sourceAccountId: template.sourceAccountId, sourceAccountId: template.sourceAccountId,
sourceAmount: template.sourceAmount, sourceAmount: template.sourceAmount,
@@ -280,6 +226,10 @@ export const useTransactionTemplatesStore = defineStore('transactionTemplates',
comment: template.comment comment: template.comment
}; };
if (clientSessionId) {
submitTemplate.clientSessionId = clientSessionId;
}
if (template.type === transactionConstants.allTransactionTypes.Expense) { if (template.type === transactionConstants.allTransactionTypes.Expense) {
submitTemplate.categoryId = template.expenseCategory; submitTemplate.categoryId = template.expenseCategory;
} else if (template.type === transactionConstants.allTransactionTypes.Income) { } else if (template.type === transactionConstants.allTransactionTypes.Income) {
@@ -292,16 +242,36 @@ export const useTransactionTemplatesStore = defineStore('transactionTemplates',
return Promise.reject('An error occurred'); return Promise.reject('An error occurred');
} }
if (isEdit) {
submitTemplate.id = template.id;
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
services.modifyTransactionTemplate(submitTemplate).then(response => { let promise = null;
if (!submitTemplate.id) {
promise = services.addTransactionTemplate(submitTemplate);
} else {
promise = services.modifyTransactionTemplate(submitTemplate);
}
promise.then(response => {
const data = response.data; const data = response.data;
if (!data || !data.success || !data.result) { if (!data || !data.success || !data.result) {
reject({ message: 'Unable to save template' }); if (!submitTemplate.id) {
reject({ message: 'Unable to add template' });
} else {
reject({ message: 'Unable to save template' });
}
return; return;
} }
updateTemplateInTransactionTemplateList(self, template.templateType, data.result); if (!submitTemplate.id) {
addTemplateToTransactionTemplateList(self, template.templateType, data.result);
} else {
updateTemplateInTransactionTemplateList(self, template.templateType, data.result);
}
resolve(data.result); resolve(data.result);
}).catch(error => { }).catch(error => {
@@ -310,7 +280,11 @@ export const useTransactionTemplatesStore = defineStore('transactionTemplates',
if (error.response && error.response.data && error.response.data.errorMessage) { if (error.response && error.response.data && error.response.data.errorMessage) {
reject({ error: error.response.data }); reject({ error: error.response.data });
} else if (!error.processed) { } else if (!error.processed) {
reject({ message: 'Unable to save template' }); if (!submitTemplate.id) {
reject({ message: 'Unable to add template' });
} else {
reject({ message: 'Unable to save template' });
}
} else { } else {
reject(error); reject(error);
} }
+16 -159
View File
@@ -6,12 +6,12 @@
<div class="title-and-toolbar d-flex align-center"> <div class="title-and-toolbar d-flex align-center">
<span>{{ $t('Transaction Templates') }}</span> <span>{{ $t('Transaction Templates') }}</span>
<v-btn class="ml-3" color="default" variant="outlined" <v-btn class="ml-3" color="default" variant="outlined"
:disabled="loading || updating || hasEditingTemplateName" @click="add">{{ $t('Add') }}</v-btn> :disabled="loading || updating" @click="add">{{ $t('Add') }}</v-btn>
<v-btn class="ml-3" color="primary" variant="tonal" <v-btn class="ml-3" color="primary" variant="tonal"
:disabled="loading || updating || hasEditingTemplateName" @click="saveSortResult" :disabled="loading || updating" @click="saveSortResult"
v-if="displayOrderModified">{{ $t('Save Display Order') }}</v-btn> v-if="displayOrderModified">{{ $t('Save Display Order') }}</v-btn>
<v-btn density="compact" color="default" variant="text" size="24" <v-btn density="compact" color="default" variant="text" size="24"
class="ml-2" :icon="true" :disabled="loading || updating || hasEditingTemplateName" class="ml-2" :icon="true" :disabled="loading || updating"
:loading="loading" @click="reload"> :loading="loading" @click="reload">
<template #loader> <template #loader>
<v-progress-circular indeterminate size="20"/> <v-progress-circular indeterminate size="20"/>
@@ -21,7 +21,7 @@
</v-btn> </v-btn>
<v-spacer/> <v-spacer/>
<v-btn density="comfortable" color="default" variant="text" class="ml-2" <v-btn density="comfortable" color="default" variant="text" class="ml-2"
:disabled="loading || updating || hasEditingTemplateName" :icon="true"> :disabled="loading || updating" :icon="true">
<v-icon :icon="icons.more" /> <v-icon :icon="icons.more" />
<v-menu activator="parent"> <v-menu activator="parent">
<v-list> <v-list>
@@ -50,7 +50,7 @@
</tr> </tr>
</thead> </thead>
<tbody v-if="loading && noAvailableTemplate && !newTemplate"> <tbody v-if="loading && noAvailableTemplate">
<tr :key="itemIdx" v-for="itemIdx in [ 1, 2, 3 ]"> <tr :key="itemIdx" v-for="itemIdx in [ 1, 2, 3 ]">
<td class="px-0"> <td class="px-0">
<v-skeleton-loader type="text" :loading="true"></v-skeleton-loader> <v-skeleton-loader type="text" :loading="true"></v-skeleton-loader>
@@ -58,7 +58,7 @@
</tr> </tr>
</tbody> </tbody>
<tbody v-if="!loading && noAvailableTemplate && !newTemplate"> <tbody v-if="!loading && noAvailableTemplate">
<tr> <tr>
<td>{{ $t('No available template') }}</td> <td>{{ $t('No available template') }}</td>
</tr> </tr>
@@ -68,7 +68,6 @@
item-key="id" item-key="id"
handle=".drag-handle" handle=".drag-handle"
ghost-class="dragging-item" ghost-class="dragging-item"
:class="{ 'has-bottom-border': newTemplate }"
:disabled="noAvailableTemplate" :disabled="noAvailableTemplate"
v-model="templates" v-model="templates"
@change="onMove"> @change="onMove">
@@ -76,7 +75,7 @@
<tr class="transaction-templates-table-row text-sm" v-if="showHidden || !element.hidden"> <tr class="transaction-templates-table-row text-sm" v-if="showHidden || !element.hidden">
<td> <td>
<div class="d-flex align-center"> <div class="d-flex align-center">
<div class="d-flex align-center" v-if="editingTemplateName.id !== element.id"> <div class="d-flex align-center">
<v-badge class="right-bottom-icon" color="secondary" <v-badge class="right-bottom-icon" color="secondary"
location="bottom right" offset-x="8" :icon="icons.hide" location="bottom right" offset-x="8" :icon="icons.hide"
v-if="element.hidden"> v-if="element.hidden">
@@ -86,24 +85,6 @@
<span class="transaction-template-name">{{ element.name }}</span> <span class="transaction-template-name">{{ element.name }}</span>
</div> </div>
<v-text-field class="w-100 mr-2" type="text"
density="compact" variant="underlined"
:disabled="loading || updating"
:placeholder="$t('Template Name')"
v-model="editingTemplateName.name"
v-else-if="editingTemplateName.id === element.id"
@keyup.enter="saveName(editingTemplateName)"
>
<template #prepend>
<v-badge class="right-bottom-icon" color="secondary"
location="bottom right" offset-x="8" :icon="icons.hide"
v-if="element.hidden">
<v-icon size="20" start :icon="icons.text"/>
</v-badge>
<v-icon size="20" start :icon="icons.text" v-else-if="!element.hidden"/>
</template>
</v-text-field>
<v-spacer/> <v-spacer/>
<v-btn class="px-2 ml-2" color="default" <v-btn class="px-2 ml-2" color="default"
@@ -112,7 +93,6 @@
:prepend-icon="element.hidden ? icons.show : icons.hide" :prepend-icon="element.hidden ? icons.show : icons.hide"
:loading="templateHiding[element.id]" :loading="templateHiding[element.id]"
:disabled="loading || updating" :disabled="loading || updating"
v-if="editingTemplateName.id !== element.id"
@click="hide(element, !element.hidden)"> @click="hide(element, !element.hidden)">
<template #loader> <template #loader>
<v-progress-circular indeterminate size="20" width="2"/> <v-progress-circular indeterminate size="20" width="2"/>
@@ -123,22 +103,7 @@
density="comfortable" variant="text" density="comfortable" variant="text"
:class="{ 'd-none': loading, 'hover-display': !loading }" :class="{ 'd-none': loading, 'hover-display': !loading }"
:prepend-icon="icons.edit" :prepend-icon="icons.edit"
:loading="templateNameUpdating[element.id]"
:disabled="loading || updating" :disabled="loading || updating"
v-if="editingTemplateName.id !== element.id"
@click="modifyName(element)">
<template #loader>
<v-progress-circular indeterminate size="20" width="2"/>
</template>
{{ $t('Modify Name') }}
</v-btn>
<v-btn class="px-2" color="default"
density="comfortable" variant="text"
:class="{ 'd-none': loading, 'hover-display': !loading }"
:prepend-icon="icons.edit"
:loading="templateNameUpdating[element.id]"
:disabled="loading || updating"
v-if="editingTemplateName.id !== element.id"
@click="edit(element)"> @click="edit(element)">
<template #loader> <template #loader>
<v-progress-circular indeterminate size="20" width="2"/> <v-progress-circular indeterminate size="20" width="2"/>
@@ -151,31 +116,12 @@
:prepend-icon="icons.remove" :prepend-icon="icons.remove"
:loading="templateRemoving[element.id]" :loading="templateRemoving[element.id]"
:disabled="loading || updating" :disabled="loading || updating"
v-if="editingTemplateName.id !== element.id"
@click="remove(element)"> @click="remove(element)">
<template #loader> <template #loader>
<v-progress-circular indeterminate size="20" width="2"/> <v-progress-circular indeterminate size="20" width="2"/>
</template> </template>
{{ $t('Delete') }} {{ $t('Delete') }}
</v-btn> </v-btn>
<v-btn class="px-2"
density="comfortable" variant="text"
:prepend-icon="icons.confirm"
:loading="templateNameUpdating[element.id]"
:disabled="loading || updating || !isTemplateModified(element)"
v-if="editingTemplateName.id === element.id" @click="saveName(editingTemplateName)">
<template #loader>
<v-progress-circular indeterminate size="20" width="2"/>
</template>
{{ $t('Save') }}
</v-btn>
<v-btn class="px-2" color="default"
density="comfortable" variant="text"
:prepend-icon="icons.cancel"
:disabled="loading || updating"
v-if="editingTemplateName.id === element.id" @click="cancelSaveName(editingTemplateName)">
{{ $t('Cancel') }}
</v-btn>
<span class="ml-2"> <span class="ml-2">
<v-icon :class="!loading && !updating && availableTemplateCount > 1 ? 'drag-handle' : 'disabled'" <v-icon :class="!loading && !updating && availableTemplateCount > 1 ? 'drag-handle' : 'disabled'"
:icon="icons.drag"/> :icon="icons.drag"/>
@@ -186,52 +132,12 @@
</tr> </tr>
</template> </template>
</draggable-list> </draggable-list>
<tbody v-if="newTemplate">
<tr class="text-sm" :class="{ 'even-row': availableTemplateCount & 1 === 1}">
<td>
<div class="d-flex align-center">
<v-text-field class="w-100 mr-2" type="text" color="primary"
density="compact" variant="underlined"
:disabled="loading || updating" :placeholder="$t('Template Name')"
v-model="newTemplate.name" @keyup.enter="saveName(newTemplate)">
<template #prepend>
<v-icon size="20" start :icon="icons.text"/>
</template>
</v-text-field>
<v-spacer/>
<v-btn class="px-2" density="comfortable" variant="text"
:prepend-icon="icons.confirm"
:loading="templateNameUpdating[null]"
:disabled="loading || updating || !isTemplateModified(newTemplate)"
@click="saveName(newTemplate)">
<template #loader>
<v-progress-circular indeterminate size="20" width="2"/>
</template>
{{ $t('Save') }}
</v-btn>
<v-btn class="px-2" color="default"
density="comfortable" variant="text"
:prepend-icon="icons.cancel"
:disabled="loading || updating"
@click="cancelSaveName(newTemplate)">
{{ $t('Cancel') }}
</v-btn>
<span class="ml-2">
<v-icon class="disabled" :icon="icons.drag"/>
</span>
</div>
</td>
</tr>
</tbody>
</v-table> </v-table>
</v-card> </v-card>
</v-col> </v-col>
</v-row> </v-row>
<edit-dialog ref="editDialog" :persistent="true" /> <edit-dialog ref="editDialog" type="template" :persistent="true" />
<confirm-dialog ref="confirmDialog"/> <confirm-dialog ref="confirmDialog"/>
<snack-bar ref="snackbar" /> <snack-bar ref="snackbar" />
@@ -244,7 +150,6 @@ import { mapStores } from 'pinia';
import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js'; import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js';
import templateConstants from '@/consts/template.js'; import templateConstants from '@/consts/template.js';
import { generateRandomUUID } from '@/lib/misc.js';
import { import {
mdiRefresh, mdiRefresh,
@@ -267,11 +172,8 @@ export default {
data() { data() {
return { return {
templateType: templateConstants.allTemplateTypes.Normal, templateType: templateConstants.allTemplateTypes.Normal,
newTemplate: null,
editingTemplateName: {},
loading: true, loading: true,
updating: false, updating: false,
templateNameUpdating: {},
templateHiding: {}, templateHiding: {},
templateRemoving: {}, templateRemoving: {},
displayOrderModified: false, displayOrderModified: false,
@@ -315,9 +217,6 @@ export default {
} }
return count; return count;
},
hasEditingTemplateName() {
return !!(this.newTemplate || (this.editingTemplateName && this.editingTemplateName.id && this.editingTemplateName.id !== ''));
} }
}, },
created() { created() {
@@ -340,10 +239,6 @@ export default {
}, },
methods: { methods: {
reload() { reload() {
if (this.hasEditingTemplateName) {
return;
}
const self = this; const self = this;
self.loading = true; self.loading = true;
@@ -410,56 +305,27 @@ export default {
}); });
}, },
add() { add() {
this.newTemplate = {
templateType: this.templateType,
name: '',
clientSessionId: generateRandomUUID()
};
},
modifyName(template) {
this.editingTemplateName.id = template.id;
this.editingTemplateName.templateType = template.templateType;
this.editingTemplateName.name = template.name;
},
saveName(template) {
const self = this; const self = this;
self.updating = true; self.$refs.editDialog.open({
self.templateNameUpdating[template.id || null] = true; templateType: self.templateType
}).then(result => {
self.transactionTemplatesStore.saveTemplateName({ if (result && result.message) {
template: template self.$refs.snackbar.showMessage(result.message);
}).then(() => {
self.updating = false;
self.templateNameUpdating[template.id || null] = false;
if (template.id) {
self.editingTemplateName = {};
} else {
self.newTemplate = null;
} }
}).catch(error => { }).catch(error => {
self.updating = false; if (error) {
self.templateNameUpdating[template.id || null] = false;
if (!error.processed) {
self.$refs.snackbar.showError(error); self.$refs.snackbar.showError(error);
} }
}); });
}, },
cancelSaveName(template) {
if (template.id) {
this.editingTemplateName = {};
} else {
this.newTemplate = null;
}
},
edit(template) { edit(template) {
const self = this; const self = this;
self.$refs.editDialog.open({ self.$refs.editDialog.open({
editTemplateId: template.id, id: template.id,
currentTemplate: { currentTemplate: {
name: template.name,
type: template.type, type: template.type,
categoryId: template.categoryId, categoryId: template.categoryId,
sourceAccountId: template.sourceAccountId, sourceAccountId: template.sourceAccountId,
@@ -474,21 +340,12 @@ export default {
if (result && result.message) { if (result && result.message) {
self.$refs.snackbar.showMessage(result.message); self.$refs.snackbar.showMessage(result.message);
} }
self.reload(false);
}).catch(error => { }).catch(error => {
if (error) { if (error) {
self.$refs.snackbar.showError(error); self.$refs.snackbar.showError(error);
} }
}); });
}, },
isTemplateModified(template) {
if (template.id) {
return this.editingTemplateName && this.editingTemplateName.name !== '' && this.editingTemplateName.name !== template.name;
} else {
return template.name !== '';
}
},
hide(template, hidden) { hide(template, hidden) {
const self = this; const self = this;
+1 -1
View File
@@ -480,7 +480,7 @@
:max-time="customMaxDatetime" :max-time="customMaxDatetime"
v-model:show="showCustomDateRangeDialog" v-model:show="showCustomDateRangeDialog"
@dateRange:change="changeCustomDateFilter" /> @dateRange:change="changeCustomDateFilter" />
<edit-dialog ref="editDialog" :persistent="true" /> <edit-dialog ref="editDialog" type="transaction" :persistent="true" />
<v-dialog width="800" v-model="showFilterAccountDialog"> <v-dialog width="800" v-model="showFilterAccountDialog">
<account-filter-settings-card type="transactionListCurrent" :dialog-mode="true" <account-filter-settings-card type="transactionListCurrent" :dialog-mode="true"
@@ -38,18 +38,18 @@
</template> </template>
<v-card-text class="d-flex flex-column flex-md-row mt-md-4 pt-0"> <v-card-text class="d-flex flex-column flex-md-row mt-md-4 pt-0">
<div class="mb-4"> <div class="mb-4">
<v-tabs class="v-tabs-pill" direction="vertical" :class="{ 'readonly': mode !== 'add' && mode !== 'editTemplate' }" <v-tabs class="v-tabs-pill" direction="vertical" :class="{ 'readonly': type === 'transaction' && mode !== 'add' }"
:disabled="loading || submitting" v-model="transaction.type"> :disabled="loading || submitting" v-model="transaction.type">
<v-tab :value="allTransactionTypes.Expense" :disabled="mode !== 'add' && mode !== 'editTemplate' && transaction.type !== allTransactionTypes.Expense" v-if="transaction.type !== allTransactionTypes.ModifyBalance"> <v-tab :value="allTransactionTypes.Expense" :disabled="type === 'transaction' && mode !== 'add' && transaction.type !== allTransactionTypes.Expense" v-if="transaction.type !== allTransactionTypes.ModifyBalance">
<span>{{ $t('Expense') }}</span> <span>{{ $t('Expense') }}</span>
</v-tab> </v-tab>
<v-tab :value="allTransactionTypes.Income" :disabled="mode !== 'add' && mode !== 'editTemplate' && transaction.type !== allTransactionTypes.Income" v-if="transaction.type !== allTransactionTypes.ModifyBalance"> <v-tab :value="allTransactionTypes.Income" :disabled="type === 'transaction' && mode !== 'add' && transaction.type !== allTransactionTypes.Income" v-if="transaction.type !== allTransactionTypes.ModifyBalance">
<span>{{ $t('Income') }}</span> <span>{{ $t('Income') }}</span>
</v-tab> </v-tab>
<v-tab :value="allTransactionTypes.Transfer" :disabled="mode !== 'add' && mode !== 'editTemplate' && transaction.type !== allTransactionTypes.Transfer" v-if="transaction.type !== allTransactionTypes.ModifyBalance"> <v-tab :value="allTransactionTypes.Transfer" :disabled="type === 'transaction' && mode !== 'add' && transaction.type !== allTransactionTypes.Transfer" v-if="transaction.type !== allTransactionTypes.ModifyBalance">
<span>{{ $t('Transfer') }}</span> <span>{{ $t('Transfer') }}</span>
</v-tab> </v-tab>
<v-tab :value="allTransactionTypes.ModifyBalance" v-if="mode !== 'editTemplate' && transaction.type === allTransactionTypes.ModifyBalance"> <v-tab :value="allTransactionTypes.ModifyBalance" v-if="type === 'transaction' && transaction.type === allTransactionTypes.ModifyBalance">
<span>{{ $t('Modify Balance') }}</span> <span>{{ $t('Modify Balance') }}</span>
</v-tab> </v-tab>
</v-tabs> </v-tabs>
@@ -58,7 +58,7 @@
<v-tab value="basicInfo"> <v-tab value="basicInfo">
<span>{{ $t('Basic Information') }}</span> <span>{{ $t('Basic Information') }}</span>
</v-tab> </v-tab>
<v-tab value="map" :disabled="!transaction.geoLocation" v-if="mode !== 'editTemplate' && mapProvider"> <v-tab value="map" :disabled="!transaction.geoLocation" v-if="type === 'transaction' && mapProvider">
<span>{{ $t('Location on Map') }}</span> <span>{{ $t('Location on Map') }}</span>
</v-tab> </v-tab>
</v-tabs> </v-tabs>
@@ -69,6 +69,16 @@
<v-window-item value="basicInfo"> <v-window-item value="basicInfo">
<v-form class="mt-2"> <v-form class="mt-2">
<v-row> <v-row>
<v-col cols="12" v-if="type === 'template'">
<v-text-field
type="text"
persistent-placeholder
:disabled="loading || submitting"
:label="$t('Template Name')"
:placeholder="$t('Template Name')"
v-model="transaction.name"
/>
</v-col>
<v-col cols="12" :md="transaction.type === allTransactionTypes.Transfer ? 6 : 12"> <v-col cols="12" :md="transaction.type === allTransactionTypes.Transfer ? 6 : 12">
<amount-input class="transaction-edit-amount font-weight-bold" <amount-input class="transaction-edit-amount font-weight-bold"
:color="sourceAmountColor" :color="sourceAmountColor"
@@ -177,7 +187,7 @@
v-model="transaction.destinationAccountId"> v-model="transaction.destinationAccountId">
</two-column-select> </two-column-select>
</v-col> </v-col>
<v-col cols="12" md="6" v-if="mode !== 'editTemplate'"> <v-col cols="12" md="6" v-if="type === 'transaction'">
<date-time-select <date-time-select
:readonly="mode === 'view'" :readonly="mode === 'view'"
:disabled="loading || submitting" :disabled="loading || submitting"
@@ -185,7 +195,7 @@
v-model="transaction.time" v-model="transaction.time"
@error="showDateTimeError" /> @error="showDateTimeError" />
</v-col> </v-col>
<v-col cols="12" md="6" v-if="mode !== 'editTemplate'"> <v-col cols="12" md="6" v-if="type === 'transaction'">
<v-autocomplete <v-autocomplete
class="transaction-edit-timezone" class="transaction-edit-timezone"
item-title="displayNameWithUtcOffset" item-title="displayNameWithUtcOffset"
@@ -207,7 +217,7 @@
</template> </template>
</v-autocomplete> </v-autocomplete>
</v-col> </v-col>
<v-col cols="12" md="12" v-if="mode !== 'editTemplate'"> <v-col cols="12" md="12" v-if="type === 'transaction'">
<v-select <v-select
persistent-placeholder persistent-placeholder
:readonly="mode === 'view'" :readonly="mode === 'view'"
@@ -368,6 +378,7 @@ import {
export default { export default {
props: [ props: [
'persistent', 'persistent',
'type',
'show' 'show'
], ],
expose: [ expose: [
@@ -381,7 +392,7 @@ export default {
showState: false, showState: false,
mode: 'add', mode: 'add',
activeTab: 'basicInfo', activeTab: 'basicInfo',
editTransactionId: null, editId: null,
originalTransactionEditable: false, originalTransactionEditable: false,
clientSessionId: '', clientSessionId: '',
loading: true, loading: true,
@@ -404,15 +415,23 @@ export default {
computed: { computed: {
...mapStores(useSettingsStore, useUserStore, useAccountsStore, useTransactionCategoriesStore, useTransactionTagsStore, useTransactionsStore, useTransactionTemplatesStore, useExchangeRatesStore), ...mapStores(useSettingsStore, useUserStore, useAccountsStore, useTransactionCategoriesStore, useTransactionTagsStore, useTransactionsStore, useTransactionTemplatesStore, useExchangeRatesStore),
title() { title() {
if (this.mode === 'add') { if (this.type === 'transaction') {
return 'Add Transaction'; if (this.mode === 'add') {
} else if (this.mode === 'edit') { return 'Add Transaction';
return 'Edit Transaction'; } else if (this.mode === 'edit') {
} else if (this.mode === 'editTemplate') { return 'Edit Transaction';
return 'Edit Transaction Template'; } else {
} else { return 'Transaction Detail';
return 'Transaction Detail'; }
} else if (this.type === 'template') {
if (this.mode === 'add') {
return 'Add Transaction Template';
} else if (this.mode === 'edit') {
return 'Edit Transaction Template';
}
} }
return '';
}, },
saveButtonTitle() { saveButtonTitle() {
if (this.mode === 'add') { if (this.mode === 'add') {
@@ -636,31 +655,48 @@ export default {
self.transactionTagsStore.loadAllTags({ force: false }) self.transactionTagsStore.loadAllTags({ force: false })
]; ];
if (options && options.id) { if (self.type === 'transaction') {
if (options.currentTransaction) { if (options && options.id) {
self.setTransaction(options.currentTransaction, options, true, true); if (options.currentTransaction) {
self.setTransaction(options.currentTransaction, options, true, true);
}
self.mode = 'view';
self.editId = options.id;
promises.push(self.transactionsStore.getTransaction({ transactionId: self.editId }));
} else {
self.mode = 'add';
self.editId = null;
if (self.settingsStore.appSettings.autoGetCurrentGeoLocation
&& !self.geoLocationStatus && !self.transaction.geoLocation) {
self.updateGeoLocation(false);
}
}
} else if (self.type === 'template') {
self.transaction.name = '';
if (options && options.templateType) {
self.transaction.templateType = options.templateType;
} }
self.mode = 'view'; if (options && options.id) {
self.editTransactionId = options.id; if (options.currentTemplate) {
self.setTransaction(options.currentTemplate, options, false, false);
self.transaction.templateType = options.currentTemplate.templateType;
self.transaction.name = options.currentTemplate.name;
}
promises.push(self.transactionsStore.getTransaction({ transactionId: self.editTransactionId })); self.mode = 'edit';
} else if (options && options.editTemplateId) { self.editId = options.id;
if (options.currentTemplate) { self.transaction.id = options.id;
self.setTransaction(options.currentTemplate, options, false, false);
}
self.mode = 'editTemplate'; promises.push(self.transactionTemplatesStore.getTemplate({ templateId: self.editId }));
self.transaction.id = options.editTemplateId; } else {
self.mode = 'add';
promises.push(self.transactionTemplatesStore.getTemplate({ templateId: options.editTemplateId })); self.editId = null;
} else { self.transaction.id = null;
self.mode = 'add';
self.editTransactionId = null;
if (self.settingsStore.appSettings.autoGetCurrentGeoLocation
&& !self.geoLocationStatus && !self.transaction.geoLocation) {
self.updateGeoLocation(false);
} }
} }
@@ -675,21 +711,27 @@ export default {
} }
Promise.all(promises).then(function (responses) { Promise.all(promises).then(function (responses) {
if (self.editTransactionId && !responses[3]) { if (self.editId && !responses[3]) {
if (self.reject) { if (self.reject) {
self.reject('Unable to retrieve transaction'); if (self.type === 'transaction') {
self.reject('Unable to retrieve transaction');
} else if (self.type === 'template') {
self.reject('Unable to retrieve template');
}
} }
return; return;
} }
if (options && options.id && responses[3]) { if (self.type === 'transaction' && options && options.id && responses[3]) {
const transaction = responses[3]; const transaction = responses[3];
self.setTransaction(transaction, options, true, true); self.setTransaction(transaction, options, true, true);
self.originalTransactionEditable = transaction.editable; self.originalTransactionEditable = transaction.editable;
} else if (options && options.editTemplateId && responses[3]) { } else if (self.type === 'template' && options && options.id && responses[3]) {
const template = responses[3]; const template = responses[3];
self.setTransaction(template, options, false, false); self.setTransaction(template, options, false, false);
self.transaction.templateType = template.templateType;
self.transaction.name = template.name;
} else { } else {
self.setTransaction(null, options, true, true); self.setTransaction(null, options, true, true);
} }
@@ -716,7 +758,7 @@ export default {
save() { save() {
const self = this; const self = this;
if (self.mode === 'add' || self.mode === 'edit') { if (self.type === 'transaction' && (self.mode === 'add' || self.mode === 'edit')) {
const doSubmit = function () { const doSubmit = function () {
self.submitting = true; self.submitting = true;
@@ -757,18 +799,26 @@ export default {
} else { } else {
doSubmit(); doSubmit();
} }
} else if (self.mode === 'editTemplate') { } else if (self.type === 'template' && (self.mode === 'add' || self.mode === 'edit')) {
self.submitting = true; self.submitting = true;
self.transactionTemplatesStore.modifyTemplateContent({ self.transactionTemplatesStore.saveTemplateContent({
template: self.transaction template: self.transaction,
isEdit: self.mode === 'edit',
clientSessionId: self.clientSessionId
}).then(() => { }).then(() => {
self.submitting = false; self.submitting = false;
if (self.resolve) { if (self.resolve) {
self.resolve({ if (self.mode === 'add') {
message: 'You have saved this template' self.resolve({
}); message: 'You have added a new template'
});
} else if (self.mode === 'edit') {
self.resolve({
message: 'You have saved this template'
});
}
} }
self.showState = false; self.showState = false;
@@ -782,11 +832,11 @@ export default {
} }
}, },
duplicate() { duplicate() {
if (this.mode !== 'view') { if (this.type !== 'transaction' || this.mode !== 'view') {
return; return;
} }
this.editTransactionId = null; this.editId = null;
this.transaction.id = null; this.transaction.id = null;
this.transaction.time = getCurrentUnixTime(); this.transaction.time = getCurrentUnixTime();
this.transaction.timeZone = this.settingsStore.appSettings.timeZone; this.transaction.timeZone = this.settingsStore.appSettings.timeZone;
@@ -795,7 +845,7 @@ export default {
this.mode = 'add'; this.mode = 'add';
}, },
edit() { edit() {
if (this.mode !== 'view') { if (this.type !== 'transaction' || this.mode !== 'view') {
return; return;
} }
@@ -804,7 +854,7 @@ export default {
remove() { remove() {
const self = this; const self = this;
if (self.mode !== 'view') { if (this.type !== 'transaction' || self.mode !== 'view') {
return; return;
} }