Skip to content

Commit 9a2b6d6

Browse files
committed
Made default servers configurable via servers.json file in root directory.
1 parent 6b91f33 commit 9a2b6d6

File tree

6 files changed

+78
-13
lines changed

6 files changed

+78
-13
lines changed

Gruntfile.coffee

+11
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,15 @@ module.exports = (grunt) ->
364364
unicodedatajson:
365365
src: 'UnicodeData.json'
366366
dest: '.tmp/'
367+
serversjson:
368+
src: 'servers.json'
369+
dest: '.tmp/'
367370
unicodedatajsondist:
368371
src: 'UnicodeData.json'
369372
dest: 'dist/'
373+
serversjsondist:
374+
src: 'servers.json'
375+
dest: 'dist/'
370376
dist:
371377
files: [
372378
expand: true
@@ -384,6 +390,7 @@ module.exports = (grunt) ->
384390
'help/html/help.html'
385391
'./../package.json'
386392
'./../.tmp/UnicodeData.json'
393+
'./../.tmp/servers.json'
387394
'images/{,*/}*.{webp,gif,png,jpg}' # added png so that my jQuery images in /images would copy over, cf. imagemin headache
388395
'styles/fonts/{,*/}*.*'
389396
'bower_components/sass-bootstrap/fonts/*.*'
@@ -544,6 +551,7 @@ module.exports = (grunt) ->
544551
'copy:coffee'
545552
'copy:packagejson'
546553
'copy:unicodedatajson'
554+
'copy:serversjson'
547555
'coffee:serve'
548556
'coffee:test'
549557
#'createDefaultTemplate'
@@ -561,6 +569,7 @@ module.exports = (grunt) ->
561569
'copy:coffee'
562570
'copy:packagejson'
563571
'copy:unicodedatajson'
572+
'copy:serversjson'
564573
'coffee:serve'
565574
#'createDefaultTemplate'
566575
#'jst'
@@ -598,6 +607,7 @@ module.exports = (grunt) ->
598607
'copy:coffee' # copy all .coffee files in app/scripts/ to .tmp/scripts/
599608
'copy:packagejson'
600609
'copy:unicodedatajson'
610+
'copy:serversjson'
601611
'coffee:dist' # convert all .coffee files in .tmp/scripts to .js in situ
602612

603613
# eco: convert all .eco files in app/scripts/templates/ to .js files in
@@ -669,6 +679,7 @@ module.exports = (grunt) ->
669679
'copy:dist'
670680

671681
'copy:unicodedatajsondist'
682+
'copy:serversjsondist'
672683
]
673684

674685
grunt.registerTask 'default', ['jshint', 'test', 'build']

app/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
<title>Dative</title>
77
<meta name="description" content="">
88
<meta name="viewport" content="width=device-width, initial-scale=1">
9-
<!-- <link id="font-awesome-css" rel="stylesheet" type="text/css"
10-
href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.css"> -->
119
<link id="font-awesome-css" rel="stylesheet" type="text/css"
12-
href="/styles/font-awesome-4.4.0/css/font-awesome.css">
10+
href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.css">
11+
<!-- <link id="font-awesome-css" rel="stylesheet" type="text/css"
12+
href="/styles/font-awesome-4.4.0/css/font-awesome.css">-->
1313

1414
<!-- Enable dynamic loading of jquery ui themes by the user -->
1515
<link id="jquery-ui-css" rel="stylesheet"

app/scripts/models/application-settings.coffee

