Refactoring
* refactoring * fixes * messages * new interface
This commit is contained in:
@@ -1,154 +1,57 @@
|
||||
@inject IHttpContextAccessor HttpContextAccessor
|
||||
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
||||
@model string
|
||||
|
||||
@model string
|
||||
@inject IHttpContextAccessor Http
|
||||
@{
|
||||
ViewBag.Title = "Hello Razor";
|
||||
var session = HttpContextAccessor.HttpContext.Session;
|
||||
var username = session.GetString("username");
|
||||
|
||||
bool auth = username.Equals(Model);
|
||||
bool isDoc = session.GetString("role").Equals("doctor");
|
||||
Patient patient = null;
|
||||
if (isDoc)
|
||||
{
|
||||
var db = dbFactory.Create();
|
||||
patient = (from p in db.Patients
|
||||
where p.Username.Equals(Model) && p.Doctor.Equals(username)
|
||||
select p).ToArray().FirstOrDefault();
|
||||
auth = auth || patient != null;
|
||||
}
|
||||
var session = Http.HttpContext.Session.GetString("username");
|
||||
}
|
||||
|
||||
@if (!auth)
|
||||
{
|
||||
<p class="box-title text-red">Non sei autorizzato a vedere i dati di @Model</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
// Aggiungere un qualcosa per scegliere le ore da vedere (Max 48?)
|
||||
<div>
|
||||
<input id="hours-data" type="text" placeholder="hours" value="24" />
|
||||
<button id="refresh-hours" class="fc-button">Cambia ora</button>
|
||||
<div id="chart-data"></div>
|
||||
</div>
|
||||
@if(isDoc && patient != null)
|
||||
{
|
||||
<div>
|
||||
<textarea id="note-area" placeholder="Scrivi una nota..">@patient.Notes</textarea>
|
||||
<button id="send-note" class="btn">Salva</button>
|
||||
<p id="note-error"></p>
|
||||
</div>
|
||||
<script>
|
||||
$("#send-note").on("click", function () {
|
||||
var text = $("#note-area").val().trim();
|
||||
$.ajax({
|
||||
url: "/Account/_addNote",
|
||||
type: "PUT",
|
||||
data: {
|
||||
Patient: "@Model", Text: text
|
||||
},
|
||||
success: function (data) {
|
||||
$("#note-error").html(data.success?"Nota salvata":data.message);
|
||||
<div id="grid"></div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
var baseUrl = "@Url.Content("~/api/" + Model + "/" + session + "/today")";
|
||||
|
||||
$("#grid").kendoGrid({
|
||||
dataSource: {
|
||||
transport: {
|
||||
read: {
|
||||
url: baseUrl,
|
||||
type: "GET"
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
}
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
$("#hours-data").on("change keyup paste click", function () {
|
||||
var t = $(this);
|
||||
t.val(t.val().replace(/[^0-9]/g, '').substring(0, 2));
|
||||
},
|
||||
serverPaging: false,
|
||||
serverSorting: false,
|
||||
batch: false,
|
||||
schema: {
|
||||
model: {
|
||||
id: "username",
|
||||
fields: {
|
||||
username: { type: "string" },
|
||||
time: { type: "date" },
|
||||
value: { type: "number" }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
scrollable: true,
|
||||
sortable: true,
|
||||
filterable: true,
|
||||
editable: false,
|
||||
columns: [
|
||||
{
|
||||
field: "username",
|
||||
title: "Username"
|
||||
},
|
||||
{
|
||||
field: "time",
|
||||
title: "Date/Time",
|
||||
format: "{0:dd/MM/yyyy HH:mm}"
|
||||
},
|
||||
{
|
||||
field: "value",
|
||||
title: "@Model"
|
||||
}
|
||||
]
|
||||
});
|
||||
$("#refresh-hours").on("click", function () {
|
||||
var hours = $("#hours-data").val();
|
||||
var base_url = "@Url.Content("~/api/")";
|
||||
var end_url = "/@Model/last/" + hours;
|
||||
|
||||
$.getJSON(base_url + "heartbeat" + end_url, function (heartbeat) {
|
||||
$.getJSON(base_url + "step" + end_url, function (steps) {
|
||||
$.getJSON(base_url + "sleep" + end_url, function (sleep) {
|
||||
var sleepArr = [];
|
||||
sleep.forEach( function (el) {
|
||||
sleepArr.push({ "time": el.time, "value": 1 });
|
||||
var base_time = new Date(el.time).getTime();
|
||||
|
||||
for (var i = 60000; i <= el.value; i += 60000) {
|
||||
sleepArr.push({ "time": new Date(base_time + i), "value": 1 });
|
||||
}
|
||||
});
|
||||
|
||||
$("#chart-data").kendoChart({
|
||||
title: { text: "Visualizzazione attivita' di @Model" },
|
||||
legend: { position: "bottom" },
|
||||
seriesDefaults: {
|
||||
type: "line",
|
||||
style: "smooth"
|
||||
},
|
||||
series: [{
|
||||
name: "Battito",
|
||||
field: "value",
|
||||
color: "red",
|
||||
axis: "Heartbeat",
|
||||
categoryField: "time",
|
||||
data: heartbeat,
|
||||
tooltip: {
|
||||
visible: true,
|
||||
format: "{0}%",
|
||||
template: "Media di: #= value # bpm"
|
||||
}
|
||||
}, {
|
||||
name: "Passi",
|
||||
field: "value",
|
||||
color: "blue",
|
||||
axis: "Steps",
|
||||
categoryField: "time",
|
||||
data: steps,
|
||||
tooltip: {
|
||||
visible: true,
|
||||
format: "{0}%",
|
||||
template: "#= series.name #: #= value #"
|
||||
}
|
||||
}, {
|
||||
type: "area",
|
||||
name: "Sonno",
|
||||
field: "value",
|
||||
color: "black",
|
||||
axis: "Sleep",
|
||||
categoryField: "time",
|
||||
data: sleepArr
|
||||
}],
|
||||
categoryAxis: {
|
||||
labels: {
|
||||
rotation: +45,
|
||||
dateFormats: {
|
||||
hours: "HH:mm"
|
||||
}
|
||||
},
|
||||
type: "Date",
|
||||
baseUnit: "hours"
|
||||
},
|
||||
valueAxes: [{
|
||||
name: "Heartbeat",
|
||||
color: "red"
|
||||
}, {
|
||||
name: "Steps",
|
||||
color: "blue"
|
||||
}, {
|
||||
name: "Sleep",
|
||||
color: "gray",
|
||||
visible: false,
|
||||
max: 1,
|
||||
min: 0
|
||||
}]
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
$("#refresh-hours").click();
|
||||
</script>
|
||||
}
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user