cm-admin 0.5.3 → 0.5.6

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: bcbb26a08fa072ec95a1363e72c63ebfad6a1c661d303d50af5379f2f5bce0b1
4
- data.tar.gz: 2f2526862a9312a48f768eb001ba52f6365182e105556136e2e763e96e21484a
3
+ metadata.gz: 9e71407dad6f3a42e093faa7247489382dd4b650b3c61f85b6758286a7d2ee45
4
+ data.tar.gz: e50e11e94676d06e9044a58b84f20cb416d92e8a0a92507afa5ff362b98d9640
5
5
  SHA512:
6
- metadata.gz: c8d834bc6b9716aeef9b5c82137106c9aae52afd435ef384e7543be09fd4f18cb3f593374aebf5d840c9d17f7d0ecb99a9c9066508a1645fdff32d433d9ef983
7
- data.tar.gz: c21ae398e2d2542186251a98bc706e203164e70319e841041527122358cd9cf3162620d8b860570b5f288f2ba1734c73a2a3a83da917c8b159120ad28c8febae
6
+ metadata.gz: 07bf22fe0ea5157252da7a3b17b012f6842ce5da4815764fd6ace17af0203db2dd09158d97efc9f19c51e9df5529f742c7284e501b5879b3694e48aed4283cf3
7
+ data.tar.gz: 9433f9fd8d71db8f7d1a95668e723cf655cc91e66df19b73d73f405336a7649e8c2a1f011c901a898990512a1e4eefe5092ed7f6502feabf75599a2e0ac0ff1d
@@ -5,6 +5,13 @@
5
5
  background-color: $white;
6
6
  overflow: auto;
7
7
 
8
+ .sticky-container {
9
+ z-index: 4;
10
+ .cm-filters-v2 {
11
+ padding: 16px 24px 36px 24px;
12
+ }
13
+ }
14
+
8
15
  &__filters {
9
16
  // If you want to overwrite filters styles ---> add styles here
10
17
  }
@@ -65,23 +72,24 @@
65
72
  }
66
73
  }
67
74
 
75
+
68
76
  .new-admin-table {
69
77
  overflow: auto;
70
78
  margin-top: 40px;
71
79
  margin-bottom: 50px;
80
+ height: 280px;
72
81
  .cm-table {
73
82
  table-layout: fixed;
74
83
  position: relative;
75
84
  min-width: fit-content;
76
85
  border-collapse: collapse;
77
- white-space: nowrap;
78
86
  border: 1px solid $grey-lighter-clr;
79
87
  border-radius: $radius-8;
80
88
  &__header {
81
89
  .header-row {
82
90
  display: block;
83
- position: relative;
84
91
  width: 100%;
92
+ position: relative;
85
93
  box-shadow: inset 0px -1px 0px rgba(148, 151, 155, 0.15);
86
94
  th {
87
95
  @include font($size: $t6-text, $color: $ink-lighter-clr, $weight: bold);
@@ -90,10 +98,22 @@
90
98
  max-width: 200px;
91
99
  padding: 12px 16px 12px 16px;
92
100
  }
101
+ th:nth-child(2){
102
+ position: sticky;
103
+ left: 38px;
104
+ z-index: 2;
105
+ background-color: #fff;
106
+ border-bottom: 1.21px solid rgb(240, 239, 239);
107
+ }
93
108
  .check-box-space {
109
+ position: sticky;
110
+ left: 0;
94
111
  min-width: fit-content;
95
112
  max-width: fit-content;
96
113
  padding: 12px 8px 12px 16px;
114
+ z-index: 2;
115
+ background-color: #fff;
116
+ border-bottom: 1.21px solid rgb(240, 239, 239);
97
117
  span {
98
118
  vertical-align: text-top;
99
119
  }
@@ -101,24 +121,47 @@
101
121
  }
102
122
  }
103
123
  &__body {
124
+ // display: block;
125
+ // overflow: auto;
126
+ // overflow-x: hidden;
127
+ // position: relative;
128
+ // width: 100%;
129
+ // height: 335px;
104
130
  display: block;
105
131
  position: relative;
106
- width: 100%; .body-row {
107
- box-shadow: inset 0px -1px 0px rgba(148, 151, 155, 0.15);
108
- transition: all .2s linear;
132
+ width: 100%;
133
+ .body-row {
134
+ border-bottom: 1.21px solid rgb(240, 239, 239);
135
+ td:nth-child(2){
136
+ position: sticky;
137
+ left: 38px;
138
+ z-index: 2;
139
+ background-color: #fff;
140
+ }
141
+
109
142
  &:nth-last-child(1) {
110
143
  box-shadow: none;
111
144
  }
112
145
  &:hover {
113
146
  background-color: $grey-lighter-clr;
147
+ td:nth-child(1) {
148
+ background-color: $grey-lighter-clr;
149
+ }
150
+ td:nth-child(2) {
151
+ background-color: $grey-lighter-clr;
152
+ }
114
153
  .row-action-cell {
115
154
  opacity: 1;
116
155
  }
117
156
  }
118
157
  .check-box-space {
158
+ position: sticky;
159
+ left: 0;
119
160
  min-width: fit-content;
120
161
  max-width: fit-content;
121
162
  padding: 16px 8px 16px 16px;
163
+ z-index: 2;
164
+ background-color: #fff;
122
165
  span {
123
166
  vertical-align: text-top;
124
167
  }
@@ -146,6 +189,17 @@
146
189
  align-items: center;
147
190
  justify-content: center;
148
191
  height: 100%;
192
+ .popup-card {
193
+ width:fit-content;
194
+ .popup-option {
195
+ a {
196
+ font-weight: 500;
197
+ font-size: 14px;
198
+ line-height: 22px;
199
+ color: #1D2129;
200
+ }
201
+ }
202
+ }
149
203
  .tool-btn {
150
204
  background-color: transparent;
151
205
  border: none;
@@ -155,15 +209,20 @@
155
209
  }
156
210
  }
157
211
  }
212
+ .cm-table > thead {
213
+ position:sticky;
214
+ top:0;
215
+ background-color: #fff;
216
+ z-index: 3;
217
+ }
158
218
  }
159
219
 
160
220
  .admin-table-index {
161
-
162
221
  position: fixed;
163
222
  width: calc(100% - 285px);
164
223
  left: 245px;
165
224
  background-color: #fff;
166
- z-index: 1;
225
+ z-index: 4;
167
226
  .table-sticky-top {
168
227
  position: sticky;
169
228
  top: 254px;
@@ -173,6 +232,8 @@
173
232
  justify-content: space-between;
174
233
  align-items: center;
175
234
  padding-bottom: 16px;
235
+ margin-top: -20px;
236
+ background-color: #fff;
176
237
  &__total-count {
177
238
  font-size: $t4-text;
178
239
  line-height: 22px;
@@ -222,7 +283,7 @@
222
283
  box-shadow: inset 0px 1px 0px rgba(148, 151, 155, 0.15);
223
284
  }
224
285
  }
225
- }
286
+ }
226
287
 
227
288
  .columns-list {
228
289
  .column-item {
@@ -266,7 +327,7 @@
266
327
  }
267
328
  }
268
329
  }
269
- }
330
+ }
270
331
  }
271
332
 
272
333
  .cm-pagination {
@@ -317,4 +378,4 @@
317
378
  }
318
379
  }
319
380
  }
320
- }
381
+ }
@@ -0,0 +1,86 @@
1
+ @import "../helpers/index.scss";
2
+
3
+ .cm-drawer {
4
+ position: fixed;
5
+ top: 0;
6
+ right: 0;
7
+ bottom: 0;
8
+ left: 0;
9
+ width: 100%;
10
+ height: 100%;
11
+ z-index: 5;
12
+ background-color: rgba(0, 0, 0, .7);
13
+ &__container {
14
+ position: relative;
15
+ width: 360px;
16
+ height: 100%;
17
+ background: $white;
18
+ box-shadow: 0px 4px 16px rgba(0, 0, 0, 0.16);
19
+ .header {
20
+ display: flex;
21
+ align-items: center;
22
+ justify-content: space-between;
23
+ padding: 24px;
24
+ background: #F8F9FA;
25
+ &__lhs {
26
+ .title {
27
+ font-family: $primary-font;
28
+ font-size: $t1-text;
29
+ font-weight: 600;
30
+ line-height: 28px;
31
+ color: $primary-text-clr;
32
+ margin-bottom: 8px;
33
+ }
34
+ .description {
35
+ font-family: $primary-font;
36
+ font-size: $t4-text;
37
+ line-height: 22px;
38
+ color: $primary-text-clr;
39
+ margin-bottom: 0;
40
+ }
41
+ }
42
+ &__rhs {
43
+ color: $ink-lighter-clr;
44
+ }
45
+ }
46
+ .body {
47
+ padding: 24px;
48
+ .info-text {
49
+ font-family: $primary-font;
50
+ font-size: $t4-text;
51
+ line-height: 22px;
52
+ color: $primary-text-clr;
53
+ }
54
+ }
55
+ }
56
+ }
57
+
58
+ .drawer-slide-in {
59
+ animation: slideInLeft .3s ease-in forwards;
60
+ }
61
+
62
+ .drawer-slide-out {
63
+ animation: slideOutLeft .3s ease-in forwards;
64
+ }
65
+
66
+ @keyframes slideInLeft {
67
+ 0% {
68
+ left: -400px;
69
+ opacity: 0;
70
+ }
71
+ 100% {
72
+ left: 0;
73
+ opacity: 1;
74
+ }
75
+ }
76
+
77
+ @keyframes slideOutLeft {
78
+ 0% {
79
+ left: 0;
80
+ opacity: 1;
81
+ }
82
+ 100% {
83
+ left: -400px;
84
+ opacity: 0;
85
+ }
86
+ }
@@ -5,3 +5,4 @@
5
5
  @import './dropdown-popup';
