cm-admin 0.9.0 → 0.9.1

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: 385e0f3031f66ab986a7c7e66837810ed8d49bca259cca0fb92bdc2e6bf4efc6
4
- data.tar.gz: 909a15a2ee902c0241295cc26749f6d7715b938131cb8d9c42cadd6625813730
3
+ metadata.gz: 785e0d596039b668a8011b689eab464ebf3c0b6133d802d115d80a2916e93e09
4
+ data.tar.gz: 3cd13d18882cf7bdc31438c95498010ea776eeb3f9fdc3667a92b875800cb09b
5
5
  SHA512:
6
- metadata.gz: 9ce3b5afcec601a5713f518d77733fd99bc0d4eb19736c1160aa5ee72b4699ca1d87ec5af1363ef4e039c1a26509ec8e444ab9b412117d396485da186cd2cdaf
7
- data.tar.gz: 5cf1e60e56910ce4326cffe4f7aabebcc488821ec82bba2ee0e4b8b4d45293599d8e6a45dbbd81e1f74ed7ad84a9a166afa7d72e71fe13943653db0a8ddd9a46
6
+ metadata.gz: 66e662348351cdc07436a127fae08df52f430e31ec8e0410fd9b3c76307d111c261cd1349d0d4f6497b605a34ee2622ab113a8d909792e03065cbf66c33afc68
7
+ data.tar.gz: '0914c2ce34558dbe09a7b10e4f6777d46c37ec3fb0aeae30b5c9fefc45a2611236b21d32d36e8f94f653c0c1fa37346f97e7f6ec33ceff8aa0376a1b5e5a7783'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (0.9.0)
4
+ cm-admin (0.9.1)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
@@ -155,7 +155,7 @@ GEM
155
155
  rack-proxy (>= 0.6.1)
156
156
  railties (>= 5.2)
157
157
  semantic_range (>= 2.3.0)
158
- zeitwerk (2.6.4)
158
+ zeitwerk (2.6.6)
159
159
 
160
160
  PLATFORMS
161
161
  ruby
@@ -33,6 +33,121 @@
33
33
  }
34
34
  }
35
35
 
