From 3c6d950bbc3dd4a281404e6384b460468c8d6197 Mon Sep 17 00:00:00 2001 From: Raphael Maenle Date: Thu, 21 May 2020 18:33:58 +0200 Subject: [PATCH] adds device page and form for new device - form added to push new device id to backend - device added to db model (needs to be pushed still) - form return right now just prints - design for device list created, still needs some updates --- server/forms.py | 6 +++++- server/googleHandler.py | 2 +- server/models.py | 4 ++++ server/routes.py | 23 +++++++++++++++++++--- server/static/css/main.css | 9 +++++++++ server/template/calendar.html | 22 ++++++++++----------- server/template/devices.html | 36 +++++++++++++++++++++++++++++++++++ 7 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 server/template/devices.html diff --git a/server/forms.py b/server/forms.py index 311ec75..2f1dda0 100644 --- a/server/forms.py +++ b/server/forms.py @@ -28,4 +28,8 @@ class RegistrationForm(FlaskForm): def validate_email(self, email): user = User.query.filter_by(email=email.data).first() if user is not None: - raise ValidationError('Please use a different email address.') \ No newline at end of file + raise ValidationError('Please use a different email address.') + +class DeviceForm(FlaskForm): + deviceId=StringField('New Device ID', validators=[DataRequired()]) + submit = SubmitField('Add New Device') diff --git a/server/googleHandler.py b/server/googleHandler.py index b36b089..888acd6 100644 --- a/server/googleHandler.py +++ b/server/googleHandler.py @@ -104,7 +104,7 @@ def calendarsFromDb(): calendars = dbCalendar.getCalendars(dbCalendar, current_user.id) pyCalendars = [] for calendar in calendars: - name = calendar.name + name = (calendar.name[:16] + '..') if len(calendar.name)> 18 else calendar.name calendarId = calendar.calendar_id toggle = calendar.toggle color = calendar.color diff --git a/server/models.py b/server/models.py index b28cbce..048fb0a 100644 --- a/server/models.py +++ b/server/models.py @@ -88,3 +88,7 @@ class Calendar(db.Model): db.session.add(newcal) db.session.commit() + +class Device(db.Model): + id = db.Column(db.Integer, primary_key=True) + deviceId = db.Column(db.String(128), index=True) diff --git a/server/routes.py b/server/routes.py index de35ceb..10e6750 100644 --- a/server/routes.py +++ b/server/routes.py @@ -19,8 +19,8 @@ import requests import server.googleHandler as google from server import login_manager, app, db -from server.forms import LoginForm, RegistrationForm -from server.models import User, Calendar +from server.forms import LoginForm, RegistrationForm, DeviceForm +from server.models import User, Calendar, Device os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1' @@ -45,7 +45,23 @@ def view(): return flask.render_template('login.html') else: return (flask.render_template('view.html')) + +@app.route("/devices", methods=['GET', 'POST']) +def devices(): + if not current_user.is_authenticated: + return flask.render_template('login.html') + device = Device() + device.deviceId="Anthon-Mouse-Car" + devices = [device] + form = DeviceForm() + if form.validate_on_submit(): + print(form.deviceId.data, flush=True) + # TODO add device to database here + + return flask.render_template('devices.html', devices=devices, form=form) + + @app.route("/calendar") @login_required def calendar(): @@ -67,6 +83,7 @@ def emaillogin(): return redirect(url_for('account')) return render_template('emaillogin.html', title='Sign In', form=form) + @app.route('/register', methods=['GET', 'POST']) def register(): if current_user.is_authenticated: @@ -81,7 +98,7 @@ def register(): db.session.commit() flash('Congratulations, you are now a registered user!') return redirect(url_for('emaillogin')) - return render_template('register.html', title='Register', form=form) + return flask.render_template('register.html', title='Register', form=form) @app.route("/test") def testAPI(): diff --git a/server/static/css/main.css b/server/static/css/main.css index c40e035..3dfcf24 100644 --- a/server/static/css/main.css +++ b/server/static/css/main.css @@ -179,6 +179,15 @@ body * background-color: #b51409; } +.container .button.adddevice { + background-color: #ddd; + color: white; +} +.container .button.addcalendar { + background-color: #ddd; + color: white; +} + .sub.container { width: 20rem; justify-content: left; diff --git a/server/template/calendar.html b/server/template/calendar.html index ed8f6d1..2043fb3 100644 --- a/server/template/calendar.html +++ b/server/template/calendar.html @@ -1,20 +1,19 @@ {% extends "sidebar.html" %} {% block body%} -
-
Calendar
-
Show on device
-
Color
+
+
Calendar
+
Show on device
+
Color
-
{% for item in calendars %} -
+
-
{{ item.name }}
+
{{ item.name }}
-
+
-
+
+
{{ item.deviceId }}
+ + +
+ Connected +
+ + +
+ +
+ +
+ {% endfor %} +
+
+ {{ form.hidden_tag() }} + {{ form.deviceId.label }} + {{ form.deviceId(size=32) }} + {{ form.submit() }} +
+
+ +{% endblock %}