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,63 +1,78 @@
|
|
1
1
|
class CacheEntry
|
2
2
|
|
3
|
-
constructor: (
|
4
|
-
@duration = Lanes.Vendor.Moment.duration(
|
5
|
-
|
6
|
-
@successCallback = @options.success
|
7
|
-
@options.success = this.setFromServer
|
8
|
-
Lanes.Models.Sync.perform('read', this, @options)
|
3
|
+
constructor: (timeout) ->
|
4
|
+
@duration = Lanes.Vendor.Moment.duration(timeout...)
|
5
|
+
@cache = {}
|
9
6
|
|
10
|
-
|
11
|
-
|
7
|
+
store: (record, key) ->
|
8
|
+
@cache[key] = {
|
9
|
+
data: record
|
10
|
+
at: Lanes.Vendor.Moment(new Date)
|
11
|
+
}
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
13
|
+
get: (key) ->
|
14
|
+
entry = @cache[key]
|
15
|
+
if entry
|
16
|
+
if entry.at.add(this.duration).isAfter(new Date)
|
17
|
+
return entry.data
|
18
|
+
else
|
19
|
+
delete @cache[key]
|
20
|
+
null
|
21
21
|
|
22
|
+
computeCollectionCacheKey = (collection, options) ->
|
23
|
+
url = _.result(collection, "url")
|
24
|
+
query = {}
|
25
|
+
for key, value of options
|
26
|
+
query[ Lanes.Models.Sync.paramsMap[key] ] = value if Lanes.Models.Sync.paramsMap[key]
|
27
|
+
url + Lanes.lib.objToParam(query)
|
22
28
|
|
23
29
|
Lanes.Models.ServerCache = {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
fetchRecord: (record, options) ->
|
30
|
+
MODELS: {}
|
31
|
+
COLLECTIONS: {}
|
32
|
+
PENDING: {}
|
33
|
+
|
34
|
+
storeRecordData: (key, records, timeout, pk) ->
|
35
|
+
cache = this.MODELS[key] ||= new CacheEntry(timeout)
|
36
|
+
for record in records
|
37
|
+
cache.store(record, record[pk])
|
38
|
+
|
39
|
+
ce = @COLLECTIONS[key] ||= new CacheEntry(timeout)
|
40
|
+
ce.store(records, key)
|
41
|
+
|
42
|
+
|
43
|
+
fetchRecord: (record, options = {}) ->
|
40
44
|
key = record.urlRoot()
|
45
|
+
if (cache = this.MODELS[key])
|
46
|
+
if (data = cache.get(record.getId()))
|
47
|
+
record.setFromServer(data, options)
|
48
|
+
return _.Promise.resolve(record)
|
49
|
+
|
50
|
+
record.sync('read', record, options).then (record) ->
|
51
|
+
Lanes.Models.ServerCache.storeRecordData(
|
52
|
+
key, [record.toJSON()], record.cacheDuration, record.idAttribute
|
53
|
+
)
|
54
|
+
record
|
55
|
+
|
56
|
+
fetchCollection: (collection, options = {}) ->
|
57
|
+
|
58
|
+
key = computeCollectionCacheKey(collection, options)
|
59
|
+
if (cache = this.COLLECTIONS[collection.url()])
|
60
|
+
|
61
|
+
if (data = cache.get(key))
|
62
|
+
collection.setFromServer(data, options)
|
63
|
+
return _.Promise.resolve(collection)
|
64
|
+
@PENDING[key] ||= collection.sync('read', collection, options).then (collection) ->
|
65
|
+
Lanes.Models.ServerCache.storeRecordData(key,
|
66
|
+
collection.toJSON(),
|
67
|
+
collection.cacheDuration,
|
68
|
+
collection.model::idAttribute
|
69
|
+
)
|
70
|
+
delete Lanes.Models.ServerCache.PENDING[key]
|
71
|
+
collection
|
41
72
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
found = data
|
47
|
-
break
|
48
|
-
if data_set && found
|
49
|
-
options.success.call(options.scope, {data: found}, "sucess", {})
|
50
|
-
else
|
51
|
-
this.sync('read', this, options)
|
52
|
-
|
53
|
-
false
|
54
|
-
|
55
|
-
fetchCollection: (collection, options) ->
|
56
|
-
key = this.computeCacheKey(collection, options)
|
57
|
-
if this.CACHE[key]
|
58
|
-
collection.setFromServer(this.CACHE[key], options)
|
59
|
-
else
|
60
|
-
new CacheEntry(collection, options, key)
|
61
|
-
return _.Promise.resolve(collection)
|
73
|
+
# ce = Lanes.Models.ServerCache.COLLECTIONS[key] ||= new CacheEntry(collection.cacheDuration)
|
74
|
+
# ce.store( collection.toJSON(), key)
|
75
|
+
# #ce.get( key )
|
76
|
+
# collection
|
62
77
|
|
63
78
|
}
|
@@ -0,0 +1,97 @@
|
|
1
|
+
class State
|
2
|
+
constructor: ->
|
3
|
+
super
|
4
|
+
@_bindEvent(eventSpec, fnName) for eventSpec, fnName of _.result(@, 'events', {})
|
5
|
+
@
|
6
|
+
|
7
|
+
_bindEvent: (eventSpec, fnName) ->
|
8
|
+
[kp, event] = eventSpec.split(' ')
|
9
|
+
unless event
|
10
|
+
event = kp; kp = ''
|
11
|
+
_.get(@, kp, @).on(event, @[fnName], @)
|
12
|
+
|
13
|
+
|
14
|
+
isState: true
|
15
|
+
dataTypes:
|
16
|
+
function:
|
17
|
+
set: (fn) ->
|
18
|
+
if _.isBlank(fn) or _.isFunction(fn)
|
19
|
+
{ val: fn, type: 'function' }
|
20
|
+
else
|
21
|
+
throw new TypeError
|
22
|
+
element:
|
23
|
+
set: (el) ->
|
24
|
+
if _.isBlank(el) or _.isElement(el)
|
25
|
+
{ val: el, type: 'element' }
|
26
|
+
else
|
27
|
+
throw new TypeError
|
28
|
+
|
29
|
+
collection:
|
30
|
+
set: (c) ->
|
31
|
+
if _.isBlank(c) or Lanes.u.isCollection(c) or _.isArray(c)
|
32
|
+
{ val: c, type: 'collection' }
|
33
|
+
else
|
34
|
+
throw new TypeError
|
35
|
+
code:
|
36
|
+
set: (newVal) ->
|
37
|
+
newVal = '' if !newVal?
|
38
|
+
if _.isString(newVal)
|
39
|
+
val: newVal.toUpperCase(), type: 'code'
|
40
|
+
else
|
41
|
+
throw new TypeError('code must be a string')
|
42
|
+
default: -> ''
|
43
|
+
# Big decimal for attributes that need precision math
|
44
|
+
bigdec:
|
45
|
+
set: (newVal) ->
|
46
|
+
try
|
47
|
+
val = _.bigDecimal(newVal)
|
48
|
+
{ val, type: 'bigdec' }
|
49
|
+
catch
|
50
|
+
{val: newVal}
|
51
|
+
default: -> new _.bigDecimal(0)
|
52
|
+
|
53
|
+
integer:
|
54
|
+
set: (newVal) ->
|
55
|
+
val = parseInt(newVal, 10) unless _.isBlank(newVal)
|
56
|
+
{val, type: 'integer'}
|
57
|
+
file:
|
58
|
+
set: (val) ->
|
59
|
+
type = if _.isObject(val) then 'file' else typeof val
|
60
|
+
if _.isBlank(val)
|
61
|
+
val = null
|
62
|
+
type = 'file'
|
63
|
+
return { val, type }
|
64
|
+
default: -> {}
|
65
|
+
|
66
|
+
moment:
|
67
|
+
get: (val) -> _.moment(val)
|
68
|
+
default: -> _.moment()
|
69
|
+
set: (newVal) -> { val: _.moment(newVal), type: 'moment' }
|
70
|
+
compare: (currentVal, newVal) -> currentVal.isSame(newVal)
|
71
|
+
|
72
|
+
# Uses the "moment" lib to parse dates and coerce strings into the date type.
|
73
|
+
date:
|
74
|
+
get: (val) -> new Date(val)
|
75
|
+
default: -> return new Date()
|
76
|
+
set: (newVal) ->
|
77
|
+
if _.isDate(newVal)
|
78
|
+
type = 'date'
|
79
|
+
val = new Date(newVal)
|
80
|
+
else if newVal
|
81
|
+
m = Lanes.Vendor.Moment(Date.parse(newVal))
|
82
|
+
if m.isValid()
|
83
|
+
type = 'date'
|
84
|
+
val = m.toDate()
|
85
|
+
else
|
86
|
+
type = typeof newVal;
|
87
|
+
return { type, val }
|
88
|
+
|
89
|
+
# ## listenToAndRun
|
90
|
+
# Shortcut for registering a listener for a model
|
91
|
+
# and also triggering it right away.
|
92
|
+
listenToAndRun: (object, events, handler) ->
|
93
|
+
bound = _.bind(handler, this)
|
94
|
+
this.listenTo(object, events, bound)
|
95
|
+
bound()
|
96
|
+
|
97
|
+
Lanes.Models.State = Lanes.lib.MakeBaseClass( Lanes.Vendor.Ampersand.State, State )
|
@@ -30,18 +30,21 @@ Lanes.Models.Sync = {
|
|
30
30
|
state: (method, model, options = {}) ->
|
31
31
|
options.url ||= _.result(model, "url")
|
32
32
|
if _.contains(['create', 'update', 'patch'], method)
|
33
|
-
|
34
|
-
|
35
|
-
model.
|
33
|
+
isSave = true
|
34
|
+
options.json ||= model.dataForSave(options)
|
35
|
+
model.requestInProgress = options
|
36
|
+
model.trigger("request", model, method, options)
|
36
37
|
return new _.Promise (resolve, reject) ->
|
37
38
|
handler = (reply) ->
|
38
39
|
delete model.requestInProgress
|
39
|
-
model.
|
40
|
-
model.trigger("error", model, options) if reply.errors
|
41
|
-
model.lastServerMessage = reply?.message
|
42
|
-
|
40
|
+
model.lastServerMessage = reply.message
|
43
41
|
model.setFromServer(reply.data, options, method)
|
42
|
+
model.trigger("save", model, reply, options) if isSave
|
44
43
|
model.trigger("sync", model, reply, options)
|
44
|
+
if reply.errors
|
45
|
+
Lanes.warn reply.errors
|
46
|
+
model.errors = reply.errors
|
47
|
+
model.trigger("error", model, options)
|
45
48
|
resolve(model)
|
46
49
|
|
47
50
|
Lanes.Models.Sync.perform(method, options).then (reply) ->
|
@@ -64,18 +67,20 @@ Lanes.Models.Sync = {
|
|
64
67
|
_.defaults(options, {
|
65
68
|
method: methodMap[method]
|
66
69
|
dataType: "json"
|
67
|
-
|
70
|
+
json: query
|
68
71
|
})
|
69
72
|
|
70
73
|
# Ensure that we have a URL.
|
71
|
-
|
74
|
+
options.url or Lanes.Models.Sync.urlError()
|
72
75
|
options.url += '.json'
|
73
76
|
unless _.isEmpty(query)
|
74
77
|
options.url += '?' + Lanes.lib.objToParam(query)
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
+
|
79
|
+
# if options.data and !_.isString(options.data)
|
80
|
+
# options.originalData = options.data
|
81
|
+
# options.json = options.data
|
78
82
|
options.headers ||= {}
|
83
|
+
# options.json = true
|
79
84
|
options.headers['X_CSRF_TOKEN'] = Lanes.config.csrf_token
|
80
85
|
options.contentType = "application/json"
|
81
86
|
|
@@ -86,7 +91,7 @@ Lanes.Models.Sync = {
|
|
86
91
|
if err
|
87
92
|
reject(error:err, body:options.xhr.responseText)
|
88
93
|
else
|
89
|
-
resolve(
|
94
|
+
resolve(body)
|
90
95
|
)
|
91
96
|
)
|
92
97
|
|
File without changes
|
@@ -0,0 +1,60 @@
|
|
1
|
+
isFileDefinition = (def) ->
|
2
|
+
(_.isString(def) and def is 'file') or (_.isObject(def) and def.type is 'file')
|
3
|
+
|
4
|
+
Lanes.Models.Mixins.FileSupport = {
|
5
|
+
|
6
|
+
included: (klass) ->
|
7
|
+
files = _.pick klass::props, (def, name) -> isFileDefinition(def)
|
8
|
+
return if _.isEmpty(files)
|
9
|
+
session = {}
|
10
|
+
for name, def of files
|
11
|
+
session["#{name}_data"] = 'any'
|
12
|
+
session["#{name}_file"] = 'any'
|
13
|
+
_.extend( klass::session ||= {}, session)
|
14
|
+
|
15
|
+
initialize: ->
|
16
|
+
@on('save', @_uploadFileAfterSave)
|
17
|
+
for name, def of @_definition when isFileDefinition(def)
|
18
|
+
@on("change:#{name}_file", _.partial(@readPossibleImage, name))
|
19
|
+
|
20
|
+
hasImage: (attr) ->
|
21
|
+
this[attr] || this["#{attr}_data"]
|
22
|
+
|
23
|
+
imageUrlFor: (attr, type = '') ->
|
24
|
+
if this["#{attr}_data"]
|
25
|
+
this["#{attr}_data"]
|
26
|
+
else if (file = this[attr])
|
27
|
+
if type then file[type].url else file.url
|
28
|
+
else
|
29
|
+
''
|
30
|
+
|
31
|
+
readPossibleImage: (name) ->
|
32
|
+
return unless (file = this["#{name}_file"])
|
33
|
+
reader = new FileReader()
|
34
|
+
reader.onloadend = =>
|
35
|
+
@["#{name}_data"] = reader.result
|
36
|
+
reader.readAsDataURL(file)
|
37
|
+
|
38
|
+
|
39
|
+
_uploadFileAfterSave: ->
|
40
|
+
files = _.pick @_definition, (def, name) =>
|
41
|
+
isFileDefinition(def) and @["#{name}_file"]
|
42
|
+
return if _.isEmpty(files)
|
43
|
+
|
44
|
+
form = new FormData()
|
45
|
+
for name, def of files
|
46
|
+
form.append("files[#{name}]", this["#{name}_file"], this["#{name}_file"].name)
|
47
|
+
form.append("type", @modelTypeIdentifier())
|
48
|
+
form.append("id", @getId())
|
49
|
+
form.append("extension_id", @FILE.extension.identifier)
|
50
|
+
url = Lanes.config.api_path + 'save-file-attribute'
|
51
|
+
|
52
|
+
Lanes.Vendor.xhr.post(url, {body: form}, (err, resp, body) =>
|
53
|
+
if err
|
54
|
+
@errors = { http: err.message }
|
55
|
+
else
|
56
|
+
model = JSON.parse(body)?.data?.model
|
57
|
+
@set(model)
|
58
|
+
this["#{name}_data"] = this["#{name}_file"] = null for name, def of files
|
59
|
+
)
|
60
|
+
}
|
@@ -1,13 +1,20 @@
|
|
1
|
+
DEFAULT_INVALID = /[^A-Z0-9a-z]/
|
2
|
+
|
1
3
|
Lanes.Models.Mixins.HasCodeField = {
|
2
4
|
|
3
|
-
INVALID: /[^A-Z0-9a-z]/
|
4
5
|
|
5
|
-
included: (klass)->
|
6
|
-
klass::INVALID_CODE_CHARS ||=
|
6
|
+
included: (klass) ->
|
7
|
+
klass::INVALID_CODE_CHARS ||= DEFAULT_INVALID
|
7
8
|
|
8
9
|
initialize: ->
|
9
|
-
this.on('change:code', this.
|
10
|
+
this.on('change:code', this._cleanCodeAttr)
|
11
|
+
|
12
|
+
_cleanCodeAttr: ->
|
13
|
+
code = this.get('code')
|
14
|
+
return unless code
|
15
|
+
this.set(
|
16
|
+
'code', code.toUpperCase().replace(@INVALID_CODE_CHARS, '')
|
17
|
+
)
|
10
18
|
|
11
|
-
|
12
|
-
this.set('code', this.get('code').toUpperCase())
|
19
|
+
visibleIdentifier: -> @code
|
13
20
|
}
|
@@ -0,0 +1,188 @@
|
|
1
|
+
class Page
|
2
|
+
|
3
|
+
constructor: (@pageNum, @result, options = {}) ->
|
4
|
+
query = {}
|
5
|
+
@rows = options.rows || []
|
6
|
+
return if options.rows
|
7
|
+
|
8
|
+
@result.query.clauses.each (clause) ->
|
9
|
+
_.extend( query, clause.toParam() ) if clause.isValid
|
10
|
+
|
11
|
+
options = {
|
12
|
+
format: 'array', total_count: 't'
|
13
|
+
start: @pageNum * @result.pageSize, limit: @result.pageSize,
|
14
|
+
query: query, url: @result.query.src::urlRoot(),
|
15
|
+
fields: _.pluck( @result.query.fields.where(query: true), 'id')
|
16
|
+
}
|
17
|
+
if @result.query.sortField
|
18
|
+
options.order = {}
|
19
|
+
{sortBy} = @result.query.sortField
|
20
|
+
field_name = if sortBy
|
21
|
+
if _.isFunction(sortBy) then @result.query.sortField.id else sortBy
|
22
|
+
else
|
23
|
+
@result.query.sortField.id
|
24
|
+
options.order[field_name] = if @result.query.sortAscending then 'asc' else 'desc'
|
25
|
+
|
26
|
+
_.extend(options, _.omit(@result.query.syncOptions, 'include'))
|
27
|
+
@result.query.trigger('request', @result.query, 'GET', {})
|
28
|
+
@result.requestInProgress = options
|
29
|
+
Lanes.Models.Sync.perform('GET', options).then (resp) =>
|
30
|
+
@result.total = resp.total
|
31
|
+
@rows = resp.data
|
32
|
+
delete @result.requestInProgress
|
33
|
+
@result.onPageLoad(@)
|
34
|
+
|
35
|
+
_normalizedIndex: (index) ->
|
36
|
+
index = index % @result.pageSize
|
37
|
+
|
38
|
+
# N.B. for convenience the index for the methods below is the absolute index for all results
|
39
|
+
# not the index just for this page. It's converted and the appropriate row returned
|
40
|
+
_rowAt: (index) ->
|
41
|
+
row = @rows[ @_normalizedIndex(index) ] || []
|
42
|
+
|
43
|
+
_rowToModel: (row) ->
|
44
|
+
attrs = {}
|
45
|
+
for field, i in @result.query.fields.models when field.query and row[field.fetchIndex]?
|
46
|
+
attrs[field.id] = row[field.fetchIndex]
|
47
|
+
new @result.query.src(attrs)
|
48
|
+
|
49
|
+
rowAt: (index) ->
|
50
|
+
@_rowAt(index)
|
51
|
+
# row = @_rowAt(index)
|
52
|
+
# @result.query.fields.map (field) =>
|
53
|
+
# value = row[field.fetchIndex]
|
54
|
+
# field.format?(value, row, @result.query) or value
|
55
|
+
|
56
|
+
modelAt: (index) ->
|
57
|
+
row = @_rowAt(index)
|
58
|
+
@modelCache ||= {}
|
59
|
+
id = @idForRow(row)
|
60
|
+
if _.isBlank(id)
|
61
|
+
@_rowToModel(row)
|
62
|
+
else
|
63
|
+
@modelCache[id] ||= @_rowToModel(row)
|
64
|
+
|
65
|
+
saveModelChanges: (model, index) ->
|
66
|
+
row = @_rowAt(index)
|
67
|
+
@modelCache[ @idForRow(row)] = model
|
68
|
+
data = model.serialize()
|
69
|
+
for field, i in @result.query.fields.models
|
70
|
+
row[field.fetchIndex] = data[field.id]
|
71
|
+
|
72
|
+
idForRow: (row) ->
|
73
|
+
row[@result.query.idIndex]
|
74
|
+
|
75
|
+
addBlankRow: (index) ->
|
76
|
+
model = new @result.query.model
|
77
|
+
row = []
|
78
|
+
for field, i in @result.query.fields.models
|
79
|
+
row[field.fetechIndex] = model[field.id]
|
80
|
+
@rows.splice(@_normalizedIndex(index), 0, row)
|
81
|
+
@_rowToModel(row)
|
82
|
+
|
83
|
+
removeRow: (index = 0) ->
|
84
|
+
@rows.splice(@_normalizedIndex(index), 1)
|
85
|
+
|
86
|
+
class Lanes.Models.Query.ArrayResult extends Lanes.Models.Query.Result
|
87
|
+
|
88
|
+
constructor: (q, options = {}) ->
|
89
|
+
@query = q
|
90
|
+
@xDataColumn = @query.fields.where(query: true).length + 1
|
91
|
+
@pageSize = options.pageSize || 20
|
92
|
+
@pages = {}
|
93
|
+
|
94
|
+
reset: ->
|
95
|
+
@total = 0
|
96
|
+
@pages = {}
|
97
|
+
|
98
|
+
pageForIndex: (index) ->
|
99
|
+
pageNum = Math.floor(index / @pageSize)
|
100
|
+
@pages[pageNum] ||= new Page(pageNum, this)
|
101
|
+
|
102
|
+
visibleIndexes: ->
|
103
|
+
@_visibleIndexes ||= (
|
104
|
+
_.compact( @query.fields.map( (f, i) ->
|
105
|
+
if f.visible then i else null
|
106
|
+
))
|
107
|
+
)
|
108
|
+
|
109
|
+
xtraData: (indexOrRow, options) ->
|
110
|
+
row = if _.isArray(indexOrRow) then indexOrRow else
|
111
|
+
@pageForIndex(indexOrRow).rowAt(indexOrRow)
|
112
|
+
row[@xDataColumn] ||= {}
|
113
|
+
_.extend(row[@xDataColumn], options) if options
|
114
|
+
row[@xDataColumn]
|
115
|
+
|
116
|
+
rowAt: (index, options = {}) ->
|
117
|
+
@pageForIndex(index).rowAt(index)
|
118
|
+
|
119
|
+
allRows: (options) ->
|
120
|
+
rows = (@rowAt(i, options) for i in [0...@length])
|
121
|
+
_.Promise.resolve(rows)
|
122
|
+
|
123
|
+
eachRow: (fn) ->
|
124
|
+
for i in [0...@length]
|
125
|
+
row = @rowAt(i)
|
126
|
+
fn(row, row[@xDataColumn], i)
|
127
|
+
|
128
|
+
map: (fn) ->
|
129
|
+
rows = []
|
130
|
+
@query.results.eachRow (row, xd, i) ->
|
131
|
+
rows.push fn(row, xd, i)
|
132
|
+
rows
|
133
|
+
|
134
|
+
|
135
|
+
filteredRows: (fn) ->
|
136
|
+
found = []
|
137
|
+
@eachRow (row, xd) ->
|
138
|
+
found.push(row) if fn(row, xd)
|
139
|
+
found
|
140
|
+
|
141
|
+
modelAt: (index) ->
|
142
|
+
@pageForIndex(index).modelAt(index)
|
143
|
+
|
144
|
+
saveModelChanges: (model, index) ->
|
145
|
+
@pageForIndex(index).saveModelChanges(model, index)
|
146
|
+
|
147
|
+
removeRow: (index = 0) ->
|
148
|
+
@total -= 1
|
149
|
+
@pageForIndex(index).removeRow(index)
|
150
|
+
|
151
|
+
addBlankRow: (index = 0) ->
|
152
|
+
@total += 1
|
153
|
+
@pageForIndex(index).addBlankRow(index)
|
154
|
+
|
155
|
+
ensureLoaded: (options = {}) ->
|
156
|
+
@pageForIndex(options.page || 0).pendingLoad or _.Promise.resolve(@)
|
157
|
+
|
158
|
+
reload: (options = {}) ->
|
159
|
+
@pages = []
|
160
|
+
@total = 0
|
161
|
+
@ensureLoaded(options)
|
162
|
+
|
163
|
+
onPageLoad: (page) ->
|
164
|
+
@query.trigger('load', @query)
|
165
|
+
@
|
166
|
+
|
167
|
+
rowRepresentation: (rowNum) ->
|
168
|
+
@pageForIndex(rowNum).rowAt(rowNum)
|
169
|
+
|
170
|
+
valueForField: (rowNum, field) ->
|
171
|
+
@rowAt(rowNum)[ field.fetchIndex ]
|
172
|
+
|
173
|
+
_updateSort: ->
|
174
|
+
fn = @sortingFunction()
|
175
|
+
if fn then @allRows().then (rows) =>
|
176
|
+
rows = _.sortBy(rows, _.bind(fn, @))
|
177
|
+
rows = if @query.sortAscending then rows.reverse() else rows
|
178
|
+
page = new Page(0, @, rows: rows)
|
179
|
+
@pages = [page]
|
180
|
+
@query.changeCount += 1
|
181
|
+
@
|
182
|
+
else
|
183
|
+
@reload().then =>
|
184
|
+
@query.changeCount += 1
|
185
|
+
@
|
186
|
+
|
187
|
+
Object.defineProperty Lanes.Models.Query.ArrayResult.prototype, 'length',
|
188
|
+
get: -> @total || 0
|