color, weigth, locale, config

This commit is contained in:
lesion
2019-06-26 14:44:21 +02:00
parent b093dae3f3
commit 1087723be8
27 changed files with 188 additions and 86 deletions

View File

@@ -14,7 +14,7 @@
<script> <script>
import { mapState, mapActions, mapGetters } from 'vuex' import { mapState, mapActions, mapGetters } from 'vuex'
import moment from 'dayjs' import moment from 'dayjs'
import { intersection, sample, get } from 'lodash' import { intersection, sample, take, get } from 'lodash'
export default { export default {
name: 'Calendar', name: 'Calendar',
@@ -40,17 +40,34 @@ export default {
}, },
computed: { computed: {
...mapGetters(['filteredEvents']), ...mapGetters(['filteredEvents']),
...mapState(['tags']),
attributes () { attributes () {
const colors = ['indigo', 'orange', 'yellow', 'green', 'teal', 'blue', 'red', 'purple', 'pink', 'grey']
const tags = take(this.tags, 10).map(t=>t.tag)
// const tags = [this.tags[0].tag, this.tags[1].tag, this.tags[2].tag, this.tags[3].tag, this.tags[4].tag, this.tags[5].tag ]
let attributes = [] let attributes = []
attributes.push ({ key: 'today', dates: new Date(), highlight: { color: 'green' }}) attributes.push ({ key: 'today', dates: new Date(), highlight: { color: 'green' }})
function getColor(event) {
const color = { class: event.past ? 'past-event vc-rounded-full' : 'vc-rounded-full', color: 'blue' }
const tag = get(event, 'tags[0].tag')
if (!tag) return color
const idx = tags.indexOf(tag)
if (idx<0) return color
color.color = colors[idx]
return color
}
attributes = attributes.concat(this.filteredEvents attributes = attributes.concat(this.filteredEvents
.filter(e => !e.multidate) .filter(e => !e.multidate)
.map(e => ({ key: e.id, dot: {}, dates: new Date(e.start_datetime*1000)}))) .map(e => ({
key: e.id,
dot: getColor(e),
dates: new Date(e.start_datetime*1000)})))
attributes = attributes.concat(this.filteredEvents attributes = attributes.concat(this.filteredEvents
.filter(e => e.multidate) .filter(e => e.multidate)
.map( e => ({ key: e.id, highlight: {}, 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) }})))
return attributes return attributes
@@ -76,4 +93,7 @@ export default {
border-radius: 15px; border-radius: 15px;
} */ } */
.past-event {
opacity: 0.2;
}
</style> </style>

View File

@@ -4,11 +4,12 @@
a(href='#totop') a(href='#totop')
el-button.top.d-block.d-sm-none(icon='el-icon-top' circle type='primary' plain) el-button.top.d-block.d-sm-none(icon='el-icon-top' circle type='primary' plain)
a.totop(name='totop') a.totop(name='totop')
//- el-backtop(target='#home')
no-ssr no-ssr
Calendar Calendar
.row.m-0 .row.m-0
.p-0.col-sm-6.col-lg-4.col-xl-3(v-for='event in filteredEvents') .p-0.col-sm-6.col-lg-4.col-xl-3(v-for='event in filteredEvents' v-if='!event.past')
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,6 +4,7 @@ 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

@@ -12,6 +12,14 @@
"logging": false "logging": false
}, },
"upload_path": "./", "upload_path": "./",
"smtp": {
"auth": {
"user": "",
"pass": ""
},
"secure": true,
"host": ""
},
"admin": { "admin": {
"email": "", "email": "",
"password": "" "password": ""

View File

@@ -46,7 +46,8 @@ const it = {
ok: 'Ok', ok: 'Ok',
cancel: 'Annulla', cancel: 'Annulla',
enable: 'Abilita', enable: 'Abilita',
disable: 'Disabilita' disable: 'Disabilita',
me: 'Sei te'
}, },
login: { login: {

View File

@@ -1,3 +1,5 @@
const conf = require('config')
module.exports = { module.exports = {
mode: 'universal', mode: 'universal',
/* /*
@@ -15,6 +17,8 @@ module.exports = {
{ path: '/api', handler: '@/server/api/index.js' } { path: '/api', handler: '@/server/api/index.js' }
], ],
server: conf.server,
/* /*
** Customize the progress-bar color ** Customize the progress-bar color
*/ */

View File

@@ -72,7 +72,7 @@
br br
el-select(v-model='event.tags' multiple filterable allow-create el-select(v-model='event.tags' multiple filterable allow-create
default-first-option placeholder='Tag') default-first-option placeholder='Tag')
el-option(v-for='tag in tags' :key='tag.tag' el-option(v-for='tag in tags' :key='tag'
:label='tag' :value='tag') :label='tag' :value='tag')
el-button.float-right(@click.native='next' :disabled='!couldProceed') {{$t('common.next')}} el-button.float-right(@click.native='next' :disabled='!couldProceed') {{$t('common.next')}}

View File

@@ -30,15 +30,18 @@
span(slot='reference') {{data.row.email}} span(slot='reference') {{data.row.email}}
el-table-column(:label="$t('common.actions')") el-table-column(:label="$t('common.actions')")
template(slot-scope='data') template(slot-scope='data')
el-button.mr-1(size='mini' div(v-if='data.row.id!==$auth.user.id')
:type='data.row.is_active?"warning":"success"' el-button.mr-1(size='mini'
@click='toggle(data.row)') {{data.row.is_active?$t('common.deactivate'):$t('common.activate')}} :type='data.row.is_active?"warning":"success"'
el-button(size='mini' @click='toggle(data.row)') {{data.row.is_active?$t('common.deactivate'):$t('common.activate')}}
:type='data.row.is_admin?"danger":"warning"' el-button(size='mini'
@click='toggleAdmin(data.row)') {{data.row.is_admin?$t('admin.remove_admin'):$t('common.admin')}} :type='data.row.is_admin?"danger":"warning"'
el-button(size='mini' @click='toggleAdmin(data.row)') {{data.row.is_admin?$t('admin.remove_admin'):$t('common.admin')}}
type='danger' el-button(size='mini'
@click='delete_user(data.row)') {{$t('admin.delete_user')}} type='danger'
@click='delete_user(data.row)') {{$t('admin.delete_user')}}
div(v-else)
span {{$t('common.me')}}
no-ssr no-ssr
el-pagination(:page-size='perPage' :currentPage.sync='userPage' :total='users.length') el-pagination(:page-size='perPage' :currentPage.sync='userPage' :total='users.length')
@@ -201,8 +204,14 @@ export default {
this.$axios.$put('/user', user) this.$axios.$put('/user', user)
}, },
async toggleAdmin(user) { async toggleAdmin(user) {
console.error(this.$auth.user)
if (user.id === this.$auth.user.id) return
user.is_admin = !user.is_admin user.is_admin = !user.is_admin
this.$axios.$put('/user', user) try {
this.$axios.$put('/user', user)
} catch(e) {
console.error(e)
}
}, },
preview (id) { preview (id) {
this.$router.push(`/event/${id}`) this.$router.push(`/event/${id}`)

View File

@@ -27,7 +27,7 @@
//- description and tags //- description and tags
div(v-if='event.description || event.tags') div(v-if='event.description || event.tags')
pre(v-html='event.description') pre(v-html='$options.filters.linkify(event.description)')
el-tag.mr-1(v-for='tag in event.tags' el-tag.mr-1(v-for='tag in event.tags'
size='mini' :key='tag.tag') {{tag.tag}} size='mini' :key='tag.tag') {{tag.tag}}

View File

@@ -15,7 +15,7 @@ export default ({ app, store }) => {
const start = moment(event.start_datetime*1000) const start = moment(event.start_datetime*1000)
const end = moment(event.end_datetime*1000) const end = moment(event.end_datetime*1000)
if (event.multidate) { if (event.multidate) {
return `${start.format('ddd, D MMMM (HH:mm)')} - ${end.format('ddd, D MMMM (HH:mm)')}` return `${start.format('ddd, D MMMM (HH:mm)')} - ${end.format('ddd, D MMMM')}`
} else if (event.end_datetime && event.end_datetime !== event.start_datetime) } else if (event.end_datetime && event.end_datetime !== event.start_datetime)
return `${start.format('ddd, D MMMM (HH:mm-')}${end.format('HH:mm)')}` return `${start.format('ddd, D MMMM (HH:mm-')}${end.format('HH:mm)')}`
else else

View File

@@ -17,7 +17,7 @@ const botController = {
access_token, access_token,
api_url: `https://${instance}/api/v1` api_url: `https://${instance}/api/v1`
}) })
const listener = botController.bot.stream('/streaming/direct') const listener = botController.bot.stream('/streaming/public')
listener.on('message', botController.message) listener.on('message', botController.message)
listener.on('error', botController.error) listener.on('error', botController.error)
// const botUsers = await User.findAll({ where: { mastodon_auth: { [Op.ne]: null } } }) // const botUsers = await User.findAll({ where: { mastodon_auth: { [Op.ne]: null } } })
@@ -51,12 +51,13 @@ ${event.description.length > 200 ? event.description.substr(0, 200) + '...' : ev
media = await bot.post('media', { file: fs.createReadStream(file) }) media = await bot.post('media', { file: fs.createReadStream(file) })
} }
} }
return botController.bot.post('/statuses', { status, visibility: 'direct', media_ids: media ? [media.data.id] : [] }) return botController.bot.post('/statuses', { status, media_ids: media ? [media.data.id] : [] })
}, },
// TOFIX: enable message deletion // TOFIX: enable message deletion
async message(msg) { async message(msg) {
const replyid = msg.data.in_reply_to_id || msg.data.last_status.in_reply_to_id const type = msg.event
const replyid = msg.data.in_reply_to_id
if (!replyid) return if (!replyid) return
let event = await Event.findOne({ where: { activitypub_id: replyid } }) let event = await Event.findOne({ where: { activitypub_id: replyid } })
if (!event) { if (!event) {
@@ -65,8 +66,8 @@ ${event.description.length > 200 ? event.description.substr(0, 200) + '...' : ev
if (!comment) return if (!comment) return
event = comment.event event = comment.event
} }
const comment = await Comment.create({ await Comment.create({
activitypub_id: msg.data.last_status.id, activitypub_id: msg.data.id,
data: msg.data, data: msg.data,
eventId: event.id eventId: event.id
}) })

View File

@@ -23,7 +23,7 @@ const eventController = {
const places = await Place.findAll({ const places = await Place.findAll({
order: [[Sequelize.literal('weigth'), 'DESC']], order: [[Sequelize.literal('weigth'), 'DESC']],
attributes: { attributes: {
include: [[Sequelize.fn('count', Sequelize.col('events.placeId')) , 'weigth']], // <---- Here you will get the total count of user include: [[Sequelize.fn('count', Sequelize.col('events.placeId')) , 'weigth']],
exclude: ['weigth', 'createdAt', 'updatedAt'] exclude: ['weigth', 'createdAt', 'updatedAt']
}, },
include: [{ model: Event, attributes: [] }], include: [{ model: Event, attributes: [] }],
@@ -32,10 +32,9 @@ const eventController = {
const tags = await Tag.findAll({ const tags = await Tag.findAll({
order: [['weigth', 'DESC']], order: [['weigth', 'DESC']],
includeIgnoreAttributes: false,
attributes: { attributes: {
exclude: ['createdAt', 'updatedAt'] exclude: ['createdAt', 'updatedAt']
} },
}) })
res.json({ tags, places }) res.json({ tags, places })
@@ -84,20 +83,20 @@ const eventController = {
// TODO retrieve next/prev event also // TODO retrieve next/prev event also
// select id, start_datetime, title from events where start_datetime > (select start_datetime from events where id=89) order by start_datetime limit 20; // select id, start_datetime, title from events where start_datetime > (select start_datetime from events where id=89) order by start_datetime limit 20;
// weigth is not updated
async get(req, res) { async get(req, res) {
const id = req.params.event_id const id = req.params.event_id
const event = await Event.findByPk(id, { let event = await Event.findByPk(id, {
plain: true,
attributes: { exclude: ['createdAt', 'updatedAt'] },
include: [ include: [
Tag, { model: Tag, attributes: ['tag', 'weigth'], through: { attributes: [] } },
Comment, { model: Place, attributes: ['name', 'address'] },
{ model: Place, attributes: ['name', 'address'] } Comment
], ],
order: [ [Comment, 'id', 'DESC'], [Tag, 'weigth', 'DESC'] ] order: [ [Comment, 'id', 'DESC'] ]
}) })
if (event) { if (event) {
event.activitypub_id = event.activitypub_id ? String(event.activitypub_id) : null
res.json(event) res.json(event)
} else { } else {
res.sendStatus(404) res.sendStatus(404)
@@ -171,17 +170,18 @@ const eventController = {
async getAll(req, res) { async getAll(req, res) {
// this is due how v-calendar shows dates // this is due how v-calendar shows dates
const start = moment().year(req.params.year).month(req.params.month) const start = moment().year(req.params.year).month(req.params.month)
.startOf('month').startOf('isoWeek').unix() .startOf('month').startOf('isoWeek')
let end = moment().utc().year(req.params.year).month(req.params.month).endOf('month') let end = moment().utc().year(req.params.year).month(req.params.month).endOf('month')
const shownDays = end.diff(start, 'days') const shownDays = end.diff(start, 'days')
if (shownDays <= 34) end = end.add(1, 'week') console.error(shownDays)
end = end.endOf('isoWeek').unix() if (shownDays <= 35) end = end.add(1, 'week')
end = end.endOf('isoWeek')
const events = await Event.findAll({ const events = await Event.findAll({
where: { where: {
is_visible: true, is_visible: true,
[Op.and]: [ [Op.and]: [
Sequelize.literal(`start_datetime >= ${start}`), Sequelize.literal(`start_datetime >= ${start.unix()}`),
Sequelize.literal(`start_datetime <= ${end}`) Sequelize.literal(`start_datetime <= ${end.unix()}`)
] ]
}, },
order: [ order: [

View File

@@ -9,26 +9,25 @@ const exportController = {
const type = req.params.type const type = req.params.type
const tags = req.query.tags const tags = req.query.tags
const places = req.query.places const places = req.query.places
const whereTag = {} const where = {}
const wherePlace = {} const yesterday = moment().subtract('1', 'day').unix()
const yesterday = moment().subtract('1', 'day')
if (tags) { if (tags) {
whereTag.tag = tags.split(',') where.tag = tags.split(',')
} }
if (places) { if (places) {
wherePlace.id = places.split(',') where.placeId = places.split(',')
} }
const events = await Event.findAll({ const events = await Event.findAll({
order: ['start_datetime'], order: ['start_datetime'],
where: { where: {
is_visible: true, is_visible: true,
start_datetime: { [Op.gte]: yesterday }, start_datetime: { [Op.gte]: yesterday },
placeId: places.split(',') ...where
}, },
attributes: { attributes: {
exclude: ['createdAt', 'updatedAt'] exclude: ['createdAt', 'updatedAt']
}, },
include: [{ model: Place, attributes: ['name', 'id', 'address', 'weigth'] }] include: [{ model: Place, attributes: ['name', 'id', 'address'] }]
}) })
switch (type) { switch (type) {
case 'feed': case 'feed':

View File

@@ -77,7 +77,7 @@ const settingsController = {
`https://${instance}`, callback) `https://${instance}`, callback)
const mastodon_auth = { client_id, client_secret, access_token } const mastodon_auth = { client_id, client_secret, access_token }
await settingsController.set('mastodon_auth', mastodon_auth, true) await settingsController.set('mastodon_auth', mastodon_auth, true)
const botController = require('./bot') const botController = require('./bot')
botController.initialize() botController.initialize()
res.redirect('/admin') res.redirect('/admin')
} catch (e) { } catch (e) {

View File

@@ -98,23 +98,24 @@ const userController = {
defaults: { address: body.place_address } }) defaults: { address: body.place_address } })
.spread((place, created) => place) .spread((place, created) => place)
await event.setPlace(place) await event.setPlace(place)
event.place = place
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
// create/assign tags // create/assign tags
if (body.tags) { if (body.tags) {
await Tag.bulkCreate(body.tags.map(t => ({ tag: t })), { ignoreDuplicates: true }) await Tag.bulkCreate(body.tags.map(t => ({ tag: t })), { ignoreDuplicates: true })
const tags = await Tag.findAll({ where: { tag: { [Op.in]: body.tags } } }) const tags = await Tag.findAll({ where: { tag: { [Op.in]: body.tags } } })
await Promise.all(tags.map(t => t.update({weigth: Number(t.weigth)+1})))
await event.addTags(tags) await event.addTags(tags)
event.tags = tags
} }
if (req.user) { if (req.user) {
await req.user.addEvent(event) await req.user.addEvent(event)
await event.setUser(req.user) await event.setUser(req.user)
} }
// event = await Event.findByPk(event.id, { include: [Tag, Place] })
// send response to client // send response to client
res.json(event) res.json(event)

View File

@@ -30,7 +30,6 @@ const jwt = expressJwt({
const [ prefix, token ] = req.cookies['auth._token.local'].split(' ') const [ prefix, token ] = req.cookies['auth._token.local'].split(' ')
if (prefix === 'Bearer') return token if (prefix === 'Bearer') return token
} }
return null
} }
}) })

View File

@@ -3,9 +3,10 @@ const path = require('path')
const moment = require('moment') const moment = require('moment')
const config = require('config') const config = require('config')
moment.locale(config.locale) moment.locale('it')
const mail = { const mail = {
send(addresses, template, locals) { send(addresses, template, locals) {
console.error('invio email via ', config.smtp)
const email = new Email({ const email = new Email({
views: { root: path.join(__dirname, '..', 'emails') }, views: { root: path.join(__dirname, '..', 'emails') },
htmlToText: false, htmlToText: false,
@@ -22,7 +23,7 @@ const mail = {
send: true, send: true,
i18n: { i18n: {
directory: path.join(__dirname, '..', '..', 'locales', 'email'), directory: path.join(__dirname, '..', '..', 'locales', 'email'),
defaultLocale: config.locale defaultLocale: 'it'
}, },
transport: config.smtp transport: config.smtp
}) })
@@ -30,11 +31,11 @@ const mail = {
template, template,
message: { message: {
to: addresses, to: addresses,
bcc: config.admin bcc: config.admin_email
}, },
locals: { locals: {
...locals, ...locals,
locale: config.locale, locale: 'it',
config: { title: config.title, baseurl: config.baseurl, description: config.description }, config: { title: config.title, baseurl: config.baseurl, description: config.description },
datetime: datetime => moment(datetime).format('ddd, D MMMM HH:mm') datetime: datetime => moment(datetime).format('ddd, D MMMM HH:mm')
} }

View File

@@ -20,15 +20,14 @@ module.exports = (sequelize, DataTypes) => {
index: true index: true
}, },
}, {}) }, {})
event.associate = function (models) { event.associate = function (models) {
event.belongsTo(models.place) event.belongsTo(models.place)
event.belongsTo(models.user) event.belongsTo(models.user)
event.belongsToMany(models.tag, { through: 'event_tags' }) event.belongsToMany(models.tag, { through: 'event_tags' })
event.belongsToMany(models.notification, { through: 'event_notification' }) event.belongsToMany(models.notification, { through: 'event_notification' })
event.hasMany(models.comment) event.hasMany(models.comment)
// Tag.belongsToMany(Event, { through: 'tagEvent' })
// Event.hasMany(models.Tag)
// associations can be defined here
} }
return event return event
} }

View File

@@ -10,7 +10,7 @@ module.exports = (sequelize, DataTypes) => {
} }
}, {}) }, {})
notification.associate = function (models) { notification.associate = function (models) {
notification.belongsToMany(models.event, { through: 'event_notification' }) notification.belongsToMany(models.event, { through: models.event_notification })
// associations can be defined here // associations can be defined here
} }
return notification return notification

View File

@@ -1,13 +1,15 @@
'use strict' 'use strict'
module.exports = (sequelize, DataTypes) => { module.exports = (sequelize, DataTypes) => {
const place = sequelize.define('place', { const place = sequelize.define('place', {
name: DataTypes.STRING, name: {
address: DataTypes.STRING, type: DataTypes.STRING,
weigth: DataTypes.INTEGER unique: true, index: true,
allowNull: false
},
address: DataTypes.STRING
}, {}) }, {})
place.associate = function (models) { place.associate = function (models) {
// associations can be defined here
place.hasMany(models.event) place.hasMany(models.event)
} }

View File

@@ -3,16 +3,16 @@ module.exports = (sequelize, DataTypes) => {
const tag = sequelize.define('tag', { const tag = sequelize.define('tag', {
tag: { tag: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false,
index: true, index: true,
primaryKey: true primaryKey: true
}, },
weigth: DataTypes.INTEGER, weigth: { type: DataTypes.INTEGER, defaultValue: 0, allowNull: false },
color: DataTypes.STRING color: DataTypes.STRING
}, {}) }, {})
tag.associate = function (models) { tag.associate = function (models) {
tag.belongsToMany(models.event, { through: 'event_tags' }) tag.belongsToMany(models.event, { through: 'event_tags' })
// associations can be defined here
} }
return tag return tag

View File

@@ -48,6 +48,10 @@ function parseArguments(rawArgs) {
}; };
} }
function notEmpty (value) {
return value.length>0
}
async function setupQuestionnaire() { async function setupQuestionnaire() {
const questions = [] const questions = []
@@ -55,7 +59,20 @@ async function setupQuestionnaire() {
message: 'Specify a baseurl for this gancio installation! (eg. http://gancio.cisti.org)', message: 'Specify a baseurl for this gancio installation! (eg. http://gancio.cisti.org)',
name: 'baseurl', name: 'baseurl',
default: 'http://localhost:3000', default: 'http://localhost:3000',
validate: baseurl => baseurl.length>0 validate: notEmpty
})
questions.push({
name: 'server.host',
message: 'address to listen to',
default: 'localhost',
validate: notEmpty
})
questions.push({
name: 'server.port',
message: 'port to listen to',
default: 13120,
}) })
questions.push({ questions.push({
@@ -75,22 +92,38 @@ async function setupQuestionnaire() {
}) })
questions.push({ questions.push({
name: 'db.user', name: 'db.host',
message: 'Postgres user', message: 'Postgres host',
default: 'localhost',
when: answers => answers.db.dialect === 'postgres',
validate: notEmpty
})
questions.push({
name: 'db.database',
message: 'DB name',
default: 'gancio', default: 'gancio',
when: answers => answers.db.dialect === 'postgres', when: answers => answers.db.dialect === 'postgres',
validate: user => user.length>0 validate: notEmpty
})
questions.push({
name: 'db.username',
message: 'DB user',
default: 'gancio',
when: answers => answers.db.dialect === 'postgres',
validate: notEmpty
}) })
questions.push({ questions.push({
name: 'db.pass', name: 'db.password',
type: 'password', type: 'password',
message: 'Postgres password', message: 'DB password',
default: 'gancio', default: 'gancio',
when: answers => answers.db.dialect === 'postgres', when: answers => answers.db.dialect === 'postgres',
validate: async (password, options) => { validate: async (password, options) => {
try { try {
const db = new sequelize({host: 'localhost', dialect: 'postgres', database: 'gancio', username: options.db.user, password }) const db = new sequelize({ ...options.db, dialect: 'postgres' , password, logging: false })
return db.authenticate().then( () => { return db.authenticate().then( () => {
consola.info(`DB connected`) consola.info(`DB connected`)
return true return true
@@ -117,14 +150,34 @@ async function setupQuestionnaire() {
questions.push({ questions.push({
name: 'admin.email', name: 'admin.email',
message: `Admin email (a first user with this username will be created)`, message: `Admin email (a first user with this username will be created)`,
validate: email => email.length>0 validate: notEmpty
}) })
questions.push({ questions.push({
name: 'admin.password', name: 'admin.password',
message: 'Admin password', message: 'Admin password',
type: 'password', type: 'password',
validate: password => password.length>0 validate: notEmpty
})
questions.push({
name: 'smtp.host',
message: 'SMTP Host',
validate: notEmpty,
})
questions.push({
name: 'smtp.auth.user',
message: 'SMTP User',
validate: notEmpty,
default: options => options.admin.email
})
questions.push({
name: 'smtp.auth.pass',
message: 'SMTP Password',
type: 'password',
validate: notEmpty,
}) })
const answers = await inquirer.prompt(questions) const answers = await inquirer.prompt(questions)

View File

@@ -1,4 +1,4 @@
p= t('email.confirm') p= t('email.confirm')
hr hr
a(href="#{config.baseurl}") #{config.title} - #{config.description} <a href="#{config.baseurl}"> #{config.title} - #{config.description}</a>

View File

@@ -3,7 +3,7 @@ p Dove: #{event.place.name} - #{event.place.address}
p Quando: #{datetime(event.start_datetime)} p Quando: #{datetime(event.start_datetime)}
br br
if event.image_path if event.image_path
<img style="width: 100%; max-height: 89vh; margin: 0 auto;" src="#{config.apiurl}/media/#{event.image_path}" /> <img style="width: 100%; max-height: 89vh; margin: 0 auto;" src="#{config.baseurl}/media/#{event.image_path}" />
p #{event.description} p #{event.description}
each tag in event.tags each tag in event.tags
@@ -17,4 +17,4 @@ else
p Puoi eliminare queste notifiche <a href="#{config.baseurl}/del_notification/#{notification.remove_code}">qui</a> p Puoi eliminare queste notifiche <a href="#{config.baseurl}/del_notification/#{notification.remove_code}">qui</a>
hr hr
a(href="#{config.baseurl}") #{config.title} - #{config.description} <a href="#{config.baseurl}">#{config.title} - #{config.description}</a>

View File

@@ -12,6 +12,9 @@ module.exports = {
consola.info('Generate random salt') consola.info('Generate random salt')
config.secret = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) config.secret = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
const admin = { email: config.admin.email, password: config.admin.password }
delete config.admin
config.admin_email = admin.email
consola.info(`Save configuration into ${config_path}`) consola.info(`Save configuration into ${config_path}`)
fs.writeFileSync(config_path, JSON.stringify(config, null, 2)) fs.writeFileSync(config_path, JSON.stringify(config, null, 2))
@@ -28,12 +31,12 @@ module.exports = {
// create admin user // create admin user
consola.info('Create admin user') consola.info('Create admin user')
await db.user.create({ await db.user.create({
email: config.admin.email, ...admin,
password: config.admin.password,
is_admin: true, is_admin: true,
is_active: true is_active: true
}) })
// set default settings // set default settings
consola.info('Set default settings') consola.info('Set default settings')
const settings = require('./api/controller/settings') const settings = require('./api/controller/settings')
@@ -42,9 +45,11 @@ module.exports = {
// add default notification // add default notification
consola.info('Add default notification') consola.info('Add default notification')
// send confirmed event to mastodon // send confirmed event to mastodon
await db.notification.create({ type: 'mastodon', filters: { is_visible: true } }) await db.notification.create({ type: 'mastodon', filters: { is_visible: true } })
// await notification.create({ type: 'mastodon', filters: { is_visible: true } })
// send every event to admin
await db.notification.create({ type: 'admin_email' })
} }
} }

View File

@@ -18,9 +18,7 @@ const notifier = {
case 'mail': case 'mail':
return mail.send(notification.email, 'event', { event, config, notification }) return mail.send(notification.email, 'event', { event, config, notification })
case 'admin_email': case 'admin_email':
const admins = await User.findAll({ where: { is_admin: true } }) return mail.send([config.smtp.auth.user, config.admin_email], 'event', { event, to_confirm: !event.is_visible, config, notification })
const admin_emails = admins.map(admin => admin.email)
return mail.send(admin_emails, 'event', { event, to_confirm: true, notification })
case 'mastodon': case 'mastodon':
// instance publish // instance publish
if (instance && access_token) { if (instance && access_token) {

View File

@@ -43,9 +43,9 @@ 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 let lastDay = null
events = map(events, e => { events = map(events, e => {