Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit dfae0ba

Browse files
committed
Merge branch 'server-configs' of https://github.com/rmisio/OpenBazaar-Client into rmisio-server-configs
2 parents c32985b + 1263477 commit dfae0ba

34 files changed

+1137
-609
lines changed

css/obBase.css

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,14 @@ h5 {
14191419
padding-top: 70px;
14201420
}
14211421
1422+
.modal-cover-fullscreen {
1423+
top: 0;
1424+
}
1425+
1426+
.modal-cover-fullscreen .modal-childMain {
1427+
top: 50px;
1428+
}
1429+
14221430
.modal-childMain {
14231431
border-radius: 3px;
14241432
background-color: #327eb8;
@@ -4200,14 +4208,66 @@ input[type="checkbox"].fieldItem:checked + label .togLabelOff {
42004208
z-index: 9;
42014209
}
42024210
4203-
#loadingModal {
4211+
#loadingModal, .page-connect-modal.startup-server-connect {
42044212
z-index: 14;
42054213
}
42064214
4207-
.server-connect-modal {
4215+
#ov1 .server-connect-modal {
42084216
z-index: 15;
42094217
}
42104218
4219+
#ov1 .server-connect-modal .modal-child {
4220+
height: 625px;
4221+
overflow: hidden;
4222+
}
4223+
4224+
#ov1 .server-connect-modal .message-bar {
4225+
top: 50px;
4226+
left: 25px;
4227+
right: 25px;
4228+
z-index: 1;
4229+
transition: top .2s, opacity .2s;
4230+
}
4231+
4232+
#ov1 .server-connect-modal .message-bar > div {
4233+
background-color: red;
4234+
padding: 8px 10px;
4235+
line-height: 2.2;
4236+
display: inline-block;
4237+
}
4238+
4239+
#ov1 .server-connect-modal .message-bar .message-bar-close {
4240+
top: -12px;
4241+
right: -3px;
4242+
}
4243+
4244+
#ov1 .server-connect-modal .message-bar.slide-out {
4245+
top: -45px;
4246+
opacity: 0;
4247+
}
4248+
4249+
#ov1 .server-config-form {
4250+
transition: top 250ms;
4251+
}
4252+
4253+
#ov1 .server-config-form.slide-out {
4254+
top: 372px;
4255+
}
4256+
4257+
#ov1 .server-config-row {
4258+
/*min-height: 73px;*/
4259+
}
4260+
4261+
#ov1 .server-config-row .connection-failed::after {
4262+
content: '';
4263+
position: absolute;
4264+
width: 10px;
4265+
background-color: red;
4266+
top: 0;
4267+
left: 0;
4268+
bottom: 0;
4269+
}
4270+
42114271
#loadingModal .btn {
42124272
-webkit-app-region: no-drag;
42134273
}
@@ -4572,6 +4632,15 @@ input[type="checkbox"].fieldItem:checked + label .togLabelOff {
45724632
overflow-x: hidden;
45734633
}
45744634

4635+
#ov1 .autoOverflowYHideX {
4636+
overflow-y: auto;
4637+
overflow-x: hidden;
4638+
}
4639+
4640+
4641+
#ov1 .vertAlignMid {
4642+
vertical-align: middle;
4643+
}
45754644

45764645
#ov1 .vCentered {
45774646
/* must be inside a relatively positioned containing element */
@@ -5192,8 +5261,6 @@ input[type="checkbox"].fieldItem:checked + label .togLabelOff {
51925261
height: 46px;
51935262
}
51945263

5195-
5196-
51975264
#ov1 .height30 {
51985265
height: 30px;
51995266
line-height: 30px;
@@ -5684,6 +5751,13 @@ input[type="checkbox"].fieldItem:checked + label .togLabelOff {
56845751
display: block;
56855752
}
56865753

5754+
#ov1 .marginCenter {
5755+
margin-left: auto;
5756+
margin-right: auto;
5757+
}
5758+
5759+
5760+
56875761
#ov1 .heightAuto {
56885762
height: auto;
56895763
}

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ <h2 class="txt-center">
7676
<div id="statusBar"></div>
7777
<div id="pageNav" class="bar navBar navBar-main custCol-secondary padding0"></div>
7878
<!-- the loading modal must be on top of the page nav or the reload button is hidden -->
79-
<div id="loadingModal" class="modal modal-opaque js-loadingModal top0">
79+
<div id="loadingModal" class="modal modal-opaque js-loadingModal top0 hide">
8080
<div class="spinner-with-logo fullCentered">
8181
<i class="ion-android-sync spinner fontSize30 spinner-with-logo-icon"></i>
8282
</div>

