module Dhatu class PricesController < ResourceController private def permitted_params params.require("dhatu/price").permit(:title, :sub_title, :price, :category_id, :priority) end def load_nested_categories # Checkout the method get_category_filters before using this method category_ids = Dhatu::Price.distinct.pluck(:category_id) @categories = Dhatu::Category.where(id: category_ids).to_a @categories.unshift(Dhatu::Category.new(id: -1, name: "All")) end def get_collections # Checkout the method get_category_filters before using this method # load_nested_categories get_category_filters("Dhatu::Price") @relation = Dhatu::Price.where("") parse_filters apply_filters @prices = @r_objects = @relation.page(@current_page).per(@per_page) return true end def apply_filters if @category.is_a?(String) @category = Dhatu::Category.new(id: -2, name: "IS NOT SET") elsif @category.blank? @category = Dhatu::Category.new(id: -1, name: "All") end if @category if @category.persisted? @relation = @relation.where("category_id = ?", @category.id) elsif @category.id == -2 @relation = @relation.where("category_id IS NULL") end end @relation = @relation.search(@query) if @query @relation = @relation.status(@status) if @status @order_by = "priority ASC, title ASC" unless @order_by @relation = @relation.order(@order_by) end def configure_filter_settings @filter_settings = { string_filters: [ { filter_name: :query }, { filter_name: :status } ], boolean_filters: [], reference_filters: [ { filter_name: :category, filter_class: Dhatu::Category }, ], variable_filters: [], } end def configure_filter_ui_settings @filter_ui_settings = { status: { object_filter: false, select_label: "Filter by Status", display_hash: Dhatu::Price::STATUS_REVERSE, current_value: @status, values: Dhatu::Price::STATUS, current_filters: @filters, filters_to_remove: [], filters_to_add: {}, url_method_name: 'prices_url', show_all_filter_on_top: true }, category: { object_filter: true, select_label: 'Select Category Type', current_value: @category, values: Dhatu::Category.filter_by_category_type("Dhatu::Price").published.order("priority ASC, name ASC").all, current_filters: @filters, url_method_name: 'prices_url', filters_to_remove: [], filters_to_add: {}, show_null_filter_on_top: true, show_all_filter_on_top: true } } end def resource_controller_configuration { page_title: "Manage Prices", current_nav: "dhatu/prices", # Resource Names class: Dhatu::Price, collection_name: :prices, item_name: :price, # Conditions get_collections_after_save_resource: false, show_modal_after_create: true, show_modal_after_update: true, # Model Size can be large or generic form_model_size: :generic, show_model_size: :generic, # Layout can be table or feed # table uses html tables and feed uses div based boxes layout: :table, # "/kuppayam/workflows/default" # # Default partial opens show and form partial according to the model_size configuration # It also respect the configuration layout and refresh the page element on both cases - i.e layout is table or feed # "/kuppayam/workflows/peacock" # "/kuppayam/workflows/parrot" # # Peacock & Parrot are old ways of doing things and it respects certail configurations # Peacock opens show and form partials in large popup where as Parrot opens it in small # Both Peacock and Parrot expect table based layout and will reload a single row after create / update # Rendering Paths view_path: "dhatu/prices", js_view_path: "/kuppayam/workflows/default", # Additional Configurations load_wysihtml5: true, tagsinput: false } end def breadcrumbs_configuration { heading: "Manage Prices", icon: "fa-dollar", description: "Listing all Prices", links: [{name: "Dashboard", link: breadcrumb_home_path, icon: 'fa-dashboard'}, {name: "Manage Prices", link: dhatu.prices_path, icon: 'fa-dollar', active: true}] } end def set_navs set_nav("dhatu/price") end end end