From 44e3fc2c6e69c3b50bf394e6f1c9467f78423a34 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Wed, 5 Jun 2019 11:25:33 +0400 Subject: [PATCH] #93 fixes --- .../ulstu/user/controller/UserController.java | 2 +- .../ru/ulstu/user/service/UserService.java | 14 ++++---- src/main/resources/public/js/users.js | 34 +++++++++++++++++++ .../resources/templates/users/activities.html | 4 +-- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index 6cabd99..d18df00 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -176,7 +176,7 @@ public class UserController extends OdinController { } @GetMapping("/activities") - public Response> getActivitiesList(@RequestParam("userId") Integer userId, + public Response> getActivitiesList(@RequestParam("userId") Integer userId, @RequestParam("dateFrom") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateFrom, @RequestParam("dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo) { return new Response<>(userService.getUsersActivity(userId, dateFrom, dateTo)); diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 3056c18..1990194 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -49,6 +49,7 @@ import ru.ulstu.utils.timetable.model.Lesson; import javax.mail.MessagingException; import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; @@ -413,15 +414,16 @@ public class UserService implements UserDetailsService { activityRepository.save(activities); } - public Map getUsersActivity(Integer userId, Date dateFrom, Date dateTo) { + public Map getUsersActivity(Integer userId, Date dateFrom, Date dateTo) { List activities = activityRepository.getByUserAndDateInterval(userId, dateFrom, dateTo); - Map dateActivities = new HashMap<>(); - + Map dateActivities = new HashMap<>(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); for (Activity activity : activities) { - if (!dateActivities.containsKey(activity.getDate())) { - dateActivities.put(activity.getDate(), 1); + String dt = formatter.format(activity.getDate()); + if (!dateActivities.containsKey(dt)) { + dateActivities.put(dt, 1); } else { - dateActivities.put(activity.getDate(), dateActivities.get(activity.getDate()) + 1); + dateActivities.put(dt, dateActivities.get(dt) + 1); } } return dateActivities; diff --git a/src/main/resources/public/js/users.js b/src/main/resources/public/js/users.js index e31d3ad..2d1244f 100644 --- a/src/main/resources/public/js/users.js +++ b/src/main/resources/public/js/users.js @@ -124,4 +124,38 @@ function resetPassword() { function isEmailValid(email) { re = /\S+@\S+\.\S+/; return re.test(email) +} + +function drawActivitiesChart() { + userId = $('#author :selected').val() + dateFrom = $('#dateFrom').val() + dateTo = $('#dateTo').val() + + $.ajax({ + url:`/api/1.0/users/activities?userId=${userId}&dateFrom=${dateFrom}&dateTo=${dateTo}`, + contentType: "application/json; charset=utf-8", + method: "GET", + success: function(response) { + if (response.data.length == 0) { + return; + } + array = [['Активности', 'Количество']] + + Object.keys(response.data).forEach(function(key) { + console.table('Key : ' + key + ', Value : ' + response.data[key]) + array.push([key, response.data[key]]) + }) + var data = google.visualization.arrayToDataTable(array); + var options = { + title: 'Активности', + is3D: true, + pieResidueSliceLabel: 'Остальное' + }; + var chart = new google.visualization.ColumnChart(document.getElementById('air')); + chart.draw(data, options); + }, + error: function(errorData) { + showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING) + } + }) } \ No newline at end of file diff --git a/src/main/resources/templates/users/activities.html b/src/main/resources/templates/users/activities.html index 9565a7e..9527b95 100644 --- a/src/main/resources/templates/users/activities.html +++ b/src/main/resources/templates/users/activities.html @@ -34,8 +34,8 @@
- - + +