36
+ //cocoon field styles
37
+ .fields-group {
38
+ display: flex;
39
+ align-items: center;
40
+ margin: 16px 0;
41
+ .field-item {
42
+ margin: 0 5px;
43
+ label {
44
+ @include font($size: $t4-text, $color: $primary-text-clr, $weight: bold);
45
+ margin-bottom: 4px;
46
+ }
47
+ input {
48
+ width: 100%;
49
+ padding: 5px 10px;
50
+ border: 1px solid #c1c7d0;
51
+ border-radius: $radius-2;
52
+ &:focus {
53
+ border-color: #66afe9 !important;
54
+ outline: 0 !important;
55
+ box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6) !important;
56
+ }
57
+ }
58
+ }
59
+ .field-remove {
60
+ margin-top: 25px;
61
+ a {
62
+ @include font($size: $t1-text, $color: #ff5656);
63
+ @include transition-linear;
64
+ &:hover {
65
+ transform: scale(1.1);
66
+ }
67
+ }
68
+ }
69
+ }
70
+
71
+ .add-field-btn {
72
+ font-size: $t4-text;
73
+ margin: 10px 0;
74
+ }
75
+
76
+ // Nested form styles
77
+ .nested-field-wrapper {
78
+ .nested-field-label {
79
+ @include font($size: $t4-text, $color: $primary-text-clr);
80
+ line-height: 22px;
81
+ margin: 0 0 4px;
82
+ span {
83
+ color: $ink-lightest-clr;
84
+ margin-left: 4px;
85
+ }
86
+ }
87
+ .nested-single-field {
88
+ display: grid;
89
+ grid-template-columns: 1fr 32px;
90
+ align-items: center;
91
+ width: 352px;
92
+ margin-bottom: 8px;
93
+ .field-remove-action {
94
+ font-size: $t3-text;
95
+ text-align: center;
96
+ a {
97
+ color: $primary-text-clr;
98
+ &:hover {
99
+ color: $primary-text-clr;
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }
105
+
106
+ // Nested form Accordion styles
107
+ .nested-form-accordion {
108
+ .accordion-item {
109
+ margin-bottom: 8px;
110
+ border: 1px solid $grey-light-clr;
111
+ border-radius: $radius-4;
112
+ }
113
+ .accordion-item:not(:first-of-type) {
114
+ border-top: 1px solid $grey-light-clr;
115
+ }
116
+ .accordion-item:first-of-type {
117
+ margin-top: 4px;
118
+ border-radius: $radius-4;
119
+ }
120
+ .accordion-item:last-of-type {
121
+ margin-bottom: 0;
122
+ border-radius: $radius-4;
123
+ }
124
+ .accordion-header {
125
+ position: relative;
126
+ display: flex;
127
+ .accordion-delete-btn {
128
+ position: absolute;
129
+ top: 14px;
130
+ right: 48px;
131
+ z-index: 9;
132
+ }
133
+ }
134
+ .accordion-button {
135
+ border-radius: $radius-4;
136
+ &:focus {
137
+ border-color: transparent;
138
+ box-shadow: none;
139
+ }
140
+ &:not(.collapsed) {
141
+ color: inherit;
142
+ background-color: transparent;
143
+ box-shadow: none;
144
+ }
145
+ &:not(.collapsed)::after {
146
+ background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23212529'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e");
147
+ }
148
+ }
149
+ }
150
+
36
151
  //Old form code
37
152
  .form-wrapper {
38
153
  // margin-top: 60px;
@@ -148,43 +263,3 @@
148
263
  }
149
264
  }
150
265
  }
151
-
152
- //cocoon field styles
153
- .fields-group {
154
- display: flex;
155
- align-items: center;
156
- margin: 16px 0;
157
- .field-item {
158
- margin: 0 5px;
159
- label {
160
- @include font($size: $t4-text, $color: $primary-text-clr, $weight: bold);
161
- margin-bottom: 4px;
162
- }
163
- input {
164
- width: 100%;
165
- padding: 5px 10px;
166
- border: 1px solid #c1c7d0;
167
- border-radius: $radius-2;
168
- &:focus {
169
- border-color: #66afe9 !important;
170
- outline: 0 !important;
171
- box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(102, 175, 233, 0.6) !important;
172
- }
173
- }
174
- }
175
- .field-remove {
176
- margin-top: 25px;
177
- a {
178
- @include font($size: $t1-text, $color: #ff5656);
179
- @include transition-linear;
180
- &:hover {
181
- transform: scale(1.1);
182
- }
183
- }
184
- }
185
- }
186
-
187
- .add-field-btn {
188
- font-size: $t4-text;
189
- margin: 10px 0;
190
- }
@@ -88,6 +88,7 @@ a {
88
88
  width: 480px;
89
89
  }
90
90
  }
91
+
91
92
  .input-wrapper.disabled {
92
93
  input:disabled {
93
94
  background-color: $grey-lightest-clr;
@@ -96,6 +97,7 @@ a {
96
97
  color: $ink-lightest-clr;
97
98
  }
98
99
  }
100
+
99
101
  .nested-fields .select2 {
100
102
  width: 320px !important;
101
103
  }
@@ -74,3 +74,33 @@ $(document).on('click', '.drawer-close', function(e) {
74
74
  $('.cm-drawer').addClass('hidden');
75
75
  }, 300);
76
76
  });
77
+
78
+ $(document).on('cocoon:after-insert', '.nested-field-wrapper', function(e) {
79
+ e.stopPropagation();
80
+ replaceAccordionTitle($(this))
81
+ });
82
+
83
+ $(document).on('cocoon:after-remove', '.nested-field-wrapper', function(e) {
84
+ e.stopPropagation();
85
+ replaceAccordionTitle($(this))
86
+ });
87
+
88
+ $(document).ready( function () {
89
+ $('.nested-field-wrapper').each(function() {
90
+ replaceAccordionTitle($(this))
91
+ })
92
+ });
93
+
94
+ var replaceAccordionTitle = function(element) {
95
+ var i = 0;
96
+ var table_name = $(element).data('table-name')
97
+ var model_name = $(element).data('model-name')
98
+ $(element).find('.accordion-item:visible').each(function() {
99
+ i++;
100
+ var accordion_title = model_name + ' ' + i
101
+ var accordion_id = table_name + '-' + i
102
+ $(this).find('.accordion-button').text(accordion_title);
103
+ $(this).find('.accordion-button').attr('data-bs-target', '#' + accordion_id);
104
+ $(this).find('.accordion-collapse').attr('id', accordion_id);
105
+ });
106
+ }
@@ -1,9 +1,26 @@
1
- .nested-fields class=assoc_name
2
- - @model.available_fields[ action(action_name) ][assoc_name].each do |field|
3
- .row
4
- .col-sm-10
5
- = input_field_for_column(f, field)
6
- .col-sm-2
7
- - unless field.input_type == :hidden
8
- - if @reflections.select {|x| x if x.name == assoc_name}.first.macro == :has_many
9
- = link_to_remove_association "x", f
1
+ - fields = @model.available_fields[ action(action_name) ][assoc_name]
2
+ - if fields.count == 1
3
+ .nested-single-field.nested-fields
4
+ - fields.each do |field|
5
+ .field-input
6
+ = input_field_for_column(f, field)
7
+ .field-remove-action
8
+ - unless field.input_type == :hidden
9
+ - if @reflections.select {|x| x if x.name == assoc_name}.first.macro == :has_many
10
+ = link_to_remove_association "", f, class: 'fa fa-times'
11
+ - else
12
+ .accordion-item.nested-fields
13
+ h2#headingOne.accordion-header
14
+ button.accordion-button[type="button" data-bs-toggle="collapse" data-bs-target="##{assoc_name}-#{f.object.id}" aria-expanded="true" aria-controls="collapseOne"]
15
+ | Chapter 1
16
+ .field-remove-action
17
+ - if @reflections.select {|x| x if x.name == assoc_name}.first.macro == :has_many
18
+ = link_to_remove_association "", f, class: 'fa fa-trash ghost-btn accordion-delete-btn'
19
+ div.accordion-collapse.collapse.show[aria-labelledby="headingOne" id="#{assoc_name}-#{f.object.id}"]
20
+ .accordion-body
21
+ - fields.each do |field|
22
+ .form-field
23
+ .field-label-wrapper
24
+ label.field-label = field.field_name.to_s.titleize
25
+ .field-input-wrapper
26
+ = input_field_for_column(f, field)
@@ -1,10 +1,9 @@
1
- .nested-field-wrapper
2
- label.field-label = table_name.to_s.titleize
3
- - initialized_record_count = 1
4
- = f.fields_for table_name do |record|
5
- - if record.object.persisted? || initialized_record_count == 1
6
- = render partial: '/cm_admin/main/nested_fields', locals: { f: record, assoc_name: table_name }
7
- - initialized_record_count += 1 if record.object.new_record?
8
- - if @reflections.select {|x| x if x.name == table_name}.first.macro == :has_many
9
- .links
10
- = link_to_add_association "+ Add #{table_name.to_s.titleize}", f, table_name, partial: '/cm_admin/main/nested_fields', render_options: {locals: { assoc_name: table_name }}
1
+ .nested-field-wrapper data-table-name=table_name data-model-name=table_name.to_s.classify
2
+ label.nested-field-label = table_name.to_s.titleize
3
+ .accordion.nested-form-accordion
4
+ = f.fields_for table_name do |record|
5
+ - if record.object.persisted?
6
+ = render partial: '/cm_admin/main/nested_fields', locals: { f: record, assoc_name: table_name }
7
+ - if @reflections.select {|x| x if x.name == table_name}.first.macro == :has_many
8
+ .links
9
+ = link_to_add_association "+ Add #{table_name.to_s.titleize}", f, table_name, partial: '/cm_admin/main/nested_fields', render_options: {locals: { assoc_name: table_name }}, class: 'd-inline-block secondary-btn mt-2'
@@ -4,4 +4,4 @@ ul.nav.nav-pills
4
4
  - if nav_item.custom_action.empty? || (nav_item.custom_action.present? && policy([:cm_admin, @model.name.classify.constantize]).send(:"#{nav_item.custom_action}?"))
5
5
  li.nav-item
6
6
  - nav_item_action_name = nav_item.custom_action.present? ? nav_item.custom_action : 'show'
7
- = link_to nav_item.nav_item_name.to_s.titleize, cm_admin.send("#{@ar_object.model_name.singular}_#{nav_item_action_name}_path", @ar_object.id), class: "nav-link #{ nav_item_action_name == action_name ? 'active' : ''}"
7
+ = link_to tab_display_name(nav_item.nav_item_name), cm_admin.send("#{@ar_object.model_name.singular}_#{nav_item_action_name}_path", @ar_object.id), class: "nav-link #{ nav_item_action_name == action_name ? 'active' : ''}"
@@ -70,7 +70,7 @@ module CmAdmin
70
70
 
71
71
  if filter.db_column_name.map{|x| x.is_a?(Hash)}.include?(true)
72
72
  associations_hash = filter.db_column_name.select{|x| x if x.is_a?(Hash)}.last
73
- records = records.joins(associations_hash.keys)
73
+ records = records.left_joins(associations_hash.keys).distinct
74
74
  end
75
75
 
76
76
  records = records.where(
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = '0.9.0'
2
+ VERSION = '0.9.1'
3
3
  end
@@ -84,6 +84,10 @@ module CmAdmin
84
84
  def custom_action_title(custom_action)
85
85
  custom_action.display_name.to_s.presence || custom_action.name.to_s.titleize
86
86
  end
87
+
88
+ def tab_display_name(nav_item_name)
89
+ nav_item_name.instance_of?(Symbol) ? nav_item_name.to_s.titleize : nav_item_name.to_s
90
+ end
87
91
  end
88
92
  end
89
93
  end
data/package-lock.json CHANGED
@@ -4902,10 +4902,9 @@
4902
4902
  }
4903
4903
  },
