summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-12-28 12:59:51 +0200
committerAlon Levy <alon@pobox.com>2014-12-28 12:59:51 +0200
commit99167ae61a6f8331de84874d183b7d3882cc30ac (patch)
tree7f17445fab0ee4e9f3a25be10303fdd57e61ff78
parent7ae51db3a74814fd14a12d4a1a00970a6d63e1d6 (diff)
Fixes #217 - username initials displayed in upper right corner blue circle
Also fixes name when none set (i.e. development mode).
-rw-r--r--res/templates/index.html7
-rw-r--r--src/client/main.js16
-rw-r--r--src/server/rhizi_api.py3
3 files changed, 23 insertions, 3 deletions
diff --git a/res/templates/index.html b/res/templates/index.html
index f805c518..cba394d6 100644
--- a/res/templates/index.html
+++ b/res/templates/index.html
@@ -11,6 +11,9 @@
</head>
<body>
+ <script type="text/javascript">
+ var logged_username = "{{ username }}";
+ </script>
<div id="chromeinputbugworkaround" style="position:fixed; top:0px; left:0px; width:100%">
<span id="measure-node" class="graph nodetext" style="position: absolute; display: inline; top: -300px; left: 0px;">suicide squade, attack!</span>
<span id="measure-link" class="graph linklabel" style="position: absolute; display: inline; top: -300px; left: 0px;">those who are about to cry, we kaput you.</span>
@@ -19,8 +22,8 @@
<div class="user-area">
<div class="username">
<div class="profile-circle"></div>
- <span class="profile-initials">UH</span>
- <div class="profile-username">Welcome&nbsp;<span id="user_id">{{ username }}</span>!<span id="logout-button" class="button">Logout</span></div>
+ <span class="profile-initials">AN<!-- must be two letters because of css --></span>
+ <div class="profile-username">Welcome&nbsp;<span id="user_id">Anonymous</span>! <span id="logout-button" class="button">Logout</span></div>
</div>
<img class="organization-logo" src="/res/img/CRI-logo.png">
</div>
diff --git a/src/client/main.js b/src/client/main.js
index 863d0440..47c9de1d 100644
--- a/src/client/main.js
+++ b/src/client/main.js
@@ -8,6 +8,20 @@ function(textanalysis_ui, textanalysis, buttons, history, drag_n_drop,
obj.size = Math.max(obj.savesize, obj.value.length);
}
+ function get_user_initials() {
+ var words = logged_username.split(' '),
+ first_initial = words.length >= 1 && words[0].length >= 1 ? words[0][0] : ' ',
+ second_initial = words.length >= 2 && words[1].length >= 1 ? words[1][0] : (words.length >= 1 && words[0].length > 1 ? words[0][1] : '_');
+
+ return (first_initial + second_initial).toUpperCase();
+ }
+
+ function update_username_ui() {
+ // logged_username is defined in the body via a template server set variable
+ $('.profile-initials').html(get_user_initials());
+ $('#user_id').html(logged_username);
+ }
+
this.main = function() {
var json,
search = $('#search'),
@@ -23,6 +37,8 @@ function(textanalysis_ui, textanalysis, buttons, history, drag_n_drop,
textanalysis_ui.main();
+ update_username_ui();
+
json = util.getParameterByName('json');
if (json) {
rz_core.load_from_json(json);
diff --git a/src/server/rhizi_api.py b/src/server/rhizi_api.py
index 1bc16ab8..cac1ae44 100644
--- a/src/server/rhizi_api.py
+++ b/src/server/rhizi_api.py
@@ -227,7 +227,8 @@ def monitor__server_info():
"</p></body></html>"
def index():
- username = escape(session.get('username'))
+ session_username = session.get('username')
+ username = escape(session_username if session_username != None else "Anonymous Stranger")
return render_template('index.html', username=username)
def login():