PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/scala/net/morrdusk/web/controller/DeviceController.scala

http://github.com/joakim666/simple-scheduler
Scala | 34 lines | 28 code | 6 blank | 0 comment | 0 complexity | 29d1df2925d8ed9477b5c76e14a26bad MD5 | raw file
  1. package net.morrdusk.web.controller
  2. import scala.collection.mutable.HashMap
  3. import org.fusesource.scalate.TemplateEngine
  4. import com.mongodb.casbah.commons.MongoDBObject
  5. import org.slf4j.LoggerFactory
  6. import net.morrdusk.model.{Event, EventDao, DeviceModel}
  7. import net.morrdusk.model.json.Device
  8. import net.morrdusk.web.AuthUser
  9. import net.morrdusk.ApiKey
  10. class DeviceController(templateEngine: TemplateEngine, apiKey: ApiKey, user: AuthUser) extends Controller(templateEngine) {
  11. val LOG = LoggerFactory.getLogger(getClass)
  12. def index() {
  13. user.accessToken match {
  14. case Some(accessToken) => {
  15. val devices = DeviceModel.list(apiKey, accessToken)
  16. val deviceEvents = new HashMap[Device, List[Event]]
  17. devices.foreach(d => {
  18. val events = EventDao.find(ref = MongoDBObject("deviceId" -> d.id)).toList
  19. deviceEvents += d -> events
  20. })
  21. render("devices/index.jade", Map("devices" -> devices, "deviceEvents" -> deviceEvents))
  22. }
  23. case None => {
  24. "Access token missing"
  25. }
  26. }
  27. }
  28. }