mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add removal of CustomCatalogEntry inside catalog via button
This commit is contained in:
parent
5bcfefe734
commit
bde2754a51
|
@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -30,14 +31,22 @@ public class CatalogController {
|
||||||
@GetMapping("/catalog_editor")
|
@GetMapping("/catalog_editor")
|
||||||
public String catalog_configuration(Model model) {
|
public String catalog_configuration(Model model) {
|
||||||
model.addAttribute("inventory", inventory);
|
model.addAttribute("inventory", inventory);
|
||||||
model.addAttribute("formCatalogEntry", new CustomCatalogEntry());
|
model.addAttribute("formCatalogEntry", new CustomCatalogEntry(
|
||||||
|
CustomCatalogEntry.EventType.EVENT_CATERING,
|
||||||
|
new HashMap<String, Integer>(),
|
||||||
|
0,
|
||||||
|
0));
|
||||||
return "catalog_editor";
|
return "catalog_editor";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/catalog_editor/catalog_add")
|
@PostMapping("/catalog_editor/catalog_add")
|
||||||
public String catalog_add(@ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) {
|
public String catalog_add(Model model) {
|
||||||
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(
|
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(
|
||||||
// TODO: Fill with formCatalogEntry's data
|
// TODO: Fill with formCatalogEntry's data instead of dummy data
|
||||||
|
CustomCatalogEntry.EventType.EVENT_CATERING,
|
||||||
|
new HashMap<String, Integer>(),
|
||||||
|
0,
|
||||||
|
0
|
||||||
));
|
));
|
||||||
return "redirect:/catalog";
|
return "redirect:/catalog";
|
||||||
}
|
}
|
||||||
|
@ -46,7 +55,7 @@ public class CatalogController {
|
||||||
@PostMapping("/catalog/remove")
|
@PostMapping("/catalog/remove")
|
||||||
public String removeEntry(@RequestParam int catalogEntryID) {
|
public String removeEntry(@RequestParam int catalogEntryID) {
|
||||||
catalogEntryRepository.removeCatalogEntry(catalogEntryID);
|
catalogEntryRepository.removeCatalogEntry(catalogEntryID);
|
||||||
return "catalog_editor";
|
return "redirect:/catalog";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/catalog_editor/product_add")
|
@PostMapping("/catalog_editor/product_add")
|
||||||
|
@ -70,10 +79,11 @@ public class CatalogController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/catalog_editor/add_time")
|
@PostMapping("/catalog_editor/add_time")
|
||||||
public String add_time(@ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) {
|
public String add_time(@RequestParam int minimumTimePeriod, @ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) {
|
||||||
System.out.println(formCatalogEntry.getMinimumTimePeriod());
|
System.out.println(minimumTimePeriod);
|
||||||
model.addAttribute("formCatalogEntry", formCatalogEntry);
|
/*System.out.println(formCatalogEntry.getMinimumTimePeriod());
|
||||||
// Might not work because on every GetMapping of /catalog_editor a new formCatalogEntry is created
|
model.addAttribute("formCatalogEntry", formCatalogEntry);*/
|
||||||
|
// TODO: Might not work because on every GetMapping of /catalog_editor a new formCatalogEntry is created
|
||||||
return "redirect:/catalog_editor";
|
return "redirect:/catalog_editor";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,13 +11,13 @@ public class CustomCatalogEntry {
|
||||||
private int minimumTimePeriod; // Declared as int for simplification of the prototype. Only whole hours.
|
private int minimumTimePeriod; // Declared as int for simplification of the prototype. Only whole hours.
|
||||||
private int totalCost; // Should actually accumulate the price of all items.
|
private int totalCost; // Should actually accumulate the price of all items.
|
||||||
|
|
||||||
public CustomCatalogEntry() {
|
public CustomCatalogEntry(EventType eventType, Map<String, Integer> products, int minimumTimePeriod, int totalCost) {
|
||||||
this.id = idCounter;
|
this.id = idCounter;
|
||||||
idCounter++;
|
idCounter++;
|
||||||
this.eventType = EventType.EVENT_CATERING;
|
this.eventType = eventType;
|
||||||
this.products = new HashMap<String, Integer>();
|
this.products = products;
|
||||||
this.minimumTimePeriod = 5;
|
this.minimumTimePeriod = minimumTimePeriod;
|
||||||
this.totalCost = 3;
|
this.totalCost = totalCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
@ -44,6 +44,9 @@ public class CustomCatalogEntry {
|
||||||
this.eventType = eventType;
|
this.eventType = eventType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setProducts(Map<String, Integer> products) {
|
||||||
|
this.products = products;
|
||||||
|
}
|
||||||
public void setMinimumTimePeriod(int timePeriod) {
|
public void setMinimumTimePeriod(int timePeriod) {
|
||||||
this.minimumTimePeriod = timePeriod;
|
this.minimumTimePeriod = timePeriod;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ public class CustomCatalogEntryDataInitializer implements DataInitializer {
|
||||||
Map<String, Integer> products = new HashMap<>();
|
Map<String, Integer> products = new HashMap<>();
|
||||||
products.put("Brötchen", 30);
|
products.put("Brötchen", 30);
|
||||||
products.put("Kerze", 20);
|
products.put("Kerze", 20);
|
||||||
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry());
|
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(CustomCatalogEntry.EventType.EVENT_CATERING, products, 4, 500));
|
||||||
|
|
||||||
products = new HashMap<>();
|
products = new HashMap<>();
|
||||||
products.put("Kuchen", 3);
|
products.put("Kuchen", 3);
|
||||||
|
@ -28,6 +28,6 @@ public class CustomCatalogEntryDataInitializer implements DataInitializer {
|
||||||
products.put("Pizza Margherita", 1);
|
products.put("Pizza Margherita", 1);
|
||||||
products.put("Pizza Quattro Formaggi", 1);
|
products.put("Pizza Quattro Formaggi", 1);
|
||||||
products.put("Ballon", 20);
|
products.put("Ballon", 20);
|
||||||
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry());
|
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(CustomCatalogEntry.EventType.PARTY_SERVICE, products, 2, 1000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
<td>
|
<td>
|
||||||
**BILD**
|
**BILD**
|
||||||
</td>
|
</td>
|
||||||
|
<td th:text="${catalogEntry.getId()}">
|
||||||
<td th:text="${catalogEntry.getEventType()}">
|
<td th:text="${catalogEntry.getEventType()}">
|
||||||
<td th:text="${catalogEntry.getMinimumTimePeriod()}">h
|
<td th:text="${catalogEntry.getMinimumTimePeriod()}">h
|
||||||
<td>
|
<td>
|
||||||
|
@ -41,6 +42,12 @@
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td th:text="${catalogEntry.getTotalCost()}">
|
<td th:text="${catalogEntry.getTotalCost()}">
|
||||||
|
<td>
|
||||||
|
<form method="post" th:action="@{/catalog/remove}">
|
||||||
|
<input type="hidden" name="catalogEntryID" th:value="${catalogEntry.getId()}">
|
||||||
|
<button type="submit">Entfernen</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -57,6 +64,12 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<form th:action="@{/catalog_editor}">
|
||||||
|
<button type="submit">Hinzufügen</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<button type="button">Hinzufügen</button>
|
<button type="button">Hinzufügen</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -70,4 +83,3 @@
|
||||||
</p>
|
</p>
|
||||||
</footer>
|
</footer>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<h1>Basisevent konfigurieren</h1>
|
<h1>Basisevent konfigurieren</h1>
|
||||||
<input type="hidden" name="addCatalog">
|
<input type="hidden" name="addCatalog">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<h2>Dienstleistung</h2>
|
<h2>Dienstleistung</h2>
|
||||||
<label for="dienstleistungen"></label>
|
<label for="dienstleistungen"></label>
|
||||||
<select name="dienstleistungen" id="dienstleistungen">
|
<select name="dienstleistungen" id="dienstleistungen">
|
||||||
<option value="eventcatering">Eventcatering</option>
|
<option value="eventcatering">Eventcatering</option>
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
<h2>Mindestzeitraum</h2>
|
<h2>Mindestzeitraum</h2>
|
||||||
<form th:object="${formCatalogEntry}" method="post" th:action="@{/catalog_editor/add_time}">
|
<form th:object="${formCatalogEntry}" method="post" th:action="@{/catalog_editor/add_time}">
|
||||||
<label>Mindestzeitraum:</label>
|
<label>Mindestzeitraum:</label>
|
||||||
<input th:field="*{minimumTimePeriod}" type="number" min="1" step="1" value="1"/>
|
<input th:field="*{minimumTimePeriod}" type="number" min="0" step="1" value="1"/>
|
||||||
<button type="submit">Zum Model hinzufügen</button>
|
<button type="submit">Zum Model hinzufügen</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@ -46,8 +46,6 @@
|
||||||
<th>Stückpreis</th>
|
<th>Stückpreis</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr th:each="item : ${inventory}">
|
<tr th:each="item : ${inventory}">
|
||||||
<td th:text="${item}">
|
|
||||||
<td th:text="${item.getItemId()}">
|
|
||||||
<td th:text="${item.getName()}">
|
<td th:text="${item.getName()}">
|
||||||
<td th:text="${item.getAmount()}">
|
<td th:text="${item.getAmount()}">
|
||||||
<td th:text="${item.getCost()}"> €
|
<td th:text="${item.getCost()}"> €
|
||||||
|
@ -58,6 +56,8 @@
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</table>
|
</table>
|
||||||
|
<hr>
|
||||||
|
<div style="height: 20px;"></div>
|
||||||
<form method="post" th:action="@{/catalog_editor/product_add}">
|
<form method="post" th:action="@{/catalog_editor/product_add}">
|
||||||
<label for="name">Produktname</label>
|
<label for="name">Produktname</label>
|
||||||
<input type="text" id="name" name="name" required>
|
<input type="text" id="name" name="name" required>
|
||||||
|
|
Loading…
Reference in a new issue