hippo-fw 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/.nvmrc +2 -0
  3. data/.travis.yml +1 -1
  4. data/client/hippo/access/login-dialog.jsx +3 -5
  5. data/client/hippo/boot.jsx +2 -2
  6. data/client/hippo/components/asset.jsx +0 -1
  7. data/client/hippo/components/data-list.jsx +16 -15
  8. data/client/hippo/components/data-list/data-list.scss +10 -0
  9. data/client/hippo/components/data-table.jsx +14 -14
  10. data/client/hippo/components/data-table/header-cell.jsx +0 -1
  11. data/client/hippo/components/data-table/table-styles.scss +7 -0
  12. data/client/hippo/components/date-time.jsx +19 -16
  13. data/client/hippo/components/date-time/calendar.jsx +5 -7
  14. data/client/hippo/components/date-time/date-time-drop.jsx +0 -2
  15. data/client/hippo/components/date-time/time.jsx +0 -1
  16. data/client/hippo/components/form.jsx +1 -1
  17. data/client/hippo/components/form/{model.js → api.js} +25 -7
  18. data/client/hippo/components/form/fields.jsx +12 -11
  19. data/client/hippo/components/form/fields/date-wrapper.jsx +1 -1
  20. data/client/hippo/components/form/fields/form-field.scss +9 -1
  21. data/client/hippo/components/form/fields/label.jsx +14 -0
  22. data/client/hippo/components/form/fields/select-wrapper.jsx +2 -3
  23. data/client/hippo/components/form/wrapper.jsx +1 -3
  24. data/client/hippo/components/icon.jsx +2 -69
  25. data/client/hippo/components/master-detail.jsx +0 -2
  26. data/client/hippo/components/network-activity-overlay.jsx +1 -4
  27. data/client/hippo/components/query-builder.jsx +15 -16
  28. data/client/hippo/components/record-finder.jsx +2 -5
  29. data/client/hippo/components/record-finder/query-layer.jsx +1 -5
  30. data/client/hippo/components/screen.jsx +7 -3
  31. data/client/hippo/components/text-editor.jsx +2 -8
  32. data/client/hippo/components/tool-tip.jsx +2 -3
  33. data/client/hippo/components/warning-notification.jsx +3 -3
  34. data/client/hippo/lib/date-range.js +28 -0
  35. data/client/hippo/lib/util.js +6 -0
  36. data/client/hippo/models/asset.js +6 -3
  37. data/client/hippo/models/config.js +1 -1
  38. data/client/hippo/models/pub_sub.js +12 -7
  39. data/client/hippo/models/pub_sub/channel.js +6 -4
  40. data/client/hippo/models/query.js +19 -4
  41. data/client/hippo/models/query/array-result.js +9 -8
  42. data/client/hippo/models/query/clause.js +21 -13
  43. data/client/hippo/models/query/field.js +7 -2
  44. data/client/hippo/models/query/info.js +7 -3
  45. data/client/hippo/models/sync.js +11 -14
  46. data/client/hippo/react/Root.jsx +1 -2
  47. data/client/hippo/react/{DefaultComponentNotFound.jsx → component-not-found.jsx} +1 -3
  48. data/client/hippo/screens/index.js +6 -2
  49. data/client/hippo/screens/system-settings.jsx +10 -6
  50. data/client/hippo/screens/system-settings/mailer-config.jsx +0 -2
  51. data/client/hippo/screens/system-settings/tenant.jsx +1 -4
  52. data/client/hippo/screens/user-management.jsx +0 -1
  53. data/client/hippo/screens/user-management/edit-form.jsx +1 -2
  54. data/client/hippo/workspace/index.jsx +21 -12
  55. data/client/hippo/workspace/menu-group.jsx +4 -7
  56. data/client/hippo/workspace/menu-option.jsx +1 -3
  57. data/client/hippo/workspace/menu.jsx +29 -11
  58. data/client/hippo/workspace/navbar.jsx +1 -2
  59. data/client/hippo/workspace/root-view.jsx +5 -2
  60. data/client/hippo/workspace/screen.jsx +2 -3
  61. data/client/hippo/workspace/styles.scss +17 -0
  62. data/command-reference-files/screen/client/appy-app/screens/ready-set-go.jsx +2 -1
  63. data/db/migrate/20170530120004_create_users.rb +1 -1
  64. data/hippo-fw.gemspec +3 -2
  65. data/lib/hippo/api/cable.rb +13 -13
  66. data/lib/hippo/api/controller_base.rb +1 -0
  67. data/lib/hippo/api/handlers/tenant.rb +1 -1
  68. data/lib/hippo/api/handlers/user_session.rb +2 -1
  69. data/lib/hippo/api/helper_methods.rb +4 -1
  70. data/lib/hippo/api/pub_sub.rb +7 -6
  71. data/lib/hippo/api/to_json.rb +1 -1
  72. data/lib/hippo/api/updates.rb +2 -0
  73. data/lib/hippo/command/console.rb +11 -3
  74. data/lib/hippo/command/jest.rb +2 -0
  75. data/lib/hippo/configuration.rb +4 -7
  76. data/lib/hippo/rake_tasks.rb +1 -1
  77. data/lib/hippo/screen.rb +31 -93
  78. data/lib/hippo/screen/definition.rb +76 -0
  79. data/lib/hippo/screen/group.rb +26 -0
  80. data/lib/hippo/spec_helper.rb +3 -0
  81. data/lib/hippo/system_settings.rb +6 -0
  82. data/lib/hippo/user.rb +11 -3
  83. data/lib/hippo/version.rb +1 -1
  84. data/package-lock.json +419 -533
  85. data/package.json +32 -30
  86. data/spec/client/access/login-dialog.spec.jsx +4 -5
  87. data/spec/client/components/__snapshots__/query-builder.spec.jsx.snap +1 -1
  88. data/spec/client/components/__snapshots__/record-finder.spec.jsx.snap +72 -0
  89. data/spec/client/components/asset.spec.jsx +2 -6
  90. data/spec/client/components/data-list.spec.jsx +2 -6
  91. data/spec/client/components/data-table.spec.jsx +3 -5
  92. data/spec/client/components/date-time.spec.jsx +1 -1
  93. data/spec/client/components/form.spec.jsx +2 -2
  94. data/spec/client/components/master-detail.spec.jsx +1 -2
  95. data/spec/client/components/network-activity-overlay.spec.jsx +2 -3
  96. data/spec/client/components/query-builder.spec.jsx +3 -6
  97. data/spec/client/components/record-finder.spec.jsx +4 -4
  98. data/spec/client/models/pub_sub.spec.js +3 -1
  99. data/spec/client/models/query.spec.js +4 -9
  100. data/spec/client/screens/system-settings-tenants.spec.jsx +1 -1
  101. data/spec/client/screens/system-settings.spec.jsx +1 -4
  102. data/spec/client/workspace/__snapshots__/menu.spec.jsx.snap +15 -20
  103. data/spec/client/workspace/menu.spec.jsx +1 -2
  104. data/spec/server/api/user_sessions_spec.rb +15 -0
  105. data/templates/client/screens/screen.jsx +2 -1
  106. data/views/hippo_root_view.erb +1 -0
  107. metadata +30 -52
  108. data/client/hippo/components/calendar/Calendar.jsx +0 -25
  109. data/client/hippo/components/calendar/index.js +0 -3
  110. data/client/hippo/components/calendar/styles.scss +0 -3
  111. data/client/hippo/components/shared/AssetsListing.jsx +0 -23
  112. data/client/hippo/components/shared/Checkbox.jsx +0 -49
  113. data/client/hippo/components/shared/CountBadge.jsx +0 -13
  114. data/client/hippo/components/shared/DateTime.jsx +0 -58
  115. data/client/hippo/components/shared/DisplayValue.jsx +0 -15
  116. data/client/hippo/components/shared/ErrorDisplay.jsx +0 -37
  117. data/client/hippo/components/shared/FieldMixin.jsx +0 -254
  118. data/client/hippo/components/shared/FieldSet.jsx +0 -52
  119. data/client/hippo/components/shared/FieldWrapper.jsx +0 -94
  120. data/client/hippo/components/shared/FormGroup.jsx +0 -41
  121. data/client/hippo/components/shared/GenericField.jsx +0 -7
  122. data/client/hippo/components/shared/IconButton.jsx +0 -13
  123. data/client/hippo/components/shared/ImageAsset.jsx +0 -78
  124. data/client/hippo/components/shared/IndeterminateCheckbox.jsx +0 -31
  125. data/client/hippo/components/shared/Input.jsx +0 -16
  126. data/client/hippo/components/shared/InputFieldMixin.jsx +0 -78
  127. data/client/hippo/components/shared/JobProgress.jsx +0 -46
  128. data/client/hippo/components/shared/NumberInput.jsx +0 -37
  129. data/client/hippo/components/shared/PanelHeader.jsx +0 -15
  130. data/client/hippo/components/shared/RadioField.jsx +0 -33
  131. data/client/hippo/components/shared/ResizeSensor.jsx +0 -18
  132. data/client/hippo/components/shared/ScreenWrapper.jsx +0 -17
  133. data/client/hippo/components/shared/TextArea.jsx +0 -19
  134. data/client/hippo/components/shared/Throbber.jsx +0 -8
  135. data/client/hippo/components/shared/ToggleField.jsx +0 -2
  136. data/client/hippo/components/shared/Tooltip.jsx +0 -23
  137. data/client/hippo/components/shared/fields.scss +0 -58
  138. data/client/hippo/components/shared/fieldset.scss +0 -27
  139. data/client/hippo/components/shared/image-asset.scss +0 -53
  140. data/client/hippo/components/shared/index.js +0 -5
  141. data/client/hippo/components/shared/overlay.scss +0 -83
  142. data/client/hippo/components/shared/resize-sensor.scss +0 -30
  143. data/client/hippo/components/shared/styles.scss +0 -64
  144. data/client/hippo/components/shared/throbber.scss +0 -53
  145. data/client/hippo/fonts/fontawesome-webfont.woff +0 -0
  146. data/client/hippo/fonts/fontawesome-webfont.woff2 +0 -0
  147. data/client/hippo/workspace/content.jsx +0 -22
  148. data/client/hippo/workspace/tabs.jsx +0 -60
  149. data/client/hippo/workspace/viewport.jsx +0 -82
  150. data/spec/client/screens/__snapshots__/tabs.spec.jsx.snap +0 -127
  151. data/spec/client/screens/tabs.spec.jsx +0 -36
