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>
|
||||
@@ -1,42 +0,0 @@
|
||||
@{
|
||||
ViewBag.Title = "Hello Razor";
|
||||
}
|
||||
|
||||
<div id="grid"></div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
var baseUrl = "@Url.Content("~/api/heartbeat/")";
|
||||
|
||||
$("#grid").kendoGrid({
|
||||
dataSource: {
|
||||
transport: {
|
||||
read: { url: baseUrl, type: "GET" }
|
||||
},
|
||||
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: "Heartbeats" }
|
||||
]
|
||||
});
|
||||
})
|
||||
|
||||
</script>
|
||||
@@ -1,4 +1,4 @@
|
||||
@model int
|
||||
@model string
|
||||
@inject IHttpContextAccessor HttpContextAccessor
|
||||
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
||||
@using LinqToDB;
|
||||
@@ -7,24 +7,81 @@
|
||||
ViewBag.Title = "Hello Razor";
|
||||
string username = HttpContextAccessor.HttpContext.Session.GetString("username");
|
||||
var db = dbFactory.Create();
|
||||
var message = (from m in db.Messages
|
||||
where m.Id.Equals(Model) && m.Reciver.Equals(username)
|
||||
select m).ToArray().FirstOrDefault();
|
||||
var user = (from u in db.Users
|
||||
where u.Username.Equals(Model)
|
||||
select u).FirstOrDefault();
|
||||
var messages = (from m in db.Messages
|
||||
where (m.Username.Equals(Model) && m.Receiver.Equals(username))
|
||||
||(m.Receiver.Equals(Model) && m.Username.Equals(username))
|
||||
orderby m.Time ascending
|
||||
select m).ToArray();
|
||||
}
|
||||
|
||||
<div class="content">
|
||||
@if (message == null)
|
||||
@if (messages.Count() == 0)
|
||||
{
|
||||
<p class="text-red">Non hai il permesso</p>
|
||||
<p class="text-red">Non hai messaggi</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
message.Seen = true;
|
||||
db.Update(message);
|
||||
<p>Messaggio da @message.Username</p>
|
||||
<p>Inviato il @message.Time</p>
|
||||
<div class="info-box-text">
|
||||
@message.Body
|
||||
</div>
|
||||
<h3 class="text-bold">Messaggi con @user.Name @user.LastName</h3>
|
||||
|
||||
foreach (var message in messages)
|
||||
{
|
||||
if (message.Seen == default && message.Receiver.Equals(username))
|
||||
{
|
||||
message.Seen = DateTime.Now;
|
||||
db.Update(message);
|
||||
}
|
||||
<div>
|
||||
@if (message.Receiver.Equals(username))
|
||||
{
|
||||
<div class="pull-left"></div>
|
||||
<div class="pull-right-container bg-light-blue">
|
||||
<span style="white-space: pre-line" class="">@message.Body</span>
|
||||
<p class="text-aqua">@message.Seen</p>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="pull-right-container bg-green-gradient">
|
||||
<div style="white-space: pre-line" class="">@message.Body</div>
|
||||
<p class="text-aqua">@message.Seen</p>
|
||||
</div>
|
||||
<div class="pull-right"></div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
<div class="pull-right">
|
||||
<textarea id="res-message" class="progress-text" placeholder="Scrivi qui per scrivere un messaggio"></textarea>
|
||||
<button id="btn-send-message">Invia</button>
|
||||
<p id="message-error" class="text-red"></p>
|
||||
</div>
|
||||
<script>
|
||||
$("#btn-send-message").on("click", function () {
|
||||
var min = 10;
|
||||
var body = $("#res-message").val().trim();
|
||||
var endMessage = $("#message-error");
|
||||
if (body.length < min) {
|
||||
endMessage.html("Messaggio non valido (minimo " + min + " caratteri)");
|
||||
return false;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: "/Account/_sendMessage",
|
||||
type: "POST",
|
||||
data: {
|
||||
Receiver: "@Model",
|
||||
Body: body
|
||||
},
|
||||
success: function (data) {
|
||||
console.log(data);
|
||||
$("#res-message").val("");
|
||||
endMessage.html("Messaggio inviato");
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
@{
|
||||
ViewBag.Title = "Hello Razor";
|
||||
}
|
||||
|
||||
<div id="grid"></div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
var baseUrl = "@Url.Content("~/api/sleep/")";
|
||||
|
||||
$("#grid").kendoGrid({
|
||||
dataSource: {
|
||||
transport: {
|
||||
read: { url: baseUrl, type: "GET" }
|
||||
},
|
||||
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: "Sleep Time", format: "{n2}", template: '${value/3600000}' }
|
||||
]
|
||||
});
|
||||
})
|
||||
|
||||
</script>
|
||||
@@ -1,42 +0,0 @@
|
||||
@{
|
||||
ViewBag.Title = "Hello Razor";
|
||||
}
|
||||
|
||||
<div id="grid"></div>
|
||||
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
var baseUrl = "@Url.Content("~/api/step/")";
|
||||
|
||||
$("#grid").kendoGrid({
|
||||
dataSource: {
|
||||
transport: {
|
||||
read: { url: baseUrl, type: "GET" }
|
||||
},
|
||||
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: "Steps done" }
|
||||
]
|
||||
});
|
||||
})
|
||||
|
||||
</script>
|
||||
184
SeniorAssistant/Views/Home/User.cshtml
Normal file
184
SeniorAssistant/Views/Home/User.cshtml
Normal file
@@ -0,0 +1,184 @@
|
||||
@inject IHttpContextAccessor HttpContextAccessor
|
||||
@inject IDataContextFactory<SeniorDataContext> dbFactory
|
||||
@model User
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Hello Razor";
|
||||
var session = HttpContextAccessor.HttpContext.Session;
|
||||
var username = session.GetString("username");
|
||||
|
||||
bool auth = username.Equals(Model.Username);
|
||||
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.Username) && p.Doctor.Equals(username)
|
||||
select p).ToArray().FirstOrDefault();
|
||||
auth = auth || patient != null;
|
||||
}
|
||||
}
|
||||
|
||||
@if (!auth)
|
||||
{
|
||||
<p class="box-title text-red">Non sei autorizzato a vedere i dati di @Model.Name @Model.LastName</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<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>
|
||||
<a class="" href="/Message/@patient.Username">Invia un messaggio al tuo paziente</a>
|
||||
<div>
|
||||
<p>Inserisci un minimo o massimo valore per il battito cardiaco</p>
|
||||
<p>Se il valore del battito del paziente supera i valori che hai inserito verrai notificato</p>
|
||||
<label>Max:</label>
|
||||
<input id="maxHeart" placeholder="max" value="@patient.MaxHeart" />
|
||||
<label>Min:</label>
|
||||
<input id="minHeart" placeholder="min" value="@patient.MinHeart" />
|
||||
</div>
|
||||
<script>
|
||||
$("#send-note").on("click", function () {
|
||||
var text = $("#note-area").val().trim();
|
||||
$.ajax({
|
||||
url: "/Account/_addNote",
|
||||
type: "PUT",
|
||||
data: {
|
||||
Patient: "@Model.Username", Text: text
|
||||
},
|
||||
success: function (data) {
|
||||
$("#note-error").html(data.success ? "Nota salvata" : data.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
$("#maxHeart, #minHeart").on("change keyup paste click", function () {
|
||||
onlyNum($(this));
|
||||
});
|
||||
$("#maxHeart, #minHeart").on("blur", function () {
|
||||
var value = parseInt($(this).val());
|
||||
var id = $(this).attr("id");
|
||||
$.ajax({
|
||||
url: "/Account/_" + id + "ToPatient",
|
||||
type: "PUT",
|
||||
data: {
|
||||
Patient: "@Model.Username",
|
||||
Value: value
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
}
|
||||
|
||||
<script>
|
||||
function onlyNum(object, numChar = 3) {
|
||||
object.val(object.val().replace(/[^0-9]/g, '').substring(0, numChar));
|
||||
}
|
||||
|
||||
$("#hours-data").on("change keyup paste click", function () {
|
||||
onlyNum($(this), 2);
|
||||
});
|
||||
$("#refresh-hours").on("click", function () {
|
||||
var hours = $("#hours-data").val();
|
||||
var base_url = "@Url.Content("~/api/")";
|
||||
var end_url = "/@Model.Username/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 });
|
||||
}
|
||||
});
|
||||
|
||||
if (Object.keys(heartbeat).length == 0
|
||||
&& Object.keys(steps).length == 0
|
||||
&& Object.keys(sleep).length == 0)
|
||||
$("#chart-data").html("Nessun dato");
|
||||
else
|
||||
$("#chart-data").kendoChart({
|
||||
title: { text: "Visualizzazione attivita' di @Model.Name @Model.LastName" },
|
||||
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
|
||||
}]
|
||||
}); /* Kendo */
|
||||
}); /* sleep */
|
||||
}); /* steps */
|
||||
}); /* heart */
|
||||
}); /* click */
|
||||
$("#refresh-hours").click();
|
||||
</script>
|
||||
}
|
||||
Reference in New Issue
Block a user