Browse Source

Feafactor: Move AutoComplete filter function as utils

pull/168/head
winkidney 5 years ago
parent
commit
b7f24b83be
2 changed files with 17 additions and 13 deletions
  1. +2
    -13
      pinry-spa/src/components/pin_edit/FilterSelect.vue
  2. +15
    -0
      pinry-spa/src/components/utils/AutoComplete.js

+ 2
- 13
pinry-spa/src/components/pin_edit/FilterSelect.vue View File

@@ -38,21 +38,10 @@
<script> <script>
import API from '../api'; import API from '../api';
import ModelForm from '../utils/ModelForm'; import ModelForm from '../utils/ModelForm';
import AutoComplete from '../utils/AutoComplete';


const fields = ['name']; const fields = ['name'];


function getFilteredOptions(options, filterText) {
return options.filter(
(option) => {
const index = option.name
.toString()
.toLowerCase()
.indexOf(filterText.toLowerCase());
return index >= 0;
},
);
}

function getBoardFromResp(boardObject) { function getBoardFromResp(boardObject) {
return { name: boardObject.name, value: boardObject.id }; return { name: boardObject.name, value: boardObject.id };
} }
@@ -62,7 +51,7 @@ function getAvailableOptions(vm, filter) {
if (filter === '' || filter === null) { if (filter === '' || filter === null) {
availableOptions = vm.allOptions; availableOptions = vm.allOptions;
} else { } else {
availableOptions = getFilteredOptions(
availableOptions = AutoComplete.getFilteredOptions(
vm.allOptions, vm.form.name.value, vm.allOptions, vm.form.name.value,
); );
} }


+ 15
- 0
pinry-spa/src/components/utils/AutoComplete.js View File

@@ -0,0 +1,15 @@
function getFilteredOptions(options, filterText) {
return options.filter(
(option) => {
const index = option.name
.toString()
.toLowerCase()
.indexOf(filterText.toLowerCase());
return index >= 0;
},
);
}

export default {
getFilteredOptions,
};

Loading…
Cancel
Save