Skip to content

Commit

Permalink
Make Astronomy and Physics the default databases for new searches
Browse files Browse the repository at this point in the history
This only applies if:

1. User is NOT logged in, and so has not updated their preferences
2. User is logged in but has not set their default database (or is still the default of none selected).
  • Loading branch information
thostetler committed Jan 9, 2024
1 parent 55e6b75 commit 31214c0
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 146 deletions.
48 changes: 26 additions & 22 deletions src/js/widgets/preferences/views/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ define([
'marionette',
'hbs!js/widgets/preferences/templates/application',
'js/widgets/config',
], function(_, Marionette, ApplicationTemplate, config) {
], function (_, Marionette, ApplicationTemplate, config) {
var DEFAULTS = {
numAuthors: {
initialOptions: _.range(1, 11).concat(['all']),
Expand Down Expand Up @@ -31,6 +31,10 @@ define([
name: 'General',
value: false,
},
{
name: 'Earth Science',
value: false,
},
],
},
hideSidebars: {
Expand All @@ -48,7 +52,7 @@ define([
];

var ApplicationView = Marionette.ItemView.extend({
initialize: function() {
initialize: function () {
// Get the latest value from the incoming model, or just take the default
var numAuthors =
this.model.get('minAuthorsPerResult') ||
Expand Down Expand Up @@ -98,7 +102,7 @@ define([
change: 'render',
},

onDatabaseSelect: function(e) {
onDatabaseSelect: function (e) {
var data = this.model.get('databaseSelected');

// find the current index of the element
Expand All @@ -111,33 +115,33 @@ define([

// place our new value in the array
var newData = data
.slice(0, idx)
.concat(newVal)
.concat(data.slice(idx + 1));
.slice(0, idx)
.concat(newVal)
.concat(data.slice(idx + 1));
this.model.set('databaseSelected', newData);
this.model.trigger('change');
},

_convertToNumber: function(val) {
_convertToNumber: function (val) {
try {
return _.isNaN(Number(val)) ? val : Number(val);
} catch (e) {
return val;
}
},

_convertToString: function(val) {
_convertToString: function (val) {
try {
return String(val) !== '[object Object]' ? String(val) : val;
} catch (e) {
return val;
}
},

syncModel: function() {
syncModel: function () {
var update = {};
var convert = this._convertToNumber;
$('.form-control', this.el).each(function() {
$('.form-control', this.el).each(function () {
var $el = $(this);
var val = $el.val();

Expand All @@ -149,7 +153,7 @@ define([
this.model.set(update);
},

onSubmit: function() {
onSubmit: function () {
this.model.set({
updateSucceeded: false,
updateFailed: false,
Expand All @@ -158,7 +162,7 @@ define([
this.syncModel();
this.trigger('change:applicationSettings', {
minAuthorsPerResult: this._convertToString(
this.model.get('numAuthorsSelected')
this.model.get('numAuthorsSelected'),
),
externalLinkAction: this.model.get('externalLinksSelected'),
defaultDatabase: this.model.get('databaseSelected'),
Expand All @@ -168,12 +172,12 @@ define([
return false;
},

onCancel: function(e) {
onCancel: function (e) {
this.initialize();
return false;
},

onResetToDefaults: function() {
onResetToDefaults: function () {
// clear the model
this.model.set(
{
Expand All @@ -184,13 +188,13 @@ define([
},
{
unset: true,
}
},
);

this.onCancel.apply(this, arguments);
},

onError: function() {
onError: function () {
var model = this.model;
model.set({
updateFailed: true,
Expand All @@ -204,7 +208,7 @@ define([
}, 5000);
},

onSuccess: function() {
onSuccess: function () {
var model = this.model;
model.set({
updateSucceeded: true,
Expand All @@ -218,13 +222,13 @@ define([
}, 3000);
},

hideMessage: function() {
$('#app-settings-msg').fadeOut(500, function() {
hideMessage: function () {
$('#app-settings-msg').fadeOut(500, function () {
$(this).empty();
});
},

onSortChange: function(e, ui) {
onSortChange: function (e, ui) {
var items = _.clone(this.model.get('addCustomFormatOptions'));
var index = this.$('#addCustomFormat .list-group-item').index(ui.item);
var id = this.$(ui.item).data('id');
Expand All @@ -240,13 +244,13 @@ define([
this.model.set('addCustomFormatOptions', items);
},

isEditing: function() {
isEditing: function () {
return _.any(this.model.get('addCustomFormatOptions'), {
editing: true,
});
},

onRender: function() {
onRender: function () {
var onSortChange = _.bind(this.onSortChange, this);
setTimeout(() => {
$('#addCustomFormat').sortable({
Expand Down

0 comments on commit 31214c0

Please sign in to comment.