forked from NashTech-Labs/mycellwasstolen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NashTech-Labs#27 more code re-factoring and added audit controller
- Loading branch information
Sushil
committed
Mar 31, 2015
1 parent
d604c2a
commit 6e5d239
Showing
23 changed files
with
275 additions
and
274 deletions.
There are no files selected for viewing
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
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,77 @@ | ||
package controllers | ||
|
||
import model.repository._ | ||
import net.liftweb.json.DefaultFormats | ||
import net.liftweb.json.JsonAST._ | ||
import net.liftweb.json.JsonDSL._ | ||
import net.liftweb.json.Serialization.write | ||
import play.api.Logger | ||
import play.api._ | ||
import play.api.Play.current | ||
import play.api.data.Form | ||
import play.api.data.Forms.{ mapping, nonEmptyText } | ||
import play.api.mvc._ | ||
import utils._ | ||
import play.api.cache.Cache | ||
import play.twirl.api.Html | ||
import java.util.Calendar | ||
|
||
class AuditController(auditRepo: AuditRepository) extends Controller with Secured { | ||
|
||
/** | ||
* Describe mobile audit form | ||
*/ | ||
val timestampform = Form( | ||
mapping( | ||
"imeiMeid" -> nonEmptyText)(AuditForm.apply)(AuditForm.unapply)) | ||
|
||
/** | ||
* Display audit page | ||
*/ | ||
def auditPage: Action[AnyContent] = withAuth { username => | ||
implicit request => | ||
val user: Option[User] = Cache.getAs[User](username) | ||
val list = List() | ||
Ok(views.html.audit.audit("imeid", list, user)) | ||
} | ||
|
||
/** | ||
* Display timestamp records of particular imei number | ||
*/ | ||
def getTimestampByIMEI: Action[AnyContent] = Action { | ||
implicit request => | ||
Logger.info("AdminController:audit -> called") | ||
val email = request.session.get(Security.username).getOrElse("") | ||
val user: Option[User] = Cache.getAs[User](email) | ||
timestampform.bindFromRequest().fold( | ||
hasErrors = { form => | ||
val list = List() | ||
Ok(views.html.audit.audit("imeid", list, user)).flashing("error" -> "Please correct the errors in the form") | ||
}, | ||
success = { timestamp => | ||
val list = auditRepo.getAllTimestampsByIMEID(timestamp.imeiMeid) | ||
Ok(views.html.audit.audit("imeid", list, user)) | ||
}) | ||
} | ||
|
||
/** | ||
* Display all timestamp records for all mobiles | ||
*/ | ||
def getAllTimestamp: Action[AnyContent] = withAuth { username => | ||
implicit request => | ||
val user: Option[User] = Cache.getAs[User](username) | ||
val list = auditRepo.getAllTimestamps | ||
Ok(views.html.audit.audit("all", list, user)) | ||
} | ||
|
||
def getRegistrationRecordsByYear(year: String): Action[AnyContent] = withAuth { username => | ||
implicit request => | ||
val user: Option[User] = Cache.getAs[User](username) | ||
val years = (2012 to Calendar.getInstance().get(Calendar.YEAR)).toList | ||
val monthList = List("Jan", "Feb", "Mar", "Apr", "May", "Jun", "July", "Aug", "Sep", "Oct", "Nov", "Dec") | ||
val recordList = auditRepo.getRecordByDate(year) | ||
val recordsList = monthList zip recordList | ||
Ok(views.html.audit.analytics(user, recordsList, years)) | ||
} | ||
} | ||
object AuditController extends AuditController(AuditRepository) |
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
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
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
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
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 |
---|---|---|
|
@@ -3,4 +3,4 @@ package utils | |
object Constants { | ||
val ZERO = 0 | ||
val ONE = 1 | ||
} | ||
} |
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
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
Oops, something went wrong.