Skip to content

Latest commit

 

History

History
102 lines (72 loc) · 2.4 KB

README.md

File metadata and controls

102 lines (72 loc) · 2.4 KB

ticketing-system

Ticketing System

Online version on Heroku

web app is running @ http://ticksys.herokuapp.com

Offline version

Added H2 (in memory SQL database)

You can run the project on your local machine.

To run the project

In the project root directory run

    sbt run

now open

    http://localhost:9000/

if sbt is not installed download it from http://www.scala-sbt.org/download.html

Screen Shots of Ticketing system

Login

UI

Home

UI

New Ticket

UI

Comments

UI

Notifications

UI

Interesting code snippets

The code that powers notifications

Notifications Action

    def notifications() = withFUser {user => implicit request => {
        implicit val timeout = Timeout(5 seconds)
        val f = (Global.nhandler ? NHandler.Stream).mapTo[Enumerator[JsValue]]
        f.map(en => {
          Ok.chunked(en &> NHandler.filter(user.id.get) &> EventSource()).as(EVENT_STREAM)
        }).recover{case throwable: Throwable => BadRequest}
      }}

Notifications Actor

    package actors

    import akka.actor.{ActorLogging, Actor}
    import play.api.libs.iteratee.{Enumeratee, Concurrent}
    import play.api.libs.json.{Json, JsValue}

    import play.api.libs.concurrent.Execution.Implicits.defaultContext
    /**
     * Created by pnagarjuna on 24/05/15.
     */
    object NHandler {
      case class Message(to: Long, msg: String)
      case object Stream
      case object Stop
      def filter(userId: Long) = Enumeratee.filter[JsValue]{  json: JsValue =>
        userId == (json\ "to").as[Long]
      }
    }

    class NHandler extends Actor with ActorLogging {
      import NHandler._
      val (en, out) = Concurrent.broadcast[JsValue]
      override def receive = {
        case Message(to, msg) =>
          log.info("{}", Message(to, msg))
          out.push(Json.obj("to" -> to, "msg" -> msg))
        case Stream => sender ! en
        case Stop =>
          out end()
          context stop self
      }
    }