Skip to content

Commit

Permalink
Refs #158. Work in progress on the User Dashboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
SBriere committed Oct 18, 2021
1 parent 8d567b1 commit c29c85e
Show file tree
Hide file tree
Showing 13 changed files with 313 additions and 12 deletions.
2 changes: 1 addition & 1 deletion teraserver/python/opentera/services/TeraUserClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def get_user_info(self):
response = self.do_get_request_to_backend('/api/user/users?user_uuid=' + self.__user_uuid)

if response.status_code == 200:
return response.json()
return response.json()[0]

return {}

Expand Down
7 changes: 7 additions & 0 deletions teraserver/python/services/VideoRehabService/FlaskModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ def init_views(self):
flask_app.add_url_rule('/participant_error',
view_func=ParticipantError.as_view('participant_error', *args, **kwargs))

# User
from services.VideoRehabService.Views.UserDashboard import UserDashboard
from services.VideoRehabService.Views.UserError import UserError

flask_app.add_url_rule('/user', view_func=UserDashboard.as_view('user_dashboard', *args, **kwargs))
flask_app.add_url_rule('/user_error', view_func=UserError.as_view('user_error', *args, **kwargs))


@flask_app.after_request
def apply_caching(response):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from flask.views import MethodView
from flask import render_template, request
from opentera.services.ServiceAccessManager import ServiceAccessManager, current_participant_client
from flask_babel import gettext
from opentera.services.ServiceAccessManager import ServiceAccessManager, current_participant_client, current_login_type\
, LoginType


class ParticipantDashboard(MethodView):
Expand All @@ -22,7 +24,12 @@ def get(self):
if 'X_EXTERNALPORT' in request.headers:
backend_port = request.headers['X_EXTERNALPORT']

participant_name = "Anonymous"
participant_name = gettext('Anonymous')

if current_login_type != LoginType.PARTICIPANT_LOGIN:
return render_template('participant_error.html', backend_hostname=backend_hostname,
backend_port=backend_port,
error_msg=gettext('Only participants can access this page. Sorry.'))

if current_participant_client:
participant_info = current_participant_client.get_participant_infos()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from flask.views import MethodView
from flask import render_template, request
from opentera.services.ServiceAccessManager import ServiceAccessManager, current_participant_client
from flask_babel import gettext
from opentera.services.ServiceAccessManager import ServiceAccessManager, current_participant_client, current_login_type\
, LoginType


class ParticipantEndpoint(MethodView):
Expand All @@ -21,6 +23,11 @@ def get(self):

participant_name = 'Anonymous'

if current_login_type != LoginType.PARTICIPANT_LOGIN:
return render_template('participant_error.html', backend_hostname=backend_hostname,
backend_port=backend_port,
error_msg=gettext('Only participants can access this page. Sorry.'))

# Get participant information
if current_participant_client:
participant_info = current_participant_client.get_participant_infos()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask.views import MethodView
from flask import render_template, request
from opentera.services.ServiceAccessManager import ServiceAccessManager
from opentera.services.ServiceAccessManager import ServiceAccessManager, current_login_type, LoginType
from flask_babel import gettext


Expand All @@ -23,6 +23,11 @@ def get(self):
if 'X_EXTERNALPORT' in request.headers:
backend_port = request.headers['X_EXTERNALPORT']

if current_login_type != LoginType.PARTICIPANT_LOGIN:
return render_template('participant_error.html', backend_hostname=backend_hostname,
backend_port=backend_port,
error_msg=gettext('Only participants can access this page. Sorry.'))

message = gettext('Your session will start soon. Thank you for your patience!')
if 'message' in request.args:
message = request.args['message']
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from flask.views import MethodView
from flask import render_template, request
from flask_babel import gettext
from opentera.services.ServiceAccessManager import ServiceAccessManager, current_user_client, current_login_type, \
LoginType


class UserDashboard(MethodView):

def __init__(self, *args, **kwargs):
self.flaskModule = kwargs.get('flaskModule', None)

@ServiceAccessManager.token_required(allow_static_tokens=False, allow_dynamic_tokens=True)
def get(self):
# print('get')

hostname = self.flaskModule.config.service_config['hostname']
port = self.flaskModule.config.service_config['port']
backend_hostname = self.flaskModule.config.backend_config['hostname']
backend_port = self.flaskModule.config.backend_config['port']
if 'X_EXTERNALSERVER' in request.headers:
backend_hostname = request.headers['X_EXTERNALSERVER']

if 'X_EXTERNALPORT' in request.headers:
backend_port = request.headers['X_EXTERNALPORT']