6
6
  @import './range';
7
7
  @import './modal';
8
+ @import './drawer';
@@ -40,4 +40,29 @@ $(document).on('click', '.row-action-cell', function(e) {
40
40
  } else {
41
41
  return $(this).find('.table-export-popup').addClass('hidden');
42
42
  }
43
+ });
44
+
45
+
46
+ $(document).on('click', '.drawer-btn', function(e) {
47
+ e.stopPropagation();
48
+ drawer_el = $(this).parent().closest('.drawer').find('.cm-drawer')
49
+ if (drawer_el.hasClass('hidden')) {
50
+ drawer_el.removeClass('hidden');
51
+ drawer_container = drawer_el.find('.drawer-container')
52
+ if (drawer_container.hasClass('drawer-slide-out')) {
53
+ drawer_container.removeClass('drawer-slide-out');
54
+ }
55
+ drawer_container.addClass('drawer-slide-in');
56
+ } else {
57
+ return drawer_el.addClass('hidden');
58
+ }
59
+ });
60
+
61
+ $(document).on('click', '.drawer-close', function(e) {
62
+ e.stopPropagation();
63
+ $('.drawer-container').removeClass('drawer-slide-in');
64
+ $('.drawer-container').addClass('drawer-slide-out');
65
+ setTimeout(() => {
66
+ $('.cm-drawer').addClass('hidden');
67
+ }, 300);
43
68
  });
@@ -37,24 +37,26 @@
37
37
  .popup-option
38
38
  a href="#{page_url('edit', ar_object)}"
39
39
  | Edit
40
- / .cm-pagination
41
- / .cm-pagination__lhs Showing 1 to 15 out of 104
42
- / .cm-pagination__rhs
43
- / span.page-move-btn.disabled
44
- / i.fa.fa-angle-double-left.bolder.f14
45
- / span.page-move-btn.disabled
46
- / i.fa.fa-chevron-left.bolder
47
- / span.page-num-btn.active 1
48
- / span.page-num-btn 2
49
- / span.page-num-btn 3
50
- / span.page-num-btn 4
51
- / span.page-num-btn 5
52
- / span.page-move-btn
53
- / i.fa.fa-chevron-right.bolder
54
- / span.page-move-btn
55
- / i.fa.fa-angle-double-right.bolder.f14
56
-
40
+ - @associated_model && @associated_model.available_actions.select{|act| act if act.route_type == 'member'}.each do |custom_action|
41
+ - if custom_action.display_if.call(ar_object)
42
+ .popup-option
43
+ - if custom_action.display_type == :button
44
+ = link_to custom_action.name.titleize, custom_action.path.gsub(':id', ar_object.id.to_s), method: custom_action.verb
45
+ - elsif custom_action.display_type == :modal
46
+ = link_to custom_action.name.titleize, '', data: { bs_toggle: "modal", bs_target: "##{custom_action.name.classify}Modal-#{ar_object.id.to_s}" }
47
+
57
48
  .cm-pagination
58
49
  .cm-pagination__lhs Showing #{@associated_ar_object.pagy.from} to #{@associated_ar_object.pagy.to} out of #{@associated_ar_object.pagy.count}
59
50
  .cm-pagination__rhs
