mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 01:34:24 +08:00
code refactor
This commit is contained in:
@@ -384,18 +384,10 @@ export default {
|
||||
self.loading = true;
|
||||
|
||||
self.editAccountId = query.id;
|
||||
self.$services.getAccount({
|
||||
id: self.editAccountId
|
||||
}).then(response => {
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
self.$toast('Unable to get account');
|
||||
router.back();
|
||||
return;
|
||||
}
|
||||
|
||||
const account = data.result;
|
||||
self.$store.dispatch('getAccount', {
|
||||
accountId: self.editAccountId
|
||||
}).then(account => {
|
||||
self.account.id = account.id;
|
||||
self.account.category = account.category;
|
||||
self.account.type = account.type;
|
||||
@@ -406,6 +398,7 @@ export default {
|
||||
self.account.balance = account.balance;
|
||||
self.account.comment = account.comment;
|
||||
self.account.visible = !account.hidden;
|
||||
self.subAccounts = [];
|
||||
|
||||
if (account.subAccounts && account.subAccounts.length > 0) {
|
||||
for (let i = 0; i < account.subAccounts.length; i++) {
|
||||
@@ -431,13 +424,10 @@ export default {
|
||||
|
||||
self.loading = false;
|
||||
}).catch(error => {
|
||||
self.$logger.error('failed to load account info', error);
|
||||
self.loading = false;
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
router.back();
|
||||
} else if (!error.processed) {
|
||||
self.$toast('Unable to get account');
|
||||
if (!error.processed) {
|
||||
self.$toast(error.message || error);
|
||||
router.back();
|
||||
}
|
||||
});
|
||||
@@ -550,29 +540,16 @@ export default {
|
||||
subAccounts: self.account.type === self.$constants.account.allAccountTypes.SingleAccount ? null : subAccounts,
|
||||
};
|
||||
|
||||
let promise = null;
|
||||
|
||||
if (!self.editAccountId) {
|
||||
promise = self.$services.addAccount(submitAccount);
|
||||
} else {
|
||||
if (self.editAccountId) {
|
||||
submitAccount.id = self.account.id;
|
||||
submitAccount.hidden = !self.account.visible;
|
||||
promise = self.$services.modifyAccount(submitAccount);
|
||||
}
|
||||
|
||||
promise.then(response => {
|
||||
self.$store.dispatch('saveAccount', {
|
||||
account: submitAccount
|
||||
}).then(() => {
|
||||
self.submitting = false;
|
||||
self.$hideLoading();
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
if (!self.editAccountId) {
|
||||
self.$toast('Unable to add account');
|
||||
} else {
|
||||
self.$toast('Unable to save account');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self.editAccountId) {
|
||||
self.$toast('You have added a new account');
|
||||
@@ -582,19 +559,11 @@ export default {
|
||||
|
||||
router.back();
|
||||
}).catch(error => {
|
||||
self.$logger.error('failed to save account', error);
|
||||
|
||||
self.submitting = false;
|
||||
self.$hideLoading();
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
} else if (!error.processed) {
|
||||
if (!self.editAccountId) {
|
||||
self.$toast('Unable to add account');
|
||||
} else {
|
||||
self.$toast('Unable to save account');
|
||||
}
|
||||
if (!error.processed) {
|
||||
self.$toast(error.message || error);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
</f7-card-content>
|
||||
</f7-card>
|
||||
|
||||
<f7-card v-for="accountCategory in usedAccountCategories" :key="accountCategory.id" v-show="showHidden || hasShownAccount(accountCategory)">
|
||||
<f7-card v-for="accountCategory in allAccountCategories" :key="accountCategory.id" v-show="(showHidden && hasAccount(accountCategory, false)) || hasAccount(accountCategory, true)">
|
||||
<f7-card-header>
|
||||
<small :style="{ opacity: 0.6 }">
|
||||
<span>{{ $t(accountCategory.name) }}</span>
|
||||
@@ -124,12 +124,12 @@
|
||||
</small>
|
||||
</f7-card-header>
|
||||
<f7-card-content class="no-safe-areas" :padding="false">
|
||||
<f7-list sortable :sortable-enabled="sortable" @sortable:sort="onSort">
|
||||
<f7-list sortable :sortable-enabled="sortable" @sortable:sort="onSort" v-if="categorizedAccounts[accountCategory.id]">
|
||||
<f7-list-item v-for="account in categorizedAccounts[accountCategory.id].accounts" v-show="showHidden || !account.hidden"
|
||||
:key="account.id" :id="account | accountDomId"
|
||||
:class="{ 'nested-list-item': true, 'has-child-list-item': account.type === $constants.account.allAccountTypes.MultiSubAccounts }"
|
||||
:after="accountBalance(account) | currency(account.currency)"
|
||||
:link="account.type === $constants.account.allAccountTypes.SingleAccount ? '/transaction/list?accountId=' + account.id : null"
|
||||
:link="!sortable && account.type === $constants.account.allAccountTypes.SingleAccount ? '/transaction/list?accountId=' + account.id : null"
|
||||
swipeout @taphold.native="setSortable()"
|
||||
>
|
||||
<f7-block slot="title" class="no-padding">
|
||||
@@ -147,7 +147,7 @@
|
||||
<f7-list-item class="no-sortable nested-list-item-child" v-for="subAccount in account.subAccounts" v-show="showHidden || !subAccount.hidden"
|
||||
:key="subAccount.id" :id="subAccount | accountDomId"
|
||||
:title="subAccount.name" :after="accountBalance(subAccount) | currency(subAccount.currency)"
|
||||
:link="'/transaction/list?accountId=' + subAccount.id"
|
||||
:link="!sortable ? '/transaction/list?accountId=' + subAccount.id : null"
|
||||
>
|
||||
<f7-icon slot="media" :icon="subAccount.icon | accountIcon"
|
||||
:style="subAccount.color | accountIconStyle('var(--default-icon-color)')">
|
||||
@@ -201,7 +201,6 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
categorizedAccounts: {},
|
||||
loading: true,
|
||||
showHidden: false,
|
||||
sortable: false,
|
||||
@@ -217,61 +216,22 @@ export default {
|
||||
defaultCurrency() {
|
||||
return this.$user.getUserInfo() ? this.$user.getUserInfo().defaultCurrency : this.$t('default.currency');
|
||||
},
|
||||
allAccountCategories() {
|
||||
return this.$constants.account.allCategories;
|
||||
},
|
||||
categorizedAccounts() {
|
||||
return this.$store.state.allCategorizedAccounts;
|
||||
},
|
||||
allAccountCount() {
|
||||
let allAccountCount = 0;
|
||||
|
||||
for (let category in this.categorizedAccounts) {
|
||||
if (!Object.prototype.hasOwnProperty.call(this.categorizedAccounts, category)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
allAccountCount += this.categorizedAccounts[category].accounts.length;
|
||||
}
|
||||
|
||||
return allAccountCount;
|
||||
return this.$store.getters.allAvailableAccountsCount;
|
||||
},
|
||||
noAvailableAccount() {
|
||||
let allAccountCount = 0;
|
||||
let shownAccountCount = 0;
|
||||
|
||||
for (let category in this.categorizedAccounts) {
|
||||
if (!Object.prototype.hasOwnProperty.call(this.categorizedAccounts, category)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const accountList = this.categorizedAccounts[category].accounts;
|
||||
|
||||
for (let i = 0; i < accountList.length; i++) {
|
||||
if (!accountList[i].hidden) {
|
||||
shownAccountCount++;
|
||||
}
|
||||
|
||||
allAccountCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.showHidden) {
|
||||
return allAccountCount < 1;
|
||||
return this.$store.getters.allAvailableAccountsCount < 1;
|
||||
} else {
|
||||
return shownAccountCount < 1;
|
||||
return this.$store.getters.allVisibleAccountsCount < 1;
|
||||
}
|
||||
},
|
||||
usedAccountCategories() {
|
||||
const allAccountCategories = this.$constants.account.allCategories;
|
||||
const usedAccountCategories = [];
|
||||
|
||||
for (let i = 0; i < allAccountCategories.length; i++) {
|
||||
const accountCategory = allAccountCategories[i];
|
||||
|
||||
if (this.categorizedAccounts[accountCategory.id] &&
|
||||
this.$utilities.isArray(this.categorizedAccounts[accountCategory.id].accounts) &&
|
||||
this.categorizedAccounts[accountCategory.id].accounts.length) {
|
||||
usedAccountCategories.push(accountCategory);
|
||||
}
|
||||
}
|
||||
|
||||
return usedAccountCategories;
|
||||
},
|
||||
netAssets() {
|
||||
if (!this.showAccountBalance) {
|
||||
return '***';
|
||||
@@ -369,36 +329,23 @@ export default {
|
||||
|
||||
self.loading = true;
|
||||
|
||||
self.$services.getAllAccounts({ visibleOnly: false }).then(response => {
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
self.$toast('Unable to get account list');
|
||||
router.back();
|
||||
return;
|
||||
}
|
||||
|
||||
self.categorizedAccounts = self.$utilities.getCategorizedAccounts(data.result);
|
||||
self.$store.dispatch('loadAllAccounts', {
|
||||
force: false
|
||||
}).then(() => {
|
||||
self.loading = false;
|
||||
}).catch(error => {
|
||||
self.$logger.error('failed to load account list', error);
|
||||
self.loading = false;
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
router.back();
|
||||
} else if (!error.processed) {
|
||||
self.$toast('Unable to get account list');
|
||||
if (!error.processed) {
|
||||
self.$toast(error.message || error);
|
||||
router.back();
|
||||
}
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
onPageAfterIn() {
|
||||
const self = this;
|
||||
const previousRoute = self.$f7router.previousRoute;
|
||||
|
||||
if (previousRoute && (previousRoute.path === '/account/add' || previousRoute.path === '/account/edit') && !self.loading) {
|
||||
self.reload(null);
|
||||
if (this.$store.state.accountListStateInvalid && !this.loading) {
|
||||
this.reload(null);
|
||||
}
|
||||
},
|
||||
reload(done) {
|
||||
@@ -409,34 +356,23 @@ export default {
|
||||
|
||||
const self = this;
|
||||
|
||||
self.$services.getAllAccounts({ visibleOnly: false }).then(response => {
|
||||
self.$store.dispatch('loadAllAccounts', {
|
||||
force: true
|
||||
}).then(() => {
|
||||
if (done) {
|
||||
done();
|
||||
}
|
||||
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
self.$toast('Unable to get account list');
|
||||
return;
|
||||
}
|
||||
|
||||
self.categorizedAccounts = self.$utilities.getCategorizedAccounts(data.result);
|
||||
}).catch(error => {
|
||||
self.$logger.error('failed to reload account list', error);
|
||||
|
||||
if (done) {
|
||||
done();
|
||||
}
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
} else if (!error.processed) {
|
||||
self.$toast('Unable to get account list');
|
||||
if (!error.processed) {
|
||||
self.$toast(error.message || error);
|
||||
}
|
||||
});
|
||||
},
|
||||
hasShownAccount(accountCategory) {
|
||||
hasAccount(accountCategory, visibleOnly) {
|
||||
if (!this.categorizedAccounts[accountCategory.id] ||
|
||||
!this.categorizedAccounts[accountCategory.id].accounts ||
|
||||
!this.categorizedAccounts[accountCategory.id].accounts.length) {
|
||||
@@ -448,7 +384,7 @@ export default {
|
||||
for (let i = 0; i < this.categorizedAccounts[accountCategory.id].accounts.length; i++) {
|
||||
const account = this.categorizedAccounts[accountCategory.id].accounts[i];
|
||||
|
||||
if (!account.hidden) {
|
||||
if (!visibleOnly || !account.hidden) {
|
||||
shownCount++;
|
||||
}
|
||||
}
|
||||
@@ -528,30 +464,27 @@ export default {
|
||||
this.displayOrderModified = false;
|
||||
},
|
||||
onSort(event) {
|
||||
const self = this;
|
||||
|
||||
if (!event || !event.el || !event.el.id || event.el.id.indexOf('account_') !== 0) {
|
||||
this.$toast('Unable to move account');
|
||||
self.$toast('Unable to move account');
|
||||
return;
|
||||
}
|
||||
|
||||
const id = event.el.id.substr(8); // account_
|
||||
const account = this.$utilities.getAccountByAccountId(this.categorizedAccounts, id);
|
||||
|
||||
if (!account ||
|
||||
!this.categorizedAccounts[account.category] ||
|
||||
!this.categorizedAccounts[account.category].accounts ||
|
||||
!this.categorizedAccounts[account.category].accounts[event.to]) {
|
||||
this.$toast('Unable to move account');
|
||||
return;
|
||||
}
|
||||
|
||||
const accountList = this.categorizedAccounts[account.category].accounts;
|
||||
accountList.splice(event.to, 0, accountList.splice(event.from, 1)[0]);
|
||||
|
||||
this.displayOrderModified = true;
|
||||
self.$store.dispatch('changeAccountDisplayOrder', {
|
||||
accountId: id,
|
||||
from: event.from,
|
||||
to: event.to
|
||||
}).then(() => {
|
||||
self.displayOrderModified = true;
|
||||
}).catch(error => {
|
||||
self.$toast(error.message || error);
|
||||
});
|
||||
},
|
||||
saveSortResult() {
|
||||
const self = this;
|
||||
const newDisplayOrders = [];
|
||||
|
||||
if (!self.displayOrderModified) {
|
||||
self.showHidden = false;
|
||||
@@ -560,50 +493,21 @@ export default {
|
||||
}
|
||||
|
||||
self.displayOrderSaving = true;
|
||||
|
||||
for (let category in self.categorizedAccounts) {
|
||||
if (!Object.prototype.hasOwnProperty.call(self.categorizedAccounts, category)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const accountList = self.categorizedAccounts[category].accounts;
|
||||
|
||||
for (let i = 0; i < accountList.length; i++) {
|
||||
newDisplayOrders.push({
|
||||
id: accountList[i].id,
|
||||
displayOrder: i + 1
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
self.$showLoading();
|
||||
|
||||
self.$services.moveAccount({
|
||||
newDisplayOrders: newDisplayOrders
|
||||
}).then(response => {
|
||||
self.$store.dispatch('updateAccountDisplayOrders').then(() => {
|
||||
self.displayOrderSaving = false;
|
||||
self.$hideLoading();
|
||||
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
self.$toast('Unable to move account');
|
||||
return;
|
||||
}
|
||||
|
||||
self.showHidden = false;
|
||||
self.sortable = false;
|
||||
self.displayOrderModified = false;
|
||||
}).catch(error => {
|
||||
self.$logger.error('failed to save accounts display order', error);
|
||||
|
||||
self.displayOrderSaving = false;
|
||||
self.$hideLoading();
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
} else if (!error.processed) {
|
||||
self.$toast('Unable to move account');
|
||||
if (!error.processed) {
|
||||
self.$toast(error.message || error);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -615,37 +519,16 @@ export default {
|
||||
|
||||
self.$showLoading();
|
||||
|
||||
self.$services.hideAccount({
|
||||
id: account.id,
|
||||
self.$store.dispatch('hideAccount', {
|
||||
account: account,
|
||||
hidden: hidden
|
||||
}).then(response => {
|
||||
}).then(() => {
|
||||
self.$hideLoading();
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
if (hidden) {
|
||||
self.$toast('Unable to hide this account');
|
||||
} else {
|
||||
self.$toast('Unable to unhide this account');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
account.hidden = hidden;
|
||||
}).catch(error => {
|
||||
self.$logger.error('failed to change account visibility', error);
|
||||
|
||||
self.$hideLoading();
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
} else if (!error.processed) {
|
||||
if (hidden) {
|
||||
self.$toast('Unable to hide this account');
|
||||
} else {
|
||||
self.$toast('Unable to unhide this account');
|
||||
}
|
||||
if (!error.processed) {
|
||||
self.$toast(error.message || error);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -669,34 +552,20 @@ export default {
|
||||
self.accountToDelete = null;
|
||||
self.$showLoading();
|
||||
|
||||
self.$services.deleteAccount({
|
||||
id: account.id
|
||||
}).then(response => {
|
||||
self.$hideLoading();
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
self.$toast('Unable to delete this account');
|
||||
return;
|
||||
self.$store.dispatch('deleteAccount', {
|
||||
account: account,
|
||||
beforeResolve: (done) => {
|
||||
app.swipeout.delete($$(`#${self.$options.filters.accountDomId(account)}`), () => {
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
app.swipeout.delete($$(`#${self.$options.filters.accountDomId(account)}`), () => {
|
||||
const accountList = self.categorizedAccounts[account.category].accounts;
|
||||
for (let i = 0; i < accountList.length; i++) {
|
||||
if (accountList[i].id === account.id) {
|
||||
accountList.splice(i, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}).then(() => {
|
||||
self.$hideLoading();
|
||||
}).catch(error => {
|
||||
self.$logger.error('failed to delete account', error);
|
||||
|
||||
self.$hideLoading();
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
} else if (!error.processed) {
|
||||
self.$toast('Unable to delete this account');
|
||||
if (!error.processed) {
|
||||
self.$toast(error.message || error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+112
-203
@@ -62,15 +62,15 @@
|
||||
</f7-icon>
|
||||
|
||||
<div class="list-item-valign-middle padding-left-half"
|
||||
v-if="!tag.editing">
|
||||
v-if="editingTag.id !== tag.id">
|
||||
{{ tag.name }}
|
||||
</div>
|
||||
<f7-input class="list-title-input padding-left-half"
|
||||
type="text"
|
||||
:placeholder="$t('Tag Title')"
|
||||
:value="tag.newName"
|
||||
v-else-if="tag.editing"
|
||||
@input="tag.newName = $event.target.value"
|
||||
:value="editingTag.name"
|
||||
v-else-if="editingTag.id === tag.id"
|
||||
@input="editingTag.name = $event.target.value"
|
||||
@keyup.enter.native="save(tag)">
|
||||
</f7-input>
|
||||
</div>
|
||||
@@ -80,30 +80,59 @@
|
||||
raised fill
|
||||
icon-f7="checkmark_alt"
|
||||
color="blue"
|
||||
v-if="tag.editing"
|
||||
@click="save(tag)">
|
||||
v-if="editingTag.id === tag.id"
|
||||
@click="save(editingTag)">
|
||||
</f7-button>
|
||||
<f7-button slot="after"
|
||||
class="no-padding margin-left-half"
|
||||
raised fill
|
||||
icon-f7="xmark"
|
||||
color="gray"
|
||||
v-if="tag.editing"
|
||||
@click="cancelSave(tag)">
|
||||
v-if="editingTag.id === tag.id"
|
||||
@click="cancelSave(editingTag)">
|
||||
</f7-button>
|
||||
<f7-swipeout-actions left v-if="sortable && !tag.editing">
|
||||
<f7-swipeout-actions left v-if="sortable && editingTag.id !== tag.id">
|
||||
<f7-swipeout-button :color="tag.hidden ? 'blue' : 'gray'" class="padding-left padding-right"
|
||||
overswipe close @click="hide(tag, !tag.hidden)">
|
||||
<f7-icon :f7="tag.hidden ? 'eye' : 'eye_slash'"></f7-icon>
|
||||
</f7-swipeout-button>
|
||||
</f7-swipeout-actions>
|
||||
<f7-swipeout-actions right v-if="!sortable && !tag.editing">
|
||||
<f7-swipeout-actions right v-if="!sortable && editingTag.id !== tag.id">
|
||||
<f7-swipeout-button color="orange" close :text="$t('Edit')" @click="edit(tag)"></f7-swipeout-button>
|
||||
<f7-swipeout-button color="red" class="padding-left padding-right" @click="remove(tag, false)">
|
||||
<f7-icon f7="trash"></f7-icon>
|
||||
</f7-swipeout-button>
|
||||
</f7-swipeout-actions>
|
||||
</f7-list-item>
|
||||
|
||||
<f7-list-item v-if="newTag">
|
||||
<f7-block slot="title" class="no-padding">
|
||||
<div class="display-flex">
|
||||
<f7-icon slot="media" f7="number"></f7-icon>
|
||||
<f7-input class="list-title-input padding-left-half"
|
||||
type="text"
|
||||
:placeholder="$t('Tag Title')"
|
||||
:value="newTag.name"
|
||||
@input="newTag.name = $event.target.value"
|
||||
@keyup.enter.native="save(newTag)">
|
||||
</f7-input>
|
||||
</div>
|
||||
</f7-block>
|
||||
<f7-button slot="after"
|
||||
:class="{ 'no-padding': true, 'disabled': !isTagModified(newTag) }"
|
||||
raised fill
|
||||
icon-f7="checkmark_alt"
|
||||
color="blue"
|
||||
@click="save(newTag)">
|
||||
</f7-button>
|
||||
<f7-button slot="after"
|
||||
class="no-padding margin-left-half"
|
||||
raised fill
|
||||
icon-f7="xmark"
|
||||
color="gray"
|
||||
@click="cancelSave(newTag)">
|
||||
</f7-button>
|
||||
</f7-list-item>
|
||||
</f7-list>
|
||||
</f7-card-content>
|
||||
</f7-card>
|
||||
@@ -133,7 +162,11 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
tags: [],
|
||||
newTag: null,
|
||||
editingTag: {
|
||||
id: '',
|
||||
name: ''
|
||||
},
|
||||
loading: true,
|
||||
showHidden: false,
|
||||
sortable: false,
|
||||
@@ -146,6 +179,9 @@ export default {
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
tags() {
|
||||
return this.$store.state.allTransactionTags;
|
||||
},
|
||||
noAvailableTag() {
|
||||
for (let i = 0; i < this.tags.length; i++) {
|
||||
if (this.showHidden || !this.tags[i].hidden) {
|
||||
@@ -156,13 +192,7 @@ export default {
|
||||
return true;
|
||||
},
|
||||
hasEditingTag() {
|
||||
for (let i = 0; i < this.tags.length; i++) {
|
||||
if (this.tags[i].editing) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return this.newTag || (this.editingTag.id && this.editingTag.id !== '');
|
||||
}
|
||||
},
|
||||
created() {
|
||||
@@ -171,30 +201,15 @@ export default {
|
||||
|
||||
self.loading = true;
|
||||
|
||||
self.$services.getAllTransactionTags().then(response => {
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
self.$toast('Unable to get tag list');
|
||||
router.back();
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < data.result.length; i++) {
|
||||
data.result[i].editing = false;
|
||||
data.result[i].newName = data.result[i].name;
|
||||
}
|
||||
|
||||
self.tags = data.result;
|
||||
self.$store.dispatch('loadAllTags', {
|
||||
force: false
|
||||
}).then(() => {
|
||||
self.loading = false;
|
||||
}).catch(error => {
|
||||
self.$logger.error('failed to load tag list', error);
|
||||
self.loading = false;
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
router.back();
|
||||
} else if (!error.processed) {
|
||||
self.$toast('Unable to get tag list');
|
||||
if (!error.processed) {
|
||||
self.$toast(error.message || error);
|
||||
router.back();
|
||||
}
|
||||
});
|
||||
@@ -208,35 +223,19 @@ export default {
|
||||
|
||||
const self = this;
|
||||
|
||||
self.$services.getAllTransactionTags().then(response => {
|
||||
self.$store.dispatch('loadAllTags', {
|
||||
force: true
|
||||
}).then(() => {
|
||||
if (done) {
|
||||
done();
|
||||
}
|
||||
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
self.$toast('Unable to get tag list');
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < data.result.length; i++) {
|
||||
data.result[i].editing = false;
|
||||
data.result[i].newName = data.result[i].name;
|
||||
}
|
||||
|
||||
self.tags = data.result;
|
||||
}).catch(error => {
|
||||
self.$logger.error('failed to reload tag list', error);
|
||||
|
||||
if (done) {
|
||||
done();
|
||||
}
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
} else if (!error.processed) {
|
||||
self.$toast('Unable to get category list');
|
||||
if (!error.processed) {
|
||||
self.$toast(error.message || error);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -250,33 +249,27 @@ export default {
|
||||
this.displayOrderModified = false;
|
||||
},
|
||||
onSort(event) {
|
||||
const self = this;
|
||||
|
||||
if (!event || !event.el || !event.el.id || event.el.id.indexOf('tag_') !== 0) {
|
||||
this.$toast('Unable to move tag');
|
||||
self.$toast('Unable to move tag');
|
||||
return;
|
||||
}
|
||||
|
||||
const id = event.el.id.substr(4); // tag_
|
||||
let tag = null;
|
||||
|
||||
for (let i = 0; i < this.tags.length; i++) {
|
||||
if (this.tags[i].id === id) {
|
||||
tag = this.tags[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!tag || !this.tags[event.to]) {
|
||||
this.$toast('Unable to move tag');
|
||||
return;
|
||||
}
|
||||
|
||||
this.tags.splice(event.to, 0, this.tags.splice(event.from, 1)[0]);
|
||||
|
||||
this.displayOrderModified = true;
|
||||
self.$store.dispatch('changeTagDisplayOrder', {
|
||||
tagId: id,
|
||||
from: event.from,
|
||||
to: event.to
|
||||
}).then(() => {
|
||||
self.displayOrderModified = true;
|
||||
}).catch(error => {
|
||||
self.$toast(error.message || error);
|
||||
});
|
||||
},
|
||||
saveSortResult() {
|
||||
const self = this;
|
||||
const newDisplayOrders = [];
|
||||
|
||||
if (!self.displayOrderModified) {
|
||||
self.showHidden = false;
|
||||
@@ -285,158 +278,87 @@ export default {
|
||||
}
|
||||
|
||||
self.displayOrderSaving = true;
|
||||
|
||||
for (let i = 0; i < self.tags.length; i++) {
|
||||
newDisplayOrders.push({
|
||||
id: self.tags[i].id,
|
||||
displayOrder: i + 1
|
||||
});
|
||||
}
|
||||
|
||||
self.$showLoading();
|
||||
|
||||
self.$services.moveTransactionTag({
|
||||
newDisplayOrders: newDisplayOrders
|
||||
}).then(response => {
|
||||
self.$store.dispatch('updateTagDisplayOrders').then(() => {
|
||||
self.displayOrderSaving = false;
|
||||
self.$hideLoading();
|
||||
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
self.$toast('Unable to move tag');
|
||||
return;
|
||||
}
|
||||
|
||||
self.showHidden = false;
|
||||
self.sortable = false;
|
||||
self.displayOrderModified = false;
|
||||
}).catch(error => {
|
||||
self.$logger.error('failed to save tags display order', error);
|
||||
|
||||
self.displayOrderSaving = false;
|
||||
self.$hideLoading();
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
} else if (!error.processed) {
|
||||
self.$toast('Unable to move tag');
|
||||
if (!error.processed) {
|
||||
self.$toast(error.message || error);
|
||||
}
|
||||
});
|
||||
},
|
||||
add() {
|
||||
this.tags.push({
|
||||
id: '',
|
||||
name: '',
|
||||
newName: '',
|
||||
hidden: false,
|
||||
editing: true
|
||||
});
|
||||
this.newTag = {
|
||||
name: ''
|
||||
};
|
||||
},
|
||||
edit(tag) {
|
||||
tag.newName = tag.name;
|
||||
tag.editing = true;
|
||||
this.editingTag.id = tag.id;
|
||||
this.editingTag.name = tag.name;
|
||||
},
|
||||
save(tag) {
|
||||
if (tag.newName === tag.name) {
|
||||
return;
|
||||
}
|
||||
|
||||
const self = this;
|
||||
|
||||
self.$showLoading();
|
||||
|
||||
let promise = null;
|
||||
|
||||
if (tag.id) {
|
||||
promise = self.$services.modifyTransactionTag({
|
||||
id: tag.id,
|
||||
name: tag.newName
|
||||
});
|
||||
} else {
|
||||
promise = self.$services.addTransactionTag({
|
||||
name: tag.newName
|
||||
});
|
||||
}
|
||||
|
||||
promise.then(response => {
|
||||
self.$store.dispatch('saveTag', {
|
||||
tag: tag
|
||||
}).then(() => {
|
||||
self.$hideLoading();
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
self.$toast('Unable to save this tag');
|
||||
return;
|
||||
if (tag.id) {
|
||||
this.editingTag.id = '';
|
||||
this.editingTag.name = '';
|
||||
} else {
|
||||
this.newTag = null;
|
||||
}
|
||||
|
||||
tag.id = data.result.id;
|
||||
tag.name = data.result.name;
|
||||
tag.hidden = data.result.hidden;
|
||||
tag.editing = false;
|
||||
}).catch(error => {
|
||||
self.$logger.error('failed to save tag', error);
|
||||
|
||||
self.$hideLoading();
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
} else if (!error.processed) {
|
||||
self.$toast('Unable to save this tag');
|
||||
if (!error.processed) {
|
||||
self.$toast(error.message || error);
|
||||
}
|
||||
});
|
||||
},
|
||||
cancelSave(tag) {
|
||||
if (tag.id) {
|
||||
tag.newName = '';
|
||||
this.editingTag.id = '';
|
||||
this.editingTag.name = '';
|
||||
} else {
|
||||
for (let i = 0; i < this.tags.length; i++) {
|
||||
if (this.tags[i] === tag) {
|
||||
this.tags.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.newTag = null;
|
||||
}
|
||||
|
||||
tag.editing = false;
|
||||
},
|
||||
isTagModified(tag) {
|
||||
return tag.newName !== tag.name;
|
||||
if (tag.id) {
|
||||
return this.editingTag.name !== '' && this.editingTag.name !== tag.name;
|
||||
} else {
|
||||
return tag.name !== '';
|
||||
}
|
||||
},
|
||||
hide(tag, hidden) {
|
||||
const self = this;
|
||||
|
||||
self.$showLoading();
|
||||
|
||||
self.$services.hideTransactionTag({
|
||||
id: tag.id,
|
||||
self.$store.dispatch('hideTag', {
|
||||
tag: tag,
|
||||
hidden: hidden
|
||||
}).then(response => {
|
||||
}).then(() => {
|
||||
self.$hideLoading();
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
if (hidden) {
|
||||
self.$toast('Unable to hide this tag');
|
||||
} else {
|
||||
self.$toast('Unable to unhide this tag');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
tag.hidden = hidden;
|
||||
}).catch(error => {
|
||||
self.$logger.error('failed to change tag visibility', error);
|
||||
|
||||
self.$hideLoading();
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
} else if (!error.processed) {
|
||||
if (hidden) {
|
||||
self.$toast('Unable to hide this tag');
|
||||
} else {
|
||||
self.$toast('Unable to unhide this tag');
|
||||
}
|
||||
if (!error.processed) {
|
||||
self.$toast(error.message || error);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -460,33 +382,20 @@ export default {
|
||||
self.tagToDelete = null;
|
||||
self.$showLoading();
|
||||
|
||||
self.$services.deleteTransactionTag({
|
||||
id: tag.id
|
||||
}).then(response => {
|
||||
self.$hideLoading();
|
||||
const data = response.data;
|
||||
|
||||
if (!data || !data.success || !data.result) {
|
||||
self.$toast('Unable to delete this tag');
|
||||
return;
|
||||
self.$store.dispatch('deleteTag', {
|
||||
tag: tag,
|
||||
beforeResolve: (done) => {
|
||||
app.swipeout.delete($$(`#${self.$options.filters.tagDomId(tag)}`), () => {
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
app.swipeout.delete($$(`#${self.$options.filters.tagDomId(tag)}`), () => {
|
||||
for (let i = 0; i < self.tags.length; i++) {
|
||||
if (self.tags[i].id === tag.id) {
|
||||
self.tags.splice(i, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}).then(() => {
|
||||
self.$hideLoading();
|
||||
}).catch(error => {
|
||||
self.$logger.error('failed to delete tag', error);
|
||||
|
||||
self.$hideLoading();
|
||||
|
||||
if (error.response && error.response.data && error.response.data.errorMessage) {
|
||||
self.$toast({ error: error.response.data });
|
||||
} else if (!error.processed) {
|
||||
self.$toast('Unable to delete this tag');
|
||||
if (!error.processed) {
|
||||
self.$toast(error.message || error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user