Update autocomplete code for #3150

This commit is contained in:
James Cole
2020-07-23 06:19:34 +02:00
parent 0f840ad082
commit 162e791dfd
16 changed files with 93 additions and 459 deletions

View File

@@ -32,13 +32,12 @@
<select class="form-control" ref="currency_select" name="foreign_currency[]" @input="handleInput">
<option
v-for="currency in this.enabledCurrencies"
v-if="currency.enabled"
:value="currency.id"
:label="currency.name"
:label="currency.attributes.name"
:selected="value.currency_id === currency.id"
>
{{ currency.name }}
{{ currency.attributes.name }}
</option>
</select>
</div>
@@ -174,27 +173,32 @@
}
},
loadCurrencies: function () {
// console.log('loadCurrencies');
let URI = document.getElementsByTagName('base')[0].href + "json/currencies";
//console.log('loadCurrencies');
let URI = document.getElementsByTagName('base')[0].href + "api/v1/currencies";
axios.get(URI, {}).then((res) => {
this.currencies = [
{
name: this.no_currency,
id: 0,
enabled: true
attributes: {
name: this.no_currency,
enabled: true
},
}
];
this.enabledCurrencies = [
{
name: this.no_currency,
attributes: {
name: this.no_currency,
enabled: true
},
id: 0,
enabled: true
}
];
for (const key in res.data.data) {
if (res.data.data.hasOwnProperty(key) && /^0$|^[1-9]\d*$/.test(key) && key <= 4294967294) {
if (res.data.data[key].enabled) {
if (res.data.data[key].attributes.enabled) {
console.log(res.data.data[key].attributes);
this.currencies.push(res.data.data[key]);
this.enabledCurrencies.push(res.data.data[key]);
}

View File

@@ -28,7 +28,7 @@
<div class="col-sm-12">
<select name="piggy_bank[]" ref="piggy" @input="handleInput" class="form-control">
<optgroup v-for="(option, key) in this.piggies" v-bind:label="key">
<option v-for="piggy in option.piggies" :label="piggy.name_with_amount" :value="piggy.id">{{piggy.name_with_amount}}</option>
<option v-for="piggy in option.piggies" :label="piggy.name_with_balance" :value="piggy.id">{{piggy.name_with_balance}}</option>
</optgroup>
</select>
<ul class="list-unstyled" v-for="error in this.error">
@@ -58,7 +58,7 @@
return this.error.length > 0;
},
loadPiggies: function () {
let URI = document.getElementsByTagName('base')[0].href + "json/piggy-banks";
let URI = document.getElementsByTagName('base')[0].href + "api/v1/autocomplete/piggy-banks-with-balance";
axios.get(URI, {}).then((res) => {
let tempList = {
0: {
@@ -67,7 +67,7 @@
},
piggies: [
{
name_with_amount: this.no_piggy_bank,
name_with_balance: this.no_piggy_bank,
id: 0,
}
],
@@ -87,11 +87,11 @@
piggies: [],
};
}
tempList[groupOrder].piggies.push({name_with_amount: currentPiggy.name_with_amount, id: currentPiggy.id});
tempList[groupOrder].piggies.push({name_with_balance: currentPiggy.name_with_balance, id: currentPiggy.id});
}
if (!currentPiggy.objectGroup) {
// add to empty one:
tempList[0].piggies.push({name_with_amount: currentPiggy.name_with_amount, id: currentPiggy.id});
tempList[0].piggies.push({name_with_balance: currentPiggy.name_with_balance, id: currentPiggy.id});
}
//console.log(currentPiggy);
this.piggies.push(res.data[key]);

View File

@@ -91,7 +91,7 @@
if (this.tag.length < 2) {
return;
}
const url = document.getElementsByTagName('base')[0].href + `json/tags?search=${this.tag}`;
const url = document.getElementsByTagName('base')[0].href + `api/v1/autocomplete/tags?query=${this.tag}`;
clearTimeout(this.debounce);
this.debounce = setTimeout(() => {
@@ -108,4 +108,4 @@
<style scoped>
</style>
</style>