@@ -36,3 +36,20 @@ pre {
36
36
  display: flex;
37
37
  }
38
38
  }
39
+
40
+ .sidebar-toggle {
41
+ position: fixed;
42
+ left: 0;
43
+ bottom: 0;
44
+ z-index: 1;
45
+ border-top-left-radius: 0;
46
+ border-bottom-right-radius: 0;
47
+ opacity: 0.2;
48
+ transistion: all 0.4s;
49
+ &:hover {
50
+ opacity: 1.0;
51
+ }
52
+ &.is-open {
53
+ display:none;
54
+ }
55
+ }
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import PropTypes from 'prop-types';
2
3
  import { observer } from 'mobx-react';
3
4
  import Screen from 'hippo/components/screen';
4
5
 
@@ -6,7 +7,7 @@ import Screen from 'hippo/components/screen';
6
7
  export default class ReadySetGo extends React.PureComponent {
7
8
 
8
9
  static propTypes = {
9
- screen: React.PropTypes.instanceOf(Screen.Instance).isRequired,
10
+ screen: PropTypes.instanceOf(Screen.Instance).isRequired,
10
11
  }
11
12
 
12
13
  render() {
@@ -9,6 +9,6 @@ class CreateUsers < ActiveRecord::Migration[5.0]
9
9
  t.timestamps null:false
10
10
  end
11
11
 
12
- add_index :users, [:login, :tenant_id], unique: true
12
+ add_index :users, 'lower(login), tenant_id', name: 'index_users_on_login_and_tenant_id', unique: true
13
13
  end
14
14
  end
data/hippo-fw.gemspec CHANGED
@@ -26,9 +26,10 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency "activejob", "~> 5.1.0"
28
28
  spec.add_dependency "activerecord", "~> 5.1.0"
29
- spec.add_dependency "activerecord-multi-tenant", "~> 0.6"
29
+ spec.add_dependency "activerecord-multi-tenant", "~> 0.7"
30
30
 
31
31
  spec.add_dependency "litecable", "~> 0.4.1"
32
+ spec.add_dependency "anycable", "~> 0.4.6"
32
33
  spec.add_dependency "websocket", "~> 1.2.4"
33
34
  spec.add_dependency "mail", "~> 2.6"
34
35
  spec.add_dependency "scenic", "~> 1.4"
@@ -65,7 +66,7 @@ Gem::Specification.new do |spec|
65
66
  spec.add_dependency "jwt", "~> 1.5"
66
67
  spec.add_dependency "mini_magick", "~> 4.3"
67
68
 
68
- spec.add_dependency "oj", "~> 2.1"
69
+ spec.add_dependency "oj", "~> 3.3"
69
70
  spec.add_dependency "pg", "~> 0.8"
70
71
  spec.add_dependency "rake", "~> 12.0"
71
72
  spec.add_dependency "require_all", "~> 1.3"
@@ -1,4 +1,4 @@
1
- require "lite_cable"
1
+ require "action_cable"
2
2
 
3
3
  module Hippo
4
4
  module API
@@ -10,14 +10,13 @@ module Hippo
10
10
  @@server.call(request.env)
11
11
  end
12
12
 
13
- class Channel < LiteCable::Channel::Base
14
- end
15
-
16
- class Connection < LiteCable::Connection::Base
13
+ class Connection < ActionCable::Connection::Base
17
14
  identified_by :current_user
18
15
 
19
16
  def connect
20
17
  token = request.params['token']
18
+ Hippo.logger_debug("NEW WS CONN: #{token}")
19
+
21
20
  begin
22
21
  self.current_user = User.for_jwt_token(token) if token
23
22
  rescue JWT::DecodeError
@@ -37,15 +36,16 @@ module Hippo
37
36
 
38
37
  def self.configure
39
38
  require_relative './updates'
39
+ @@config = ActionCable::Server::Configuration.new
40
+ config.logger = Hippo.logger
41
+ config.cable = Hippo.config.cable
42
+ config.connection_class = -> { Connection }
43
+ config.allowed_request_origins = -> (host) {
44
+ host
45
+ }
46
+ ActionCable::Server::Base.config = config
47
+ @@server = ActionCable.server
40
48
 
41
- if Hippo.config.api_use_any_cable
42
-
43
- else
44
- require "lite_cable/server"
45
- @@server = LiteCable::Server::Middleware.new(
46
- Hippo::API::Root, connection_class: Hippo::API::Cable::Connection
47
- )
48
- end
49
49
  Updates.relay!
50
50
  end
51
51
 
@@ -212,6 +212,7 @@ module Hippo
212
212
  def add_modifiers_to_query(query)
213
213
  query = query.limit(query_limit_size)
214
214
  query = query.offset(query_offset.to_i) if query_offset.present?
215
+
215
216
  if include_associations.any?
216
217
  allowed_includes = include_associations.each_with_object([]) do |desired, results|
217
218
  if desired.is_a?(Hash)
@@ -12,7 +12,7 @@ module Hippo::API::Handlers
12
12
  tenant = Hippo::Tenant.current
13
13
  tenant.assign_attributes(data.slice(*PUBLIC_ATTRS))
14
14
  success = tenant.save
15
- if success
15
+ if success && tenant.slug_previously_changed?
16
16
  Hippo::Tenant.system.perform do
17
17
  Hippo::Templates::TenantChange.create(tenant).deliver
18
18
  end
@@ -8,7 +8,8 @@ module Hippo::API::Handlers
8
8
  def self.create
9
9
  lambda do
10
10
  wrap_reply(with_transaction: false) do
11
- user = Hippo::User.where(login: data['login']).first
11
+ user = Hippo::User.with_login(data['login']).first
12
+
12
13
  if user && user.authenticate(data['password'])
13
14
  { success: true, message: "Login succeeded",
14
15
  data: user.workspace_data }
@@ -34,7 +34,10 @@ module Hippo
34
34
  end
35
35
 
36
36
  def data
37
- @json_data ||= Oj.load( request.body.read ) || {}
37
+ @json_data ||= (
38
+ body = request.body.read
39
+ body.present? ? Oj.load(body) : {}
40
+ )
38
41
  end
39
42
 
40
43
  def request_origin
@@ -3,8 +3,7 @@ require_relative 'cable'
3
3
  module Hippo
4
4
  module API
5
5
 
6
- class PubSub < Cable::Channel
7
- identifier :pubsub
6
+ class PubSub < ActionCable::Channel::Base
8
7
 
9
8
  PREFIX = 'ps:'
10
9
 
@@ -14,14 +13,16 @@ module Hippo
14
13
  end
15
14
 
16
15
  def off(data)
17
- Hippo.logger.info "pubsub off: #{data['channel']}"
18
- stop_stream channel_prefix + data['channel']
16
+ channel = channel_prefix + data['channel']
17
+ subscribers = pubsub
18
+ .instance_variable_get('@listener')
19
+ .instance_variable_get('@subscribers')[channel]
20
+ pubsub.unsubscribe(channel, subscribers.first) if subscribers.any?
19
21
  end
20
22
 
21
23
  def self.publish(channel, data)
22
- Hippo.logger.info "pubsub pub: #{channel}"
23
24
  channel = channel_prefix + channel
24
- LiteCable.broadcast(channel, data.merge(channel: channel))
25
+ ActionCable.server.broadcast(channel, data.merge(channel: channel))
25
26
  end
26
27
 
27
28
  def self.channel_prefix
@@ -2,6 +2,6 @@ require 'oj'
2
2
 
3
3
  module Hippo::API
4
4
  def self.to_json(data)
5
- Oj.dump(data, mode: :compat, time_format: :xmlschema)
5
+ Oj.dump(data)
6
6
  end
7
7
  end
@@ -1,3 +1,5 @@
1
+ require_relative './pub_sub'
2
+
1
3
  module Hippo
2
4
 
3
5
  module API
@@ -1,3 +1,5 @@
1
+ require_relative '../api/updates'
2
+
1
3
  module Hippo
2
4
  module Command
3
5
 
@@ -19,10 +21,16 @@ module Hippo
19
21
  ext.root_path.join('spec/factories')
20
22
  end
21
23
  FactoryGirl.find_definitions
22
- MultiTenant.current_tenant = Hippo::Tenant.system
24
+ Hippo::API::Cable.configure
25
+ MultiTenant.current_tenant = Hippo::Tenant.find_by_slug(
26
+ Hippo.env.development? ? 'test' : 'system'
27
+ )
23
28
  ext.on_dev_console
24
- ARGV.clear
25
- IRB.start
29
+ Pry::Commands.block_command "tenant", "set current tenant to <slug>" do |slug|
30
+ MultiTenant.current_tenant=Hippo::Tenant.find_by_slug!(slug)
31
+ puts "Current tenant id = #{MultiTenant.current_tenant.id}"
32
+ end
33
+ Pry.start
26
34
  end
27
35
 
28
36
  end
@@ -17,6 +17,7 @@ module Hippo
17
17
 
18
18
 
19
19
  def configure
20
+ @extension ||= Command.load_current_extension(raise_on_fail:true)
20
21
  @config = Hippo::Webpack::ClientConfig.new
21
22
  @config.invoke_all
22
23
  self
@@ -33,6 +34,7 @@ module Hippo
33
34
  options.each do |key, value|
34
35
  cmd << " --#{key}" if value
35
36
  end
37
+ say cmd, :green
36
38
  exec(cmd)
37
39
  end
38
40
  end
@@ -50,6 +50,8 @@ module Hippo
50
50
  end
51
51
 
52
52
  def self.apply
53
+ Oj.default_options = { mode: :rails, time_format: :xmlschema }
54
+
53
55
  controlling_ext = Hippo::Extensions.bootstrap
54
56
  secrets = controlling_ext.root_path.join('config', 'secrets.yml')
55
57
  @@secrets = Hashie::Mash.new(
@@ -114,11 +116,8 @@ module Hippo
114
116
  # prefix to use for all urls
115
117
  config_option :mounted_at, '/'
116
118
 
117
- # The initial id of the screen that should be displayed
118
- config_option :root_view, 'workspace-layout'
119
-
120
- # Screen to display on load (if workspace extension is used)
121
- config_option :initial_workspace_screen_id, ''
119
+ # Configuration for action cable
120
+ config_option :cable, { 'adapter' => 'redis' }
122
121
 
123
122
  # types of assets to include into compiled package
124
123
  config_option :static_asset_types, ['images','fonts']
@@ -127,8 +126,6 @@ module Hippo
127
126
 
128
127
  config_option :product_name, 'Hippo Funtime'
129
128
 
130
- config_option :api_use_any_cable, false
131
-
132
129
  def api_path
133
130
  mounted_at + 'api'
134
131
  end
@@ -63,7 +63,7 @@ task :test => [:spec] do
63
63
  end
64
64
 
65
65
  task :lint do
66
- sh %{node node_modules/eslint/bin/eslint.js client spec/client/}
66
+ sh %{node node_modules/eslint/bin/eslint.js --ext .js --ext .jsx client spec/client/}
67
67
  end
68
68
 
69
69
  task :ci do
data/lib/hippo/screen.rb CHANGED
@@ -1,29 +1,49 @@
1
1
  require 'yaml'
2
2
  require 'oj'
3
3
  require 'pry'
4
+ require_relative 'screen/group'
5
+ require_relative 'screen/definition'
4
6
 
5
7
  module Hippo
6
8
 
7
9
  module Screen
8
10
 
9
11
  GROUPS=Hash.new{|h,k| g=Group.new; g.identifier=k; h[k]=g }
10
- DEFINITIONS=Hash.new
12
+ DEFINITIONS = Hash.new
13
+ EXTENSIONS = Hash.new
11
14
 
12
15
  mattr_accessor :enabled_group_ids
13
16
 
14
17
  class DefinitionList
18
+ attr_reader :ids
19
+
20
+ include Enumerable
21
+
15
22
  def initialize(extension_id)
23
+ @ids = []
16
24
  @extension_id = extension_id
17
25
  end
18
26
 
19
27
  def define(id)
28
+ ids.push(id)
20
29
  definition = (DEFINITIONS[id] ||= Definition.new(id, @extension_id))
21
30
  yield definition
22
31
  end
32
+
33
+ def extend(id)
34
+ ids.push(id)
35
+ definition = DEFINITIONS[id]
36
+ definition.extension_id = @extension_id
37
+ yield definition if block_given?
38
+ end
39
+
40
+ def each
41
+ ids.each { |id| yield DEFINITIONS[id] }
42
+ end
43
+
23
44
  end
24
45
 
25
46
  class << self
26
-
27
47
  include Enumerable
28
48
 
29
49
  def [](config)
@@ -34,8 +54,14 @@ module Hippo
34
54
  end
35
55
  end
36
56
 
57
+ def each
58
+ DEFINITIONS.values.each { |s| yield s }
59
+ end
60
+
37
61
  def for_extension(id)
38
- yield DefinitionList.new(id)
62
+ definition = EXTENSIONS[id] ||= DefinitionList.new(id)
63
+ yield definition if block_given?
64
+ definition
39
65
  end
40
66
 
41
67
  def define_group(id)
@@ -43,9 +69,9 @@ module Hippo
43
69
  yield group
44
70
  end
45
71
 
46
- def each
72
+ def active_ids
47
73
  Extensions.load_screens
48
- DEFINITIONS.values.each{ | definition | yield definition }
74
+ for_extension(Hippo::Extensions.controlling.identifier).map(&:identifier)
49
75
  end
50
76
 
51
77
  def each_group
@@ -59,94 +85,6 @@ module Hippo
59
85
 
60
86
  end
61
87
 
62
-
63
- class Group
64
- include Concerns::AttrAccessorWithDefault
65
-
66
- attr_accessor_with_default :identifier
67
- attr_accessor_with_default :title
68
- attr_accessor_with_default :description
69
- attr_accessor_with_default :icon
70
- attr_accessor_with_default :order
71
-
72
- def to_json
73
- Oj.dump({
74
- id: identifier,
75
- title: title,
76
- description: description,
77
- icon: icon
78
- }, mode: :compat)
79
- end
80
- end
81
-
82
- class Definition
83
- include Concerns::AttrAccessorWithDefault
84
-
85
- attr_accessor_with_default :identifier
86
- attr_accessor_with_default :title
87
- attr_accessor_with_default :description
88
- attr_accessor_with_default :icon
89
- attr_accessor_with_default :group_id
90
- attr_accessor_with_default :extension
91
- attr_accessor_with_default :view_class
92
- attr_accessor_with_default :model_class
93
- attr_accessor_with_default :model_access, 'read'
94
- attr_accessor_with_default :asset
95
-
96
- def initialize(id, extension_id)
97
- self.identifier = id
98
- @extension_id = extension_id
99
- @extension = extension_id.underscore.camelize
100
- end
101
-
102
- def group
103
- GROUPS[@group_id]
104
- end
105
-
106
- def has_file_matching?(pattern)
107
- Pathname.glob(root_path.join(pattern)).any?
108
- end
109
-
110
- def root_path
111
- ext = Hippo::Extensions.for_identifier(@extension_id)
112
- raise "Unable to find extension '#{@extension_id}' for screen group" unless ext
113
- ext.root_path.join('client', url_prefix, identifier)
114
- end
115
-
116
- def model
117
- return nil if @model_class.blank?
118
- ext = Hippo::Extensions.for_identifier(@extension_id)
119
- (@extension_id.camelize + '::' + @model_class).constantize
120
- end
121
-
122
- def viewable_by?(user)
123
- model.nil? || user.can_read?(self)
124
- end
125
-
126
- def asset_path
127
- (asset && asset =~ /\//) ? asset : "#{@extension_id}/screens/#{asset || identifier}"
128
- end
129
-
130
- def as_json
131
- {
132
- id: identifier,
133
- title: title,
134
- icon: icon,
135
- model: model_class,
136
- view: view_class,
137
- access: model_access,
138
- group_id: group_id,
139
- extension: extension,
140
- description: description,
141
- asset: asset_path
142
- }
143
- end
144
-
145
- def to_json
146
- Oj.dump(as_json, mode: :compat)
147
- end
148
- end
149
-
150
88
  end
151
89
 
152
90
  end