Skip to content

Commit

Permalink
Add auto complete for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
RadhiFadlillah committed Jun 7, 2018
1 parent 2d10415 commit 9fa4cb2
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 28 deletions.
36 changes: 18 additions & 18 deletions cmd/serve/assets-prod.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion view/css/stylesheet.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion view/css/yla-dialog.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,16 @@
}
})
.then((response) => {
this.loading = false;
this.bookmarks = response.data;
this.page = 0;
this.bookmarks = response.data;
this.maxPage = Math.ceil(this.bookmarks.length / pageSize) - 1;
window.scrollTo(0, 0);

return rest.get('/api/tags');
})
.then((response) => {
this.tags = response.data;
this.loading = false;
})
.catch((error) => {
var errorMsg = (error.response ? error.response.data : error.message).trim();
Expand Down Expand Up @@ -359,7 +364,9 @@
type: 'area'
}, {
name: 'tags',
label: 'Comma separated tags (optional)'
label: 'Comma separated tags (optional)',
separator: ',',
dictionary: this.tags.map(tag => tag.name)
}, ],
mainText: 'OK',
secondText: 'Cancel',
Expand Down
14 changes: 9 additions & 5 deletions view/js/component/yla-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var YlaDialog = function () {
@focus="$event.target.select()"
@keyup="handleInput(index)"
@keyup.enter="handleInputEnter(index)">
<span ref="suggestion" v-if="field.suggestion" class="suggestion">{{field.suggestion}}</span>
<span :ref="'suggestion-'+index" v-if="field.suggestion" class="suggestion">{{field.suggestion}}</span>
</template>
</slot>
</div>
Expand Down Expand Up @@ -112,6 +112,7 @@ var YlaDialog = function () {
value: '',
type: 'text',
dictionary: [],
separator: ' ',
suggestion: undefined
}

Expand All @@ -121,6 +122,7 @@ var YlaDialog = function () {
value: field.value || '',
type: field.type || 'text',
dictionary: field.dictionary instanceof Array ? field.dictionary : [],
separator: field.separator || ' ',
suggestion: undefined
}
});
Expand Down Expand Up @@ -161,7 +163,7 @@ var YlaDialog = function () {
if (dictionary.length === 0) return;

// Fetch suggestion from dictionary
var words = field.value.split(' '),
var words = field.value.split(field.separator),
lastWord = words[words.length - 1].toLowerCase(),
suggestion;

Expand All @@ -179,7 +181,7 @@ var YlaDialog = function () {
// Display suggestion
this.$nextTick(() => {
var input = this.$refs.input[index],
span = this.$refs.suggestion[index],
span = this.$refs['suggestion-' + index][0],
inputRect = input.getBoundingClientRect();

span.style.top = (inputRect.bottom - 1) + 'px';
Expand All @@ -194,11 +196,13 @@ var YlaDialog = function () {
return;
}

var words = this.formFields[index].value.split(' ');
var separator = this.formFields[index].separator,
words = this.formFields[index].value.split(separator);

words.pop();
words.push(suggestion);

this.formFields[index].value = words.join(' ') + ' ';
this.formFields[index].value = words.join(separator) + separator;
this.formFields[index].suggestion = undefined;
},
focus() {
Expand Down
4 changes: 4 additions & 0 deletions view/less/stylesheet.less
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
border-color: var(--border);
background-color: var(--contentBg);
}
>.suggestion {
border-color: var(--border);
background-color: var(--bg);
}
}
>.yla-dialog__footer {
border-color: var(--border);
Expand Down
1 change: 1 addition & 0 deletions view/less/yla-dialog.less
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
padding: 8px;
background-color: @bg;
border: 1px solid @border;
font-size: 0.9em;
}
}
>.yla-dialog__footer {
Expand Down

0 comments on commit 9fa4cb2

Please sign in to comment.