lanes 0.1.9.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Rakefile +1 -1
- data/client/lanes/Boot.cjsx +3 -3
- data/client/lanes/Config.coffee +38 -3
- data/client/lanes/access/Extension.coffee +1 -1
- data/client/lanes/access/LoginDialog.cjsx +57 -47
- data/client/lanes/access/Roles.coffee +2 -2
- data/client/lanes/access/User.coffee +4 -3
- data/client/lanes/access/screens/user-management/UserManagement.cjsx +12 -11
- data/client/lanes/components/calendar/Calendar.cjsx +16 -0
- data/client/lanes/components/calendar/index.js +3 -0
- data/client/lanes/components/calendar/styles.scss +3 -0
- data/client/lanes/components/grid/Body.cjsx +86 -0
- data/client/lanes/components/grid/CellStyles.coffee +20 -0
- data/client/lanes/components/grid/EditingMixin.cjsx +84 -24
- data/client/lanes/components/grid/Editor.cjsx +45 -0
- data/client/lanes/components/grid/Grid.cjsx +62 -104
- data/client/lanes/components/grid/Header.cjsx +35 -0
- data/client/lanes/components/grid/PopOverMixin.cjsx +19 -9
- data/client/lanes/components/grid/PopoverEditor.cjsx +7 -1
- data/client/lanes/components/grid/RowEditor.cjsx +1 -1
- data/client/lanes/components/grid/Selections.cjsx +39 -0
- data/client/lanes/components/grid/Toolbar.cjsx +24 -5
- data/client/lanes/components/grid/editors.scss +22 -50
- data/client/lanes/components/grid/index.js +0 -1
- data/client/lanes/components/grid/row-editor.scss +68 -0
- data/client/lanes/components/grid/styles.scss +79 -3
- data/client/lanes/components/modal/Modal.cjsx +64 -24
- data/client/lanes/components/modal/styles.scss +12 -0
- data/client/lanes/components/record-finder/Clause.cjsx +11 -4
- data/client/lanes/components/record-finder/Dialog.cjsx +23 -24
- data/client/lanes/components/record-finder/RecordFinder.cjsx +45 -14
- data/client/lanes/components/record-finder/styles.scss +9 -6
- data/client/lanes/components/select-field/SelectField.cjsx +108 -53
- data/client/lanes/components/select-field/styles.scss +19 -0
- data/client/lanes/components/shared/ControlLabel.cjsx +45 -0
- data/client/lanes/components/shared/DateTime.cjsx +48 -0
- data/client/lanes/components/shared/DisplayValue.cjsx +16 -0
- data/client/lanes/components/shared/FieldMixin.cjsx +54 -23
- data/client/lanes/components/shared/FieldSet.cjsx +12 -35
- data/client/lanes/components/shared/FieldWrapper.cjsx +13 -0
- data/client/lanes/components/shared/FormGroup.cjsx +37 -0
- data/client/lanes/components/shared/Icon.cjsx +20 -0
- data/client/lanes/components/shared/ImageSaver.cjsx +33 -0
- data/client/lanes/components/shared/Input.cjsx +19 -0
- data/client/lanes/components/shared/InputFieldMixin.cjsx +48 -0
- data/client/lanes/components/shared/JobProgress.cjsx +27 -0
- data/client/lanes/components/shared/NetworkActivityOverlay.cjsx +58 -0
- data/client/lanes/components/shared/NumberInput.cjsx +29 -0
- data/client/lanes/components/shared/ResizeSensor.cjsx +11 -0
- data/client/lanes/components/shared/ScreenWrapper.cjsx +13 -0
- data/client/lanes/components/shared/Throbber.cjsx +3 -0
- data/client/lanes/components/shared/ToggleField.cjsx +33 -0
- data/client/lanes/components/shared/Tooltip.cjsx +2 -2
- data/client/lanes/components/shared/fields.scss +75 -13
- data/client/lanes/components/shared/fieldset.scss +3 -5
- data/client/lanes/components/shared/image-saver.scss +38 -0
- data/client/lanes/components/shared/index.js +2 -0
- data/client/lanes/{styles/plugins → components/shared}/overlay.scss +17 -4
- data/client/lanes/components/shared/resize-sensor.scss +30 -0
- data/client/lanes/components/shared/styles.scss +13 -0
- data/client/lanes/components/shared/throbber.scss +53 -0
- data/client/lanes/components/toolbar/RemoteChangeSets.cjsx +21 -48
- data/client/lanes/components/toolbar/SaveButton.cjsx +24 -0
- data/client/lanes/components/toolbar/Toolbar.cjsx +24 -37
- data/client/lanes/components/toolbar/changes-notification.scss +10 -6
- data/client/lanes/components/toolbar/styles.scss +29 -9
- data/client/lanes/extension/Base.coffee +4 -5
- data/client/lanes/index.js +0 -1
- data/client/lanes/index.scss.erb +10 -1
- data/client/lanes/lib/HotReload.coffee +13 -15
- data/client/lanes/lib/MakeBaseClass.coffee +6 -1
- data/client/lanes/lib/development.coffee +2 -0
- data/client/lanes/lib/dom-polyfills.coffee +5 -0
- data/client/lanes/lib/dom.coffee +38 -9
- data/client/lanes/lib/format.coffee +11 -0
- data/client/lanes/lib/index.js.erb +2 -0
- data/client/lanes/lib/production.coffee +6 -0
- data/client/lanes/lib/utilFunctions.coffee +50 -15
- data/client/lanes/models/AssociationMap.coffee +122 -46
- data/client/lanes/models/AssociationProxy.coffee +147 -0
- data/client/lanes/models/Base.coffee +97 -85
- data/client/lanes/models/ChangeMonitor.coffee +7 -3
- data/client/lanes/models/ChangeSet.coffee +2 -2
- data/client/lanes/models/Collection.coffee +49 -6
- data/client/lanes/models/JobStatus.coffee +32 -0
- data/client/lanes/models/PubSub.coffee +7 -5
- data/client/lanes/models/Query.coffee +115 -34
- data/client/lanes/models/ServerCache.coffee +67 -52
- data/client/lanes/models/State.coffee +97 -0
- data/client/lanes/models/Sync.coffee +18 -13
- data/client/lanes/models/SystemSettings.coffee +0 -0
- data/client/lanes/models/index.js +1 -0
- data/client/lanes/models/mixins/FileSupport.coffee +60 -0
- data/client/lanes/models/mixins/HasCodeField.coffee +13 -6
- data/client/lanes/models/query/ArrayResult.coffee +188 -0
- data/client/lanes/models/query/CollectionResult.coffee +71 -0
- data/client/lanes/models/query/Result.coffee +9 -0
- data/client/lanes/react/Component.coffee +7 -3
- data/client/lanes/react/PubSub.coffee +7 -7
- data/client/lanes/react/Root.cjsx +1 -4
- data/client/lanes/react/Screen.coffee +1 -0
- data/client/lanes/react/TypeValidators.coffee +3 -3
- data/client/lanes/react/Viewport.coffee +41 -7
- data/client/lanes/react/index.js +0 -1
- data/client/lanes/react/mixins/Access.coffee +4 -1
- data/client/lanes/react/mixins/Data.coffee +40 -25
- data/client/lanes/react/mixins/FieldErrors.coffee +27 -0
- data/client/lanes/react/mixins/RelayEditingState.coffee +4 -0
- data/client/lanes/react/mixins/Screen.coffee +14 -0
- data/client/lanes/react/mixins/Viewport.coffee +9 -3
- data/client/lanes/screens/ChangeListener.coffee +3 -3
- data/client/lanes/screens/Commands.coffee +14 -7
- data/client/lanes/screens/CommonComponents.cjsx +20 -0
- data/client/lanes/screens/Definitions.coffee +64 -20
- data/client/lanes/screens/SystemSettings.cjsx +56 -0
- data/client/lanes/screens/UserPreferences.cjsx +38 -0
- data/client/lanes/screens/index.js +3 -0
- data/client/lanes/screens/styles.scss +2 -1
- data/client/lanes/styles/fonts.scss +1 -0
- data/client/lanes/styles/global.scss +2 -1
- data/client/lanes/styles/global/flexbox.scss +16 -0
- data/client/lanes/styles/global/styles.scss +1 -0
- data/client/lanes/styles/mixins/_dropdown.scss +21 -0
- data/client/lanes/styles/mixins/_flexbox.scss +394 -0
- data/client/lanes/styles/mixins/all.scss +2 -0
- data/client/lanes/styles/variables.scss +28 -0
- data/client/lanes/testing/BeforeEach.coffee +15 -14
- data/client/lanes/testing/Helpers.coffee +14 -5
- data/client/lanes/testing/TestObjects.coffee +10 -2
- data/client/lanes/testing/index.js +1 -0
- data/client/lanes/testing/jasmine-react.js +125 -0
- data/client/lanes/vendor/base.js +56049 -74987
- data/client/lanes/vendor/calendar.js +17301 -0
- data/client/lanes/vendor/calendar.scss +303 -0
- data/client/lanes/vendor/commons.js +14990 -15847
- data/client/lanes/vendor/development.js +4912 -1952
- data/client/lanes/vendor/grid.js +14246 -5551
- data/client/lanes/vendor/grid.scss +876 -335
- data/client/lanes/vendor/index.js +1 -0
- data/client/lanes/vendor/message-bus-ajax.js +44 -0
- data/client/lanes/vendor/message-bus.js +414 -0
- data/client/lanes/vendor/rw-widgets.eot +0 -0
- data/client/lanes/vendor/rw-widgets.svg +18 -0
- data/client/lanes/vendor/rw-widgets.ttf +0 -0
- data/client/lanes/vendor/rw-widgets.woff +0 -0
- data/client/lanes/vendor/toggle.js +345 -0
- data/client/lanes/vendor/toggle.scss +138 -0
- data/client/lanes/vendor/widgets.js +21245 -6839
- data/client/lanes/vendor/widgets.scss +83 -67
- data/client/lanes/workspace/Layout.cjsx +18 -8
- data/client/lanes/workspace/Modal.cjsx +47 -0
- data/client/lanes/workspace/Navbar.cjsx +16 -2
- data/client/lanes/workspace/ScreenView.cjsx +10 -3
- data/client/lanes/workspace/ScreensMenu.cjsx +23 -7
- data/client/lanes/workspace/Tabs.cjsx +55 -0
- data/client/lanes/workspace/UIState.coffee +7 -8
- data/client/lanes/workspace/index.js +2 -1
- data/client/lanes/workspace/mixin.coffee +11 -0
- data/client/lanes/workspace/mixins/UIState.coffee +8 -0
- data/client/lanes/workspace/mixins/index.js +3 -0
- data/client/lanes/workspace/styles.scss +2 -1
- data/client/lanes/workspace/styles/header.scss +23 -1
- data/client/lanes/workspace/styles/layout.scss +26 -24
- data/client/lanes/workspace/styles/screens.scss +0 -4
- data/client/lanes/workspace/styles/tabs.scss +3 -10
- data/config/routes.rb +10 -4
- data/config/screens.rb +25 -0
- data/db/migrate/01_create_system_settings.rb +10 -0
- data/docs/todo-example-part-1.md +18 -20
- data/lanes.gemspec +15 -6
- data/lib/lanes.rb +4 -2
- data/lib/lanes/access/config/routes.rb +5 -3
- data/lib/lanes/access/config/screens.rb +1 -0
- data/lib/lanes/access/db/migrate/20140615031600_create_lanes_users.rb +1 -1
- data/lib/lanes/access/user.rb +1 -1
- data/lib/lanes/api.rb +2 -1
- data/lib/lanes/api/controller.rb +32 -71
- data/lib/lanes/api/default_routes.rb +10 -8
- data/lib/lanes/api/formatted_reply.rb +53 -0
- data/lib/lanes/api/handlers/file.rb +26 -0
- data/lib/lanes/api/helper_methods.rb +29 -5
- data/lib/lanes/api/javascript_processor.rb +36 -17
- data/lib/lanes/api/pub_sub.rb +6 -9
- data/lib/lanes/api/request_wrapper.rb +1 -2
- data/lib/lanes/api/root.rb +11 -43
- data/lib/lanes/api/routing.rb +63 -0
- data/lib/lanes/api/sprockets_extension.rb +15 -7
- data/lib/lanes/api/updates.rb +1 -2
- data/lib/lanes/command.rb +0 -1
- data/lib/lanes/command/app.rb +6 -5
- data/lib/lanes/command/console.rb +1 -0
- data/lib/lanes/command/generate.rb +3 -0
- data/lib/lanes/command/generate_migration.rb +33 -0
- data/lib/lanes/command/generate_model.rb +4 -26
- data/lib/lanes/command/migration_support.rb +29 -0
- data/lib/lanes/command/update_model.rb +14 -5
- data/lib/lanes/concerns/all.rb +2 -0
- data/lib/lanes/concerns/api_path.rb +4 -2
- data/lib/lanes/concerns/association_extensions.rb +1 -1
- data/lib/lanes/concerns/attr_accessor_with_default.rb +3 -1
- data/lib/lanes/concerns/code_identifier.rb +1 -1
- data/lib/lanes/concerns/image_uploader.rb +42 -0
- data/lib/lanes/concerns/pub_sub.rb +0 -1
- data/lib/lanes/concerns/queries.rb +2 -2
- data/lib/lanes/concerns/set_attribute_data.rb +4 -13
- data/lib/lanes/concerns/sorting_expressions.rb +34 -0
- data/lib/lanes/configuration.rb +48 -9
- data/lib/lanes/extension.rb +16 -7
- data/lib/lanes/extension/definition.rb +8 -2
- data/lib/lanes/job.rb +78 -0
- data/lib/lanes/job/failure_logger.rb +33 -0
- data/lib/lanes/model.rb +4 -0
- data/lib/lanes/rake_tasks.rb +6 -0
- data/lib/lanes/redis.rb +13 -0
- data/lib/lanes/screen.rb +34 -18
- data/lib/lanes/system_settings.rb +66 -0
- data/lib/lanes/version.rb +1 -1
- data/lib/lanes/workspace/extension.rb +1 -1
- data/npm-build/base.js +10 -3
- data/npm-build/calendar.js +6 -0
- data/npm-build/development.js +4 -5
- data/npm-build/grid.js +3 -5
- data/npm-build/package.json +40 -29
- data/npm-build/react-toggle.js +5 -0
- data/npm-build/react-widgets.js +6 -0
- data/npm-build/update-dayz +14 -0
- data/npm-build/webpack.config.js +5 -2
- data/spec/command-reference-files/initial/Gemfile +1 -1
- data/spec/command-reference-files/initial/config/routes.rb +2 -0
- data/spec/command-reference-files/initial/lib/appy-app.rb +4 -0
- data/spec/command-reference-files/initial/lib/appy-app/extension.rb +2 -0
- data/spec/command-reference-files/initial/spec/server/{spec_helpers.rb → spec_helper.rb} +0 -0
- data/spec/command-reference-files/model/config/routes.rb +2 -0
- data/spec/command-reference-files/model/spec/server/test_test_spec.rb +1 -1
- data/spec/command-reference-files/screen/client/appy-app/screens/ready-set-go/ReadySetGo.cjsx +6 -4
- data/spec/command-reference-files/screen/client/appy-app/screens/ready-set-go/index.scss +4 -3
- data/spec/command-reference-files/screen/config/screens.rb +4 -2
- data/spec/command-reference-files/screen/spec/appy-app/screens/ready-set-go/ReadySetGoSpec.coffee +1 -1
- data/spec/fixtures/system_settings.yml +1 -0
- data/spec/lanes/components/grid/GridSpec.coffee +56 -31
- data/spec/lanes/components/grid/RowEditorSpec.coffee +96 -0
- data/spec/lanes/components/select-field/SelectFieldSpec.coffee +99 -0
- data/spec/lanes/components/shared/NetworkActivityOverlaySpec.coffee +34 -0
- data/spec/lanes/models/AssociationMapSpec.coffee +36 -2
- data/spec/lanes/models/AssociationProxySpec.coffee +77 -0
- data/spec/lanes/models/BaseSpec.coffee +37 -4
- data/spec/lanes/models/CollectionSpec.coffee +11 -17
- data/spec/lanes/models/PubSubSpec.coffee +1 -1
- data/spec/lanes/models/ServerCacheSpec.coffee +65 -0
- data/spec/server/api/coffeescript_processor_spec.rb +1 -1
- data/spec/server/concerns/pub_sub_spec.rb +9 -10
- data/spec/server/concerns/sorting_expressions_spec.rb +34 -0
- data/spec/server/configuration_spec.rb +3 -3
- data/spec/server/job_spec.rb +54 -0
- data/spec/server/spec_helper.rb +0 -5
- data/spec/server/system_settings_spec.rb +23 -0
- data/templates/client/screens/Screen.cjsx +6 -4
- data/templates/client/screens/styles.scss +4 -3
- data/templates/config/routes.rb +2 -0
- data/templates/config/screen.rb +4 -2
- data/templates/lib/namespace.rb +4 -0
- data/templates/lib/namespace/extension.rb +2 -0
- data/templates/spec/client/Screen.coffee +1 -1
- data/templates/spec/server/model_spec.rb +1 -1
- data/templates/spec/server/{spec_helpers.rb → spec_helper.rb} +0 -0
- data/views/lanes_root_view.erb +70 -0
- data/views/specs.erb +2 -2
- metadata +207 -68
- data/client/images/lanes/dataTables/Sorting icons.psd +0 -0
- data/client/images/lanes/dataTables/back_disabled.png +0 -0
- data/client/images/lanes/dataTables/back_enabled.png +0 -0
- data/client/images/lanes/dataTables/back_enabled_hover.png +0 -0
- data/client/images/lanes/dataTables/favicon.ico +0 -0
- data/client/images/lanes/dataTables/forward_disabled.png +0 -0
- data/client/images/lanes/dataTables/forward_enabled.png +0 -0
- data/client/images/lanes/dataTables/forward_enabled_hover.png +0 -0
- data/client/images/lanes/dataTables/loading-background.png +0 -0
- data/client/images/lanes/dataTables/sort_asc.png +0 -0
- data/client/images/lanes/dataTables/sort_asc_disabled.png +0 -0
- data/client/images/lanes/dataTables/sort_both.png +0 -0
- data/client/images/lanes/dataTables/sort_desc.png +0 -0
- data/client/images/lanes/dataTables/sort_desc_disabled.png +0 -0
- data/client/lanes/components/shared/Resize.cjsx +0 -152
- data/client/lanes/components/shared/TextArea.cjsx +0 -19
- data/client/lanes/components/shared/TextField.cjsx +0 -25
- data/client/lanes/models/Bootstrap.coffee +0 -5
- data/client/lanes/models/QueryResults.coffee +0 -93
- data/client/lanes/react/FormBindings.coffee +0 -103
- data/client/lanes/react/Router.cjsx +0 -18
- data/client/lanes/styles/dataTables.scss +0 -4
- data/client/lanes/styles/plugins/all.scss +0 -2
- data/client/lanes/styles/plugins/resize-sensor.scss +0 -24
- data/client/lanes/vendor/jquery-2.js +0 -9190
- data/client/lanes/vendor/jquery.tap.js +0 -401
- data/client/lanes/vendor/magicsuggest.js +0 -1565
- data/client/lanes/vendor/message-bus.coffee +0 -264
- data/client/lanes/workspace/ActiveScreenSwitcher.cjsx +0 -38
- data/client/lanes/workspace/styles/toolbar.scss +0 -4
- data/lib/lanes/api/eco.js +0 -516
- data/lib/lanes/api/sprockets_compressor.rb +0 -39
- data/spec/command-reference-files/model/lib/appy-app.rb +0 -11
- data/views/index.erb +0 -19
@@ -0,0 +1,44 @@
|
|
1
|
+
// A bare-bones implementation of $.ajax that MessageBus will use
|
2
|
+
// as a fallback if jQuery is not present
|
3
|
+
//
|
4
|
+
// Only implements methods & options used by MessageBus
|
5
|
+
(function(global, undefined) {
|
6
|
+
'use strict';
|
7
|
+
if (!global.MessageBus){
|
8
|
+
throw new Error("MessageBus must be loaded before the ajax adapter");
|
9
|
+
}
|
10
|
+
|
11
|
+
var cacheBuster = Math.random() * 10000 | 0;
|
12
|
+
|
13
|
+
global.MessageBus.ajax = function(options){
|
14
|
+
var XHRImpl = (global.MessageBus && global.MessageBus.xhrImplementation) || global.XMLHttpRequest;
|
15
|
+
var xhr = new XHRImpl();
|
16
|
+
xhr.dataType = options.dataType;
|
17
|
+
var url = options.url;
|
18
|
+
if (!options.cache){
|
19
|
+
url += ((-1 == url.indexOf('?')) ? '?' : '&') + '_=' + (cacheBuster++)
|
20
|
+
}
|
21
|
+
xhr.open('POST', url);
|
22
|
+
for (var name in options.headers){
|
23
|
+
xhr.setRequestHeader(name, options.headers[name]);
|
24
|
+
}
|
25
|
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
26
|
+
if (options.messageBus.chunked){
|
27
|
+
options.messageBus.onProgressListener(xhr);
|
28
|
+
}
|
29
|
+
xhr.onreadystatechange = function(){
|
30
|
+
if (xhr.readyState === 4){
|
31
|
+
var status = xhr.status;
|
32
|
+
if (status >= 200 && status < 300 || status === 304){
|
33
|
+
options.success(xhr.responseText);
|
34
|
+
} else {
|
35
|
+
options.error(xhr, xhr.statusText);
|
36
|
+
}
|
37
|
+
options.complete();
|
38
|
+
}
|
39
|
+
}
|
40
|
+
xhr.send(JSON.stringify(options.data));
|
41
|
+
return xhr;
|
42
|
+
};
|
43
|
+
|
44
|
+
})(window);
|
@@ -0,0 +1,414 @@
|
|
1
|
+
/*jshint bitwise: false*/
|
2
|
+
(function(global, document, undefined) {
|
3
|
+
'use strict';
|
4
|
+
var previousMessageBus = global.MessageBus;
|
5
|
+
|
6
|
+
// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
|
7
|
+
var callbacks, clientId, failCount, shouldLongPoll, queue, responseCallbacks, uniqueId, baseUrl;
|
8
|
+
var me, started, stopped, longPoller, pollTimeout, paused, later, jQuery, interval, chunkedBackoff;
|
9
|
+
|
10
|
+
uniqueId = function() {
|
11
|
+
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
12
|
+
var r, v;
|
13
|
+
r = Math.random() * 16 | 0;
|
14
|
+
v = c === 'x' ? r : (r & 0x3 | 0x8);
|
15
|
+
return v.toString(16);
|
16
|
+
});
|
17
|
+
};
|
18
|
+
|
19
|
+
clientId = uniqueId();
|
20
|
+
responseCallbacks = {};
|
21
|
+
callbacks = [];
|
22
|
+
queue = [];
|
23
|
+
interval = null;
|
24
|
+
failCount = 0;
|
25
|
+
baseUrl = "/";
|
26
|
+
paused = false;
|
27
|
+
later = [];
|
28
|
+
chunkedBackoff = 0;
|
29
|
+
jQuery = global.jQuery;
|
30
|
+
var hiddenProperty;
|
31
|
+
|
32
|
+
(function(){
|
33
|
+
var prefixes = ["","webkit","ms","moz"];
|
34
|
+
for(var i=0; i<prefixes.length; i++) {
|
35
|
+
var prefix = prefixes[i];
|
36
|
+
var check = prefix + (prefix === "" ? "hidden" : "Hidden");
|
37
|
+
if(document[check] !== undefined ){
|
38
|
+
hiddenProperty = check;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
})();
|
42
|
+
|
43
|
+
var isHidden = function() {
|
44
|
+
if (hiddenProperty !== undefined){
|
45
|
+
return document[hiddenProperty];
|
46
|
+
} else {
|
47
|
+
return !document.hasFocus;
|
48
|
+
}
|
49
|
+
};
|
50
|
+
|
51
|
+
var hasonprogress = (new XMLHttpRequest()).onprogress === null;
|
52
|
+
var allowChunked = function(){
|
53
|
+
return me.enableChunkedEncoding && hasonprogress;
|
54
|
+
};
|
55
|
+
|
56
|
+
shouldLongPoll = function() {
|
57
|
+
return me.alwaysLongPoll || !isHidden();
|
58
|
+
};
|
59
|
+
|
60
|
+
var totalAjaxFailures = 0;
|
61
|
+
var totalAjaxCalls = 0;
|
62
|
+
var lastAjax;
|
63
|
+
|
64
|
+
var processMessages = function(messages) {
|
65
|
+
var gotData = false;
|
66
|
+
if (!messages) return false; // server unexpectedly closed connection
|
67
|
+
|
68
|
+
for (var i=0; i<messages.length; i++) {
|
69
|
+
var message = messages[i];
|
70
|
+
gotData = true;
|
71
|
+
for (var j=0; j<callbacks.length; j++) {
|
72
|
+
var callback = callbacks[j];
|
73
|
+
if (callback.channel === message.channel) {
|
74
|
+
callback.last_id = message.message_id;
|
75
|
+
try {
|
76
|
+
callback.func(message.data);
|
77
|
+
}
|
78
|
+
catch(e){
|
79
|
+
if(console.log) {
|
80
|
+
console.log("MESSAGE BUS FAIL: callback " + callback.channel + " caused exception " + e.message);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
if (message.channel === "/__status") {
|
85
|
+
if (message.data[callback.channel] !== undefined) {
|
86
|
+
callback.last_id = message.data[callback.channel];
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
return gotData;
|
93
|
+
};
|
94
|
+
|
95
|
+
var reqSuccess = function(messages) {
|
96
|
+
failCount = 0;
|
97
|
+
if (paused) {
|
98
|
+
if (messages) {
|
99
|
+
for (var i=0; i<messages.length; i++) {
|
100
|
+
later.push(messages[i]);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
} else {
|
104
|
+
return processMessages(messages);
|
105
|
+
}
|
106
|
+
return false;
|
107
|
+
};
|
108
|
+
|
109
|
+
longPoller = function(poll,data){
|
110
|
+
var gotData = false;
|
111
|
+
var aborted = false;
|
112
|
+
lastAjax = new Date();
|
113
|
+
totalAjaxCalls += 1;
|
114
|
+
data.__seq = totalAjaxCalls;
|
115
|
+
|
116
|
+
var longPoll = shouldLongPoll() && me.enableLongPolling;
|
117
|
+
var chunked = longPoll && allowChunked();
|
118
|
+
if (chunkedBackoff > 0) {
|
119
|
+
chunkedBackoff--;
|
120
|
+
chunked = false;
|
121
|
+
}
|
122
|
+
|
123
|
+
var headers = {
|
124
|
+
'X-SILENCE-LOGGER': 'true'
|
125
|
+
};
|
126
|
+
|
127
|
+
if (!chunked){
|
128
|
+
headers["Dont-Chunk"] = 'true';
|
129
|
+
}
|
130
|
+
|
131
|
+
var dataType = chunked ? "text" : "json";
|
132
|
+
|
133
|
+
var handle_progress = function(payload, position) {
|
134
|
+
|
135
|
+
var separator = "\r\n|\r\n";
|
136
|
+
var endChunk = payload.indexOf(separator, position);
|
137
|
+
|
138
|
+
if (endChunk === -1) {
|
139
|
+
return position;
|
140
|
+
}
|
141
|
+
|
142
|
+
var chunk = payload.substring(position, endChunk);
|
143
|
+
chunk = chunk.replace(/\r\n\|\|\r\n/g, separator);
|
144
|
+
|
145
|
+
try {
|
146
|
+
reqSuccess(JSON.parse(chunk));
|
147
|
+
} catch(e) {
|
148
|
+
if (console.log) {
|
149
|
+
console.log("FAILED TO PARSE CHUNKED REPLY");
|
150
|
+
console.log(data);
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
154
|
+
return handle_progress(payload, endChunk + separator.length);
|
155
|
+
}
|
156
|
+
|
157
|
+
var disableChunked = function(){
|
158
|
+
if (me.longPoll) {
|
159
|
+
me.longPoll.abort();
|
160
|
+
chunkedBackoff = 30;
|
161
|
+
}
|
162
|
+
};
|
163
|
+
|
164
|
+
var setOnProgressListener = function(xhr) {
|
165
|
+
var position = 0;
|
166
|
+
// if it takes longer than 3000 ms to get first chunk, we have some proxy
|
167
|
+
// this is messing with us, so just backoff from using chunked for now
|
168
|
+
var chunkedTimeout = setTimeout(disableChunked,3000);
|
169
|
+
xhr.onprogress = function () {
|
170
|
+
clearTimeout(chunkedTimeout);
|
171
|
+
if(xhr.getResponseHeader('Content-Type') === 'application/json; charset=utf-8') {
|
172
|
+
// not chunked we are sending json back
|
173
|
+
chunked = false;
|
174
|
+
return;
|
175
|
+
}
|
176
|
+
position = handle_progress(xhr.responseText, position);
|
177
|
+
}
|
178
|
+
};
|
179
|
+
if (!me.ajax){
|
180
|
+
throw new Error("Either jQuery or the ajax adapter must be loaded");
|
181
|
+
}
|
182
|
+
var req = me.ajax({
|
183
|
+
url: me.baseUrl + "message-bus/" + me.clientId + "/poll" + (!longPoll ? "?dlp=t" : ""),
|
184
|
+
data: data,
|
185
|
+
cache: false,
|
186
|
+
dataType: dataType,
|
187
|
+
type: 'POST',
|
188
|
+
headers: headers,
|
189
|
+
messageBus: {
|
190
|
+
chunked: chunked,
|
191
|
+
onProgressListener: function(xhr) {
|
192
|
+
var position = 0;
|
193
|
+
// if it takes longer than 3000 ms to get first chunk, we have some proxy
|
194
|
+
// this is messing with us, so just backoff from using chunked for now
|
195
|
+
var chunkedTimeout = setTimeout(disableChunked,3000);
|
196
|
+
return xhr.onprogress = function () {
|
197
|
+
clearTimeout(chunkedTimeout);
|
198
|
+
if(xhr.getResponseHeader('Content-Type') === 'application/json; charset=utf-8') {
|
199
|
+
chunked = false; // not chunked, we are sending json back
|
200
|
+
} else {
|
201
|
+
position = handle_progress(xhr.responseText, position);
|
202
|
+
}
|
203
|
+
}
|
204
|
+
}
|
205
|
+
},
|
206
|
+
xhr: function() {
|
207
|
+
var xhr = jQuery.ajaxSettings.xhr();
|
208
|
+
if (!chunked) {
|
209
|
+
return xhr;
|
210
|
+
}
|
211
|
+
this.messageBus.onProgressListener(xhr);
|
212
|
+
return xhr;
|
213
|
+
},
|
214
|
+
success: function(messages) {
|
215
|
+
if (!chunked) {
|
216
|
+
// we may have requested text so jQuery will not parse
|
217
|
+
if (typeof(messages) === "string") {
|
218
|
+
messages = JSON.parse(messages);
|
219
|
+
}
|
220
|
+
gotData = reqSuccess(messages);
|
221
|
+
}
|
222
|
+
},
|
223
|
+
error: function(xhr, textStatus, err) {
|
224
|
+
if(textStatus === "abort") {
|
225
|
+
aborted = true;
|
226
|
+
} else {
|
227
|
+
failCount += 1;
|
228
|
+
totalAjaxFailures += 1;
|
229
|
+
}
|
230
|
+
},
|
231
|
+
complete: function() {
|
232
|
+
var interval;
|
233
|
+
try {
|
234
|
+
if (gotData || aborted) {
|
235
|
+
interval = 100;
|
236
|
+
} else {
|
237
|
+
interval = me.callbackInterval;
|
238
|
+
if (failCount > 2) {
|
239
|
+
interval = interval * failCount;
|
240
|
+
} else if (!shouldLongPoll()) {
|
241
|
+
interval = me.backgroundCallbackInterval;
|
242
|
+
}
|
243
|
+
if (interval > me.maxPollInterval) {
|
244
|
+
interval = me.maxPollInterval;
|
245
|
+
}
|
246
|
+
|
247
|
+
interval -= (new Date() - lastAjax);
|
248
|
+
|
249
|
+
if (interval < 100) {
|
250
|
+
interval = 100;
|
251
|
+
}
|
252
|
+
}
|
253
|
+
} catch(e) {
|
254
|
+
if(console.log && e.message) {
|
255
|
+
console.log("MESSAGE BUS FAIL: " + e.message);
|
256
|
+
}
|
257
|
+
}
|
258
|
+
|
259
|
+
pollTimeout = setTimeout(function(){pollTimeout=null; poll();}, interval);
|
260
|
+
me.longPoll = null;
|
261
|
+
}
|
262
|
+
});
|
263
|
+
|
264
|
+
return req;
|
265
|
+
};
|
266
|
+
|
267
|
+
me = {
|
268
|
+
enableChunkedEncoding: true,
|
269
|
+
enableLongPolling: true,
|
270
|
+
callbackInterval: 15000,
|
271
|
+
backgroundCallbackInterval: 60000,
|
272
|
+
maxPollInterval: 3 * 60 * 1000,
|
273
|
+
callbacks: callbacks,
|
274
|
+
clientId: clientId,
|
275
|
+
alwaysLongPoll: false,
|
276
|
+
baseUrl: baseUrl,
|
277
|
+
ajax: (jQuery && jQuery.ajax),
|
278
|
+
noConflict: function(){
|
279
|
+
global.MessageBus = global.MessageBus.previousMessageBus;
|
280
|
+
return this;
|
281
|
+
},
|
282
|
+
diagnostics: function(){
|
283
|
+
console.log("Stopped: " + stopped + " Started: " + started);
|
284
|
+
console.log("Current callbacks");
|
285
|
+
console.log(callbacks);
|
286
|
+
console.log("Total ajax calls: " + totalAjaxCalls + " Recent failure count: " + failCount + " Total failures: " + totalAjaxFailures);
|
287
|
+
console.log("Last ajax call: " + (new Date() - lastAjax) / 1000 + " seconds ago") ;
|
288
|
+
},
|
289
|
+
|
290
|
+
pause: function() {
|
291
|
+
paused = true;
|
292
|
+
},
|
293
|
+
|
294
|
+
resume: function() {
|
295
|
+
paused = false;
|
296
|
+
processMessages(later);
|
297
|
+
later = [];
|
298
|
+
},
|
299
|
+
|
300
|
+
stop: function() {
|
301
|
+
stopped = true;
|
302
|
+
started = false;
|
303
|
+
},
|
304
|
+
|
305
|
+
// Start polling
|
306
|
+
start: function() {
|
307
|
+
var poll, delayPollTimeout;
|
308
|
+
|
309
|
+
if (started) return;
|
310
|
+
started = true;
|
311
|
+
stopped = false;
|
312
|
+
|
313
|
+
poll = function() {
|
314
|
+
var data;
|
315
|
+
|
316
|
+
if(stopped) {
|
317
|
+
return;
|
318
|
+
}
|
319
|
+
|
320
|
+
if (callbacks.length === 0) {
|
321
|
+
if(!delayPollTimeout) {
|
322
|
+
delayPollTimeout = setTimeout(function(){ delayPollTimeout = null; poll();}, 500);
|
323
|
+
}
|
324
|
+
return;
|
325
|
+
}
|
326
|
+
|
327
|
+
data = {};
|
328
|
+
for (var i=0;i<callbacks.length;i++) {
|
329
|
+
data[callbacks[i].channel] = callbacks[i].last_id;
|
330
|
+
}
|
331
|
+
|
332
|
+
me.longPoll = longPoller(poll,data);
|
333
|
+
};
|
334
|
+
|
335
|
+
|
336
|
+
// monitor visibility, issue a new long poll when the page shows
|
337
|
+
if(document.addEventListener && 'hidden' in document){
|
338
|
+
me.visibilityEvent = global.document.addEventListener('visibilitychange', function(){
|
339
|
+
if(!document.hidden && !me.longPoll && pollTimeout){
|
340
|
+
clearTimeout(pollTimeout);
|
341
|
+
pollTimeout = null;
|
342
|
+
poll();
|
343
|
+
}
|
344
|
+
});
|
345
|
+
}
|
346
|
+
|
347
|
+
poll();
|
348
|
+
},
|
349
|
+
|
350
|
+
// Subscribe to a channel
|
351
|
+
subscribe: function(channel, func, lastId) {
|
352
|
+
|
353
|
+
if(!started && !stopped){
|
354
|
+
me.start();
|
355
|
+
}
|
356
|
+
|
357
|
+
if (typeof(lastId) !== "number" || lastId < -1){
|
358
|
+
lastId = -1;
|
359
|
+
}
|
360
|
+
callbacks.push({
|
361
|
+
channel: channel,
|
362
|
+
func: func,
|
363
|
+
last_id: lastId
|
364
|
+
});
|
365
|
+
if (me.longPoll) {
|
366
|
+
me.longPoll.abort();
|
367
|
+
}
|
368
|
+
|
369
|
+
return func;
|
370
|
+
},
|
371
|
+
|
372
|
+
// Unsubscribe from a channel
|
373
|
+
unsubscribe: function(channel, func) {
|
374
|
+
// TODO allow for globbing in the middle of a channel name
|
375
|
+
// like /something/*/something
|
376
|
+
// at the moment we only support globbing /something/*
|
377
|
+
var glob;
|
378
|
+
if (channel.indexOf("*", channel.length - 1) !== -1) {
|
379
|
+
channel = channel.substr(0, channel.length - 1);
|
380
|
+
glob = true;
|
381
|
+
}
|
382
|
+
|
383
|
+
var removed = false;
|
384
|
+
|
385
|
+
for (var i=callbacks.length-1; i>=0; i--) {
|
386
|
+
|
387
|
+
var callback = callbacks[i];
|
388
|
+
var keep;
|
389
|
+
|
390
|
+
if (glob) {
|
391
|
+
keep = callback.channel.substr(0, channel.length) !== channel;
|
392
|
+
} else {
|
393
|
+
keep = callback.channel !== channel;
|
394
|
+
}
|
395
|
+
|
396
|
+
if(!keep && func && callback.func !== func){
|
397
|
+
keep = true;
|
398
|
+
}
|
399
|
+
|
400
|
+
if (!keep) {
|
401
|
+
callbacks.splice(i,1);
|
402
|
+
removed = true;
|
403
|
+
}
|
404
|
+
}
|
405
|
+
|
406
|
+
if (removed && me.longPoll) {
|
407
|
+
me.longPoll.abort();
|
408
|
+
}
|
409
|
+
|
410
|
+
return removed;
|
411
|
+
}
|
412
|
+
};
|
413
|
+
global.MessageBus = me;
|
414
|
+
})(window, document);
|