60
- == render partial: 'cm_admin/main/cm_pagy_nav', locals: { pagy: @associated_ar_object.pagy }
51
+ == render partial: 'cm_admin/main/cm_pagy_nav', locals: { pagy: @associated_ar_object.pagy }
52
+
53
+ - @associated_ar_object.data.each do |ar_object|
54
+ - @associated_model && @associated_model.available_actions.select{|act| act if act.route_type == 'member'}.each do |custom_action|
55
+ .modal.fade id="#{custom_action.name.classify}Modal-#{ar_object.id.to_s}" aria-hidden="true" aria-labelledby="#{custom_action.name.classify}ModalLabel" tabindex="1"
56
+ .modal-dialog
57
+ .modal-content
58
+ .modal-header
59
+ h5.modal-title id="#{custom_action.name.classify}ModalLabel" = custom_action.name.classify
60
+ button.btn-close aria-label="Close" data-bs-dismiss="modal" type="button"
61
+ .modal-body
62
+ = render partial: custom_action.partial, locals: { ar_object: ar_object }
@@ -0,0 +1,13 @@
1
+ .cm-drawer.hidden
2
+ .cm-drawer__container#drawer-container
3
+ .header
4
+ .header__lhs
5
+ h2.title Review
6
+ p.description Theresa Webb
7
+ .header__rhs
8
+ i.fa.fa-times.drawer-close.pointer
9
+ .body
10
+ p.info-text
11
+ | It was really an amazing experience being an Unschooler. Its really different from other e-learning websites in every aspects like certification, providing internship opportunities and many more. I am going to recommend Unschool for sure!
12
+
13
+
@@ -24,11 +24,13 @@
24
24
  input.cm-checkbox type="checkbox"
25
25
  - @model.available_fields[:index].each_with_index do |column, index|
26
26
  td.text-ellipsis
27
- span class="#{column.cm_css_class}"
27
+ span class="#{column.field_type.to_s} #{column.cm_css_class} "
28
28
  - if index == 0
29
29
  = link_to ar_object.send(column.field_name), "/cm_admin/#{ar_object.model_name.collection}/#{ar_object.id}"
30
30
  - else
31
31
  = show_field_value(ar_object, column)
32
+ - if column.field_type == :drawer
33
+ = render partial: column.drawer_partial, locals: { ar_object: ar_object}
32
34
  td.row-action-cell
33
35
  .row-action-tool
34
36
  button.secondary-btn.tool-btn type="button"
@@ -40,10 +42,10 @@
40
42
  .popup-option
41
43
  a href="#{page_url('edit', ar_object)}"
42
44
  | Edit
43
- - @model.available_actions.select{|act| act if act.route_type == 'member'}.each do |custom_action|
45
+ - @model.available_actions.select{|act| act if act.route_type == 'member' && [:button, :modal].include?(act.display_type)}.each do |custom_action|
44
46
  - if custom_action.display_if.call(ar_object)
45
47
  .popup-option
46
- = link_to custom_action.name, custom_action.path.gsub(':id', ar_object.id.to_s), method: custom_action.verb
48
+ = link_to custom_action.name.titleize, custom_action.path.gsub(':id', ar_object.id.to_s), method: custom_action.verb
47
49
 
48
50
  .cm-pagination
49
51
  .cm-pagination__lhs Showing #{@ar_object.pagy.from} to #{@ar_object.pagy.to} out of #{@ar_object.pagy.count}
@@ -28,9 +28,14 @@
28
28
  = link_to custom_action.name.titleize, @model.ar_model.table_name + '/' + custom_action.path, class: 'primary-btn ml-2', method: custom_action.verb
29
29
  - elsif custom_action.display_type == :modal
30
30
  = link_to custom_action.name.titleize, '', class: 'primary-btn ml-2', data: { bs_toggle: "modal", bs_target: "##{custom_action.name.classify}Modal" }
31
- - elsif @model.current_action.name == 'show' || @action.layout_type == "cm_association_show"
31
+ - elsif @model.current_action.name == 'show'
32
32
  - @model.available_actions.select{|act| act if act.route_type == 'member'}.each do |custom_action|
33
33
  - if custom_action.display_type == :button && custom_action.display_if.call(@ar_object)
34
34
  = link_to custom_action.name.titleize, custom_action.path.gsub(':id', params[:id]), class: 'primary-btn ml-2', method: custom_action.verb
35
35
  - elsif custom_action.display_type == :modal && custom_action.display_if.call(@ar_object)
36
- = link_to custom_action.name.titleize, '', class: 'primary-btn ml-2', data: { bs_toggle: "modal", bs_target: "##{custom_action.name.classify}Modal" }
36
+ = link_to custom_action.name.titleize, '', class: 'primary-btn ml-2', data: { bs_toggle: "modal", bs_target: "##{custom_action.name.classify}Modal" }
37
+
38
+ - edit_action = @model.available_actions.select{|act| act if act.action_type.eql?(:default) && act.name.eql?('edit')}
39
+ - if edit_action.any?
40
+ a.primary-btn.ml-2 href="#{page_url('edit', @ar_object)}"
41
+ = "Edit #{@model.name}"
@@ -10,3 +10,4 @@
10
10
 
