dhatu 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36759d01bacfbc0a7baa19da61d564470b1cd677
4
- data.tar.gz: f373bfbc5d1523cb583eeea9789c6d202f193745
3
+ metadata.gz: 1c25f8018bef9276cfb153a87554a1d79b91574a
4
+ data.tar.gz: eb525b3bcba7b0cb4ed2b7f258ae5b6c648e5592
5
5
  SHA512:
6
- metadata.gz: ae2b6c44eb5d2f2bbad11ca05405670e6171485f86ebeecb482d567443a8516ce8c83659b2e46f3ddf32cb0a101b8e36501bcb58fb4e07c845825749a4b3e1c3
7
- data.tar.gz: 4eb5eef76c579bff8b8efc122c3ed30817e81254c1e4e6357590f6a2531bebfec298815be8dce23b309752fe9955ce807f0e66ef93bc9ca3807ef4601f9dc8c9
6
+ metadata.gz: fcd07dd19aeeff0b0a6915238ca957a8be7b714d239e5c6a0a75f41516f17a240114213a11dec9c927bf6ecb40a72e133e6a3028760e3d9fe0d2debc274d92af
7
+ data.tar.gz: 470e2d222f441ec7847ec6c8846a13ad57676b5e22dabf29eb7a7f63159726b8f9b30f8b8d62e41bd89e054d7115869ba1dbf1c01975d96f3e2094dcfedf476a
@@ -0,0 +1,108 @@
1
+ module Dhatu
2
+ class Dhatu::PromotionAttributesController < ResourceController
3
+
4
+ private
5
+
6
+ def save_resource
7
+ @r_object.values = params[:values].split(",") if params[:values]
8
+ if @r_object.valid?
9
+ @r_object.save
10
+ # get_collections if @resource_options[:layout] = :table
11
+ set_flash_message(I18n.translate("forms.save", item: default_item_name.titleize), :success)
12
+ end
13
+ set_resource_notification(@r_object)
14
+ action_name = params[:action].to_s == "create" ? "new" : "edit"
15
+ url = @r_object.persisted? ? resource_url(@r_object) : nil
16
+ render_or_redirect(@r_object.errors.any?, url, action_name)
17
+ end
18
+
19
+ def get_collections
20
+ @promotion = @r_object.promotion
21
+ @promotion_attributes = @promotion.promotion_attributes.page(@current_page).per(@per_page)
22
+ return true
23
+ end
24
+
25
+ def apply_filters
26
+ @relation = @relation.status(@status) if @status
27
+ @relation = @relation.where("promotion_id = ?", @promotion.id) if @promotion
28
+ @order_by = "priority ASC, name ASC" unless @order_by
29
+ @relation = @relation.order(@order_by)
30
+ end
31
+
32
+ def resource_url(obj)
33
+ url_for(obj)
34
+ end
35
+
36
+ def configure_filter_settings
37
+ @filter_settings = {
38
+ string_filters: [
39
+ { filter_name: :query },
40
+ { filter_name: :status }
41
+ ],
42
+ boolean_filters: [],
43
+ reference_filters: [
44
+ { filter_name: :promotion, filter_class: Dhatu::Promotion }
45
+ ],
46
+ variable_filters: [],
47
+ }
48
+ end
49
+
50
+ def configure_filter_ui_settings
51
+ @filter_ui_settings = {
52
+ status: {
53
+ object_filter: false,
54
+ select_label: "Select Data Type",
55
+ display_hash: Dhatu::PromotionAttribute::DATA_TYPES,
56
+ current_value: @data_type,
57
+ values: Dhatu::PromotionAttribute::DATA_TYPES_REVERSE,
58
+ current_filters: @filters,
59
+ filters_to_remove: [],
60
+ filters_to_add: {},
61
+ url_method_name: 'promotion_attributes_url',
62
+ show_all_filter_on_top: true
63
+ }
64
+ }
65
+ end
66
+
67
+ def resource_controller_configuration
68
+ {
69
+ page_title: "Promotion Attributes",
70
+ js_view_path: "/kuppayam/workflows/parrot",
71
+ view_path: "/dhatu/promotion_attributes",
72
+ collection_name: :promotion_attributes,
73
+ item_name: :promotion_attribute,
74
+ class: Dhatu::PromotionAttribute,
75
+ show_modal_after_create: false,
76
+ show_modal_after_update: false
77
+ }
78
+ end
79
+
80
+ def breadcrumbs_configuration
81
+ {
82
+ heading: "Manage Promotion Attributes",
83
+ icon: "fa-list",
84
+ description: "Listing all Promotion Attributes",
85
+ links: [{name: "Home", link: dashboard_path, icon: 'fa-home'},
86
+ {name: "Manage Promotion Attributes", link: promotion_attributes_path, icon: 'fa-list', active: true}]
87
+ }
88
+ end
89
+
90
+ def permitted_params
91
+ params.require("dhatu/promotion_attribute").permit(:name, :data_type, :promotion_id, :display, :mandatory, :values_string, :priority)
92
+ end
93
+
94
+ def set_navs
95
+ set_nav("dhatu/promotion_attributes")
96
+ end
97
+
98
+ def get_resource
99
+ @r_object = @resource_options[:class].find_by_id(params[:id])
100
+ @promotion = @r_object.promotion
101
+ if params[:action] == "update"
102
+ @r_object.mandatory = false
103
+ @r_object.display = false
104
+ end
105
+ end
106
+
107
+ end
108
+ end
@@ -0,0 +1,87 @@
1
+ module Dhatu
2
+ class PromotionsController < ResourceController
3
+
4
+ private
5
+
6
+ def permitted_params
7
+ params.require("dhatu/promotion").permit(:title, :short_description, :display_name, :display_email, :display_phone, :name_mandatory, :email_mandatory, :phone_mandatory)
8
+ end
9
+
10
+ def get_resource
11
+ @promotion = @r_object = @resource_options[:class].find_by_id(params[:id])
12
+ @promotion_attributes = @promotion.promotion_attributes.page(@current_page).per(@per_page)
13
+ end
14
+
15
+ def get_collections
16
+ @relation = Dhatu::Promotion.includes(:cover_image).where("")
17
+ params[:st] = "published" if params[:st].nil?
18
+ parse_filters
19
+ apply_filters
20
+ @promotions = @r_objects = @relation.page(@current_page).per(@per_page)
21
+ return true
22
+ end
23
+
24
+ def apply_filters
25
+ @relation = @relation.search(@query) if @query
26
+ @relation = @relation.status(@status) if @status
27
+ @relation = @relation.order("priority ASC, title ASC")
28
+ end
29
+
30
+ def configure_filter_settings
31
+ @filter_settings = {
32
+ string_filters: [
33
+ { filter_name: :query },
34
+ { filter_name: :status }
35
+ ],
36
+
37
+ boolean_filters: [],
38
+
39
+ reference_filters: [],
40
+ variable_filters: [],
41
+ }
42
+ end
43
+
44
+ def configure_filter_ui_settings
45
+ @filter_ui_settings = {
46
+ status: {
47
+ object_filter: false,
48
+ select_label: "Select Status",
49
+ display_hash: Dhatu::Promotion::STATUS,
50
+ current_value: @status,
51
+ values: Dhatu::Promotion::STATUS_REVERSE,
52
+ current_filters: @filters,
53
+ filters_to_remove: [],
54
+ filters_to_add: {},
55
+ url_method_name: 'promotions_url',
56
+ show_all_filter_on_top: true
57
+ }
58
+ }
59
+ end
60
+
61
+ def resource_controller_configuration
62
+ {
63
+ page_title: "Promotions",
64
+ js_view_path: "/kuppayam/workflows/peacock",
65
+ view_path: "dhatu/promotions",
66
+ collection_name: :promotions,
67
+ item_name: :promotion,
68
+ class: Dhatu::Promotion
69
+ }
70
+ end
71
+
72
+ def breadcrumbs_configuration
73
+ {
74
+ heading: "Manage Promotions",
75
+ icon: "fa-gift",
76
+ description: "Listing all Promotions",
77
+ links: [{name: "Dashboard", link: breadcrumb_home_path, icon: 'fa-dashboard'},
78
+ {name: "Manage Promotions", link: dhatu.promotions_path, icon: 'fa-gift', active: true}]
79
+ }
80
+ end
81
+
82
+ def set_navs
83
+ set_nav("dhatu/promotions")
84
+ end
85
+
86
+ end
87
+ end
@@ -18,5 +18,10 @@ module Dhatu
18
18
  @categories = Dhatu::Category.where(category_type: category_type).order("priority ASC, name ASC").all
19
19
  end
20
20
 
21
+ def configure_filter_param_mapping
22
+ @filter_param_mapping = default_filter_param_mapping
23
+ @filter_param_mapping[:promotion] = :pr
24
+ end
25
+
21
26
  end
22
27
  end
@@ -0,0 +1,73 @@
1
+ class Dhatu::Promotion < Dhatu::ApplicationRecord
2
+
3
+ # Set Table Name
4
+ self.table_name = "promotions"
5
+
6
+ # Including the State Machine Methods
7
+ include Publishable
8
+ include Featureable
9
+
10
+ # Validations
11
+ validates :title, presence: true, length: {minimum: 5, maximum: 256}, allow_blank: false
12
+ validates :code, length: {minimum: 5, maximum: 64}, allow_blank: true
13
+ validates :short_description, length: {minimum: 3, maximum: 512}, allow_blank: true
14
+
15
+ # Associations
16
+ has_many :promotion_attributes
17
+ has_one :cover_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::CoverImage"
18
+
19
+ # Callbacks
20
+ after_create :generate_and_save_code
21
+
22
+ # ------------------
23
+ # Class Methods
24
+ # ------------------
25
+
26
+ scope :search, lambda { |query| where("LOWER(title) LIKE LOWER('%#{query}%') OR\
27
+ LOWER(code) LIKE LOWER('%#{query}%') OR\
28
+ LOWER(short_description) LIKE LOWER('%#{query}%')")}
29
+
30
+ scope :upcoming, lambda { where("starts_at >= ?", Time.now) }
31
+ scope :past, lambda { where("starts_at < ?", Time.now) }
32
+
33
+ # ------------------
34
+ # Instance variables
35
+ # ------------------
36
+
37
+ # Generic Methods
38
+ # ---------------
39
+ def to_param
40
+ "#{id}-#{title.parameterize[0..32]}"
41
+ end
42
+
43
+ def display_name
44
+ "#{title_was}"
45
+ end
46
+
47
+ def promotion_attributes_with_values
48
+ hsh = {}
49
+ self.promotion_attributes.each do |pa|
50
+ hsh[pa.name] = { values: pa.values, selected: "selected", data_type: pa.data_type, mandatory: pa.mandatory}
51
+ end
52
+ hsh
53
+ end
54
+
55
+ # Permission Methods
56
+ # ------------------
57
+
58
+ def can_be_edited?
59
+ status?(:published) or status?(:unpublished)
60
+ end
61
+
62
+ def can_be_deleted?
63
+ status?(:removed)
64
+ end
65
+
66
+ # Callback Methods
67
+ # -----------------
68
+
69
+ def generate_and_save_code
70
+ self.update_attribute(:code, SecureRandom.hex(4))
71
+ end
72
+
73
+ end
@@ -0,0 +1,62 @@
1
+ class Dhatu::PromotionAttribute < Dhatu::ApplicationRecord
2
+
3
+ # Set Table Name
4
+ self.table_name = "promotion_attributes"
5
+
6
+ # Including the State Machine Methods
7
+ include Publishable
8
+
9
+ attr_accessor :values_string
10
+
11
+ # Data Type could be text, integer, date, list_drop_down (Select from a List), list_radio_button (Choose one) & boolean (Checkbox)
12
+ DATA_TYPES = {"Text" => "text", "Integer" => "integer", "Date" => "date", "List (Drop Down)" => "list_drop_down", "List (Radio Button)" => "list_radio_button", "Boolean (Checkbox)" => "boolean"}
13
+ DATA_TYPES_REVERSE = {"text" => "Text", "integer" => "Integer", "date" => "Date", "list_drop_down" => "List (Drop Down)", "list_radio_button" => "List (Radio Button)", "boolean" => "Boolean (Checkbox)"}
14
+
15
+ # Validations
16
+ validate_string :name, mandatory: true, min_length: 2, max_length: 128, format: /.*/i
17
+ validates :data_type, :presence=> true, :inclusion => {:in => DATA_TYPES.values, :presence_of => :data_type, :message => "%{value} is not a valid data type" }
18
+
19
+ # Associations
20
+ belongs_to :promotion
21
+
22
+ # Serializers
23
+ serialize :values, Array
24
+
25
+ # Callbacks
26
+ before_validation :convert_string_values_to_array
27
+
28
+ # ------------------
29
+ # Instance variables
30
+ # ------------------
31
+
32
+ # Other Methods
33
+ # ------------------
34
+
35
+ def display_name
36
+ self.name
37
+ end
38
+
39
+ def display_data_type
40
+ DATA_TYPES_REVERSE[self.data_type]
41
+ end
42
+
43
+ def convert_string_values_to_array
44
+ self.values = self.values_string.split(",") if self.values_string
45
+ end
46
+
47
+ def set_string_values
48
+ self.values_string = self.values.join(",") if ["list_drop_down", "list_radio_button", ""].include?(self.data_type.to_s)
49
+ end
50
+
51
+ # Permission Methods
52
+ # ------------------
53
+
54
+ def can_be_edited?
55
+ true
56
+ end
57
+
58
+ def can_be_deleted?
59
+ true
60
+ end
61
+
62
+ end
@@ -0,0 +1,56 @@
1
+ class Dhatu::PromotionEnquiry < Dhatu::ApplicationRecord
2
+
3
+ # Set Table Name
4
+ self.table_name = "promotion_enquiries"
5
+
6
+ # Including the State Machine Methods
7
+ include Readable
8
+ include Featureable
9
+
10
+ # Validations
11
+
12
+
13
+ # Associations
14
+ belongs_to :promotion
15
+
16
+ # Serializers
17
+ serialize :additional_attributes, Hash
18
+
19
+ # ------------------
20
+ # Class Methods
21
+ # ------------------
22
+
23
+ scope :search, lambda {|query| where("LOWER(name) LIKE LOWER('%#{query}%') OR\
24
+ LOWER(email) LIKE LOWER('%#{query}%') OR\
25
+ LOWER(mobile) LIKE LOWER('%#{query}%') OR\
26
+ LOWER(message) LIKE LOWER('%#{query}%')")}
27
+
28
+ scope :upcoming, lambda { where("created_at >= ?", Time.now) }
29
+ scope :past, lambda { where("created_at < ?", Time.now) }
30
+
31
+ # ------------------
32
+ # Instance variables
33
+ # ------------------
34
+
35
+ # Generic Methods
36
+ # ---------------
37
+ def to_param
38
+ "#{id}-#{name.parameterize[0..32]}"
39
+ end
40
+
41
+ def display_name
42
+ "#{name_was}"
43
+ end
44
+
45
+ # Permission Methods
46
+ # ------------------
47
+
48
+ def can_be_edited?
49
+ false
50
+ end
51
+
52
+ def can_be_deleted?
53
+ status?(:removed)
54
+ end
55
+
56
+ end
@@ -1,5 +1,17 @@
1
1
  <%
2
2
  dhatu_items = {
3
+ promotions: {
4
+ text: "Promotions",
5
+ icon_class: "fa-gift",
6
+ url: dhatu.promotions_url,
7
+ has_permission: @current_user.has_read_permission?(Dhatu::Promotion)
8
+ },
9
+ promotion_enquiries: {
10
+ text: "Promotional Enquiries",
11
+ icon_class: "linecons-sound",
12
+ url: dhatu.promotion_enquiries_url,
13
+ has_permission: @current_user.has_read_permission?(Dhatu::PromotionEnquiry)
14
+ },
3
15
  bookings: {
4
16
  text: "Bookings",
5
17
  icon_class: "fa-calendar",
@@ -65,6 +77,18 @@
65
77
  icon_class: "fa-sitemap",
66
78
  url: dhatu.categories_url,
67
79
  has_permission: @current_user.has_read_permission?(Dhatu::Category)
80
+ },
81
+ section_types: {
82
+ text: "Section Types",
83
+ icon_class: "fa-reorder",
84
+ url: dhatu.section_types_url,
85
+ has_permission: @current_user.has_read_permission?(Dhatu::SectionType)
86
+ },
87
+ promotion_attributes: {
88
+ text: "Promotion Attributes",
89
+ icon_class: "fa-list",
90
+ url: dhatu.promotion_attributes_url,
91
+ has_permission: @current_user.has_read_permission?(Dhatu::PromotionAttribute)
68
92
  }
69
93
  }
70
94
  %>