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
@@ -1,16 +1,18 @@
|
|
1
1
|
module Lanes
|
2
2
|
API.routes.draw do
|
3
|
-
get "default-records" do
|
4
|
-
{ success: true, data: Lanes::API.default_records }
|
5
|
-
end
|
6
3
|
|
7
|
-
|
4
|
+
put Lanes.config.api_path + 'system-settings.json',
|
5
|
+
&SystemSettings.update_handler
|
6
|
+
|
7
|
+
post Lanes.config.api_path + 'save-file-attribute',
|
8
|
+
&API::Handlers::File.saver
|
9
|
+
|
10
|
+
get Lanes.config.api_path + 'file/*',
|
11
|
+
&API::Handlers::File.getter
|
12
|
+
|
13
|
+
Extensions.each(reversed: true) do | ext |
|
8
14
|
ext.route(self)
|
9
15
|
end
|
10
16
|
|
11
|
-
get '/*' do
|
12
|
-
content_type 'text/html'
|
13
|
-
erb :index
|
14
|
-
end
|
15
17
|
end
|
16
18
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Lanes
|
2
|
+
module API
|
3
|
+
module FormattedReply
|
4
|
+
# json methods
|
5
|
+
# constructs a Hash with success, messages, and data keys and
|
6
|
+
# populates them appropriately
|
7
|
+
|
8
|
+
def std_api_reply(type, data, options)
|
9
|
+
success = options[:success].nil? ? true : options[:success]
|
10
|
+
json = {}
|
11
|
+
if data.is_a?(ActiveRecord::Base) && data.errors.any?
|
12
|
+
json[:errors] = {}
|
13
|
+
success = false
|
14
|
+
data.errors.each{ | attr, message |
|
15
|
+
json[:errors][attr] = message
|
16
|
+
}
|
17
|
+
end
|
18
|
+
if options[:total_count]
|
19
|
+
json[:total] = options.delete(:total_count)
|
20
|
+
end
|
21
|
+
json.merge(
|
22
|
+
success: success,
|
23
|
+
message: options[:messsage] || json_status_str(data, type.to_s.capitalize, success),
|
24
|
+
data: success ? records_for_reply(data, type, options) : []
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return Array<Array> returns either an array of fields
|
29
|
+
def records_for_reply(data, type, options)
|
30
|
+
return [] if :destroy == type
|
31
|
+
if options[:format] == 'array'
|
32
|
+
data.pluck( *requested_fields )
|
33
|
+
else
|
34
|
+
data.as_json(options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def json_status_str(record, type, success)
|
39
|
+
if success
|
40
|
+
type + " succeeded"
|
41
|
+
elsif record
|
42
|
+
msg = type + " failed"
|
43
|
+
if record.is_a?(ActiveRecord::Base)
|
44
|
+
msg += ": " + record.errors.full_messages.join("; ")
|
45
|
+
end
|
46
|
+
else
|
47
|
+
return "Record not found"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Lanes::API::Handlers
|
2
|
+
|
3
|
+
class File
|
4
|
+
|
5
|
+
def self.saver
|
6
|
+
lambda do
|
7
|
+
Lanes.logger.debug "Saving File. Root=#{CarrierWave.root}"
|
8
|
+
path = "#{params['extension_id']}/#{params['type']}"
|
9
|
+
model = path.underscore.camelize.constantize
|
10
|
+
record = model.find(params['id'])
|
11
|
+
params['files'].each do |attr, data|
|
12
|
+
record.send(attr).store!( data )
|
13
|
+
end
|
14
|
+
record.save!
|
15
|
+
|
16
|
+
json_reply std_api_reply :create, { model: record }, success: true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.getter
|
21
|
+
lambda do
|
22
|
+
send_file CarrierWave::Uploader::Base.root.call + '/' + params['splat'].first
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -3,12 +3,16 @@ module Lanes
|
|
3
3
|
|
4
4
|
module HelperMethods
|
5
5
|
|
6
|
-
def
|
7
|
-
|
6
|
+
def lanes_application_title
|
7
|
+
Extensions.controlling.title
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def lanes_javascript_tags
|
11
|
+
javascript_tag('lanes/vendor') + "\n" + javascript_tag('lanes')
|
12
|
+
end
|
13
|
+
|
14
|
+
def lanes_stylesheet_tags
|
15
|
+
stylesheet_tag('lanes')
|
12
16
|
end
|
13
17
|
|
14
18
|
def client_bootstrap_data
|
@@ -20,12 +24,32 @@ module Lanes
|
|
20
24
|
end
|
21
25
|
|
22
26
|
def lanes_api_url
|
23
|
-
Lanes.config.
|
27
|
+
Lanes.config.api_path
|
28
|
+
end
|
29
|
+
|
30
|
+
def error_as_json
|
31
|
+
Lanes.logger.warn request.env['sinatra.error']
|
32
|
+
Oj.dump({
|
33
|
+
success: false,
|
34
|
+
errors: { exception: request.env['sinatra.error'].message },
|
35
|
+
message: request.env['sinatra.error'].message
|
36
|
+
})
|
24
37
|
end
|
25
38
|
|
26
39
|
def data
|
27
40
|
@json_data ||= Oj.load( request.body.read )
|
28
41
|
end
|
42
|
+
|
43
|
+
def request_origin
|
44
|
+
@request_origin ||= env['HTTP_ORIGIN']
|
45
|
+
end
|
46
|
+
|
47
|
+
def json_reply( response )
|
48
|
+
content_type 'application/json'
|
49
|
+
Oj.dump(response, mode: :compat)
|
50
|
+
end
|
51
|
+
|
52
|
+
|
29
53
|
end
|
30
54
|
|
31
55
|
end
|
@@ -19,30 +19,49 @@ module Lanes
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
def get_js_aliases(ns)
|
23
|
+
ext = Extensions.for_identifier(ns)
|
24
|
+
aliases = ext ? ext.client_js_aliases : {}
|
25
|
+
aliases.merge!({
|
26
|
+
'LC' => 'window.Lanes.Components',
|
27
|
+
'React' => 'window.Lanes.Vendor.React',
|
28
|
+
'BS' => 'window.Lanes.Vendor.ReactBootstrap'
|
29
|
+
})
|
30
|
+
[ aliases.keys.join(','), aliases.values.join(',') ]
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_wrapping_vars(identifier)
|
34
|
+
if identifier
|
35
|
+
ns = identifier.underscore.camelize
|
36
|
+
else
|
37
|
+
ns = ''
|
38
|
+
identifier = ''
|
39
|
+
end
|
40
|
+
if identifier == "lanes"
|
41
|
+
ns_file_ref = "window.Lanes"
|
42
|
+
ns_ref = ''
|
43
|
+
ns_name = ''
|
44
|
+
else
|
45
|
+
ns_name = "#{ns},"
|
46
|
+
ns_ref = "(window.Lanes ? window.Lanes['#{ns}'] : null),"
|
47
|
+
ns_file_ref = "window.Lanes['#{ns}']"
|
48
|
+
end
|
49
|
+
return ns, ns_file_ref, ns_ref, ns_name
|
50
|
+
end
|
51
|
+
|
22
52
|
def wrap_js(scope, js)
|
23
53
|
dirs = scope.logical_path.split(File::SEPARATOR)
|
24
|
-
|
54
|
+
identifier = dirs.many? ? dirs.first : nil
|
25
55
|
path = "[" + dirs.map{|d| "\"#{d}\"" }.join(",") + "]"
|
26
56
|
# if the file is being loaded under the "lanes" directory
|
27
57
|
# it's not an extension
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
ns_file_ref = "window.Lanes['#{ns}']"
|
33
|
-
else
|
34
|
-
ns_name = ""
|
35
|
-
ns_ref = ""
|
36
|
-
ns_file_ref = "window.Lanes"
|
37
|
-
end
|
38
|
-
file="{namespace:#{ns_file_ref},extensionName:'#{ns}',path:#{path}}"
|
39
|
-
"(function(Lanes,#{ns_name}_,LC,React,BS,FILE,window,undefined)"\
|
58
|
+
(aliases, definitions) = get_js_aliases(identifier)
|
59
|
+
ns, ns_file_ref, ns_ref, ns_name = get_wrapping_vars(identifier)
|
60
|
+
file="{namespace:#{ns_file_ref},extension:{name:'#{ns}',identifier:'#{identifier}'},path:#{path}}"
|
61
|
+
"(function(Lanes,#{ns_name}_,#{aliases},FILE,window,undefined)"\
|
40
62
|
"{\n#{js}\n})"\
|
41
63
|
"(window.Lanes,#{ns_ref}window.Lanes.Vendor.ld,"\
|
42
|
-
"window
|
43
|
-
"window.Lanes.Vendor.React,"\
|
44
|
-
"window.Lanes.Vendor.ReactBootstrap,"\
|
45
|
-
"#{file}, window);"
|
64
|
+
"#{definitions},#{file},window);"
|
46
65
|
end
|
47
66
|
|
48
67
|
end
|
data/lib/lanes/api/pub_sub.rb
CHANGED
@@ -6,6 +6,7 @@ module Lanes
|
|
6
6
|
class PubSub
|
7
7
|
|
8
8
|
def self.publish(channel, data)
|
9
|
+
Lanes.logger.debug "publishing on: #{channel}"
|
9
10
|
::MessageBus.publish channel, data
|
10
11
|
end
|
11
12
|
|
@@ -20,16 +21,12 @@ module Lanes
|
|
20
21
|
require 'message_bus'
|
21
22
|
api.use MessageBus::Rack::Middleware if api
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
begin
|
28
|
-
require 'json'
|
29
|
-
rescue
|
30
|
-
# ignore
|
24
|
+
if defined?(::PhusionPassenger)
|
25
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
26
|
+
MessageBus.after_fork if forked
|
27
|
+
end
|
31
28
|
end
|
32
|
-
|
29
|
+
|
33
30
|
Updates.relay!
|
34
31
|
|
35
32
|
::Lanes::API.routes.draw do
|
data/lib/lanes/api/root.rb
CHANGED
@@ -1,65 +1,32 @@
|
|
1
1
|
require 'sinatra'
|
2
2
|
require 'oj'
|
3
|
-
require 'rack/
|
4
|
-
|
3
|
+
require 'rack/protection'
|
5
4
|
require_relative 'sprockets_extension'
|
6
5
|
require_relative 'helper_methods'
|
7
6
|
require_relative 'pub_sub'
|
8
7
|
|
8
|
+
|
9
9
|
module Lanes
|
10
10
|
module API
|
11
11
|
class Root < Sinatra::Application
|
12
|
+
|
12
13
|
Lanes.config.get(:environment) do | env |
|
13
14
|
set :environment, env
|
14
15
|
end
|
15
16
|
register SprocketsExtension
|
16
17
|
helpers RequestWrapper
|
17
18
|
helpers HelperMethods
|
19
|
+
helpers FormattedReply
|
18
20
|
use Rack::Session::Cookie, :key => 'lanes.session', :secret => Lanes.config.session_secret_key_base
|
19
21
|
use ActiveRecord::ConnectionAdapters::ConnectionManagement
|
20
22
|
not_found do
|
21
23
|
Oj.dump({ message: "endpoint not found", success: false })
|
22
24
|
end
|
23
|
-
error do
|
24
|
-
|
25
|
-
Oj.dump({
|
26
|
-
success: false,
|
27
|
-
errors: { exception: request.env['sinatra.error'].message },
|
28
|
-
message: request.env['sinatra.error'].message
|
29
|
-
})
|
25
|
+
error ActiveRecord::RecordNotFound do
|
26
|
+
halt 404, error_as_json
|
30
27
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
path = options[:path] || model.api_path
|
35
|
-
controller = options[:controller] || Lanes::API::Controller
|
36
|
-
|
37
|
-
parent_attribute = false
|
38
|
-
prefix = if options[:under]
|
39
|
-
parent_attribute = options[:parent_attribute] || options[:under].underscore.singularize+'_id'
|
40
|
-
else
|
41
|
-
''
|
42
|
-
end
|
43
|
-
|
44
|
-
# index
|
45
|
-
get "#{prefix}/#{path}/?:id?.json", &RequestWrapper.get(model, controller, parent_attribute)
|
46
|
-
|
47
|
-
# create
|
48
|
-
post "#{prefix}/#{path}.json", &RequestWrapper.post(model, controller, parent_attribute)
|
49
|
-
|
50
|
-
unless options[:immutable]
|
51
|
-
|
52
|
-
# update
|
53
|
-
patch "#{prefix}/#{path}/?:id?.json", &RequestWrapper.update(model, controller, parent_attribute)
|
54
|
-
put "#{prefix}/#{path}/?:id?.json", &RequestWrapper.update(model, controller, parent_attribute)
|
55
|
-
|
56
|
-
unless options[:indestructible]
|
57
|
-
# destroy
|
58
|
-
delete "#{prefix}/#{path}/?:id?.json", &RequestWrapper.delete(model, controller, parent_attribute)
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
28
|
+
error do
|
29
|
+
error_as_json
|
63
30
|
end
|
64
31
|
|
65
32
|
configure do
|
@@ -67,14 +34,15 @@ module Lanes
|
|
67
34
|
set :show_exceptions, false
|
68
35
|
require_relative 'routing'
|
69
36
|
|
70
|
-
DB.establish_connection
|
71
37
|
PubSub.initialize(self)
|
72
38
|
Extensions.load_controlling_config
|
73
39
|
# late load in case an extension has provided an alternative implementation
|
74
40
|
unless API.const_defined?(:AuthenticationProvider)
|
75
41
|
require "lanes/api/null_authentication_provider"
|
76
42
|
end
|
77
|
-
|
43
|
+
use Rack::Protection #, :skip=>['GET:/'], :raise => true
|
44
|
+
|
45
|
+
Lanes::Configuration.apply
|
78
46
|
end
|
79
47
|
|
80
48
|
end
|
data/lib/lanes/api/routing.rb
CHANGED
@@ -1,6 +1,64 @@
|
|
1
1
|
module Lanes
|
2
2
|
module API
|
3
3
|
|
4
|
+
class RoutingBlock
|
5
|
+
def initialize(ext_id)
|
6
|
+
Lanes::Extensions.for_identifier(ext_id) ||
|
7
|
+
raise( "Unable to find extension '#{ext_id}' for screen group")
|
8
|
+
@ext_id = ext_id
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_view( view )
|
12
|
+
API::Root.get Lanes.config.mounted_at + '?*' do
|
13
|
+
pass unless request.accept? 'text/html'
|
14
|
+
erb view
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
[:get, :post, :put, :patch, :delete].each do | method_name |
|
19
|
+
define_method(method_name) do | path, options = {}, &block |
|
20
|
+
API::Root.send(method_name, make_path(path), options, &block)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def resources(model, options = {})
|
25
|
+
path = options[:path] || model.api_path
|
26
|
+
controller = options[:controller] || Lanes::API::Controller
|
27
|
+
parent_attribute = false
|
28
|
+
if options[:under]
|
29
|
+
parent_attribute = options[:parent_attribute] || options[:under].underscore.singularize+'_id'
|
30
|
+
end
|
31
|
+
|
32
|
+
prefix = parent_attribute ? parent_attribute + '/' : ''
|
33
|
+
|
34
|
+
# index
|
35
|
+
get "#{prefix}#{path}/?:id?.json", &RequestWrapper.get(model, controller, parent_attribute)
|
36
|
+
|
37
|
+
# create
|
38
|
+
post "#{prefix}#{path}.json", &RequestWrapper.post(model, controller, parent_attribute)
|
39
|
+
|
40
|
+
unless options[:immutable]
|
41
|
+
|
42
|
+
# update
|
43
|
+
patch "#{prefix}#{path}/?:id?.json", &RequestWrapper.update(model, controller, parent_attribute)
|
44
|
+
put "#{prefix}#{path}/?:id?.json", &RequestWrapper.update(model, controller, parent_attribute)
|
45
|
+
|
46
|
+
unless options[:indestructible]
|
47
|
+
# destroy
|
48
|
+
delete "#{prefix}#{path}/?:id?.json", &RequestWrapper.delete(model, controller, parent_attribute)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def make_path(path)
|
58
|
+
Lanes.config.api_path + @ext_id + '/' + path
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
4
62
|
class RouteSet
|
5
63
|
def initialize(root)
|
6
64
|
@root = root
|
@@ -9,6 +67,11 @@ module Lanes
|
|
9
67
|
def draw(&block)
|
10
68
|
@root.instance_eval(&block)
|
11
69
|
end
|
70
|
+
|
71
|
+
def for_extension(ext_id, &block)
|
72
|
+
routes = RoutingBlock.new(ext_id)
|
73
|
+
routes.instance_eval(&block)
|
74
|
+
end
|
12
75
|
end
|
13
76
|
|
14
77
|
def self.routes(&block)
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'sprockets'
|
2
2
|
require 'sass'
|
3
3
|
require 'sinatra/sprockets-helpers'
|
4
|
-
require_relative 'javascript_processor'
|
5
4
|
require 'compass/import-once/activate'
|
6
5
|
require 'sprockets-helpers'
|
6
|
+
require 'tilt/erb'
|
7
|
+
require 'compass/import-once/activate'
|
7
8
|
|
8
9
|
module Lanes
|
9
10
|
module API
|
@@ -11,10 +12,15 @@ module Lanes
|
|
11
12
|
class << self
|
12
13
|
|
13
14
|
def compile!
|
15
|
+
# only require processor if it's needed
|
16
|
+
# it requires asset pipeline functionality that requires a JS runtime
|
17
|
+
# which may not be available on production
|
18
|
+
require_relative 'javascript_processor'
|
14
19
|
env = ::Sprockets::Environment.new
|
15
20
|
Lanes::API::SprocketsExtension.configure(env, compress:true)
|
21
|
+
JsAssetCompiler.register(env)
|
16
22
|
manifest = Sprockets::Manifest.new( env.index, "public/assets/manifest.json" )
|
17
|
-
manifest.compile('lanes.js', 'lanes.css')
|
23
|
+
manifest.compile('lanes/vendor.js', 'lanes.js', 'lanes.css')
|
18
24
|
Extensions.each do |ext|
|
19
25
|
ext.each_static_asset do | asset |
|
20
26
|
manifest.compile( asset.to_s )
|
@@ -43,14 +49,16 @@ module Lanes
|
|
43
49
|
env.append_path(path)
|
44
50
|
}
|
45
51
|
end
|
46
|
-
|
47
52
|
if compress
|
48
|
-
|
49
|
-
env.
|
50
|
-
|
53
|
+
env.js_compressor = :uglifier
|
54
|
+
env.css_compressor = :sass
|
55
|
+
end
|
56
|
+
# assets are pre-compiled on production
|
57
|
+
unless Lanes.env.production?
|
58
|
+
require_relative 'javascript_processor'
|
59
|
+
JsAssetCompiler.register(env)
|
51
60
|
end
|
52
61
|
env.append_path root.join('client')
|
53
|
-
JsAssetCompiler.register(env)
|
54
62
|
end
|
55
63
|
|
56
64
|
def registered(app)
|