11
11
  = column_pop_up(@model)
12
12
  = manage_column_pop_up(@model)
13
+
@@ -1,9 +1,9 @@
1
- - @model.available_actions.select{|act| act if act.route_type == 'collection' && act.display_type == :modal}.each do |custom_action|
2
- .modal.fade id="#{custom_action.name.classify}Modal" aria-hidden="true" aria-labelledby="exampleModalLabel" tabindex="1"
1
+ - @model.available_actions.select{|act| act if act.display_type == :modal}.each do |custom_action|
2
+ .modal.fade id="#{custom_action.name.classify}Modal" aria-hidden="true" aria-labelledby="#{custom_action.name.classify}ModalLabel" tabindex="1"
3
3
  .modal-dialog
4
4
  .modal-content
5
5
  .modal-header
6
- h5#exampleModalLabel.modal-title = custom_action.name.classify
6
+ h5.modal-title id="#{custom_action.name.classify}ModalLabel" = custom_action.name.classify
7
7
  button.btn-close aria-label="Close" data-bs-dismiss="modal" type="button"
8
8
  .modal-body
9
9
  = render partial: custom_action.partial
@@ -22,7 +22,7 @@ module CmAdmin
22
22
  include Models::DslMethod
23
23
  include Models::ControllerMethod
24
24
  attr_accessor :available_actions, :actions_set, :available_fields, :permitted_fields, :current_action, :params, :filters, :available_tabs
25
- attr_reader :name, :ar_model
25
+ attr_reader :name, :ar_model, :is_visible_on_sidebar
26
26
 
27
27
  # Class variable for storing all actions
28
28
  # CmAdmin::Model.all_actions
@@ -31,6 +31,7 @@ module CmAdmin
31
31
  def initialize(entity, &block)
32
32
  @name = entity.name
33
33
  @ar_model = entity
34
+ @is_visible_on_sidebar = true
34
35
  @available_actions ||= []
35
36
  @current_action = nil
36
37
  @available_tabs ||= []
@@ -85,6 +86,10 @@ module CmAdmin
85
86
  @actions_set = true
86
87
  end
87
88
 
89
+ def visible_on_sidebar(visible_option)
90
+ @is_visible_on_sidebar = visible_option
91
+ end
92
+
88
93
 
89
94
  private
90
95
 
@@ -6,7 +6,9 @@ module CmAdmin
6
6
  include Actions::Blocks
7
7
  attr_accessor :name, :verb, :layout_type, :layout, :partial, :path, :page_title, :page_description,
8
8
  :child_records, :is_nested_field, :nested_table_name, :parent, :display_if, :route_type, :code_block,
9
- :display_type, :action_type, :redirection_url
9
+ :display_type, :action_type, :redirection_url, :sort_direction, :sort_column
10
+
11
+ VALID_SORT_DIRECTION = Set[:asc, :desc].freeze
10
12
 
11
13
  def initialize(attributes = {}, &block)
12
14
  if attributes[:layout_type].present? && attributes[:layout].nil? && attributes[:partial].nil?
@@ -30,6 +32,8 @@ module CmAdmin
30
32
  self.display_if = lambda { |arg| return true }
31
33
  self.display_type = :button
32
34
  self.action_type = :default
35
+ self.sort_column = :created_at
36
+ self.sort_direction = :desc
33
37
  end
34
38
 
35
39
  class << self
@@ -7,12 +7,10 @@ module CmAdmin
7
7
  def initialize(section_name, &block)
8
8
  @available_section_fields = []
9
9
  @section_name = section_name
10
- puts "-- reached here --"
11
10
  instance_eval(&block)
12
11
  end
13
12
 
14
13
  def field(field_name, options={})
15
- puts "For printing field #{field_name}"
16
14
  @available_section_fields << CmAdmin::Models::Field.new(field_name, options)
17
15
  end
18
16
  end
@@ -2,7 +2,7 @@ module CmAdmin
2
2
  module Models
3
3
  class Column
4
4
  attr_accessor :field_name, :field_type, :header, :format, :prefix, :suffix, :exportable, :round,
5
- :cm_css_class, :link, :url, :custom_method, :helper_method, :managable, :lockable
5
+ :cm_css_class, :link, :url, :custom_method, :helper_method, :managable, :lockable, :drawer_partial
6
6
 
7
7
  def initialize(field_name, attributes = {})
8
8
  @field_name = field_name
@@ -7,23 +7,23 @@ module CmAdmin
7
7
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'show')
8
8
  @ar_object = @ar_model.find(params[:id])
9
9
  end
10
-
10
+
11
11
  def index(params)
12
12
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'index')
13
13
  # Based on the params the filter and pagination object to be set
14
14
  @ar_object = filter_by(params, nil, filter_params(params))
15
15
  end
16
-
16
+
17
17
  def new(params)
18
18
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'new')
19
19
  @ar_object = @ar_model.new
20
20
  end
21
-
21
+
22
22
  def edit(params)
23
23
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'edit')
24
24
  @ar_object = @ar_model.find(params[:id])
25
25
  end
26
-
26
+
27
27
  def update(params)
28
28
  @ar_object = @ar_model.find(params[:id])
29
29
  @ar_object.assign_attributes(resource_params(params))
@@ -41,6 +41,8 @@ module CmAdmin
41
41
  sort_direction = %w[asc desc].include?(sort_params[:sort_direction]) ? sort_params[:sort_direction] : "asc"
42
42
  sort_params = {sort_column: sort_column, sort_direction: sort_direction}
43
43
  records = self.name.constantize.where(nil) if records.nil?
44
+ records = records.order("#{current_action.sort_column} #{current_action.sort_direction}")
45
+
44
46
  final_data = CmAdmin::Models::Filter.filtered_data(filter_params, records, @filters)
45
47
  pagy, records = pagy(final_data)
46
48
  filtered_result.data = records
@@ -50,7 +52,7 @@ module CmAdmin
50
52
  # filtered_result.facets.sort = sort_params
51
53
  return filtered_result
52
54
  end
53
-
55
+
54
56
  def resource_params(params)
55
57
  permittable_fields = @permitted_fields || @ar_model.columns.map(&:name).reject { |i| CmAdmin::REJECTABLE_FIELDS.include?(i) }.map(&:to_sym)
56
58
  permittable_fields += @ar_model.reflect_on_all_attachments.map {|x|
@@ -62,15 +64,16 @@ module CmAdmin
62
64
  }.compact
63
65
  nested_tables = self.available_fields[:new].except(:fields).keys
64
66
  nested_tables += self.available_fields[:edit].except(:fields).keys
65
- nested_fields = nested_tables.map {|table|
67
+ nested_fields = nested_tables.uniq.map {|table|
66
68
  Hash[
67
69
  table.to_s + '_attributes',
68
70
  table.to_s.classify.constantize.columns.map(&:name).reject { |i| CmAdmin::REJECTABLE_FIELDS.include?(i) }.map(&:to_sym) + [:id, :_destroy]
69
71
  ]
70
72
  }
71
73
  permittable_fields += nested_fields
74
+ @ar_model.columns.map { |col| permittable_fields << col.name.split('_cents') if col.name.include?('_cents') }
72
75
  params.require(self.name.underscore.to_sym).permit(*permittable_fields)
73
76
  end
74
77
  end
75
78
  end
76
- end
79
+ end
@@ -24,14 +24,14 @@ module CmAdmin
24
24
  @current_action.page_description = page_description
25
25
  yield
26
26
  end
27
-
27
+
28
28
  def cm_edit(page_title: nil,page_description: nil, &block)
29
29
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'edit')
30
30
  @current_action.page_title = page_title
31
31
  @current_action.page_description = page_description
32
32
  yield
33
33
  end
34
-
34
+
35
35
  def cm_new(page_title: nil,page_description: nil,&block)
36
36
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'new')
37
37
  @current_action.page_title = page_title
@@ -44,13 +44,13 @@ module CmAdmin
44
44
  @current_action.page_title = title
45
45
  end
46
46
  end
47
-
47
+
48
48
  def page_description(description)
49
49
  if @current_action
50
50
  @current_action.page_description = description
51
51
  end
52
52
  end
53
-
53
+
54
54
  def tab(tab_name, custom_action, associated_model: nil, layout_type: nil, layout: nil, partial: nil, &block)
55
55
  if custom_action.to_s == ''
56
56
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'show')
@@ -65,12 +65,12 @@ module CmAdmin
65
65
  end
66
66
  yield if block
67
67
  end
68
-
68
+
69
69
  def cm_show_section(section_name, &block)
70
70
  @available_fields[@current_action.name.to_sym] ||= []
71
71
  @available_fields[@current_action.name.to_sym] << CmAdmin::Models::CmShowSection.new(section_name, &block)
72
72
  end
73
-
73
+
74
74
  def form_field(field_name, options={}, arg=nil)
75
75
  unless @current_action.is_nested_field
76
76
  @available_fields[@current_action.name.to_sym][:fields] << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
@@ -79,23 +79,24 @@ module CmAdmin
79
79
  @available_fields[@current_action.name.to_sym][@current_action.nested_table_name] << CmAdmin::Models::FormField.new(field_name, options[:input_type], options)
80
80
  end
81
81
  end
82
-
82
+
83
83
  def nested_form_field(field_name, &block)
84
84
  @current_action.is_nested_field = true
85
85
  @current_action.nested_table_name = field_name
86
86
  yield
87
87
  end
88
-
88
+
89
89
  def column(field_name, options={})
90
90
  @available_fields[@current_action.name.to_sym] ||= []
91
91
  if @available_fields[@current_action.name.to_sym].select{|x| x.lockable}.size > 0 && options[:lockable]
92
92
  raise "Only one column can be locked in a table."
93
93
  end
94
+
94
95
  unless @available_fields[@current_action.name.to_sym].map{|x| x.field_name.to_sym}.include?(field_name)
95
96
  @available_fields[@current_action.name.to_sym] << CmAdmin::Models::Column.new(field_name, options)
96
97
  end
97
98
  end
98
-
99
+
99
100
  def all_db_columns(options={})
100
101
  field_names = self.instance_variable_get(:@ar_model)&.columns&.map{|x| x.name.to_sym}
101
102
  if options.include?(:exclude) && field_names
@@ -130,6 +131,24 @@ module CmAdmin
130
131
  def filter(db_column_name, filter_type, options={})
131
132
  @filters << CmAdmin::Models::Filter.new(db_column_name: db_column_name, filter_type: filter_type, options: options)
132
133
  end
134
+
135
+ def sort_direction(direction = :desc)
136
+ raise ArgumentError, "Select a valid sort direction like #{CmAdmin::Models::Action::VALID_SORT_DIRECTION.join(' or ')} instead of #{direction}" unless CmAdmin::Models::Action::VALID_SORT_DIRECTION.include?(direction.to_sym.downcase)
137
+
138
+ @current_action.sort_direction = direction.to_sym if @current_action
139
+ end
140
+
141
+ def sort_column(column = :created_at)
142
+ model = if @current_action.child_records
143
+ CmAdmin::Model.find_by(name: @current_action.child_records.to_s.classify)
144
+ else
145
+ self
146
+ end
147
+ db_columns = model.instance_variable_get(:@ar_model)&.columns&.map{|x| x.name.to_sym}
148
+ raise "Sorting for custom column #{column} does not exist." unless db_columns.include?(column.to_sym)
149
+
150
+ @current_action.sort_column = column.to_sym if @current_action
151
+ end
133
152
  end
134
153
  end
135
- end
154
+ end
@@ -15,6 +15,7 @@ module CmAdmin
15
15
 
16
16
  def set_default_values
17
17
  self.disabled = false
18
+ self.label = self.field_name.to_s.titleize
18
19
  end
19
20
  end
20
21
  end
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.6"
3
3
  end
@@ -47,6 +47,11 @@ module CmAdmin
47
47
  end
48
48
  when :attachment
49
49
  concat show_attachment_value(ar_object, field)
50
+ when :drawer
51
+ content_tag :span do
52
+ concat content_tag(:span, truncate(ar_object.send(field.field_name).to_s, length: 25))
53
+ concat content_tag(:a, " View", class: "drawer-btn")
54
+ end
50
55
  end
51
56
  end
52
57
  end
@@ -44,10 +44,10 @@ module CmAdmin
44
44
  if field.input_type.eql?(:hidden)
45
45
  concat input_field_for_column(f, field)
46
46
  else
47
- concat f.label field.field_name, class: 'field-label'
47
+ concat f.label field.label, class: 'field-label'
48
48
  concat tag.br
49
49
  concat(content_tag(:div, class: "datetime-wrapper") do
50
- concat input_field_for_column(f, field)
50
+ concat input_field_for_column(f, field)
51
51
  end)
52
52
  concat tag.p resource.errors[field.field_name].first if resource.errors[field.field_name].present?
53
53
  end
@@ -5,26 +5,28 @@ module CmAdmin
5
5
  include Pagy::Frontend
6
6
  def navigation_links(navigation_type)
7
7
  CmAdmin.cm_admin_models.map { |model|
8
- path = CmAdmin::Engine.mount_path + '/' + model.name.underscore.pluralize
9
- if navigation_type == "sidebar"
10
- content_tag(:a, href: path) do
11
- content_tag(:div, class: 'menu-item') do
12
- content_tag(:span, class: 'menu-icon') do
13
- concat tag.i class: 'fa fa-th-large'
14
- end +
15
- model.name
16
- end
17
- end
18
- elsif navigation_type == "quick_links"
19
- content_tag(:a, href: path, class: 'visible') do
20
- content_tag(:div, class: 'result-item') do
21
- content_tag(:span) do
22
- concat tag.i class: 'fa fa-th-large'
23
- end +
24
- content_tag(:span) do
8
+ if model.is_visible_on_sidebar
9
+ path = CmAdmin::Engine.mount_path + '/' + model.name.underscore.pluralize
10
+ if navigation_type == "sidebar"
11
+ content_tag(:a, href: path) do
12
+ content_tag(:div, class: 'menu-item') do
13
+ content_tag(:span, class: 'menu-icon') do
14
+ concat tag.i class: 'fa fa-th-large'
15
+ end +
25
16
  model.name
26
17
  end
27
18
  end
19
+ elsif navigation_type == "quick_links"
20
+ content_tag(:a, href: path, class: 'visible') do
21
+ content_tag(:div, class: 'result-item') do
22
+ content_tag(:span) do
23
+ concat tag.i class: 'fa fa-th-large'
24
+ end +
25
+ content_tag(:span) do
26
+ model.name
27
+ end
28
+ end
29
+ end
28
30
  end
29
31
  end
30
32
  }.join.html_safe
@@ -1 +1 @@
1
- b50f217278de15248bddb0b6f2e6be58edbffa7c
1
+ d5850cd60f91abe79ff8a84a45a9e24c75cb0e4b
data/yarn.lock CHANGED
@@ -2941,9 +2941,9 @@ flush-write-stream@^1.0.0:
2941
2941
  readable-stream "^2.3.6"
2942
2942
 
2943
2943
  follow-redirects@^1.0.0:
2944
- version "1.14.1"
2945
- resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.1.tgz#d9114ded0a1cfdd334e164e6662ad02bfd91ff43"
2946
- integrity sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg==
2944
+ version "1.14.8"
2945
+ resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.8.tgz#016996fb9a11a100566398b1c6839337d7bfa8fc"
2946
+ integrity sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==
2947
2947
 
2948
2948
  for-in@^1.0.2:
2949
2949
  version "1.0.2"
@@ -6589,9 +6589,9 @@ urix@^0.1.0:
6589
6589
  integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=
6590
6590
 
6591
6591
  url-parse@^1.4.3, url-parse@^1.5.1:
6592
- version "1.5.3"
6593
- resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.3.tgz#71c1303d38fb6639ade183c2992c8cc0686df862"
6594
- integrity sha512-IIORyIQD9rvj0A4CLWsHkBBJuNqWpFQe224b6j9t/ABmquIS0qDU2pY6kl6AuOrL5OkCXHMCFNe1jBcuAggjvQ==
6592
+ version "1.5.10"
6593
+ resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.10.tgz#9d3c2f736c1d75dd3bd2be507dcc111f1e2ea9c1"
6594
+ integrity sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==
6595
6595
  dependencies:
6596
6596
  querystringify "^2.1.1"
6597
6597
  requires-port "^1.0.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cm-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - sajinmp
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2022-02-10 00:00:00.000000000 Z
13
+ date: 2022-03-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: pagy
@@ -116,6 +116,7 @@ files:
116
116
  - app/assets/stylesheets/cm_admin/cm_admin.css.scss
117
117
  - app/assets/stylesheets/cm_admin/components/_alerts.scss
118
118
  - app/assets/stylesheets/cm_admin/components/_buttons.scss
119
+ - app/assets/stylesheets/cm_admin/components/_drawer.scss
119
120
  - app/assets/stylesheets/cm_admin/components/_dropdown-popup.scss
120
121
  - app/assets/stylesheets/cm_admin/components/_input.scss
121
122
  - app/assets/stylesheets/cm_admin/components/_modal.scss
@@ -139,6 +140,7 @@ files:
139
140
  - app/javascript/stylesheets/cm_admin/application.scss
140
141
  - app/views/cm_admin/main/_associated_table.html.slim
141
142
  - app/views/cm_admin/main/_cm_pagy_nav.html.slim
143
+ - app/views/cm_admin/main/_drawer.html.slim
142
144
  - app/views/cm_admin/main/_filters.html.slim
143
145
  - app/views/cm_admin/main/_nested_fields.html.slim
144
146
  - app/views/cm_admin/main/_nested_table_form.html.slim