Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sscarano committed Mar 31, 2012
1 parent 4eb604e commit aefe092
Show file tree
Hide file tree
Showing 39 changed files with 1,886 additions and 291 deletions.
5 changes: 0 additions & 5 deletions .openshift/action_hooks/build

This file was deleted.

5 changes: 0 additions & 5 deletions .openshift/action_hooks/deploy

This file was deleted.

4 changes: 0 additions & 4 deletions .openshift/action_hooks/post_deploy

This file was deleted.

5 changes: 0 additions & 5 deletions .openshift/action_hooks/pre_build

This file was deleted.

4 changes: 0 additions & 4 deletions .openshift/action_hooks/start

This file was deleted.

2 changes: 0 additions & 2 deletions .openshift/action_hooks/stop

This file was deleted.

22 changes: 0 additions & 22 deletions .openshift/cron/README.cron

This file was deleted.

Empty file removed .openshift/cron/daily/.gitignore
Empty file.
Empty file removed .openshift/cron/hourly/.gitignore
Empty file.
Empty file.
Empty file removed .openshift/cron/monthly/.gitignore
Empty file.
16 changes: 0 additions & 16 deletions .openshift/cron/weekly/README

This file was deleted.

1 change: 0 additions & 1 deletion .openshift/cron/weekly/chrono.dat

This file was deleted.

3 changes: 0 additions & 3 deletions .openshift/cron/weekly/chronograph

This file was deleted.

12 changes: 0 additions & 12 deletions .openshift/cron/weekly/jobs.allow

This file was deleted.

7 changes: 0 additions & 7 deletions .openshift/cron/weekly/jobs.deny

This file was deleted.

55 changes: 5 additions & 50 deletions README
Original file line number Diff line number Diff line change
@@ -1,52 +1,7 @@
Feel free to change or remove this file, it is informational only.
This is a classic CRUD application, backed by a JDBC database. It demonstrates:

Get started
===========
1. Add framework of choice to your repo.
2. Modify .openshift/action_hooks/start to start your application.
The application is required to bind to $OPENSHIFT_INTERNAL_IP:8080.
3. Modify .openshift/action_hooks/stop to stop your application.
4. Commit and push your changes.
- Accessing a JDBC database, using Anorm.
- Achieving, table pagination and CRUD forms.
- Integrating with a CSS framework (Twitter Bootstrap ).

Repo layout
===========
static/ - Externally exposed static content goes here
../data - For persistent data (full path in environment var: OPENSHIFT_DATA_DIR)
.openshift/action_hooks/start - Script that gets run to start your application
.openshift/action_hooks/stop - Script that gets run to stop your application
.openshift/action_hooks/pre_build - Script that gets run every git push before the build
.openshift/action_hooks/build - Script that gets run every git push as part of the build process (on the CI system if available)
.openshift/action_hooks/deploy - Script that gets run every git push after build but before the app is restarted
.openshift/action_hooks/post_deploy - Script that gets run every git push after the app is restarted


Notes about layout
==================
Please leave the static directory in place (alter but do not delete) but feel
free to create additional directories if needed.

Note: Every time you push, everything in your remote repo dir gets recreated
please store long term items (like an sqlite database) in ../data which will
persist between pushes of your repo.


Environment Variables
=====================

OpenShift Express provides several environment variables to reference for ease
of use. The following list are some common variables but far from exhaustive:

$_ENV['OPENSHIFT_INTERNAL_IP'] - IP Address assigned to the application
$_ENV['OPENSHIFT_GEAR_NAME'] - Application name
$_ENV['OPENSHIFT_GEAR_DIR'] - Application dir
$_ENV['OPENSHIFT_DATA_DIR'] - For persistent storage (between pushes)
$_ENV['OPENSHIFT_TMP_DIR'] - Temp storage (unmodified files deleted after 10 days)

To get a full list of environment variables, simply add a line in your
.openshift/action_hooks/build script that says "export" and push.


Additional information
======================

Link to additional information will be here, when we have it :)
Twitter Bootstrap requires a different form layout to the default one that the Play 2.0 form helper generates, so this application also provides an example of integrating a custom form input constructor.
112 changes: 112 additions & 0 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package controllers

import play.api._
import play.api.mvc._
import play.api.data._
import play.api.data.Forms._

import anorm._

import views._
import models._

/**
* Manage a database of computers
*/
object Application extends Controller {

/**
* This result directly redirect to the application home.
*/
val Home = Redirect(routes.Application.list(0, 2, ""))

/**
* Describe the computer form (used in both edit and create screens).
*/
val computerForm = Form(
mapping(
"id" -> ignored(NotAssigned:Pk[Long]),
"name" -> nonEmptyText,
"introduced" -> optional(date("yyyy-MM-dd")),
"discontinued" -> optional(date("yyyy-MM-dd")),
"company" -> optional(longNumber)
)(Computer.apply)(Computer.unapply)
)

// -- Actions

/**
* Handle default path requests, redirect to computers list
*/
def index = Action { Home }

/**
* Display the paginated list of computers.
*
* @param page Current page number (starts from 0)
* @param orderBy Column to be sorted
* @param filter Filter applied on computer names
*/
def list(page: Int, orderBy: Int, filter: String) = Action { implicit request =>
Ok(html.list(
Computer.list(page = page, orderBy = orderBy, filter = ("%"+filter+"%")),
orderBy, filter
))
}

/**
* Display the 'edit form' of a existing Computer.
*
* @param id Id of the computer to edit
*/
def edit(id: Long) = Action {
Computer.findById(id).map { computer =>
Ok(html.editForm(id, computerForm.fill(computer)))
}.getOrElse(NotFound)
}

/**
* Handle the 'edit form' submission
*
* @param id Id of the computer to edit
*/
def update(id: Long) = Action { implicit request =>
computerForm.bindFromRequest.fold(
formWithErrors => BadRequest(html.editForm(id, formWithErrors)),
computer => {
Computer.update(id, computer)
Home.flashing("success" -> "Computer %s has been updated".format(computer.name))
}
)
}

/**
* Display the 'new computer form'.
*/
def create = Action {
Ok(html.createForm(computerForm))
}

/**
* Handle the 'new computer form' submission.
*/
def save = Action { implicit request =>
computerForm.bindFromRequest.fold(
formWithErrors => BadRequest(html.createForm(formWithErrors)),
computer => {
Computer.insert(computer)
Home.flashing("success" -> "Computer %s has been created".format(computer.name))
}
)
}

/**
* Handle computer deletion.
*/
def delete(id: Long) = Action {
Computer.delete(id)
Home.flashing("success" -> "Computer has been deleted")
}

}

Loading

0 comments on commit aefe092

Please sign in to comment.