Compare commits
5 Commits
dc9d4e03ff
...
8e11d984a2
Author | SHA1 | Date |
---|---|---|
buttle | 8e11d984a2 | |
buttle | 38dc4d9842 | |
buttle | 83c645c2fb | |
buttle | 2a0fc20f5d | |
buttle | 5ba594e5d1 |
|
@ -8,7 +8,7 @@ This file is part of ArciveList.
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<Search></Search>
|
<Search v-bind:url_search_text="url_search_text"></Search>
|
||||||
|
|
||||||
<section class="collections-list">
|
<section class="collections-list">
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ This file is part of ArciveList.
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { mapMutations, mapGetters } from 'vuex'
|
import { mapMutations, mapGetters, mapActions } from 'vuex'
|
||||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
|
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
|
||||||
import { faLongArrowAltUp } from '@fortawesome/free-solid-svg-icons'
|
import { faLongArrowAltUp } from '@fortawesome/free-solid-svg-icons'
|
||||||
import { faLongArrowAltDown } from '@fortawesome/free-solid-svg-icons'
|
import { faLongArrowAltDown } from '@fortawesome/free-solid-svg-icons'
|
||||||
|
@ -135,20 +135,22 @@ export default {
|
||||||
active_column: 'date',
|
active_column: 'date',
|
||||||
faLongArrowAltUp: faLongArrowAltUp,
|
faLongArrowAltUp: faLongArrowAltUp,
|
||||||
faLongArrowAltDown: faLongArrowAltDown,
|
faLongArrowAltDown: faLongArrowAltDown,
|
||||||
|
url_search_text: location.hash.substr(1),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
|
||||||
},
|
|
||||||
ready: function () {
|
|
||||||
|
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
var payload = {
|
var payload = {
|
||||||
'sites': JSON.parse(this.collections),
|
'sites': JSON.parse(this.collections),
|
||||||
'column_name': this.active_column,
|
'active_column': this.active_column,
|
||||||
'order': this.columns_order[this.active_column]}
|
'column_order': this.columns_order[this.active_column]}
|
||||||
this.setSites(payload)
|
this.setSites(payload)
|
||||||
|
if (this.url_search_text) {
|
||||||
|
this.setSearchText(this.url_search_text)
|
||||||
|
this.siteSearch()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
setActiveColumn: function(name) {
|
setActiveColumn: function(name) {
|
||||||
|
@ -166,15 +168,17 @@ export default {
|
||||||
return this.columns_order[name] == 'asc' ? faLongArrowAltUp : faLongArrowAltDown
|
return this.columns_order[name] == 'asc' ? faLongArrowAltUp : faLongArrowAltDown
|
||||||
},
|
},
|
||||||
loadMoreSites() {
|
loadMoreSites() {
|
||||||
console.log('loading')
|
|
||||||
this.incrementPageCount()
|
this.incrementPageCount()
|
||||||
},
|
},
|
||||||
...mapGetters([
|
...mapGetters([
|
||||||
'getSitesForDisplay', 'getPageCount'
|
'getSitesForDisplay', 'getPageCount',
|
||||||
]),
|
]),
|
||||||
...mapMutations([
|
...mapMutations([
|
||||||
'setSites', 'setColumnOrder', 'incrementPageCount'
|
'setColumnOrder', 'incrementPageCount', 'setSearchText'
|
||||||
]),
|
]),
|
||||||
|
...mapActions([
|
||||||
|
'siteSearch', 'setSites'
|
||||||
|
])
|
||||||
},
|
},
|
||||||
watched: {
|
watched: {
|
||||||
|
|
||||||
|
|
|
@ -27,31 +27,29 @@ This file is part of ArciveList.
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { mapMutations, mapGetters } from 'vuex'
|
import { mapMutations, mapGetters, mapActions } from 'vuex'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Search",
|
name: "Search",
|
||||||
|
props: [
|
||||||
|
'url_search_text'
|
||||||
|
],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
search_text: "",
|
search_text: "",
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
mounted() {
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
search: function() {
|
search: function() {
|
||||||
|
//console.log('searching for: '+this.search_text)
|
||||||
|
const uri = window.location.toString()
|
||||||
|
const withNoHash = uri.substring(0, uri.indexOf('#'))
|
||||||
|
//console.log('setting hash')
|
||||||
|
window.history.replaceState({}, document.title, withNoHash+'#'+this.search_text)
|
||||||
this.setSearchText(this.search_text)
|
this.setSearchText(this.search_text)
|
||||||
var local_search_result = this.searchLocalSiteData()
|
this.siteSearch()
|
||||||
var api_endpoint = '/api/collections/search?fulltext_search='
|
|
||||||
var search_url = api_endpoint + this.search_text;
|
|
||||||
var self = this;
|
|
||||||
axios.get(search_url, {
|
|
||||||
})
|
|
||||||
.then(function (response) {
|
|
||||||
//console.log(response.data)
|
|
||||||
self.setFilteredSites(Object.assign({}, local_search_result, response.data))
|
|
||||||
})
|
|
||||||
.catch(function (error) {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
...mapMutations([
|
...mapMutations([
|
||||||
'setFilteredSites', 'setSearchText'
|
'setFilteredSites', 'setSearchText'
|
||||||
|
@ -59,7 +57,9 @@ export default {
|
||||||
...mapGetters([
|
...mapGetters([
|
||||||
'searchLocalSiteData'
|
'searchLocalSiteData'
|
||||||
]),
|
]),
|
||||||
|
...mapActions([
|
||||||
|
'siteSearch'
|
||||||
|
])
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
57
src/store.js
57
src/store.js
|
@ -8,6 +8,7 @@ This file is part of ArciveList.
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
import _ from 'underscore';
|
import _ from 'underscore';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
@ -18,19 +19,18 @@ const store = new Vuex.Store({
|
||||||
sites: [],
|
sites: [],
|
||||||
filtered_sites: [],
|
filtered_sites: [],
|
||||||
page_count: 1,
|
page_count: 1,
|
||||||
|
active_column: null,
|
||||||
|
column_order: null
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
setSearchText(state, text) {
|
setSearchText(state, text) {
|
||||||
state.search_text = text
|
state.search_text = text
|
||||||
},
|
},
|
||||||
setSites(state, payload) {
|
|
||||||
state.sites = _.sortBy(payload.sites, payload.column_name)
|
|
||||||
},
|
|
||||||
incrementPageCount(state) {
|
incrementPageCount(state) {
|
||||||
state.page_count = state.page_count +1
|
state.page_count = state.page_count +1
|
||||||
},
|
},
|
||||||
setFilteredSites(state, filtered_site_ids) {
|
setFilteredSites(state, filtered_site_ids) {
|
||||||
console.log(filtered_site_ids)
|
//console.log(filtered_site_ids)
|
||||||
var sites = []
|
var sites = []
|
||||||
for (const [site_id, weight] of Object.entries(filtered_site_ids)) {
|
for (const [site_id, weight] of Object.entries(filtered_site_ids)) {
|
||||||
var site = state.sites.find(x => x.id == site_id)
|
var site = state.sites.find(x => x.id == site_id)
|
||||||
|
@ -42,19 +42,44 @@ const store = new Vuex.Store({
|
||||||
state.page_count = 1
|
state.page_count = 1
|
||||||
},
|
},
|
||||||
setColumnOrder(state, payload) {
|
setColumnOrder(state, payload) {
|
||||||
//state.sites = _.sortBy(state.sites, payload.column_name)
|
state.active_column = payload.active_column
|
||||||
//state.filtered_sites = _.sortBy(state.filtered_sites, payload.column_name)
|
state.column_order = payload.column_order
|
||||||
state.sites = order_items(state.sites, payload.column_name, payload.order)
|
state.sites = order_items(state.sites,
|
||||||
state.filtered_sites = order_items(state.filtered_sites, payload.column_name, payload.order)
|
payload.active_column,
|
||||||
/*
|
payload.column_order)
|
||||||
if (payload.order == 'desc') {
|
state.filtered_sites = order_items(state.filtered_sites,
|
||||||
state.sites.reverse()
|
payload.active_column,
|
||||||
state.filtered_sites.reverse()
|
payload.column_order)
|
||||||
}
|
},
|
||||||
*/
|
},
|
||||||
|
actions: {
|
||||||
|
setSites(context, payload) {
|
||||||
|
context.state.sites = payload.sites
|
||||||
|
context.commit("setColumnOrder", {'active_column': payload.active_column,
|
||||||
|
'column_order': payload.column_order})
|
||||||
|
},
|
||||||
|
siteSearch (context) {
|
||||||
|
console.log('new site search')
|
||||||
|
var api_endpoint = '/api/collections/search?fulltext_search='
|
||||||
|
axios.post(api_endpoint + context.getters.getSearchText, {})
|
||||||
|
.then(function (response) {
|
||||||
|
var local_search_result = context.getters.searchLocalSiteData
|
||||||
|
var merged_results = Object.assign({},
|
||||||
|
local_search_result,
|
||||||
|
response.data)
|
||||||
|
context.commit("setFilteredSites", merged_results)
|
||||||
|
context.commit("setColumnOrder", {'active_column': context.state.active_column,
|
||||||
|
'column_order': context.state.column_order})
|
||||||
|
})
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
|
getSearchText: state => {
|
||||||
|
return state.search_text
|
||||||
|
},
|
||||||
getSitesForDisplay: state => {
|
getSitesForDisplay: state => {
|
||||||
if (state.search_text === "") {
|
if (state.search_text === "") {
|
||||||
return state.sites
|
return state.sites
|
||||||
|
@ -92,8 +117,6 @@ const store = new Vuex.Store({
|
||||||
result[id] = weight
|
result[id] = weight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('load search')
|
|
||||||
console.log(result)
|
|
||||||
return result
|
return result
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -106,8 +129,6 @@ function order_items(items, field_name, ascending) {
|
||||||
if (field_name == 'date') {
|
if (field_name == 'date') {
|
||||||
field_name = 'project_date'
|
field_name = 'project_date'
|
||||||
}
|
}
|
||||||
console.log("sss: "+ field_name)
|
|
||||||
console.log(first_el)
|
|
||||||
if (first_el[field_name] === undefined || first_el[field_name] === ""){
|
if (first_el[field_name] === undefined || first_el[field_name] === ""){
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue