2019-07-19 20:51:57 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
|
|
|
|
|
2019-07-21 16:28:07 +00:00
|
|
|
<div class="ui equal width grid">
|
|
|
|
|
|
|
|
<!-- mobile search menu -->
|
|
|
|
<div class="ui mobile only row">
|
|
|
|
<!-- Small screen new note button -->
|
|
|
|
<div class="ui four wide column">
|
|
|
|
<div @click="createNote" class="ui fluid green icon button">
|
|
|
|
<i class="plus icon"></i>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="ui twelve wide column">
|
|
|
|
<div class="ui form">
|
|
|
|
<input v-model="searchTerm" @keyup="searchKeyUp" @:keyup.enter="search" placeholder="Search Notes" />
|
2019-07-24 18:06:50 +00:00
|
|
|
</div>
|
2019-07-21 16:28:07 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2019-07-19 20:51:57 +00:00
|
|
|
<!-- search menu -->
|
2019-07-21 16:28:07 +00:00
|
|
|
<div class="ui large screen only row">
|
|
|
|
|
2019-07-20 23:07:22 +00:00
|
|
|
<div class="ui two wide column">
|
|
|
|
<div @click="createNote" class="ui fluid green button">
|
|
|
|
<i class="plus icon"></i>
|
|
|
|
New Note
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-07-21 16:28:07 +00:00
|
|
|
|
2019-07-20 23:07:22 +00:00
|
|
|
<div class="ui five wide column">
|
|
|
|
<div class="ui form">
|
|
|
|
<input v-model="searchTerm" @keyup="searchKeyUp" @:keyup.enter="search" placeholder="Search Notes" />
|
2019-07-24 18:06:50 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="ui nine wide column">
|
|
|
|
|
|
|
|
<router-link class="ui basic button" to="/help">Help</router-link>
|
|
|
|
|
|
|
|
<div class="ui right floated basic button"
|
|
|
|
data-tooltip="Log Out" data-position="left center"
|
|
|
|
v-on:click="destroyLoginToken">{{username}}</div>
|
2019-07-20 23:07:22 +00:00
|
|
|
</div>
|
2019-07-19 20:51:57 +00:00
|
|
|
</div>
|
2019-07-21 16:28:07 +00:00
|
|
|
|
2019-07-19 20:51:57 +00:00
|
|
|
<div class="ui row">
|
2019-07-21 16:28:07 +00:00
|
|
|
|
|
|
|
<!-- tags display -->
|
|
|
|
<div class="ui two wide large screen only column">
|
2019-07-20 23:07:22 +00:00
|
|
|
<div class="ui basic fluid button" @click="reset">Reset</div>
|
|
|
|
<div class="ui divider"></div>
|
2019-07-19 20:51:57 +00:00
|
|
|
<div class="ui clickable basic fluid large label" v-for="tag in commonTags" @click="toggleTagFilter(tag.id)"
|
|
|
|
:class="{ 'green':(searchTags.includes(tag.id)) }">
|
|
|
|
{{ucWords(tag.text)}} <div class="detail">{{tag.usages}}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-07-21 16:28:07 +00:00
|
|
|
|
|
|
|
<!-- Note title cards -->
|
|
|
|
<div class="ui fourteen wide computer sixteen wide mobile column">
|
2019-07-20 23:07:22 +00:00
|
|
|
<h2>Notes ({{notes.length}})</h2>
|
2019-07-19 20:51:57 +00:00
|
|
|
<div v-if="notes !== null">
|
2019-07-21 16:28:07 +00:00
|
|
|
<note-title-display-card
|
|
|
|
v-for="note in notes"
|
|
|
|
:onClick="openNote"
|
|
|
|
:data="note"
|
2019-07-24 18:06:50 +00:00
|
|
|
:key="note.id + note.color + searchTerm + note.note_highlights.length + note.attachment_highlights.length + note.tag_highlights.length"
|
2019-07-21 16:28:07 +00:00
|
|
|
/>
|
2019-07-19 20:51:57 +00:00
|
|
|
</div>
|
2019-07-24 18:06:50 +00:00
|
|
|
|
2019-07-19 20:51:57 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2019-07-20 23:07:22 +00:00
|
|
|
|
|
|
|
<input-notes v-if="activeNoteId1 != null" :noteid="activeNoteId1" :position="activeNote1Position" />
|
|
|
|
<input-notes v-if="activeNoteId2 != null" :noteid="activeNoteId2" :position="activeNote2Position" />
|
|
|
|
|
2019-07-19 20:51:57 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'SearchBar',
|
2019-07-20 23:07:22 +00:00
|
|
|
components: {
|
|
|
|
'input-notes': require('./InputNotes.vue').default,
|
2019-07-21 16:28:07 +00:00
|
|
|
'note-title-display-card': require('./NoteTitleDisplayCard.vue').default,
|
2019-07-20 23:07:22 +00:00
|
|
|
},
|
2019-07-19 20:51:57 +00:00
|
|
|
data () {
|
|
|
|
return {
|
2019-07-24 18:06:50 +00:00
|
|
|
username:'',
|
2019-07-19 20:51:57 +00:00
|
|
|
initComponent: true,
|
|
|
|
commonTags: [],
|
|
|
|
searchTerm: '',
|
|
|
|
searchTags: [],
|
2019-07-20 23:07:22 +00:00
|
|
|
notes: [],
|
|
|
|
searchDebounce: null,
|
|
|
|
|
|
|
|
//Currently open notes in app
|
|
|
|
activeNoteId1: null,
|
|
|
|
activeNoteId2: null,
|
|
|
|
//Position determines how note is Positioned
|
|
|
|
activeNote1Position: 0,
|
2019-07-24 18:06:50 +00:00
|
|
|
activeNote2Position: 0,
|
2019-07-19 20:51:57 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeMount(){
|
2019-07-20 23:07:22 +00:00
|
|
|
this.$bus.$on('close_active_note', position => {
|
|
|
|
this.closeNote(position)
|
|
|
|
})
|
2019-07-24 18:06:50 +00:00
|
|
|
|
|
|
|
|
2019-07-19 20:51:57 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
2019-07-24 18:06:50 +00:00
|
|
|
let username = this.$store.getters.getUsername
|
|
|
|
this.username = this.ucWords(username)
|
|
|
|
|
2019-07-19 20:51:57 +00:00
|
|
|
this.search()
|
2019-07-24 18:06:50 +00:00
|
|
|
|
2019-07-19 20:51:57 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2019-07-20 23:07:22 +00:00
|
|
|
openNote(id){
|
|
|
|
|
|
|
|
//Do not open same note twice
|
|
|
|
if(this.activeNoteId1 == id || this.activeNoteId2 == id){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//1 note open
|
|
|
|
if(this.activeNoteId1 == null && this.activeNoteId2 == null){
|
|
|
|
this.activeNoteId1 = id
|
|
|
|
this.activeNote1Position = 0 //Middel of page
|
|
|
|
return
|
|
|
|
}
|
|
|
|
//2 notes open
|
|
|
|
if(this.activeNoteId1 != null && this.activeNoteId2 == null){
|
|
|
|
this.activeNoteId2 = id
|
|
|
|
this.activeNote1Position = 1 //Right side of page
|
|
|
|
this.activeNote2Position = 2 //Left side of page
|
|
|
|
return
|
|
|
|
}
|
|
|
|
},
|
|
|
|
closeNote(position){
|
|
|
|
//One note open, close that note
|
|
|
|
if(position == 0){
|
|
|
|
this.activeNoteId1 = null
|
|
|
|
this.activeNoteId2 = null
|
|
|
|
}
|
|
|
|
//Right note closed, thats 1
|
|
|
|
if(position == 1){
|
|
|
|
this.activeNoteId1 = null
|
|
|
|
}
|
|
|
|
if(position == 2){
|
|
|
|
this.activeNoteId2 = null
|
|
|
|
}
|
|
|
|
|
|
|
|
this.activeNote1Position = 0
|
|
|
|
this.activeNote2Position = 0
|
|
|
|
|
|
|
|
this.search()
|
|
|
|
},
|
2019-07-19 20:51:57 +00:00
|
|
|
toggleTagFilter(tagId){
|
|
|
|
|
|
|
|
if(this.searchTags.includes(tagId)){
|
|
|
|
this.searchTags.splice( this.searchTags.indexOf(tagId) , 1);
|
|
|
|
} else {
|
|
|
|
this.searchTags.push(tagId)
|
|
|
|
}
|
|
|
|
|
|
|
|
this.search()
|
|
|
|
},
|
|
|
|
search(){
|
|
|
|
let postData = {
|
|
|
|
searchQuery: this.searchTerm,
|
|
|
|
searchTags: this.searchTags
|
|
|
|
}
|
|
|
|
//Perform search
|
|
|
|
let vm = this
|
|
|
|
axios.post('/api/notes/search', postData).
|
|
|
|
then(response => {
|
|
|
|
console.log('Notes and Tags')
|
|
|
|
console.log(response.data)
|
|
|
|
|
|
|
|
vm.commonTags = response.data.tags
|
|
|
|
vm.notes = response.data.notes
|
2019-07-24 18:06:50 +00:00
|
|
|
vm.highlights = response.data.highlights
|
2019-07-19 20:51:57 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
searchKeyUp(){
|
|
|
|
let vm = this
|
|
|
|
clearTimeout(vm.searchDebounce)
|
|
|
|
vm.searchDebounce = setTimeout(() => {
|
|
|
|
vm.search()
|
|
|
|
}, 300)
|
|
|
|
},
|
|
|
|
createNote(event){
|
|
|
|
const title = ''
|
|
|
|
let vm = this
|
|
|
|
|
|
|
|
axios.post('/api/notes/create', {title})
|
|
|
|
.then(response => {
|
|
|
|
|
|
|
|
if(response.data && response.data.id){
|
|
|
|
vm.openNote(response.data.id)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
ucWords(str){
|
|
|
|
return (str + '')
|
|
|
|
.replace(/^(.)|\s+(.)/g, function ($1) {
|
|
|
|
return $1.toUpperCase()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
reset(){
|
|
|
|
this.searchTerm = ''
|
|
|
|
this.searchTags = []
|
|
|
|
this.search()
|
2019-07-24 18:06:50 +00:00
|
|
|
},
|
|
|
|
destroyLoginToken() {
|
|
|
|
this.$store.commit('destroyLoginToken')
|
2019-07-19 20:51:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style type="text/css" scoped>
|
|
|
|
.detail {
|
|
|
|
float: right;
|
|
|
|
}
|
|
|
|
</style>
|