-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,886 additions
and
291 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.