create transaction template and modify template name in edit dialog
This commit is contained in:
@@ -324,7 +324,6 @@ func startWebServer(c *cli.Context) error {
|
||||
apiV1Route.GET("/transaction/templates/list.json", bindApi(api.TransactionTemplates.TemplateListHandler))
|
||||
apiV1Route.GET("/transaction/templates/get.json", bindApi(api.TransactionTemplates.TemplateGetHandler))
|
||||
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/hide.json", bindApi(api.TransactionTemplates.TemplateHideHandler))
|
||||
apiV1Route.POST("/transaction/templates/move.json", bindApi(api.TransactionTemplates.TemplateMoveHandler))
|
||||
|
||||
@@ -36,6 +36,11 @@ func (a *TransactionTemplatesApi) TemplateListHandler(c *core.Context) (any, *er
|
||||
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()
|
||||
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)
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
maxOrderId, err := a.templates.GetMaxDisplayOrder(c, uid, templateCreateReq.TemplateType)
|
||||
@@ -139,50 +154,6 @@ func (a *TransactionTemplatesApi) TemplateCreateHandler(c *core.Context) (any, *
|
||||
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
|
||||
func (a *TransactionTemplatesApi) TemplateModifyHandler(c *core.Context) (any, *errs.Error) {
|
||||
var templateModifyReq models.TransactionTemplateModifyRequest
|
||||
@@ -193,6 +164,11 @@ func (a *TransactionTemplatesApi) TemplateModifyHandler(c *core.Context) (any, *
|
||||
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()
|
||||
template, err := a.templates.GetTemplateByTemplateId(c, uid, templateModifyReq.Id)
|
||||
|
||||
@@ -204,6 +180,7 @@ func (a *TransactionTemplatesApi) TemplateModifyHandler(c *core.Context) (any, *
|
||||
newTemplate := &models.TransactionTemplate{
|
||||
TemplateId: template.TemplateId,
|
||||
Uid: uid,
|
||||
Name: templateModifyReq.Name,
|
||||
Type: templateModifyReq.Type,
|
||||
CategoryId: templateModifyReq.CategoryId,
|
||||
AccountId: templateModifyReq.SourceAccountId,
|
||||
@@ -215,7 +192,8 @@ func (a *TransactionTemplatesApi) TemplateModifyHandler(c *core.Context) (any, *
|
||||
Comment: templateModifyReq.Comment,
|
||||
}
|
||||
|
||||
if newTemplate.Type == template.Type &&
|
||||
if newTemplate.Name == template.Name &&
|
||||
newTemplate.Type == template.Type &&
|
||||
newTemplate.CategoryId == template.CategoryId &&
|
||||
newTemplate.AccountId == template.AccountId &&
|
||||
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)
|
||||
|
||||
serverUtcOffset := utils.GetServerTimezoneOffsetMinutes()
|
||||
newTemplate.Name = template.Name
|
||||
newTemplate.TemplateType = template.TemplateType
|
||||
newTemplate.DisplayOrder = template.DisplayOrder
|
||||
newTemplate.Hidden = template.Hidden
|
||||
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 {
|
||||
return &models.TransactionTemplate{
|
||||
Uid: uid,
|
||||
TemplateType: templateCreateReq.TemplateType,
|
||||
Name: templateCreateReq.Name,
|
||||
Type: models.TRANSACTION_TYPE_EXPENSE,
|
||||
DisplayOrder: order,
|
||||
Uid: uid,
|
||||
TemplateType: templateCreateReq.TemplateType,
|
||||
Name: templateCreateReq.Name,
|
||||
Type: templateCreateReq.Type,
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import "net/http"
|
||||
|
||||
// Error codes related to transaction templates
|
||||
var (
|
||||
ErrTransactionTemplateIdInvalid = NewNormalError(NormalSubcategoryTemplate, 0, http.StatusBadRequest, "transaction template id is invalid")
|
||||
ErrTransactionTemplateNotFound = NewNormalError(NormalSubcategoryTemplate, 1, http.StatusBadRequest, "transaction template not found")
|
||||
ErrTransactionTemplateIdInvalid = NewNormalError(NormalSubcategoryTemplate, 0, http.StatusBadRequest, "transaction template id is invalid")
|
||||
ErrTransactionTemplateNotFound = NewNormalError(NormalSubcategoryTemplate, 1, http.StatusBadRequest, "transaction template not found")
|
||||
ErrTransactionTemplateTypeInvalid = NewNormalError(NormalSubcategoryTemplate, 2, http.StatusBadRequest, "transaction template type is invalid")
|
||||
)
|
||||
|
||||
@@ -39,7 +39,7 @@ type TransactionTemplate struct {
|
||||
|
||||
// TransactionTemplateListRequest represents all parameters of transaction template list request
|
||||
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
|
||||
@@ -49,9 +49,18 @@ type TransactionTemplateGetRequest struct {
|
||||
|
||||
// TransactionTemplateCreateRequest represents all parameters of transaction template creation request
|
||||
type TransactionTemplateCreateRequest struct {
|
||||
TemplateType TransactionTemplateType `json:"templateType" binding:"required,min=1,max=1"`
|
||||
Name string `json:"name" binding:"required,notBlank,max=32"`
|
||||
ClientSessionId string `json:"clientSessionId"`
|
||||
TemplateType TransactionTemplateType `json:"templateType"`
|
||||
Name string `json:"name" binding:"required,notBlank,max=32"`
|
||||
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
|
||||
@@ -63,8 +72,9 @@ type TransactionTemplateModifyNameRequest struct {
|
||||
// TransactionTemplateModifyRequest represents all parameters of transaction template modification request
|
||||
type TransactionTemplateModifyRequest struct {
|
||||
Id int64 `json:"id,string" binding:"required,min=1"`
|
||||
Name string `json:"name" binding:"required,notBlank,max=32"`
|
||||
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"`
|
||||
DestinationAccountId int64 `json:"destinationAccountId,string" binding:"min=0"`
|
||||
SourceAmount int64 `json:"sourceAmount" binding:"min=-99999999999,max=99999999999"`
|
||||
|
||||
@@ -125,28 +125,7 @@ func (s *TransactionTemplateService) ModifyTemplate(c *core.Context, template *m
|
||||
template.UpdatedUnixTime = time.Now().Unix()
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
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
|
||||
|
||||
+12
-8
@@ -523,22 +523,26 @@ export default {
|
||||
getTransactionTemplate: ({ 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', {
|
||||
templateType,
|
||||
name,
|
||||
type,
|
||||
categoryId,
|
||||
sourceAccountId,
|
||||
destinationAccountId,
|
||||
sourceAmount,
|
||||
destinationAmount,
|
||||
hideAmount,
|
||||
tagIds,
|
||||
comment,
|
||||
clientSessionId
|
||||
});
|
||||
},
|
||||
modifyTransactionNameTemplate: ({ id, name }) => {
|
||||
return axios.post('v1/transaction/templates/modify_name.json', {
|
||||
id,
|
||||
name
|
||||
});
|
||||
},
|
||||
modifyTransactionTemplate: ({ id, type, categoryId, sourceAccountId, destinationAccountId, sourceAmount, destinationAmount, hideAmount, tagIds, comment }) => {
|
||||
modifyTransactionTemplate: ({ id, name, type, categoryId, sourceAccountId, destinationAccountId, sourceAmount, destinationAmount, hideAmount, tagIds, comment }) => {
|
||||
return axios.post('v1/transaction/templates/modify.json', {
|
||||
id,
|
||||
name,
|
||||
type,
|
||||
categoryId,
|
||||
sourceAccountId,
|
||||
|
||||
+6
-1
@@ -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 index not found': 'Transaction tag index is not found',
|
||||
'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 too much': 'There are too many query items',
|
||||
'query items have invalid item': 'There is invalid item in query items',
|
||||
@@ -738,6 +741,7 @@ export default {
|
||||
'month': 'Month',
|
||||
'page': 'Page Index',
|
||||
'count': 'Count',
|
||||
'templateType': 'Template Type',
|
||||
'comment': 'Description',
|
||||
},
|
||||
'parameterizedError': {
|
||||
@@ -788,7 +792,6 @@ export default {
|
||||
'Show': 'Show',
|
||||
'Hide': 'Hide',
|
||||
'Version': 'Version',
|
||||
'Modify Name': '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': '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': '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',
|
||||
|
||||
@@ -702,6 +702,9 @@ export default {
|
||||
'transaction tag is in use and cannot be deleted': '交易标签正在被使用,无法删除',
|
||||
'transaction tag index not found': '交易标签索引不存在',
|
||||
'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 too much': '请求项目过多',
|
||||
'query items have invalid item': '请求项目中有非法项目',
|
||||
@@ -738,6 +741,7 @@ export default {
|
||||
'month': '月份',
|
||||
'page': '页码索引',
|
||||
'count': '数量',
|
||||
'templateType': '模板类型',
|
||||
'comment': '描述',
|
||||
},
|
||||
'parameterizedError': {
|
||||
@@ -788,7 +792,6 @@ export default {
|
||||
'Show': '显示',
|
||||
'Hide': '隐藏',
|
||||
'Version': '版本',
|
||||
'Modify Name': '修改名称',
|
||||
'Edit': '编辑',
|
||||
'Remove': '移除',
|
||||
'Delete': '删除',
|
||||
@@ -1021,6 +1024,7 @@ export default {
|
||||
'Transactions': '交易',
|
||||
'Add Transaction': '添加交易',
|
||||
'Edit Transaction': '编辑交易',
|
||||
'Add Transaction Template': '添加交易模板',
|
||||
'Edit Transaction Template': '编辑交易模板',
|
||||
'Modify Balance': '修改余额',
|
||||
'Expense Amount': '支出金额',
|
||||
@@ -1278,6 +1282,7 @@ export default {
|
||||
'Template list has been updated': '模板列表已更新',
|
||||
'Unable to add template': '无法添加模板',
|
||||
'Unable to save template': '无法保存模板',
|
||||
'You have added a new template': '您已经添加新模板',
|
||||
'Unable to move template': '无法移动模板',
|
||||
'Unable to retrieve template': '无法获取模板',
|
||||
'Unable to hide this template': '无法隐藏该模板',
|
||||
|
||||
@@ -129,13 +129,6 @@ export const useTransactionTemplatesStore = defineStore('transactionTemplates',
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
generateNewTransactionTemplateModel(templateType) {
|
||||
return {
|
||||
id: '',
|
||||
templateType: templateType,
|
||||
name: ''
|
||||
};
|
||||
},
|
||||
updateTransactionTemplateListInvalidState(templateType, invalidState) {
|
||||
this.transactionTemplateListStatesInvalid[templateType] = invalidState;
|
||||
},
|
||||
@@ -217,59 +210,12 @@ export const useTransactionTemplatesStore = defineStore('transactionTemplates',
|
||||
});
|
||||
});
|
||||
},
|
||||
saveTemplateName({ template }) {
|
||||
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 }) {
|
||||
saveTemplateContent({ template, isEdit, clientSessionId }) {
|
||||
const self = this;
|
||||
|
||||
const submitTemplate = {
|
||||
id: template.id,
|
||||
templateType: template.templateType,
|
||||
name: template.name,
|
||||
type: template.type,
|
||||
sourceAccountId: template.sourceAccountId,
|
||||
sourceAmount: template.sourceAmount,
|
||||
@@ -280,6 +226,10 @@ export const useTransactionTemplatesStore = defineStore('transactionTemplates',
|
||||
comment: template.comment
|
||||
};
|
||||
|
||||
if (clientSessionId) {
|
||||
submitTemplate.clientSessionId = clientSessionId;
|
||||
}
|
||||
|
||||
if (template.type === transactionConstants.allTransactionTypes.Expense) {
|
||||
submitTemplate.categoryId = template.expenseCategory;
|
||||
} else if (template.type === transactionConstants.allTransactionTypes.Income) {
|
||||
@@ -292,16 +242,36 @@ export const useTransactionTemplatesStore = defineStore('transactionTemplates',
|
||||
return Promise.reject('An error occurred');
|
||||
}
|
||||
|
||||
if (isEdit) {
|
||||
submitTemplate.id = template.id;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}).catch(error => {
|
||||
@@ -310,7 +280,11 @@ export const useTransactionTemplatesStore = defineStore('transactionTemplates',
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
reject({ error: error.response.data });
|
||||
} 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 {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
<div class="title-and-toolbar d-flex align-center">
|
||||
<span>{{ $t('Transaction Templates') }}</span>
|
||||
<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"
|
||||
:disabled="loading || updating || hasEditingTemplateName" @click="saveSortResult"
|
||||
:disabled="loading || updating" @click="saveSortResult"
|
||||
v-if="displayOrderModified">{{ $t('Save Display Order') }}</v-btn>
|
||||
<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">
|
||||
<template #loader>
|
||||
<v-progress-circular indeterminate size="20"/>
|
||||
@@ -21,7 +21,7 @@
|
||||
</v-btn>
|
||||
<v-spacer/>
|
||||
<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-menu activator="parent">
|
||||
<v-list>
|
||||
@@ -50,7 +50,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody v-if="loading && noAvailableTemplate && !newTemplate">
|
||||
<tbody v-if="loading && noAvailableTemplate">
|
||||
<tr :key="itemIdx" v-for="itemIdx in [ 1, 2, 3 ]">
|
||||
<td class="px-0">
|
||||
<v-skeleton-loader type="text" :loading="true"></v-skeleton-loader>
|
||||
@@ -58,7 +58,7 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
<tbody v-if="!loading && noAvailableTemplate && !newTemplate">
|
||||
<tbody v-if="!loading && noAvailableTemplate">
|
||||
<tr>
|
||||
<td>{{ $t('No available template') }}</td>
|
||||
</tr>
|
||||
@@ -68,7 +68,6 @@
|
||||
item-key="id"
|
||||
handle=".drag-handle"
|
||||
ghost-class="dragging-item"
|
||||
:class="{ 'has-bottom-border': newTemplate }"
|
||||
:disabled="noAvailableTemplate"
|
||||
v-model="templates"
|
||||
@change="onMove">
|
||||
@@ -76,7 +75,7 @@
|
||||
<tr class="transaction-templates-table-row text-sm" v-if="showHidden || !element.hidden">
|
||||
<td>
|
||||
<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"
|
||||
location="bottom right" offset-x="8" :icon="icons.hide"
|
||||
v-if="element.hidden">
|
||||
@@ -86,24 +85,6 @@
|
||||
<span class="transaction-template-name">{{ element.name }}</span>
|
||||
</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-btn class="px-2 ml-2" color="default"
|
||||
@@ -112,7 +93,6 @@
|
||||
:prepend-icon="element.hidden ? icons.show : icons.hide"
|
||||
:loading="templateHiding[element.id]"
|
||||
:disabled="loading || updating"
|
||||
v-if="editingTemplateName.id !== element.id"
|
||||
@click="hide(element, !element.hidden)">
|
||||
<template #loader>
|
||||
<v-progress-circular indeterminate size="20" width="2"/>
|
||||
@@ -123,22 +103,7 @@
|
||||
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="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)">
|
||||
<template #loader>
|
||||
<v-progress-circular indeterminate size="20" width="2"/>
|
||||
@@ -151,31 +116,12 @@
|
||||
:prepend-icon="icons.remove"
|
||||
:loading="templateRemoving[element.id]"
|
||||
:disabled="loading || updating"
|
||||
v-if="editingTemplateName.id !== element.id"
|
||||
@click="remove(element)">
|
||||
<template #loader>
|
||||
<v-progress-circular indeterminate size="20" width="2"/>
|
||||
</template>
|
||||
{{ $t('Delete') }}
|
||||
</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">
|
||||
<v-icon :class="!loading && !updating && availableTemplateCount > 1 ? 'drag-handle' : 'disabled'"
|
||||
:icon="icons.drag"/>
|
||||
@@ -186,52 +132,12 @@
|
||||
</tr>
|
||||
</template>
|
||||
</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-card>
|
||||
</v-col>
|
||||
</v-row>
|
||||
|
||||
<edit-dialog ref="editDialog" :persistent="true" />
|
||||
<edit-dialog ref="editDialog" type="template" :persistent="true" />
|
||||
|
||||
<confirm-dialog ref="confirmDialog"/>
|
||||
<snack-bar ref="snackbar" />
|
||||
@@ -244,7 +150,6 @@ import { mapStores } from 'pinia';
|
||||
import { useTransactionTemplatesStore } from '@/stores/transactionTemplate.js';
|
||||
|
||||
import templateConstants from '@/consts/template.js';
|
||||
import { generateRandomUUID } from '@/lib/misc.js';
|
||||
|
||||
import {
|
||||
mdiRefresh,
|
||||
@@ -267,11 +172,8 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
templateType: templateConstants.allTemplateTypes.Normal,
|
||||
newTemplate: null,
|
||||
editingTemplateName: {},
|
||||
loading: true,
|
||||
updating: false,
|
||||
templateNameUpdating: {},
|
||||
templateHiding: {},
|
||||
templateRemoving: {},
|
||||
displayOrderModified: false,
|
||||
@@ -315,9 +217,6 @@ export default {
|
||||
}
|
||||
|
||||
return count;
|
||||
},
|
||||
hasEditingTemplateName() {
|
||||
return !!(this.newTemplate || (this.editingTemplateName && this.editingTemplateName.id && this.editingTemplateName.id !== ''));
|
||||
}
|
||||
},
|
||||
created() {
|
||||
@@ -340,10 +239,6 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
reload() {
|
||||
if (this.hasEditingTemplateName) {
|
||||
return;
|
||||
}
|
||||
|
||||
const self = this;
|
||||
self.loading = true;
|
||||
|
||||
@@ -410,56 +305,27 @@ export default {
|
||||
});
|
||||
},
|
||||
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;
|
||||
|
||||
self.updating = true;
|
||||
self.templateNameUpdating[template.id || null] = true;
|
||||
|
||||
self.transactionTemplatesStore.saveTemplateName({
|
||||
template: template
|
||||
}).then(() => {
|
||||
self.updating = false;
|
||||
self.templateNameUpdating[template.id || null] = false;
|
||||
|
||||
if (template.id) {
|
||||
self.editingTemplateName = {};
|
||||
} else {
|
||||
self.newTemplate = null;
|
||||
self.$refs.editDialog.open({
|
||||
templateType: self.templateType
|
||||
}).then(result => {
|
||||
if (result && result.message) {
|
||||
self.$refs.snackbar.showMessage(result.message);
|
||||
}
|
||||
}).catch(error => {
|
||||
self.updating = false;
|
||||
self.templateNameUpdating[template.id || null] = false;
|
||||
|
||||
if (!error.processed) {
|
||||
if (error) {
|
||||
self.$refs.snackbar.showError(error);
|
||||
}
|
||||
});
|
||||
},
|
||||
cancelSaveName(template) {
|
||||
if (template.id) {
|
||||
this.editingTemplateName = {};
|
||||
} else {
|
||||
this.newTemplate = null;
|
||||
}
|
||||
},
|
||||
edit(template) {
|
||||
const self = this;
|
||||
|
||||
self.$refs.editDialog.open({
|
||||
editTemplateId: template.id,
|
||||
id: template.id,
|
||||
currentTemplate: {
|
||||
name: template.name,
|
||||
type: template.type,
|
||||
categoryId: template.categoryId,
|
||||
sourceAccountId: template.sourceAccountId,
|
||||
@@ -474,21 +340,12 @@ export default {
|
||||
if (result && result.message) {
|
||||
self.$refs.snackbar.showMessage(result.message);
|
||||
}
|
||||
|
||||
self.reload(false);
|
||||
}).catch(error => {
|
||||
if (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) {
|
||||
const self = this;
|
||||
|
||||
|
||||
@@ -480,7 +480,7 @@
|
||||
:max-time="customMaxDatetime"
|
||||
v-model:show="showCustomDateRangeDialog"
|
||||
@dateRange:change="changeCustomDateFilter" />
|
||||
<edit-dialog ref="editDialog" :persistent="true" />
|
||||
<edit-dialog ref="editDialog" type="transaction" :persistent="true" />
|
||||
|
||||
<v-dialog width="800" v-model="showFilterAccountDialog">
|
||||
<account-filter-settings-card type="transactionListCurrent" :dialog-mode="true"
|
||||
|
||||
@@ -38,18 +38,18 @@
|
||||
</template>
|
||||
<v-card-text class="d-flex flex-column flex-md-row mt-md-4 pt-0">
|
||||
<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">
|
||||
<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>
|
||||
</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>
|
||||
</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>
|
||||
</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>
|
||||
</v-tab>
|
||||
</v-tabs>
|
||||
@@ -58,7 +58,7 @@
|
||||
<v-tab value="basicInfo">
|
||||
<span>{{ $t('Basic Information') }}</span>
|
||||
</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>
|
||||
</v-tab>
|
||||
</v-tabs>
|
||||
@@ -69,6 +69,16 @@
|
||||
<v-window-item value="basicInfo">
|
||||
<v-form class="mt-2">
|
||||
<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">
|
||||
<amount-input class="transaction-edit-amount font-weight-bold"
|
||||
:color="sourceAmountColor"
|
||||
@@ -177,7 +187,7 @@
|
||||
v-model="transaction.destinationAccountId">
|
||||
</two-column-select>
|
||||
</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
|
||||
:readonly="mode === 'view'"
|
||||
:disabled="loading || submitting"
|
||||
@@ -185,7 +195,7 @@
|
||||
v-model="transaction.time"
|
||||
@error="showDateTimeError" />
|
||||
</v-col>
|
||||
<v-col cols="12" md="6" v-if="mode !== 'editTemplate'">
|
||||
<v-col cols="12" md="6" v-if="type === 'transaction'">
|
||||
<v-autocomplete
|
||||
class="transaction-edit-timezone"
|
||||
item-title="displayNameWithUtcOffset"
|
||||
@@ -207,7 +217,7 @@
|
||||
</template>
|
||||
</v-autocomplete>
|
||||
</v-col>
|
||||
<v-col cols="12" md="12" v-if="mode !== 'editTemplate'">
|
||||
<v-col cols="12" md="12" v-if="type === 'transaction'">
|
||||
<v-select
|
||||
persistent-placeholder
|
||||
:readonly="mode === 'view'"
|
||||
@@ -368,6 +378,7 @@ import {
|
||||
export default {
|
||||
props: [
|
||||
'persistent',
|
||||
'type',
|
||||
'show'
|
||||
],
|
||||
expose: [
|
||||
@@ -381,7 +392,7 @@ export default {
|
||||
showState: false,
|
||||
mode: 'add',
|
||||
activeTab: 'basicInfo',
|
||||
editTransactionId: null,
|
||||
editId: null,
|
||||
originalTransactionEditable: false,
|
||||
clientSessionId: '',
|
||||
loading: true,
|
||||
@@ -404,15 +415,23 @@ export default {
|
||||
computed: {
|
||||
...mapStores(useSettingsStore, useUserStore, useAccountsStore, useTransactionCategoriesStore, useTransactionTagsStore, useTransactionsStore, useTransactionTemplatesStore, useExchangeRatesStore),
|
||||
title() {
|
||||
if (this.mode === 'add') {
|
||||
return 'Add Transaction';
|
||||
} else if (this.mode === 'edit') {
|
||||
return 'Edit Transaction';
|
||||
} else if (this.mode === 'editTemplate') {
|
||||
return 'Edit Transaction Template';
|
||||
} else {
|
||||
return 'Transaction Detail';
|
||||
if (this.type === 'transaction') {
|
||||
if (this.mode === 'add') {
|
||||
return 'Add Transaction';
|
||||
} else if (this.mode === 'edit') {
|
||||
return 'Edit Transaction';
|
||||
} else {
|
||||
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() {
|
||||
if (this.mode === 'add') {
|
||||
@@ -636,31 +655,48 @@ export default {
|
||||
self.transactionTagsStore.loadAllTags({ force: false })
|
||||
];
|
||||
|
||||
if (options && options.id) {
|
||||
if (options.currentTransaction) {
|
||||
self.setTransaction(options.currentTransaction, options, true, true);
|
||||
if (self.type === 'transaction') {
|
||||
if (options && options.id) {
|
||||
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';
|
||||
self.editTransactionId = options.id;
|
||||
if (options && 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 }));
|
||||
} else if (options && options.editTemplateId) {
|
||||
if (options.currentTemplate) {
|
||||
self.setTransaction(options.currentTemplate, options, false, false);
|
||||
}
|
||||
self.mode = 'edit';
|
||||
self.editId = options.id;
|
||||
self.transaction.id = options.id;
|
||||
|
||||
self.mode = 'editTemplate';
|
||||
self.transaction.id = options.editTemplateId;
|
||||
|
||||
promises.push(self.transactionTemplatesStore.getTemplate({ templateId: options.editTemplateId }));
|
||||
} else {
|
||||
self.mode = 'add';
|
||||
self.editTransactionId = null;
|
||||
|
||||
if (self.settingsStore.appSettings.autoGetCurrentGeoLocation
|
||||
&& !self.geoLocationStatus && !self.transaction.geoLocation) {
|
||||
self.updateGeoLocation(false);
|
||||
promises.push(self.transactionTemplatesStore.getTemplate({ templateId: self.editId }));
|
||||
} else {
|
||||
self.mode = 'add';
|
||||
self.editId = null;
|
||||
self.transaction.id = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -675,21 +711,27 @@ export default {
|
||||
}
|
||||
|
||||
Promise.all(promises).then(function (responses) {
|
||||
if (self.editTransactionId && !responses[3]) {
|
||||
if (self.editId && !responses[3]) {
|
||||
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;
|
||||
}
|
||||
|
||||
if (options && options.id && responses[3]) {
|
||||
if (self.type === 'transaction' && options && options.id && responses[3]) {
|
||||
const transaction = responses[3];
|
||||
self.setTransaction(transaction, options, true, true);
|
||||
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];
|
||||
self.setTransaction(template, options, false, false);
|
||||
self.transaction.templateType = template.templateType;
|
||||
self.transaction.name = template.name;
|
||||
} else {
|
||||
self.setTransaction(null, options, true, true);
|
||||
}
|
||||
@@ -716,7 +758,7 @@ export default {
|
||||
save() {
|
||||
const self = this;
|
||||
|
||||
if (self.mode === 'add' || self.mode === 'edit') {
|
||||
if (self.type === 'transaction' && (self.mode === 'add' || self.mode === 'edit')) {
|
||||
const doSubmit = function () {
|
||||
self.submitting = true;
|
||||
|
||||
@@ -757,18 +799,26 @@ export default {
|
||||
} else {
|
||||
doSubmit();
|
||||
}
|
||||
} else if (self.mode === 'editTemplate') {
|
||||
} else if (self.type === 'template' && (self.mode === 'add' || self.mode === 'edit')) {
|
||||
self.submitting = true;
|
||||
|
||||
self.transactionTemplatesStore.modifyTemplateContent({
|
||||
template: self.transaction
|
||||
self.transactionTemplatesStore.saveTemplateContent({
|
||||
template: self.transaction,
|
||||
isEdit: self.mode === 'edit',
|
||||
clientSessionId: self.clientSessionId
|
||||
}).then(() => {
|
||||
self.submitting = false;
|
||||
|
||||
if (self.resolve) {
|
||||
self.resolve({
|
||||
message: 'You have saved this template'
|
||||
});
|
||||
if (self.mode === 'add') {
|
||||
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;
|
||||
@@ -782,11 +832,11 @@ export default {
|
||||
}
|
||||
},
|
||||
duplicate() {
|
||||
if (this.mode !== 'view') {
|
||||
if (this.type !== 'transaction' || this.mode !== 'view') {
|
||||
return;
|
||||
}
|
||||
|
||||
this.editTransactionId = null;
|
||||
this.editId = null;
|
||||
this.transaction.id = null;
|
||||
this.transaction.time = getCurrentUnixTime();
|
||||
this.transaction.timeZone = this.settingsStore.appSettings.timeZone;
|
||||
@@ -795,7 +845,7 @@ export default {
|
||||
this.mode = 'add';
|
||||
},
|
||||
edit() {
|
||||
if (this.mode !== 'view') {
|
||||
if (this.type !== 'transaction' || this.mode !== 'view') {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -804,7 +854,7 @@ export default {
|
||||
remove() {
|
||||
const self = this;
|
||||
|
||||
if (self.mode !== 'view') {
|
||||
if (this.type !== 'transaction' || self.mode !== 'view') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user