ADD:: Added dashboard

added controller class and functionality to switch between sections
This commit is contained in:
Sem van der Hoeven
2019-03-11 14:05:26 +01:00
parent 2e1becbe32
commit aabe922f8f
8 changed files with 186 additions and 11 deletions

View File

@@ -1,11 +1,18 @@
buildscript { buildscript {
repositories { repositories {
mavenCentral() mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
} }
dependencies { dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE") classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.5.RELEASE")
classpath("org.openjfx:javafx-plugin:0.0.7")
} }
} }
//plugins {
// id "org.openjfx.javafxplugin" version "0.0.7"
//}
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'eclipse' apply plugin: 'eclipse'
@@ -15,9 +22,11 @@ apply plugin: 'io.spring.dependency-management'
apply plugin: 'jacoco' apply plugin: 'jacoco'
apply plugin: 'checkstyle' apply plugin: 'checkstyle'
//apply plugin: 'org.openjfx.javafxplugin'
tasks.withType(Checkstyle) { tasks.withType(Checkstyle) {
reports { reports {
html.destination rootProject.file("reports/checkstyle.html") html.destination rootProject.file("build/reports/checkstyle.html")
} }
} }
@@ -81,3 +90,5 @@ jacocoTestReport {
bootJar { bootJar {
mainClassName = 'Client.Application' mainClassName = 'Client.Application'
} }

View File

@@ -70,7 +70,7 @@ dependencies {
} }
jacoco { jacoco {
toolVersion = "0.8.2" toolVersion = "0.8.3"
reportsDir = file("$buildDir/customJacocoReportDir") reportsDir = file("$buildDir/customJacocoReportDir")
} }

View File

