Skip to content

Commit

Permalink
Merge pull request #56 from constantine2nd/develop
Browse files Browse the repository at this point in the history
Enhancements
  • Loading branch information
simonredfern authored Oct 8, 2021
2 parents 4c82732 + de4b75f commit 5dec8de
Show file tree
Hide file tree
Showing 23 changed files with 785 additions and 70 deletions.
44 changes: 4 additions & 40 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<name>Social Finance</name>
<inceptionYear>2011</inceptionYear>
<properties>
<scala.version>2.11</scala.version>
<scala.compiler>2.11.8</scala.compiler>
<lift.version>2.6.3</lift.version>
<scala.version>2.12</scala.version>
<scala.compiler>2.12.10</scala.compiler>
<lift.version>3.4.1</lift.version>
<jetty.version>9.4.12.v20180830</jetty.version>
<!-- Common plugin settings -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -61,26 +61,6 @@
<artifactId>lift-mapper_${scala.version}</artifactId>
<version>${lift.version}</version>
</dependency>
<dependency>
<groupId>net.liftmodules</groupId>
<artifactId>widgets_2.6_${scala.version}</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.databinder</groupId>
<artifactId>dispatch-http_${scala.version}</artifactId>
<version>0.8.10</version>
</dependency>
<dependency>
<groupId>net.databinder</groupId>
<artifactId>dispatch-oauth_${scala.version}</artifactId>
<version>0.8.10</version>
</dependency>
<dependency>
<groupId>net.databinder.dispatch</groupId>
<artifactId>dispatch-lift-json_${scala.version}</artifactId>
<version>0.11.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand All @@ -96,7 +76,7 @@
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.version}</artifactId>
<version>2.2.6</version>
<version>3.0.8</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -341,20 +321,4 @@
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<charset>${project.build.sourceEncoding}</charset>
<jvmArgs>
<jvmArg>-Xmx1024m</jvmArg>
<jvmArg>-DpackageLinkDefs=file://${project.build.directory}/packageLinkDefs.properties</jvmArg>
</jvmArgs>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
22 changes: 22 additions & 0 deletions src/main/resources/i18n/lift-core.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
login = Login
logout = Logout
sign_in_as = Sign in as
views = Views
private_accounts = Private accounts
public_accounts = Public accounts
my_accounts = My accounts
account_name = Account Name
you_are_logged_out = You are logged out. No authorised accounts available.
enter_label = Enter a label...
create_account_label = Create a bank account
bank_name = Bank name
account_label = Account label
income_description = Description
income_amount = Amount \u20ac
payment_description = Description
payment_amount = Amount \u20ac
income = Income
payment = Expenditure
add_expenditure = Add expenditure
add_income = Add income
button.save = Save
21 changes: 21 additions & 0 deletions src/main/resources/i18n/lift-core_en_GB.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
login = Login
logout = Logout
sign_in_as = Sign in as
views = Views
private_accounts = Private accounts
public_accounts = Public accounts
my_accounts = My accounts
account_name = Account Name
you_are_logged_out = You are logged out. No authorised accounts available.
enter_label = Enter a label...
create_account_label = Create a bank account
bank_name = Bank name
account_label = Account label
income_description = Description
income_amount = Amount \u20ac
payment_description = Description
payment_amount = Amount \u20ac
income = Income
payment = Expenditure
add_expenditure = Add expenditure
button.save = Save
19 changes: 19 additions & 0 deletions src/main/resources/i18n/lift-core_it_IT.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
login = Accedi
logout = Esci
sign_in_as = Accedi come
views = Visualizzazioni
private_accounts = Conti privati
public_accounts = Conti pubblici
my_accounts = I miei account
account_name = Nome utente
you_are_logged_out = Sei disconnesso. Nessun account autorizzato disponibile.
enter_label = Enter a label...
create_account_label = Crea un conto in banca
bank_name = nome della banca
account_label = Etichetta dell'account
income_description = Income description
income_amount = Income amount
payment_description = payment description
payment_amount = payment amount
income = Income
payment = payment
20 changes: 20 additions & 0 deletions src/main/resources/i18n/lift-core_uk_UA.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# The main drawback here is that all application resources for a given locale must exist
# in the same file, and that extended characters such as œ aren’t properly encoded by
# default. This is due to Java properties bundles using ISO 8859-1 encoding and thus
# requiring conversion to escaped format, such as \u0153. Fortunately this process can
# be automated using tools like native2ascii
login = Login
logout = Logout
sign_in_as = Sign in as
views = Views
private_accounts = Private accounts
public_accounts = \u041f\u0443\u0431\u043b\u0456\u0447\u043d\u0456 \u0440\u0430\u0445\u0443\u043d\u043a\u0438
my_accounts = \u041c\u043e\u0457 \u0440\u0430\u0445\u0443\u043d\u043a\u0438
account_name = \u041d\u0430\u0437\u0432\u0430 \u043e\u0431\u043b\u0456\u043a\u043e\u0432\u043e\u0433\u043e \u0437\u0430\u043f\u0438\u0441\u0443
you_are_logged_out = \u0412\u0438 \u0432\u0438\u0439\u0448\u043b\u0438 \u0437 \u0441\u0438\u0441\u0442\u0435\u043c\u0438. \u041d\u0435\u043c\u0430\u0454 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u0438\u0445 \u043e\u0431\u043b\u0456\u043a\u043e\u0432\u0438\u0445 \u0437\u0430\u043f\u0438\u0441\u0456\u0432.
enter_label = \u0412\u0432\u0435\u0434\u0456\u0442\u044c \u043c\u0456\u0442\u043a\u0443 ...
create_account_label = \u0421\u0442\u0432\u043e\u0440\u0456\u0442\u044c \u0431\u0430\u043d\u043a\u0456\u0432\u0441\u044c\u043a\u0438\u0439 \u0440\u0430\u0445\u0443\u043d\u043e\u043a
bank_name = \u043d\u0430\u0437\u0432\u0430 \u0431\u0430\u043d\u043a\u0443
account_label = \u041c\u0456\u0442\u043a\u0430 \u043e\u0431\u043b\u0456\u043a\u043e\u0432\u043e\u0433\u043e \u0437\u0430\u043f\u0438\u0441\u0443
income_description = Income description
income = Income
13 changes: 12 additions & 1 deletion src/main/resources/props/sample.props.template
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,15 @@ sytems_views_to_display=owner,accountant,auditor
hide_public_accounts_panel=false

