Changed appdata behaviour
This commit is contained in:
parent
601fad6433
commit
7b01a60d82
@ -1,10 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
|
<?import com.jfoenix.controls.JFXListView ?>
|
||||||
<?import java.net.URL ?>
|
<?import java.net.URL ?>
|
||||||
<?import javafx.geometry.Insets ?>
|
<?import javafx.geometry.Insets ?>
|
||||||
<?import javafx.scene.control.Button ?>
|
<?import javafx.scene.control.Button ?>
|
||||||
<?import javafx.scene.control.Label ?>
|
<?import javafx.scene.control.Label ?>
|
||||||
<?import javafx.scene.control.ListView ?>
|
|
||||||
<?import javafx.scene.control.TextArea ?>
|
<?import javafx.scene.control.TextArea ?>
|
||||||
<?import javafx.scene.layout.BorderPane ?>
|
<?import javafx.scene.layout.BorderPane ?>
|
||||||
<?import javafx.scene.layout.FlowPane ?>
|
<?import javafx.scene.layout.FlowPane ?>
|
||||||
@ -18,28 +18,14 @@
|
|||||||
<left>
|
<left>
|
||||||
<VBox fx:id="usersVBox" alignment="TOP_CENTER" prefHeight="200.0" prefWidth="175.0" BorderPane.alignment="CENTER">
|
<VBox fx:id="usersVBox" alignment="TOP_CENTER" prefHeight="200.0" prefWidth="175.0" BorderPane.alignment="CENTER">
|
||||||
<children>
|
<children>
|
||||||
<Button mnemonicParsing="false" styleClass="userButton" text="User1" VBox.vgrow="ALWAYS">
|
<JFXListView fx:id="usersListView" prefHeight="554.0" prefWidth="175.0" styleClass="my-list-view" />
|
||||||
<VBox.margin>
|
|
||||||
<Insets />
|
|
||||||
</VBox.margin>
|
|
||||||
</Button>
|
|
||||||
<Button mnemonicParsing="false" styleClass="userButton" text="User2">
|
|
||||||
<VBox.margin>
|
|
||||||
<Insets />
|
|
||||||
</VBox.margin>
|
|
||||||
</Button>
|
|
||||||
</children>
|
</children>
|
||||||
</VBox>
|
</VBox>
|
||||||
</left>
|
</left>
|
||||||
<center>
|
<center>
|
||||||
<VBox prefHeight="200.0" prefWidth="100.0" spacing="5.0" BorderPane.alignment="CENTER">
|
<VBox prefHeight="200.0" prefWidth="100.0" spacing="5.0" BorderPane.alignment="CENTER">
|
||||||
<children>
|
<children>
|
||||||
<ListView fx:id="chatListView" prefHeight="792.0" prefWidth="610.0" />
|
<JFXListView fx:id="chatListView" prefHeight="463.0" prefWidth="610.0" />
|
||||||
<TextArea id="chatTextArea" fx:id="chatTextArea" editable="false" prefHeight="474.0" prefWidth="690.0" styleClass="lead" visible="false" VBox.vgrow="ALWAYS">
|
|
||||||
<VBox.margin>
|
|
||||||
<Insets />
|
|
||||||
</VBox.margin>
|
|
||||||
</TextArea>
|
|
||||||
<HBox prefHeight="50.0" prefWidth="790.0" spacing="2.0">
|
<HBox prefHeight="50.0" prefWidth="790.0" spacing="2.0">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="label" contentDisplay="CENTER" maxWidth="100.0" prefHeight="30.0" prefWidth="52.0" text="Label" />
|
<Label fx:id="label" contentDisplay="CENTER" maxWidth="100.0" prefHeight="30.0" prefWidth="52.0" text="Label" />
|
||||||
@ -61,7 +47,7 @@
|
|||||||
</VBox>
|
</VBox>
|
||||||
</center>
|
</center>
|
||||||
<stylesheets>
|
<stylesheets>
|
||||||
<URL value="@../styles/ui.css" />
|
<!-- <URL value="@../styles/ui.css" />
|
||||||
<URL value="@../styles/bootstrapfx.css" />
|
<URL value="@../styles/bootstrapfx.css" /> -->
|
||||||
</stylesheets>
|
</stylesheets>
|
||||||
</BorderPane>
|
</BorderPane>
|
@ -43,10 +43,10 @@
|
|||||||
<Font size="14.0" />
|
<Font size="14.0" />
|
||||||
</font>
|
</font>
|
||||||
</Label>
|
</Label>
|
||||||
<JFXTextField fx:id="usernameTextField" focusColor="#d30699" labelFloat="true" minWidth="196.0" prefHeight="31.0" prefWidth="215.0" promptText="Username" />
|
<JFXTextField fx:id="usernameTextField" focusColor="#d30699" labelFloat="true" minWidth="196.0" prefHeight="31.0" prefWidth="215.0" id="username" promptText="Username" />
|
||||||
<JFXPasswordField fx:id="passwordTextField" focusColor="#fb06d2" labelFloat="true" minWidth="196.0" prefHeight="31.0" prefWidth="215.0" promptText="Password" />
|
<JFXPasswordField fx:id="passwordTextField" focusColor="#fb06d2" labelFloat="true" minWidth="196.0" prefHeight="31.0" prefWidth="215.0" id="password" promptText="Password" />
|
||||||
<!-- <JFXButton fx:id="submitButton" buttonType="RAISED" prefHeight="37.0" prefWidth="110.0" ripplerFill="WHITE" style="-fx-background-color: #fb06d2; -fx-background-radius: 50px;" text="Get started" textFill="WHITE" /> -->
|
<!-- <JFXButton fx:id="submitButton" buttonType="RAISED" prefHeight="37.0" prefWidth="110.0" ripplerFill="WHITE" style="-fx-background-color: #fb06d2; -fx-background-radius: 50px;" text="Get started" textFill="WHITE" /> -->
|
||||||
<JFXButton fx:id="submitButton" styleClass="btn, btn-primary" text="Submit" />
|
<JFXButton fx:id="submitButton" styleClass="btn, btn-primary" text="Submit" onAction="#actionLogin" />
|
||||||
|
|
||||||
<!-- style="-fx-background-radius: 50px;-fx-background-color: #fb06d2" -->
|
<!-- style="-fx-background-radius: 50px;-fx-background-color: #fb06d2" -->
|
||||||
|
|
||||||
@ -70,7 +70,7 @@
|
|||||||
</VBox>
|
</VBox>
|
||||||
</children>
|
</children>
|
||||||
<stylesheets>
|
<stylesheets>
|
||||||
<URL value="@../styles/style2.css" />
|
<!-- <URL value="@../styles/style2.css" /> -->
|
||||||
<URL value="@../styles/bootstrapfx.css" />
|
<URL value="@../styles/bootstrapfx.css" />
|
||||||
</stylesheets>
|
</stylesheets>
|
||||||
</GridPane>
|
</GridPane>
|
@ -4,7 +4,7 @@
|
|||||||
<?import javafx.scene.layout.* ?>
|
<?import javafx.scene.layout.* ?>
|
||||||
<?import javafx.scene.control.* ?>
|
<?import javafx.scene.control.* ?>
|
||||||
|
|
||||||
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="400" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="wow.doge.chatto.controller.MainViewController">
|
<AnchorPane id="rootPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="400" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="wow.doge.chatto.controller.MainViewController">
|
||||||
<children>
|
<children>
|
||||||
<MenuBar VBox.vgrow="NEVER" fx:id="menuBar">
|
<MenuBar VBox.vgrow="NEVER" fx:id="menuBar">
|
||||||
<menus>
|
<menus>
|
||||||
@ -61,11 +61,12 @@
|
|||||||
prefHeight="30.0" styleClass="status"/>
|
prefHeight="30.0" styleClass="status"/>
|
||||||
</bottom>
|
</bottom>
|
||||||
</BorderPane> -->
|
</BorderPane> -->
|
||||||
<AnchorPane fx:id="loginPane"></AnchorPane>
|
<AnchorPane fx:id="mainPane"></AnchorPane>
|
||||||
<AnchorPane fx:id="chatPane"></AnchorPane>
|
<!-- <AnchorPane fx:id="chatPane"></AnchorPane> -->
|
||||||
</children>
|
</children>
|
||||||
<stylesheets>
|
<stylesheets>
|
||||||
<URL value="@default.css" />
|
<!-- <URL value="@default.css" />
|
||||||
<URL value="@../styles/ui.css" />
|
<URL value="@../styles/ui.css" />
|
||||||
|
<URL value="@../styles/style2.css" /> -->
|
||||||
</stylesheets>
|
</stylesheets>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
@ -1,16 +1,50 @@
|
|||||||
#rootPane{
|
#rootPane {
|
||||||
-fx-background-image: url("../images/backgroung.jpg");
|
-fx-background-image: url("../images/backgroung.jpg");
|
||||||
-fx-background-size: 1920.0 1080.0;
|
-fx-background-size: 1920 1080;
|
||||||
-fx-background-position: center center;
|
-fx-background-position: center center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ikonli-font-icon{
|
.ikonli-font-icon {
|
||||||
-fx-icon-size: 100px;
|
-fx-icon-size: 100px;
|
||||||
-fx-icon-color: blue;
|
-fx-icon-color: blue;
|
||||||
}
|
}
|
||||||
|
|
||||||
.user-radio .radio {
|
.user-radio .radio {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
-fx-pref-width: 0px;
|
-fx-pref-width: 0px;
|
||||||
-fx-max-width: 0px;
|
-fx-max-width: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mylistview .scroll-bar:horizontal .track,
|
||||||
|
.mylistview .scroll-bar:vertical .track {
|
||||||
|
-fx-background-color: transparent;
|
||||||
|
-fx-border-color: transparent;
|
||||||
|
-fx-background-radius: 0em;
|
||||||
|
-fx-border-radius: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mylistview .scroll-bar:horizontal .increment-button,
|
||||||
|
.mylistview .scroll-bar:horizontal .decrement-button {
|
||||||
|
-fx-background-color: transparent;
|
||||||
|
-fx-background-radius: 0em;
|
||||||
|
-fx-padding: 0 0 10 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mylistview .scroll-bar:vertical .increment-button,
|
||||||
|
.mylistview .scroll-bar:vertical .decrement-button {
|
||||||
|
-fx-background-color: transparent;
|
||||||
|
-fx-background-radius: 0em;
|
||||||
|
-fx-padding: 0 10 0 0;
|
||||||
|
}
|
||||||
|
.mylistview .scroll-bar .increment-arrow,
|
||||||
|
.mylistview .scroll-bar .decrement-arrow {
|
||||||
|
-fx-shape: " ";
|
||||||
|
-fx-padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mylistview .scroll-bar:horizontal .thumb,
|
||||||
|
.mylistview .scroll-bar:vertical .thumb {
|
||||||
|
-fx-background-color: derive(black, 90%);
|
||||||
|
-fx-background-insets: 2, 0, 0;
|
||||||
|
-fx-background-radius: 2em;
|
||||||
|
}
|
||||||
|
@ -13,44 +13,42 @@
|
|||||||
-fx-pref-height: 40px;
|
-fx-pref-height: 40px;
|
||||||
-fx-background-insets: 5px;
|
-fx-background-insets: 5px;
|
||||||
} */
|
} */
|
||||||
.root{
|
.root {
|
||||||
-fx-padding: 5.0 5.0 5.0 5.0;
|
-fx-padding: 5 5 5 5;
|
||||||
-fx-background-image: url("../images/backgroung.jpg");
|
-fx-background-image: url("../images/backgroung.jpg");
|
||||||
-fx-background-size: 1920.0 1080.0;
|
-fx-background-size: 1920 1080;
|
||||||
-fx-background-position: center center;
|
-fx-background-position: center center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#flowPane {
|
#flowPane {
|
||||||
-fx-hgap: 5.0px;
|
-fx-hgap: 5px;
|
||||||
-fx-vgap: 5.0px;
|
-fx-vgap: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.userVbox {
|
/* .userVbox {
|
||||||
-fx-padding: 5.0 5.0 5.0 5.0;
|
-fx-padding: 5 5 5 5;
|
||||||
-fx-background-insets: 5px;
|
-fx-background-insets: 5px;
|
||||||
-fx-background-size: 1920.0 1080.0;
|
-fx-background-size: 1920 1080;
|
||||||
-fx-background-position: center center;
|
-fx-background-position: center center;
|
||||||
-fx-background-color: #ff0055;
|
-fx-background-color: #ff0055;
|
||||||
-fx-background-radius: 10px;
|
-fx-background-radius: 10px;
|
||||||
|
} */
|
||||||
|
|
||||||
|
#chatTextArea {
|
||||||
|
-fx-font-size: 1.4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#chatTextArea{
|
/* .my-list-cell {
|
||||||
-fx-font-size: 1.4em;
|
-fx-background-color: null;
|
||||||
}
|
|
||||||
|
|
||||||
.my-list-cell {
|
|
||||||
-fx-background-color: null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-list-view {
|
.my-list-view {
|
||||||
-fx-background-color: null;
|
-fx-background-color: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-list-view > .list-cell {
|
.my-list-view > .list-cell {
|
||||||
-fx-background-color: null;
|
-fx-background-color: null;
|
||||||
}
|
} */
|
||||||
|
|
||||||
/*.myButton {
|
/*.myButton {
|
||||||
-fx-background-radius: 21.0px;
|
-fx-background-radius: 21.0px;
|
||||||
|
@ -18,6 +18,10 @@ import org.json4s.JsonDSL._
|
|||||||
import scala.util.Success
|
import scala.util.Success
|
||||||
import scala.util.Failure
|
import scala.util.Failure
|
||||||
import com.softwaremill.quicklens._
|
import com.softwaremill.quicklens._
|
||||||
|
import org.scalafx.extras._
|
||||||
|
import wow.doge.chatto.service.UserService
|
||||||
|
import javax.inject._
|
||||||
|
import javafx.application.Platform
|
||||||
@Named
|
@Named
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
class ApplicationController extends DefaultWindowController {
|
class ApplicationController extends DefaultWindowController {
|
||||||
@ -29,6 +33,9 @@ class ApplicationController extends DefaultWindowController {
|
|||||||
|
|
||||||
// override def width: Int = 400
|
// override def width: Int = 400
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private var appDataHandler: AppDataHandler = _
|
||||||
|
|
||||||
def applicationDidLaunch() = {
|
def applicationDidLaunch() = {
|
||||||
logger.info("start " + this)
|
logger.info("start " + this)
|
||||||
applicationEnvironment.loadResourceBundle("bundles/application")
|
applicationEnvironment.loadResourceBundle("bundles/application")
|
||||||
@ -39,11 +46,6 @@ class ApplicationController extends DefaultWindowController {
|
|||||||
def applicationName: ApplicationName = {
|
def applicationName: ApplicationName = {
|
||||||
ApplicationName(configStringValue("application.name"))
|
ApplicationName(configStringValue("application.name"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Produces var appData: AppData = synchronized {
|
|
||||||
AppData(User.empty, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Produces
|
@Produces
|
||||||
def httpBackend = backend
|
def httpBackend = backend
|
||||||
|
|
||||||
@ -62,19 +64,30 @@ class ApplicationController extends DefaultWindowController {
|
|||||||
super.applicationWillStop()
|
super.applicationWillStop()
|
||||||
println("stopping")
|
println("stopping")
|
||||||
await(httpBackend.close())
|
await(httpBackend.close())
|
||||||
|
Platform.exit()
|
||||||
System.exit(0)
|
System.exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
def showLoginPane() = {
|
def showLoginPane() = onFX {
|
||||||
appData = appData.copy(user = User.empty)
|
offFX { appDataHandler.clearCredentials() }
|
||||||
appData = appData.modify(_.user).using(_ => User.empty)
|
// replaceSceneContent(mainViewController.loginController)
|
||||||
appData = appData.modify(_.user.username).using(_ => "")
|
// mainViewController.mainManager.updatePaneContent(
|
||||||
|
// mainViewController.loginController
|
||||||
|
// )
|
||||||
replaceSceneContent(mainViewController.loginController)
|
replaceSceneContent(mainViewController.loginController)
|
||||||
}
|
}
|
||||||
|
|
||||||
def showChatPane(): Unit = {
|
def logout() = {
|
||||||
|
val newMainViewController = getController[MainViewController]()
|
||||||
|
replaceSceneContent(newMainViewController)
|
||||||
|
}
|
||||||
|
|
||||||
|
def showChatPane(): Unit = onFX {
|
||||||
// import org.scalafx.extras._
|
// import org.scalafx.extras._
|
||||||
replaceSceneContent(mainViewController.chatController, true)
|
replaceSceneContent(mainViewController.chatController, true)
|
||||||
|
// mainViewController.mainManager.updatePaneContent(
|
||||||
|
// mainViewController.chatController
|
||||||
|
// )
|
||||||
// httpBackend.send(basicRequest.get(uri""))
|
// httpBackend.send(basicRequest.get(uri""))
|
||||||
// val willBeResponse = basicRequest
|
// val willBeResponse = basicRequest
|
||||||
// .get(uri"https://httpbin.org/get")
|
// .get(uri"https://httpbin.org/get")
|
||||||
@ -94,9 +107,32 @@ class ApplicationController extends DefaultWindowController {
|
|||||||
// } yield (r.body)
|
// } yield (r.body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final case class ApplicationName(name: String)
|
final case class ApplicationName(name: String)
|
||||||
final case class User(username: String, password: String, token: String)
|
final case class UserCredentials(
|
||||||
object User {
|
username: String,
|
||||||
def empty = User("", "", "")
|
password: String,
|
||||||
|
token: String
|
||||||
|
)
|
||||||
|
object UserCredentials {
|
||||||
|
def empty = UserCredentials("empty", "empty", "empty")
|
||||||
}
|
}
|
||||||
final case class AppData(user: User, sumth: String)
|
|
||||||
|
@ApplicationScoped
|
||||||
|
class AppDataHandler {
|
||||||
|
private var _appData: AppData = AppData(UserCredentials.empty, "empty")
|
||||||
|
|
||||||
|
private def appData_=(appData: AppData) = synchronized { _appData = appData }
|
||||||
|
|
||||||
|
def appData = _appData
|
||||||
|
|
||||||
|
def updateCredentials(credentials: UserCredentials): Unit = offFX {
|
||||||
|
println(credentials)
|
||||||
|
appData = appData.copy(credentials = credentials)
|
||||||
|
}
|
||||||
|
|
||||||
|
def clearCredentials() = {
|
||||||
|
appData = appData.copy(credentials = UserCredentials.empty)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final case class AppData(credentials: UserCredentials, sumth: String)
|
||||||
|
@ -25,6 +25,8 @@ class UserBox() extends VBox() {
|
|||||||
|
|
||||||
fxmlLoader.load();
|
fxmlLoader.load();
|
||||||
|
|
||||||
|
()
|
||||||
|
|
||||||
// userRadioButton
|
// userRadioButton
|
||||||
// .selectedProperty()
|
// .selectedProperty()
|
||||||
// .addListener(changeListener => {
|
// .addListener(changeListener => {
|
||||||
@ -37,16 +39,12 @@ class UserBox() extends VBox() {
|
|||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
|
||||||
userRadioButton.selected.onChange { (_, _, _) =>
|
// userRadioButton.selected.onChange { (_, _, _) =>
|
||||||
{
|
// {
|
||||||
getStyleClass().clear();
|
// getStyleClass().clear();
|
||||||
getStyleClass().addAll("btn", "btn-primary", "user-box");
|
// getStyleClass().addAll("btn", "btn-primary", "user-box");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object UserBox {
|
|
||||||
// val ub = new UserBox()
|
|
||||||
}
|
|
||||||
|
@ -20,19 +20,26 @@ import scala.concurrent.ExecutionContext.Implicits.global
|
|||||||
import com.typesafe.scalalogging.LazyLogging
|
import com.typesafe.scalalogging.LazyLogging
|
||||||
// import wow.doge.chatto.controller.LoginController.Person
|
// import wow.doge.chatto.controller.LoginController.Person
|
||||||
import com.sfxcode.sapphire.core.value.FXBean
|
import com.sfxcode.sapphire.core.value.FXBean
|
||||||
|
import wow.doge.chatto.AppDataHandler
|
||||||
|
import com.jfoenix.controls.JFXListView
|
||||||
|
import scala.async.Async.{async, await}
|
||||||
|
import javafx.scene.paint.Color
|
||||||
|
|
||||||
class ChatController @Inject() (userService: UserService)
|
class ChatController @Inject() (
|
||||||
extends AbstractViewController
|
userService: UserService,
|
||||||
|
appDataHandler: AppDataHandler
|
||||||
|
) extends AbstractViewController
|
||||||
with LazyLogging {
|
with LazyLogging {
|
||||||
|
|
||||||
@FXML private var label: Label = _
|
@FXML private var label: Label = _
|
||||||
@FXML private var flowPane: FlowPane = _
|
@FXML private var flowPane: FlowPane = _
|
||||||
@FXML private var submitButton: Button = _
|
@FXML private var submitButton: Button = _
|
||||||
@FXML private var loginButton: Button = _
|
@FXML private var logoutButton: Button = _
|
||||||
@FXML private var chatTextArea: TextArea = _
|
// @FXML private var chatTextArea: TextArea = _
|
||||||
@FXML private var chatInput: TextArea = _
|
@FXML private var chatInput: TextArea = _
|
||||||
@FXML private var usersVBox: VBox = _
|
@FXML private var usersVBox: VBox = _
|
||||||
@FXML private var chatListView: ListView[HBox] = _
|
@FXML var usersListView: JFXListView[Any] = _
|
||||||
|
@FXML private var chatListView: JFXListView[HBox] = _
|
||||||
// applicationController.show
|
// applicationController.show
|
||||||
|
|
||||||
override def didGainVisibilityFirstTime(): Unit = {
|
override def didGainVisibilityFirstTime(): Unit = {
|
||||||
@ -42,13 +49,13 @@ class ChatController @Inject() (userService: UserService)
|
|||||||
ub.messageLabel.text = "Hi there"
|
ub.messageLabel.text = "Hi there"
|
||||||
// ub.messageLabel.id =
|
// ub.messageLabel.id =
|
||||||
ub.userRadioButton.text = "User 1"
|
ub.userRadioButton.text = "User 1"
|
||||||
usersVBox.children.clear()
|
// usersVBox.children.clear()
|
||||||
usersVBox.children += ub
|
// usersVBox.children += ub
|
||||||
println("test")
|
println("test")
|
||||||
println(s"Result = ${func()}")
|
println(s"Result = ${func()}")
|
||||||
offFX(println("hello from new thread"))
|
offFX(println("hello from new thread"))
|
||||||
chatTextArea.visible <== !chatInput.text.isEmpty
|
// chatTextArea.visible <== !chatInput.text.isEmpty
|
||||||
chatTextArea.text <== chatInput.text
|
// chatTextArea.text <== chatInput.text
|
||||||
|
|
||||||
for (r <- userService.func2()) yield (logger.info(s"${r.body}"))
|
for (r <- userService.func2()) yield (logger.info(s"${r.body}"))
|
||||||
|
|
||||||
@ -64,10 +71,47 @@ class ChatController @Inject() (userService: UserService)
|
|||||||
bean.updateValue("name", "Lester")
|
bean.updateValue("name", "Lester")
|
||||||
println(bean.bean)
|
println(bean.bean)
|
||||||
|
|
||||||
|
logoutButton.onAction = (e) => {
|
||||||
|
applicationController.logout()
|
||||||
|
println(appDataHandler.appData)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override def didGainVisibility(): Unit = {
|
override def didGainVisibility(): Unit = {
|
||||||
super.didGainVisibility()
|
super.didGainVisibility()
|
||||||
|
chatInput.requestFocus()
|
||||||
|
|
||||||
|
async {
|
||||||
|
val willBeUsers = userService
|
||||||
|
.getUsers(appDataHandler.appData.credentials)
|
||||||
|
.map(_.body)
|
||||||
|
val maybeUsers = await(willBeUsers)
|
||||||
|
val maybeUsersBoxes = maybeUsers.map(users => {
|
||||||
|
users.map(user => {
|
||||||
|
// val ub = new UserBox()
|
||||||
|
// ub.messageLabel.text = "Hi there"
|
||||||
|
// ub.userRadioButton.text = user
|
||||||
|
// ub
|
||||||
|
// new Rectangle {
|
||||||
|
// fill <== when(hover) choose (Color.Red)
|
||||||
|
// }
|
||||||
|
val hb = new HBox
|
||||||
|
new HBox {
|
||||||
|
this.children += new Label {
|
||||||
|
textProperty() = user
|
||||||
|
// textFillProperty <== when(this.hover) choose (Color.RED) otherwise (Color.BLUE)
|
||||||
|
}
|
||||||
|
// fill <== when(this.hover) choose (Color.RED) otherwise (Color.BLUE)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
onFX {
|
||||||
|
maybeUsersBoxes.map(userBoxes => {
|
||||||
|
usersListView.items() ++= userBoxes
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
def func() = {
|
def func() = {
|
||||||
val x = offFXAndWait {
|
val x = offFXAndWait {
|
||||||
|
@ -22,19 +22,26 @@ import javafx.scene.control.Label
|
|||||||
import javafx.scene.input.KeyCode
|
import javafx.scene.input.KeyCode
|
||||||
import scala.async.Async.{async, await}
|
import scala.async.Async.{async, await}
|
||||||
import wow.doge.chatto.AppData
|
import wow.doge.chatto.AppData
|
||||||
import wow.doge.chatto.User
|
import wow.doge.chatto.UserCredentials
|
||||||
import sttp.client._
|
import sttp.client._
|
||||||
import scala.concurrent.Future
|
import scala.concurrent.Future
|
||||||
import sttp.client.asynchttpclient.WebSocketHandler
|
import sttp.client.asynchttpclient.WebSocketHandler
|
||||||
import wow.doge.chatto.types.AppTypes.HttpBackend
|
import wow.doge.chatto.types.AppTypes.HttpBackend
|
||||||
import wow.doge.chatto.types.AppTypes
|
import wow.doge.chatto.types.AppTypes
|
||||||
|
import org.scalafx.extras._
|
||||||
|
import wow.doge.chatto.AppDataHandler
|
||||||
|
import com.sfxcode.sapphire.core.value.BeanConversions
|
||||||
|
|
||||||
class LoginController @Inject() (userService: UserService, var appData: AppData)(
|
class LoginController @Inject() (
|
||||||
|
userService: UserService,
|
||||||
|
appDataHandler: AppDataHandler
|
||||||
|
)(
|
||||||
implicit backend: HttpBackend
|
implicit backend: HttpBackend
|
||||||
) extends AbstractViewController
|
) extends AbstractViewController
|
||||||
with LazyLogging
|
with LazyLogging
|
||||||
with AppTypes {
|
with AppTypes
|
||||||
@FXML private var submitButton: JFXButton = _
|
with BeanConversions {
|
||||||
|
@FXML var submitButton: JFXButton = _
|
||||||
|
|
||||||
@FXML private var usernameTextField: JFXTextField = _
|
@FXML private var usernameTextField: JFXTextField = _
|
||||||
|
|
||||||
@ -45,12 +52,11 @@ class LoginController @Inject() (userService: UserService, var appData: AppData)
|
|||||||
override def didGainVisibilityFirstTime(): Unit = {
|
override def didGainVisibilityFirstTime(): Unit = {
|
||||||
super.didGainVisibilityFirstTime()
|
super.didGainVisibilityFirstTime()
|
||||||
this.stage.resizable = false
|
this.stage.resizable = false
|
||||||
usernameTextField.requestFocus()
|
// usernameTextField.requestFocus()
|
||||||
submitButton.setOnAction(actionLogin)
|
|
||||||
|
|
||||||
// println(something)
|
// submitButton.setOnAction(actionLogin)
|
||||||
|
|
||||||
val bindings = KeyBindings("usernameTextField", "passwordTextField")
|
val bindings = KeyBindings("username", "password")
|
||||||
// Expression Binding Example
|
// Expression Binding Example
|
||||||
// bindings.add(
|
// bindings.add(
|
||||||
// "usernameTextField",
|
// "usernameTextField",
|
||||||
@ -59,26 +65,13 @@ class LoginController @Inject() (userService: UserService, var appData: AppData)
|
|||||||
|
|
||||||
val box = new VBox()
|
val box = new VBox()
|
||||||
val adapter = FXBeanAdapter[Person](this)
|
val adapter = FXBeanAdapter[Person](this)
|
||||||
// adapter.
|
|
||||||
val bean = FXBean[Person](Person("twar", "username", "password"))
|
val bean = FXBean[Person](Person("twar", "username", "password"))
|
||||||
// bean.
|
|
||||||
// bean.get
|
|
||||||
adapter.addBindings(bindings)
|
adapter.addBindings(bindings)
|
||||||
adapter.set(bean)
|
adapter.set(bean)
|
||||||
// adapter.addIntConverter("age")
|
// adapter.addIntConverter("age")
|
||||||
// adapter.hasBeanProperty
|
// adapter.hasBeanProperty
|
||||||
// adapter.revert()
|
// adapter.revert()
|
||||||
|
|
||||||
// usernameTextField.onKeyPressed = (keyEvent) => {
|
|
||||||
// if (keyEvent.getCode() == KeyCode.ENTER) submitButton.fire()
|
|
||||||
// }
|
|
||||||
// submitButton.onKeyPressed = (keyEvent) => {
|
|
||||||
// if (keyEvent.getCode() == KeyCode.ENTER) submitButton.fire()
|
|
||||||
// }
|
|
||||||
// passwordTextField.onKeyPressed = (keyEvent) => {
|
|
||||||
// if (keyEvent.getCode() == KeyCode.ENTER) submitButton.fire()
|
|
||||||
// }
|
|
||||||
|
|
||||||
Array(usernameTextField, passwordTextField, submitButton)
|
Array(usernameTextField, passwordTextField, submitButton)
|
||||||
.foreach(_.onKeyPressed = (keyEvent) => {
|
.foreach(_.onKeyPressed = (keyEvent) => {
|
||||||
if (keyEvent.getCode() == KeyCode.ENTER) submitButton.fire()
|
if (keyEvent.getCode() == KeyCode.ENTER) submitButton.fire()
|
||||||
@ -90,51 +83,43 @@ class LoginController @Inject() (userService: UserService, var appData: AppData)
|
|||||||
usernameTextField.requestFocus()
|
usernameTextField.requestFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
def actionLogin(e: ActionEvent) = {
|
def actionLogin() = {
|
||||||
import org.scalafx.extras._
|
|
||||||
val inputUserName = usernameTextField.text()
|
val inputUserName = usernameTextField.text()
|
||||||
val inputPassword = passwordTextField.text()
|
val inputPassword = passwordTextField.text()
|
||||||
|
|
||||||
// val authenticated =
|
|
||||||
// inputPassword.equals("password") && inputUserName.equals("hmm")
|
|
||||||
login(inputUserName, inputPassword) onComplete {
|
login(inputUserName, inputPassword) onComplete {
|
||||||
case Success(value) => {
|
case Success(maybeToken) => {
|
||||||
value.foreach(println)
|
maybeToken.foreach(println)
|
||||||
value match {
|
maybeToken match {
|
||||||
case Some(token) => {
|
case Some(token) =>
|
||||||
appData =
|
async {
|
||||||
appData.copy(user = User(inputUserName, inputPassword, token))
|
val credentials =
|
||||||
}
|
UserCredentials(inputUserName, inputPassword, token)
|
||||||
|
appDataHandler.updateCredentials(credentials)
|
||||||
|
await {
|
||||||
|
userService.getUsers(credentials).map(_.body.foreach(println))
|
||||||
|
}
|
||||||
|
applicationController.showChatPane()
|
||||||
|
}
|
||||||
case None => {
|
case None => {
|
||||||
onFX(errorLabel.text =
|
updateErrorLabel("Error logging in - please check your password")
|
||||||
"Error logging in - please check your password"
|
|
||||||
)
|
|
||||||
logger.warn("Login unsuccessful wrong password")
|
logger.warn("Login unsuccessful wrong password")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Platform.runLater(() => applicationController.showChatPane())
|
// applicationController.showChatPane()
|
||||||
onFX(applicationController.showChatPane())
|
|
||||||
}
|
}
|
||||||
case Failure(exception) => {
|
case Failure(exception) => {
|
||||||
logger.error(s"${exception.getMessage()}")
|
logger.error(s"${exception.getMessage()}")
|
||||||
logger.warn("Login unsuccessful network problem")
|
logger.warn("Login unsuccessful network problem")
|
||||||
onFX {
|
updateErrorLabel("Error logging in - Please check your network")
|
||||||
errorLabel.text = "Error logging in - Please check your network"
|
// applicationController.showChatPane()
|
||||||
applicationController.showChatPane()
|
|
||||||
}
|
|
||||||
// onFX(applicationController.showChatPane())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if (authenticated) {
|
}
|
||||||
// passwordTextField.clear()
|
|
||||||
// val res = Result(username = inputUserName, password = inputPassword)
|
|
||||||
// println(res)
|
|
||||||
// // loginManager.
|
|
||||||
|
|
||||||
// applicationController.showChatPane()
|
def updateErrorLabel(message: String) = onFX {
|
||||||
// } else {
|
errorLabel.text = message
|
||||||
// logger.error("Login Error")
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def login(username: String, password: String) = async {
|
def login(username: String, password: String) = async {
|
||||||
@ -153,8 +138,8 @@ class LoginController @Inject() (userService: UserService, var appData: AppData)
|
|||||||
|
|
||||||
final case class Person(
|
final case class Person(
|
||||||
id: String,
|
id: String,
|
||||||
usernameTextField: String,
|
username: String,
|
||||||
passwordTextField: String
|
password: String
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,9 @@ class MainViewController extends ViewController with LazyLogging {
|
|||||||
// @FXML
|
// @FXML
|
||||||
// var navigationPane: Pane = _
|
// var navigationPane: Pane = _
|
||||||
|
|
||||||
@FXML var loginPane: Pane = _
|
@FXML var mainPane: Pane = _
|
||||||
|
|
||||||
@FXML var chatPane: Pane = _
|
// @FXML var chatPane: Pane = _
|
||||||
|
|
||||||
lazy val workspaceController = getController[WorkspaceController]()
|
lazy val workspaceController = getController[WorkspaceController]()
|
||||||
lazy val navigationController = getController[NavigationController]()
|
lazy val navigationController = getController[NavigationController]()
|
||||||
@ -42,13 +42,13 @@ class MainViewController extends ViewController with LazyLogging {
|
|||||||
|
|
||||||
override def didGainVisibilityFirstTime() {
|
override def didGainVisibilityFirstTime() {
|
||||||
// menuBar.setUseSystemMenuBar(true)
|
// menuBar.setUseSystemMenuBar(true)
|
||||||
menuBar.setVisible(false)
|
// menuBar.setVisible(false)
|
||||||
|
|
||||||
// navigationManager =
|
// navigationManager =
|
||||||
// ContentManager(navigationPane, this, navigationController)
|
// ContentManager(navigationPane, this, navigationController)
|
||||||
// statusBarManager = ContentManager(statusPane, this, statusBarController)
|
// statusBarManager = ContentManager(statusPane, this, statusBarController)
|
||||||
// workspaceManager = ContentManager(workspacePane, this, workspaceController)
|
// workspaceManager = ContentManager(workspacePane, this, workspaceController)
|
||||||
mainManager = ContentManager(loginPane, this, loginController)
|
mainManager = ContentManager(mainPane, this, loginController)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package wow.doge.chatto.model
|
|
||||||
|
|
||||||
import java.time.Instant
|
|
||||||
|
|
||||||
case class ChatUser(
|
|
||||||
userId: Long,
|
|
||||||
userName: String,
|
|
||||||
password: String,
|
|
||||||
joinDate: Instant
|
|
||||||
)
|
|
@ -14,21 +14,28 @@ import scala.util.Success
|
|||||||
import scala.util.Failure
|
import scala.util.Failure
|
||||||
import wow.doge.chatto.AppData
|
import wow.doge.chatto.AppData
|
||||||
import wow.doge.chatto.types.AppTypes.HttpBackend
|
import wow.doge.chatto.types.AppTypes.HttpBackend
|
||||||
|
import com.typesafe.scalalogging.LazyLogging
|
||||||
|
import org.scalafx.extras._
|
||||||
|
import wow.doge.chatto.ApplicationController
|
||||||
|
import wow.doge.chatto.UserCredentials
|
||||||
|
import javax.inject._
|
||||||
|
import wow.doge.chatto.AppDataHandler
|
||||||
|
|
||||||
class UserService @Inject() (appData: AppData)(
|
class UserService @Inject() (appDataHandler: AppDataHandler)(
|
||||||
implicit backend: HttpBackend
|
implicit backend: HttpBackend
|
||||||
) {
|
) extends LazyLogging {
|
||||||
private implicit lazy val serialization = org.json4s.native.Serialization
|
private implicit lazy val serialization = org.json4s.native.Serialization
|
||||||
|
private val domain = "http://localhost:8080"
|
||||||
|
private lazy val baseUrl = uri"$domain/api/chat"
|
||||||
|
private lazy val authBasicRequest = (credentials: UserCredentials) =>
|
||||||
|
basicRequest.auth
|
||||||
|
.basic(credentials.username, credentials.password)
|
||||||
|
// .header("X-AUTH-TOKEN", appData.credentials.token)
|
||||||
|
|
||||||
def func1() = {
|
def func1() = async {
|
||||||
val willBeResponse = basicRequest
|
val willBeResponse = func2()
|
||||||
.get(uri"https://httpbin.org/get")
|
val r = await { willBeResponse }
|
||||||
.response(asJson[HttpBinResponse])
|
r.body.map(println)
|
||||||
.send()
|
|
||||||
async {
|
|
||||||
val r = await { willBeResponse }
|
|
||||||
r.body.map(println)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def func2() =
|
def func2() =
|
||||||
@ -37,9 +44,21 @@ class UserService @Inject() (appData: AppData)(
|
|||||||
.response(asJson[HttpBinResponse])
|
.response(asJson[HttpBinResponse])
|
||||||
.send()
|
.send()
|
||||||
|
|
||||||
|
private def endpoint(uri: String) = uri"$baseUrl/$uri"
|
||||||
|
|
||||||
|
def getUsers(credentials: UserCredentials) = async {
|
||||||
|
println(appDataHandler.appData)
|
||||||
|
await {
|
||||||
|
authBasicRequest(credentials)
|
||||||
|
.get(uri"http://localhost:8080/api/chat/get/users")
|
||||||
|
.response(asJson[List[String]])
|
||||||
|
.send()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case class HttpBinResponse(
|
final case class HttpBinResponse(
|
||||||
url: String,
|
url: String,
|
||||||
origin: String,
|
origin: String,
|
||||||
headers: Map[String, String]
|
headers: Map[String, String]
|
||||||
|
Loading…
Reference in New Issue
Block a user