Api Explorer: Better drop down logic and logged in status

This commit is contained in:
Simon Redfern 2015-10-06 02:10:43 +02:00
parent 553fc55a5a
commit 3fcf18e7dd
3 changed files with 25 additions and 10 deletions

View File

@ -185,17 +185,17 @@ class ApiExplorer extends Loggable {
def onBankChange (v: Any) = {
logger.info("bank changed to " + v.toString)
S.redirectTo(s"api-explorer?bank_id=${v}&account_id=${presetAccountId}&view_id=${presetViewId}&counterparty_id=${presetCounterpartyId}")
S.redirectTo(s"api-explorer?bank_id=${v}")
}
def onAccountChange (v: Any) = {
logger.info("account changed to " + v.toString)
S.redirectTo(s"api-explorer?bank_id=${presetBankId}&account_id=${v}&view_id=${presetViewId}&counterparty_id=${presetCounterpartyId}")
S.redirectTo(s"api-explorer?bank_id=${presetBankId}&account_id=${v}")
}
def onViewChange (v: Any) = {
logger.info("view changed to " + v.toString)
S.redirectTo(s"api-explorer?bank_id=${presetBankId}&account_id=${presetAccountId}&view_id=${v}&counterparty_id=${presetCounterpartyId}")
S.redirectTo(s"api-explorer?bank_id=${presetBankId}&account_id=${presetAccountId}&view_id=${v}")
}
def onCounterpartyChange (v: Any) = {
@ -203,7 +203,6 @@ class ApiExplorer extends Loggable {
S.redirectTo(s"api-explorer?bank_id=${presetBankId}&account_id=${presetAccountId}&view_id=${presetViewId}&counterparty_id=${v}")
}
// Get a list of tuples List(("bank short name", "id"),("bank two", "id2")) to populate the drop down select list.
// Could we write this in a way such that if there are no banks the doBankSelect is not run?
val bankOptions = ("", "Select Bank") :: banks.map(b => b.bankJsons.map(bj => (bj.id.getOrElse(""), bj.short_name.getOrElse("")))).getOrElse(List(("", "No Banks")))
@ -239,10 +238,15 @@ class ApiExplorer extends Loggable {
def getViewOptions : List[(String,String)] = {
val selectOne = ("", "Select View")
val selectOne = OAuthClient.loggedIn match {
case true => ("", "Select View")
case false => ("", "Login for Views")
}
val noneFound = ("", "No Views Found")
// TODO Should check for both presetBankId and presetAccountId
// Logged in user required?
val options: List[(String, String)] = presetAccountId match {
case "" => List(noneFound)
case _ => for {
@ -259,7 +263,10 @@ class ApiExplorer extends Loggable {
def getCounterpartyOptions : List[(String,String)] = {
val selectOne = ("", "Select Counterparty")
val selectOne = OAuthClient.loggedIn match {
case true => ("", "Select Counterparty")
case false => ("", "Login for Counterparties")
}
val noneFound = ("", "No Counterparties Found")
// TODO Should check for both presetBankId and presetAccountId
@ -297,11 +304,15 @@ class ApiExplorer extends Loggable {
Full(presetCounterpartyId),
v => onCounterpartyChange(v))
def loggedInStatusMessage = {
if (OAuthClient.loggedIn) "" else "Some options and calls require login."
}
// In case we use Extraction.decompose
implicit val formats = net.liftweb.json.DefaultFormats
"#login_status_message" #> loggedInStatusMessage &
"#bank_selector" #> doBankSelect _ &
"#account_selector" #> doAccountSelect _ &
"#view_selector" #> doViewSelect _ &

View File

@ -41,7 +41,7 @@ import net.liftweb.http.js.JsCmds.Noop
class Login {
// TODO show currenctly loggedin user / name
// TODO show currently logged-in user / name
private def loggedIn = {
".logged-out *" #> "" &
".logout [onclick+]" #> SHtml.onEvent(s => {

View File

@ -10,7 +10,12 @@
<div class="lift:Msgs"></div>
<div>
<div id="selectors">
<div id="login_status_message">
Logged In Status
</div>
<br />
<select id="bank_selector">
<option value="bank_id1">Bank 1</option>
<option value="bank_id2">Bank 2</option>
@ -28,7 +33,6 @@
<option value="other_account_id_1">Counterparty 1</option>
<option value="other_account_id_2">Counterparty 2</option>
</select>
</div>