4904
4904
  "node_modules/file-loader/node_modules/loader-utils": {
4905
- "version": "2.0.0",
4906
- "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.0.tgz",
4907
- "integrity": "sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==",
4908
- "license": "MIT",
4905
+ "version": "2.0.4",
4906
+ "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.4.tgz",
4907
+ "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==",
4909
4908
  "dependencies": {
4910
4909
  "big.js": "^5.2.2",
4911
4910
  "emojis-list": "^3.0.0",
@@ -6550,10 +6549,9 @@
6550
6549
  }
6551
6550
  },
6552
6551
  "node_modules/loader-utils": {
6553
- "version": "1.4.0",
6554
- "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.0.tgz",
6555
- "integrity": "sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==",
6556
- "license": "MIT",
6552
+ "version": "1.4.2",
6553
+ "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.2.tgz",
6554
+ "integrity": "sha512-I5d00Pd/jwMD2QCduo657+YM/6L3KZu++pmX9VFncxaxvHcru9jx1lBaFft+r4Mt2jK0Yhp41XlRAihzPxHNCg==",
6557
6555
  "dependencies": {
6558
6556
  "big.js": "^5.2.2",
6559
6557
  "emojis-list": "^3.0.0",
@@ -6984,10 +6982,9 @@
6984
6982
  "license": "MIT"
6985
6983
  },
6986
6984
  "node_modules/minimatch": {
6987
- "version": "3.0.4",
6988
- "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
6989
- "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
6990
- "license": "ISC",
6985
+ "version": "3.1.2",
6986
+ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
6987
+ "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
6991
6988
  "dependencies": {
6992
6989
  "brace-expansion": "^1.1.7"
6993
6990
  },
@@ -9919,10 +9916,9 @@
9919
9916
  }
9920
9917
  },
