Skip to content

Commit

Permalink
LANG_007a Basic Implementation of Testing Mode [SF,WK]
Browse files Browse the repository at this point in the history
  • Loading branch information
kristiana-16 committed May 20, 2020
1 parent 0b44b48 commit dee088e
Show file tree
Hide file tree
Showing 13 changed files with 611 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -42,6 +44,8 @@ public MVCController(VocabularyRepository vocabularyRepository) {
this.vocabularyRepository = vocabularyRepository;
}

private List<VocabularyEntries> testingdata;

/* Welcome Page */
@GetMapping("/")
public String root() {
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ tag=Tag
add=Add New Vocabulary
edit_voc=Edit Vocabulary
studyinterface=Study Interface
testingmode=Testing Mode
logout=Logout

#edit_vocab
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ tag=Taggen
add=Neue Vokabel hinzufügen
edit_voc=Vokabel bearbeiten
studyinterface=Lernumgebung
testingmode=Testmodus
logout=Ausloggen

#edit_vocab
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ tag=Tag
add=Add New Vocabulary
edit_voc=Edit Vocabulary
studyinterface=Study Interface
testingmode=Testing Mode
logout=Logout

#edit_vocab
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 20 additions & 19 deletions src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,30 @@
<style>
body { text-align: center; margin-top: 50px;}
</style>
<div align="right">
<select id="locales">
<option value=""></option>
<option value="de" th:text="#{lang.de}"></option>
<option value="en" th:text="#{lang.eng}"></option>
<option value="fr" th:text="#{lang.fr}"></option>
</select>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#locales").change(function () {
var selectedOption = $('#locales').val();
if (selectedOption != ''){
window.location.replace('/?lang=' + selectedOption);
}
});
});
</script>

</head>
<body>
<div align="right">
<select id="locales">
<option value=""></option>
<option value="de" th:text="#{lang.de}"></option>
<option value="en" th:text="#{lang.eng}"></option>
<option value="fr" th:text="#{lang.fr}"></option>
</select>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#locales").change(function () {
var selectedOption = $('#locales').val();
if (selectedOption != ''){
window.location.replace('/?lang=' + selectedOption);
}
});
});
</script>

<div th:remove="tag">

Expand Down
45 changes: 24 additions & 21 deletions src/main/resources/templates/user/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@
}
</style>

<div align="right">
<select id="locales">
<option value=""></option>
<option value="de" th:text="#{lang.de}"></option>
<option value="en" th:text="#{lang.eng}"></option>
<option value="fr" th:text="#{lang.fr}"></option>
</select>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#locales").change(function () {
var selectedOption = $('#locales').val();
if (selectedOption != ''){
window.location.replace('/user/?lang=' + selectedOption);
}
});
});
</script>

</head>
<body>

Expand All @@ -62,6 +83,9 @@
<li class="nav-item">
<a class="nav-link" href="/user/studyInterface"><span th:text="#{studyinterface}"></span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/user/test"><span th:text="#{testingmode}"></span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/user/addvoc"><span th:text="#{add}"></span></a>
</li>
Expand All @@ -85,27 +109,6 @@
<h1 style="display: inline" th:text="#{greeting}"> </h1>
<h1 style="display: inline; color: lightpink; font-weight: bold" th:text="${current_user}"></h1>

<div align="right">
<select id="locales">
<option value=""></option>
<option value="de" th:text="#{lang.de}"></option>
<option value="en" th:text="#{lang.eng}"></option>
<option value="fr" th:text="#{lang.fr}"></option>
</select>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#locales").change(function () {
var selectedOption = $('#locales').val();
if (selectedOption != ''){
window.location.replace('/user/?lang=' + selectedOption);
}
});
});
</script>

<br>
<br>

Expand Down
83 changes: 83 additions & 0 deletions src/main/resources/templates/user/test/testingmode.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>TestingMode</title>

<!-- Bootstrap -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">

<!-- Bootstrap Script Dependencies -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>

<!-- Some Custom Style -->
<style>
body { text-align: center; margin-top: 50px;}
</style>

</head>
<body>
<div th:remove="tag">

<h5>Testing mode</h5>

<p>Please enter the amount of vocabulary you want to check:</p>
<form method="get" action="/user/testinggerman">
<select th:id="amountg" th:name="amountg">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10" selected>10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
<option value="35">35</option>
<option value="40">40</option>
<option value="45">45</option>
<option value="50">50</option>
<option value="75">75</option>
<option value="100">100</option>
</select>
<input type="submit" value="English to German">
</form>

</br>

<form method="get" action="/user/testingenglish">
<select th:id="amounte" th:name="amounte">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10" selected>10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
<option value="35">35</option>
<option value="40">40</option>
<option value="45">45</option>
<option value="50">50</option>
<option value="75">75</option>
<option value="100">100</option>
</select>

<input type="submit" value="German to English">
</form>
</div>
</body>
</html>
Loading

0 comments on commit dee088e

Please sign in to comment.