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.
Files changed (304) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/Rakefile +1 -1
  4. data/client/lanes/Boot.cjsx +3 -3
  5. data/client/lanes/Config.coffee +38 -3
  6. data/client/lanes/access/Extension.coffee +1 -1
  7. data/client/lanes/access/LoginDialog.cjsx +57 -47
  8. data/client/lanes/access/Roles.coffee +2 -2
  9. data/client/lanes/access/User.coffee +4 -3
  10. data/client/lanes/access/screens/user-management/UserManagement.cjsx +12 -11
  11. data/client/lanes/components/calendar/Calendar.cjsx +16 -0
  12. data/client/lanes/components/calendar/index.js +3 -0
  13. data/client/lanes/components/calendar/styles.scss +3 -0
  14. data/client/lanes/components/grid/Body.cjsx +86 -0
  15. data/client/lanes/components/grid/CellStyles.coffee +20 -0
  16. data/client/lanes/components/grid/EditingMixin.cjsx +84 -24
  17. data/client/lanes/components/grid/Editor.cjsx +45 -0
  18. data/client/lanes/components/grid/Grid.cjsx +62 -104
  19. data/client/lanes/components/grid/Header.cjsx +35 -0
  20. data/client/lanes/components/grid/PopOverMixin.cjsx +19 -9
  21. data/client/lanes/components/grid/PopoverEditor.cjsx +7 -1
  22. data/client/lanes/components/grid/RowEditor.cjsx +1 -1
  23. data/client/lanes/components/grid/Selections.cjsx +39 -0
  24. data/client/lanes/components/grid/Toolbar.cjsx +24 -5
  25. data/client/lanes/components/grid/editors.scss +22 -50
  26. data/client/lanes/components/grid/index.js +0 -1
  27. data/client/lanes/components/grid/row-editor.scss +68 -0
  28. data/client/lanes/components/grid/styles.scss +79 -3
  29. data/client/lanes/components/modal/Modal.cjsx +64 -24
  30. data/client/lanes/components/modal/styles.scss +12 -0
  31. data/client/lanes/components/record-finder/Clause.cjsx +11 -4
  32. data/client/lanes/components/record-finder/Dialog.cjsx +23 -24
  33. data/client/lanes/components/record-finder/RecordFinder.cjsx +45 -14
  34. data/client/lanes/components/record-finder/styles.scss +9 -6
  35. data/client/lanes/components/select-field/SelectField.cjsx +108 -53
  36. data/client/lanes/components/select-field/styles.scss +19 -0
  37. data/client/lanes/components/shared/ControlLabel.cjsx +45 -0
  38. data/client/lanes/components/shared/DateTime.cjsx +48 -0
  39. data/client/lanes/components/shared/DisplayValue.cjsx +16 -0
  40. data/client/lanes/components/shared/FieldMixin.cjsx +54 -23
  41. data/client/lanes/components/shared/FieldSet.cjsx +12 -35
  42. data/client/lanes/components/shared/FieldWrapper.cjsx +13 -0
  43. data/client/lanes/components/shared/FormGroup.cjsx +37 -0
  44. data/client/lanes/components/shared/Icon.cjsx +20 -0
  45. data/client/lanes/components/shared/ImageSaver.cjsx +33 -0
  46. data/client/lanes/components/shared/Input.cjsx +19 -0
  47. data/client/lanes/components/shared/InputFieldMixin.cjsx +48 -0
  48. data/client/lanes/components/shared/JobProgress.cjsx +27 -0
  49. data/client/lanes/components/shared/NetworkActivityOverlay.cjsx +58 -0
  50. data/client/lanes/components/shared/NumberInput.cjsx +29 -0
  51. data/client/lanes/components/shared/ResizeSensor.cjsx +11 -0
  52. data/client/lanes/components/shared/ScreenWrapper.cjsx +13 -0
  53. data/client/lanes/components/shared/Throbber.cjsx +3 -0
  54. data/client/lanes/components/shared/ToggleField.cjsx +33 -0
  55. data/client/lanes/components/shared/Tooltip.cjsx +2 -2
  56. data/client/lanes/components/shared/fields.scss +75 -13
  57. data/client/lanes/components/shared/fieldset.scss +3 -5
  58. data/client/lanes/components/shared/image-saver.scss +38 -0
  59. data/client/lanes/components/shared/index.js +2 -0
  60. data/client/lanes/{styles/plugins → components/shared}/overlay.scss +17 -4
  61. data/client/lanes/components/shared/resize-sensor.scss +30 -0
  62. data/client/lanes/components/shared/styles.scss +13 -0
  63. data/client/lanes/components/shared/throbber.scss +53 -0
  64. data/client/lanes/components/toolbar/RemoteChangeSets.cjsx +21 -48
  65. data/client/lanes/components/toolbar/SaveButton.cjsx +24 -0
  66. data/client/lanes/components/toolbar/Toolbar.cjsx +24 -37
  67. data/client/lanes/components/toolbar/changes-notification.scss +10 -6
  68. data/client/lanes/components/toolbar/styles.scss +29 -9
  69. data/client/lanes/extension/Base.coffee +4 -5
  70. data/client/lanes/index.js +0 -1
  71. data/client/lanes/index.scss.erb +10 -1
  72. data/client/lanes/lib/HotReload.coffee +13 -15
  73. data/client/lanes/lib/MakeBaseClass.coffee +6 -1
  74. data/client/lanes/lib/development.coffee +2 -0
  75. data/client/lanes/lib/dom-polyfills.coffee +5 -0
  76. data/client/lanes/lib/dom.coffee +38 -9
  77. data/client/lanes/lib/format.coffee +11 -0
  78. data/client/lanes/lib/index.js.erb +2 -0
  79. data/client/lanes/lib/production.coffee +6 -0
  80. data/client/lanes/lib/utilFunctions.coffee +50 -15
  81. data/client/lanes/models/AssociationMap.coffee +122 -46
  82. data/client/lanes/models/AssociationProxy.coffee +147 -0
  83. data/client/lanes/models/Base.coffee +97 -85
  84. data/client/lanes/models/ChangeMonitor.coffee +7 -3
  85. data/client/lanes/models/ChangeSet.coffee +2 -2
  86. data/client/lanes/models/Collection.coffee +49 -6
  87. data/client/lanes/models/JobStatus.coffee +32 -0
  88. data/client/lanes/models/PubSub.coffee +7 -5
  89. data/client/lanes/models/Query.coffee +115 -34
  90. data/client/lanes/models/ServerCache.coffee +67 -52
  91. data/client/lanes/models/State.coffee +97 -0
  92. data/client/lanes/models/Sync.coffee +18 -13
  93. data/client/lanes/models/SystemSettings.coffee +0 -0
  94. data/client/lanes/models/index.js +1 -0
  95. data/client/lanes/models/mixins/FileSupport.coffee +60 -0
  96. data/client/lanes/models/mixins/HasCodeField.coffee +13 -6
  97. data/client/lanes/models/query/ArrayResult.coffee +188 -0
  98. data/client/lanes/models/query/CollectionResult.coffee +71 -0
  99. data/client/lanes/models/query/Result.coffee +9 -0
  100. data/client/lanes/react/Component.coffee +7 -3
  101. data/client/lanes/react/PubSub.coffee +7 -7
  102. data/client/lanes/react/Root.cjsx +1 -4
  103. data/client/lanes/react/Screen.coffee +1 -0
  104. data/client/lanes/react/TypeValidators.coffee +3 -3
  105. data/client/lanes/react/Viewport.coffee +41 -7
  106. data/client/lanes/react/index.js +0 -1
  107. data/client/lanes/react/mixins/Access.coffee +4 -1
  108. data/client/lanes/react/mixins/Data.coffee +40 -25
  109. data/client/lanes/react/mixins/FieldErrors.coffee +27 -0
  110. data/client/lanes/react/mixins/RelayEditingState.coffee +4 -0
  111. data/client/lanes/react/mixins/Screen.coffee +14 -0
  112. data/client/lanes/react/mixins/Viewport.coffee +9 -3
  113. data/client/lanes/screens/ChangeListener.coffee +3 -3
  114. data/client/lanes/screens/Commands.coffee +14 -7
  115. data/client/lanes/screens/CommonComponents.cjsx +20 -0
  116. data/client/lanes/screens/Definitions.coffee +64 -20
  117. data/client/lanes/screens/SystemSettings.cjsx +56 -0
  118. data/client/lanes/screens/UserPreferences.cjsx +38 -0
  119. data/client/lanes/screens/index.js +3 -0
  120. data/client/lanes/screens/styles.scss +2 -1
  121. data/client/lanes/styles/fonts.scss +1 -0
  122. data/client/lanes/styles/global.scss +2 -1
  123. data/client/lanes/styles/global/flexbox.scss +16 -0
  124. data/client/lanes/styles/global/styles.scss +1 -0
  125. data/client/lanes/styles/mixins/_dropdown.scss +21 -0
  126. data/client/lanes/styles/mixins/_flexbox.scss +394 -0
  127. data/client/lanes/styles/mixins/all.scss +2 -0
  128. data/client/lanes/styles/variables.scss +28 -0
  129. data/client/lanes/testing/BeforeEach.coffee +15 -14
  130. data/client/lanes/testing/Helpers.coffee +14 -5
  131. data/client/lanes/testing/TestObjects.coffee +10 -2
  132. data/client/lanes/testing/index.js +1 -0
  133. data/client/lanes/testing/jasmine-react.js +125 -0
  134. data/client/lanes/vendor/base.js +56049 -74987
  135. data/client/lanes/vendor/calendar.js +17301 -0
  136. data/client/lanes/vendor/calendar.scss +303 -0
  137. data/client/lanes/vendor/commons.js +14990 -15847
  138. data/client/lanes/vendor/development.js +4912 -1952
  139. data/client/lanes/vendor/grid.js +14246 -5551
  140. data/client/lanes/vendor/grid.scss +876 -335
  141. data/client/lanes/vendor/index.js +1 -0
  142. data/client/lanes/vendor/message-bus-ajax.js +44 -0
  143. data/client/lanes/vendor/message-bus.js +414 -0
  144. data/client/lanes/vendor/rw-widgets.eot +0 -0
  145. data/client/lanes/vendor/rw-widgets.svg +18 -0
  146. data/client/lanes/vendor/rw-widgets.ttf +0 -0
  147. data/client/lanes/vendor/rw-widgets.woff +0 -0
  148. data/client/lanes/vendor/toggle.js +345 -0
  149. data/client/lanes/vendor/toggle.scss +138 -0
  150. data/client/lanes/vendor/widgets.js +21245 -6839
  151. data/client/lanes/vendor/widgets.scss +83 -67
  152. data/client/lanes/workspace/Layout.cjsx +18 -8
  153. data/client/lanes/workspace/Modal.cjsx +47 -0
  154. data/client/lanes/workspace/Navbar.cjsx +16 -2
  155. data/client/lanes/workspace/ScreenView.cjsx +10 -3
  156. data/client/lanes/workspace/ScreensMenu.cjsx +23 -7
  157. data/client/lanes/workspace/Tabs.cjsx +55 -0
  158. data/client/lanes/workspace/UIState.coffee +7 -8
  159. data/client/lanes/workspace/index.js +2 -1
  160. data/client/lanes/workspace/mixin.coffee +11 -0
  161. data/client/lanes/workspace/mixins/UIState.coffee +8 -0
  162. data/client/lanes/workspace/mixins/index.js +3 -0
  163. data/client/lanes/workspace/styles.scss +2 -1
  164. data/client/lanes/workspace/styles/header.scss +23 -1
  165. data/client/lanes/workspace/styles/layout.scss +26 -24
  166. data/client/lanes/workspace/styles/screens.scss +0 -4
  167. data/client/lanes/workspace/styles/tabs.scss +3 -10
  168. data/config/routes.rb +10 -4
  169. data/config/screens.rb +25 -0
  170. data/db/migrate/01_create_system_settings.rb +10 -0
  171. data/docs/todo-example-part-1.md +18 -20
  172. data/lanes.gemspec +15 -6
  173. data/lib/lanes.rb +4 -2
  174. data/lib/lanes/access/config/routes.rb +5 -3
  175. data/lib/lanes/access/config/screens.rb +1 -0
  176. data/lib/lanes/access/db/migrate/20140615031600_create_lanes_users.rb +1 -1
  177. data/lib/lanes/access/user.rb +1 -1
  178. data/lib/lanes/api.rb +2 -1
  179. data/lib/lanes/api/controller.rb +32 -71
  180. data/lib/lanes/api/default_routes.rb +10 -8
  181. data/lib/lanes/api/formatted_reply.rb +53 -0
  182. data/lib/lanes/api/handlers/file.rb +26 -0
  183. data/lib/lanes/api/helper_methods.rb +29 -5
  184. data/lib/lanes/api/javascript_processor.rb +36 -17
  185. data/lib/lanes/api/pub_sub.rb +6 -9
  186. data/lib/lanes/api/request_wrapper.rb +1 -2
  187. data/lib/lanes/api/root.rb +11 -43
  188. data/lib/lanes/api/routing.rb +63 -0
  189. data/lib/lanes/api/sprockets_extension.rb +15 -7
  190. data/lib/lanes/api/updates.rb +1 -2
  191. data/lib/lanes/command.rb +0 -1
  192. data/lib/lanes/command/app.rb +6 -5
  193. data/lib/lanes/command/console.rb +1 -0
  194. data/lib/lanes/command/generate.rb +3 -0
  195. data/lib/lanes/command/generate_migration.rb +33 -0
  196. data/lib/lanes/command/generate_model.rb +4 -26
  197. data/lib/lanes/command/migration_support.rb +29 -0
  198. data/lib/lanes/command/update_model.rb +14 -5
  199. data/lib/lanes/concerns/all.rb +2 -0
  200. data/lib/lanes/concerns/api_path.rb +4 -2
  201. data/lib/lanes/concerns/association_extensions.rb +1 -1
  202. data/lib/lanes/concerns/attr_accessor_with_default.rb +3 -1
  203. data/lib/lanes/concerns/code_identifier.rb +1 -1
  204. data/lib/lanes/concerns/image_uploader.rb +42 -0
  205. data/lib/lanes/concerns/pub_sub.rb +0 -1
  206. data/lib/lanes/concerns/queries.rb +2 -2
  207. data/lib/lanes/concerns/set_attribute_data.rb +4 -13
  208. data/lib/lanes/concerns/sorting_expressions.rb +34 -0
  209. data/lib/lanes/configuration.rb +48 -9
  210. data/lib/lanes/extension.rb +16 -7
  211. data/lib/lanes/extension/definition.rb +8 -2
  212. data/lib/lanes/job.rb +78 -0
  213. data/lib/lanes/job/failure_logger.rb +33 -0
  214. data/lib/lanes/model.rb +4 -0
  215. data/lib/lanes/rake_tasks.rb +6 -0
  216. data/lib/lanes/redis.rb +13 -0
  217. data/lib/lanes/screen.rb +34 -18
  218. data/lib/lanes/system_settings.rb +66 -0
  219. data/lib/lanes/version.rb +1 -1
  220. data/lib/lanes/workspace/extension.rb +1 -1
  221. data/npm-build/base.js +10 -3
  222. data/npm-build/calendar.js +6 -0
  223. data/npm-build/development.js +4 -5
  224. data/npm-build/grid.js +3 -5
  225. data/npm-build/package.json +40 -29
  226. data/npm-build/react-toggle.js +5 -0
  227. data/npm-build/react-widgets.js +6 -0
  228. data/npm-build/update-dayz +14 -0
  229. data/npm-build/webpack.config.js +5 -2
  230. data/spec/command-reference-files/initial/Gemfile +1 -1
  231. data/spec/command-reference-files/initial/config/routes.rb +2 -0
  232. data/spec/command-reference-files/initial/lib/appy-app.rb +4 -0
  233. data/spec/command-reference-files/initial/lib/appy-app/extension.rb +2 -0
  234. data/spec/command-reference-files/initial/spec/server/{spec_helpers.rb → spec_helper.rb} +0 -0
  235. data/spec/command-reference-files/model/config/routes.rb +2 -0
  236. data/spec/command-reference-files/model/spec/server/test_test_spec.rb +1 -1
  237. data/spec/command-reference-files/screen/client/appy-app/screens/ready-set-go/ReadySetGo.cjsx +6 -4
  238. data/spec/command-reference-files/screen/client/appy-app/screens/ready-set-go/index.scss +4 -3
  239. data/spec/command-reference-files/screen/config/screens.rb +4 -2
  240. data/spec/command-reference-files/screen/spec/appy-app/screens/ready-set-go/ReadySetGoSpec.coffee +1 -1
  241. data/spec/fixtures/system_settings.yml +1 -0
  242. data/spec/lanes/components/grid/GridSpec.coffee +56 -31
  243. data/spec/lanes/components/grid/RowEditorSpec.coffee +96 -0
  244. data/spec/lanes/components/select-field/SelectFieldSpec.coffee +99 -0
  245. data/spec/lanes/components/shared/NetworkActivityOverlaySpec.coffee +34 -0
  246. data/spec/lanes/models/AssociationMapSpec.coffee +36 -2
  247. data/spec/lanes/models/AssociationProxySpec.coffee +77 -0
  248. data/spec/lanes/models/BaseSpec.coffee +37 -4
  249. data/spec/lanes/models/CollectionSpec.coffee +11 -17
  250. data/spec/lanes/models/PubSubSpec.coffee +1 -1
  251. data/spec/lanes/models/ServerCacheSpec.coffee +65 -0
  252. data/spec/server/api/coffeescript_processor_spec.rb +1 -1
  253. data/spec/server/concerns/pub_sub_spec.rb +9 -10
  254. data/spec/server/concerns/sorting_expressions_spec.rb +34 -0
  255. data/spec/server/configuration_spec.rb +3 -3
  256. data/spec/server/job_spec.rb +54 -0
  257. data/spec/server/spec_helper.rb +0 -5
  258. data/spec/server/system_settings_spec.rb +23 -0
  259. data/templates/client/screens/Screen.cjsx +6 -4
  260. data/templates/client/screens/styles.scss +4 -3
  261. data/templates/config/routes.rb +2 -0
  262. data/templates/config/screen.rb +4 -2
  263. data/templates/lib/namespace.rb +4 -0
  264. data/templates/lib/namespace/extension.rb +2 -0
  265. data/templates/spec/client/Screen.coffee +1 -1
  266. data/templates/spec/server/model_spec.rb +1 -1
  267. data/templates/spec/server/{spec_helpers.rb → spec_helper.rb} +0 -0
  268. data/views/lanes_root_view.erb +70 -0
  269. data/views/specs.erb +2 -2
  270. metadata +207 -68
  271. data/client/images/lanes/dataTables/Sorting icons.psd +0 -0
  272. data/client/images/lanes/dataTables/back_disabled.png +0 -0
  273. data/client/images/lanes/dataTables/back_enabled.png +0 -0
  274. data/client/images/lanes/dataTables/back_enabled_hover.png +0 -0
  275. data/client/images/lanes/dataTables/favicon.ico +0 -0
  276. data/client/images/lanes/dataTables/forward_disabled.png +0 -0
  277. data/client/images/lanes/dataTables/forward_enabled.png +0 -0
  278. data/client/images/lanes/dataTables/forward_enabled_hover.png +0 -0
  279. data/client/images/lanes/dataTables/loading-background.png +0 -0
  280. data/client/images/lanes/dataTables/sort_asc.png +0 -0
  281. data/client/images/lanes/dataTables/sort_asc_disabled.png +0 -0
  282. data/client/images/lanes/dataTables/sort_both.png +0 -0
  283. data/client/images/lanes/dataTables/sort_desc.png +0 -0
  284. data/client/images/lanes/dataTables/sort_desc_disabled.png +0 -0
  285. data/client/lanes/components/shared/Resize.cjsx +0 -152
  286. data/client/lanes/components/shared/TextArea.cjsx +0 -19
  287. data/client/lanes/components/shared/TextField.cjsx +0 -25
  288. data/client/lanes/models/Bootstrap.coffee +0 -5
  289. data/client/lanes/models/QueryResults.coffee +0 -93
  290. data/client/lanes/react/FormBindings.coffee +0 -103
  291. data/client/lanes/react/Router.cjsx +0 -18
  292. data/client/lanes/styles/dataTables.scss +0 -4
  293. data/client/lanes/styles/plugins/all.scss +0 -2
  294. data/client/lanes/styles/plugins/resize-sensor.scss +0 -24
  295. data/client/lanes/vendor/jquery-2.js +0 -9190
  296. data/client/lanes/vendor/jquery.tap.js +0 -401
  297. data/client/lanes/vendor/magicsuggest.js +0 -1565
  298. data/client/lanes/vendor/message-bus.coffee +0 -264
  299. data/client/lanes/workspace/ActiveScreenSwitcher.cjsx +0 -38
  300. data/client/lanes/workspace/styles/toolbar.scss +0 -4
  301. data/lib/lanes/api/eco.js +0 -516
  302. data/lib/lanes/api/sprockets_compressor.rb +0 -39
  303. data/spec/command-reference-files/model/lib/appy-app.rb +0 -11
  304. data/views/index.erb +0 -19
