Skip to content

Commit

Permalink
#32 Add lavel and path to model
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Nov 20, 2017
1 parent 8a90afe commit 411d86c
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions app/org/elastic4play/models/ModelDef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ abstract class ModelAttributes(val name: String) extends AttributeDef {
val updatedAt = optionalAttribute("updatedAt", AttributeFormat.dateFmt, "user who created this entity", AttributeOption.model)
}

abstract class BaseModelDef(name: String) extends ModelAttributes(name) {
abstract class BaseModelDef(name: String, val label: String, val path: String) extends ModelAttributes(name) {
def apply(attributes: JsObject): BaseEntity
def removeAttribute: JsObject = throw InternalError(s"$name can't be removed")

Expand Down Expand Up @@ -132,13 +132,13 @@ abstract class EntityDef[M <: BaseModelDef, E <: BaseEntity](model: M, attribute
}
}

abstract class AbstractModelDef[M <: AbstractModelDef[M, E], E <: BaseEntity](name: String) extends BaseModelDef(name) {
abstract class AbstractModelDef[M <: AbstractModelDef[M, E], E <: BaseEntity](name: String, label: String, path: String) extends BaseModelDef(name, label, path) {
override def apply(attributes: JsObject): E
}

abstract class ModelDef[M <: ModelDef[M, E], E <: BaseEntity](name: String)(implicit e: Manifest[E]) extends AbstractModelDef[M, E](name) { self: M
abstract class ModelDef[M <: ModelDef[M, E], E <: BaseEntity](name: String, label: String, path: String)(implicit e: Manifest[E]) extends AbstractModelDef[M, E](name, label, path) { self: M
override def apply(attributes: JsObject): E = e.runtimeClass.getConstructor(getClass, classOf[JsObject]).newInstance(self, attributes).asInstanceOf[E]
}
abstract class ChildModelDef[M <: ChildModelDef[M, E, PM, PE], E <: BaseEntity, PM <: BaseModelDef, PE <: BaseEntity](val parentModel: PM, name: String)(implicit e: Manifest[E]) extends AbstractModelDef[M, E](name) { self: M
abstract class ChildModelDef[M <: ChildModelDef[M, E, PM, PE], E <: BaseEntity, PM <: BaseModelDef, PE <: BaseEntity](val parentModel: PM, name: String, label: String, path: String)(implicit e: Manifest[E]) extends AbstractModelDef[M, E](name, label, path) { self: M
override def apply(attributes: JsObject): E = e.runtimeClass.getConstructor(getClass, classOf[JsObject]).newInstance(self, attributes).asInstanceOf[E]
}
2 changes: 1 addition & 1 deletion app/org/elastic4play/services/AttachmentSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ trait AttachmentAttributes { _: AttributeDef ⇒
}

@Singleton
class AttachmentModel(datastoreName: String) extends ModelDef[AttachmentModel, AttachmentChunk](datastoreName) with AttachmentAttributes {
class AttachmentModel(datastoreName: String) extends ModelDef[AttachmentModel, AttachmentChunk](datastoreName, "Attachment", "/datastore") with AttachmentAttributes {
@Inject() def this(configuration: Configuration) = this(configuration.get[String]("datastore.name"))
}
class AttachmentChunk(model: AttachmentModel, attributes: JsObject) extends EntityDef[AttachmentModel, AttachmentChunk](model, attributes) with AttachmentAttributes
Expand Down
2 changes: 1 addition & 1 deletion app/org/elastic4play/services/DBList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.elastic4play.models.{ Attribute, EntityDef, ModelDef, AttributeFormat
import org.elastic4play.utils.{ Hasher, RichFuture }

@Singleton
class DBListModel(dblistName: String) extends ModelDef[DBListModel, DBListItemEntity](dblistName) {
class DBListModel(dblistName: String) extends ModelDef[DBListModel, DBListItemEntity](dblistName, "DBList", "/list") {
model
@Inject def this(configuration: Configuration) = this(configuration.get[String]("dblist.name"))

Expand Down
2 changes: 1 addition & 1 deletion test/org/elastic4play/services/CreateSrvSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.elastic4play.{ AttributeCheckingError, InvalidFormatAttributeError, M
@RunWith(classOf[JUnitRunner])
class CreateSrvSpec extends PlaySpecification with Mockito {

class TestModel extends ModelDef[TestModel, TestEntity]("testModel") {
class TestModel extends ModelDef[TestModel, TestEntity]("testModel", "TestModel", "/test") {
val textAttribute: Attribute[String] = attribute("textAttribute", F.textFmt, "textAttribute")
val stringAttribute: Attribute[String] = attribute("stringAttribute", F.stringFmt, "stringAttribute")
val dateAttribute: Attribute[Date] = attribute("dateAttribute", F.dateFmt, "dateAttribute")
Expand Down
2 changes: 1 addition & 1 deletion test/org/elastic4play/services/DeleteSrvSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import org.elastic4play.utils.RichFuture
@RunWith(classOf[JUnitRunner])
class DeleteSrvSpec extends PlaySpecification with Mockito {

class TestModel extends ModelDef[TestModel, TestEntity]("testModel") {
class TestModel extends ModelDef[TestModel, TestEntity]("testModel", "TestModel", "/test") {
val textAttribute = attribute("textAttribute", F.textFmt, "textAttribute")
val stringAttribute = attribute("stringAttribute", F.stringFmt, "stringAttribute")
val dateAttribute = attribute("dateAttribute", F.dateFmt, "dateAttribute")
Expand Down
2 changes: 1 addition & 1 deletion test/org/elastic4play/services/UpdateSrvSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.elastic4play.{ AttributeCheckingError, InvalidFormatAttributeError, U
@RunWith(classOf[JUnitRunner])
class UpdateSrvSpec extends PlaySpecification with Mockito {

class TestModel extends ModelDef[TestModel, TestEntity]("testModel") {
class TestModel extends ModelDef[TestModel, TestEntity]("testModel", "TestModel", "/test") {
val textAttribute = attribute("textAttribute", F.textFmt, "textAttribute")
val stringAttribute = attribute("stringAttribute", F.stringFmt, "stringAttribute")
val dateAttribute = attribute("dateAttribute", F.dateFmt, "dateAttribute")
Expand Down

0 comments on commit 411d86c

Please sign in to comment.