Commit 3eb3e53a authored by Martins Berzins's avatar Martins Berzins
Browse files

eeeee

parents f1d4ecb3 adad28e1
package com.example.calendar.controller;
import java.util.Arrays;
import java.util.EnumSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import com.example.calendar.models.Event;
import com.example.calendar.models.EventType;
import com.example.calendar.repo.EventRepo;
import java.util.List;
@Controller
public class eventController {
@Autowired
EventRepo eventRepo;
@GetMapping(value = "/addNewEvent")
public String addNewEventGet(Model models, Event event)
{
//TODO Var pievienot, ka default date radaas shodienas datums, lidzigi ar laiku.
List<EventType> allEventTypes = Arrays.asList(EventType.values());
models.addAttribute("eventTypes", allEventTypes);
return "addNewEvent";
}
@PostMapping(value = "/addNewEvent")
public String addNewEventPost(Event event)
{
//TODO japievieno events konkretajam calendaram kuraa ir user
System.out.println(event);
eventRepo.save(event);
return "redirect:/ok";
}
}
......@@ -12,6 +12,8 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.springframework.format.annotation.DateTimeFormat;
@Entity
@Table(name = "EventTable")
public class Event {
......@@ -20,8 +22,12 @@ public class Event {
private String name;
@Column(name = "Description")
private String description;
@DateTimeFormat(pattern = "yyyy-MM-dd")
@Column(name = "StartDate")
private LocalDate startDate;
@DateTimeFormat(pattern = "HH:mm")
@Column(name = "StartTime")
private LocalTime startTime;
@Id
......@@ -44,7 +50,7 @@ public class Event {
setDescription(description);
setStartDate(startDate);
setStartTime(startTime);
setAllDayEvent(isAllDayEvent);
setIsAllDayEvent(isAllDayEvent);
this.eventType = eventType;
}
......@@ -54,7 +60,7 @@ public class Event {
setDescription(description);
setStartDate(startDate);
setStartTime(startTime);
setAllDayEvent(isAllDayEvent);
setIsAllDayEvent(isAllDayEvent);
}
//Constructor no description
......@@ -63,7 +69,7 @@ public class Event {
setName(name);
setStartDate(startDate);
setStartTime(startTime);
setAllDayEvent(isAllDayEvent);
setIsAllDayEvent(isAllDayEvent);
}
//Constructor no description or eventType
......@@ -71,7 +77,7 @@ public class Event {
setName(name);
setStartDate(startDate);
setStartTime(startTime);
setAllDayEvent(isAllDayEvent);
setIsAllDayEvent(isAllDayEvent);
}
......@@ -131,11 +137,11 @@ public class Event {
this.eventType = eventType;
}
public boolean isAllDayEvent() {
public boolean getIsAllDayEvent() {
return isAllDayEvent;
}
public void setAllDayEvent(boolean isAllDayEvent) {
public void setIsAllDayEvent(boolean isAllDayEvent) {
this.isAllDayEvent = isAllDayEvent;
}
......
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Add new Event</title>
</head>
<h2>Add New Event</h2>
<body>
<form action="#" th:action="@{addNewEvent}" th:object="${event}" method="post">
<table>
<tr>
<td>Title:</td>
<td><input type="text" th:field="*{name}" /></td>
</tr>
<tr>
<td>Description:</td>
<td><input type="text" th:field="*{description}" /></td>
</tr>
<tr>
<td><input type="checkbox" th:field="*{isAllDayEvent}" value = "allDay" /></td>
<td><label for="allDay">All day event?</label></td>
</tr>
<tr>
<td>Date:</td>
<td> <input type="date" th:field="*{startDate}" /></td>
</tr>
<tr>
<td>Time:</td>
<td> <input type="time" th:field="*{startTime}" /></td>
</tr>
<tr>
<td>
<select th:field = "*{eventType}">
<option th:each="eTemp : ${eventTypes}"
th:value="${eTemp}"
th:text="${eTemp}">
</option>
</select>
</td>
</tr>
<tr>
<td><button type="submit">Submit</button></td>
</tr>
</table>
</form>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment