summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/api/events.js11
-rw-r--r--server/migrations/20190402032400-add-configid-event.js4
-rw-r--r--server/models/config.js1
-rw-r--r--server/models/event.js3
-rw-r--r--webapp/src/components/EventModuleEdit.vue9
-rw-r--r--webapp/src/components/EventModuleEventList.vue2
-rw-r--r--webapp/src/store/events.js3
7 files changed, 17 insertions, 16 deletions
diff --git a/server/api/events.js b/server/api/events.js
index 23aeae7..5affbb0 100644
--- a/server/api/events.js
+++ b/server/api/events.js
@@ -13,7 +13,7 @@ var router = decorateApp(express.Router())
* @return: Returns event of given id.
*/
router.getAsync('/:id', async (req, res) => {
- var event = await db.event.findOne({ where: { id: req.params.id }, include: ['clients', 'groups'] })
+ var event = await db.event.findOne({ where: { id: req.params.id }, include: ['config', 'clients', 'groups'] })
if (event) res.send(event)
else res.status(404).end()
})
@@ -22,7 +22,7 @@ router.getAsync('/:id', async (req, res) => {
* @return: Returns a list of all events in the database.
*/
router.getAsync('', async (req, res) => {
- var events = await db.event.findAll({ include: ['clients', 'groups'] })
+ var events = await db.event.findAll({ include: ['config', 'clients', 'groups'] })
if (events) res.status(200).send(events)
else res.status(404).end()
})
@@ -30,6 +30,9 @@ router.getAsync('', async (req, res) => {
// ############################################################################
// ########################## POST requests #################################
+/*
+ * @return: Returns a list of all childs of the given groups
+ */
router.postAsync('/blacklist', async (req, res) => {
if (req.body.groups) {
var blacklist = await groupUtil.getAllChildren(req.body.groups)
@@ -51,7 +54,7 @@ router.postAsync(['', '/:id'], async (req, res) => {
// Update existing role
eventDb = await db.event.findOne({ where: { id: req.params.id } })
if (eventDb !== null) {
- promises.push(eventDb.update({ name: req.body.name, description: req.body.description, config: req.body.config || null, times: req.body.times, important: req.body.important }))
+ promises.push(eventDb.update({ name: req.body.name, description: req.body.description, times: req.body.times, important: req.body.important, configId: req.body.config || null }))
promises.push(eventDb.setGroups(req.body.groups, { through: { blacklist: 0 } }))
promises.push(eventDb.setClients(req.body.clients, { through: { blacklist: 0 } }))
await Promise.all(promises)
@@ -64,7 +67,7 @@ router.postAsync(['', '/:id'], async (req, res) => {
}
} else {
// Create new role
- eventDb = await db.event.create({ name: req.body.name, description: req.body.description, config: req.body.config || null, times: req.body.times, important: req.body.important })
+ eventDb = await db.event.create({ name: req.body.name, description: req.body.description, times: req.body.times, important: req.body.important, configId: req.body.config || null })
promises.push(eventDb.setGroups(req.body.groups, { through: { blacklist: 0 } }))
promises.push(eventDb.setClients(req.body.clients, { through: { blacklist: 0 } }))
await Promise.all(promises)
diff --git a/server/migrations/20190402032400-add-configid-event.js b/server/migrations/20190402032400-add-configid-event.js
index 34e6ac9..fa44b52 100644
--- a/server/migrations/20190402032400-add-configid-event.js
+++ b/server/migrations/20190402032400-add-configid-event.js
@@ -1,7 +1,7 @@
'use strict'
module.exports = {
up: (queryInterface, Sequelize) => {
- return queryInterface.addColumn('events', 'config', {
+ return queryInterface.addColumn('events', 'configId', {
type: Sequelize.INTEGER,
onDelete: 'SET NULL',
references: {
@@ -11,6 +11,6 @@ module.exports = {
})
},
down: (queryInterface, Sequelize) => {
- return queryInterface.removeColumn('events', 'config')
+ return queryInterface.removeColumn('events', 'configId')
}
}
diff --git a/server/models/config.js b/server/models/config.js
index ae728f6..84f3d1b 100644
--- a/server/models/config.js
+++ b/server/models/config.js
@@ -24,6 +24,7 @@ module.exports = (sequelize, DataTypes) => {
config.belongsToMany(models.entry, { as: 'entries', through: ConfigXEntry, foreignKey: 'configId', otherKey: 'entryId' })
config.hasMany(models.group, { as: 'groups' })
config.hasMany(models.client, { as: 'clients' })
+ config.hasMany(models.event, { as: 'events'})
}
return config
}
diff --git a/server/models/event.js b/server/models/event.js
index 11a35e7..00f72c7 100644
--- a/server/models/event.js
+++ b/server/models/event.js
@@ -9,7 +9,6 @@ module.exports = (sequelize, DataTypes) => {
},
name: DataTypes.STRING,
description: DataTypes.STRING(2048),
- config: DataTypes.INTEGER,
times: DataTypes.STRING(4096),
important: DataTypes.BOOLEAN
}, {
@@ -21,6 +20,8 @@ module.exports = (sequelize, DataTypes) => {
var GroupXEvent = sequelize.define('group_x_event', { blacklist: DataTypes.BOOLEAN }, { timestamps: false, freezeTableName: true })
event.belongsToMany(models.group, { as: 'groups', through: GroupXEvent, foreignKey: 'eventId', otherKey: 'groupId' })
+
+ event.belongsTo(models.config, { as: 'config' })
}
return event
}
diff --git a/webapp/src/components/EventModuleEdit.vue b/webapp/src/components/EventModuleEdit.vue
index 196a94e..5421fba 100644
--- a/webapp/src/components/EventModuleEdit.vue
+++ b/webapp/src/components/EventModuleEdit.vue
@@ -458,14 +458,7 @@ export default {
this.description = value.info.description || ''
this.important = value.info.important || false
- this.config = []
- if (value.info.config) {
- for (let i = 0; i < this.configList.length; i++) {
- if (this.configList[i].id === value.info.config) {
- this.config.push(this.configList[i])
- }
- }
- }
+ this.config = [value.info.config] || []
this.times = value.info.times ? JSON.parse(value.info.times) : {}
this.repetitiveEvent = this.times.repetitive || false
diff --git a/webapp/src/components/EventModuleEventList.vue b/webapp/src/components/EventModuleEventList.vue
index fe2ac1a..1cbe233 100644
--- a/webapp/src/components/EventModuleEventList.vue
+++ b/webapp/src/components/EventModuleEventList.vue
@@ -58,7 +58,7 @@ export default {
return [
{ text: this.$t('name'), key: 'name' },
{ text: this.$t('description'), key: 'description' },
- { text: this.$t('config'), key: 'config' },
+ { text: this.$t('config'), key: 'configName' },
{ sortable: false, key: 'action', width: '60px' }
]
},
diff --git a/webapp/src/store/events.js b/webapp/src/store/events.js
index 9f9e29b..7a5551f 100644
--- a/webapp/src/store/events.js
+++ b/webapp/src/store/events.js
@@ -19,6 +19,9 @@ export default {
actions: {
loadEvents (context) {
axios.get('/api/events').then(response => {
+ for (let i = 0; i < response.data.length; i++) {
+ response.data[i].configName = response.data[i].config.name
+ }
context.commit('setEvents', response.data)
})
},