Commit f44d5662 authored by s7_spruge_k's avatar s7_spruge_k
Browse files

user has stats field + updated controller

parent a855dd72
......@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import com.example.calendar.models.Calendar;
import com.example.calendar.models.Event;
import com.example.calendar.models.StatHelper2;
import com.example.calendar.helpers.StatHelper;
import com.example.calendar.models.User;
import com.example.calendar.repo.CalendarRepo;
......@@ -125,7 +126,7 @@ public class GraphController {
@GetMapping(value = "/choose-cal")
public String chooseCalGet(Model model, StatHelper statHelper, String calName)
public String chooseCalGet(Model model, StatHelper2 statHelper, String calName)
{
User currUser = findCurrentUser();
......@@ -151,15 +152,39 @@ public class GraphController {
calendarJson.addProperty("title", allUserCalendars.get(i).getName());
calendarArray.add(calendarJson);
}
ArrayList<String> graphTypes = new ArrayList<>();
graphTypes.add("bar");
graphTypes.add("doughnut");
graphTypes.add("column");
graphTypes.add("line");
ArrayList<String> analysisTypes = new ArrayList<>();
analysisTypes.add("Analysis by day");
analysisTypes.add("Analysis by month");
model.addAttribute("analysisTypes", analysisTypes);
model.addAttribute("graphTypes", graphTypes);
model.addAttribute("calendarList", calendarArray);
return "chooseCal";
}
@PostMapping(value ="/choose-cal")
public String chooseCalPost(Model models, StatHelper statHelper, String calName)
public String chooseCalPost(Model models, StatHelper2 statHelper, String calName)
{
statHelper.setChosenCalendar(calName);
System.out.println(statHelper);
User currUser = findCurrentUser();
currUser.setStats(statHelper);
userRepo.save(currUser);
System.out.println(currUser.getStats());
return "redirect:/stat";
}
......
package com.example.calendar.models;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@Entity
@Table(name = "statTable")
public class StatHelper2 {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID_st")
private int stat_ID;
@Column(name = "Calendar")
private String chosenCalendar;
@Column(name = "analysisType")
private String analysisType;
@Column(name = "graphType")
private String graphType;
@OneToOne
@JoinColumn(name = "currUser")
private User currUser;
public StatHelper2() {}
public StatHelper2(String chosenCalendar, String analysisType, String graphType) {
super();
this.chosenCalendar = chosenCalendar;
this.analysisType = analysisType;
this.graphType = graphType;
}
public String getChosenCalendar() {
return chosenCalendar;
}
public void setChosenCalendar(String chosenCalendar) {
this.chosenCalendar = chosenCalendar;
}
public String getAnalysisType() {
return analysisType;
}
public void setAnalysisType(String analysisType) {
this.analysisType = analysisType;
}
public String getGraphType() {
return graphType;
}
public void setGraphType(String graphType) {
this.graphType = graphType;
}
@Override
public String toString() {
return "StatHelper [chosenCalendar=" + chosenCalendar + ", analysisType=" + analysisType + ", graphType="
+ graphType + "]";
}
}
......@@ -10,8 +10,10 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.springframework.data.annotation.Transient;
......@@ -42,6 +44,9 @@ public class User {
@Column(name = "activeCalendar")
private String activeCalendar = "";
@OneToOne(mappedBy = "currUser",cascade = {CascadeType.ALL})
private StatHelper2 stats;
public User() {
}
......@@ -112,6 +117,17 @@ public class User {
this.activeCalendar = activeCalendar;
}
public StatHelper2 getStats() {
return stats;
}
public void setStats(StatHelper2 stats) {
this.stats = stats;
}
@Override
public String toString() {
return "ID= " + user_ID +" " +username + " password=" + password + "activeCal: " + activeCalendar;
......
......@@ -13,7 +13,7 @@
<div class="container w-50 ">
<br><br><br> <form action="#" th:action="@{/choose-cal}" th:object="${statHelper}" method="post">
<br><br><br> <form action="#" th:action="@{/choose-cal}" th:object="${statHelper2}" method="post">
<h2 class="form-signin-heading text-center">Your calendars</h2><br>
<div class="form-group">
......@@ -23,7 +23,23 @@
</div>
<div class="form-group">
</div>
<select th:field="*{analysisType}">
<option
th:each="dropdownValue: ${analysisTypes}"
th:value="${dropdownValue}"
th:text="${dropdownValue}" ></option>
</select>
<ul>
<li th:each="radioValue: ${graphTypes}">
<input type="radio"
th:field="*{graphType}"
th:value="${radioValue}" />
<label
th:for="${#ids.prev('graphType')}"
th:text="${radioValue}"></label>
</li>
</ul>
<br> <button class="btn btn-lg btn-primary btn-block" type="submit">Generate statistics!</button><br>
</form>
......
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