+9-4
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ define [
239239
JSON.parse(localStorage.getItem(@localStorageKey))
240240
applicationSettingsObject = @backbonify applicationSettingsObject
241241
@set applicationSettingsObject
242+
@usingDefaults = false
242243
else
244+
@usingDefaults = true
243245
@save()
244246

245247
# Logout
@@ -434,6 +436,8 @@ define [
434436

435437
defaults: ->
436438

439+
# Moving to specifying default servers at runtime using servers.json
440+
437441
server1Object = new FieldDB.Connection(FieldDB.Connection.defaultConnection('localhost'))
438442
server1 =
439443
new ServerModel
@@ -476,10 +480,11 @@ define [
476480
corpusServerURL: null
477481
website: 'http://www.onlinelinguisticdatabase.org'
478482

479-
if window.location.hostname in ["localhost", '127.0.0.1']
480-
servers = new ServersCollection([server1, server2, server3, server4])
481-
else
482-
servers = new ServersCollection([server3, server4])
483+
# if window.location.hostname in ["localhost", '127.0.0.1']
484+
# servers = new ServersCollection([server1, server2, server3, server4])
485+
# else
486+
# servers = new ServersCollection([server3, server4])
487+
servers = new ServersCollection([server2])
483488

484489
parserTaskSetModel = new ParserTaskSetModel()
485490

app/scripts/views/app.coffee

+44-5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ define [
6969
'./../models/page'
7070
'./../models/phonology'
7171
'./../models/search'
72+
'./../models/server'
7273
'./../models/source'
7374
'./../models/speaker'
7475
'./../models/subcorpus'
@@ -89,6 +90,7 @@ define [
8990
'./../collections/pages'
9091
'./../collections/phonologies'
9192
'./../collections/searches'
93+
'./../collections/servers'
9294
'./../collections/sources'
9395
'./../collections/speakers'
9496
'./../collections/subcorpora'
@@ -117,16 +119,16 @@ define [
117119
ApplicationSettingsModel, CollectionModel, ElicitationMethodModel, FileModel,
118120
FormModel, LanguageModelModel, LanguageModel, MorphologicalParserModel,
119121
MorphologyModel, OLDApplicationSettingsModel, OrthographyModel, PageModel,
120-
PhonologyModel, SearchModel, SourceModel, SpeakerModel, SubcorpusModel,
121-
SyntacticCategoryModel, TagModel, UserModel,
122+
PhonologyModel, SearchModel, ServerModel, SourceModel, SpeakerModel,
123+
SubcorpusModel, SyntacticCategoryModel, TagModel, UserModel,
122124

123125
CollectionsCollection, ElicitationMethodsCollection, FilesCollection,
124126
FormsCollection, LanguageModelsCollection, LanguagesCollection,
125127
MorphologicalParsersCollection, MorphologiesCollection,
126128
OrthographiesCollection, OLDApplicationSettingsCollection, PagesCollection,
127-
PhonologiesCollection, SearchesCollection, SourcesCollection,
128-
SpeakersCollection, SubcorporaCollection, SyntacticCategoriesCollection,
129-
TagsCollection, UsersCollection,
129+
PhonologiesCollection, SearchesCollection, ServersCollection,
130+
SourcesCollection, SpeakersCollection, SubcorporaCollection,
131+
SyntacticCategoriesCollection, TagsCollection, UsersCollection,
130132

131133
globals, appTemplate) ->
132134

@@ -146,6 +148,10 @@ define [
146148
initialize: (options) ->
147149
@preventParentScroll()
148150
@getApplicationSettings options
151+
@fetchServers()
152+
153+
# Continue initialization after fetching servers.json
154+
initializeContinue: ->
149155
globals.applicationSettings = @applicationSettings
150156
@overrideFieldDBNotificationHooks()
151157
@initializePersistentSubviews()
@@ -479,6 +485,39 @@ define [
479485
else
480486
@applicationSettings = new ApplicationSettingsModel()
481487

488+
# We have fetched the default servers array from the server hosting this
489+
# Dative.
490+
addDefaultServers: (serversArray) ->
491+
serverModelsArray = []
492+
for s in serversArray
493+
s.id = @guid()
494+
serverModelsArray.push(new ServerModel(s))
495+
serversCollection = new ServersCollection(serverModelsArray)
496+
activeServer = serversCollection.at 0
497+
@applicationSettings.set 'servers', serversCollection
498+
@applicationSettings.set 'activeServer', activeServer
499+
@applicationSettings.save()
500+
@initializeContinue()
501+
502+
# Fetch servers.json. This is a JSON object that contains an array of
503+
# server objects. This allows the default list of (OLD/FieldDB) servers
504+
# that this Dative knows about to be specified at runtime.
505+
fetchServers: ->
506+
if @applicationSettings.usingDefaults
507+
url = 'servers.json'
508+
$.ajax
509+
url: url
510+
type: 'GET'
511+
dataType: 'json'
512+
error: (jqXHR, textStatus, errorThrown) ->
513+
console.log "Ajax request for #{url} threw an error:
514+
#{errorThrown}"
515+
@initializeContinue()
516+
success: (serversArray, textStatus, jqXHR) =>
517+
@addDefaultServers serversArray
518+
else
519+
@initializeContinue()
520+
482521
# Size the #appview div relative to the window size
483522
matchWindowDimensions: ->
484523
@$('#appview').css height: $(window).height() - 50

app/scripts/views/server.coffee

-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ define [
126126
.tooltip content: 'make this server the active one'
127127

128128
activateServer: ->
129-
console.log 'activateServer of ServerView'
130129
# The ApplicationSettingsView changes the active server.
131130
Backbone.trigger 'activateServer', @model.get('id')
132131

servers.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[
2+
{
3+
"name": "OLD Local Development",
4+
"type": "OLD",
5+
"url": "http://127.0.0.1:5000",
6+
"serverCode": null,
7+
"corpusServerURL": null,
8+
"website": "http://www.onlinelinguisticdatabase.org"
9+
}
10+
]
11+

0 commit comments

Comments
 (0)