Skip to content
Snippets Groups Projects
Commit f1b6ced2 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Add subs to dashboard

parent 1294a2a4
No related branches found
No related tags found
1 merge request!86Merge school-apps
......@@ -37,7 +37,13 @@ class Dashboard extends React.Component {
that.setState({...data, refreshIn: REFRESH_TIME + 1, isLoading: false});
that.updateRefreshTime();
}
})
});
$.getJSON(API_URL + "/my-plan", (data) => {
console.log(data);
if (data && data.lessons) {
that.setState({lessons: data.lessons});
}
});
};
componentDidMount() {
......@@ -85,7 +91,9 @@ class Dashboard extends React.Component {
<i className={"material-icons left"}>refresh</i>
in {this.state.refreshIn} s
</button>
<p className="flow-text">Willkommen bei SchoolApps!</p>
<p className="flow-text">Moin
Moin, {this.state.user.full_name !== "" ? this.state.user.full_name : this.state.user.username}. Hier
findest du alle aktuellen Informationen:</p>
{this.state.unread_notifications && this.state.unread_notifications.length > 0 ?
this.state.unread_notifications.map(function (notification) {
return <div className={"alert primary scale-transition"} id={"not-" + notification.id}
......@@ -109,9 +117,38 @@ class Dashboard extends React.Component {
<div className="col s12 m12 l12 xl6">
<div className="card">
{this.state.has_plan ? <div className="card-content">
<span className="card-title">Vertretungen {this.state.plan.type == 2 ? "der" : "für"}
<em>{this.state.plan.name}</em> für {this.state.date_formatted}</span>
<p>Keine Vertretungen für morgen vorhanden.</p>
<span className="card-title">
Vertretungen {this.state.plan.type === 2 ? "der" : "für"} <em>
{this.state.plan.name}</em> für {this.state.date_formatted}
</span>
{this.state.lessons && this.state.lessons.length > 0 ? <div>
{this.state.lessons.map(function (lesson) {
return <div className="row">
<div className="col s4">
<div className="card timetable-title-card">
<div className="card-content">
<span className="card-title left">
{lesson.time.number_format}
</span>
<div
className="right timetable-time grey-text text-darken-2">
<span>{lesson.time.start}</span>
<br/>
<span>{lesson.time.end}</span>
</div>
</div>
</div>
</div>
<div className={"col s8"} dangerouslySetInnerHTML={{__html: lesson.html}}/>
</div>;
})}
</div>
:
<p>Keine Vertretungen für morgen vorhanden.</p>
}
</div> : <p className={"flow-text"}>Keine Vertretungen vorhanden.</p>}
{this.state.has_plan ? <div className="card-action">
<a href={MY_PLAN_URL}>
......
......@@ -5,5 +5,6 @@ urlpatterns = [
path('', views.index, name='dashboard'),
path('api', views.api_information, name="api_information"),
path('api/notifications/read/<int:id>', views.api_read_notification, name="api_read_notification"),
path('api/my-plan', views.api_my_plan_html, name="api_my_plan_html"),
path('test/', views.test_notification, name='test'),
]
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from django.shortcuts import render, redirect, get_object_or_404
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils import timezone
from django.utils import timezone, formats
from helper import get_newest_articles, get_current_events
from schoolapps.settings import SHORT_WEEK_DAYS, LONG_WEEK_DAYS
from timetable.hints import get_all_hints_by_class_and_time_period, get_all_hints_for_teachers_by_time_period
from timetable.views import get_next_weekday_with_time, get_type_and_object_of_user
from timetable.views import get_next_weekday_with_time, get_type_and_object_of_user, get_calendar_week
from untisconnect.api import TYPE_TEACHER, TYPE_CLASS
from untisconnect.plan import get_plan
from .models import Activity, register_notification, Notification
# from .apps import DashboardConfig
from mailer import send_mail_with_template
......@@ -88,6 +90,10 @@ def api_information(request):
"newest_article": newest_article,
"current_events": get_current_events()[:3],
"date_formatted": date_formatted,
"user": {
"username": request.user.username,
"full_name": request.user.first_name
}
}
if _type is not None:
......@@ -112,6 +118,56 @@ def api_read_notification(request, id):
return JsonResponse({"success": True})
@login_required
def api_my_plan_html(request):
# Get user type (student, teacher, etc.)
_type, el = get_type_and_object_of_user(request.user)
hints = None
if _type == TYPE_TEACHER:
# Teacher
plan_id = el.id
raw_type = "teacher"
# Get hints
# hints = list(get_all_hints_for_teachers_by_time_period(next_weekday, next_weekday))
elif _type == TYPE_CLASS:
# Student
plan_id = el.id
raw_type = "class"
# Get hints
# hints = list(get_all_hints_by_class_and_time_period(el, next_weekday, next_weekday))
else:
return JsonResponse({"success": False})
# Get calendar week and monday of week
next_weekday = get_next_weekday_with_time(timezone.now(), timezone.now().time())
calendar_week = next_weekday.isocalendar()[1]
monday_of_week = get_calendar_week(calendar_week, next_weekday.year)["first_day"]
week_day = next_weekday.isoweekday() - 1
print(raw_type, plan_id, next_weekday, calendar_week, monday_of_week)
# Get plan
plan = get_plan(_type, plan_id, smart=True, monday_of_week=monday_of_week)
lessons = []
for row, time in plan:
lesson_container = row[week_day]
for element in lesson_container.elements:
if element.substitution is not None:
print(time)
html = render_to_string("timetable/lesson.html", {"col": lesson_container}, request=request)
time["start"] = formats.date_format(time["start"], "H:i")
time["end"] = formats.date_format(time["end"], "H:i")
lessons.append({"time": time, "html": html})
break
print(lessons)
return JsonResponse({"success": True, "lessons": lessons})
@login_required
def test_notification(request):
""" Sends a test mail """
......
......@@ -89,6 +89,12 @@ var Dashboard = function (_React$Component) {
that.updateRefreshTime();
}
});
$.getJSON(API_URL + "/my-plan", function (data) {
console.log(data);
if (data && data.lessons) {
that.setState({lessons: data.lessons});
}
});
};
_this.state = {
......@@ -178,7 +184,9 @@ var Dashboard = function (_React$Component) {
React.createElement(
"p",
{className: "flow-text"},
"Willkommen bei SchoolApps!"
"Moin Moin, ",
this.state.user.full_name !== "" ? this.state.user.full_name : this.state.user.username,
". Hier findest du alle aktuellen Informationen:"
),
this.state.unread_notifications && this.state.unread_notifications.length > 0 ? this.state.unread_notifications.map(function (notification) {
return React.createElement(
......@@ -244,7 +252,7 @@ var Dashboard = function (_React$Component) {
"span",
{className: "card-title"},
"Vertretungen ",
this.state.plan.type == 2 ? "der" : "für",
this.state.plan.type === 2 ? "der" : "für",
" ",
React.createElement(
"em",
......@@ -254,7 +262,54 @@ var Dashboard = function (_React$Component) {
" f\xFCr ",
this.state.date_formatted
),
React.createElement(
this.state.lessons && this.state.lessons.length > 0 ? React.createElement(
"div",
null,
this.state.lessons.map(function (lesson) {
return React.createElement(
"div",
{className: "row"},
React.createElement(
"div",
{className: "col s4"},
React.createElement(
"div",
{className: "card timetable-title-card"},
React.createElement(
"div",
{className: "card-content"},
React.createElement(
"span",
{className: "card-title left"},
lesson.time.number_format
),
React.createElement(
"div",
{
className: "right timetable-time grey-text text-darken-2"
},
React.createElement(
"span",
null,
lesson.time.start
),
React.createElement("br", null),
React.createElement(
"span",
null,
lesson.time.end
)
)
)
)
),
React.createElement("div", {
className: "col s8",
dangerouslySetInnerHTML: {__html: lesson.html}
})
);
})
) : React.createElement(
"p",
null,
"Keine Vertretungen f\xFCr morgen vorhanden."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment