add category and tag filter

This commit is contained in:
chiu 2020-08-04 10:37:49 +08:00
parent 3b6d3480ed
commit d47b14d2e1
6 changed files with 58 additions and 13 deletions

View File

@ -154,7 +154,7 @@ var Calendar = function(dom){
c.calendar.fullCalendar({
editable: true,
selectable: true,
events: "/admin/calendars/",
events: window.location.href,
eventResize: change_event,
eventDrop: change_event ,
header: false,

View File

@ -4,11 +4,18 @@ class Admin::CalendarsController < OrbitAdminController
def index
@events = []
tags = @module_app.tags
categories = @module_app.categories
@filter_fields = {
:category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}},
:tags=>tags.map{|tag| {:title=>(tag.name.blank? ? " " : tag.name), :id=>tag.id}}
}
if params[:start].present? && params[:end].present?
sdt = Time.at(params[:start].to_i)
edt = Time.at(params[:end].to_i)
@monthly_events = Event.monthly_event(sdt,edt)
@re = Event.recurring_event(sdt,edt)
@monthly_events = Event.monthly_event(sdt,edt).with_categories(filters("category"))
.with_tags(filters("tag"))
@re = Event.with_categories(filters("category")).with_tags(filters("tag")).recurring_event(sdt,edt)
allevents = @monthly_events.inject(@re, :<<)
events = allevents.to_json
events = JSON.parse(events)
@ -17,9 +24,16 @@ class Admin::CalendarsController < OrbitAdminController
@events << e
end
end
respond_to do |format|
format.html # index.html.erb
format.json { render json: @events.to_json }
if request.xhr?
respond_to do |format|
format.html { render :partial => "index" }
format.json { render json: @events.to_json }
end
else
respond_to do |format|
format.html { render "index" }
format.json { render json: @events.to_json }
end
end
end

View File

@ -23,6 +23,14 @@ class Event
validates_presence_of :title, :message => "Please fill the title of the Event"
def self.with_categories(cat_ids=[])
if cat_ids.blank?
self.all
else
type_ids = CalendarType.where(:category_id.in=>cat_ids).pluck(:id)
self.where(:calendar_type_id.in => type_ids)
end
end
def bulletin
Bulletin.find(self.bulletin_id) rescue nil
end

View File

@ -1,3 +1,16 @@
<style type="text/css">
.controls[data-toggle^="buttons-"] input[type="checkbox"] {
margin-left: 0;
margin-top: 0;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
display: block;
opacity: 0;
}
</style>
<% if @event.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@event.errors.count, "error") %> prohibited this event from being saved:</h2>
@ -65,6 +78,12 @@
<%= f.select :calendar_type_id, @categories.collect{|t| [ t.title, t.id ]} %>
</div>
</div>
<!-- Tag Module -->
<div class="control-group">
<label class="control-label"><%= t(:tags) %></label>
<%= select_tags(f, @module_app) %>
</div>
<div class="control-group">
<label class="control-label"></label>
<div class="controls">

View File

@ -0,0 +1,8 @@
<div id="calendar"></div>
<div id="calendar_agenda"></div>
<script type="text/javascript">
var calendar
$(document).ready(function(){
calendar = new Calendar("#calendar");
})
</script>

View File

@ -6,6 +6,7 @@
<%= stylesheet_link_tag "fullcalendar"%>
<%= stylesheet_link_tag "calendar"%>
<%= render_filter @filter_fields, "orbit_calendar" %>
<div id="orbit_calendar" class="month_view">
<div class="clearfix cal-fn">
<div id='sec2'>
@ -46,16 +47,11 @@
</div>
</div>
<div id="view_holder">
<div id="calendar"></div>
<div id="calendar_agenda"></div>
<%= render partial: 'index' %>
</div>
</div>
<div id="event_create_space"></div>
<div id="calendar-loading"></div>
<div class="calendar-form-actions form-actions text-right">
<%= link_to "Add", new_admin_calendar_path, :class => "btn btn-primary", :id=>"create_event_btn", :ref=>"add-btn" %>
</div>
<script type="text/javascript">
var calendar = new Calendar("#calendar");
</script>
</div>