Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Orcid Mode Timeout #1518

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/js/modules/orcid/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ function (
var action = data.action;
var orcidApi = this.getBeeHive().getService('OrcidApi');
var oldOrcid = _.clone(data.model.get('orcid') || {});
var pubsub = this.getPubSub();
pubsub.publish(pubsub.CUSTOM_EVENT, 'orcid-action', action);

var handlers = {
'orcid-add': function (model) {
Expand Down
62 changes: 38 additions & 24 deletions src/js/widgets/navbar/widget.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
define([
'underscore',
'marionette',
'js/widgets/base/base_widget',
'hbs!js/widgets/navbar/template/navbar',
Expand All @@ -9,6 +10,7 @@ define([
'js/components/api_targets',
'bootstrap'
], function (
_,
Marionette,
BaseWidget,
NavBarTemplate,
Expand All @@ -31,7 +33,8 @@ define([
orcidFirstName: undefined,
orcidLastName: undefined,
//should it show hourly banner?
hourly: false
hourly: false,
timeout: 600000 // 10 minutes
}
}
});
Expand Down Expand Up @@ -90,25 +93,11 @@ define([
this.trigger("user-change-orcid-mode");
},

changeOrcidMode: function () {
var that = this;
//allow animation to run before rerendering
setTimeout(function () {

if (that.$(".orcid-mode").is(":checked")) {
that.model.set("orcidModeOn", true);
}
else {
that.model.set("orcidModeOn", false);
}

//need to explicitly trigger to widget that this has changed
//otherwise it will be ignored, since it can also be changed
//from outside
that.trigger("user-change-orcid-mode");

that.render();
}, 400);
changeOrcidMode: function (ev) {
var checked = _.isBoolean(ev) ? ev : ev && ev.currentTarget && ev.currentTarget.checked;
this.model.set('orcidModeOn', checked);
this.trigger('user-change-orcid-mode');
this.render();
},

onRender: function () {
Expand Down Expand Up @@ -156,19 +145,42 @@ define([

activate: function (beehive) {
this.setBeeHive(beehive);
_.bindAll(this, ["handleUserAnnouncement", "getOrcidUserInfo", "storeLatestPage"]);
_.bindAll(this, ["handleUserAnnouncement", "getOrcidUserInfo", "storeLatestPage", 'onCustomEvent']);
var pubsub = this.getPubSub();
pubsub.subscribe(pubsub.USER_ANNOUNCEMENT, this.handleUserAnnouncement);
pubsub.subscribe(pubsub.APP_STARTED, this.getOrcidUserInfo);
pubsub.subscribe(pubsub.NAVIGATE, this.storeLatestPage)
pubsub.subscribe(pubsub.NAVIGATE, this.storeLatestPage);
pubsub.subscribe(pubsub.CUSTOM_EVENT, this.onCustomEvent);
this.setInitialVals();
if (!this.model.get('timer')) {
this.resetOrcidTimer();
}
},

onCustomEvent: function (ev) {
if (ev === 'orcid-action') {
this.resetOrcidTimer();
}
},

storeLatestPage : function(page){
//to know whether to orcid redirect
this._latestPage = page;
},

resetOrcidTimer: function () {
var timer = this.model.get('timer');
var timeout = this.model.get('timeout');
if (timer) {
clearTimeout(timer);
}

// only start the timer if orcid mode is actually on
if (this.model.get('orcidModeOn')) {
timer = setTimeout(_.bind(this.toggleOrcidMode, this, false), timeout);
this.model.set('timer', timer);
}
},

viewEvents: {
//dealing with authentication/user
Expand Down Expand Up @@ -307,19 +319,21 @@ define([
//we don't want to respond to changes from pubsub or user object with this,
//only changes that the user has initiated using the navbar widget,
//otherwise things will be toggled incorrectly
toggleOrcidMode: function () {
toggleOrcidMode: function (val) {
var user = this.getBeeHive().getObject('User'),
orcidApi = this.getBeeHive().getService("OrcidApi");

var newVal = this.model.get("orcidModeOn");
var newVal = _.isBoolean(val) ? val : this.model.get("orcidModeOn");
user.setOrcidMode(newVal);
this.model.set('orcidModeOn', newVal);

if (newVal) {
//sign into orcid api if not signed in already
if (!orcidApi.hasAccess()) {
orcidApi.signIn();
}
}
this.resetOrcidTimer();
},

searchAuthor: function () {
Expand Down