cm-admin 0.5.4 → 0.5.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: 590c14bc3ee438f00943ac40316aaf1e0850639a5eda8da1d4c73dec80b11963
4
- data.tar.gz: df5b1269f85267cc86e123c15b950e50292396771cb83cc10dc27bb3337d7416
3
+ metadata.gz: 4005c7711af2f931298a2054cd527de1a67a92a42deaecd8fb71b37fbcdc5fb2
4
+ data.tar.gz: 8fa616289069247a2418896b7ac2cb4f6ca5ec1dfc121d5a06cececb9c3a5242
5
5
  SHA512:
6
- metadata.gz: 1b530f87e1a584d25e43684491ddee0156d7544bcb31f13c8b4d53aedff611ff0ffae7fc4ea9898d5186f4a3453463d7d77b7ecf4f39bee8020fcb4c753f6e76
7
- data.tar.gz: ec22d42e7c47f2755642a902821db15616378361b661b0a609d22fe5b678527ae6ddddf62d902ba0aa55fc647eb215bb4704df046f5b7bbf5625c1b7ffceaa2f
6
+ metadata.gz: 82d898a13ff420a9c3e7b9df6f9daca9174df4bc3587c879cac1817cdbdcb5e812562f81a7e5ed8716729da466da5240037e3d7bca36900d5efb355859c4ca1a
7
+ data.tar.gz: 29a54f03bb2aaa0cec4aa0fecaef373376e94a4e6e47e67219245ae257f2f2774ad388e9a4b8b9510a23d45f130fc9a6703128403b512256525d2197dae292a0
@@ -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,10 +72,12 @@
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;
@@ -79,8 +88,8 @@
79
88
  &__header {
80
89
  .header-row {
81
90
  display: block;
82
- position: relative;
83
91
  width: 100%;
92
+ position: relative;
84
93
  box-shadow: inset 0px -1px 0px rgba(148, 151, 155, 0.15);
85
94
  th {
86
95
  @include font($size: $t6-text, $color: $ink-lighter-clr, $weight: bold);
@@ -89,10 +98,22 @@
89
98
  max-width: 200px;
90
99
  padding: 12px 16px 12px 16px;
91
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
+ }
92
108
  .check-box-space {
109
+ position: sticky;
110
+ left: 0;
93
111
  min-width: fit-content;
94
112
  max-width: fit-content;
95
113
  padding: 12px 8px 12px 16px;
114
+ z-index: 2;
115
+ background-color: #fff;
116
+ border-bottom: 1.21px solid rgb(240, 239, 239);
96
117
  span {
97
118
  vertical-align: text-top;
98
119
  }
@@ -100,24 +121,47 @@
100
121
  }
101
122
  }
102
123
  &__body {
124
+ // display: block;
125
+ // overflow: auto;
126
+ // overflow-x: hidden;
127
+ // position: relative;
128
+ // width: 100%;
129
+ // height: 335px;
103
130
  display: block;
104
131
  position: relative;
105
- width: 100%; .body-row {
106
- box-shadow: inset 0px -1px 0px rgba(148, 151, 155, 0.15);
107
- 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
+
108
142
  &:nth-last-child(1) {
109
143
  box-shadow: none;
110
144
  }
111
145
  &:hover {
112
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
+ }
113
153
  .row-action-cell {
114
154
  opacity: 1;
115
155
  }
116
156
  }
117
157
  .check-box-space {
158
+ position: sticky;
159
+ left: 0;
118
160
  min-width: fit-content;
119
161
  max-width: fit-content;
120
162
  padding: 16px 8px 16px 16px;
163
+ z-index: 2;
164
+ background-color: #fff;
121
165
  span {
122
166
  vertical-align: text-top;
123
167
  }
@@ -145,6 +189,17 @@
145
189
  align-items: center;
146
190
  justify-content: center;
147
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
+ }
148
203
  .tool-btn {
149
204
  background-color: transparent;
150
205
  border: none;
@@ -154,15 +209,20 @@
154
209
  }
155
210
  }
156
211
  }
212
+ .cm-table > thead {
213
+ position:sticky;
214
+ top:0;
215
+ background-color: #fff;
216
+ z-index: 3;
217
+ }
157
218
  }
158
219
 
159
220
  .admin-table-index {
160
-
161
221
  position: fixed;
162
222
  width: calc(100% - 285px);
163
223
  left: 245px;
164
224
  background-color: #fff;
165
- z-index: 1;
225
+ z-index: 4;
166
226
  .table-sticky-top {
167
227
  position: sticky;
168
228
  top: 254px;
@@ -172,6 +232,8 @@
172
232
  justify-content: space-between;
173
233
  align-items: center;
174
234
  padding-bottom: 16px;
235
+ margin-top: -20px;
236
+ background-color: #fff;
175
237
  &__total-count {
176
238
  font-size: $t4-text;
177
239
  line-height: 22px;
@@ -0,0 +1,90 @@
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
+ }
87
+
88
+ .drawer {
89
+ cursor: pointer;
90
+ }
@@ -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
  });
@@ -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,26 +24,32 @@
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
- td.row-action-cell
33
- .row-action-tool
34
- button.secondary-btn.tool-btn type="button"
35
- span
36
- i.fa.fa-bars.bolder
37
- span
38
- i.fa.fa-angle-down
39
- .popup-card.table-export-popup.hidden
40
- .popup-option
41
- a href="#{page_url('edit', ar_object)}"
42
- | Edit
43
- - @model.available_actions.select{|act| act if act.route_type == 'member'}.each do |custom_action|
44
- - if custom_action.display_if.call(ar_object)
45
- .popup-option
46
- = link_to custom_action.name, custom_action.path.gsub(':id', ar_object.id.to_s), method: custom_action.verb
32
+ - if column.field_type == :drawer
33
+ = render partial: column.drawer_partial, locals: { ar_object: ar_object}
34
+
35
+ - edit_action = @model.available_actions.select{|act| act if act.action_type.eql?(:default) && act.name.eql?('edit')}
36
+ - custom_actions = @model.available_actions.select{|act| act if act.route_type == 'member' && [:button, :modal].include?(act.display_type)}
37
+ - if custom_actions.any? || edit_action.any?
38
+ td.row-action-cell
39
+ .row-action-tool
40
+ button.secondary-btn.tool-btn type="button"
41
+ span
42
+ i.fa.fa-bars.bolder
43
+ span
44
+ i.fa.fa-angle-down
45
+ .popup-card.table-export-popup.hidden
46
+ - if edit_action.any?
47
+ = link_to "#{page_url('edit', ar_object)}" do
48
+ .popup-option Edit
49
+ - custom_actions.each do |custom_action|
50
+ - if custom_action.display_if.call(ar_object)
51
+ = link_to custom_action.path.gsub(':id', ar_object.id.to_s), method: custom_action.verb do
52
+ .popup-option = custom_action.name.titleize
47
53
 
48
54
  .cm-pagination
49
55
  .cm-pagination__lhs Showing #{@ar_object.pagy.from} to #{@ar_object.pagy.to} out of #{@ar_object.pagy.count}
@@ -20,9 +20,9 @@
20
20
  li
21
21
  .popup-option.pointer data-bs-toggle='modal' data-bs-target='#exportmodal'
22
22
  span Export
23
-
24
- a.primary-btn.ml-2 href="#{page_url('new')}"
25
- | Add
23
+ - new_action = @model.available_actions.select{|act| act if act.action_type.eql?(:default) && act.name.eql?('new')}
24
+ - if new_action.any?
25
+ = link_to 'Add', "#{page_url('new')}", class: 'primary-btn ml-2'
26
26
  - @model.available_actions.select{|act| act if act.route_type == 'collection'}.each do |custom_action|
27
27
  - if custom_action.display_type == :button
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
@@ -37,5 +37,4 @@
37
37
 
38
38
  - edit_action = @model.available_actions.select{|act| act if act.action_type.eql?(:default) && act.name.eql?('edit')}
39
39
  - if edit_action.any?
40
- a.primary-btn.ml-2 href="#{page_url('edit', @ar_object)}"
41
- = "Edit #{@model.name}"
40
+ = link_to "Edit #{@model.name}", "#{page_url('edit', @ar_object)}", class: 'primary-btn ml-2'
@@ -1,6 +1,6 @@
1
1
  .cm-index-page
2
2
  .index-page
3
- .index-page__table-container.pt-0
3
+ .index-page__table-container
4
4
  == render partial: 'cm_admin/main/associated_table'
5
5
 
6
6
  // = column_pop_up(@associated_model)
@@ -10,3 +10,4 @@
10
10
 
11
11
  = column_pop_up(@model)
12
12
  = manage_column_pop_up(@model)
13
+
@@ -21,7 +21,8 @@ module CmAdmin
21
21
  include Models::Blocks
22
22
  include Models::DslMethod
23
23
  include Models::ControllerMethod
24
- attr_accessor :available_actions, :actions_set, :available_fields, :permitted_fields, :current_action, :params, :filters, :available_tabs
24
+ attr_accessor :available_actions, :actions_set, :available_fields, :permitted_fields,
25
+ :current_action, :params, :filters, :available_tabs, :icon_name
25
26
  attr_reader :name, :ar_model, :is_visible_on_sidebar
26
27
 
27
28
  # Class variable for storing all actions
@@ -32,6 +33,7 @@ module CmAdmin
32
33
  @name = entity.name
33
34
  @ar_model = entity
34
35
  @is_visible_on_sidebar = true
36
+ @icon_name = 'fa fa-th-large'
35
37
  @available_actions ||= []
36
38
  @current_action = nil
37
39
  @available_tabs ||= []
@@ -59,7 +61,7 @@ module CmAdmin
59
61
  current_action = CmAdmin::Models::Action.find_by(self, name: action_name.to_s)
60
62
  if current_action
61
63
  @current_action = current_action
62
- @ar_object = @ar_model.find(params[:id])
64
+ @ar_object = @ar_model.name.classify.constantize.find(params[:id])
63
65
  if @current_action.child_records
64
66
  child_records = @ar_object.send(@current_action.child_records)
65
67
  @associated_model = CmAdmin::Model.find_by(name: @ar_model.reflect_on_association(@current_action.child_records).klass.name)
@@ -90,6 +92,10 @@ module CmAdmin
90
92
  @is_visible_on_sidebar = visible_option
91
93
  end
92
94
 
95
+ def set_icon(name)
96
+ @icon_name = name
97
+ end
98
+
93
99
 
94
100
  private
95
101
 
@@ -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.4"
2
+ VERSION = "0.5.7"
3
3
  end
@@ -43,10 +43,15 @@ module CmAdmin
43
43
  ar_object.send(field.field_name).to_s.titleize
44
44
  when :tag
45
45
  content_tag :span, class: "status-tag default-#{ar_object.send(field.field_name.to_s + '_before_type_cast')}" do
46
- ar_object.send(field.field_name).to_s.titleize
46
+ ar_object.send(field.field_name).to_s.upcase
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
@@ -11,16 +11,16 @@ module CmAdmin
11
11
  content_tag(:a, href: path) do
12
12
  content_tag(:div, class: 'menu-item') do
13
13
  content_tag(:span, class: 'menu-icon') do
14
- concat tag.i class: 'fa fa-th-large'
14
+ concat tag.i class: "#{model.icon_name}"
15
15
  end +
16
- model.name
16
+ model.name.pluralize
17
17
  end
18
18
  end
19
19
  elsif navigation_type == "quick_links"
20
20
  content_tag(:a, href: path, class: 'visible') do
21
21
  content_tag(:div, class: 'result-item') do
22
22
  content_tag(:span) do
23
- concat tag.i class: 'fa fa-th-large'
23
+ concat tag.i class: "#{model.icon_name}"
24
24
  end +
25
25
  content_tag(:span) do
26
26
  model.name
@@ -1 +1 @@
1
- 33d3c35c58c8db0310c4cb3ec7ff742813910e07
1
+ 07d558738c316293586496817b2bccbf6430b5bd
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.4
4
+ version: 0.5.7
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-15 00:00:00.000000000 Z
13
+ date: 2022-03-11 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
@@ -228,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
230
  - !ruby/object:Gem::Version
229
231
  version: '0'
230
232
  requirements: []
231
- rubygems_version: 3.0.3
233
+ rubygems_version: 3.2.32
232
234
  signing_key:
233
235
  specification_version: 4
234
236
  summary: This is an admin panel gem