Skip to content

Commit

Permalink
Merge branch 'origin/service' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
VaheKri committed May 5, 2023
2 parents 6d7bc9d + da220f1 commit 19f7f69
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/main/java/fr/coding/pastadellamamma/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public void start(Stage stage) throws IOException {
stage.setTitle("Pasta della Mama");
stage.setScene(scene);
stage.show();



}

public static Restaurant pastaDellaMamma;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package fr.coding.pastadellamamma.controller;

import fr.coding.pastadellamamma.model.Chrono;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;

public class ChronoController {
@FXML
private Label timerLabel;

@FXML
private Button startServiceButton;

@FXML
public void initialize() {
timerLabel.setText(Chrono.getTime());

if (Chrono.isRunning) {
Chrono.setTimerLabel(timerLabel);
startServiceButton.setDisable(true);
}
}

@FXML
public void onStartServiceButtonClicked() {
startServiceButton.setDisable(true);
Chrono chrono = new Chrono(timerLabel, startServiceButton);
chrono.start();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package fr.coding.pastadellamamma.controller;



import fr.coding.pastadellamamma.Main;
import fr.coding.pastadellamamma.model.Chrono;
import fr.coding.pastadellamamma.model.Order;
import fr.coding.pastadellamamma.model.Table;
import javafx.collections.FXCollections;
Expand All @@ -21,6 +24,8 @@
import java.util.ResourceBundle;
import java.util.stream.Collectors;

import static fr.coding.pastadellamamma.model.Chrono.endOrder;

public class CommandesController implements Initializable {

public static ObservableList<Order> listCommande;
Expand Down Expand Up @@ -82,8 +87,10 @@ public void onChanged(Change<? extends Order> change) {
loadFXML("orderDetails.fxml", "détail de la commande",content);

});

newOrder.setOnAction(e -> loadFXML("AddNewOrder.fxml", "nouvelle commande",content));
// Commande test = AddNewOrderController.envoieCommande();
if (Chrono.endOrder = false) {
newOrder.setOnAction(e -> loadFXML("AddNewOrder.fxml", "nouvelle commande"));
}
}

public static void addNewOrder(Order order){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ public class MainController implements Initializable {

@FXML
public MenuItem menu;

@FXML
public MenuItem amployeList;

@FXML
public MenuItem employe;

@FXML
public MenuItem room;

@FXML
public MenuItem commandes;

@FXML
public MenuItem service;

public void loadFXML(String name, String title) {

try {
Expand All @@ -51,5 +58,6 @@ public void initialize(URL location, ResourceBundle resources) {
amployeList.setOnAction(e -> loadFXML("amployeList.fxml", "Gestion des employés"));
room.setOnAction(e -> loadFXML("table.fxml", "Gestion de salle"));
commandes.setOnAction(e -> loadFXML("commande.fxml", "Prise de commandes"));
service.setOnAction(e -> loadFXML("chrono.fxml", "Chrono"));
}
}
67 changes: 67 additions & 0 deletions src/main/java/fr/coding/pastadellamamma/model/Chrono.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package fr.coding.pastadellamamma.model;

import javafx.application.Platform;
import javafx.scene.control.Button;
import javafx.scene.control.Label;

import java.util.Timer;

public class Chrono extends Thread {

private static final int SERVICE_DURATION_SECONDS = 25 * 60;
private static int remainingTime = SERVICE_DURATION_SECONDS;
private static Timer timer;
private static Label timerLabel;
private static Button startServiceButton;
public static boolean isRunning;

public static boolean endOrder = false;

public static void stopService() {
isRunning = false;
timer.cancel();
timer = null;
remainingTime = SERVICE_DURATION_SECONDS;
timerLabel.setText(getTime());
startServiceButton.setDisable(false);
}

public static String getTime() {
int minutes = remainingTime / 60;
int remainingSeconds = remainingTime % 60;
return String.format("%02d:%02d", minutes, remainingSeconds);
}

public static void setTimerLabel(Label label) {
timerLabel = label;
}

public void run() {
isRunning = true;

try {
for (;;) {
System.out.println(remainingTime);
Platform.runLater(() -> timerLabel.setText(getTime()));

Thread.sleep(1000);
remainingTime--;

if (remainingTime <= 0) {
stopService();
}

if (remainingTime <= 900) {
endOrder = true;
}
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

public Chrono(Label label, Button startButton) {
timerLabel = label;
startServiceButton = startButton;
}
}
34 changes: 34 additions & 0 deletions src/main/resources/fr/coding/pastadellamamma/chrono.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>


<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.coding.pastadellamamma.controller.ChronoController">
<children>
<SplitPane dividerPositions="0.32357859531772576" prefHeight="457.0" prefWidth="600.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="631.0" prefWidth="175.0">
<children>
<Button fx:id="startServiceButton" layoutX="35.0" layoutY="78.0" mnemonicParsing="false" onAction="#onStartServiceButtonClicked" text="Démarer le service" />
<Label fx:id="timerLabel" layoutX="60.0" layoutY="250.0">
<font>
<Font size="36.0" />
</font>
</Label>
<Label layoutY="131.0" prefHeight="68.0" prefWidth="191.0" text="Temps restant avant la fin du service" textAlignment="CENTER" wrapText="true">
<font>
<Font size="18.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="412.0" prefWidth="416.0" />
</items>
</SplitPane>
</children>
</VBox>
1 change: 1 addition & 0 deletions src/main/resources/fr/coding/pastadellamamma/main.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<MenuItem fx:id="amployeList" mnemonicParsing="false" text="Gestion des employés" />
<MenuItem fx:id="room" mnemonicParsing="false" text="Gestion de salle" />
<MenuItem fx:id="commandes" mnemonicParsing="false" text="Prise de commandes" />
<MenuItem fx:id="service" mnemonicParsing="false" text="Service" />
</items>
</Menu>
</menus>
Expand Down

0 comments on commit 19f7f69

Please sign in to comment.