Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/views/faalis/dashboard/resource/show.html.slim
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.nav-tabs-custom
ul.nav.nav-tabs
- @reflection_controller.each do |mdl|
li = link_to(t(mdl), controller: mdl, "#{controller_name.singularize}_id" => @resource.id)

.row
.col-sm-12.col-lg-12
.box.box-primary
Expand Down
4 changes: 3 additions & 1 deletion config/locales/faalis.en.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
en:
dashboard: Dashboard
index: index
faalis:
confirm_password: Password Confirmation
forgot_your_password: Forget your password
Expand Down Expand Up @@ -58,7 +60,7 @@ en:

permission:
permissions: Permissions

dashboard:
users: Users
groups: Groups
Expand Down
13 changes: 11 additions & 2 deletions lib/faalis/dashboard/sections/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ def _engine

private

def filter_params
params_keys = Set.new(params).map(&:to_sym)
fields = model.columns_hash.keys.map(&:to_sym)
params_keys & fields
end

def _route_name
nil
end
Expand Down Expand Up @@ -101,15 +107,18 @@ def _show_route(id)

def _edit_route(id)
if respond_to? :edit
filter_params_hash = Hash[filter_params.map{|key| [key, params[key]]}]
url_for(controller: params[:controller],
action: :edit,
id: id)
id: id,
**filter_params_hash)
end
end

def _new_route
if respond_to? :new
url_for(controller: params[:controller], action: :new)
filter_params_hash = Hash[filter_params.map{|key| [key, params[key]]}]
url_for(controller: params[:controller], action: :new, **filter_params_hash)
end
end

Expand Down
1 change: 0 additions & 1 deletion lib/faalis/dashboard/sections/resource_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def update
# The actual action method for creating new resource.
def create
authorize model

@resource = model.new(creation_params)
@resource.assign_attributes(**reflections_hash) unless reflections_hash.nil?

Expand Down
13 changes: 13 additions & 0 deletions lib/faalis/dashboard/sections/resource_show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ def show

@resource_title = t(_resource_title.singularize)

# list all the model names that have :has_many relation
reflection_models = model.reflect_on_all_associations(:has_many).
map(&:class_name)

@reflection_controller = []

if reflection_models.length > 0
reflection_models.each do |mdl|
@reflection_controller.push mdl.tableize.split('/')[-1]
end
end


show_hook(@resource)

return if _override_views.include? :show
Expand Down
79 changes: 49 additions & 30 deletions lib/faalis/dashboard/sections/resources_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,57 +20,76 @@ def index

protected

# Fetch all or part of the corresponding resource
# from data base with respect to `scope` DSL.
#
# The important thing here is that by using `scope`
# DSL this method will chain the resulted scope
# with other scopes like `page` and `policy_scope`
def fetch_index_objects
# Fetch all or part of the corresponding resource
# from data base with respect to `scope` DSL.
#
# The important thing here is that by using `scope`
# DSL this method will chain the resulted scope
# with other scopes like `page` and `policy_scope`
def fetch_index_all_objects
scope = index_properties.default_scope
puts "<<<<<<<" * 100, scope
# If user provided an scope for `index` section.
if !scope.nil?

# If user provided an scope for `index` section.

if scope.respond_to? :call
# If scope provided by a block
scope = scope.call
else
# If scope provided by a symbol
# which should be a method name
scope = self.send(scope)
end
# If user provided an scope for `index` section.

if scope.respond_to? :call
# If scope provided by a block
scope = scope.call
else
scope = model.all
#scope = ApplicationPolicy::Scope.new(current_user, model.all).resolve
# If scope provided by a symbol
# which should be a method name
scope = self.send(scope)
end

scope = scope.order('created_at DESC').page(params[:page])
policy_scope(scope)

else
scope = model.all
#scope = ApplicationPolicy::Scope.new(current_user, model.all).resolve
end

def index_properties
Faalis::Dashboard::DSL::Index.new(model)
scope = scope.order('created_at DESC').page(params[:page])
policy_scope(scope)

end

def fetch_index_filtered_objects(filter_params)
items = fetch_index_all_objects
filter_params.each do |v|
items = items.where(v => params[v])
end
items
end

def index_properties
Faalis::Dashboard::DSL::Index.new(model)
end

private

def fetch_and_set_all
result = fetch_index_objects
# rename ---- fetch_all_index_objects

# Check if the params have common with model fields
# pass it to the `fetch_index_filtered_objects` to
# filtering the query. it used for nested sections
# and search result

if filter_params.empty?
result = fetch_index_all_objects
else
result = fetch_index_filtered_objects(filter_params)
end
instance_variable_set("@#{plural_name}", result)

@index_fields = index_properties.fields
@resources = result
end

# You can override this method to change the behaviour of `index`
# action
def index_hook(resources)
# You can override this method to change the behaviour of `index`
# action
def index_hook(resources)

end
end
# The actual DSL for index ages
module ClassMethods

Expand Down