9921
9918
  "node_modules/sass-loader/node_modules/loader-utils": {
9922
- "version": "2.0.0",
9923
- "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.0.tgz",
9924
- "integrity": "sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==",
9925
- "license": "MIT",
9919
+ "version": "2.0.4",
9920
+ "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.4.tgz",
9921
+ "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==",
9926
9922
  "dependencies": {
9927
9923
  "big.js": "^5.2.2",
9928
9924
  "emojis-list": "^3.0.0",
@@ -16974,9 +16970,9 @@
16974
16970
  },
16975
16971
  "dependencies": {
16976
16972
  "loader-utils": {
16977
- "version": "2.0.0",
16978
- "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.0.tgz",
16979
- "integrity": "sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==",
16973
+ "version": "2.0.4",
16974
+ "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.4.tgz",
16975
+ "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==",
16980
16976
  "requires": {
16981
16977
  "big.js": "^5.2.2",
16982
16978
  "emojis-list": "^3.0.0",
@@ -18096,9 +18092,9 @@
18096
18092
  "integrity": "sha512-Jsmr89RcXGIwivFY21FcRrisYZfvLMTWx5kOLc+JTxtpBOG6xML0vzbc6SEQG2FO9/4Fc3wW4LVcB5DmGflaRw=="
18097
18093
  },
18098
18094
  "loader-utils": {
18099
- "version": "1.4.0",
18100
- "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.0.tgz",
18101
- "integrity": "sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==",
18095
+ "version": "1.4.2",
18096
+ "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.2.tgz",
18097
+ "integrity": "sha512-I5d00Pd/jwMD2QCduo657+YM/6L3KZu++pmX9VFncxaxvHcru9jx1lBaFft+r4Mt2jK0Yhp41XlRAihzPxHNCg==",
18102
18098
  "requires": {
18103
18099
  "big.js": "^5.2.2",
18104
18100
  "emojis-list": "^3.0.0",
@@ -18413,9 +18409,9 @@
18413
18409
  "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo="
18414
18410
  },
18415
18411
  "minimatch": {
18416
- "version": "3.0.4",
18417
- "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
18418
- "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
18412
+ "version": "3.1.2",
18413
+ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
18414
+ "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
18419
18415
  "requires": {
18420
18416
  "brace-expansion": "^1.1.7"
18421
18417
  }
@@ -20626,9 +20622,9 @@
20626
20622
  },
20627
20623
  "dependencies": {
20628
20624
  "loader-utils": {
20629
- "version": "2.0.0",
20630
- "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.0.tgz",
20631
- "integrity": "sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==",
20625
+ "version": "2.0.4",
20626
+ "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.4.tgz",
20627
+ "integrity": "sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==",
20632
20628
  "requires": {
20633
20629
  "big.js": "^5.2.2",
20634
20630
  "emojis-list": "^3.0.0",
@@ -1 +1 @@
1
- 44c10d1e702ae7e3f4af6ad8684f30bfd32edcf9
1
+ 44c10d1e702ae7e3f4af6ad8684f30bfd32edcf9