filteredEventsWithPast, check db connection

This commit is contained in:
lesion 2019-06-26 15:44:26 +02:00
parent 665939a883
commit 491fc11d78
8 changed files with 50 additions and 37 deletions

View file

@ -39,8 +39,8 @@ export default {
}, },
}, },
computed: { computed: {
...mapGetters(['filteredEvents']), ...mapGetters(['filteredEventsWithPast']),
...mapState(['tags']), ...mapState(['tags', 'filters']),
attributes () { attributes () {
const colors = ['indigo', 'orange', 'yellow', 'green', 'teal', 'blue', 'red', 'purple', 'pink', 'grey'] const colors = ['indigo', 'orange', 'yellow', 'green', 'teal', 'blue', 'red', 'purple', 'pink', 'grey']
const tags = take(this.tags, 10).map(t=>t.tag) const tags = take(this.tags, 10).map(t=>t.tag)
@ -48,8 +48,9 @@ export default {
let attributes = [] let attributes = []
attributes.push ({ key: 'today', dates: new Date(), highlight: { color: 'green' }}) attributes.push ({ key: 'today', dates: new Date(), highlight: { color: 'green' }})
const that = this
function getColor(event) { function getColor(event) {
const color = { class: event.past ? 'past-event vc-rounded-full' : 'vc-rounded-full', color: 'blue' } const color = { class: event.past && !that.filters.show_past_events ? 'past-event vc-rounded-full' : 'vc-rounded-full', color: 'blue' }
const tag = get(event, 'tags[0].tag') const tag = get(event, 'tags[0].tag')
if (!tag) return color if (!tag) return color
const idx = tags.indexOf(tag) const idx = tags.indexOf(tag)
@ -58,14 +59,14 @@ export default {
return color return color
} }
attributes = attributes.concat(this.filteredEvents attributes = attributes.concat(this.filteredEventsWithPast
.filter(e => !e.multidate) .filter(e => !e.multidate)
.map(e => ({ .map(e => ({
key: e.id, key: e.id,
dot: getColor(e), dot: getColor(e),
dates: new Date(e.start_datetime*1000)}))) dates: new Date(e.start_datetime*1000)})))
attributes = attributes.concat(this.filteredEvents attributes = attributes.concat(this.filteredEventsWithPast
.filter(e => e.multidate) .filter(e => e.multidate)
.map( e => ({ key: e.id, highlight: getColor(e), dates: { .map( e => ({ key: e.id, highlight: getColor(e), dates: {
start: new Date(e.start_datetime*1000), end: new Date(e.end_datetime*1000) }}))) start: new Date(e.start_datetime*1000), end: new Date(e.end_datetime*1000) }})))

View file

@ -9,7 +9,7 @@
Calendar Calendar
.row.m-0 .row.m-0
.p-0.col-sm-6.col-lg-4.col-xl-3(v-for='event in filteredEvents' v-if='!event.past') .p-0.col-sm-6.col-lg-4.col-xl-3(v-for='event in filteredEvents')
a(:id='event.newDay' v-if='event.newDay') a(:id='event.newDay' v-if='event.newDay')
.d-block.d-sm-none .d-block.d-sm-none
el-divider {{event.start_datetime|day}} el-divider {{event.start_datetime|day}}

View file

@ -4,7 +4,6 @@ div#list
el-timeline el-timeline
el-timeline-item( el-timeline-item(
v-for='event in events' v-for='event in events'
v-if='!event.past'
:key='event.id' :key='event.id'
:timestamp='event|event_when' :timestamp='event|event_when'
placement='top' icon='el-icon-arrow-down' size='large' placement='top' icon='el-icon-arrow-down' size='large'

View file

@ -1,5 +1,5 @@
<template lang="pug"> <template lang="pug">
el-card#eventDetail(v-loading='!loaded') el-card#eventDetail
//- close button //- close button
nuxt-link.float-right(to='/') nuxt-link.float-right(to='/')
v-icon(name='times' color='red') v-icon(name='times' color='red')
@ -19,7 +19,7 @@
v-icon(name='chevron-right') v-icon(name='chevron-right')
//- image //- image
img(:src='imgPath' v-if='event.image_path' @load='image_loaded') img(:src='imgPath' v-if='event.image_path')
.info .info
div {{event|event_when}} div {{event|event_when}}
@ -59,11 +59,6 @@ import { MessageBox } from 'element-ui'
export default { export default {
name: 'Event', name: 'Event',
data () {
return {
loaded: false,
}
},
// transition: null, // transition: null,
// Watch for $route.query.page to call Component methods (asyncData, fetch, validate, layout, etc.) // Watch for $route.query.page to call Component methods (asyncData, fetch, validate, layout, etc.)
// watchQuery: ['id'], // watchQuery: ['id'],
@ -101,8 +96,7 @@ export default {
}, },
async asyncData ( { $axios, params }) { async asyncData ( { $axios, params }) {
const event = await $axios.$get(`/event/${params.id}`) const event = await $axios.$get(`/event/${params.id}`)
const loaded = !event.image_path return { event, id: params.id }
return { event, id: params.id, loaded }
}, },
computed: { computed: {
...mapGetters(['filteredEvents']), ...mapGetters(['filteredEvents']),
@ -131,9 +125,6 @@ export default {
}, },
}, },
methods: { methods: {
image_loaded (e, b) {
this.loaded = true
},
...mapActions(['delEvent']), ...mapActions(['delEvent']),
comment_filter (value) { comment_filter (value) {
return value.replace(/<a.*href="([^">]+).*>(?:.(?!\<\/a\>))*.<\/a>/, (orig, url) => { return value.replace(/<a.*href="([^">]+).*>(?:.(?!\<\/a\>))*.<\/a>/, (orig, url) => {

View file

@ -70,7 +70,7 @@ const userController = {
} }
}, },
// ADD EVENT // ADD EVENT // there's probably a better way to do this with sequelize! TOFIX
async addEvent(req, res) { async addEvent(req, res) {
const body = req.body const body = req.body

View file

@ -1,12 +1,16 @@
const argv = require('yargs').argv
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
const Sequelize = require('sequelize') const Sequelize = require('sequelize')
const basename = path.basename(__filename) const basename = path.basename(__filename)
const config = require('config') const config = require('config')
const consola = require('consola')
const db = {} const db = {}
const sequelize = new Sequelize(config.db) const sequelize = new Sequelize(config.db)
sequelize.authenticate().catch( e => {
consola.error('Error connecting to DB: ', e)
process.exit(-1)
})
fs fs
.readdirSync(__dirname) .readdirSync(__dirname)

View file

@ -7,8 +7,7 @@ module.exports = (sequelize, DataTypes) => {
index: true, index: true,
primaryKey: true primaryKey: true
}, },
weigth: { type: DataTypes.INTEGER, defaultValue: 0, allowNull: false }, weigth: { type: DataTypes.INTEGER, defaultValue: 0, allowNull: false }
color: DataTypes.STRING
}, {}) }, {})
tag.associate = function (models) { tag.associate = function (models) {

View file

@ -22,9 +22,8 @@ export const state = () => ({
export const getters = { export const getters = {
// filter current + future events only // filter matches search tag/place
// plus, filter matches search tag/place filteredEvents: state => {
filteredEvents: (state) => {
let events = state.events let events = state.events
// TOFIX: use lodash // TOFIX: use lodash
@ -43,26 +42,46 @@ export const getters = {
}) })
} }
// if (!state.filters.show_past_events) { if (!state.filters.show_past_events) {
// events = events.filter(e => !e.past) events = events.filter(e => !e.past)
// } }
let lastDay = null return events
events = map(events, e => { },
const currentDay = moment(e.start_datetime*1000).date() // filter matches search tag/place
e.newDay = (!lastDay || lastDay !== currentDay) && currentDay filteredEventsWithPast: state => {
lastDay = currentDay let events = state.events
return e
// TOFIX: use lodash
if (state.filters.tags.length || state.filters.places.length) {
events = events.filter((e) => {
if (state.filters.tags.length) {
const m = intersection(e.tags.map(t => t.tag), state.filters.tags)
if (m.length > 0) return true
}
if (state.filters.places.length) {
if (state.filters.places.find(p => p === e.place.id)) {
return true
}
}
return 0
}) })
}
return events return events
} }
} }
export const mutations = { export const mutations = {
setEvents(state, events) { setEvents(state, events) {
// set a `past` flag // set`past` and `newDay` flags to event
let lastDay = null
state.events = events.map((e) => { state.events = events.map((e) => {
const currentDay = moment(e.start_datetime*1000).date()
e.newDay = (!lastDay || lastDay !== currentDay) && currentDay
lastDay = currentDay
const end_datetime = e.end_datetime || e.start_datetime+3600*2 const end_datetime = e.end_datetime || e.start_datetime+3600*2
const past = (moment().unix() - end_datetime) > 0 const past = (moment().unix() - end_datetime) > 0
e.past = !!past e.past = !!past