@@ -20,8 +20,7 @@ module Lanes
20
20
  @relaying_messages = true
21
21
  Lanes::Model.observe(:save) do |model|
22
22
  if model.changes.any?
23
- path = "/#{model.class.api_path}/#{model.id}"
24
-
23
+ path = "/#{model.class.api_path(with_module: true)}/#{model.id}"
25
24
  Lanes::API::PubSub.publish(path, {
26
25
  by: self.user_info_for_change(model),
27
26
  update: model.changes
data/lib/lanes/command.rb CHANGED
@@ -19,7 +19,6 @@ module Lanes
19
19
  #
20
20
  # @return [Extension] extension that was loaded, nil if none was found
21
21
  def load_current_extension(raise_on_fail:false)
22
- previous = Extensions.all
23
22
  ext = Dir.glob("./lib/*/extension.rb").first
24
23
  if ext
25
24
  begin
@@ -4,9 +4,9 @@ module Lanes
4
4
  class App < NamedCommand
5
5
 
6
6
  class_options :force => :boolean
7
-
8
- class_option :directory, :type=>:string
9
-
7
+ class_option :directory, type: :string
8
+ class_option :title, type: :string
9
+ attr_reader :title
10
10
 
11
11
  def load_namespace # override
12
12
  @namespace = name.underscore.camelize
@@ -15,6 +15,7 @@ module Lanes
15
15
 
16
16
  def set_variables
17
17
  super
18
+ @title = options[:title] || @namespace
18
19
  self.destination_root = options[:directory] || name
19
20
  end
20
21
 
@@ -54,8 +55,8 @@ module Lanes
54
55
  def create_spec_helpers
55
56
  template "spec/client/helpers/ClientHelpers.coffee",
56
57
  "#{spec_dir}/helpers/#{namespace}Helpers.coffee"
57
- template "spec/server/spec_helpers.rb",
58
- "spec/server/spec_helpers.rb"
58
+ template "spec/server/spec_helper.rb",
59
+ "spec/server/spec_helper.rb"
59
60
  end
60
61
 
61
62
  def create_screen_base
@@ -11,6 +11,7 @@ module Lanes
11
11
  require 'pp'
12
12
  DB.establish_connection
13
13
  ActiveRecord::Base.logger = Logger.new STDOUT
14
+ Configuration.apply
14
15
  ARGV.clear
15
16
  IRB.start
16
17
  end
@@ -3,6 +3,9 @@ module Lanes
3
3
 
4
4
  class Generate < Thor
5
5
 
6
+ long_desc Command.usage_from_file("generate_model")
7
+ method_options( GenerateMigration::OPTIONS )
8
+ register Command::GenerateMigration, 'migration', 'migration [NAME] ...FIELDS', 'Creates a new migration'
6
9
  long_desc Command.usage_from_file("generate_model")
7
10
  method_options( GenerateModel::OPTIONS )
8
11
  register Command::GenerateModel, 'model', 'model [NAME] ...FIELDS', 'Creates a new model'
@@ -0,0 +1,33 @@
1
+ require_relative 'model_attribute'
2
+
3
+ module Lanes
4
+ module Command
5
+
6
+ class GenerateMigration < NamedCommand
7
+
8
+ include MigrationSupport
9
+
10
+ OPTIONS ||= {
11
+ timestamps: true
12
+ }
13
+
14
+ class_options OPTIONS
15
+
16
+ argument :fields, type: :array, default: []
17
+
18
+ attr_reader :file_name, :table_name
19
+
20
+ def set_variables
21
+ super
22
+ @file_name = name.underscore
23
+ prefix = extension.db_table_prefix
24
+ @table_name = prefix ? "#{prefix}_#{name.tableize}" : name.tableize
25
+ end
26
+
27
+ def generate_module
28
+ create_migration
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -4,6 +4,8 @@ module Lanes
4
4
  module Command
5
5
 
6
6
  class GenerateModel < NamedCommand
7
+ include MigrationSupport
8
+
7
9
  RESERVED_YAML_KEYWORDS = %w(y yes n no true false on off null)
8
10
  OPTIONS ||= {
9
11
  timestamps: true,
@@ -23,11 +25,8 @@ module Lanes
23
25
  @table_name = prefix ? "#{prefix}_#{name.tableize}" : name.tableize
24
26
  end
25
27
 
26
- def create_migration
27
- migration = exising_migration ||
28
- migration_timestamp + "_create_#{table_name}.rb"
29
- self.fields = fields.map{ |field| ModelAttribute.parse(field) }
30
- template "db/create_table_migration.rb", "db/migrate/#{migration}"
28
+ def generate_migration
29
+ create_migration
31
30
  end
32
31
 
33
32
  def create_model
@@ -59,19 +58,6 @@ module Lanes
59
58
 
60
59
  private
61
60
 
62
- def fields_with_index
63
- fields.select { |a| !a.reference? && a.has_index? }
64
- end
65
-
66
- def exising_migration
67
- migrations = Pathname.glob("#{destination_root}/db/migrate/[0-9]*_create_#{table_name}.rb")
68
- migrations.any? ? migrations.first.basename.to_s : nil
69
- end
70
-
71
- def migration_timestamp
72
- ENV['MIGRATION_TIMESTAMP'] || Time.now.utc.strftime("%Y%m%d%H%M%S")
73
- end
74
-
75
61
  def computed_namespace
76
62
  # find a file and directory with the same basename
77
63
  entries = Dir.glob(self.destination_root + "/lib/*")
@@ -91,14 +77,6 @@ module Lanes
91
77
  end
92
78
  end
93
79
 
94
- # def client_parent
95
- # if options[:parent] == 'Lanes::Model'
96
- # "Lanes.Models.Base"
97
- # else
98
- # "#{namespace.camelize}.Models.#{options[:parent]}"
99
- # end
100
- # end
101
-
102
80
  def max_field_length
103
81
  @max_field_length ||= fields.map{|field|
104
82
  field.name.length + ( field.reference? ? 3 : 0 )
@@ -0,0 +1,29 @@
1
+ require_relative 'model_attribute'
2
+
3
+ module Lanes
4
+ module Command
5
+ module MigrationSupport
6
+ def create_migration
7
+ migration = existing_migration ||
8
+ migration_timestamp + "_create_#{table_name}.rb"
9
+ self.fields = fields.map{ |field| ModelAttribute.parse(field) }
10
+ template "db/create_table_migration.rb", "db/migrate/#{migration}"
11
+ end
12
+
13
+ private
14
+
15
+ def existing_migration
16
+ migrations = Pathname.glob("#{destination_root}/db/migrate/[0-9]*_create_#{table_name}.rb")
17
+ migrations.any? ? migrations.first.basename.to_s : nil
18
+ end
19
+
20
+ def migration_timestamp
21
+ ENV['MIGRATION_TIMESTAMP'] || Time.now.utc.strftime("%Y%m%d%H%M%S")
22
+ end
23
+
24
+ def fields_with_index
25
+ fields.select { |a| !a.reference? && a.has_index? }
26
+ end
27
+ end
28
+ end
29
+ end
@@ -7,6 +7,11 @@ module Lanes
7
7
 
8
8
  attr_reader :namespaced_name
9
9
 
10
+ def set_variables
11
+ super
12
+ @file_name = name.underscore
13
+ end
14
+
10
15
  def read_class
11
16
  if name=~/::/
12
17
  (@namespace,@name) = name.split("::")
@@ -14,7 +19,7 @@ module Lanes
14
19
  ext = Command.load_current_extension(raise_on_fail:true)
15
20
  @namespace = ext.identifier
16
21
  end
17
- class_name = name.camelize
22
+
18
23
  namespaced_name = "#{namespace.classify}::#{class_name}"
19
24
  @klass = namespaced_name.safe_constantize
20
25
  if !@klass
@@ -80,9 +85,13 @@ module Lanes
80
85
  else
81
86
  type = { type: type_for_column(column), required: true }
82
87
  if column.default
83
- type[:default] = column.default
88
+ type[:default] = case column.default
89
+ when 'true' then true
90
+ when 'false' then false
91
+ else column.default
92
+ end
84
93
  end
85
- type.to_json
94
+ type.to_json.gsub(%r{,"}, ', "')
86
95
  end
87
96
  end
88
97
 
@@ -104,10 +113,10 @@ module Lanes
104
113
  when :datetime then 'date'
105
114
  when :integer then 'integer'
106
115
  when :float then 'number'
107
- when :text then 'string'
108
- when :string then 'string'
109
116
  when :boolean then 'boolean'
110
117
  when :decimal then 'bigdec'
118
+ when :text, :string then 'string'
119
+ when :jsonb, :json, :hstore then 'object'
111
120
  else 'any'
112
121
  end
113
122
  end
@@ -10,3 +10,5 @@ require_relative "pub_sub"
10
10
  require_relative "code_identifier"
11
11
  require_relative "queries"
12
12
  require_relative "sanitize_fields"
13
+ require_relative "image_uploader.rb"
14
+ require_relative "sorting_expressions"
@@ -6,12 +6,14 @@ module Lanes::Concerns
6
6
 
7
7
  module ClassMethods
8
8
 
9
- def api_path
10
- self.to_s.demodulize.pluralize.underscore.dasherize
9
+ def api_path(with_module: false)
10
+ path = with_module ? to_s : to_s.demodulize
11
+ path.pluralize.underscore.dasherize
11
12
  end
12
13
 
13
14
  def from_api_path(path)
14
15
  name = path.underscore.camelize.singularize
16
+
15
17
  name = "Lanes::#{name}" unless name=~/^Lanes/
16
18
  name.safe_constantize
17
19
  end
@@ -63,7 +63,7 @@ module Lanes::Concerns
63
63
  end
64
64
  begin
65
65
  klass = association.klass # This will throw if the class hasn't been loaded yet
66
- targets.each{ | name, proc | klass._add_event_listener( name, &proc ) }
66
+ targets.each{ | name, proc | klass.send :_add_event_listener, name, &proc }
67
67
  rescue NameError
68
68
  pending = Lanes::Concerns::PubSub::PendingListeners.add(association.class_name)
69
69
  targets.each do | name, proc |
@@ -52,7 +52,9 @@ module Lanes::Concerns
52
52
  if instance_variable_defined?(instance_var)
53
53
  instance_variable_get(instance_var)
54
54
  else
55
- instance_variable_set(instance_var, default.is_a?(Proc) ? default.call : default )
55
+ instance_variable_set(instance_var,
56
+ default.is_a?(Proc) ?
57
+ instance_exec(&default) : default )
56
58
  end
57
59
  end
58
60
  end
@@ -26,7 +26,7 @@ module Lanes
26
26
  before_validation(:on=>:create) do
27
27
  source = self[from]
28
28
  unless source.blank?
29
- self.code ||= Lanes::Strings.code_identifier( source, length:max_length )
29
+ self.code ||= Lanes::Strings.code_identifier( source, length:max_length, padding: '' )
30
30
  end
31
31
  end
32
32
  end
@@ -0,0 +1,42 @@
1
+ require 'mini_magick'
2
+ require 'carrierwave'
3
+ require 'fastimage'
4
+
5
+ module Lanes::Concerns
6
+
7
+ class ImageUploader < CarrierWave::Uploader::Base
8
+
9
+ include CarrierWave::MiniMagick
10
+
11
+ version :medium do
12
+ process :resize_to_fit => [800, 800]
13
+ end
14
+
15
+ version :thumb do
16
+ process :resize_to_fit => [200,200]
17
+ end
18
+
19
+ def cache_dir
20
+ '/tmp'
21
+ end
22
+
23
+ def store_dir
24
+ "images/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
25
+ end
26
+
27
+ def filename
28
+ if original_filename.present?
29
+ ext = FastImage.type(file.file)
30
+ "#{secure_token}.#{ext}"
31
+ end
32
+ end
33
+
34
+ protected
35
+
36
+ def secure_token
37
+ var = :"@#{mounted_as}_secure_token"
38
+ model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.hex(6))
39
+ end
40
+ end
41
+
42
+ end
@@ -113,7 +113,6 @@ module Lanes::Concerns
113
113
  def fire_pubsub_event(name, *arguments)
114
114
  return if self.class._event_listeners.nil? ||
115
115
  !self.class._event_listeners.has_key?(name.to_sym)
116
- arguments = arguments.dup.unshift(self)
117
116
  self.class._event_listeners[ name.to_sym ].each{ | block |
118
117
  block.call(*arguments)
119
118
  }
@@ -9,9 +9,9 @@ module Lanes
9
9
  module ClassMethods
10
10
 
11
11
  def compose_query_using_detail_view( view: nil, join_to: nil )
12
- view = Lanes.config.table_prefix + view.to_s
12
+ join_to = "#{table_name.singularize}_#{primary_key}" unless join_to
13
13
  joins("join #{view} as details on details.#{join_to} = #{table_name}.#{primary_key}")
14
- .select("#{table_name}.*, details.*")
14
+ .select("#{table_name}.*, details.*")
15
15
  end
16
16
 
17
17
  end
@@ -95,28 +95,19 @@ module Lanes::Concerns
95
95
  target = send(name) || association.build
96
96
  result[name] = target.set_attribute_data(value, user)
97
97
  elsif value.is_a?(Array) && :has_many == association.reflection.macro
98
- result[name] = _set_attribute_data_from_collection(association, value, user)
98
+ result[name] = _set_attribute_data_from_collection(association, name, value, user)
99
99
  end
100
100
  end
101
101
  end
102
102
  end
103
103
 
104
- def _set_attribute_data_from_collection(association, value, user)
105
-
106
- records = if association.loaded?
107
- association.target
108
- else
109
- attribute_ids = value.map {|a| a['id'] || a[:id] }.compact
110
- attribute_ids.empty? ? [] : association.scope.where(
111
- association.klass.primary_key => attribute_ids
112
- )
113
- end
114
-
104
+ def _set_attribute_data_from_collection(association, name, value, user)
105
+ records = public_send(name, value)
115
106
  value.map do | association_data |
116
107
  record = if association_data['id'].blank?
117
108
  association.build
118
109
  else
119
- records.detect{ |r| r.id.to_s == value['id'].to_s }
110
+ records.detect{ |r| r.id.to_s == association_data['id'].to_s }
120
111
  end
121
112
  record.set_attribute_data(association_data, user) if record
122
113
  end
@@ -0,0 +1,34 @@
1
+ module Lanes::Concerns
2
+
3
+ # @see ClassMethods
4
+ module SortingExpressions
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ # Add a proc that will be called to add a sort expression to a query.
9
+ # The proc should accept an arel query object and a single direction parameter,
10
+ # which will be a symbol value of :asc or :desc
11
+ # It must return a arel query with the sort applied
12
+ # @param name [String] The name of the expression
13
+ def export_sort( name, &block )
14
+ @sorting_expressions ||= {}
15
+ @sorting_expressions[name.to_s] = block
16
+ end
17
+
18
+ def has_sorting_expression?(name)
19
+ @sorting_expressions && @sorting_expressions[name]
20
+ end
21
+
22
+ def append_sort_to_query(query, field, dir)
23
+ dir = :asc unless dir == :desc
24
+ if @sorting_expressions && (block = @sorting_expressions[field])
25
+ block.call(query, dir)
26
+ else
27
+ query.order(field.gsub(/[^\w|^\.]/,'') + ' ' +
28
+ ( ( :asc == dir ) ? 'ASC' : 'DESC' ) )
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -1,6 +1,12 @@
1
1
  require_relative "concerns/attr_accessor_with_default"
2
2
  require 'securerandom'
3
3
  require 'pathname'
4
+ require 'carrierwave'
5
+ require 'active_job'
6
+ require 'jobba'
7
+ require 'fog'
8
+ require 'message_bus'
9
+
4
10
  module Lanes
5
11
 
6
12
  class Configuration
@@ -40,6 +46,39 @@ module Lanes
40
46
  value
41
47
  end
42
48
 
49
+ def self.apply
50
+ identifier = Lanes::Extensions.controlling.identifier
51
+ ActiveJob::Base.queue_adapter = Lanes.env.test? ? :test : :resque
52
+ Lanes::Job::FailureLogger.configure
53
+
54
+ DB.establish_connection
55
+
56
+ Jobba.configure do |config|
57
+ config.redis_options = Lanes.config.redis
58
+ config.namespace = "#{identifier}::jobba"
59
+ end
60
+
61
+
62
+ Resque.redis.namespace = "#{identifier}::resque"
63
+ Resque.redis = Lanes.config.redis
64
+ MessageBus.redis_config = Lanes.config.redis
65
+ MessageBus.logger = Lanes.logger
66
+ CarrierWave.configure do |config|
67
+ settings = Lanes::SystemSettings.for_ext('lanes')
68
+ config.storage = settings.file_storage ? settings.file_storage.to_sym : :file
69
+ config.root = lambda {
70
+ Lanes::SystemSettings.for_ext('lanes').storage_dir ||
71
+ Lanes::Extensions.controlling.root_path.join('public/assets').to_s
72
+ }
73
+ config.asset_host = Lanes.config.api_path + 'file'
74
+ config.fog_credentials = settings.fog_credentials
75
+ config.ignore_integrity_errors = false
76
+ config.ignore_processing_errors = false
77
+ config.ignore_download_errors = false
78
+ end
79
+ Extensions.each{|ext| ext.apply_configuration }
80
+ end
81
+
43
82
  end
44
83
 
45
84
  class DefaultConfiguration < Configuration
@@ -48,9 +87,6 @@ module Lanes
48
87
  # we don't care about AttrReaderWithDefault sharing values between instances
49
88
  # Therefore all the values are given directly and not enclosed in Procs/lambdas.
50
89
 
51
- # Database tables will have this prefix applied to them
52
- config_option :table_prefix, ''
53
-
54
90
  # The configuration environment to use, test, development, production
55
91
  config_option :environment, (ENV['LANES_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development').to_sym
56
92
 
@@ -58,17 +94,14 @@ module Lanes
58
94
  config_option :session_secret_key_base, '1234', silent: true
59
95
 
60
96
  # Configuration for Redis
61
- config_option :redis, ENV.has_key?('REDISTOGO_URL') ?
62
- {url: ENV["REDISTOGO_URL"]} : {path: "/tmp/redis.sock"}
63
-
64
- # Title of application
65
- config_option :app_title, "Lanes Test"
97
+ config_option :redis, ENV.has_key?('REDIS_URL') ?
98
+ {url: ENV["REDIS_URL"]} : {path: "/tmp/redis.sock"}
66
99
 
67
100
  # url prefix to use for assets
68
101
  config_option :assets_path_prefix, "/assets"
69
102
 
70
103
  # prefix to use for all urls
71
- config_option :mounted_at, ''
104
+ config_option :mounted_at, '/'
72
105
 
73
106
  # The initial view class to display
74
107
  config_option :root_view, 'Lanes.Workspace.Layout'
@@ -78,6 +111,12 @@ module Lanes
78
111
 
79
112
  # types of assets to include into compiled package
80
113
  config_option :static_asset_types, ['images','fonts']
114
+
115
+ config_option :configuration_id, (ENV['LANES_CONFIG_ID'] || 1)
116
+
117
+ def api_path
118
+ mounted_at + 'api/'
119
+ end
81
120
  end
82
121
 
83
122
  class << self