cm_page_builder-rails 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 658618c90bd048b3dbf923697641340e5e2230bb1060ad24d0ffacb8e60da832
4
- data.tar.gz: 628fd865f7ddb5b685646278de7efbedc2aa47ed81adf691ee7c4eb5ef21b80a
3
+ metadata.gz: 8b499190f1a37b5e7814f23963ed1a1e4c91206c5b318766a08e800b00dd1b8e
4
+ data.tar.gz: 9e5036922867ebe90b64df0f70145132be417949d38116564912a4b30e295709
5
5
  SHA512:
6
- metadata.gz: de13dd220f6c5723daee54449ba5bb145553a3be6d81e5a88706212f61fa4dcf43d9ddc253c4668e5e3a39ec5fdefa9e95404b527fc79313041d209d3e0871d1
7
- data.tar.gz: 49a982ff69e5e313e206b16e5e5638498ad9b8dd5f738f8a3ddf52e541a4e360008896ad4ada1097dd2fe8470ea27523d63e378153c4121188ad11ae0826a957
6
+ metadata.gz: 22fcd8aaf9960982c8b85327c7f57facd5a0e1b2abcf237677fa6523247cf6cb814b7b847cb99497455ffc2e24f72ccd426e50303baaeeff24dce1952b92a90b
7
+ data.tar.gz: 5a861d9187ef9ef9ef7ff73921880767d64e7dc4545b7335df91ad256c4e16fcd0ddb2312495bf905eeb686edb10cd57ab3c1dff384736df54e03e405fb896fc
data/README.md CHANGED
@@ -21,6 +21,10 @@ Or install it yourself as:
21
21
  $ gem install cm_page_builder-rails
22
22
  ```
23
23
 
24
+ ### Setting up CORS for aws
25
+ Do this or the direct upload capabilities won't work
26
+ https://keithpblog.org/post/active-storage-on-amazon-s3/
27
+
24
28
  ## Contributing
25
29
  Contribution directions go here.
26
30
 
@@ -5,19 +5,36 @@ module CmPageBuilder::Rails
5
5
 
6
6
  accepts_nested_attributes_for :page_components, allow_destroy: true
7
7
 
8
+ def get_components
9
+ self.page_components.select(:id, :component_type, :position, :content).map do |component|
10
+ json_component = component.as_json.transform_keys! {|key| key.camelize(:lower)}
11
+ attachment = component.component_attachment.attachment
12
+ pp attachment
13
+ json_component["component_attachment"] = if attachment
14
+ {
15
+ filename: attachment.filename.to_s,
16
+ url: attachment.service_url
17
+ }
18
+ end
19
+ json_component
20
+ end
21
+ end
22
+
8
23
  def save_content(component_json)
9
24
  components = JSON.parse component_json
10
25
  deleted_components = self.page_components.where.not(
11
26
  id: components.map {|c| c["id"] } )
12
27
  deleted_components.delete_all
13
28
  components.each do |component|
14
- self.page_components
15
- .find_or_initialize_by(id: component["id"])
16
- .update!(
29
+ page_component = self.page_components.find_or_initialize_by(id: component["id"])
30
+ page_component.update!(
17
31
  content: component["content"],
18
32
  position: component["position"],
19
33
  component_type: component["componentType"]
20
34
  )
35
+ signed_id = component.dig("component_attachment", "signed_id")
36
+ page_component.component_attachment = signed_id if signed_id
37
+ page_component.save!
21
38
  end
22
39
 
23
40
  end
@@ -1,5 +1,7 @@
1
1
  module CmPageBuilder::Rails
2
2
  class PageComponent < ApplicationRecord
3
- belongs_to :page
3
+ belongs_to :page
4
+
5
+ has_one_attached :component_attachment
4
6
  end
5
7
  end
@@ -8,7 +8,7 @@
8
8
 
9
9
  .field
10
10
  input type='hidden' id="content-editor" name="page[components]"
11
- - components = @page.page_components.select(:id, :component_type, :position, :content).map { |component| component.as_json.transform_keys! {|key| key.camelize(:lower)} }
11
+ - components = @page.get_components
12
12
  = react_component("cm_content_manager/Content", {input: "content-editor", components: components})
13
13
 
14
14
  .actions = f.submit
@@ -1,5 +1,5 @@
1
1
  module CmPageBuilder
2
2
  module Rails
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cm_page_builder-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Camilo Ernesto Forero Junco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-21 00:00:00.000000000 Z
11
+ date: 2019-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails