Skip to content

Commit

Permalink
Merge pull request #1761 from thostetler/fixup-routes
Browse files Browse the repository at this point in the history
Fix A few Routes
  • Loading branch information
thostetler authored Mar 21, 2019
2 parents a9fb382 + 0e25249 commit 8d2a665
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 87 deletions.
2 changes: 1 addition & 1 deletion src/discovery.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ require.config({
ShowAssociated: 'es6!js/widgets/associated/widget.jsx',
ShowRecommender: 'js/widgets/recommender/widget',
ShowMetrics: 'js/wraps/paper_metrics',
ShowPaperExport: 'js/wraps/paper_export',
ShowPaperexport: 'js/wraps/paper_export',
ShowLibraryAdd: 'js/wraps/abstract_page_library_add/widget',

IndividualLibraryWidget: 'js/widgets/library_individual/widget',
Expand Down
145 changes: 75 additions & 70 deletions src/js/apps/discovery/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function (
return app.getWidget('LandingPage').then(function (widget) {
widget.setActive('SearchWidget');
that.route = '';
that.title = '';
defer.resolve();
});
}
Expand All @@ -103,22 +104,25 @@ function (
// another function that sets a route
var that = this;
var defer = $.Deferred();
self.get('index-page').execute().then(function() {
var exec = _.bind(self.get('index-page').execute, this);
exec().then(function() {
that.route = '';
that.title = '';
defer.resolve();
})
});
return defer.promise();
});

this.set('404', function () {
var defer = $.Deferred();
var that = this;
app.getObject('MasterPageManager').show('ErrorPage').then(function() {
that.route = '404';
defer.resolve();
});
return defer.promise();
});


this.set('ClassicSearchForm', function () {
var defer = $.Deferred();
var that = this;
Expand All @@ -127,7 +131,7 @@ function (
that.route = '#classic-form';
that.title = 'Classic Form';
defer.resolve();
})
});
return defer.promise();
});

Expand All @@ -146,6 +150,7 @@ function (
this.set('LibraryImport', function (page, data) {
var that = this;
var defer = $.Deferred();
var that = this;
if (redirectIfNotSignedIn()) {
defer.resolve();
return defer.promise();
Expand All @@ -166,7 +171,6 @@ function (
return defer.promise();
});


function settingsPreferencesView(widgetName, defaultView, title) {
return function (page, data) {
var defer = $.Deferred();
Expand Down Expand Up @@ -223,71 +227,65 @@ function (
publishPageChange('libraries-page');
});
defer.resolve();
})
});
return defer.promise();
});

