Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autocomplete support for tag inputs #936

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/views/portfolio/projects/ProjectCreateProjectModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
:tags="tags"
:add-on-key="addOnKeys"
:placeholder="$t('message.add_tag')"
:autocomplete-items="tagsAutoCompleteItems"
@tags-changed="(newTags) => (this.tags = newTags)"
class="mw-100 bg-transparent text-lowercase"
/>
Expand Down Expand Up @@ -244,6 +245,8 @@ export default {
project: {},
tag: '', // The contents of a tag as its being typed into the vue-tag-input
tags: [], // An array of tags bound to the vue-tag-input
tagsAutoCompleteItems: [],
tagsAutoCompleteDebounce: null,
addOnKeys: [9, 13, 32, ':', ';', ','], // Separators used when typing tags into the vue-tag-input
labelIcon: {
dataOn: '\u2713',
Expand Down Expand Up @@ -274,6 +277,9 @@ export default {
return this.availableClassifiers;
},
},
watch: {
tag: 'searchTags',
},
methods: {
syncReadOnlyNameField: function (value) {
this.readOnlyProjectName = value;
Expand Down Expand Up @@ -374,6 +380,21 @@ export default {
});
}
},
searchTags: function () {
if (!this.tag) {
return;
}

clearTimeout(this.tagsAutoCompleteDebounce);
this.tagsAutoCompleteDebounce = setTimeout(() => {
const url = `${this.$api.BASE_URL}/${this.$api.URL_TAG}?searchText=${encodeURIComponent(this.tag)}&pageNumber=1&pageSize=6`;
this.axios.get(url).then((response) => {
this.tagsAutoCompleteItems = response.data.map((tag) => {
return { text: tag.name };
});
});
}, 250);
},
},
};
</script>
Expand Down
21 changes: 21 additions & 0 deletions src/views/portfolio/projects/ProjectDetailsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
:tags="tags"
:add-on-key="addOnKeys"
:placeholder="$t('message.add_tag')"
:autocomplete-items="tagsAutoCompleteItems"
@tags-changed="(newTags) => (this.tags = newTags)"
class="mw-100 bg-transparent text-lowercase"
:readonly="this.isNotPermitted(PERMISSIONS.PORTFOLIO_MANAGEMENT)"
Expand Down Expand Up @@ -500,6 +501,8 @@ export default {
availableParents: [],
tag: '', // The contents of a tag as its being typed into the vue-tag-input
tags: [], // An array of tags bound to the vue-tag-input
tagsAutoCompleteItems: [],
tagsAutoCompleteDebounce: null,
addOnKeys: [9, 13, 32, ':', ';', ','], // Separators used when typing tags into the vue-tag-input
labelIcon: {
dataOn: '\u2713',
Expand Down Expand Up @@ -648,6 +651,9 @@ export default {
this.$root.$emit('bv::show::modal', 'projectDetailsModal');
});
},
watch: {
tag: 'searchTags',
},
methods: {
initializeTags: function () {
this.tags = (this.project.tags || []).map((tag) => ({ text: tag.name }));
Expand Down Expand Up @@ -750,6 +756,21 @@ export default {
});
}
},
searchTags: function () {
if (!this.tag) {
return;
}

clearTimeout(this.tagsAutoCompleteDebounce);
this.tagsAutoCompleteDebounce = setTimeout(() => {
const url = `${this.$api.BASE_URL}/${this.$api.URL_TAG}?searchText=${encodeURIComponent(this.tag)}&pageNumber=1&pageSize=6`;
this.axios.get(url).then((response) => {
this.tagsAutoCompleteItems = response.data.map((tag) => {
return { text: tag.name };
});
});
}, 250);
},
resetValues: function () {
this.selectedParent = this.parent;
this.availableParents = [{ name: '', version: '', uuid: null }];
Expand Down
Loading