activeadmin-index_as_calendar 0.0.4 → 0.0.5
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfe4e99ae55c82ac3607db4185506ea1e0d060ed
|
4
|
+
data.tar.gz: 0e22453dd7c9f49886edcc2e4141687ae7297aee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7197efc034ac26d4cec3467f6941fbf224012970d3b6cc69452fd169da0d64a5301402341654dddd7dea188e4fa05ae658f72d0c501e7ffbd46f89cba5e9c10
|
7
|
+
data.tar.gz: 9331019eaed2c8f1ac267d71c60d2dc8c03c0305162552895ee3d81f0e6c589e2e7e3f734aea8a06d8deaea24d940b2ef889c0da4c4da60174312530b5f03553
|
@@ -4,24 +4,12 @@ module ActiveAdmin
|
|
4
4
|
|
5
5
|
def build(page_presenter, collection)
|
6
6
|
add_class "calendar"
|
7
|
-
context = {:page_presenter => page_presenter, :collection => collection}
|
7
|
+
context = {:page_presenter => page_presenter, :collection => collection, :fullCalendarOptions => nil}
|
8
8
|
events = instance_exec(context, &page_presenter.block) unless page_presenter.block.blank?
|
9
9
|
|
10
|
-
# Builds default events array for collection if page_presenter.block returns no data
|
11
|
-
if events.blank?
|
12
|
-
events = collection.map do |item|
|
13
|
-
{
|
14
|
-
id: item.id,
|
15
|
-
title: item.to_s,
|
16
|
-
start: item.created_at.blank? ? Date.today.to_s : item.created_at,
|
17
|
-
url: "#{auto_url_for(item)}"
|
18
|
-
}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
10
|
# Render fullCalendar
|
23
11
|
panel "Calendar", id: "calendar" do
|
24
|
-
render :partial => "calendar", locals: {events: events, options: context[:
|
12
|
+
render :partial => "calendar", locals: {events: events, options: context[:fullCalendarOptions].to_json.html_safe}
|
25
13
|
end
|
26
14
|
end
|
27
15
|
|
@@ -1,5 +1,70 @@
|
|
1
1
|
module ActiveAdminIndexAsCalendar
|
2
2
|
module DSL
|
3
3
|
|
4
|
+
#
|
5
|
+
# Initializes activeadmin index as calendar
|
6
|
+
#
|
7
|
+
def index_as_calendar( options={}, &block )
|
8
|
+
default_options = {
|
9
|
+
:ajax => nil,
|
10
|
+
:model => nil, # Needed only for AJAX
|
11
|
+
:includes => nil, # Eager loading of related models
|
12
|
+
:start_field => :created_at, # Default
|
13
|
+
:end_field => nil,
|
14
|
+
:block => block
|
15
|
+
}
|
16
|
+
options = default_options.deep_merge(options)
|
17
|
+
|
18
|
+
# Defines controller for event_mapping model items to events
|
19
|
+
controller do
|
20
|
+
def event_mapping( items, options )
|
21
|
+
events = items.map do |item|
|
22
|
+
if !options[:block].blank?
|
23
|
+
instance_exec(item, &options[:block])
|
24
|
+
else
|
25
|
+
{
|
26
|
+
:id => item.id,
|
27
|
+
:title => item.to_s,
|
28
|
+
:start => (options[:start_field].blank? or item.send(options[:start_field]).blank?) ? Date.today.to_s : item.send(options[:start_field])
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Setup AJAX
|
36
|
+
if options[:ajax]
|
37
|
+
|
38
|
+
# Setup fullCalendar to use AJAX calls to retrieve event data
|
39
|
+
index as: :calendar do |context|
|
40
|
+
events = {
|
41
|
+
url: "#{collection_path()}/index_as_events.json",
|
42
|
+
type: 'GET',
|
43
|
+
data: params
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
# Defines collection_action to get events data
|
48
|
+
collection_action :index_as_events, :method => :get do
|
49
|
+
items = options[:model] || end_of_association_chain
|
50
|
+
items = items.send(params[:scope]) if params[:scope].present?
|
51
|
+
items = items.includes(options[:includes]) unless options[:includes].blank?
|
52
|
+
items = items.where(options[:start_field] => params[:start].to_date...params[:end].to_date).search(params[:q]).result
|
53
|
+
|
54
|
+
events = event_mapping(items, options)
|
55
|
+
|
56
|
+
respond_to do |format|
|
57
|
+
format.json { render :json => events }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Return events to be used during partial render
|
62
|
+
else
|
63
|
+
index as: :calendar do |context|
|
64
|
+
events = self.controller.event_mapping(context[:collection], options)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
4
69
|
end
|
5
|
-
end
|
70
|
+
end
|