Skip to content
Snippets Groups Projects
Commit 26b4b35e authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Add pad settings sync; fixed design settings sync

parent 793e1023
No related branches found
No related tags found
No related merge requests found
Showing with 165 additions and 46 deletions
package de.tobias.playpad.server.project.settings
import java.util.UUID
import javafx.util.Duration
import de.tobias.playpad.server.json._
import de.tobias.playpad.server.project.{Design, Pad}
class PadSettings {
@JsonName(value = "id", handler = classOf[UUIDSerializerHandler])
var id: UUID = UUID.randomUUID()
@JsonName(value = "volume", handler = classOf[DoubleSerializerHandler])
var volume: Double = _
@JsonName(value = "loop", handler = classOf[BooleanSerializerHandler])
var loop: Boolean = _
@JsonName("timeMode")
var timeMode: String = _ // In PlayWallDesktop ENUM
@JsonObj("fade")
var fade: Fade = _
@JsonName(value = "warning", handler = classOf[DurationSerializerHandler])
var warning: Duration = _
@JsonObj("design")
var design: Design = _
@JsonParent
var pad: Pad = _
}
......@@ -32,8 +32,14 @@ object SqlDef {
val DESIGN = "Design"
val DESIGN_ID = "id"
val DESIGN_PAD_REF = "pad_id"
val DESIGN_PAD_REF = "settings_id"
val DESIGN_BACKGROUND_COLOR = "background_color"
val DESIGN_PLAY_COLOR = "play_color"
val PAD_SETTINGS = "PadSettings"
val PAD_SETTINGS_PAD_REF = "pad_id"
val PAD_SETTINGS_VOLUME = "volume"
val PAD_SETTINGS_LOOP = "looping"
val PAD_SETTINGS_TIME_MODE = "timemode"
val PAD_SETTINGS_WARNING = "warning"
}
......@@ -32,8 +32,13 @@ object SqlHelper {
preparedStatement.setString(2, value)
preparedStatement.setString(3, value)
case value: Boolean =>
preparedStatement.setBoolean(2, value)
preparedStatement.setBoolean(3, value)
val v = if (value) {
1
} else {
0
}
preparedStatement.setInt(2, v)
preparedStatement.setInt(3, v)
case value: Int =>
preparedStatement.setInt(2, value)
preparedStatement.setInt(3, value)
......@@ -51,7 +56,6 @@ object SqlHelper {
preparedStatement.setNull(3, NULL)
}
preparedStatement
}
......@@ -96,66 +100,67 @@ object SqlHelper {
| `project_id` varchar(48) DEFAULT NULL,
| PRIMARY KEY (`id`),
| UNIQUE KEY `id` (`id`),
| CONSTRAINT `Page_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `Project` (`id`) ON DELETE CASCADE
| KEY `project_id` (`project_id`),
| CONSTRAINT `Page_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `Project` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin)
createTable(
"""CREATE TABLE IF NOT EXISTS `Fade` (
"""CREATE TABLE IF NOT EXISTS `Pad` (
| `id` varchar(48) NOT NULL DEFAULT '',
| `fadeIn` int(11) DEFAULT NULL,
| `fadeOut` int(11) DEFAULT NULL,
| `fadeInStart` tinyint(1) DEFAULT NULL,
| `fadeInPause` tinyint(1) DEFAULT NULL,
| `fadeOutPause` tinyint(1) DEFAULT NULL,
| `fadeOutStop` tinyint(1) DEFAULT NULL,
| PRIMARY KEY (`id`)
| `name` varchar(255) DEFAULT NULL,
| `position` int(11) DEFAULT NULL,
| `content_type` varchar(100) DEFAULT NULL,
| `page_id` varchar(48) DEFAULT NULL,
| PRIMARY KEY (`id`),
| UNIQUE KEY `id` (`id`),
| KEY `Pad_ibfk_1` (`page_id`),
| CONSTRAINT `Pad_ibfk_1` FOREIGN KEY (`page_id`) REFERENCES `Page` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin)
createTable(
"""CREATE TABLE IF NOT EXISTS `Design` (
"""CREATE TABLE IF NOT EXISTS `Path` (
| `id` varchar(40) NOT NULL DEFAULT '',
| `background_color` varchar(20) DEFAULT NULL,
| `play_color` varchar(20) DEFAULT NULL,
| PRIMARY KEY (`id`)
| `filename` text,
| `pad_id` varchar(40) DEFAULT NULL,
| PRIMARY KEY (`id`),
| KEY `pad_id` (`pad_id`),
| CONSTRAINT `Path_ibfk_1` FOREIGN KEY (`pad_id`) REFERENCES `Pad` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin)
createTable(
"""CREATE TABLE IF NOT EXISTS `PadSettings` (
| `id` varchar(48) NOT NULL DEFAULT '',
| `volume` double DEFAULT NULL,
| `loop` tinyint(1) DEFAULT NULL,
| `timeMode` varchar(20) DEFAULT NULL,
| `fade` varchar(48) DEFAULT NULL,
| `warning` int(11) DEFAULT NULL,
| `design` varchar(48) DEFAULT NULL,
| `pad_id` varchar(48) DEFAULT NULL,
| PRIMARY KEY (`id`),
| KEY `fade` (`fade`),
| KEY `design` (`design`),
| CONSTRAINT `PadSettings_ibfk_2` FOREIGN KEY (`design`) REFERENCES `Design` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
| CONSTRAINT `PadSettings_ibfk_1` FOREIGN KEY (`fade`) REFERENCES `Fade` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
| KEY `pad_id` (`pad_id`),
| CONSTRAINT `PadSettings_ibfk_1` FOREIGN KEY (`pad_id`) REFERENCES `Pad` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin)
createTable(
"""CREATE TABLE IF NOT EXISTS `Pad` (
| `id` varchar(48) NOT NULL DEFAULT '',
| `name` varchar(255) DEFAULT NULL,
| `position` int(11) DEFAULT NULL,
| `content_type` varchar(100) DEFAULT NULL,
| `page_id` varchar(48) DEFAULT NULL,
"""CREATE TABLE IF NOT EXISTS `Design` (
| `id` varchar(40) NOT NULL DEFAULT '',
| `background_color` varchar(20) DEFAULT NULL,
| `play_color` varchar(20) DEFAULT NULL,
| `settings_id` varchar(48) DEFAULT NULL,
| PRIMARY KEY (`id`),
| UNIQUE KEY `id` (`id`),
| KEY `Pad_ibfk_1` (`page_id`),
| KEY `settings_id` (`settings_id`),
| CONSTRAINT `Pad_ibfk_2` FOREIGN KEY (`settings_id`) REFERENCES `PadSettings` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
| CONSTRAINT `Pad_ibfk_1` FOREIGN KEY (`page_id`) REFERENCES `Page` (`id`) ON DELETE CASCADE
| CONSTRAINT `Design_ibfk_1` FOREIGN KEY (`settings_id`) REFERENCES `PadSettings` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin)
createTable(
"""CREATE TABLE IF NOT EXISTS `Path` (
| `id` varchar(40) NOT NULL DEFAULT '',
| `filename` text,
| `pad_id` varchar(40) DEFAULT NULL,
"""CREATE TABLE IF NOT EXISTS `Fade` (
| `id` varchar(48) NOT NULL DEFAULT '',
| `fadeIn` int(11) DEFAULT NULL,
| `fadeOut` int(11) DEFAULT NULL,
| `fadeInStart` tinyint(1) DEFAULT NULL,
| `fadeInPause` tinyint(1) DEFAULT NULL,
| `fadeOutPause` tinyint(1) DEFAULT NULL,
| `fadeOutStop` tinyint(1) DEFAULT NULL,
| `padSettings_id` varchar(48) DEFAULT NULL,
| PRIMARY KEY (`id`),
| KEY `pad_id` (`pad_id`),
| CONSTRAINT `Path_ibfk_1` FOREIGN KEY (`pad_id`) REFERENCES `Pad` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
| KEY `padSettings_id` (`padSettings_id`),
| CONSTRAINT `Fade_ibfk_1` FOREIGN KEY (`padSettings_id`) REFERENCES `PadSettings` (`id`)
|) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin)
}
}
......@@ -10,6 +10,7 @@ import de.tobias.playpad.server.account.Account
import de.tobias.playpad.server.project.utils.SqlDef
import de.tobias.playpad.server.server.SqlHelper
import de.tobias.playpad.server.server.project.sync.listener.design.{DesignAddListener, DesignUpdateListener}
import de.tobias.playpad.server.server.project.sync.listener.pad.settings.{PadSettingsAddListener, PadSettingsUpdateListener}
import de.tobias.playpad.server.server.project.sync.listener.pad.{PadAddListener, PadClearListener, PadRemoveListener, PadUpdateListener}
import de.tobias.playpad.server.server.project.sync.listener.page.{PageAddListener, PageRemoveListener, PageUpdateListener}
import de.tobias.playpad.server.server.project.sync.listener.path.{PathAddListener, PathRemoveListener}
......@@ -47,7 +48,10 @@ import scala.collection.{Map, mutable}
"path-rm" -> new PathRemoveListener(),
"design-add" -> new DesignAddListener(),
"design-update" -> new DesignUpdateListener()
"design-update" -> new DesignUpdateListener(),
"pad-settings-add" -> new PadSettingsAddListener(),
"pad-settings-update" -> new PadSettingsUpdateListener()
)
@OnWebSocketConnect def onConnect(serverSession: Session): Unit = {
......
......@@ -15,11 +15,11 @@ import de.tobias.playpad.server.server.project.sync.listener.Listener
class DesignAddListener extends Listener {
override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = {
val designId = UUID.fromString(json.get("id").getAsString)
val padId = UUID.fromString(json.get("pad").getAsString)
val padSettingsId = UUID.fromString(json.get("pad_settings").getAsString)
val backgroundColor = json.get("background_color").getAsString
val playColor = json.get("play_color").getAsString
SqlHelper.insertOrUpdate(connection, SqlDef.DESIGN, designId, SqlDef.DESIGN_PAD_REF, padId)
SqlHelper.insertOrUpdate(connection, SqlDef.DESIGN, designId, SqlDef.DESIGN_PAD_REF, padSettingsId)
SqlHelper.insertOrUpdate(connection, SqlDef.DESIGN, designId, SqlDef.DESIGN_BACKGROUND_COLOR, backgroundColor)
SqlHelper.insertOrUpdate(connection, SqlDef.DESIGN, designId, SqlDef.DESIGN_PLAY_COLOR, playColor)
}
......
......@@ -15,14 +15,14 @@ import de.tobias.playpad.server.server.project.sync.listener.Listener
class DesignUpdateListener extends Listener {
override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = {
val designId = UUID.fromString(json.get("id").getAsString)
val padId = UUID.fromString(json.get("pad").getAsString)
val padSettingsId = UUID.fromString(json.get("pad_settings").getAsString)
val field = json.get("field").getAsString
SqlHelper.insertOrUpdate(connection, DESIGN, designId, DESIGN_PAD_REF, padId)
SqlHelper.insertOrUpdate(connection, DESIGN, designId, DESIGN_PAD_REF, padSettingsId)
field match {
case "background_color" => SqlHelper.insertOrUpdate(connection, DESIGN, designId, DESIGN_BACKGROUND_COLOR, json.get("value").getAsString)
case "play_color" => SqlHelper.insertOrUpdate(connection, DESIGN, designId, DESIGN_PLAY_COLOR, json.get("value").getAsInt)
case "play_color" => SqlHelper.insertOrUpdate(connection, DESIGN, designId, DESIGN_PLAY_COLOR, json.get("value").getAsString)
}
}
}
package de.tobias.playpad.server.server.project.sync.listener.pad.settings
import java.sql.Connection
import java.util.UUID
import com.google.gson.JsonObject
import de.tobias.playpad.server.account.Session
import de.tobias.playpad.server.project.utils.SqlDef
import de.tobias.playpad.server.server.SqlHelper
import de.tobias.playpad.server.server.project.sync.listener.Listener
class PadSettingsAddListener extends Listener {
override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = {
val padSettingsId = UUID.fromString(json.get("id").getAsString)
val padId = UUID.fromString(json.get("pad_id").getAsString)
val volume = json.get("volume").getAsDouble
val loop = json.get("loop").getAsBoolean
SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, padSettingsId, SqlDef.PAD_SETTINGS_PAD_REF, padId)
SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, padSettingsId, SqlDef.PAD_SETTINGS_VOLUME, volume)
SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, padSettingsId, SqlDef.PAD_SETTINGS_LOOP, loop)
if (json.get("time_mode") != null) {
val timeMode = json.get("time_mode").getAsString
SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, padSettingsId, SqlDef.PAD_SETTINGS_TIME_MODE, timeMode)
}
if (json.get("warning") != null) {
val warning = json.get("warning").getAsInt
SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, padSettingsId, SqlDef.PAD_SETTINGS_WARNING, warning)
}
}
}
package de.tobias.playpad.server.server.project.sync.listener.pad.settings
import java.sql.Connection
import java.util.UUID
import com.google.gson.JsonObject
import de.tobias.playpad.server.account.Session
import de.tobias.playpad.server.project.utils.SqlDef
import de.tobias.playpad.server.server.SqlHelper
import de.tobias.playpad.server.server.project.sync.listener.Listener
class PadSettingsUpdateListener extends Listener {
override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = {
val settingsId = UUID.fromString(json.get("id").getAsString)
val padId = UUID.fromString(json.get("pad_id").getAsString)
val field = json.get("field").getAsString
SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, settingsId, SqlDef.PAD_SETTINGS_PAD_REF, padId)
field match {
case "volume" => SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, settingsId, SqlDef.PAD_SETTINGS_VOLUME, json.get("value").getAsDouble)
case "loop" => SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, settingsId, SqlDef.PAD_SETTINGS_LOOP, json.get("value").getAsBoolean)
case "time_mode" =>
val value = if (!json.get("value").isJsonNull) {
json.get("value").getAsString
} else {
null
}
SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, settingsId, SqlDef.PAD_SETTINGS_TIME_MODE, value)
case "warning" =>
val value = if (!json.get("value").isJsonNull) {
json.get("value").getAsInt
} else {
null
}
SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, settingsId, SqlDef.PAD_SETTINGS_WARNING, value)
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment