1
0
mirror of https://github.com/citizenfx/cfx-server-data.git synced 2025-01-11 00:03:18 +08:00
cfx-server-data/resources/[system]/chat/html/Suggestions.js

45 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-05-21 22:52:55 +08:00
Vue.component('suggestions', {
2017-05-18 01:22:20 +08:00
template: '#suggestions_template',
props: ['message', 'suggestions'],
data() {
return {};
},
computed: {
currentSuggestions() {
if (this.message === '') {
return [];
}
const currentSuggestions = this.suggestions.filter((s) => {
if (!s.name.startsWith(this.message)) {
const suggestionSplitted = s.name.split(' ');
const messageSplitted = this.message.split(' ');
for (let i = 0; i < messageSplitted.length; i += 1) {
if (i >= suggestionSplitted.length) {
return i < suggestionSplitted.length + s.params.length;
}
if (suggestionSplitted[i] !== messageSplitted[i]) {
return false;
}
}
}
return true;
2017-05-21 22:52:55 +08:00
}).slice(0, CONFIG.suggestionLimit);
2017-05-18 01:22:20 +08:00
currentSuggestions.forEach((s) => {
// eslint-disable-next-line no-param-reassign
s.disabled = !s.name.startsWith(this.message);
s.params.forEach((p, index) => {
const wType = (index === s.params.length - 1) ? '.' : '\\S';
const regex = new RegExp(`${s.name} (?:\\w+ ){${index}}(?:${wType}*)$`, 'g');
// eslint-disable-next-line no-param-reassign
p.disabled = this.message.match(regex) == null;
});
});
return currentSuggestions;
},
},
methods: {},
2017-05-21 22:52:55 +08:00
});