diff --git a/src/main/java/ecorp/easy/installer/AppConstants.java b/src/main/java/ecorp/easy/installer/AppConstants.java index 792f3b128118c7db162f0b7398e879b23ec2ead4..198567a0322b9b78c7d7fba5f31ef6416e73954e 100644 --- a/src/main/java/ecorp/easy/installer/AppConstants.java +++ b/src/main/java/ecorp/easy/installer/AppConstants.java @@ -20,12 +20,13 @@ import java.io.File; import java.nio.file.Paths; /** - * + * @TODO make all final static field with uppercase or lowcase but not a mix of both * @author Vincent Bourgmayer * @author Omer Akram */ public abstract class AppConstants { + public final static String APP_VERSION = "v0.11.2-beta"; public final static String Separator = FileSystems.getDefault().getSeparator(); public final static String OsName = System.getProperty("os.name"); public final static String JavaHome = System.getProperty("java.home"); diff --git a/src/main/java/ecorp/easy/installer/EasyInstaller.java b/src/main/java/ecorp/easy/installer/EasyInstaller.java index 55b99470b6c6f7181c5a1a233e6f012de66e93ad..fc941e36f66d95fff59ebce89e2b5470701280db 100644 --- a/src/main/java/ecorp/easy/installer/EasyInstaller.java +++ b/src/main/java/ecorp/easy/installer/EasyInstaller.java @@ -44,6 +44,7 @@ public class EasyInstaller extends Application { private ResourceBundle i18n; //i18n mean "internationalization" private MainWindowController controller; + @Override public void start(Stage stage) throws Exception { @@ -62,7 +63,7 @@ public class EasyInstaller extends Application { //Defines some properties Scene scene = new Scene(root); - stage.setTitle(i18n.getString("appTitle")+"v0.11.2-beta"); + stage.setTitle(i18n.getString("appTitle")+AppConstants.APP_VERSION); stage.setScene(scene); stage.setResizable(true); diff --git a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FeedbackController.java b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FeedbackController.java index 94bd0bda0b4cac45b8a72124ac56bdba81f287b7..ddf0c86fc7fad8750d64b3c72f9126f53b7cc064 100644 --- a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FeedbackController.java +++ b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FeedbackController.java @@ -24,7 +24,12 @@ import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.util.Date; +import java.util.TimeZone; import java.util.UUID; +import java.util.regex.Pattern; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.Label; @@ -41,10 +46,14 @@ import org.slf4j.LoggerFactory; */ public class FeedbackController extends AbstractSubController { private final static Logger logger = LoggerFactory.getLogger(FeedbackController.class); + private final static Pattern feelingsPattern = Pattern.compile("\nFeelings: .*"); + + private @FXML Button sendAnswerBtn; private @FXML TextArea commentArea; + private @FXML Label fixedFeedbackContent; private @FXML Label thanksLabel; - + private @FXML Label sendPrecision; private Button selectedFeelings; private final static String SELECTED_STYLE="selected-feelings"; @@ -62,6 +71,7 @@ public class FeedbackController extends AbstractSubController { logger.warn("setParentController(), parentController.getDevice() == null"); } commentArea.setWrapText(true); + prefillCommentArea(); } @@ -86,6 +96,7 @@ public class FeedbackController extends AbstractSubController { selectedFeelings = clickedButton; logger.debug("onFeelingsSelected(), select: {}", selectedFeelings.getId()); } + updateFeelingInText(); } /** @@ -101,6 +112,8 @@ public class FeedbackController extends AbstractSubController { if( (Boolean) eh.getSource().getValue() ){ //if success sendAnswerBtn.setManaged(false); sendAnswerBtn.setVisible(false); + sendPrecision.setManaged(false); + sendPrecision.setVisible(false); thanksLabel.setVisible(true); thanksLabel.setManaged(true); logger.debug("onSendBtnClicked(), sending feedback: success"); @@ -123,6 +136,44 @@ public class FeedbackController extends AbstractSubController { } + /** + * Prefill CommentArea with data + */ + private void prefillCommentArea(){ + StringBuffer sb = new StringBuffer(); + String time = LocalDateTime.now().withNano(0).toString(); + + sb.append("Timestamp: "+time.replace("T", " ")) + .append("\nDevice model: "+this.deviceModel) + .append("\nOS name: "+AppConstants.OsName) + .append("\nEasy-Installer version: "+AppConstants.APP_VERSION) + .append("\nFeelings: "); + if(selectedFeelings != null){ + sb.append(selectedFeelings.getId()); + }else{ + sb.append("not selected"); + } + commentArea.setText("Comment: \n"); + fixedFeedbackContent.setText(sb.toString()); + } + + /** + * Replace the feelings value in the commentArea + */ + private void updateFeelingInText(){ + logger.debug("update Feeling in text"); + final String content = fixedFeedbackContent.getText(); + + String feelings; + if(selectedFeelings != null) feelings = selectedFeelings.getId(); + else feelings = "not selected"; + logger.debug("contain: "+feelingsPattern.matcher(content).find()); + + final String newContent= feelingsPattern.matcher(content).replaceFirst("\nFeelings: "+feelings); + fixedFeedbackContent.setText(newContent); + } + + /** * Create the file with feedback inside * @return @@ -131,14 +182,10 @@ public class FeedbackController extends AbstractSubController { String answerFilePath = AppConstants.getWritableFolder()+"feedback-"+UUID.randomUUID()+".txt"; try(PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(answerFilePath, true)))) { - out.write("Timestamp: "+System.currentTimeMillis()); - out.write("\nDevice model: "+this.deviceModel); - out.write("\nOS name: "+AppConstants.OsName); - if(selectedFeelings != null){ - out.write("\nFeelings: "+selectedFeelings.getId()); - } - out.write("\nComment: \n"+this.commentArea.getText()); + out.write(fixedFeedbackContent.getText()+"\n"); + out.write(commentArea.getText()); + out.close(); } catch (IOException e) { logger.error("createAnswerFile()\n answerFilePath = {}\n error: {}", answerFilePath, e.toString()); return null; diff --git a/src/main/resources/css/style.css b/src/main/resources/css/style.css index 2be2fb63f58b757fe0ba8ca05031c9805281a8ed..28f64fd6c00ccde32a1b1c090dfa9baa381a4fa2 100644 --- a/src/main/resources/css/style.css +++ b/src/main/resources/css/style.css @@ -60,6 +60,7 @@ Button { -fx-background-color: #1789E9; -fx-text-fill: white; -fx-font-size: 1.1em; + -fx-padding: 0 18 0 18; } Button:hover{ @@ -187,3 +188,7 @@ Button:pressed{ -fx-border-width: 3px; -fx-border-radius: 80; } + +#fixedFeedbackContent{ + -fx-text-fill: #505050; +} diff --git a/src/main/resources/fxml/9-feedback.fxml b/src/main/resources/fxml/9-feedback.fxml index 42a02d11305c6d35f26e42bfe4d9b43eee1eee65..b569bf4ff07f89400d23fbe0842dbe5fe4ab0755 100644 --- a/src/main/resources/fxml/9-feedback.fxml +++ b/src/main/resources/fxml/9-feedback.fxml @@ -84,8 +84,14 @@