Skip to content

Commit

Permalink
fix #312, use prefix $ for commands (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
1138-4EB authored and hacdias committed Apr 23, 2018
1 parent 4c30b2c commit 390c530
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
62 changes: 38 additions & 24 deletions src/components/Search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default {
computed: {
...mapState(['user', 'show']),
// Placeholder value.
placeholder: function () {
placeholder () {
if (this.user.allowCommands && this.user.commands.length > 0) {
return this.$t('search.searchOrCommand')
}
Expand All @@ -134,7 +134,7 @@ export default {
},
// The text that is shown on the results' box while
// there is no search result or command output to show.
text: function () {
text () {
if (this.ongoing) {
return ''
}
Expand All @@ -144,17 +144,27 @@ export default {
return `${this.$t('search.searchOrSupportedCommand')} ${this.user.commands.join(', ')}.`
}
this.$t('search.type')
this.$t('search.typeSearch')
}
if (!this.supported() || !this.user.allowCommands) {
if (!(this.value[0] === '$') || !this.user.allowCommands) {
return this.$t('search.pressToSearch')
} else {
if (this.command.length === 0) {
return this.$t('search.typeCommand')
}
if (!this.supported()) {
return this.$t('search.notSupportedCommand')
}
return this.$t('search.pressToExecute')
}
},
// The command, without the leading symbol ('$') with or without a following space (' ')
command () {
return this.value[1] === ' ' ? this.value.slice(2) : this.value.slice(1)
}
},
mounted: function () {
mounted () {
// Gets the result div which will be scrollable.
this.scrollable = document.querySelector('#search #result')
Expand All @@ -181,14 +191,15 @@ export default {
},
// Checks if the current input is a supported command.
supported () {
let pieces = this.value.split(' ')
for (let i = 0; i < this.user.commands.length; i++) {
if (pieces[0] === this.user.commands[i]) {
return true
let cmd = this.command.split(' ')[0]
let cl = this.user.commands.length
if (cl !== 0) {
for (let i = 0; i < cl; i++) {
if (cmd.match(this.user.commands[i])) {
return true
}
}
}
return false
},
// Initializes the search with a default value.
Expand Down Expand Up @@ -227,19 +238,22 @@ export default {
}
// In case of being a command.
if (this.supported() && this.user.allowCommands) {
api.command(path, this.value,
(event) => {
this.commands.push(event.data)
this.scrollable.scrollTop = this.scrollable.scrollHeight
},
(event) => {
this.reload = true
this.ongoing = false
this.scrollable.scrollTop = this.scrollable.scrollHeight
}
)
if (this.value[0] === '$') {
if (this.supported() && this.user.allowCommands) {
api.command(path, this.command,
(event) => {
this.commands.push(event.data)
this.scrollable.scrollTop = this.scrollable.scrollHeight
},
(event) => {
this.reload = true
this.ongoing = false
this.scrollable.scrollTop = this.scrollable.scrollHeight
}
)
return
}
this.ongoing = false
return
}
Expand Down
6 changes: 4 additions & 2 deletions src/i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,15 @@ sidebar:
search:
images: Images
music: Music
notSupportedCommand: This is a not supported command.
pdf: PDF
pressToExecute: Press enter to execute.
pressToSearch: Press enter to search.
search: Search...
searchOrCommand: Search or execute a command...
searchOrSupportedCommand: 'Search or use one of your supported commands:'
type: Type and press enter to search.
searchOrSupportedCommand: 'Search or prepend ''$'' and use one of your supported commands:'
typeCommand: Type and press enter to execute.
typeSearch: Type and press enter to search.
types: Types
video: Video
writeToSearch: Write here to search
Expand Down

0 comments on commit 390c530

Please sign in to comment.