js/App.js

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var ipcRenderer = require('ipc-renderer'),
2-
Socket = require('./utils/Socket'),
2+
Polyglot = require('node-polyglot'),
3+
__ = require('underscore'),
34
$ = require('jquery'),
4-
ServerConfigMd = require('./models/serverConfigMd'),
5+
Socket = require('./utils/Socket'),
56
_app;
67

78
function App() {
@@ -15,55 +16,42 @@ function App() {
1516
this._notifUnread = 0;
1617
this._chatMessagesUnread = 0;
1718

18-
// TODO: what is wrong with the localStorage adapter??? shouldn't need
19-
// to manually provide the data to the model. All that should be needed
20-
// is an ID and then a subsequent fetch, but that doesn't return the data.
21-
// Investigate!
22-
this.serverConfig = new ServerConfigMd( JSON.parse(localStorage['_serverConfig-1'] || '{}') );
23-
24-
// serverConfigMd.fetch();
25-
if (!localStorage['_serverConfig-1']) {
26-
this.serverConfig.save();
27-
}
28-
29-
this.connectHeartbeatSocket();
30-
}
19+
// TODO: rather than attach the serverConfigs CL
20+
// in main.js, pass in the instance here so the
21+
// dependency is more explicit.
22+
};
3123

3224
App.prototype.connectHeartbeatSocket = function() {
33-
var self = this;
25+
var activeServer = this.serverConfigs.getActive();
3426

35-
clearTimeout(this.heartbeatSocketTimesup);
27+
if (!activeServer) {
28+
throw new Error(`No active server set. Please set via the Server Configs collection.`);
29+
}
3630

3731
if (this._heartbeatSocket) {
38-
this._heartbeatSocket.connect(this.serverConfig.getHeartbeatSocketUrl());
32+
this._heartbeatSocket.connect(activeServer.getHeartbeatSocketUrl());
3933
} else {
40-
this._heartbeatSocket = new Socket(this.serverConfig.getHeartbeatSocketUrl());
41-
42-
this._heartbeatSocket.on('close', function() {
43-
clearTimeout(self._heartbeatSocketTimesup);
44-
});
34+
this._heartbeatSocket = new Socket(activeServer.getHeartbeatSocketUrl());
4535
}
46-
47-
// give up if it takes to long
48-
this._heartbeatSocketTimesup = setTimeout(function() {
49-
if (self._heartbeatSocket.getReadyState() !== 1) {
50-
//self._heartbeatSocket._socket.close(); //turn off for now, until server issues are fixed
51-
alert(polyglot.t('errorMessages.serverTimeout'));
52-
}
53-
}, 30000); //wait for 30 seconds, sometimes the server stalls
5436
};
5537

5638
App.prototype.getHeartbeatSocket = function() {
5739
return this._heartbeatSocket;
5840
};
5941

