Skip to content

Commit

Permalink
update drop event
Browse files Browse the repository at this point in the history
  • Loading branch information
vf-faizan committed Jul 13, 2018
1 parent 63d224c commit 1f7680a
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ gem 'figaro'
gem 'momentjs-rails'
gem 'bootstrap3-datetimepicker-rails'
gem "paranoia", github: "rubysherpas/paranoia", branch: "rails5"
gem 'pry-rails', :group => :development
# gem 'pry-rails', :group => :development
gem 'jquery-datetimepicker-rails'
gem 'draper'
# gem 'jquery-rails' already added above
Expand Down Expand Up @@ -79,6 +79,8 @@ group :development do
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'sqlite3'
gem 'rails_db'
end

gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Expand Down
30 changes: 27 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (>= 2.0, < 4.0)
codemirror-rails (5.16.0)
railties (>= 3.0, < 6.0)
coderay (1.1.2)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -258,6 +260,18 @@ GEM
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
kaminari (1.1.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.1.1)
kaminari-activerecord (= 1.1.1)
kaminari-core (= 1.1.1)
kaminari-actionview (1.1.1)
actionview
kaminari-core (= 1.1.1)
kaminari-activerecord (1.1.1)
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
launchy (2.4.3)
addressable (~> 2.3)
letter_opener (1.5.0)
Expand Down Expand Up @@ -318,8 +332,6 @@ GEM
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-rails (0.3.6)
pry (>= 0.10.4)
public_suffix (3.0.1)
puma (3.11.0)
rack (2.0.3)
Expand Down Expand Up @@ -349,6 +361,13 @@ GEM
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_db (2.0.2)
codemirror-rails
kaminari
rails (>= 5.0.0)
ransack
simple_form
terminal-table
rails_serve_static_assets (0.0.5)
rails_stdout_logging (0.0.5)
railties (5.0.6)
Expand Down Expand Up @@ -435,10 +454,13 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
sshkit (1.15.1)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
temple (0.8.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
therubyracer (0.12.3)
libv8 (~> 3.16.14.15)
ref
Expand All @@ -458,6 +480,7 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.7.4)
unicode-display_width (1.4.0)
validates_timeliness (4.0.2)
timeliness (~> 0.3.7)
vcr (4.0.0)
Expand Down Expand Up @@ -537,11 +560,11 @@ DEPENDENCIES
paranoia!
pg
premailer-rails
pry-rails
puma (~> 3.0)
rails (~> 5.0.3)
rails-controller-testing
rails_12factor
rails_db
ransack
rdiscount
recurring_select!
Expand All @@ -554,6 +577,7 @@ DEPENDENCIES
spring-commands-cucumber
spring-commands-rspec
spring-watcher-listen (~> 2.0.0)
sqlite3
therubyracer
time_difference
turbolinks (~> 5.x)
Expand Down
30 changes: 30 additions & 0 deletions app/assets/javascripts/admin_full_calender.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,36 @@ var neonCalendar2 = neonCalendar2 || {};
});
$('#updateThisAndFutureChildern').click(function (){
console.log("Update this Event and future only.");
var event_data = {
event: {
id: event.id,
start: moment(event.start).format("DD-MM-YYYY HH:mm"),
end: moment(event.end).format("DD-MM-YYYY HH:mm")
}
};
$.ajax({
url: " /admin/events/"+ event.id +"/update_all_future_events",
dataType: 'json',
data: event_data,
type: 'POST',
success: function(doc) {
console.log(JSON.stringify(doc , null ,2 ));
console.log(doc['success']);
if(doc.success){
$("#modal-4").modal('hide');
flash_success(doc.message);
updateEvent(doc.data);
}else{
revertFunc();
$.each(doc.errors, function (i, error) {
flash_error(error);
});
}
},
error: function() {
revertFunc();
}
});
});

