Skip to content

Commit

Permalink
Analytics if configured will be included
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivar Abrahamsen committed Jul 2, 2012
1 parent eec64e0 commit d8ec199
Show file tree
Hide file tree
Showing 26 changed files with 86 additions and 60 deletions.
10 changes: 6 additions & 4 deletions app/Global.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@

import controllers.Tracked
import play.api._
import play.api.mvc._
import play.api.mvc.Results._

object Global extends GlobalSettings {
object Global extends GlobalSettings {

private val analyticsDetails = None

override def onHandlerNotFound(request: RequestHeader) = {
if (request.path != "/favicon.ico" ) // && Logger.isInfoEnabled)
Logger.info("Not found: " + request.path)
NotFound(views.html.errors.notfound(request.path))
NotFound(views.html.errors.notfound(request.path)(analyticsDetails))
}

//override def onBadRequest(request: RequestHeader, error: String) = {
Expand All @@ -17,7 +19,7 @@ object Global extends GlobalSettings {

override def onError(request: RequestHeader, ex: Throwable) = {
Logger.error("Server error: " + request.path,ex)
InternalServerError(views.html.errors.servererror(ex))
InternalServerError(views.html.errors.servererror(ex)(analyticsDetails))
}


Expand Down
4 changes: 2 additions & 2 deletions app/controllers/AlbumController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import models._
import notifiers.EmailNotifier


object AlbumController extends Controller with EventWrappers with Secured {
object AlbumController extends Controller with EventWrappers with Secured with Tracked {

val albumForm = Form(
tuple(
Expand Down Expand Up @@ -59,7 +59,7 @@ object AlbumController extends Controller with EventWrappers with Secured {
val albums = Album.findAlbums(eventId)
val participants = event.findParticipants
val requesters = event.findRequests
BadRequest(views.html.events.edit(event,albums,participants,requesters,EventController.updateForm)
BadRequest(views.html.events.edit(event,albums,participants,requesters,EventController.updateForm,EventController.addParticipantToEventForm)
).flashing("errorMessage" -> "Invalid album data")
},
submittedAlbumForm => {
Expand Down
12 changes: 10 additions & 2 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package controllers

import play.api._
import play.api.Play.current
import mvc._
import play.api.data._
import play.api.data.Forms._
import models._
import notifiers._

object Application extends Controller with Secured {
object Application extends Controller with Secured with Tracked {


val loginForm = Form(
Expand Down Expand Up @@ -150,8 +151,9 @@ trait Secured {
}

def onUnauthorised(request: RequestHeader, event: Event)(implicit session: Session, flash: Flash) = {
implicit def analyticsDetails : Option[String] = Application.analyticsDetails
Results.Unauthorized(
views.html.events.unauthorised(event)(currentParticipant,flash)
views.html.events.unauthorised(event)(currentParticipant,flash,Application.analyticsDetails)
).flashing("message"->"Event private, and you do not have access to it")
}

Expand All @@ -172,5 +174,11 @@ trait Secured {
implicit def currentParticipant(implicit session: Session): Option[Participant] = {
Participant.findByUsername(session.get(Security.username).getOrElse(""))
}
}


trait Tracked {
private val analyticsId : Option[String] = Play.application.configuration.getString("analyticsId")
implicit def analyticsDetails : Option[String] = analyticsId
}

14 changes: 7 additions & 7 deletions app/controllers/EventController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import play.Logger
import models._
import notifiers.EmailNotifier

object EventController extends Controller with EventWrappers with Secured {
object EventController extends Controller with EventWrappers with Secured with Tracked {

val searchForm: Form[String] = Form(
"searchText" -> text(maxLength = 100)
Expand All @@ -30,7 +30,7 @@ object EventController extends Controller with EventWrappers with Secured {
)
)

val participantForm = Form(
val addParticipantToEventForm = Form(
"username" -> nonEmptyText(maxLength = 99)
)

Expand Down Expand Up @@ -118,7 +118,7 @@ object EventController extends Controller with EventWrappers with Secured {
val albums = Album.findAlbums(eventId)
val participants = event.findParticipants
val requests = event.findRequests
Ok(views.html.events.edit(event,albums,participants,requests,editForm))
Ok(views.html.events.edit(event,albums,participants,requests,editForm,addParticipantToEventForm))
}


Expand All @@ -129,7 +129,7 @@ object EventController extends Controller with EventWrappers with Secured {
val albums = Album.findAlbums(event.eventId)
val participants = event.findParticipants
val requests = event.findRequests
BadRequest(views.html.events.edit(event,albums,participants,requests,errors))
BadRequest(views.html.events.edit(event,albums,participants,requests,errors,addParticipantToEventForm))
},
updatedForm => {
val updatedEvent = event.copy(
Expand Down Expand Up @@ -179,16 +179,16 @@ object EventController extends Controller with EventWrappers with Secured {
}


def addCurrentParticipant(eventId: Long) = isEventOrganiserOrAdmin(eventId) { (event,participant) => implicit request =>
participantForm.bindFromRequest.fold(
def addParticipant(eventId: Long) = isEventOrganiserOrAdmin(eventId) { (event,participant) => implicit request =>
addParticipantToEventForm.bindFromRequest.fold(
errors => {
for(error<-errors.errors){
Logger.warn("Bad add participant request:"+error.key + " " + error.message)
}
val albums = Album.findAlbums(event.eventId)
val participants = event.findParticipants
val requests = event.findRequests
BadRequest(views.html.events.edit(event,albums,participants,requests,updateForm)).flashing("errorMessage" -> "Invalid participant");
BadRequest(views.html.events.edit(event,albums,participants,requests,updateForm,errors)).flashing("errorMessage" -> "Invalid participant");
},
addParticipantForm => addAnyParticipant(event,Participant.findByUsername(addParticipantForm))
)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/ParticipantController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import play.Logger
import models._
import notifiers.EmailNotifier

object ParticipantController extends Controller with Secured {
object ParticipantController extends Controller with Secured with Tracked {

val resetForm = Form(
"username" -> nonEmptyText(maxLength = 99)
Expand Down
2 changes: 1 addition & 1 deletion app/views/albums/add.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(event: Event, albumForm: Form[(Option[String],String)])(implicit currentParticipant: Option[Participant])
@(event: Event, albumForm: Form[(Option[String],String)])(implicit currentParticipant: Option[Participant], analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand Down
12 changes: 12 additions & 0 deletions app/views/analytics.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@(implicit analyticsDetails: Option[String])
@analyticsDetails.map { analyticsId => <script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '@analyticsId']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script> }
2 changes: 1 addition & 1 deletion app/views/errors/notfound.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(requestPath: String)
@(requestPath: String)(implicit analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand Down
2 changes: 1 addition & 1 deletion app/views/errors/servererror.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(exception: Throwable)
@(exception: Throwable)(implicit analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/delete.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(event: Event)(implicit currentParticipant: Option[Participant])
@(event: Event)(implicit currentParticipant: Option[Participant], analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand Down
13 changes: 10 additions & 3 deletions app/views/events/edit.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(event: Event, albums: Seq[Album], participants: Seq[Participant], requesters: Seq[Participant], updateForm: Form[(String,String,String,String,Boolean,Boolean) ])(implicit currentParticipant: Option[Participant], flash: Flash)
@(event: Event, albums: Seq[Album], participants: Seq[Participant], requesters: Seq[Participant], updateForm: Form[(String,String,String,String,Boolean,Boolean) ], addParticipantForm: Form[String] )(implicit currentParticipant: Option[Participant], flash: Flash, analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand All @@ -18,6 +18,13 @@
</p>
}


@for(error <- addParticipantForm.errors){
<p class="alert alert-error">
Oh dear: @error.message: @error.key
</p>
}

@flash.get("message").map { message =>
<p class="alert alert-info">
@message
Expand Down Expand Up @@ -158,7 +165,7 @@ <h3>Join requests</h3>
<td>@participant.username</td>
<td>
@form(action = routes.EventController.addRequestedParticipant(event.eventId,participant.participantId), 'class -> "form-horizontal"){
<button type="submit" class="btn btn-primary btn-mini">Add participant</button>
<button type="submit" class="btn btn-success btn-mini">Add participant</button>
}
</td>
</tr>
Expand All @@ -167,7 +174,7 @@ <h3>Join requests</h3>
</table>
}

@form(action = routes.EventController.addCurrentParticipant(event.eventId), 'class -> "well form-horizontal"){
@form(action = routes.EventController.addParticipant(event.eventId), 'class -> "well form-horizontal"){
<input type="text" name="username" class="span3" placeholder="Username of participant" value=""/>
<button type="submit" class="btn btn-success btn-small">Add participant</button>
}
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/joinrequest.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(event: Event)(implicit currentParticipant: Option[Participant], flash: Flash)
@(event: Event)(implicit currentParticipant: Option[Participant], flash: Flash, analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/list.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(searchText: String,organiserEvents: Seq[Event],events: Seq[Event],participants: Seq[Participant])(implicit currentParticipant: Option[Participant])
@(searchText: String,organiserEvents: Seq[Event],events: Seq[Event],participants: Seq[Participant])(implicit currentParticipant: Option[Participant], analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/unauthorised.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(event: Event)(implicit currentParticipant: Option[Participant], flash: Flash)
@(event: Event)(implicit currentParticipant: Option[Participant], flash: Flash, analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/view.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(event: Event,albums: Seq[Album],participants: Seq[Participant])(implicit currentParticipant: Option[Participant], flash: Flash)
@(event: Event,albums: Seq[Album],participants: Seq[Participant])(implicit currentParticipant: Option[Participant], flash: Flash, analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand Down
2 changes: 1 addition & 1 deletion app/views/index.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(searchForm: Form[String],createForm: Form[String], registerForm: Form[(String,Option[String],String,String,String)])(implicit currentParticipant: Option[Participant], flash: Flash)
@(searchForm: Form[String],createForm: Form[String], registerForm: Form[(String,Option[String],String,String,String)])(implicit currentParticipant: Option[Participant], flash: Flash, analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand Down
2 changes: 1 addition & 1 deletion app/views/login.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(loginForm: Form[(String,String)])(implicit currentParticipant: Option[Participant], flash: Flash)
@(loginForm: Form[(String,String)])(implicit currentParticipant: Option[Participant], flash: Flash, analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand Down
9 changes: 3 additions & 6 deletions app/views/main.scala.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@(title: String)(breadcrumb: Html)(content: Html)(implicit currentParticipant: Option[Participant]=None)

@(title: String)(breadcrumb: Html)(content: Html)(implicit currentParticipant: Option[Participant]=None, analyticsDetails: Option[String])
<!DOCTYPE html>

<html lang="en">
Expand All @@ -12,9 +11,7 @@
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/cargo.css")">
<script src="@routes.Assets.at("javascripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="@routes.Assets.at("javascripts/bootstrap.min.js")" type="text/javascript"></script>
<script src="@routes.Assets.at("javascripts/underscore-min.js")" type="text/javascript"></script>
<script src="@routes.Assets.at("javascripts/json2.js")" type="text/javascript"></script>
<script src="@routes.Assets.at("javascripts/backbone-min.js")" type="text/javascript"></script>
@analytics(analyticsDetails)
</head>
<body>
<div id="ocean" class="structure">
Expand All @@ -25,7 +22,7 @@
<div id="vaka" class="structure">
<div id="bow" class="structure">
<a href="http://github.com/flurdy/snaps" target="_blank"><img id="fork-me" alt="Fork me on github"
title="Fork me on github" src="@routes.Assets.at("images/ForkMe_Blk.png")" /></a>
title="Fork me on github" src="@routes.Assets.at("images/ForkMe_Blk.png")" /></a>
<header class="topbar">
<h1 class="fill">
Snaps
Expand Down
2 changes: 1 addition & 1 deletion app/views/participant/deleteparticipant.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(participant: Participant)(implicit currentParticipant: Option[Participant])
@(participant: Participant)(implicit currentParticipant: Option[Participant], analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand Down
2 changes: 1 addition & 1 deletion app/views/participant/resetpassword.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@()(implicit flash: Flash)
@()(implicit flash: Flash, analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand Down
2 changes: 1 addition & 1 deletion app/views/participant/viewparticipant.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(participant: Participant,events: Seq[Event],updateParticipantForm: Form[(String,Option[String],String)],passwordForm: Form[(String,String,String)])(implicit currentParticipant: Option[Participant], flash: Flash)
@(participant: Participant,events: Seq[Event],updateParticipantForm: Form[(String,Option[String],String)],passwordForm: Form[(String,String,String)])(implicit currentParticipant: Option[Participant], flash: Flash, analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand Down
2 changes: 1 addition & 1 deletion app/views/register.scala.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@(registerForm: Form[(String,Option[String],String,String,String)])(implicit currentParticipant: Option[Participant], flash: Flash)
@(registerForm: Form[(String,Option[String],String,String,String)])(implicit currentParticipant: Option[Participant], flash: Flash, analyticsDetails: Option[String])

@import helper._
@import helper.twitterBootstrap._
Expand Down
2 changes: 1 addition & 1 deletion conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PUT /events/:eventId/album/:albumId/ controllers.AlbumController.u
POST /events/:eventId/album/:albumId/delete controllers.AlbumController.removeAlbum(eventId: Long, albumId: Long)
DELETE /events/:eventId/album/:albumId/ controllers.AlbumController.removeAlbum(eventId: Long, albumId: Long)

POST /events/:eventId/participant/ controllers.EventController.addCurrentParticipant(eventId: Long)
POST /events/:eventId/participant/ controllers.EventController.addParticipant(eventId: Long)
POST /events/:eventId/participant/:participantId controllers.EventController.addRequestedParticipant(eventId: Long, participantId: Long)
POST /events/:eventId/participant/:participantId/delete controllers.EventController.removeParticipant(eventId: Long, participantId: Long)
DELETE /events/:eventId/participant/:participantId/ controllers.EventController.removeParticipant(eventId: Long, participantId: Long)
Expand Down
4 changes: 2 additions & 2 deletions test/EmailSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import play.Logger

class EmailSpec extends Specification {

val testUser = Participant(0,"tester",Some("Test User"), Some("test@example.com"), Some("testpassword"))
val testUser = Participant(0,"tester",Some("Test User"), "test@example.com", Some("testpassword"))

"Notifications" should {
"be send on registration" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
EmailNotifier.registrationNotification(testUser)
EmailNotifier.registrationAlert(testUser)
1 must beGreaterThan(0)
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/EventSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.specs2.specification.BeforeExample

class EventSpec extends Specification {

val testUser = Participant(0,"tester",Some("Test User"), Some("test@example.com"), Some("testpassword"))
val testUser = Participant(0,"tester",Some("Test User"), "test@example.com", Some("testpassword"))

"An Event" should {

Expand Down Expand Up @@ -102,7 +102,7 @@ class EventSpec extends Specification {

class AlbumSpec extends Specification {

val testUser = Participant(0,"tester",Some("Test User"), Some("test@example.com"), Some("testpassword"))
val testUser = Participant(0,"tester",Some("Test User"), "test@example.com", Some("testpassword"))


"An Album" should {
Expand Down
Loading

0 comments on commit d8ec199

Please sign in to comment.