6042
App.prototype.login = function() {
43+
var activeServer = this.serverConfigs.getActive();
44+
45+
if (!activeServer) {
46+
throw new Error(`No active server set. Please set via the Server Configs collection.`);
47+
}
48+
6149
return $.ajax({
62-
url: this.serverConfig.getServerBaseUrl() + '/login',
50+
url: activeServer.getServerBaseUrl() + '/login',
6351
method: 'POST',
6452
data: {
65-
username: this.serverConfig.get('username'),
66-
password: this.serverConfig.get('password')
53+
username: activeServer.get('username'),
54+
password: activeServer.get('password')
6755
},
6856
timeout: 3000
6957
});
@@ -148,7 +136,4 @@ App.getApp = function() {
148136
return _app;
149137
};
150138

151-
152-
module.exports = App;
153-
154-
139+
module.exports = App;

js/collections/chatConversationsCl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var Backbone = require('backbone'),
44

55
module.exports = Backbone.Collection.extend({
66
url: function() {
7-
return app.serverConfig.getServerBaseUrl() + '/get_chat_conversations';
7+
return app.serverConfigs.getActive().getServerBaseUrl() + '/get_chat_conversations';
88
},
99

1010
model: ChatConversationMd,

js/collections/chatMessagesCl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var Backbone = require('backbone'),
44

55
module.exports = Backbone.Collection.extend({
66
url: function() {
7-
return app.serverConfig.getServerBaseUrl() + '/get_chat_messages';
7+
return app.serverConfigs.getActive().getServerBaseUrl() + '/get_chat_messages';
88
},
99

1010
model: ChatMessageMd,

js/collections/notificationsCl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var Backbone = require('backbone'),
55

66
module.exports = Backbone.Collection.extend({
77
url: function() {
8-
return app.serverConfig.getServerBaseUrl() + '/get_notifications';
8+
return app.serverConfigs.getActive().getServerBaseUrl() + '/get_notifications';
99
},
1010

1111
model: NotificationMd,

js/collections/ratingCl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var __ = require('underscore'),
55

66
module.exports = Backbone.Collection.extend({
77
url: function() {
8-
return app.serverConfig.getServerBaseUrl() + '/get_ratings';
8+
return app.serverConfigs.getActive().getServerBaseUrl() + '/get_ratings';
99
},
1010

1111
model: RatingMd,

js/collections/serverConfigsCl.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var Backbone = require('backbone'),
2+
localStorageSync = require('../utils/backboneLocalStorage'),
3+
ServerConfigMd = require('../models/serverConfigMd');
4+
5+
module.exports = Backbone.Collection.extend({
6+
sync: localStorageSync.sync,
7+
localStorage: new localStorageSync('__serverConfig'),
8+
model: ServerConfigMd,
9+
10+
getActive: function() {
11+
var config = this.get(localStorage.activeServer);
12+
13+
if (!config && this.length) {
14+
config = this.at(this.length - 1);
15+
this.setActive(config.id);
16+
}
17+
18+
return config;
19+
},
20+
21+
setActive: function(id) {
22+
var md;
23+
24+
if (!(md = this.get(id))) {
25+
throw new Error(`Unable to set the active server config. It must be an id of one of the available
26+
server configs stored in this collection.`)
27+
}
28+
29+
if (this._active !== id) {
30+
this._active = id;
31+
localStorage.activeServer = id;
32+
this.trigger('activeServerChange', md);
33+
}
34+
}
35+
});

js/languages/en-US.json

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"of": "of",
2525
"Sell": "Sell",
2626
"New": "New",
27+
"Retry": "Retry",
2728
"HighlightToStyle": "Highlight text to style",
2829
"Excellent": "Excellent",
2930
"Good": "Good",
@@ -666,23 +667,29 @@
666667
"noSearchResultsFound": "No results found"
667668
},
668669
"serverConnectModal": {
669-
"statusTryingToConnect": "Trying to connect to your server...",
670-
"statusConnected": "Connected.",
671-
"statusFailedConnection": "Unable to connect to your server",
672-
"statusFailedAuthentication": "Authentication failed",
673-
"statusTooManyAttempts": "Too many failed login attempts",
670+
"connect": "Connect",
671+
"connected": "Connected",
672+
"connecting": "Connecting",
674673
"serverConfiguration": "Server Configuration",
675-
"connecting": "Connecting...",
676674
"intro": "OpenBazaar is designed to allow you to host your server separate from the client. By default, your server will run locally, but you can override it below.",
677675
"serverIP": "Server IP",
678676
"restApiPort": "Rest API port",
679677
"websocketApiPort": "Websocket API port",
680678
"heartbeatSocketApiPort": "Heartbeat socket port",
681679
"username": "Username",
682680
"password": "Password",
683-
"restoreDefaults": "Restore defaults",
684681
"saveChanges": "Save Changes",
685-
"retry": "Retry connection"
682+
"defaultServerName": "default",
683+
"connectionFailed": "Connection failed to %{serverName}",
684+
"connectingTo": "Connecting to %{serverName}",
685+
"connectingToDefault": "Connecting to the default server",
686+
"authFailed": "authentication failed",
687+
"authFailedTooManyAttempts": "too many failed authentication attempts",
688+
"serverConfigsHeaderMsg": "Your Server Configurations",
689+
"newConfigHeaderMsg": "Enter Server Details",
690+
"editConfigHeaderMsg": "Configuration Settings",
691+
"serverConfigsTitle": "Server Configurations",
692+
"newConfigTitle": "New Configuration"
686693
},
687694
"timezones": {
688695
"-12": "(GMT -12:00) Eniwetok, Kwajalein",

0 commit comments

Comments
 (0)