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