From 3e41859789c644a59334da6a07157aa0f1e0138f Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 10 Dec 2012 16:35:33 +0100 Subject: wip --- src/main/scala/Web.scala | 25 +++++++++++ src/main/scala/developerstream/Db.scala | 30 ++++++++++++++ .../developerstream/DeveloperStreamPlan.scala | 48 ++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 src/main/scala/Web.scala create mode 100644 src/main/scala/developerstream/Db.scala create mode 100644 src/main/scala/developerstream/DeveloperStreamPlan.scala (limited to 'src/main/scala') diff --git a/src/main/scala/Web.scala b/src/main/scala/Web.scala new file mode 100644 index 0000000..b33e137 --- /dev/null +++ b/src/main/scala/Web.scala @@ -0,0 +1,25 @@ +import developerstream.DeveloperStreamPlan +import util.Properties + +object Web extends App { + val port = Properties.envOrElse("PORT", "1337").toInt + + unfiltered.jetty.Http.local(port).filter(new DeveloperStreamPlan()).run() + + + /* + val resources = new ResourceCollection( + Resource.newResource(new File("src/main/webapp")), + Resource.newClassPathResource("static/") + ) + + val server = new Server(port) + val context = new WebAppContext() + context.setContextPath("/") + context.setBaseResource(resources) + + server.setHandler(context) + server.setStopAtShutdown(true) + server.start() + */ +} diff --git a/src/main/scala/developerstream/Db.scala b/src/main/scala/developerstream/Db.scala new file mode 100644 index 0000000..4ddd129 --- /dev/null +++ b/src/main/scala/developerstream/Db.scala @@ -0,0 +1,30 @@ +package developerstream + +// Import the session management, including the implicit threadLocalSession +import org.scalaquery.session._ +import org.scalaquery.session.Database.threadLocalSession +import org.joda.time.DateTime +import java.util.UUID +import java.net.URL +import java.sql.Timestamp + +// Import the query language +import org.scalaquery.ql._ + +// Import the standard SQL types +import org.scalaquery.ql.TypeMapper._ + +// Use H2Driver which implements ExtendedProfile and thus requires ExtendedTables +import org.scalaquery.ql.extended.PostgresDriver.Implicit._ +import org.scalaquery.ql.extended.{ExtendedTable => Table} + +object Db { + val JenkinsServer = new Table[(UUID, Timestamp, String, Boolean)]("jenkins_server") { + def uuid = column[UUID]("uuid", O.PrimaryKey) + def created_date = column[Timestamp]("created_date") + def url = column[String]("url") + def enabled = column[Boolean]("enabled") + // Every table needs a * projection with the same type as the table's type parameter + def * = uuid ~ created_date ~ url ~ enabled + } +} diff --git a/src/main/scala/developerstream/DeveloperStreamPlan.scala b/src/main/scala/developerstream/DeveloperStreamPlan.scala new file mode 100644 index 0000000..ff36abc --- /dev/null +++ b/src/main/scala/developerstream/DeveloperStreamPlan.scala @@ -0,0 +1,48 @@ +package developerstream + +import unfiltered.request._ +import unfiltered.response._ +import unfiltered.filter.Plan +import unfiltered.filter.Plan._ +import org.scalaquery.session.{Database, Session} +import org.scalaquery.ql.Query +import org.scalaquery.ql._ +import org.scalaquery.ql.extended.PostgresDriver.Implicit._ +import org.scalaquery.ql.extended.{ExtendedTable => Table} +import xml.Elem + +class DeveloperStreamPlan extends Plan { + + def withSession[T](f: Session => T) = Database.forURL("jdbc:postgresql://localhost/esper", user = "esper", password = "esper") withSession { session => f(session) } + + def intent: Intent = { + case Path("/") => + Ok ~> Html5( + +

Jenkins Servers

+ + + + + + + + {withSession { + implicit session => + val q = for { + server <- Db.JenkinsServer + } yield server.url ~ server.enabled + + q.list map { case (url, enabled) => } + }} +
URLEnabled
{url}{enabled}
+ + ) + } + + val url = "" + val enabled = false + + def server() = + {url}{enabled} +} -- cgit v1.2.3