Skip to content
Browse files

First piece of Lift webapp for Music Gradebook

  • Loading branch information...
1 parent c5cceb6 commit f2d80cbd4e041c940f9a2affeb4981c1acfe5b54 @dcbriccetti committed Oct 16, 2012
View
32 music-gradebook/build.sbt
@@ -0,0 +1,32 @@
+name := "Lift 2.5 starter template"
+
+version := "0.0.1"
+
+organization := "net.liftweb"
+
+scalaVersion := "2.9.1"
+
+resolvers ++= Seq("snapshots" at "http://oss.sonatype.org/content/repositories/snapshots",
+ "releases" at "http://oss.sonatype.org/content/repositories/releases"
+ )
+
+seq(com.github.siasia.WebPlugin.webSettings :_*)
+
+scalacOptions ++= Seq("-deprecation", "-unchecked")
+
+libraryDependencies ++= {
+ val liftVersion = "2.5-M1"
+ Seq(
+ "net.liftweb" %% "lift-webkit" % liftVersion % "compile",
+ "net.liftweb" %% "lift-mapper" % liftVersion % "compile",
+ "net.liftmodules" %% "lift-jquery-module" % (liftVersion + "-1.0"),
+ "org.eclipse.jetty" % "jetty-webapp" % "8.1.7.v20120910" % "container,test",
+ "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container,test" artifacts Artifact("javax.servlet", "jar", "jar"),
+ "ch.qos.logback" % "logback-classic" % "1.0.6",
+ "org.specs2" %% "specs2" % "1.12.1" % "test",
+ "com.h2database" % "h2" % "1.3.167",
+ "org.squeryl" %% "squeryl" % "0.9.5-3",
+ "postgresql" % "postgresql" % "8.4-701.jdbc4"
+ )
+}
+
View
7 music-gradebook/project/plugins.sbt
@@ -0,0 +1,7 @@
+libraryDependencies <+= sbtVersion(v => "com.github.siasia" %% "xsbt-web-plugin" % "0.12.0-0.2.11.1")
+
+//Uncoment this line to enable the sbt idea plugin
+addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.1.0")
+
+//Uncoment this line to enable the sbt eclipse plugin
+addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")
View
1 music-gradebook/sbt
@@ -0,0 +1 @@
+java -Xmx1024M -Xss2M -XX:MaxPermSize=512m -XX:+CMSClassUnloadingEnabled -jar `dirname $0`/sbt-launch-0.12.jar "$@"
View
2 music-gradebook/sbt.bat
@@ -0,0 +1,2 @@
+set SCRIPT_DIR=%~dp0
+java -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx1024M -Xss2M -jar "%SCRIPT_DIR%\sbt-launch-0.12.jar" %*
View
23 music-gradebook/src/main/resources/props/default.logback.xml
@@ -0,0 +1,23 @@
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <file>console.devmode.log</file>
+ <append>true</append>
+ <encoder>
+ <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+
+
+ <logger name="com.dbschools.mgb.snippet" level="info" />
+ <logger name="net.liftweb" level="warn" />
+ <logger name="bootstrap.liftweb" level="info" />
+ <root level="warn">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>
View
0 music-gradebook/src/main/resources/props/default.props
No changes.
View
73 music-gradebook/src/main/scala/bootstrap/liftweb/Boot.scala
@@ -0,0 +1,73 @@
+package bootstrap.liftweb
+
+import net.liftweb._
+import util._
+import Helpers._
+
+import common._
+import http._
+import js.jquery.JQueryArtifacts
+import sitemap._
+import Loc._
+import mapper._
+
+import net.liftmodules.JQueryModule
+import org.squeryl.PrimitiveTypeMode._
+import com.dbschools.mgb.Db
+
+
+/**
+ * A class that's instantiated early and run. It allows the application
+ * to modify lift's environment
+ */
+class Boot {
+ def boot {
+ if (!DB.jndiJdbcConnAvailable_?) {
+ val vendor =
+ new StandardDBVendor(Props.get("db.driver") openOr "org.h2.Driver",
+ Props.get("db.url") openOr
+ "jdbc:h2:lift_proto.db;AUTO_SERVER=TRUE",
+ Props.get("db.user"), Props.get("db.password"))
+
+ LiftRules.unloadHooks.append(vendor.closeAllConnections_! _)
+
+ DB.defineConnectionManager(DefaultConnectionIdentifier, vendor)
+ }
+
+ // where to search snippet
+ LiftRules.addToPackages("com.dbschools.mgb")
+
+ // Build SiteMap
+ def sitemap = SiteMap(
+ Menu.i("Home") / "index"
+ )
+
+ LiftRules.setSiteMap(sitemap)
+
+ //Init the jQuery module, see http://liftweb.net/jquery for more information.
+ LiftRules.jsArtifacts = JQueryArtifacts
+ JQueryModule.InitParam.JQuery=JQueryModule.JQuery172
+ JQueryModule.init()
+
+ //Show the spinny image when an Ajax call starts
+ LiftRules.ajaxStart =
+ Full(() => LiftRules.jsArtifacts.show("ajax-loader").cmd)
+
+ // Make the spinny image go away when it ends
+ LiftRules.ajaxEnd =
+ Full(() => LiftRules.jsArtifacts.hide("ajax-loader").cmd)
+
+ // Force the request to be UTF-8
+ LiftRules.early.append(_.setCharacterEncoding("UTF-8"))
+
+ // What is the function to test if a user is logged in?
+ LiftRules.loggedInTest = Full(() => true)
+
+ // Use HTML5 for rendering
+ LiftRules.htmlProperties.default.set((r: Req) =>
+ new Html5Properties(r.userAgent))
+
+ Db.initialize()
+ S.addAround(new LoanWrapper{override def apply[T](f: => T): T = {inTransaction {f}}})
+ }
+}
View
20 music-gradebook/src/main/scala/com/dbschools/mgb/Db.scala
@@ -0,0 +1,20 @@
+package com.dbschools.mgb
+
+import java.sql.{Connection, DriverManager}
+import org.squeryl.adapters.PostgreSqlAdapter
+import org.squeryl.{SessionFactory, Session}
+
+object Db {
+
+ /**
+ * Initialize database processing for the webapp, and for standalone tests.
+ */
+ def initialize() {
+ Class.forName("org.postgresql.Driver")
+ SessionFactory.concreteFactory = Some(() =>
+ Session.create(
+ DriverManager.getConnection(
+ "jdbc:postgresql://localhost:5432/dbsmusic?user=dbschools", "", ""),
+ new PostgreSqlAdapter))
+ }
+}
View
13 music-gradebook/src/main/scala/com/dbschools/mgb/schema/AppSchema.scala
@@ -0,0 +1,13 @@
+package com.dbschools.mgb.schema
+
+import org.squeryl.Schema
+import org.squeryl.PrimitiveTypeMode._
+import org.squeryl.dsl.ast.{FunctionNode, EqualityExpression}
+import org.squeryl.Schema
+
+object AppSchema extends Schema {
+ val musicians = table[Musician]("musician")
+ val groups = table[Group]("music_group")
+ val musicianGroups = table[MusicianGroup]("musician_group")
+}
+
View
6 music-gradebook/src/main/scala/com/dbschools/mgb/schema/Group.scala
@@ -0,0 +1,6 @@
+package com.dbschools.mgb.schema
+
+case class Group(
+ group_id: Int,
+ name: String
+)
View
8 music-gradebook/src/main/scala/com/dbschools/mgb/schema/Musician.scala
@@ -0,0 +1,8 @@
+package com.dbschools.mgb.schema
+
+case class Musician(
+ musician_id: Int,
+ first_name: String,
+ last_name: String,
+ graduation_year: Int
+)
View
8 music-gradebook/src/main/scala/com/dbschools/mgb/schema/MusicianGroup.scala
@@ -0,0 +1,8 @@
+package com.dbschools.mgb.schema
+
+case class MusicianGroup(
+ id: Int,
+ musician_id: Int,
+ group_id: Int,
+ school_year: Int
+)
View
49 music-gradebook/src/main/scala/com/dbschools/mgb/snippet/Students.scala
@@ -0,0 +1,49 @@
+package com.dbschools.mgb
+package snippet
+
+import scala.xml.{NodeSeq, Text}
+import org.squeryl.PrimitiveTypeMode._
+import net.liftweb._
+import util._
+import Helpers._
+import schema.AppSchema
+
+class Students {
+
+ def render = {
+ <table>
+ <thead>
+ <tr>
+ <th>Graduation Year</th>
+ <th>Name</th>
+ <th>School Year</th>
+ <th>Group</th>
+ </tr>
+ </thead>
+ <tbody>
+ {
+ import AppSchema._
+ from (musicians, groups, musicianGroups)((m, g, mg) =>
+ where(m.musician_id === mg.musician_id and mg.group_id === g.group_id)
+ select((m, g, mg))
+ orderBy(mg.school_year, m.last_name, m.first_name, g.name)
+ ).map(r =>
+ <tr>
+ <td>
+ {r._1.graduation_year}
+ </td>
+ <td>
+ {r._1.last_name + ", " + r._1.first_name}
+ </td>
+ <td>
+ {r._3.school_year}
+ </td>
+ <td>
+ {r._2.name}
+ </td>
+ </tr>
+ )}
+ </tbody>
+ </table>
+ }
+}
View
21 music-gradebook/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+
+<!DOCTYPE web-app
+PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+"http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+<filter>
+ <filter-name>LiftFilter</filter-name>
+ <display-name>Lift Filter</display-name>
+ <description>The Filter that intercepts lift calls</description>
+ <filter-class>net.liftweb.http.LiftFilter</filter-class>
+</filter>
+
+
+<filter-mapping>
+ <filter-name>LiftFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+</filter-mapping>
+
+</web-app>
View
BIN music-gradebook/src/main/webapp/images/ajax-loader.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
11 music-gradebook/src/main/webapp/index.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<body class="lift:content_id=main">
+<div id="main" class="lift:surround?with=default;at=content">
+ <h2>Students</h2>
+ <div class="span-24">
+ <lift:Students/>
+ </div>
+</div>
+</body>
+</html>
View
78 music-gradebook/src/main/webapp/templates-hidden/default.html
@@ -0,0 +1,78 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:lift="http://liftweb.net/">
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
+ <meta name="description" content="" />
+ <meta name="keywords" content="" />
+ <title class="lift:Menu.title">DBSchools Music Gradebook</title>
+ <style class="lift:CSS.blueprint"></style>
+ <style class="lift:CSS.fancyType"></style>
+ <script id="jquery" src="/classpath/jquery.js" type="text/javascript"></script>
+ <script id="json" src="/classpath/json.js" type="text/javascript"></script>
+ <style type="text/css">
+/* <![CDATA[ */
+.edit_error_class {
+ display: block;
+ color: red;
+}
+
+.sidebar ul {
+ margin:0;
+ padding:0;
+ border-bottom:1px solid #ccc;
+}
+
+
+.sidebar ul li {
+ margin:0;
+ padding:0;
+ list-style:none;
+ border:1px solid #ccc;
+ border-bottom:none;
+}
+
+.sidebar ul li a {
+ display:block;
+ padding:3px;
+ text-indent:30px;
+ text-decoration:none;
+}
+
+.sidebar ul li span {
+ display:block;
+ padding:3px;
+ text-indent:30px;
+ text-decoration:none;
+}
+
+.sidebar ul li a:hover {
+ background-color: #eee;
+}
+
+
+ /* ]]> */
+ </style>
+ </head>
+ <body>
+ <div class="container">
+ <div class="column span-12 last" style="text-align: right">
+ <h1 class="alt">DBSchools Music Gradebook<img alt="" id="ajax-loader" style="display:none; margin-bottom: 0px; margin-left: 5px" src="/images/ajax-loader.gif"></h1>
+ </div>
+
+ <hr>
+
+ <div class="column span-6 colborder sidebar">
+ <hr class="space" >
+
+ <span class="lift:Menu.builder"></span>
+
+ <div class="lift:Msgs?showAll=true"></div>
+ <hr class="space" />
+ </div>
+
+ <div class="column span-17 last">
+ <div id="content">The main content will get bound here</div>
+ </div>
+
+ </div>
+ </body>
+</html>
View
23 music-gradebook/src/test/resources/logback-test.xml
@@ -0,0 +1,23 @@
+<configuration>
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+ <appender name="FILE" class="ch.qos.logback.core.FileAppender">
+ <file>console.devmode.log</file>
+ <append>true</append>
+ <encoder>
+ <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+
+
+ <logger name="com.dbschools.mgb.snippet" level="info" />
+ <logger name="net.liftweb" level="warn" />
+ <logger name="bootstrap.liftweb" level="info" />
+ <root level="warn">
+ <appender-ref ref="STDOUT" />
+ </root>
+</configuration>

0 comments on commit f2d80cb

Please sign in to comment.
Something went wrong with that request. Please try again.