maglevcms 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0d746d7653900e39f4c0a7b45ba3503a5688d37cc45f242943f7187729f607f
4
- data.tar.gz: 4d5a6ff5eab5449ada366810c2ffedbde9466600faf1d30c8c4b6c906db24510
3
+ metadata.gz: d6ebce98e16aca2b48cc0029e9c9168602b29f8bcd320261904c634b4d97132d
4
+ data.tar.gz: 463986303bb445fdc237f1089186055284ff29cb62773a878a7f4ae1d90ab7a6
5
5
  SHA512:
6
- metadata.gz: 6395309dbf50aed228ef2143e48bc4fb34f3184f715d9b70b478487567c56485483253b8e66a951a512e592917732be376815f78591a6fc02fae3e730bede303
7
- data.tar.gz: 7fd1217aae956ca2b19228fe83c815f9905e18020047db71feccb15c20662ff1b720d9af2dd54874e0217e7ed0f2ef90235e49444c130b6bac24d7b27f92c715
6
+ metadata.gz: c6d853c3d35076069a0ba22053b8828a8e837eabaf3c715e4ac9955ac2f38663cd6cad9d86b55f759b310633e564b19c8373d2fd06df8c3b6a05b2bb8eeaf026
7
+ data.tar.gz: f3e2b09342501025517ef5a11ce16f8e2f213fd1b99fb760312edf99b321220cf2e65ea73c3feabf12c6706f27b5dede2482adb0686d160537558334daa76cd7
@@ -80,6 +80,7 @@ module Maglev
80
80
  # we drop the path after the "_" segment
81
81
  params[:path].split('/').reduce([]) do |memo, segment|
82
82
  return memo if segment == '_'
83
+
83
84
  memo.push(segment)
84
85
  end
85
86
  end
@@ -15,6 +15,8 @@ module Maglev
15
15
  private
16
16
 
17
17
  def fetch_maglev_site_scoped_sections
18
+ return if within_maglev_engine?
19
+
18
20
  fetch_maglev_site
19
21
  fetch_maglev_theme
20
22
  fetch_maglev_dummy_page
@@ -24,5 +26,9 @@ module Maglev
24
26
  def fetch_maglev_dummy_page
25
27
  @fetch_maglev_page = ::Maglev::Page.new(title: 'DummyPage', sections: fetch_maglev_site.sections)
26
28
  end
29
+
30
+ def within_maglev_engine?
31
+ controller_path.starts_with?('maglev/')
32
+ end
27
33
  end
28
34
  end
@@ -80,6 +80,7 @@
80
80
  :label="setting.label"
81
81
  :name="setting.id"
82
82
  v-model="inputValue"
83
+ :collection-id="options.collectionId"
83
84
  v-if="setting.type == 'collection_item'"
84
85
  />
85
86
  </div>
@@ -10,7 +10,7 @@
10
10
  :searchEnabled="true"
11
11
  :searchPlaceholder="$t(`collectionItemInput.select.searchPlaceholder`)"
12
12
  :emptyLabel="$t(`collectionItemInput.select.emptyLabel`)"
13
- :fetchList="(q) => services.collectionItem.findAll('products', { q })"
13
+ :fetchList="(q) => services.collectionItem.findAll(collectionId, { q })"
14
14
  :clearEnabled="true"
15
15
  buttonClass="h-10"
16
16
  v-model="selectedCollectionItem"
@@ -42,18 +42,21 @@
42
42
  </template>
43
43
 
44
44
  <script>