if current_login_type != LoginType.USER_LOGIN:
return render_template('user_error.html', backend_hostname=backend_hostname,
backend_port=backend_port,
error_msg=gettext('Only users can access this page. Sorry.'))

user_name = gettext('Anonymous')
if current_user_client:
user_info = current_user_client.get_user_info()
if user_info and 'user_name' in user_info:
user_name = user_info['user_name']

return render_template('user_dashboard.html', hostname=hostname, port=port,
backend_hostname=backend_hostname, backend_port=backend_port,
user_name=user_name,
user_token=current_user_client.user_token,
user_uuid=current_user_client.user_uuid
)
35 changes: 35 additions & 0 deletions teraserver/python/services/VideoRehabService/Views/UserError.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from flask.views import MethodView
from flask import render_template, request
from opentera.services.ServiceAccessManager import ServiceAccessManager, current_user_client
from flask_babel import gettext


class UserError(MethodView):

def __init__(self, *args, **kwargs):
self.flaskModule = kwargs.get('flaskModule', None)

@ServiceAccessManager.token_required(allow_static_tokens=False, allow_dynamic_tokens=True)
def get(self):
backend_hostname = self.flaskModule.config.backend_config['hostname']
backend_port = self.flaskModule.config.backend_config['port']

if 'X_EXTERNALSERVER' in request.headers:
backend_hostname = request.headers['X_EXTERNALSERVER']

if 'X_EXTERNALPORT' in request.headers:
backend_port = request.headers['X_EXTERNALPORT']

if 'error' in request.args:
error_msg = request.args['error']
else:
error_msg = gettext('Unknown error')

# Get participant information
if current_user_client:
return render_template('user_error.html', backend_hostname=backend_hostname,
backend_port=backend_port,
user_token=current_user_client.user_token,
error_msg=error_msg)
else:
return 'Unauthorized', 403
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.topbar {
position:absolute;
top:0;
left:0;
width:100%;
height:50px;
border:0;
}

.logo {
display:block;
position:absolute;
}

.status-zone {
display:block;
position:absolute;
top:10px;
right:0px;
padding-right:12.5px;
}

.name-zone {
line-height:50px;
display:block;
vertical-align:middle;
height:50px;
margin:auto;
}

.main-frame {
position:absolute;
top:50px;
left:0;
width:100%;
border:0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.topbar {
position:absolute;
top:0;
left:0;
width:100%;
height:50px;
border:0;
background-color: #647E85;
}

.logo {
display:block;
position:absolute;
}

.status-zone {
display:block;
position:absolute;
top:10px;
right:0px;
padding-right:12.5px;
}

.name-zone {
line-height:50px;
display:block;
vertical-align:middle;
height:50px;
margin:auto;
}

.main-frame {
position:absolute;
top:50px;
left:0;
width:100%;
border:0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8" />
<title>OpenTeraPlus - Participant</title>
<title>{{ gettext('OpenTera - Participant Video Dashboard') }}</title>

<link href="./static/images/favicon.ico" rel="icon" type="image/x-icon" />
<link href="./static/images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
Expand All @@ -18,6 +18,7 @@
<link href="./static/css/fontawesome.min.css" rel="stylesheet" />
<link rel="stylesheet" href="./static/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="./static/css/main_style.css" />
<link rel="stylesheet" href="./static/css/participant_style.css" />

<script src="./static/bootstrap/js/bootstrap.min.js"></script>

Expand Down Expand Up @@ -71,19 +72,19 @@ <h5 class="modal-title" id="errorDialogLongTitle" data-i18n="errorDialog.title">
</div>
</div>

<div id="communicator" style="position:absolute;top:0;left:0;width:100%;height:50px;border:0;">
<div align="left" style="display:block;position:absolute;">
<div id="communicator" class="topbar">
<div align="left" class="logo">
<img id="imgLogo" src="./static/images/LogoOpenTeraPlus.png" style="height: 50px; width: 100px;"/>
</div>
<div style="display:block;position:absolute;top:10px;right:0px;padding-right:12.5px;">
<div class="status-zone">
<button id="btnLogout" class="green-button" onclick="doLogout(backend_hostname, backend_port);">{{ gettext('Logout') }}</button>
<img id="imgStatus" src="./static/images/grey_button.png" width="24px"/>
</div>
<div align="center" style="line-height:50px;display:block;vertical-align:middle;height:50px;margin:auto;">
<div align="center" class="name-zone">
<label id="displayname">{{ participant_name }}</label>
</div>
</div>
<iframe id="mainview" class = "iframe-with-footer" src="" style="position:absolute;top:50px;left:0;width:100%;border:0;" allow="camera; microphone;">Frames not supported in this browser!</iframe>
<iframe id="mainview" class = "iframe-with-footer main-frame" src="" allow="camera; microphone;">Frames not supported in this browser!</iframe>
{% include "footer.html" %}
</body>
</html>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<title>{{ gettext('OpenTera - Error') }}</title>
</head>
<body >
<body onload="if ('{{participant_token}}' === '') hideElement('btnConnect'); ">
<div class="container fluid mt-5">
<div class="jumbotron jumbotron-fluid bg-danger" >
<div class="container">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>{{ gettext('OpenTera - User Video Dashboard') }}</title>

<link href="./static/images/favicon.ico" rel="icon" type="image/x-icon" />
<link href="./static/images/favicon.ico" rel="shortcut icon" type="image/x-icon" />

<script src="./static/js/bowser.js"></script>
<script src="/static/js/jquery-3.5.1.min.js"></script>

<script src="./static/js/opentera.js"></script> <!-- Always include first -->
<script src="./static/js/opentera_websockets.js"></script>
<script src="./static/js/opentera_login.js"></script>
<script src="./static/js/opentera_dashboard.js"></script>

<link href="./static/css/fontawesome.min.css" rel="stylesheet" />
<link rel="stylesheet" href="./static/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="./static/css/main_style.css" />
<link rel="stylesheet" href="./static/css/user_style.css" />

<script src="./static/bootstrap/js/bootstrap.min.js"></script>

<!-- Translations -->
<script>
const str_unsupported_browser_title = "{{ gettext('Unsupported browser detected') }}";
const str_unsupported_browser = "{{ gettext('Your browser is not supported. Session might or might not work, but it is recommended to user another browser.') }}";
const str_your_browser = "{{ gettext('Your browser') }}";
const str_supported_browsers = "{{ gettext('Supported browsers') }}";
const str_cant_connect = "{{ gettext('Unable to connect') }}";
const str_cant_connect_reasons = "{{ gettext('Your access might have been disabled or you might be already logged in on another device') }}";
const str_session_complete = "{{ gettext('Your session is now over. You may now logout or close this page.') }}";
</script>

<!-- Server informations -->
<script>
let backend_hostname = "{{ backend_hostname }}";
let backend_port = {{ backend_port }};
let user_token = "{{ user_token }}";
let user_name = "{{ user_name }}";
let user_uuid = "{{ user_uuid }}";

const browser = bowser.getParser(window.navigator.userAgent);
window.onload = function() {
console.log('Page loaded. Ready to start!');
init_dashboard(backend_hostname, backend_port);
//init_system();
}
</script>
</head>
<body>
<!-- ErrorDialog -->
<div class="modal fade" id="errorDialog" tabindex="-1" role="dialog" aria-labelledby="errorDialogCenterTitle"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header modal-header-error">
<h5 class="modal-title" id="errorDialogLongTitle" data-i18n="errorDialog.title">{{ gettext('Error') }}</h5>
<!--<button type="button" class="close" data-dismiss="modal" aria-label="Fermer">
<span aria-hidden="true" style="color: white;">&times;</span>
</button>-->
</div>
<div class="modal-body modal-body-error">
<label id="errorDialogText">Description de l'erreur.</label><br></p>
</div>
<div class="modal-footer modal-footer-error">
<button type="button" id="errorRefresh" class="btn btn-success" data-dismiss="modal" onclick="location.reload();" data-i18n="errorDialog.retry">{{ gettext('Retry') }}</button>
<!--<button type="button" id="errorIgnore" class="btn btn-warning" data-dismiss="modal" onclick="loginParticipant();" data-i18n="errorDialog.ignore">{{ gettext('Ignore') }}</button>-->
</div>
</div>
</div>
</div>

<div id="communicator" class="topbar">
<div align="left" class="logo">
<img id="imgLogo" src="./static/images/LogoOpenTeraPlus.png" style="height: 50px; width: 100px;"/>
</div>
<div class="status-zone">
<button id="btnLogout" class="green-button" onclick="doLogout(backend_hostname, backend_port);">{{ gettext('Logout') }}</button>
<img id="imgStatus" src="./static/images/grey_button.png" width="24px"/>
</div>
<div align="center" class="name-zone">
<label id="displayname">{{ user_name }}</label>
</div>
</div>
<iframe id="mainview" class = "iframe-with-footer main-frame" src="" allow="camera; microphone;">Frames not supported in this browser!</iframe>
{% include "footer.html" %}
</body>
</html>

Loading

0 comments on commit c29c85e

Please sign in to comment.