Skip to content

Commit

Permalink
updated to play 2
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesward committed Mar 22, 2012
1 parent 6d6f0c1 commit 3132c73
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 155 deletions.
13 changes: 6 additions & 7 deletions .gitignore
@@ -1,7 +1,6 @@
logs
project/project
project/target
target
tmp
*.iml

/logs
/project/project
/project/target
/target
/*.iml
/.idea
39 changes: 0 additions & 39 deletions Playbars2a.iml

This file was deleted.

2 changes: 1 addition & 1 deletion Procfile
@@ -1 +1 @@
web: target/start
web: target/start -Dhttp.port=$PORT -DapplyEvolutions.default=true -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=$DATABASE_URL
19 changes: 0 additions & 19 deletions app/Global.java

This file was deleted.

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>Bar " + item.name + "</li>"
16 changes: 5 additions & 11 deletions app/controllers/Application.java
Expand Up @@ -13,24 +13,18 @@
public class Application extends Controller {

public static Result index() {
return ok(index.render("2 Enter the name of your new bar:", form(Bar.class)));
return ok(index.render(form(Bar.class)));
}

public static Result addBar() {
Form<Bar> form = form(Bar.class).bindFromRequest();
if (form.hasErrors()) {
return badRequest(index.render("Error in Bar form. Enter new Bar", form(Bar.class)));
} else {
Bar bar = form.get();
bar.save();
return ok(
index.render("2 The bar " + bar.name + " was saved. Enter a new Bar:", form(Bar.class))
);
}
Bar bar = form.get();
bar.save();
return redirect(controllers.routes.Application.index());
}

public static Result listBars() {
JsonNode jsonNodes = toJson(Bar.findAll());
JsonNode jsonNodes = toJson(Bar.find.all());
return ok(jsonNodes);
}
}
14 changes: 4 additions & 10 deletions app/models/Bar.java
Expand Up @@ -3,22 +3,16 @@
import play.db.ebean.Model;

import javax.persistence.Entity;
import java.util.List;
import javax.persistence.Id;

@Entity
public class Bar extends Model {

@Id
public String id;

public String name;

// -- Queries
public static Model.Finder<String, Bar> find = new Model.Finder(String.class, Bar.class);

/**
* Retrieve all users.
*/
public static List<Bar> findAll() {
return find.all();
}


}
23 changes: 7 additions & 16 deletions app/views/index.scala.html
@@ -1,23 +1,14 @@
@(message: String)(barForm: Form[Bar])
@(form: play.data.Form[Bar])

@import helper._
@main("Welcome to Play 2.0") {

@main("Welcome to PlayBar 2") {
<h3>@message</h3>
<script src="@routes.Assets.at("javascripts/index.js")" type="text/javascript"></script>

@form(action = routes.Application.addBar, args = 'id -> "barForm") {
<ul id="bars"></ul>

@inputText(
field = barForm("name"),
args = 'label -> "Name of bar?", 'placeholder -> "Foo Bar"
)

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

<ul id="bars">

</ul>
}
15 changes: 1 addition & 14 deletions app/views/main.scala.html
Expand Up @@ -5,23 +5,10 @@
<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.6.4.min.js")" type="text/javascript"></script>

<script type="text/javascript">
$(function() {
$.get("bars.json", function(data) {
$.each(data, function(index, item) {
$("#bars").append("<li>Bar " + item.name + "</li>");
});
});
});
</script>

<script src="@routes.Assets.at("javascripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
</head>
<body>
<h1>@title</h1>
@content
</body>
</html>
7 changes: 3 additions & 4 deletions conf/application.conf
Expand Up @@ -13,16 +13,15 @@ application.secret="E27D^[_<Lpt0vjad]de;3/i;tx3gpRmG4Byof/3nahO/dIo9gbsMWut1w3xg
# 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.driver=org.postgresql.Driver
db.default.driver=org.h2.Driver
#db.default.driver=org.postgresql.Driver


#eventually moving to heroku, we need to use an environment variable
#for an in-memory database set this to --- jdbc:h2:mem:play
#for postgresql database set this to --- jdbc:postgresql://localhost:5432/postgres?user=postgres&password=oracle

#db.default.url=${DATABASE_URL}
db.default.url=${MY_DB_URL}
db.default.url="jdbc:h2:mem:play"

# Ebean configuration
# ~~~~~
Expand Down
26 changes: 26 additions & 0 deletions conf/evolutions/default/1.sql
@@ -0,0 +1,26 @@
# --- Created by Ebean DDL
# To stop Ebean DDL generation, remove this comment and start using Evolutions

# --- !Ups

create table bar (
id varchar(255) not null,
name varchar(255),
constraint pk_bar primary key (id))
;

create sequence bar_seq;




# --- !Downs

SET REFERENTIAL_INTEGRITY FALSE;

drop table if exists bar;

SET REFERENTIAL_INTEGRITY TRUE;

drop sequence if exists bar_seq;

8 changes: 0 additions & 8 deletions conf/initial-data.yml

This file was deleted.

6 changes: 3 additions & 3 deletions conf/routes
Expand Up @@ -3,9 +3,9 @@
# ~~~~

# Home page
GET / controllers.Application.index()
GET /bars.json controllers.Application.listBars
POST / controllers.Application.addBar
GET / controllers.Application.index
GET /listBars controllers.Application.listBars
POST /addBar controllers.Application.addBar

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
14 changes: 3 additions & 11 deletions project/Build.scala
Expand Up @@ -4,23 +4,15 @@ import PlayProject._

object ApplicationBuild extends Build {

val appName = "PlayBars2a"
val appVersion = "1.0"

val postgresql = "postgresql" % "postgresql" % "9.0-801.jdbc3"

ebeanEnabled := true
val appName = "play2bars-scala"
val appVersion = "1.0-SNAPSHOT"

val appDependencies = Seq(
// Add your project dependencies here,
postgresql
"postgresql" % "postgresql" % "9.0-801.jdbc3"
)

val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
// Add your own project settings here
resolvers ++= Seq(DefaultMavenRepository,
Resolver.url("Play", url("https://playframework2.ci.cloudbees.com/job/play2-integrationtest/ws/repository/local/"))
(Resolver.ivyStylePatterns), "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/")
)

}
13 changes: 5 additions & 8 deletions project/plugins.sbt
@@ -1,11 +1,8 @@
// Comment to get more information during initialization
logLevel := Level.Warn

resolvers ++= Seq(
DefaultMavenRepository,
Resolver.url("Play", url("https://playframework2.ci.cloudbees.com/job/play2-integrationtest/ws/repository/local/"))(Resolver.ivyStylePatterns),
"Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
)
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

addSbtPlugin("play" % "sbt-plugin" % "2.0-RC1-SNAPSHOT")

addSbtPlugin("com.typesafe.startscript" % "xsbt-start-script-plugin" % "0.5.0")
// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.0")
4 changes: 0 additions & 4 deletions public/javascripts/jquery-1.6.4.min.js

This file was deleted.

4 changes: 4 additions & 0 deletions public/javascripts/jquery-1.7.1.min.js

Large diffs are not rendered by default.

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

0 comments on commit 3132c73

Please sign in to comment.