45
+ import { camelizeKeys } from '@/misc/utils'
46
+
45
47
  export default {
46
48
  name: 'CollectionItemInput',
47
49
  props: {
48
50
  label: { type: String, default: 'Label' },
49
51
  name: { type: String, default: 'image' },
50
52
  value: { default: () => null },
53
+ collectionId: { type: String },
51
54
  isFocused: { type: Boolean, default: false },
52
55
  },
53
56
  computed: {
54
57
  selectedCollectionItem: {
55
58
  get() {
56
- return this.value
59
+ return camelizeKeys(this.value)
57
60
  },
58
61
  set(collectionItem) {
59
62
  this.$emit('input', collectionItem ? { ...collectionItem } : null)
@@ -8,11 +8,28 @@ export const isBlank = (object) => {
8
8
  }
9
9
 
10
10
  export const camelize = (str) => {
11
+ if (!str.includes('_')) return str
11
12
  return str
12
13
  .toLowerCase()
13
14
  .replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase())
14
15
  }
15
16
 
17
+ export const camelizeKeys = (obj) => {
18
+ if (Array.isArray(obj)) {
19
+ return obj.map(v => camelizeKeys(v));
20
+ } else if (obj != null && obj.constructor === Object) {
21
+ return Object.keys(obj).reduce(
22
+ (result, key) => ({
23
+ ...result,
24
+ [camelize(key)]: camelizeKeys(obj[key]),
25
+ }),
26
+ {},
27
+ );
28
+ }
29
+ return obj;
30
+ }
31
+
32
+
16
33
  export const numberToHumanSize = (size, i18n) => {
17
34
  if (isBlank(size)) return null
18
35
 
@@ -21,6 +21,7 @@ class Maglev::Section::Setting
21
21
  when :image then build_default_image_content(default)
22
22
  when :link then build_default_link_content(default)
23
23
  when :checkbox then build_default_checkbox_content(default)
24
+ when :collection_item then build_default_collection_item_content(default)
24
25
  else
25
26
  default || label
26
27
  end
@@ -42,6 +43,10 @@ class Maglev::Section::Setting
42
43
  default.presence || false
43
44
  end
44
45
 
46
+ def build_default_collection_item_content(default)
47
+ { id: default }
48
+ end
49
+
45
50
  ## class methods ##
46
51
  def self.build(hash)
47
52
  attributes = hash.slice('id', 'label', 'type', 'default')
@@ -3,7 +3,7 @@
3
3
  # rubocop:disable Style/ClassAndModuleChildren
4
4
  module Maglev::GetPageSections::TransformCollectionItemConcern
5
5
  def transform_collection_item_content_setting(content, setting)
6
- item_id = content.dig('value', 'id')
6
+ item_id = content&.dig('value', 'id')
7
7
  return if item_id.blank?
8
8
 
9
9
  item = fetch_collection_items.call(
@@ -33,7 +33,7 @@ module Maglev
33
33
 
34
34
  def fetch_item
35
35
  build_item(
36
- fetch_original_items.find_by(id: id)
36
+ id == 'any' ? fetch_original_items.first : fetch_original_items.find_by(id: id)
37
37
  )
38
38
  end
39
39
 
@@ -78,7 +78,11 @@ module Maglev
78
78
  end
79
79
 
80
80
  def collection
81
- config.collections[collection_id.to_sym]
81
+ config.collections[collection_id.to_sym].tap do |collection|
82
+ next if collection
83
+
84
+ raise "[Maglev] unregistered '#{collection_id}' collection in the Maglev configuration."
85
+ end
82
86
  end
83
87
 
84
88
  def build_item(original_item)
@@ -1,4 +1,4 @@
1
- class CreateMaglevPagePaths < ActiveRecord::Migration[6.1]
1
+ class CreateMaglevPagePaths < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  create_table :maglev_page_paths do |t|
4
4
  t.references :maglev_page
@@ -1,4 +1,4 @@
1
- class AddCanonicalToPages < ActiveRecord::Migration[6.1]
1
+ class AddCanonicalToPages < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  add_column :maglev_page_paths, :canonical, :boolean, null: true, default: true
4
4
  add_index :maglev_page_paths, %i[canonical maglev_page_id locale], unique: true, name: 'canonical_uniqueness'
@@ -1,4 +1,4 @@
1
- class AddLocalesToSites < ActiveRecord::Migration[6.1]
1
+ class AddLocalesToSites < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  add_column :maglev_sites, :locales, :jsonb, default: []
4
4
  end
@@ -1,4 +1,4 @@
1
- class TranslateSectionContent < ActiveRecord::Migration[6.1]
1
+ class TranslateSectionContent < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  remove_column :maglev_sites, :sections, :jsonb, default: []
4
4
  add_column :maglev_sites, :sections_translations, :jsonb, default: {}
@@ -1,4 +1,4 @@
1
- class AddLockVersionToMaglevPages < ActiveRecord::Migration[6.1]
1
+ class AddLockVersionToMaglevPages < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  add_column :maglev_sites, :lock_version, :integer
4
4
  add_column :maglev_pages, :lock_version, :integer
@@ -1,4 +1,4 @@
1
- class BetterPagePathCanonicalIndices < ActiveRecord::Migration[6.1]
1
+ class BetterPagePathCanonicalIndices < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  remove_index :maglev_page_paths, [:value, :locale], unique: true
4
4
  remove_index :maglev_page_paths, %i[canonical maglev_page_id locale], unique: true, name: 'canonical_uniqueness'
@@ -1,4 +1,4 @@
1
- class FixPagePathIndices < ActiveRecord::Migration[6.1]
1
+ class FixPagePathIndices < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  remove_index :maglev_page_paths, %i[canonical maglev_page_id locale value], unique: true, name: 'canonical_uniqueness'
4
4
  add_index :maglev_page_paths, %i[canonical maglev_page_id locale], name: 'scoped_canonical_speed'
@@ -1,4 +1,4 @@
1
- class AddOpenGraphTagsToPages < ActiveRecord::Migration[6.1]
1
+ class AddOpenGraphTagsToPages < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  change_table :maglev_pages do |t|
4
4
  t.jsonb :og_title_translations, default: {}
@@ -1,4 +1,4 @@
1
- class AddStyleToSites < ActiveRecord::Migration[6.1]
1
+ class AddStyleToSites < ActiveRecord::Migration[6.0]
2
2
  def change
3
3
  change_table :maglev_sites do |t|
4
4
  t.jsonb :style, default: []
@@ -113,6 +113,7 @@ module Maglev
113
113
  when 'color' then '#E5E7EB'
114
114
  when 'radio', 'select' then 'option_1'
115
115
  when 'icon' then 'default-icon-class'
116
+ when 'collection_item' then 'any'
116
117
  end
117
118
  end
118
119
  # rubocop:enable Metrics/CyclomaticComplexity
@@ -40,6 +40,8 @@ settings:
40
40
  value: option_2
41
41
  <%- when 'color' -%>
42
42
  presets: ['#E5E7EB', '#FECACA', '#FDE68A', '#A7F3D0', '#BFDBFE']
43
+ <%- when 'collection_item' -%>
44
+ collection_id: products # check your config/initializers/maglev.rb to register your collection
43
45
  <%- end -%>
44
46
  <% if setting.value? -%>default: <%= setting.default %><% end -%>
45
47
 
@@ -69,6 +71,8 @@ blocks: <%- if blocks.blank? -%>[]
69
71
  value: option_1
70
72
  - label: Option 2
71
73
  value: option_2
74
+ <%- when 'collection_item' -%>
75
+ collection_id: products # check your config/initializers/maglev.rb to register your collection
72
76
  <%- end -%>
73
77
  <%- if setting.value? -%>
74
78
  default: <%= setting.default %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Maglev
4
- VERSION = '1.1.6'
4
+ VERSION = '1.1.7'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maglevcms
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Didier Lafforgue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-28 00:00:00.000000000 Z
11
+ date: 2022-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jbuilder