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();
// 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)
{
subscribeType = SubscribeType.ByUser;
}
if (subscribeId == null)
{
subscribeId = db.Resources.FirstOrDefault().Id;
}
var model = new StatisticViewModel()
{
Log = db.Statistic.ToList()
};
var model = new StatisticViewModel();
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.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.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 == 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();
var subscibedUser = db.Resources.FirstOrDefault(k => k.Id == subscribeId).Users.Count;
var allUsers = db.Users.Count();
var subscibedUser = db.Resources.Select(k => k.Users.Count()).Sum();
var allUsers = db.Users.Count() * db.Resources.Count();
model.Subscribe = new List<Subscribe>();
model.Subscribe.Add(new Subscribe() { Name = "Subscribed user", Value = 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);
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
@ -7,7 +8,30 @@ namespace ResoursesManager.Models
{
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
{

View File

@ -3,20 +3,18 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace ResoursesManager.ViewModels
{
public enum SubscribeType
{
ByUser, ByResource
}
public class StatisticViewModel
{
public List<ByType> ByType { get; set; }
public List<ByResource> ByResource { get; set; }
public List<ByTypeCircle> ByTypeCircle { 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
{

View File

@ -20,6 +20,8 @@
<script src="~/amcharts/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="~/amcharts/plugins/export/export.css" type="text/css" media="all" />
<script src="~/amcharts/themes/light.js"></script>
@Scripts.Render("~/bundles/jquery")
<!-- Chart code -->
<script>
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 chart2 = AmCharts.makeChart( "chartdiv2", {
"type": "serial",
@ -99,8 +100,7 @@
}
} );
</script>
<script>
var chart3 = AmCharts.makeChart( "chartdiv3", {
"type": "pie",
"theme": "light",
@ -114,8 +114,7 @@
"enabled": false
}
} );
</script>
<script>
var chart4 = AmCharts.makeChart( "chartdiv4", {
"type": "pie",
"theme": "light",
@ -129,65 +128,32 @@
"enabled": false
}
} );
</script>
<h2>Statisztika</h2>
<!-- HTML -->
@using (Html.BeginForm(null, null, FormMethod.Get, new { enctype = "multipart/form-data", id="form" }))
{
@Html.AntiForgeryToken()
<h3>Műveletek száma</h3>
@Html.DropDownList("statTypeId", Model.StatisticType)
<div id="chartdiv"></div>
<h3>Tevékenységek száma </h3>
@Html.DropDownList("resId", Model.Resources)
<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>
<table class="table">
<tr>
<th>
@Html.DisplayName("UserId")
</th>
<th>
@Html.DisplayName("ResourceId")
</th>
<th>
@Html.DisplayName("ReservationId")
</th>
<th>
@Html.DisplayName("StatisticType")
</th>
<th>
@Html.DisplayName("DateTime")
</th>
</tr>
@foreach (var item in Model.Log)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.UserId)
</td>
<td>
@Html.DisplayFor(modelItem => item.ResourceId)
</td>
<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)
<script type="text/javascript">
$('#statTypeId').on('change', function () {
$('form').submit();
});
$('#resId').on('change', function () {
$('form').submit();
});
</script>