$('#updateOnlyThisJob').click(function (){
Expand Down
96 changes: 94 additions & 2 deletions app/controllers/backend/admin/events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Backend::Admin::EventsController < Backend::Admin::AdminsController
# respond_to :json , :js , :html
before_action :set_event, only: [:show, :edit, :update, :destroy]
before_action :set_event, only: [:show, :edit, :update, :destroy, :update_all_future_events]
before_action :new_resource , only: [:new]
def index
@calendar_events = Event.includes(:employee , :customer).where(start: params[:start]..params[:end])
Expand Down Expand Up @@ -54,6 +54,98 @@ def update
end
end

def diffdate_in_days(start_date, end_date)
a=end_date.strftime("%Y-%m-%d")
b=start_date.strftime("%Y-%m-%d")
a=Date.parse(a)
b=Date.parse(b)
days=(a-b).to_i
return days
end
# def check_event_already_exist_future_day? all_events, start_date
#
# end_date = all_events.last.end
# diff_date = diffdate_in_days start_date, end_date
# puts "Start Date is #{start_date}"
# puts "End date is #{end_date}"
# puts "Diff date is #{diff_date}"
# i = 1
#
# while start_date <= end_date do
# start_date = start_date + (i * diff_date).day
# return true if all_events.where("parent_id = #{@event.parent_id} and events.start >= '#{start_date.beginning_of_day.strftime("%Y-%m-%d %I:%M%P")}' and events.end <= '#{start_date.end_of_day.strftime("%Y-%m-%d %I:%M%P")}'").present?
# puts("Inside the loop i = #{i}" )
# i = i + 1
# end
# return false
# end

def update_all_future_events
if @event.recurring?
if event_params[:start]
start_date = @event.start
all_events = Event.where("events.parent_id = #{@event.parent_id} and events.start >= '#{start_date.strftime("%Y-%m-%d %I:%M%P")}'").order(start: :asc)
if all_events.empty?
update
else
end_date = all_events.last.end
diff_date = diffdate_in_days start_date, Time.zone.parse(event_params[:end]).to_date
diff_date = diff_date * -1 if diff_date < 0
puts "Start Date is #{start_date}"
puts "End date is #{end_date}"
puts "Diff date is #{diff_date}"
i = 1
is_terminate = true
while (is_terminate and diff_date > 0 and start_date <= end_date) do
start_date = start_date + 7.day + diff_date.day
puts("Inside the loop i = #{i}" )
puts "Start Date is #{start_date}"
# start_date = start_date + (i * diff_date).day
if Event.where("parent_id = #{@event.parent_id} and events.start >= '#{start_date.beginning_of_day.strftime("%Y-%m-%d %I:%M%P")}' and events.end <= '#{start_date.end_of_day.strftime("%Y-%m-%d %I:%M%P")}'").present?
is_terminate = false
puts "terminating on #{start_date}"
end
i = i + 1
end
if not is_terminate
puts "Event Exist"
else
puts "Event Not Exist"
end

# if check_event_already_exist_future_day? all_events, start_date
# puts "Event Exist"
# else
# puts "Event Not Exist"
# end
end
end
end

#
# else
# if @event.update(event_params)
# respond_to do |format|
# flash.now[:success] = "Successfully Updated."
# format.js do
# if @event.recurring?
# @calendar_events = [@event] + @event.children
# else
# @calendar_events = [@event]
# end
# end
# format.json { render json: {success: true , data: render_to_string( template: 'backend/admin/events/show.json.jbuilder', event: @event) , message: "Successfully Updated."} }
# end
# else
# respond_to do |format|
# flash.now[:errors] = @event.errors.full_messages
# format.js {}
# format.json { render json: {success: false , errors: @event.errors.full_messages} }
# end
# end
# end

end
def destroy
@event.destroy
end
Expand All @@ -65,7 +157,7 @@ def new_resource
end

def set_event
@event = Event.find_by_id(params[:id])
@event = Event.find_by_id(params[:id] || params[:event_id])
end

def event_params
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
end
resources :employee_invoices
resources :customer_invoices
resources :events
resources :events do
post "update_all_future_events", as: :update_all_future_events
end
resources :jobs do
match :search, to: 'jobs#index', via: [:post , :get ], on: :collection
end
Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
Admin.create!(first_name: "Joanna" , last_name: "Cleaning" , email:'[email protected]',password:'password',password_confirmation:'password',role:'owner')
Admin.create!(username: 'joanna' , email:'[email protected]',password:'password',password_confirmation:'password', role:'owner')

0 comments on commit 1f7680a

Please sign in to comment.