Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
s7_spruge_k
calendar
Commits
b5d311f0
Commit
b5d311f0
authored
Jun 18, 2019
by
s7_spruge_k
Browse files
basic month graphs
parent
aa082b64
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
143 additions
and
6 deletions
+143
-6
src/main/java/com/example/calendar/controller/GraphController.java
...java/com/example/calendar/controller/GraphController.java
+78
-2
src/main/resources/templates/statsTest.html
src/main/resources/templates/statsTest.html
+56
-4
src/main/resources/templates/statsTest2.html
src/main/resources/templates/statsTest2.html
+9
-0
No files found.
src/main/java/com/example/calendar/controller/GraphController.java
View file @
b5d311f0
package
com.example.calendar.controller
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -173,9 +174,84 @@ public class GraphController {
public
String
chooseCalPost
(
Model
models
,
StatHelper
statHelper
,
String
calName
)
{
statHelper
.
setChosenCalendar
(
calName
);
System
.
out
.
println
(
statHelper
);
models
.
addAttribute
(
"statHelper"
,
statHelper
);
User
currUser
=
findCurrentUser
();
try
{
calendarRepo
.
findAllByUser
(
currUser
);
}
catch
(
Exception
e
)
{
return
"redirect:/add-new-calendar"
;
}
Calendar
chosenCalendar
=
calendarRepo
.
findByName
(
calName
);
try
{
ArrayList
<
Event
>
allEventsInCal
=
eventRepo
.
findAllByCalendar
(
chosenCalendar
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Nav event kalendara"
);
return
"redirect:/choose-cal"
;
}
ArrayList
<
Event
>
allEventsInCal
=
eventRepo
.
findAllByCalendar
(
chosenCalendar
);
if
(
statHelper
.
getStatMethod
().
equals
(
"Analysis by month"
))
{
ArrayList
<
Integer
>
eventCountInMonths
=
new
ArrayList
<>();
LocalDate
now
=
LocalDate
.
now
();
for
(
int
i
=
1
;
i
<=
12
;
i
++)
{
int
temp
=
0
;
for
(
Event
e
:
allEventsInCal
)
{
if
(
e
.
getStartDate
().
getMonthValue
()
==
i
&&
now
.
getYear
()
==
e
.
getStartDate
().
getYear
())
{
temp
++;
}
}
eventCountInMonths
.
add
(
temp
);
}
ArrayList
<
String
>
monthNames
=
new
ArrayList
<>();
monthNames
.
add
(
"January"
);
monthNames
.
add
(
"February"
);
monthNames
.
add
(
"March"
);
monthNames
.
add
(
"April"
);
monthNames
.
add
(
"May"
);
monthNames
.
add
(
"June"
);
monthNames
.
add
(
"July"
);
monthNames
.
add
(
"August"
);
monthNames
.
add
(
"September"
);
monthNames
.
add
(
"October"
);
monthNames
.
add
(
"November"
);
monthNames
.
add
(
"December"
);
JsonArray
eventArray
=
new
JsonArray
();
for
(
int
i
=
0
;
i
<
eventCountInMonths
.
size
();
i
++)
{
JsonObject
eventJson
=
new
JsonObject
();
eventJson
.
addProperty
(
"name"
,
monthNames
.
get
(
i
));
eventJson
.
addProperty
(
"eventCount"
,
eventCountInMonths
.
get
(
i
));
eventArray
.
add
(
eventJson
);
}
String
title
=
"Event count each month in calendar: "
+
statHelper
.
getChosenCalendar
();
models
.
addAttribute
(
"name"
,
title
);
models
.
addAttribute
(
"allEvents"
,
eventArray
);
}
else
if
(
statHelper
.
getStatMethod
().
equals
(
"Analysis by day"
))
{
}
models
.
addAttribute
(
"graphType"
,
statHelper
.
getGraphMethod
());
//models.addAttribute("statHelper", statHelper);
return
"statsTest"
;
}
...
...
src/main/resources/templates/statsTest.html
View file @
b5d311f0
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
>
<Head><title>
StatHelper test
</title></Head>
<head>
<link
href=
"https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.1.0/fullcalendar.min.css"
rel=
"stylesheet"
>
<link
href=
"https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.7/semantic.min.css"
rel=
"stylesheet"
>
<link
rel=
"stylesheet"
href=
"https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity=
"sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin=
"anonymous"
>
<title>
Statistics
</title>
</head>
<input
type=
"hidden"
id=
"events"
th:value=
"${allEvents}"
/>
<input
type=
"hidden"
id=
"name"
th:value=
"${name}"
/>
<input
type=
"hidden"
id=
"graphType"
th:value=
"${graphType}"
/>
<script
src=
"https://canvasjs.com/assets/script/canvasjs.min.js"
></script>
<script
type=
"text/javascript"
>
var
allEvents
=
JSON
.
parse
(
document
.
getElementById
(
"
events
"
).
value
)
var
name
=
document
.
getElementById
(
"
name
"
).
value
var
graph
=
document
.
getElementById
(
"
graphType
"
).
value
window
.
onload
=
function
()
{
var
dataFromEvents
=
[];
for
(
i
=
0
;
i
<
allEvents
.
length
;
i
++
)
{
dataFromEvents
[
i
]
=
{
label
:
allEvents
[
i
].
name
,
y
:
allEvents
[
i
].
eventCount
}
}
console
.
log
(
dataFromEvents
);
var
chart
=
new
CanvasJS
.
Chart
(
"
chartContainer
"
,
{
title
:{
text
:
name
},
axisX
:{
interval
:
1
,
},
data
:
[
{
// Change type to "doughnut", "line", "splineArea", etc.
type
:
graph
,
//dataPoints : dataFromEvents;
dataPoints
:
dataFromEvents
}
]
});
chart
.
render
();
}
</script>
</head>
<body>
<h1
th:text=
"${statHelper.getChosenCalendar()}"
></h1>
<h1
th:text=
"${statHelper.getGraphMethod()}"
></h1>
<h1
th:text=
"${statHelper.getStatMethod()}"
></h1>
<div
id=
"chartContainer"
style=
"height: 300px; width: 100%;"
></div>
</body>
</html>
\ No newline at end of file
src/main/resources/templates/statsTest2.html
0 → 100644
View file @
b5d311f0
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
>
<Head><title>
Staats
</title></Head>
<body>
<h1
th:text=
"${statHelper.getChosenCalendar()}"
></h1>
<h1
th:text=
"${statHelper.getStatMethod()}"
></h1>
<h1
th:text=
"${statHelper.getGraphMethod()}"
></h1>
</body>
</html>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment