dropdown list fixed

This commit is contained in:
Bukovenszki Tamás 2017-11-04 12:56:56 +01:00
parent 4686902b54
commit 044b7c9fec
4 changed files with 69 additions and 93 deletions

View File

@ -17,40 +17,28 @@ namespace ResoursesManager.Controllers
private ApplicationDbContext db = new ApplicationDbContext(); private ApplicationDbContext db = new ApplicationDbContext();
// GET: Statistics // GET: Statistics
public ActionResult Index(StatisticType? byTypeType, int? byResourceId, SubscribeType? subscribeType, int? subscribeId) public ActionResult Index(StatisticType? statTypeId, int? resId)
{ {
if (byTypeType == null) if (statTypeId == null)
{ {
byTypeType = StatisticType.Reserv; statTypeId = Models.StatisticType.Reserv;
} }
if (byResourceId == null) if (resId == null)
{ {
byResourceId = db.Resources.FirstOrDefault().Id; resId = db.Resources.FirstOrDefault().Id;
} }
if (subscribeType == null) var model = new StatisticViewModel();
{
subscribeType = SubscribeType.ByUser;
}
if (subscribeId == null)
{
subscribeId = db.Resources.FirstOrDefault().Id;
}
var model = new StatisticViewModel()
{
Log = db.Statistic.ToList()
};
var today = DateTime.Today.AddDays(-30.0); var today = DateTime.Today.AddDays(-30.0);
model.ByType = db.Statistic.Where(k => k.StatisticType == byTypeType && k.DateTime > today).GroupBy(l => DbFunctions.TruncateTime(l.DateTime)).Select(j => new ByType() { Name = (DateTime)j.Key, Value = j.Count() }).ToList(); model.ByType = db.Statistic.Where(k => k.StatisticType == statTypeId && k.DateTime > today).GroupBy(l => DbFunctions.TruncateTime(l.DateTime)).Select(j => new ByType() { Name = (DateTime)j.Key, Value = j.Count() }).ToList();
model.ByResource = db.Statistic.Where(k => k.ResourceId == byResourceId & k.DateTime > today).GroupBy(l => DbFunctions.TruncateTime(l.DateTime)).Select(j => new ByResource() { Name = (DateTime)j.Key, Value = j.Count() }).ToList(); model.ByResource = db.Statistic.Where(k => k.ResourceId == resId & k.DateTime > today).GroupBy(l => DbFunctions.TruncateTime(l.DateTime)).Select(j => new ByResource() { Name = (DateTime)j.Key, Value = j.Count() }).ToList();
model.ByTypeCircle = db.Statistic.GroupBy(l => l.StatisticType).Select(j => new ByTypeCircle() { Name = ((StatisticType)j.Key).ToString(), Value = j.Count() }).ToList(); model.ByTypeCircle = db.Statistic.GroupBy(l => l.StatisticType).Select(j => new ByTypeCircle() { Name = ((StatisticType)j.Key).ToString(), Value = j.Count() }).ToList();
var subscibedUser = db.Resources.FirstOrDefault(k => k.Id == subscribeId).Users.Count; var subscibedUser = db.Resources.Select(k => k.Users.Count()).Sum();
var allUsers = db.Users.Count(); var allUsers = db.Users.Count() * db.Resources.Count();
model.Subscribe = new List<Subscribe>(); model.Subscribe = new List<Subscribe>();
model.Subscribe.Add(new Subscribe() { Name = "Subscribed user", Value = subscibedUser }); model.Subscribe.Add(new Subscribe() { Name = "Subscribed user", Value = subscibedUser });
model.Subscribe.Add(new Subscribe() { Name = "Unsubscibed user", Value = allUsers - subscibedUser }); model.Subscribe.Add(new Subscribe() { Name = "Unsubscibed user", Value = allUsers - subscibedUser });
model.Resources = new SelectList(db.Resources, "Id", "Name", resId);
model.StatisticType = new SelectList(Enum.GetValues(typeof(StatisticType)).Cast<StatisticType>(), (int)statTypeId);
return View(model); return View(model);
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Web; using System.Web;
@ -7,7 +8,30 @@ namespace ResoursesManager.Models
{ {
public enum StatisticType public enum StatisticType
{ {
ResourceCreate, ResourceModified, ResourceDelete, Reserv, ReservartionModified, ReservationDelete, Subscribe, Unsubscirbe, SubscribeAll, UnsubscirbeAll, Register, Login, Logout [Description("Resource create")]
ResourceCreate,
[Description("Resource modifie")]
ResourceModified,
[Description("Resource delete")]
ResourceDelete,
[Description("Reservation")]
Reserv,
[Description("Reservation modifie")]
ReservartionModified,
[Description("Reservation delete")]
ReservationDelete,
Subscribe,
Unsubscirbe,
[Description("Subscribe to all resource")]
SubscribeAll,
[Description("Unsubscribe from all resource")]
UnsubscirbeAll,
[Description("New registration")]
Register,
[Description("Log in")]
Login,
[Description("Log out")]
Logout
} }
public class StatisticModel public class StatisticModel
{ {

View File

@ -3,20 +3,18 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Web; using System.Web;
using System.Web.Mvc;
namespace ResoursesManager.ViewModels namespace ResoursesManager.ViewModels
{ {
public enum SubscribeType
{
ByUser, ByResource
}
public class StatisticViewModel public class StatisticViewModel
{ {
public List<ByType> ByType { get; set; } public List<ByType> ByType { get; set; }
public List<ByResource> ByResource { get; set; } public List<ByResource> ByResource { get; set; }
public List<ByTypeCircle> ByTypeCircle { get; set; } public List<ByTypeCircle> ByTypeCircle { get; set; }
public List<Subscribe> Subscribe { get; set; } public List<Subscribe> Subscribe { get; set; }
public List<StatisticModel> Log { get; set; } public SelectList Resources { get; set; }
public SelectList StatisticType { get; set; }
} }
public class ByType public class ByType
{ {

View File

@ -20,6 +20,8 @@
<script src="~/amcharts/plugins/export/export.min.js"></script> <script src="~/amcharts/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="~/amcharts/plugins/export/export.css" type="text/css" media="all" /> <link rel="stylesheet" href="~/amcharts/plugins/export/export.css" type="text/css" media="all" />
<script src="~/amcharts/themes/light.js"></script> <script src="~/amcharts/themes/light.js"></script>
@Scripts.Render("~/bundles/jquery")
<!-- Chart code --> <!-- Chart code -->
<script> <script>
var data = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.ByType, Newtonsoft.Json.Formatting.None, new Newtonsoft.Json.Converters.IsoDateTimeConverter() { DateTimeFormat = "MMM-dd" })); var data = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.ByType, Newtonsoft.Json.Formatting.None, new Newtonsoft.Json.Converters.IsoDateTimeConverter() { DateTimeFormat = "MMM-dd" }));
@ -60,8 +62,7 @@
} }
} ); } );
</script>
<script>
var data2 = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.ByResource, Newtonsoft.Json.Formatting.None, new Newtonsoft.Json.Converters.IsoDateTimeConverter() { DateTimeFormat = "MMM-dd" })); var data2 = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.ByResource, Newtonsoft.Json.Formatting.None, new Newtonsoft.Json.Converters.IsoDateTimeConverter() { DateTimeFormat = "MMM-dd" }));
var chart2 = AmCharts.makeChart( "chartdiv2", { var chart2 = AmCharts.makeChart( "chartdiv2", {
"type": "serial", "type": "serial",
@ -99,8 +100,7 @@
} }
} ); } );
</script>
<script>
var chart3 = AmCharts.makeChart( "chartdiv3", { var chart3 = AmCharts.makeChart( "chartdiv3", {
"type": "pie", "type": "pie",
"theme": "light", "theme": "light",
@ -114,8 +114,7 @@
"enabled": false "enabled": false
} }
} ); } );
</script>
<script>
var chart4 = AmCharts.makeChart( "chartdiv4", { var chart4 = AmCharts.makeChart( "chartdiv4", {
"type": "pie", "type": "pie",
"theme": "light", "theme": "light",
@ -129,65 +128,32 @@
"enabled": false "enabled": false
} }
} ); } );
</script> </script>
<h2>Statisztika</h2> <h2>Statisztika</h2>
<!-- HTML -->
<h3>Műveletek száma</h3>
<div id="chartdiv"></div>
<h3>Tevékenységek száma </h3>
<div id="chartdiv2"></div>
<h3>Tevékenységek aránya</h3>
<div id="chartdiv3"></div>
<h3>Felíratkozások aránya</h3>
<div id="chartdiv4"></div>
<h2>Napló</h2> @using (Html.BeginForm(null, null, FormMethod.Get, new { enctype = "multipart/form-data", id="form" }))
<table class="table"> {
<tr> @Html.AntiForgeryToken()
<th> <h3>Műveletek száma</h3>
@Html.DisplayName("UserId") @Html.DropDownList("statTypeId", Model.StatisticType)
</th> <div id="chartdiv"></div>
<th> <h3>Tevékenységek száma </h3>
@Html.DisplayName("ResourceId") @Html.DropDownList("resId", Model.Resources)
</th> <div id="chartdiv2"></div>
<th> <h3>Tevékenységek aránya</h3>
@Html.DisplayName("ReservationId") <div id="chartdiv3"></div>
</th> <h3>Felíratkozások aránya</h3>
<th> <div id="chartdiv4"></div>
@Html.DisplayName("StatisticType")
</th>
<th>
@Html.DisplayName("DateTime")
</th>
</tr>
@foreach (var item in Model.Log) }
{ <script type="text/javascript">
<tr> $('#statTypeId').on('change', function () {
<td> $('form').submit();
@Html.DisplayFor(modelItem => item.UserId) });
</td> $('#resId').on('change', function () {
<td> $('form').submit();
@Html.DisplayFor(modelItem => item.ResourceId) });
</td> </script>
<td>
@Html.DisplayFor(modelItem => item.ReservationId)
</td>
<td>
@Html.DisplayFor(modelItem => item.StatisticType)
</td>
<td>
@Html.DisplayFor(modelItem => item.DateTime)
</td>
</tr>
}
</table>
<p>json</p>
@Newtonsoft.Json.JsonConvert.SerializeObject(Model.ByType)
<p>-</p>
@Newtonsoft.Json.JsonConvert.SerializeObject(Model.ByResource)
<p>-</p>
@Newtonsoft.Json.JsonConvert.SerializeObject(Model.ByTypeCircle)
<p>-</p>
@Newtonsoft.Json.JsonConvert.SerializeObject(Model.Subscribe)