@@ -6,13 +6,9 @@ import javafx.scene.Scene;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication @SpringBootApplication
public class Application extends javafx.application.Application { public class Application extends javafx.application.Application {
@@ -40,12 +36,19 @@ public class Application extends javafx.application.Application {
@Override @Override
public void start(Stage primaryStage) throws Exception{ public void start(Stage primaryStage) throws Exception{
fxmlLoader.setLocation(this.getClass().getClassLoader().getResource("fxml/sample.fxml")); fxmlLoader.setLocation(this.getClass().getClassLoader().getResource("fxml/sample.fxml"));
// fxmlLoader.setLocation(this.getClass().getClassLoader().getResource("fxml/dashboard.fxml"));
rootNode = fxmlLoader.load(); rootNode = fxmlLoader.load();
// rootNode = FXMLLoader.load(this.getClass().getClassLoader().getResource("fxml/sample.fxml")); // rootNode = FXMLLoader.load(this.getClass().getClassLoader().getResource("fxml/sample.fxml"));
primaryStage.setTitle("GoGreen"); primaryStage.setTitle("GoGreen");
Scene scene = new Scene(rootNode); Scene scene = new Scene(rootNode);
// scene.getStylesheets().add(getClass().getResource("stylesheets/dashboardStyle.css").toExternalForm());
primaryStage.setScene(scene); primaryStage.setScene(scene);
primaryStage.show(); primaryStage.show();
} }

View File

@@ -0,0 +1,78 @@
package gogreen.client.controller;
import gogreen.client.rest.UserService;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.effect.DropShadow;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import org.springframework.beans.factory.annotation.Autowired;
public class DashBoardController {
@Autowired
UserService userService;
@FXML
public AnchorPane menuBar;
public AnchorPane dashboardPane;
public AnchorPane userPane;
public AnchorPane activitiesPane;
public Label welcomebacktext;
// public Button addActivityButton;
// public ComboBox addActivity;
@FXML
public Label dashboardText;
public Label activitiesText;
public Label userText;
public Button dashboardButton;
public Button activitiesButton;
public Button userButton;
DropShadow shadow = new DropShadow();
public void handleClickAction(MouseEvent event) {
if (event.getTarget() == dashboardButton) {
dashboardPane.setVisible(true);
userPane.setVisible(false);
activitiesPane.setVisible(false);
} else if (event.getTarget() == activitiesButton){
dashboardPane.setVisible(false);
userPane.setVisible(false);
activitiesPane.setVisible(true);
} else if (event.getTarget() == userButton) {
dashboardPane.setVisible(false);
userPane.setVisible(true);
activitiesPane.setVisible(false);
}
}
public void displayDashboard(ActionEvent event) {
dashboardPane.setVisible(true);
userPane.setVisible(false);
activitiesPane.setVisible(false);
}
public void displayActivities(ActionEvent event) {
dashboardPane.setVisible(false);
userPane.setVisible(false);
activitiesPane.setVisible(true);
}
public void displayUser(ActionEvent event) {
dashboardPane.setVisible(false);
userPane.setVisible(true);
activitiesPane.setVisible(false);
}
public void addShadow(MouseEvent event) {
userButton.setEffect(shadow);
}
public void removeShadow(MouseEvent event) {
userButton.setEffect(null);
}
}

View File

@@ -4,7 +4,6 @@ import gogreen.client.rest.UserService;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
@@ -35,6 +34,8 @@ public class UserController {
@FXML @FXML
private Button signupButton; private Button signupButton;
// @Value("${my.url}") // @Value("${my.url}")
// private String myUrl; // private String myUrl;
@@ -68,11 +69,28 @@ public class UserController {
} }
userService.registerUser(usernameField.getText(), passwordField.getText()); userService.registerUser(usernameField.getText(), passwordField.getText());
// load the dashboard stage
// Parent parent = FXMLLoader.load(this.getClass().getClassLoader().getResource("/fxml/dashboard.fxml")); // Parent parent = FXMLLoader.load(this.getClass().getClassLoader().getResource("/fxml/dashboard.fxml"));
//
// Scene scene = new Scene(parent); // Scene scene = new Scene(parent);
// Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow(); // Stage app_stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
// app_stage.setScene(scene); // app_stage.setScene(scene);
// app_stage.setFullScreen(true);
// app_stage.show(); // app_stage.show();
//on,y works once, when already logged in once, need to restart client for it to work again
openDashboard();
}
public void openDashboard() throws IOException {
Parent dash = FXMLLoader.load(this.getClass().getClassLoader().getResource("fxml/Dashboard.fxml"));
Scene scene = new Scene(dash);
Stage app_stage = new Stage();
app_stage.setScene(scene);
// app_stage.setFullScreen(true);
app_stage.show();
} }
public static class AlertHelper { public static class AlertHelper {

View File

@@ -1,6 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.collections.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.collections.FXCollections?>
<AnchorPane prefHeight="602.0" prefWidth="926.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gogreen.client.controller.DashBoardController">
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" /> <children>
<AnchorPane fx:id="menuBar" prefHeight="603.0" prefWidth="216.0" style="-fx-background-color: #545b4f;">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" layoutY="-2.0" prefHeight="90.0" prefWidth="216.0" text="Go Green" textAlignment="CENTER" textFill="#07a11c">
<font>
<Font size="36.0" />
</font>
</Label>
<Button fx:id="dashboardButton" layoutY="88.0" mnemonicParsing="false" onAction="#displayDashboard" prefHeight="45.0" prefWidth="216.0" style="-fx-background-color: #5a635c;" text="dashboard">
<font>
<Font size="21.0" />
</font>
</Button>
<Button fx:id="activitiesButton" layoutY="133.0" mnemonicParsing="false" onAction="#displayActivities" prefHeight="45.0" prefWidth="216.0" style="-fx-background-color: #5a635c;" text="activities">
<font>
<Font size="21.0" />
</font>
</Button>
<Button fx:id="userButton" layoutY="178.0" mnemonicParsing="false" onAction="#displayUser" prefHeight="45.0" prefWidth="216.0" style="-fx-background-color: #5a635c;" text="you">
<font>
<Font size="21.0" />
</font>
</Button>
</children></AnchorPane>
<AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="603.0" prefWidth="711.0" visible="false" />
<AnchorPane fx:id="userPane" layoutX="215.0" layoutY="-1.0" prefHeight="603.0" prefWidth="711.0" visible="false" />
<AnchorPane fx:id="dashboardPane" layoutX="215.0" prefHeight="603.0" prefWidth="711.0">
<children>
<HBox layoutX="97.0" layoutY="124.0" prefHeight="100.0" prefWidth="200.0" />
<Label fx:id="welcomebacktext" layoutX="69.0" layoutY="53.0" text="Welcome back user!">
<font>
<Font size="30.0" />
</font>
</Label>
<Button layoutX="583.0" layoutY="41.0" mnemonicParsing="false" style="-fx-background-color: #167526;" text="+" textFill="#e0fcdb">
<font>
<Font name="Eras Bold ITC" size="28.0" />
</font>
</Button>
<!--<ComboBox fx:id="addActivity" layoutX="532.0" layoutY="28.0" prefWidth="150.0" promptText="Add an Activity" style="-fx-background-color: #1f951f;">-->
<!--<items>-->
<!--<FXCollections fx:factory="observableArrayList">-->
<!--<String fx:value="Ate a vegetarian meal" />-->
<!--</FXCollections>-->
<!--</items>-->
<!--</ComboBox>-->
</children>
</AnchorPane>
</children>
</AnchorPane>

View File

@@ -0,0 +1,5 @@
.button {
-fx-border-width: 0px 0px 1px 0px;
-fx-border-color: #f9f9f9;
-fx-border-radius: 0%;
}

View File

@@ -58,7 +58,7 @@ dependencies {
} }
jacoco { jacoco {
toolVersion = "0.8.2" toolVersion = "0.8.3"
reportsDir = file("$buildDir/customJacocoReportDir") reportsDir = file("$buildDir/customJacocoReportDir")
} }
@@ -70,4 +70,8 @@ jacocoTestReport {
} }
} }
checkstyle {
toolVersion = "7.6.1"
}