Skip to content

Commit

Permalink
[FIX] root
Browse files Browse the repository at this point in the history
  • Loading branch information
Elad Meidar committed Aug 13, 2012
1 parent d9b5bf1 commit 709ff28
Show file tree
Hide file tree
Showing 17 changed files with 218 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
@@ -0,0 +1,7 @@
logs
project/project
project/target
target
tmp
.history
dist
4 changes: 4 additions & 0 deletions README
@@ -0,0 +1,4 @@
This is your new Play 2.0 application
=====================================

This file will be packaged with your application, when using `play dist`.
4 changes: 4 additions & 0 deletions app/assets/javascripts/index.coffee
@@ -0,0 +1,4 @@
$ ->
$.get "/listBars", (data) ->
$.each data, (index, item) ->
$("#bars").append "<li>" + item.name + " was here</li>"
43 changes: 43 additions & 0 deletions app/controllers/Application.scala
@@ -0,0 +1,43 @@
package controllers

import play.api.data.Form
import play.api.data.Forms.{single, nonEmptyText}
import play.api.mvc.{Action, Controller}

import com.codahale.jerkson.Json

import anorm.NotAssigned

import models.Bar


object Application extends Controller {

val barForm = Form(
single("name" -> nonEmptyText)
)

def index = Action {
Ok(views.html.index(barForm))
}

def addBar() = Action { implicit request =>
barForm.bindFromRequest.fold(
errors => BadRequest,
{
case (name) =>
Bar.create(Bar(NotAssigned, name))
Redirect(routes.Application.index())
}
)
}

def listBars() = Action {
val bars = Bar.findAll()

val json = Json.generate(bars)

Ok(json).as("application/json")
}

}
34 changes: 34 additions & 0 deletions app/models/Bar.scala
@@ -0,0 +1,34 @@
package models

import play.api.db._
import play.api.Play.current

import anorm._
import anorm.SqlParser._

case class Bar(id: Pk[Long], name: String)

object Bar {

val simple = {
get[Pk[Long]]("id") ~
get[String]("name") map {
case id~name => Bar(id, name)
}
}

def findAll(): Seq[Bar] = {
DB.withConnection { implicit connection =>
SQL("select * from bar").as(Bar.simple *)
}
}

def create(bar: Bar): Unit = {
DB.withConnection { implicit connection =>
SQL("insert into bar(name) values ({name})").on(
'name -> bar.name
).executeUpdate()
}
}

}
12 changes: 12 additions & 0 deletions app/views/index.scala.html
@@ -0,0 +1,12 @@
@(form: play.api.data.Form[String])

@main("Elad's tests") {

@helper.form(action = routes.Application.addBar) {
@helper.inputText(form("name"))
<input type="submit"/>
}

<script src="@routes.Assets.at("javascripts/index.js")" type="text/javascript"></script>
<ul id="bars">koko</ul>
}
15 changes: 15 additions & 0 deletions app/views/main.scala.html
@@ -0,0 +1,15 @@
@(title: String)(content: Html)

<!DOCTYPE html>

<html>
<head>
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
<script src="@routes.Assets.at("javascripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
</head>
<body>
@content
</body>
</html>
45 changes: 45 additions & 0 deletions conf/application.conf
@@ -0,0 +1,45 @@
# This is the main configuration file for the application.
# ~~~~~

# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
application.secret="mtcN0fdBoU1L:VaDpE;uYm2EVkoiknKeOS>aKLRdeb_MaLt17Ag4D3CekVrq42Qy"

# The application languages
# ~~~~~
application.langs="en"

# Global object class
# ~~~~~
# Define the Global object class for this application.
# Default to Global in the root package.
# global=Global

# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"

# Evolutions
# ~~~~~
# You can disable evolutions if needed
# evolutionplugin=disabled

# Logger
# ~~~~~
# You can also configure logback (http://logback.qos.ch/), by providing a logger.xml file in the conf directory .

# Root logger:
logger.root=ERROR

# Logger used by the framework:
logger.play=INFO

# Logger provided to your application:
logger.application=DEBUG

Empty file added conf/evolutions/1.sql
Empty file.
12 changes: 12 additions & 0 deletions conf/evolutions/default/1.sql
@@ -0,0 +1,12 @@
# --- First database schema

# --- !Ups

CREATE TABLE bar (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL
);

# --- !Downs

DROP TABLE IF EXISTS bar;
11 changes: 11 additions & 0 deletions conf/routes
@@ -0,0 +1,11 @@
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET / controllers.Application.index
POST /addBar controllers.Application.addBar
GET /listBars controllers.Application.listBars

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
18 changes: 18 additions & 0 deletions project/Build.scala
@@ -0,0 +1,18 @@
import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

val appName = "foobar"
val appVersion = "1.0-SNAPSHOT"

val appDependencies = Seq(
// Add your project dependencies here,
)

val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
// Add your own project settings here
)

}
1 change: 1 addition & 0 deletions project/build.properties
@@ -0,0 +1 @@
sbt.version=0.11.2
8 changes: 8 additions & 0 deletions project/plugins.sbt
@@ -0,0 +1,8 @@
// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.0.1")
Binary file added public/images/favicon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/javascripts/jquery-1.7.1.min.js

Large diffs are not rendered by default.

Empty file added public/stylesheets/main.css
Empty file.

0 comments on commit 709ff28

Please sign in to comment.