From dee088ec237e9f141996c241b802b97b90fbe630 Mon Sep 17 00:00:00 2001 From: kristiana-16 Date: Wed, 20 May 2020 11:56:56 +0200 Subject: [PATCH] LANG_007a Basic Implementation of Testing Mode [SF,WK] --- .../project/controller/MVCController.java | 133 +++++++++++++++++- src/main/resources/messages.properties | 1 + src/main/resources/messages_de.properties | 1 + src/main/resources/messages_en.properties | 1 + src/main/resources/messages_fr.properties | 1 + src/main/resources/templates/index.html | 39 ++--- src/main/resources/templates/user/index.html | 45 +++--- .../templates/user/test/testingmode.html | 83 +++++++++++ .../user/test/testingmode_e_to_g.html | 56 ++++++++ .../user/test/testingmode_g_to_e.html | 65 +++++++++ .../user/test/testingmode_repetition.html | 62 ++++++++ .../user/test/testingmode_result_english.html | 83 +++++++++++ .../user/test/testingmode_result_german.html | 85 +++++++++++ 13 files changed, 611 insertions(+), 44 deletions(-) create mode 100644 src/main/resources/templates/user/test/testingmode.html create mode 100644 src/main/resources/templates/user/test/testingmode_e_to_g.html create mode 100644 src/main/resources/templates/user/test/testingmode_g_to_e.html create mode 100644 src/main/resources/templates/user/test/testingmode_repetition.html create mode 100644 src/main/resources/templates/user/test/testingmode_result_english.html create mode 100644 src/main/resources/templates/user/test/testingmode_result_german.html diff --git a/src/main/java/com/vocabularytrainer/project/controller/MVCController.java b/src/main/java/com/vocabularytrainer/project/controller/MVCController.java index f8be0f5..6d2c3a8 100644 --- a/src/main/java/com/vocabularytrainer/project/controller/MVCController.java +++ b/src/main/java/com/vocabularytrainer/project/controller/MVCController.java @@ -19,19 +19,21 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletRequest; +import java.util.Collections; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Arrays; import java.util.List; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + @Controller public class MVCController { @@ -42,6 +44,8 @@ public MVCController(VocabularyRepository vocabularyRepository) { this.vocabularyRepository = vocabularyRepository; } + private List testingdata; + /* Welcome Page */ @GetMapping("/") public String root() { @@ -323,6 +327,127 @@ public String getFrenchPage() { return "user/?lang=fr"; } + //Testing Mode + @GetMapping("/user/test") + public String userTest(Model model) { + + return "user/test/testingmode"; + + } + + @GetMapping("/user/testinggerman") + public String userTestingGerman(Model model, @RequestParam("amountg") int amountg) { + + //model.addAttribute("amount", userTest.getElementById("amountg")); + // tell the thymeleaf which user is logged in + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + UserDetails userDetails = (UserDetails) authentication.getPrincipal(); + + model.addAttribute("current_user", userDetails.getUsername()); + + // give x vocabulary + testingdata = this.vocabularyRepository.showAllVocabularyFromUserX(userDetails.getUsername()); + Collections.shuffle(testingdata); + + if(amountg < testingdata.size()) + { + testingdata = testingdata.subList(0, amountg); + } + + model.addAttribute("overview", testingdata); + + return "user/test/testingmode_e_to_g"; + } + + /*@RequestMapping("/user/g_result") + public String getURLValue(HttpServletRequest request) { + String test = request.getRequestURI(); + return test; + }*/ + + @GetMapping("/user/testingenglish") + public String userTestingEnglish(Model model, @RequestParam("amounte") int amounte) { + + + //model.getAttribute("amount", userTest("${amounte}")); + // tell the thymeleaf which user is logged in + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + UserDetails userDetails = (UserDetails) authentication.getPrincipal(); + + model.addAttribute("current_user", userDetails.getUsername()); + + // give x vocabulary + testingdata = this.vocabularyRepository.showAllVocabularyFromUserX(userDetails.getUsername()); + Collections.shuffle(testingdata); + + if(amounte < testingdata.size()) { + testingdata = testingdata.subList(0, amounte); + } + + model.addAttribute("overview", testingdata); + return "user/test/testingmode_g_to_e"; + } + + @RequestMapping(value = "/user/g_result/{result}", method = RequestMethod.GET) + @ResponseBody + public String getFoosBySimplePathWithPathVariable( + @PathVariable("result") char result) { + System.out.println(result); + return "Get a specific Foo with id=" + result; + } + + @GetMapping("/user/g_result") + public String userTestResultGerman(Model model) { + + // tell the thymeleaf which user is logged in + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + UserDetails userDetails = (UserDetails) authentication.getPrincipal(); + + //model.addAttribute("current_user", userDetails.getUsername()); + + // get the Query to show current vocabulary entries of user x + + //System.out.println(input); + + //testingdata = testingdata.subList(); + + model.addAttribute("overview", testingdata); + + return "user/test/testingmode_result_german"; + } + + @GetMapping("/user/e_result") + public String userTestResultEnglish(Model model) { + + // tell the thymeleaf which user is logged in + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + UserDetails userDetails = (UserDetails) authentication.getPrincipal(); + + model.addAttribute("current_user", userDetails.getUsername()); + + // get the Query to show current vocabulary entries of user x + + model.addAttribute("overview", testingdata); + + return "user/test/testingmode_result_english"; + } + + @GetMapping("/user/repetition") + public String userTestRepetition(Model model) { + + // tell the thymeleaf which user is logged in + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + UserDetails userDetails = (UserDetails) authentication.getPrincipal(); + + model.addAttribute("current_user", userDetails.getUsername()); + + // get the Query to show current vocabulary entries of user x + + model.addAttribute("overview", testingdata); + return "user/test/testingmode_repetition"; + } + + /* Export and Download vocabularies as CSV */ @GetMapping("user/export_vocabularies") public ResponseEntity export() diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index be9811d..b6076d8 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -23,6 +23,7 @@ tag=Tag add=Add New Vocabulary edit_voc=Edit Vocabulary studyinterface=Study Interface +testingmode=Testing Mode logout=Logout #edit_vocab diff --git a/src/main/resources/messages_de.properties b/src/main/resources/messages_de.properties index 876691b..b5e96c1 100644 --- a/src/main/resources/messages_de.properties +++ b/src/main/resources/messages_de.properties @@ -23,6 +23,7 @@ tag=Taggen add=Neue Vokabel hinzufügen edit_voc=Vokabel bearbeiten studyinterface=Lernumgebung +testingmode=Testmodus logout=Ausloggen #edit_vocab diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index be9811d..b6076d8 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -23,6 +23,7 @@ tag=Tag add=Add New Vocabulary edit_voc=Edit Vocabulary studyinterface=Study Interface +testingmode=Testing Mode logout=Logout #edit_vocab diff --git a/src/main/resources/messages_fr.properties b/src/main/resources/messages_fr.properties index 7569071..3460197 100644 --- a/src/main/resources/messages_fr.properties +++ b/src/main/resources/messages_fr.properties @@ -23,6 +23,7 @@ tag=Étiquette add=Ajouter un nouveau vocabulaire edit_voc=Modifier le vocabulaire studyinterface=Environnement d'apprentissage +testingmode=Mode de test logout=Se déconnecter #edit_vocab diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 49a9196..913f65b 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -16,29 +16,30 @@ +
+ +
+ + + -
- -
- -
diff --git a/src/main/resources/templates/user/index.html b/src/main/resources/templates/user/index.html index 43c0a0d..7144e0b 100644 --- a/src/main/resources/templates/user/index.html +++ b/src/main/resources/templates/user/index.html @@ -43,6 +43,27 @@ } +
+ +
+ + + + @@ -62,6 +83,9 @@ + @@ -85,27 +109,6 @@

-
- -
- - - -

diff --git a/src/main/resources/templates/user/test/testingmode.html b/src/main/resources/templates/user/test/testingmode.html new file mode 100644 index 0000000..d2ccdbc --- /dev/null +++ b/src/main/resources/templates/user/test/testingmode.html @@ -0,0 +1,83 @@ + + + + + TestingMode + + + + + + + + + + + + + + +
+ +
Testing mode
+ +

Please enter the amount of vocabulary you want to check:

+
+ + +
+ +
+ +
+ + + +
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/user/test/testingmode_e_to_g.html b/src/main/resources/templates/user/test/testingmode_e_to_g.html new file mode 100644 index 0000000..1ad4661 --- /dev/null +++ b/src/main/resources/templates/user/test/testingmode_e_to_g.html @@ -0,0 +1,56 @@ + + + + + TestingMode + + + + + + + + + + + + + + + +
+ + +
Testing mode - German

+ +
+
+ + + + + + + + + + + + +
+ English words: + + Please enter German translation here: +
+ + + +
+ +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/user/test/testingmode_g_to_e.html b/src/main/resources/templates/user/test/testingmode_g_to_e.html new file mode 100644 index 0000000..f607bda --- /dev/null +++ b/src/main/resources/templates/user/test/testingmode_g_to_e.html @@ -0,0 +1,65 @@ + + + + + TestingMode + + + + + + + + + + + + + + + +
+ +
Testing mode - English
+ +
+ + + + + +
+ + + + + + + + + + + +
+ English words: + + Please enter German translation here: +
+ + + +
+ +
+ + +
+ +
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/user/test/testingmode_repetition.html b/src/main/resources/templates/user/test/testingmode_repetition.html new file mode 100644 index 0000000..e103ce5 --- /dev/null +++ b/src/main/resources/templates/user/test/testingmode_repetition.html @@ -0,0 +1,62 @@ + + + + + TestingMode + + + + + + + + + + + + + + + + + + + + + + +
+ + +
Repetition

+ +
+
+ + + + + + + + + + + +
+ English words: + + Please enter German translation here: +
+ + + +
+ +
+
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/user/test/testingmode_result_english.html b/src/main/resources/templates/user/test/testingmode_result_english.html new file mode 100644 index 0000000..4b51cf5 --- /dev/null +++ b/src/main/resources/templates/user/test/testingmode_result_english.html @@ -0,0 +1,83 @@ + + + + + TestingMode + + + + + + + + + + + + + + + + + + + + + + +
+ +

Result English:

+ + +

Overview of tested vocabulary:

+
+ + + + + + + + + + + + +
German VocabularyEnglish Translation
+
+ +
+ +
+ Testing Mode
+ Back to overview + +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/user/test/testingmode_result_german.html b/src/main/resources/templates/user/test/testingmode_result_german.html new file mode 100644 index 0000000..06253f7 --- /dev/null +++ b/src/main/resources/templates/user/test/testingmode_result_german.html @@ -0,0 +1,85 @@ + + + + + TestingMode + + + + + + + + + + + + + + + + + + + + + + +
+ +

Result German:

+ + +

Overview of tested vocabulary:

+
+ + + + + + + + + + + + + +
English VocabularyGerman Translation
+
+
+ +
+ + Testing Mode
+ Back to overview + + +
+ + \ No newline at end of file