Slowly adding some basic table mutators
parent
74afa40620
commit
076000c934
|
@ -60,6 +60,8 @@ object CellsServer extends cask.MainRoutes
|
|||
{
|
||||
send(AddTable(table.serialize))
|
||||
}
|
||||
case RequestSetTablePosition(id, x, y) =>
|
||||
send(SetTablePosition(id, x, y))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,16 @@ package net.okennedy.cells.state
|
|||
import net.okennedy.cells.Identifier
|
||||
import net.okennedy.cells.serialized
|
||||
|
||||
class Table(var id: Identifier)
|
||||
class Table(val id: Identifier)
|
||||
{
|
||||
var x = 20
|
||||
var y = 20
|
||||
|
||||
def serialize =
|
||||
serialized.Table(
|
||||
id
|
||||
id = id,
|
||||
x = x,
|
||||
y = y,
|
||||
)
|
||||
|
||||
}
|
|
@ -6,8 +6,18 @@ sealed trait WebsocketRequest
|
|||
|
||||
case class WebsocketHello(client: String) extends WebsocketRequest
|
||||
|
||||
sealed trait CanvasRequest extends WebsocketRequest
|
||||
|
||||
sealed trait TableRequest extends CanvasRequest
|
||||
{
|
||||
val table: Identifier
|
||||
}
|
||||
|
||||
case class RequestSetTablePosition(table: Identifier, x: Int, y: Int) extends TableRequest
|
||||
|
||||
object WebsocketRequest
|
||||
{
|
||||
implicit val WebsocketHelloFormat: Format[WebsocketHello] = Json.format
|
||||
implicit val RequestSetTablePositionFormat: Format[RequestSetTablePosition] = Json.format
|
||||
implicit val WebsocketRequestFormat: Format[WebsocketRequest] = Json.format
|
||||
}
|
|
@ -8,10 +8,14 @@ sealed trait CanvasOp extends WebsocketResponse
|
|||
case class AddTable(table: serialized.Table) extends CanvasOp
|
||||
|
||||
sealed trait TableOp extends CanvasOp
|
||||
|
||||
{
|
||||
val table: Identifier
|
||||
}
|
||||
case class SetTablePosition(table: Identifier, x: Int, y: Int) extends TableOp
|
||||
|
||||
object WebsocketResponse
|
||||
{
|
||||
implicit val AddTableFormat: Format[AddTable] = Json.format
|
||||
implicit val WebsocketResponseFormat: Format[WebsocketResponse] = Json.format
|
||||
implicit val SetTablePositionResponseFormat: Format[SetTablePosition] = Json.format
|
||||
implicit val WebsocketResponseFormat: Format[WebsocketResponse] = Json.format
|
||||
}
|
|
@ -5,8 +5,8 @@ import net.okennedy.cells._
|
|||
|
||||
case class Table(
|
||||
id: Identifier,
|
||||
// x: Int,
|
||||
// y: Int,
|
||||
x: Int,
|
||||
y: Int,
|
||||
// rows: Seq[RowSpec],
|
||||
// cols: Seq[ColSpec],
|
||||
// data: Seq[Seq[Cell]]
|
||||
|
|
|
@ -10,7 +10,7 @@ import net.okennedy.cells.sheet
|
|||
|
||||
class Connection(url: String)
|
||||
{
|
||||
val canvas = new sheet.Canvas()
|
||||
val canvas = new sheet.Canvas(this)
|
||||
|
||||
var socket = getSocket()
|
||||
|
||||
|
|
|
@ -4,8 +4,9 @@ import scala.collection.mutable
|
|||
import com.raquo.airstream.state.Var
|
||||
import net.okennedy.cells._
|
||||
import com.raquo.laminar.api.L._
|
||||
import net.okennedy.cells.network.Connection
|
||||
|
||||
class Canvas()
|
||||
class Canvas(connection: Connection)
|
||||
{
|
||||
val tables = Var[Map[Identifier, Table]](initial = Map.empty)
|
||||
|
||||
|
@ -13,7 +14,9 @@ class Canvas()
|
|||
{
|
||||
op match {
|
||||
case AddTable(table) =>
|
||||
tables.set(tables.now() ++ Map(table.id -> new Table(table)))
|
||||
tables.set(tables.now() ++ Map(table.id -> new Table(table, connection)))
|
||||
case op:TableOp =>
|
||||
tables.now().apply(op.table).process(op)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,17 +12,38 @@ import com.raquo.airstream.flatten.FlattenStrategy.ConcurrentStreamStrategy
|
|||
import com.raquo.airstream.flatten.FlattenStrategy
|
||||
import net.okennedy.cells.widgets.DragFrame
|
||||
import com.raquo.airstream.ownership.OneTimeOwner
|
||||
import net.okennedy.cells.TableOp
|
||||
import net.okennedy.cells.SetTablePosition
|
||||
import com.raquo.airstream.core.Transaction
|
||||
import net.okennedy.cells.CellsUI
|
||||
import net.okennedy.cells.network.Connection
|
||||
import net.okennedy.cells.RequestSetTablePosition
|
||||
|
||||
class Table(val id: Identifier)
|
||||
class Table(val id: Identifier, connection: Connection)
|
||||
{
|
||||
implicit val tableOwner: Owner =
|
||||
new OneTimeOwner( () => println(s"Accessing owner of table $id after killed") )
|
||||
|
||||
def this(ser: serialized.Table) =
|
||||
def this(ser: serialized.Table, connection: Connection) =
|
||||
{
|
||||
this(
|
||||
ser.id
|
||||
ser.id,
|
||||
connection
|
||||
)
|
||||
new Transaction( _ =>
|
||||
this.x.set(ser.x)
|
||||
this.y.set(ser.y)
|
||||
)
|
||||
}
|
||||
|
||||
def process(op: TableOp): Unit =
|
||||
{
|
||||
op match {
|
||||
case SetTablePosition(_, newX, newY) =>
|
||||
new Transaction( _ =>
|
||||
x.set(newX); y.set(newY)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val columns =
|
||||
|
@ -106,7 +127,11 @@ class Table(val id: Identifier)
|
|||
width.now()+Constants.GUTTER_WIDTH,
|
||||
height.now()+Constants.GUTTER_HEIGHT,
|
||||
evt
|
||||
) { (x, y) => println(s"Move to : $x, $y")}
|
||||
) { (x, y) =>
|
||||
connection.send(
|
||||
RequestSetTablePosition(id, x, y)
|
||||
)
|
||||
}
|
||||
evt.stopPropagation()
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue