cm-admin 1.3.9 → 1.4.0

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: 562260419c63a8ecbe47434934436fcbcfcc0bba45d5fdb1ec79b409dab1eae8
4
- data.tar.gz: 44254130972962094d599673a89bbc4b1961ef4ef8eedc1087c5313f18c7b683
3
+ metadata.gz: 680b8d7f174e764d9a17115f20014a8c02ff18a274bc4df022f5285671be343f
4
+ data.tar.gz: b3278745964ecd7cfc13ea6a4c8381ba5b8ead0b19e086dcc125a6da6ab70fde
5
5
  SHA512:
6
- metadata.gz: 763022ed87852040e0dfe161df4d9044ce802f8b3555bac98eafd765dde5d6f396eb5f3c4c46ede87cffae6e5b6ba09ac6f9f60001690091f803d9f1b292568c
7
- data.tar.gz: b1495b2af0cffaf34e0aedba3a7ead53c13e8ab7ad9dc883d403ec6594e4301cca7c208193daa80ea48fd95f8657045fb31af88de4d87234c2f9bd22fa1b69de
6
+ metadata.gz: f5ba67994c1f9746a5ccd57a02ea66ce0127cebfec936792f54ad655e8a7a5dc075bfa7c25d3294b234baf095cbf956ef70f65310d332b1271410d51b0728878
7
+ data.tar.gz: 26c7185ff4ef0168e0ee16936a4518e84250836c10a3b549d21f0691816411d407b99e030c7d605524da04e58fabc4ff424a6de0069bc887b8e820320e622f63
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cm-admin (1.3.9)
4
+ cm-admin (1.4.0)
5
5
  caxlsx_rails
6
6
  cocoon (~> 1.2.15)
7
7
  csv-importer (~> 0.8.2)
@@ -8,5 +8,5 @@ import './filters.js'
8
8
  import './form_validation.js'
9
9
  import './quick_search.js'
10
10
  import './custom.js'
11
-
11
+ import './kanban.js'
12
12
 
@@ -70,7 +70,17 @@ var getFilteredData = function(filterType, filterValue, filterColumn=null) {
70
70
  success: function(data) {
71
71
  var queryParam = jQuery.param(queryString)
72
72
  window.history.pushState("", "", url + '?' + queryParam);
73
- $('.cm-index-page__table-container').html(data);
73
+ if ($('#view_type').val() == 'kanban') {
74
+ $.each(data.table.data, function(key, value) {
75
+ $('.' + key + ' .cards').html(value)
76
+ });
77
+ $('.kanban-list .counter').html(0)
78
+ $.each(data.table.column_count, function(key, value) {
79
+ $('.' + key + ' .counter').html(value)
80
+ });
81
+ } else {
82
+ $('.cm-index-page__table-container').html(data);
83
+ }
74
84
  },
75
85
  error: function(jqxhr, textStatus, errorThrown) {
76
86
  console.log(errorThrown, textStatus);
@@ -0,0 +1,30 @@
1
+ $(document).on('click', '.kanban-show-more', function(e) {
2
+ e.preventDefault();
3
+ var page = $(this).data('page') + 1
4
+ var query_string = window.location.search
5
+ $.ajax('/admin/batch_order_items' + query_string, {
6
+ type: "GET",
7
+ data: {
8
+ page: page,
9
+ per_page: $(this).data('per-page'),
10
+ view_type: 'kanban'
11
+ },
12
+ success: function (data) {
13
+ apply_response_to_board(data.table.data);
14
+ $('.kanban-show-more').data('page', page)
15
+ if (data.table.paging.next_page == false) {
16
+ $('.kanban-show-more').addClass('disabled')
17
+ }
18
+ $('.kanban-show-more').data('page', page)
19
+ },
20
+ error: function (jqxhr, textStatus, errorThrown) {
21
+ alert("Something went wrong. Please try again later.\n" + errorThrown);
22
+ },
23
+ });
24
+ })
25
+
26
+ function apply_response_to_board(json_data) {
27
+ $.each(json_data, function(key, value) {
28
+ $('.' + key + ' .cards').append(value)
29
+ });
30
+ }
@@ -7,37 +7,38 @@
7
7
  .card-grid {
8
8
  @extend .row, .row-cols-4, .g-3;
9
9
  }
10
- .item-card {
11
- @extend .card, .position-relative;
12
- border-radius: 4px;
13
- .card-menu {
14
- @extend .dropdown, .position-absolute;
15
- top: 8px;
16
- right: 8px;
17
- }
18
- .card-img-top {
19
- height: 185px;
20
- object-fit: cover;
21
- border-top-left-radius: 4px;
22
- border-top-right-radius: 4px;
23
- }
24
- .card-subtitle {
25
- @extend .d-flex, .justify-content-between, .text-secondary, .fw-medium;
26
- font-size: $t4-text;
27
- .item-id {
28
- margin: 0;
29
- span {
30
- border-left: 1px solid;
31
- padding-left: 4px;
32
- }
10
+ }
11
+
12
+ .item-card {
13
+ @extend .card, .position-relative;
14
+ border-radius: 4px;
15
+ .card-menu {
16
+ @extend .dropdown, .position-absolute;
17
+ top: 8px;
18
+ right: 8px;
19
+ }
20
+ .card-img-top {
21
+ height: 185px;
22
+ object-fit: cover;
23
+ border-top-left-radius: 4px;
24
+ border-top-right-radius: 4px;
25
+ }
26
+ .card-subtitle {
27
+ @extend .d-flex, .justify-content-between, .text-secondary, .fw-medium;
28
+ font-size: $t4-text;
29
+ .item-id {
30
+ margin: 0;
31
+ span {
32
+ border-left: 1px solid;
33
+ padding-left: 4px;
33
34
  }
34
35
  }
35
- .card-footer {
36
- @extend .d-flex, .justify-content-between, .bg-white;
37
- .item-price {
38
- font-size: $t4-text;
39
- margin: 0;
40
- }
36
+ }
37
+ .card-footer {
38
+ @extend .d-flex, .justify-content-between, .bg-white;
39
+ .item-price {
40
+ font-size: $t4-text;
41
+ margin: 0;
41
42
  }
42
43
  }
43
44
  }
@@ -0,0 +1,35 @@
1
+ @import "../helpers/index.scss";
2
+ @import "../dependency/bootstrap/scss/bootstrap";
3
+
4
+ .comments-wrapper {
5
+ padding: 24px;
6
+ .comment-card {
7
+ @extend .card;
8
+ margin: 8px 0;
9
+ background-color: $card-grey-lighter-clr;
10
+ border: none;
11
+ .comment {
12
+ @extend .d-flex;
13
+ gap: 8px;
14
+ .profile-pic {
15
+ width: 32px;
16
+ height: 32px;
17
+ @extend .rounded-circle;
18
+ }
19
+ .comment-info {
20
+ .user-name {
21
+ @extend .fw-semibold;
22
+ color: $ink-regular-clr;
23
+ }
24
+ .timing {
25
+ @extend .text-body-tertiary, .fw-normal;
26
+ }
27
+ .comment-text {
28
+ color: $ink-regular-clr;
29
+ max-width: 656px;
30
+ margin: 0;
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,37 @@
1
+ @import "../helpers/index.scss";
2
+ @import "../dependency/bootstrap/scss/bootstrap";
3
+
4
+ .kanban-container {
5
+ @extend .d-flex, .flex-nowrap;
6
+ gap: 8px;
7
+ max-width: 100%;
8
+ height: calc(100vh - 214px);
9
+ padding-right: 24px;
10
+ overflow-x: auto;
11
+ .kanban-list {
12
+ min-width: 240px;
13
+ max-width: 240px;
14
+ background: var(--grey-lighter, #f3f4f6);
15
+ padding: 8px;
16
+ &__header {
17
+ @extend .d-flex, .justify-content-between;
18
+ p {
19
+ font-size: $t4-text;
20
+ margin-bottom: 8px;
21
+ &:nth-child(1) {
22
+ color: $ink-regular-clr;
23
+ }
24
+ &:nth-child(2) {
25
+ color: $ink-lighter-clr;
26
+ }
27
+ }
28
+ }
29
+ }
30
+ .item-card {
31
+ margin-bottom: 8px;
32
+ }
33
+ }
34
+
35
+ .kanban-pagination {
36
+ justify-content: center !important;
37
+ }
@@ -233,6 +233,10 @@
233
233
  }
234
234
  }
235
235
  }
236
+
237
+ .kanban-pagination {
238
+ justify-content: center !important;
239
+ }
236
240
  }
237
241
 
238
242
  [data-field-type="money"] {
@@ -21,8 +21,10 @@
21
21
  *= require 'cm_admin/base/scaffold'
22
22
  *= require 'cm_admin/base/auth'
23
23
  *= require 'cm_admin/base/filters'
24
+ *= require 'cm_admin/base/comments'
24
25
  *= require 'cm_admin/base/common'
25
26
  *= require 'cm_admin/base/cardView'
27
+ *= require 'cm_admin/base/kanban'
26
28
  *= require 'cm_admin/components/index'
27
29
  *= require 'cm_admin/dependency/bootstrap.min'
28
30
  *= require 'cm_admin/dependency/flatpickr.min'
@@ -37,6 +37,7 @@ $grey-light-clr: #d9dee3;
37
37
  $grey-lighter-clr: #f3f4f6;
38
38
  $grey-lightest-clr: #f8f9fa;
39
39
  $grey-dark-clr: #828282;
40
+ $card-grey-lighter-clr: #f3f4f6;
40
41
 
41
42
  /* Ink Colors */
42
43
  $ink-regular-clr: #1d2129;
@@ -10,10 +10,15 @@ module CmAdmin
10
10
  # Based on the params the filter and pagination object to be set
11
11
  records = "CmAdmin::#{@model.name}Policy::Scope".constantize.new(Current.user, @model.name.constantize).resolve
12
12
  records = apply_scopes(records)
13
- @ar_object = filter_by(params, records, @model.filter_params(params))
14
- # resource_identifier
13
+ if (request.xhr? && params[:view_type] == 'kanban') || @current_action.view_type == :kanban
14
+ @ar_object = kanban_filter_by(params, records, @model.filter_params(params))
15
+ else
16
+ @ar_object = filter_by(params, records, @model.filter_params(params))
17
+ end
15
18
  respond_to do |format|
16
- if request.xhr?
19
+ if request.xhr? && (params[:view_type] == 'kanban' || @current_action.view_type == :kanban)
20
+ format.json { render json: @ar_object }
21
+ elsif request.xhr?
17
22
  format.html { render partial: '/cm_admin/main/table' }
18
23
  else
19
24
  format.html { render '/cm_admin/main/' + action_name }
@@ -258,6 +263,45 @@ module CmAdmin
258
263
  return filtered_result
259
264
  end
260
265
 
266
+ def kanban_filter_by(params, records, filter_params={}, sort_params={})
267
+ filtered_result = OpenStruct.new
268
+ cm_model = @associated_model || @model
269
+ db_columns = cm_model.ar_model&.columns&.map{|x| x.name.to_sym}
270
+ if db_columns.include?(@current_action.sort_column)
271
+ sort_column = @current_action.sort_column
272
+ else
273
+ sort_column = 'created_at'
274
+ end
275
+ records = "CmAdmin::#{@model.name}Policy::Scope".constantize.new(Current.user, @model.name.constantize).resolve if records.nil?
276
+ # records = records.order("#{sort_column} #{@current_action.sort_direction}")
277
+ final_data = CmAdmin::Models::Filter.filtered_data(filter_params, records, cm_model.filters)
278
+ filtered_result.data = {}
279
+ filtered_result.paging = {}
280
+ filtered_result.paging['next_page'] = true
281
+ group_record_count = final_data.group(@current_action.kanban_attr[:column_name]).count
282
+ per_page = params[:per_page] || 20
283
+ page = params[:page] || 1
284
+ max_page = (group_record_count.values.max.to_i / per_page.to_f).ceil
285
+ filtered_result.paging['next_page'] = (page.to_i < max_page)
286
+ filtered_result.column_count = group_record_count.reject {|key, value| key.blank? }
287
+
288
+ column_names = @model.ar_model.send(@current_action.kanban_attr[:column_name].pluralize).keys
289
+ if @current_action.kanban_attr[:only].present?
290
+ column_names &= @current_action.kanban_attr[:only]
291
+ elsif @current_action.kanban_attr[:exclude].present?
292
+ column_names -= @current_action.kanban_attr[:exclude]
293
+ end
294
+ column_names.each do |column|
295
+ total_count = group_record_count[column]
296
+ filtered_result.data[column] = ''
297
+ next if page.to_i > (total_count.to_i / per_page.to_f).ceil
298
+
299
+ pagy, records = pagy(final_data.send(column), items: per_page.to_i)
300
+ filtered_result.data[column] = render_to_string partial: 'cm_admin/main/kanban_card', locals: { ar_collection: records}
301
+ end
302
+ filtered_result
303
+ end
304
+
261
305
  def generate_nested_params(nested_table_field)
262
306
  if nested_table_field.parent_field
263
307
  ar_model = nested_table_field.parent_field.to_s.classify.constantize
@@ -18,6 +18,20 @@ $(document).on('turbolinks:load', function () {
18
18
  animation: 150
19
19
  });
20
20
  }
21
+
22
+ // var array = $('#searchKeywords').val().split(",");
23
+ // $.each(array,function(i){
24
+ // alert(array[i]);
25
+ // });
26
+
27
+ // var el = document.getElementsByClassName('kanban-list')
28
+ // if(el[0]) {
29
+ // Sortable.create(el,{
30
+ // handle: '.kanban-item',
31
+ // animation: 150
32
+ // });
33
+ // }
34
+
21
35
  var headerElemHeight = $('.page-top-bar').height() + 64
22
36
  var calculatedHeight = "calc(100vh - " + headerElemHeight+"px"+")"
23
37
  $('.table-wrapper').css("maxHeight", calculatedHeight);
@@ -6,7 +6,7 @@
6
6
  .btn-group[role="group" aria-label="Basic example"]
7
7
  a.btn.btn-ghost href="#{cm_admin.send("#{@model.name.underscore}_index_path")}?page=#{params[:page] || 1}"
8
8
  i.fa.fa-table
9
- a.btn.btn-ghost href="#{cm_admin.send("#{@model.name.underscore}_index_path")}?page=#{params[:page] || 1}&list_type=card"
9
+ a.btn.btn-ghost href="#{cm_admin.send("#{@model.name.underscore}_index_path")}?page=#{params[:page] || 1}&view_type=card"
10
10
  i.fa.fa-table-cells
11
11
  / button.secondary-btn.column-btn data-bs-target="#columnActionModal" data-bs-toggle="modal"
12
12
  / span
@@ -0,0 +1,21 @@
1
+ - if flash[:alert].present?
2
+ .alert.alert-danger role="alert"
3
+ = flash[:alert].html_safe
4
+ - elsif flash[:notice].present?
5
+ .alert.alert-success
6
+ = flash[:notice].html_safe
7
+
8
+ .kanban-container
9
+ - column_names = @ar_object.data.keys
10
+ = hidden_field_tag :kanban_column_names, column_names
11
+ - column_names.each do |column_name|
12
+ .kanban-list class="#{column_name}"
13
+ .kanban-list__header
14
+ p = column_name.to_s.titleize
15
+ p.counter = @ar_object.column_count[column_name].to_i
16
+ .cards
17
+ = @ar_object.data[column_name]
18
+
19
+ .pagination-bar.kanban-pagination
20
+ .btn.btn-primary.kanban-show-more data-page=1 Show more
21
+ = render partial: 'cm_admin/main/show_as_drawer'
@@ -0,0 +1,2 @@
1
+ .cm-drawer.batch-order-item.hidden
2
+ .cm-drawer__container
@@ -1,11 +1,11 @@
1
1
  .table-top
2
2
  p.table-top__total-count = "#{humanized_ar_collection_count(@ar_object.pagy.count, @model.ar_model.table_name)}"
3
3
  .table-top__column-action
4
- - if @current_action.card_layout
4
+ - if @current_action.view_type == :card_view
5
5
  .btn-group[role="group" aria-label="Card Toggle"]
6
6
  a.btn.btn-ghost href="#{cm_admin.send("#{@model.name.underscore}_index_path")}?page=#{params[:page] || 1}"
7
7
  i.fa.fa-table
8
- a.btn.btn-ghost href="#{cm_admin.send("#{@model.name.underscore}_index_path")}?page=#{params[:page] || 1}&list_type=card"
8
+ a.btn.btn-ghost href="#{cm_admin.send("#{@model.name.underscore}_index_path")}?page=#{params[:page] || 1}&view_type=card"
9
9
  i.fa.fa-table-cells
10
10
  / button.secondary-btn.column-btn data-bs-target="#columnActionModal" data-bs-toggle="modal"
11
11
  / span
@@ -1,4 +1,5 @@
1
1
 
2
+ = hidden_field_tag :view_type, (@current_action.view_type || params[:view_type])
2
3
  .cm-index-page.cm-page-container
3
4
  .sticky-container.page-top-bar
4
5
  == render 'cm_admin/main/top_navbar'
@@ -8,10 +9,12 @@
8
9
  .cm-index-page__table-container
9
10
  - if @action.partial
10
11
  == render @action.partial
11
- - elsif params[:list_type] == 'card'
12
+ - elsif params[:view_type] == 'card' || @current_action.view_type == :card_view
12
13
  == render 'cm_admin/main/card'
14
+ - elsif params[:view_type] == 'kanban' || @current_action.view_type == :kanban
15
+ == render 'cm_admin/main/kanban'
13
16
  - else
14
17
  == render 'cm_admin/main/table'
15
- = column_pop_up(@model)
16
- = manage_column_pop_up(@model)
18
+ = column_pop_up(@model)
19
+ = manage_column_pop_up(@model)
17
20
 
@@ -47,5 +47,6 @@ html
47
47
  - else
48
48
  = yield
49
49
  = render 'layouts/cm_flash_message'
50
- = render 'layouts/custom_action_modals'
50
+ - unless (@current_action.view_type || params[:view_type])
51
+ = render 'layouts/custom_action_modals'
51
52
 
@@ -6,7 +6,8 @@ module CmAdmin
6
6
  include Actions::Blocks
7
7
  attr_accessor :name, :display_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, :sort_direction, :sort_column, :icon_name, :scopes, :card_layout
9
+ :display_type, :action_type, :redirection_url, :sort_direction, :sort_column, :icon_name, :scopes, :view_type,
10
+ :kanban_attr
10
11
 
11
12
  VALID_SORT_DIRECTION = Set[:asc, :desc].freeze
12
13
 
@@ -39,14 +40,15 @@ module CmAdmin
39
40
  self.verb = :get
40
41
  self.route_type = nil
41
42
  self.display_type = nil
42
- self.card_layout = false
43
+ self.view_type = :table
44
+ self.kanban_attr = {}
43
45
  end
44
46
 
45
- def set_values(page_title, page_description, partial, card_layout=false)
47
+ def set_values(page_title, page_description, partial, view_type=:table)
46
48
  self.page_title = page_title
47
49
  self.page_description = page_description
48
50
  self.partial = partial
49
- self.card_layout = card_layout
51
+ self.view_type = view_type
50
52
  end
51
53
 
52
54
  def controller_action_name
@@ -3,9 +3,9 @@ module CmAdmin
3
3
  module DslMethod
4
4
  extend ActiveSupport::Concern
5
5
 
6
- def cm_index(page_title: nil, page_description: nil, partial: nil, card_layout: false, &block)
6
+ def cm_index(page_title: nil, page_description: nil, partial: nil, view_type: :table, &block)
7
7
  @current_action = CmAdmin::Models::Action.find_by(self, name: 'index')
8
- @current_action.set_values(page_title, page_description, partial, card_layout)
8
+ @current_action.set_values(page_title, page_description, partial, view_type)
9
9
  yield
10
10
  end
11
11
 
@@ -39,6 +39,15 @@ module CmAdmin
39
39
  end
40
40
  end
41
41
 
42
+ def kanban_view(column_name, exclude: [], only: [])
43
+ if @current_action
44
+ @current_action.kanban_attr[:column_name] = column_name
45
+ @current_action.kanban_attr[:exclude] = exclude
46
+ @current_action.kanban_attr[:only] = only
47
+ end
48
+
49
+ end
50
+
42
51
  def scope_list(scopes=[])
43
52
  return unless @current_action
44
53
 
@@ -1,3 +1,3 @@
1
1
  module CmAdmin
2
- VERSION = '1.3.9'
2
+ VERSION = '1.4.0'
3
3
  end
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: 1.3.9
4
+ version: 1.4.0
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: 2023-12-06 00:00:00.000000000 Z
13
+ date: 2023-12-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -197,14 +197,17 @@ files:
197
197
  - app/assets/javascripts/cm_admin/exports.js
198
198
  - app/assets/javascripts/cm_admin/filters.js
199
199
  - app/assets/javascripts/cm_admin/form_validation.js
200
+ - app/assets/javascripts/cm_admin/kanban.js
200
201
  - app/assets/javascripts/cm_admin/quick_search.js
201
202
  - app/assets/javascripts/cm_admin/scaffolds.js
202
203
  - app/assets/javascripts/cm_admin/shared_scaffolds.js
203
204
  - app/assets/stylesheets/cm_admin/base/auth.scss
204
205
  - app/assets/stylesheets/cm_admin/base/cardView.scss
206
+ - app/assets/stylesheets/cm_admin/base/comments.scss
205
207
  - app/assets/stylesheets/cm_admin/base/common.scss
206
208
  - app/assets/stylesheets/cm_admin/base/filters.scss
207
209
  - app/assets/stylesheets/cm_admin/base/form.scss
210
+ - app/assets/stylesheets/cm_admin/base/kanban.scss
208
211
  - app/assets/stylesheets/cm_admin/base/main-nav.scss
209
212
  - app/assets/stylesheets/cm_admin/base/navbar.scss
210
213
  - app/assets/stylesheets/cm_admin/base/quicksearch.scss
@@ -354,10 +357,12 @@ files:
354
357
  - app/views/cm_admin/main/_custom_action_modal_form.html.slim
355
358
  - app/views/cm_admin/main/_drawer.html.slim
356
359
  - app/views/cm_admin/main/_filters.html.slim
360
+ - app/views/cm_admin/main/_kanban.html.slim
357
361
  - app/views/cm_admin/main/_member_custom_action_modal.html.slim
358
362
  - app/views/cm_admin/main/_nested_fields.html.slim
359
363
  - app/views/cm_admin/main/_nested_table_form.html.slim
360
364
  - app/views/cm_admin/main/_nested_table_section.html.slim
365
+ - app/views/cm_admin/main/_show_as_drawer.html.slim
361
366
  - app/views/cm_admin/main/_show_section.html.slim
362
367
  - app/views/cm_admin/main/_table.html.slim
363
368
  - app/views/cm_admin/main/_tabs.html.slim