Skip to content

Commit

Permalink
Add observable authUser and migrate some uses of currentUser. See #41
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Aug 15, 2021
1 parent dc9feb3 commit b64bf22
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
16 changes: 11 additions & 5 deletions client/app/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ define(["jquery", "knockout", "canvg", "base64", "js/download", "ace/ext/static_
var vars = ko.observableArray([]);
var plotHistory = ko.observableArray([]);
var currentPlotIdx = ko.observable(-1);
var currentUser = ko.observable();
var authUser = ko.observable(); // user who is currently logged in
var currentUser = ko.observable(); // user who owns the workspace (may or may not be the same as authUser)
var currentBucket = ko.observable();
var viewModel = window.viewModel = {
files: allOctFiles,
Expand Down Expand Up @@ -169,7 +170,7 @@ define(["jquery", "knockout", "canvg", "base64", "js/download", "ace/ext/static_
}
}),
patreonValue: ko.computed(function() {
var user = currentUser();
var user = authUser();
return user && user.patreon && user.patreon.currently_entitled_amount_cents;
}),

Expand Down Expand Up @@ -216,6 +217,7 @@ define(["jquery", "knockout", "canvg", "base64", "js/download", "ace/ext/static_
},

// Sign In / Sign Out
authUser: authUser,
currentUser: currentUser,
doLogout: function(){
onboarding.reset();
Expand Down Expand Up @@ -645,15 +647,15 @@ define(["jquery", "knockout", "canvg", "base64", "js/download", "ace/ext/static_
}
},
askForEnroll: function(program){
if(!viewModel.currentUser()){
if(!viewModel.authUser()){
utils.alert(oo_translations["students.enroll.p1"]);
return;
}

if(confirm(
oo_translations["students.enroll.p2"] + "\n\nenroll('default')\n\n" + oo_translations["students.enroll.p3"])){
OctMethods.socket.enroll(program);
viewModel.currentUser().program = program; // note: this is not observable
viewModel.authUser().program = program; // note: this is not observable
}
},
addTime: function() {
Expand Down Expand Up @@ -999,6 +1001,10 @@ define(["jquery", "knockout", "canvg", "base64", "js/download", "ace/ext/static_
return;
}

// Trigger Knockout
data.name = data.name || data.displayName;
viewModel.authUser(data);

// Set up the UI
onboarding.showUserPromo(data);
onboarding.hideScriptPromo();
Expand Down Expand Up @@ -1407,7 +1413,7 @@ define(["jquery", "knockout", "canvg", "base64", "js/download", "ace/ext/static_

// Add a credit line at the bottom
var creditDiv = $("<div></div>");
creditDiv.append(oo_translations["print.p1"] + " " + (viewModel.currentUser() || { name: "Anonymous" }).name);
creditDiv.append(oo_translations["print.p1"] + " " + (viewModel.authUser() || { name: "Anonymous" }).name);
creditDiv.append("<br/>");
creditDiv.append(oo_translations["print.p2"]);
creditDiv.append("<br/>");
Expand Down
18 changes: 9 additions & 9 deletions front/src/views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ with Octave Online Server. If not, see <https://www.gnu.org/licenses/>.
<!-- ko if: editable -->
<span id="editor_print" title="<%= t("editor.toolbar.print#btn") %>" data-bind="click: print"></span>
<label id="wrap_checkbox" title="<%= t("editor.toolbar.wrap#btn") %>"><input type="checkbox" data-bind="checked: wrap" /></label>
<!-- ko if: $root.purpose() !== "bucket" && $root.currentUser -->
<!-- ko if: $root.purpose() !== "bucket" && $root.authUser -->
<span id="editor_share" title="<%= t("editor.toolbar.share#btn") %>" data-bind="click: share"></span>
<!-- /ko -->
<span id="editor_save" title="<%= t("editor.toolbar.save#btn") %>" data-bind="click: save"></span>
Expand Down Expand Up @@ -229,7 +229,7 @@ with Octave Online Server. If not, see <https://www.gnu.org/licenses/>.
<div id="console_output_container">
<pre id="console" data-bind="css: { 'console-wrap': consoleWhiteSpaceWrap }"></pre>
<!-- ko if: patreonValue() > 0 -->
<div id="tier_background"><div data-bind="class: currentUser().patreon.tier_name, click: showUpgradeTier" title="<%= t("panel.output.upgraded#ui") %>"></div></div>
<div id="tier_background"><div data-bind="class: authUser().patreon.tier_name, click: showUpgradeTier" title="<%= t("panel.output.upgraded#ui") %>"></div></div>
<!-- /ko -->
<% if (config.client.onboarding) { %>
<div id="instructor-promo" aria-hidden="true">
Expand All @@ -242,7 +242,7 @@ with Octave Online Server. If not, see <https://www.gnu.org/licenses/>.
<div id="type_here" aria-hidden="true">
<span class="l1"><%= t("promos.prompt.title") %></span>
<span class="l2"><%= t("promos.prompt.p1") %></span>
<!-- ko ifnot: currentUser() -->
<!-- ko ifnot: authUser() -->
<span class="l3"><%= t("promos.prompt.p2") %> <a href="javascript:void(0)" id="sign_in_shortcut"><%= t("promos.prompt.btn1") %></a></span>
<!-- /ko -->
</div>
Expand All @@ -267,7 +267,7 @@ with Octave Online Server. If not, see <https://www.gnu.org/licenses/>.
</span>
<span id="add_time_container">
<span class="clickable" data-bind="click: addTime"><%- t("panel.prompt.add#btn", { numSecondsHTML: '<span data-bind="text: countdownExtraTimeSeconds"></span>' }) %></span>
<!-- ko if: (currentUser() && (!currentUser().patreon || !currentUser().patreon.currently_entitled_tier)) -->
<!-- ko if: (authUser() && (!authUser().patreon || !authUser().patreon.currently_entitled_tier)) -->
/ <span class="clickable" data-bind="click: showUpgradeTier"><%= t("panel.prompt.upgrade#btn") %></span>
<!-- /ko -->
</span>
Expand All @@ -291,7 +291,7 @@ with Octave Online Server. If not, see <https://www.gnu.org/licenses/>.
}, value: currentLanguage"></select>
</div>
<% } %>
<!-- ko if: (!currentUser() && purpose() !== "student") -->
<!-- ko if: (!authUser() && purpose() !== "student") -->
<svg width="200" height="40" class="login_btn" id="sign_in_with_google">
<image xlink:href="images/sign-in-with-google.svg" src="images/sign-in-with-google.png" width="200" height="40" alt="<%= t("header.sidebar.signingoogle#btn") %>" />
</svg>
Expand All @@ -302,9 +302,9 @@ with Octave Online Server. If not, see <https://www.gnu.org/licenses/>.
<image xlink:href="images/sign-in-with-email.svg" src="images/sign-in-with-email.png" width="200" height="40" alt="<%= t("header.sidebar.signinemail#btn") %>" />
</svg>
<!-- /ko -->
<!-- ko if: (currentUser() && purpose() !== "student") -->
<!-- ko if: (authUser() && purpose() !== "student") -->
<div id="userbox">
<span data-bind="text: currentUser().name"></span>
<span data-bind="text: authUser().name"></span>
<a id="logout_icon" href="javascript:void(0)" title="Sign Out" data-bind="click: doLogout"><%= t("header.sidebar.signout#btn") %></a>
</div>
<div class="site-control-item" data-bind="click: showUpgradeTier">
Expand Down Expand Up @@ -631,12 +631,12 @@ with Octave Online Server. If not, see <https://www.gnu.org/licenses/>.
<h2 class="popover-title-bar">
<%= t("modals.upgrade.title") %>
</h2>
<!-- ko ifnot: currentUser -->
<!-- ko ifnot: authUser -->
<p class="action-links">
<a href="/auth/patreon/plans" target="_blank"><%= t("modals.upgrade.btn1") %></a> / <a href="/auth/patreon"><%= t("modals.upgrade.btn2") %></a>
</p>
<!-- /ko -->
<!-- ko with: currentUser -->
<!-- ko with: authUser -->
<!-- ko ifnot: $data.patreon -->
<p class="action-links">
<a href="/auth/patreon/plans" target="_blank"><%= t("modals.upgrade.btn1") %></a> / <a href="/auth/patreon"><%= t("modals.upgrade.btn2") %></a>
Expand Down

0 comments on commit b64bf22

Please sign in to comment.