Skip to content

Commit

Permalink
Added scalajs-google-charts example in PatientGantt
Browse files Browse the repository at this point in the history
  • Loading branch information
aleastChs committed Aug 11, 2017
1 parent 277326e commit 875ab74
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 8 deletions.
4 changes: 4 additions & 0 deletions gui/src/main/scala/spgui/widgets/charts/GanttCSS.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ object GanttCSS extends StyleSheet.Inline {
cursor.pointer
)

val background = style(
backgroundColor(rgb(0,180,50))
)

this.addToDocument()
}

84 changes: 80 additions & 4 deletions gui/src/main/scala/spgui/widgets/charts/PatientGanttWidget.scala
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package spgui.widgets.charts

import japgolly.scalajs.react.vdom.html_<^._
import japgolly.scalajs.react._
import sp.domain.SPValue
import japgolly.scalajs.react.vdom.html_<^._
import japgolly.scalajs.react.vdom.all.svg

import scalacss.ScalaCssReact._
import sp.domain.SPValue
import sp.messages.Pickles.SPHeader
import spgui.communication._
import spgui.widgets.{API_Patient => apiPatient, API_PatientEvent => api}
import spgui.widgets.ToAndFrom
import spgui.widgets.css.{WidgetStyles => Styles}
import aleastchs.googleCharts.helpers.chartsHelp.{GoogleChartsLoaded, TimelineHelper, TimelineRow, TimelineOption}
import aleastchs.googleCharts.google

import scala.scalajs.js

object PatientGanttWidget {

val id = "patientGanttWidget"

private class Backend($: BackendScope[String, Map[String, apiPatient.Patient]]) {

var patientObs = Option.empty[rx.Obs]
Expand All @@ -33,6 +40,76 @@ object PatientGanttWidget {

def render(p: String, s: Map[String, apiPatient.Patient]) = {
<.div(Styles.helveticaZ)
(
<.div(
^.className := GanttCSS.background.htmlClass,
^.id := id,
<.div(^.id := id+"scheme")
)
)
}

/*********EXAMPLE USE OF GOOGLE API WITH Helper-class*************/
val rowList: List[TimelineRow] =
TimelineRow("Besök", "Patientens Besök På Sjukhuset",
new js.Date(2017, 5, 20, 8, 5, 3, 2), new js.Date(2017, 5, 20, 10, 32, 23, 9)) ::
TimelineRow("Kölapp", "Tar Kölapp",
new js.Date(2017, 5, 20, 8, 6, 13, 8), new js.Date(2017, 5, 20, 8, 6, 31, 7)) ::
TimelineRow("Väntetid", "Patient Väntar På inskrivning",
new js.Date(2017, 5, 20, 8, 6, 31, 7), new js.Date(2017, 5, 20, 8, 23, 54, 1)) ::
TimelineRow("Inskrivning", "Patient Skriver in sig",
new js.Date(2017, 5, 20, 8, 24, 11, 2), new js.Date(2017, 5, 20, 8, 26, 46, 3)) ::
TimelineRow("Väntetid", "Patienten väntar på läkare",
new js.Date(2017, 5, 20, 8, 26, 46, 3), new js.Date(2017, 5, 20, 9, 1, 35, 4)) ::
TimelineRow("Läkarbesök", "Patient träffar läkare",
new js.Date(2017, 5, 20, 9, 1, 35, 4), new js.Date(2017, 5, 20, 9, 9, 21, 5)) ::
TimelineRow("Väntetid", "Patient väntar på diagnos",
new js.Date(2017, 5, 20, 9, 9, 21, 5), new js.Date(2017, 5, 20, 9, 59, 1, 0)) ::
TimelineRow("Diagnostiering", "Läkare sätter diagnos",
new js.Date(2017, 5, 20, 9, 9, 21, 5), new js.Date(2017, 5, 20, 9, 27, 54, 9)) ::
TimelineRow("Läkarbesök", "Patient träffar läkare",
new js.Date(2017, 5, 20, 9, 59, 1, 0), new js.Date(2017, 5, 20, 10, 14, 13, 4)) ::
Nil

def onMount() = {
println("Hej Google Charts Mount")
println(GoogleChartsLoaded)
if(GoogleChartsLoaded.asInstanceOf[Boolean]) {
val timelineElement = js.Dynamic.global.document.getElementById(id+"scheme")
val timelineHelper = TimelineHelper(timelineElement, "Gantt För Patienter")


rowList.foreach(row => timelineHelper.newRow(row))

timelineHelper.draw()
//onUpdate(rowList, timelineHelper)
}
Callback.empty
}


/** When EricaPatients from Google Pub/Sub is updated,
* clear gantt scheme.
*
* Then add the rows to the helper with new updated data.
*
* Draw the new rows
*
* @note Precondition: The timelineHelper must have a div-element where to be printed
*
* @param rows A List of TimelineRow
* @param helperToUse A TimelineHelper from scalajs-google-charts library
*
* @return the new TimelineHelper that just drawn the updated gantt scheme
*/
def onUpdate(rows: List[TimelineRow], helperToUse: TimelineHelper): TimelineHelper = {
helperToUse.clear()

rows.foreach(row => helperToUse.newRow(row))

helperToUse.draw()

helperToUse
}

def onUnmount() = {
Expand All @@ -59,8 +136,7 @@ object PatientGanttWidget {
apiPatient.Finished(false, false, "2017-02-01T10:01:38Z")
)))
.renderBackend[Backend]
// .componentDidMount(_.backend.getWidgetWidth())
.componentDidMount(ctx => Callback(ctx.backend.setPatientObs()))
.componentDidMount(_.backend.onMount())
.componentWillUnmount(_.backend.onUnmount())
.build

Expand Down
4 changes: 2 additions & 2 deletions spcore/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
</appender>

<appender name="file-appender" class="ch.qos.logback.core.FileAppender">
<file>../logs/erica.log</file>
<file>../logs/erica2.log</file>
<!-- <append>false</append> Append to existing log file or create new each restart. -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>../logs/erica.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>../logs/erica2.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 50MB -->
Expand Down
3 changes: 2 additions & 1 deletion spservices/gPubSubService/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ libraryDependencies ++= {
"com.typesafe.akka" %% "akka-http" % "10.0.9",
"com.typesafe.akka" %% "akka-http-testkit" % "10.0.9",
"com.github.romix.akka" %% "akka-kryo-serialization" % "0.4.2",
"com.google.cloud" % "google-cloud" % "0.21.1-alpha"
"com.google.cloud" % "google-cloud" % "0.21.1-alpha",
"io.netty" % "netty-all" % "4.1.14.Final"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ class ElvisPubSuber(project: String, topic: String, subscription: String, sendTo


log.info("Connecting to Google pubsub. Subscription: " + subscription + " Topic: " + topic)
deleteSubscription(subscription)
println("Connecting to Google pubsub. Subscription: " + subscription + " Topic: " + topic)
val x = deleteSubscription(subscription)
println("delete:")
println(x)

val subTry = createSubscription(topic, subscription)
log.debug("Subscription attempt resulted in: " + subTry)
val res = subTry.map{s =>
Expand Down

0 comments on commit 875ab74

Please sign in to comment.