# Show/Hide Twitter link at the footer.
display_twitter_link=true
display_twitter_link=true

# Set Locale
language_tag = en-GB

# Incoming account
incoming.bank_id=FILL_ME_IN
incoming.account_id=FILL_ME_IN

# Outgoing account
outgoing.bank_id=FILL_ME_IN
outgoing.account_id=FILL_ME_IN
66 changes: 60 additions & 6 deletions src/main/scala/bootstrap/liftweb/Boot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ Berlin 13359, Germany
package bootstrap.liftweb

import java.io.{File, FileInputStream}
import java.util.Locale

import code.Constant._
import code.lib.ObpJson._
import code.lib.{OAuthClient, ObpAPI, ObpGet, ObpJson}
import code.lib.{OAuthClient, ObpAPI, ObpGet}
import code.snippet._
import code.util.Helper.MdcLoggable
import code.util.{Helper, MyExceptionLogger}
import net.liftmodules.widgets.tablesorter.TableSorter
import net.liftweb._
import net.liftweb.common._
import net.liftweb.http._
import net.liftweb.http.provider.HTTPCookie
import net.liftweb.sitemap.Loc._
import net.liftweb.sitemap._
import net.liftweb.util.Helpers._
Expand Down Expand Up @@ -162,7 +162,7 @@ class Boot extends MdcLoggable{

for {
//TODO: Pagination: This is not totally trivial, since the transaction list groups by date and 2 pages may have some transactions on the same date
transactionsJson <- ObpAPI.transactions(bankId, accountId, viewId, Some(10000), Some(0), None, None, None)
transactionsJson <- ObpAPI.transactions(bankId, accountId, viewId, Some(10000), Some(0), None, Some(now), None)
accountJson <- ObpAPI.getAccount(bankId, accountId, viewId) //TODO: Execute this request and the one above in parallel
} yield {
(transactionsJson, accountJson, transactionsURLParams)
Expand Down Expand Up @@ -265,6 +265,18 @@ class Boot extends MdcLoggable{
case _ => None
}
}

def getBanks(URLParameters : List[String]): Box[List[BankJson400]] = {
if (URLParameters.length == 2) {
val bank = URLParameters(0)
}
val result =
for {
json <- ObpGet(s"/$versionOfApi/banks").flatMap(_.extractOpt[BanksJson400])
} yield (json.banks)

result
}

//getTransaction can be called twice by lift, so it's best to memoize the result of the potentially expensive calculation
object transactionMemo extends RequestVar[Box[Box[(code.lib.ObpJson.TransactionJson, code.lib.ObpJson.AccountJson, code.snippet.CommentsURLParams)]]](Empty)
Expand Down Expand Up @@ -400,6 +412,11 @@ class Boot extends MdcLoggable{
Menu.params[(OtherAccountsJson, ManagementURLParams)]("Management", "management", getAccount _ , t => List("")) / "banks" / * / "accounts" / * / "management",

Menu.params[List[String]]("AccountSettings", "Account settings", getAccountSettings _, x => List("")) / "banks" / * / "accounts" / * / "settings",

Menu.params[List[BankJson400]]("CreateBankAccount", "Create bank account", getBanks _, x => List("")) / "banks" / * / "accounts" / "create-bank-account",

Menu.params[List[String]]("CreateIncome", "Create Income", getAccountSettings _, x => List("")) / "banks" / * / "accounts" / * / "create-income",
Menu.params[List[String]]("CreateExpenditure", "Create Expenditure", getAccountSettings _, x => List("")) / "banks" / * / "accounts" / * / "create-expenditure",

Menu.params[ViewsDataJSON]("Views","Views Overview", getCompleteAccountViews _ , x => List("")) / "banks" / * / "accounts" / * / "views" / "list",

Expand Down Expand Up @@ -449,14 +466,51 @@ class Boot extends MdcLoggable{
// Force the request to be UTF-8
LiftRules.early.append(_.setCharacterEncoding("UTF-8"))

//set base localization according to a props value (instead of computer default)
val locale = Locale.getAvailableLocales().toList.filter { l =>
l.toLanguageTag == Props.get("language_tag", "en-GB")
}.head
Locale.setDefault(locale)
logger.info("Default Project Locale is :" + locale)

// Properly convert a language tag to a Locale
def computeLocale(tag : String) = tag.split(Array('-', '_')) match {
case Array(lang) => new Locale(lang)
case Array(lang, country) => new Locale(lang, country)
case Array(lang, country, variant) => new Locale(lang, country, variant)
}
// Cookie name
val localeCookieName = "SELECTED_LOCALE"
LiftRules.localeCalculator = {
case fullReq @ Full(req) => {
// Check against a set cookie, or the locale sent in the request
def currentLocale : Locale = {
S.findCookie(localeCookieName).flatMap {
cookie => cookie.value.map(computeLocale)
} openOr locale
}

// Check to see if the user explicitly requests a new locale
S.param("locale") match {
case Full(requestedLocale) if requestedLocale != null => {
val computedLocale = computeLocale(requestedLocale)
S.addCookie(HTTPCookie(localeCookieName, requestedLocale))
computedLocale
}
case _ => currentLocale
}
}
case _ => locale
}

// LiftRules.resourceNames = "i18n.lift-core" :: Nil

// Use HTML5 for rendering
LiftRules.htmlProperties.default.set((r: Req) =>
new Html5Properties(r.userAgent))

LiftRules.explicitlyParsedSuffixes = Helpers.knownSuffixes &~ (Set("com"))

TableSorter.init

LiftRules.exceptionHandler.prepend{
case MyExceptionLogger(_, _, t) => throw t // this will never happen
}
Expand Down
Loading

0 comments on commit 5dec8de

Please sign in to comment.