Skip to content

Commit

Permalink
Merge 5ec6124 into 6f40bd7
Browse files Browse the repository at this point in the history
  • Loading branch information
zingmane committed Apr 26, 2018
2 parents 6f40bd7 + 5ec6124 commit 914ca06
Show file tree
Hide file tree
Showing 15 changed files with 209 additions and 53 deletions.
1 change: 1 addition & 0 deletions GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Call this endpoint of a specific table to retrieve its columns. The different da
"multilanguage": true, // deprecated, false if languageType equals neutral
"languageType": "language", // language type can be neutral, language, or country
"identifier": true, // flag if this column is used to identify a row
"frontendReadOnly": true, // flag whether this column is marked as read only for the frontend (default: 'false')
"displayName": { // user-friendly column name
"de": "Name",
"en": "Name",
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ dependencies {
testCompile "io.vertx:vertx-unit:${vertxVersion}"
testCompile 'junit:junit:4.12'
testCompile "org.scalatest:scalatest_2.12:3.0.5"
testCompile 'org.skyscreamer:jsonassert:1.5.0'
}

mainClassName = "io.vertx.core.Launcher"
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/schema/schema_v22.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE system_columns
ADD COLUMN frontend_read_only BOOLEAN DEFAULT 'FALSE' NOT NULL;
Original file line number Diff line number Diff line change
Expand Up @@ -115,35 +115,45 @@ class StructureController(override val config: TableauxConfig, override protecte
for {
created <- tableStruc.create(tableName, hidden, langtags, displayInfos, SettingsTable, tableGroupId)

_ <- columnStruc.createColumn(
created,
CreateSimpleColumn("key", None, ShortTextType, LanguageNeutral, identifier = true, Seq.empty))
_ <- columnStruc.createColumn(created,
CreateSimpleColumn("key",
None,
ShortTextType,
LanguageNeutral,
identifier = true,
frontendReadOnly = false,
Seq.empty))
_ <- columnStruc.createColumn(
created,
CreateSimpleColumn("displayKey",
None,
ShortTextType,
MultiLanguage,
identifier = false,
frontendReadOnly = false,
Seq(
NameOnly("de", "Bezeichnung"),
NameOnly("en", "Identifier")
))
)
_ <- columnStruc.createColumn(created,
CreateSimpleColumn("value",
None,
TextType,
MultiLanguage,
identifier = false,
Seq(
NameOnly("de", "Inhalt"),
NameOnly("en", "Value")
)))
_ <- columnStruc.createColumn(
created,
CreateSimpleColumn("value",
None,
TextType,
MultiLanguage,
identifier = false,
frontendReadOnly = false,
Seq(
NameOnly("de", "Inhalt"),
NameOnly("en", "Value")
))
)
_ <- columnStruc.createColumn(created,
CreateAttachmentColumn("attachment",
None,
identifier = false,
frontendReadOnly = false,
Seq(
NameOnly("de", "Anhang"),
NameOnly("en", "Attachment")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class SystemController(override val config: TableauxConfig,
None,
singleDirection = false,
identifier = false,
frontendReadOnly = false,
List(),
Constraint(Cardinality(1, 0), deleteCascade = false)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ sealed trait ColumnInformation {
val name: String
val ordering: Ordering
val identifier: Boolean
val frontendReadOnly: Boolean
val displayInfos: Seq[DisplayInfo]
val groupColumnIds: Seq[ColumnId]
}
Expand All @@ -43,6 +44,7 @@ object BasicColumnInformation {
createColumn.name,
ordering,
createColumn.identifier,
createColumn.frontendReadOnly,
displayInfos,
Seq.empty)
}
Expand All @@ -53,6 +55,7 @@ case class BasicColumnInformation(override val table: Table,
override val name: String,
override val ordering: Ordering,
override val identifier: Boolean,
override val frontendReadOnly: Boolean,
override val displayInfos: Seq[DisplayInfo],
override val groupColumnIds: Seq[ColumnId])
extends ColumnInformation
Expand All @@ -63,6 +66,7 @@ case class ConcatColumnInformation(override val table: Table) extends ColumnInfo
// Right now, every concat column is
// an identifier
override val identifier = true
override val frontendReadOnly = false

override val id: ColumnId = 0
override val ordering: Ordering = 0
Expand Down Expand Up @@ -166,6 +170,8 @@ sealed trait ColumnType[+A] extends DomainObject {

final val identifier: Boolean = columnInformation.identifier

final val frontendReadOnly: Boolean = columnInformation.frontendReadOnly

override def getJson: JsonObject = {

// backward compatibility
Expand Down Expand Up @@ -198,6 +204,8 @@ sealed trait ColumnType[+A] extends DomainObject {
// do nothing
}

if (frontendReadOnly) json.mergeIn(Json.obj("frontendReadOnly" -> frontendReadOnly))

columnInformation.displayInfos.foreach(displayInfo => {
displayInfo.optionalName.map(name => {
json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sealed trait CreateColumn {
val languageType: LanguageType
val ordering: Option[Ordering]
val identifier: Boolean
val frontendReadOnly: Boolean
val displayInfos: Seq[DisplayInfo]
}

Expand All @@ -17,6 +18,7 @@ case class CreateSimpleColumn(override val name: String,
override val kind: TableauxDbType,
override val languageType: LanguageType,
override val identifier: Boolean,
override val frontendReadOnly: Boolean,
override val displayInfos: Seq[DisplayInfo])
extends CreateColumn

Expand All @@ -35,6 +37,7 @@ object CreateLinkColumn {
toDisplayInfos: Option[Seq[DisplayInfo]],
singleDirection: Boolean,
identifier: Boolean,
frontendReadOnly: Boolean,
displayInfos: Seq[DisplayInfo],
constraint: Constraint): CreateLinkColumn = {
val createBackLinkColumn = CreateBackLinkColumn(
Expand All @@ -49,6 +52,7 @@ object CreateLinkColumn {
toTable,
singleDirection,
identifier,
frontendReadOnly,
displayInfos,
constraint,
createBackLinkColumn
Expand All @@ -61,6 +65,7 @@ case class CreateLinkColumn(override val name: String,
toTable: TableId,
singleDirection: Boolean,
override val identifier: Boolean,
override val frontendReadOnly: Boolean,
override val displayInfos: Seq[DisplayInfo],
constraint: Constraint,
foreignLinkColumn: CreateBackLinkColumn)
Expand All @@ -72,6 +77,7 @@ case class CreateLinkColumn(override val name: String,
case class CreateAttachmentColumn(override val name: String,
override val ordering: Option[Ordering],
override val identifier: Boolean,
override val frontendReadOnly: Boolean,
override val displayInfos: Seq[DisplayInfo])
extends CreateColumn {
override val kind = AttachmentType
Expand All @@ -81,6 +87,7 @@ case class CreateAttachmentColumn(override val name: String,
case class CreateGroupColumn(override val name: String,
override val ordering: Option[Ordering],
override val identifier: Boolean,
override val frontendReadOnly: Boolean,
override val displayInfos: Seq[DisplayInfo],
groups: Seq[ColumnId])
extends CreateColumn {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class SystemModel(override protected[this] val connection: DatabaseConnection) e
setupVersion(readSchemaFile("schema_v18"), 18),
setupVersion(readSchemaFile("schema_v19"), 19),
setupVersion(readSchemaFile("schema_v20"), 20),
setupVersion(readSchemaFile("schema_v21"), 21)
setupVersion(readSchemaFile("schema_v21"), 21),
setupVersion(readSchemaFile("schema_v22"), 22)
)

private def readSchemaFile(name: String): String = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,21 @@ class ColumnModel(val connection: DatabaseConnection) extends DatabaseQuery {
): Future[(connection.Transaction, CreatedColumnInformation)] = {

def insertStatement(tableId: TableId, ordering: String) = {
s"""INSERT INTO system_columns (
table_id,
column_id,
column_type,
user_column_name,
ordering,
link_id,
multilanguage,
identifier,
country_codes
)
VALUES (?, nextval('system_columns_column_id_table_$tableId'), ?, ?, $ordering, ?, ?, ?, ?)
RETURNING column_id, ordering""".stripMargin
s"""|INSERT INTO system_columns (
| table_id,
| column_id,
| column_type,
| user_column_name,
| ordering,
| link_id,
| multilanguage,
| identifier,
| frontend_read_only,
| country_codes
| )
| VALUES (?, nextval('system_columns_column_id_table_$tableId'), ?, ?, $ordering, ?, ?, ?, ?, ?)
| RETURNING column_id, ordering
|""".stripMargin
}

val countryCodes = createColumn.languageType match {
Expand Down Expand Up @@ -425,6 +427,7 @@ RETURNING column_id, ordering""".stripMargin
linkId.orNull,
createColumn.languageType.toString,
createColumn.identifier,
createColumn.frontendReadOnly,
countryCodes.map(f => Json.arr(f: _*)).orNull
)
)
Expand All @@ -439,6 +442,7 @@ RETURNING column_id, ordering""".stripMargin
linkId.orNull,
createColumn.languageType.toString,
createColumn.identifier,
createColumn.frontendReadOnly,
countryCodes.map(f => Json.arr(f: _*)).orNull
)
)
Expand Down Expand Up @@ -646,7 +650,8 @@ RETURNING column_id, ordering""".stripMargin
| (
| SELECT json_agg(group_column_id) FROM system_column_groups
| WHERE table_id = c.table_id AND grouped_column_id = c.column_id
| ) AS group_column_ids
| ) AS group_column_ids,
| frontend_read_only
|FROM system_columns c
|WHERE
| table_id = ? AND
Expand Down Expand Up @@ -730,7 +735,8 @@ RETURNING column_id, ordering""".stripMargin
| (
| SELECT json_agg(group_column_id) FROM system_column_groups
| WHERE table_id = c.table_id AND grouped_column_id = c.column_id
| ) AS group_column_ids
| ) AS group_column_ids,
| frontend_read_only
|FROM system_columns c
|WHERE
| table_id = ?
Expand Down Expand Up @@ -844,6 +850,8 @@ RETURNING column_id, ordering""".stripMargin
.map(str => Json.fromArrayString(str).asScala.map(_.asInstanceOf[Int].toLong).toSeq)
.getOrElse(Seq.empty[ColumnId])

val frontendReadOnly = row.get[Boolean](8)

for {
displayInfoSeq <- retrieveDisplayInfo(table, columnId)

Expand All @@ -853,6 +861,7 @@ RETURNING column_id, ordering""".stripMargin
columnName,
ordering,
identifier,
frontendReadOnly,
displayInfoSeq,
groupColumnIds
)
Expand Down
8 changes: 5 additions & 3 deletions src/main/scala/com/campudus/tableaux/helper/JsonUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ object JsonUtils extends LazyLogging {
// optional fields
val ordering = Try(json.getInteger("ordering").longValue()).toOption
val identifier = Try[Boolean](json.getBoolean("identifier")).getOrElse(false)
val frontendReadOnly = Try[Boolean](json.getBoolean("frontendReadOnly")).getOrElse(false)

// languageType or deprecated multilanguage
// if languageType == 'country' countryCodes must be specified
Expand All @@ -99,7 +100,7 @@ object JsonUtils extends LazyLogging {

dbType match {
case AttachmentType =>
CreateAttachmentColumn(name, ordering, identifier, displayInfos)
CreateAttachmentColumn(name, ordering, identifier, frontendReadOnly, displayInfos)

case LinkType =>
// link specific fields
Expand Down Expand Up @@ -140,6 +141,7 @@ object JsonUtils extends LazyLogging {
toTableId,
singleDirection,
identifier,
frontendReadOnly,
displayInfos,
constraint.getOrElse(DefaultConstraint),
createBackLinkColumn)
Expand All @@ -153,10 +155,10 @@ object JsonUtils extends LazyLogging {
.map(_.toLong)
.toSeq

CreateGroupColumn(name, ordering, identifier, displayInfos, groups)
CreateGroupColumn(name, ordering, identifier, frontendReadOnly, displayInfos, groups)

case _ =>
CreateSimpleColumn(name, ordering, dbType, languageType, identifier, displayInfos)
CreateSimpleColumn(name, ordering, dbType, languageType, identifier, frontendReadOnly, displayInfos)
}
}
}
Expand Down
Loading

0 comments on commit 914ca06

Please sign in to comment.