this.set('LibraryAdminView', function (widget) {
var defer = $.Deferred();
var that = this;
// this is NOT navigable from outside, so library already has data
// only setting a nav event to hide previous widgets
app.getWidget('IndividualLibraryWidget').done(function (widget) {
widget.setSubView({ subView: 'admin' });
app.getObject('MasterPageManager').show('LibrariesPage',
['IndividualLibraryWidget', 'UserNavbarWidget']).then(function() {
publishPageChange('libraries-page');
defer.resolve();
})
app.getObject('MasterPageManager').show('LibrariesPage',
['IndividualLibraryWidget', 'UserNavbarWidget']).then(function() {
app.getWidget('IndividualLibraryWidget').done(function (widget) {
widget.setSubView({ subView: 'admin' });
});
publishPageChange('libraries-page');
defer.resolve();
});

return defer.promise();
});

this.set('IndividualLibraryWidget', function (widget, data) {
var defer = $.Deferred();
var that = this;

if (redirectIfNotSignedIn()) {
return defer.resolve().promise();
}

// where view is an object in the form
// {subView: subView, id: id, publicView : false}

data.publicView = data.publicView ? data.publicView : false;

var that = this;
this.route = data.publicView ? '#/public-libraries/' + data.id : '#user/libraries/' + data.id;

app.getObject('LibraryController').getLibraryMetadata(data.id).done(function (metadata) {
data.editRecords = _.contains(['write', 'admin', 'owner'], metadata.permission) && !data.publicView;
that.title = data.publicView ? 'Public' : 'Private' + ' Library | ' + metadata.name;
// inform library list widget about the data
app.getWidget('LibraryListWidget').done(function (widget) {
widget.setData(data);

if (data.publicView) {
app.getWidget('IndividualLibraryWidget').done(function (widget) {
widget.setSubView(data);
// then, show library page manager
app.getObject('MasterPageManager').show('PublicLibrariesPage',
['IndividualLibraryWidget', 'LibraryListWidget']).then(function() {
defer.resolve();
});
});
}
// make sure user is signed in
else if (!redirectIfNotSignedIn()) {
app.getWidget('IndividualLibraryWidget').done(function (widget) {
widget.setSubView(data);
app.getObject('MasterPageManager').show('LibrariesPage',
['IndividualLibraryWidget', 'LibraryListWidget', 'UserNavbarWidget']).then(function() {
publishPageChange('libraries-page');
defer.resolve();
});
});
}
else {
var pub = data.publicView;

app.getObject('MasterPageManager').show(
pub ? 'PublicLibrariesPage' : 'LibrariesPage',
pub ?
['IndividualLibraryWidget', 'LibraryListWidget']
: ['IndividualLibraryWidget', 'LibraryListWidget', 'UserNavbarWidget']
).then(function () {

app.getObject('LibraryController').getLibraryMetadata(data.id).done(function (metadata) {
data.editRecords = _.contains(['write', 'admin', 'owner'], metadata.permission) && !data.publicView;
that.title = data.publicView ? 'Public' : 'Private' + ' Library | ' + metadata.name;

app.getWidget('LibraryListWidget', 'IndividualLibraryWidget').then(function (w) {
w['LibraryListWidget'].setData(data);
w['IndividualLibraryWidget'].setSubView(data);
if (pub) publishPageChange('libraries-page');

defer.resolve();
}
});
});
});
return defer.promise();

return defer.promise();
});

// for external widgets shown by library
Expand Down Expand Up @@ -379,9 +377,12 @@ function (

this.set('home-page', function () {
var defer = $.Deferred();
var that = this;
app.getObject('MasterPageManager').show('HomePage',
[]).then(function() {
publishPageChange('home-page');
that.title = '';
that.route = '';
defer.resolve();
})
return defer.promise();
Expand Down Expand Up @@ -847,7 +848,7 @@ function (
var q = app.getObject('AppStorage').getCurrentQuery();
if (!q && options.q) {
q = options.q;
} else {
} else if (!q && !options.q) {
return defer.resolve().promise();
}
publishFeedback({ code: ApiFeedback.CODES.MAKE_SPACE });
Expand Down Expand Up @@ -979,18 +980,12 @@ function (
that.title = doc.title && doc.title[0];
}

// we can grab the current title from storage and just add our prefix from there
var title = that.title || app.getObject('AppStorage').getDocumentTitle();
var prefix = 'Abstract';
if (title && title.indexOf(prefix) === -1) {
that.title = prefix + ' | ' + title;
}

that.route = data.href;
defer.resolve();
});
return defer.promise();
});

this.set('ShowCitations', function (id, data) {
var defer = $.Deferred(),
that = this;
Expand All @@ -1012,6 +1007,7 @@ function (
});
return defer.promise();
});

this.set('ShowReferences', function (id, data) {
var defer = $.Deferred(),
that = this;
Expand All @@ -1032,6 +1028,7 @@ function (
});
return defer.promise();
});

this.set('ShowCoreads', function (id, data) {
var defer = $.Deferred(),
that = this;
Expand All @@ -1052,6 +1049,7 @@ function (
});
return defer.promise();
});

this.set('ShowSimilar', function (id, data) {
var defer = $.Deferred(),
that = this;
Expand All @@ -1072,6 +1070,7 @@ function (
});
return defer.promise();
});

this.set('ShowTableofcontents', function (id, data) {
var defer = $.Deferred(),
that = this;
Expand All @@ -1092,6 +1091,7 @@ function (
});
return defer.promise();
});

this.set('ShowMetrics', function (id, data) {
var defer = $.Deferred(),
that = this;
Expand All @@ -1112,26 +1112,30 @@ function (
})
return defer.promise();
});
this.set('ShowPaperExport', function (id, data) {

this.set('ShowPaperexport', function (id, data) {
var defer = $.Deferred(),
that = this;
showDetail([id].concat(detailsPageAlwaysVisible), id).then(function (w) {
if (data.bibcode) {
self.getPubSub().publish(self.getPubSub().DISPLAY_DOCUMENTS, new ApiQuery({ q: 'bibcode:' + data.bibcode }));
}
w.setActive(id);

// we can grab the current title from storage and just add our prefix from there
var title = app.getObject('AppStorage').getDocumentTitle();
var prefix = 'Export Citation';
if (title && title.indexOf(prefix) === -1) {
that.title = prefix + ' | ' + title;
}
that.route = data.href;
defer.resolve();
});
// the default subView should be `default`
var format = data.subView || 'default';
app.getObject('MasterPageManager').show('DetailsPage',
[id].concat(detailsPageAlwaysVisible)).done(function() {
app.getWidget('DetailsPage').done(function (w) {
if (data.bibcode) {
self.getPubSub().publish(self.getPubSub().DISPLAY_DOCUMENTS, new ApiQuery({ q: 'bibcode:' + data.bibcode }));

// guarantees the bibcode is set on the widget
w.widgets[id].ingestBroadcastedPayload(_.pick(data, 'bibcode'));
w.setActive(id, format);
}
that.route = data.href;
defer.resolve();
});
});
return defer.promise();
});

this.set('ShowGraphics', function (id, data) {
var defer = $.Deferred(),
that = this;
Expand All @@ -1145,6 +1149,7 @@ function (
});
return defer.promise();
});

this.set('show-author-affiliation-tool', function (id, options) {
var defer = $.Deferred(),
that = this;
Expand All @@ -1163,7 +1168,7 @@ function (
that.route = '#search/' + queryUpdater.clean(q).url();
defer.resolve();
});
})
});
return defer.promise();
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function (
if (_.isUndefined(title) || title === false) return;
var currTitle = this.storage.getDocumentTitle();
var setDocTitle = _.bind(function (t) {
document.title = t + TITLE_SEP + APP_TITLE;
document.title = t === '' ? APP_TITLE : t + TITLE_SEP + APP_TITLE;
this.storage.setDocumentTitle(t);
}, this);

Expand Down
2 changes: 1 addition & 1 deletion src/js/widgets/library_individual/views/library_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ define([
var data = this.model.toJSON();
data.date_last_modified = this.formatDate(data.date_last_modified);
data.date_created = this.formatDate(data.date_created);
if (this.model.get('num_documents') >= 2000) {
if (this.model.get('num_documents') >= 200) { // careful, must be lower than server GET limits (incl all other headers that we are sending)
// show a warning when user exports library that it might take a while
data.largeLibrary = true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/js/widgets/library_list/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ define([
'libraryID': data.id,
'editRecords': data.editRecords
});
this.dispatchRequest();
},

initialize: function (options) {
Expand Down Expand Up @@ -228,7 +229,7 @@ define([
},

onShow: function () {
this.dispatchRequest();

},

composeRequest: function (apiQuery) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<div data-widget="ShowSimilar"/>
<div data-widget="ShowTableofcontents"/>
<div data-widget="ShowGraphics" />
<div data-widget="ShowPaperExport" data-origin="abstract"/>
<div data-widget="ShowPaperexport" data-origin="abstract"/>
<div data-widget="ShowMetrics" data-allow-redirect="false"/>
<div data-widget="MetaTagsWidget"></div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/js/wraps/abstract_page_manager/abstract_page_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ define([
category: 'view',
order: 7
},
ShowPaperExport__default: {
ShowPaperexport__default: {
title: 'Export',
path: 'export',
path: 'paperexport',
category: 'export',
alwaysThere: 'true',
order: 8
Expand Down
Loading

0 comments on commit 8d2a665

Please sign in to comment.