From 8534d36ec698790278f9967b515aa20fe4654380 Mon Sep 17 00:00:00 2001 From: Guntis Smaukstelis Date: Mon, 1 Jan 2024 20:25:39 +0200 Subject: [PATCH] Add postgres host to .env, filter out sum values for country --- src/main/scala/db/DBConnection.scala | 3 ++- web/src/App.tsx | 2 -- web/src/country/result/Result.tsx | 12 ++++++++++++ web/src/css/index.css | 12 ++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/scala/db/DBConnection.scala b/src/main/scala/db/DBConnection.scala index 922acbf..eeee9ff 100644 --- a/src/main/scala/db/DBConnection.scala +++ b/src/main/scala/db/DBConnection.scala @@ -12,9 +12,10 @@ object DBConnection { private def getDbName = sys.env.getOrElse("POSTGRES_DB", "") private def getDbUser = sys.env.getOrElse("POSTGRES_USER", "") private def getDbPassword = sys.env.getOrElse("POSTGRES_PASSWORD", "") + private def getDbHost = sys.env.getOrElse("POSTGRES_HOST", "") private def getDatabaseUrl: String = - sys.env.getOrElse("DATABASE_URL", s"postgres://${getDbUser}:${getDbPassword}@postgres:5432/${getDbName}") // host - postgres for docker, 0.0.0.0 outside docker + sys.env.getOrElse("DATABASE_URL", s"postgres://${getDbUser}:${getDbPassword}@${getDbHost}:5432/${getDbName}") // host - postgres for docker, 0.0.0.0 outside docker private def parseUrl(url: String): Either[String, PostgresConfig] = { Try { diff --git a/web/src/App.tsx b/web/src/App.tsx index 1580c3c..8d202fd 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -10,8 +10,6 @@ import { apiHost } from './consts'; console.log("env:", import.meta.env.MODE); console.log("api host:", apiHost); -// type Section = "station" | "cities" | "country" | "database"; - const App: Component = () => { const pages: [string, () => JSXElement][] = [ ["station", () => ], diff --git a/web/src/country/result/Result.tsx b/web/src/country/result/Result.tsx index dccbbb5..296a3ee 100644 --- a/web/src/country/result/Result.tsx +++ b/web/src/country/result/Result.tsx @@ -9,6 +9,7 @@ export const Result: Component<{ }> = ({ result: resultResource }) => { const countryData = () => Object.entries(resultResource()!) .sort((a, b) => a[0] > b[0] ? 1 : -1) + .map(filterOutSums) .map(([field, values]) => {field} {values[0]} @@ -31,4 +32,15 @@ export const Result: Component<{ ); +} + +type CountryFieldValues = [number | undefined, number | undefined, number | undefined, number | undefined]; + +const sumFields = ["precipitation", "snowAvg", "sunDuration"]; + +function filterOutSums([field, values]: [string, CountryFieldValues]): [string, CountryFieldValues] { + const modifiedValues: CountryFieldValues = [...values]; + if (!sumFields.includes(field)) modifiedValues[3] = undefined; + + return [field, modifiedValues]; } \ No newline at end of file diff --git a/web/src/css/index.css b/web/src/css/index.css index 996329a..6700903 100644 --- a/web/src/css/index.css +++ b/web/src/css/index.css @@ -41,4 +41,16 @@ thead { .primary:hover { background-color: #ffb92d; +} + +table td { + padding: 3px 7px; +} + +table tr:nth-child(odd) { + background: #d6d6d6; +} + +table tr:hover { + background: #c0c0c0; } \ No newline at end of file