Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate event date and time copying #572

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
10 changes: 8 additions & 2 deletions app/assets/javascripts/network_events.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ $(document).on 'ready page:load turbolinks:load', ->
else
$('#order_div').hide()

$('#event-datetimepicker').datetimepicker({
$('#event-datepicker').datetimepicker({
showClear: true,
format: 'YYYY-MM-DD hh:mm a',
format: 'YYYY-MM-DD',
useCurrent: false
})

$('#event-timepicker').datetimepicker({
showClear: true,
format: 'hh:mm a',
useCurrent: false
})

Expand Down
11 changes: 9 additions & 2 deletions app/controllers/network_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def create
# PATCH/PUT /network_events/1
# PATCH/PUT /network_events/1.json
def update
@network_event.scheduled_at = "#{(params[:network_event][:scheduled_at_date] + ' ' + params[:network_event][:scheduled_at_time]).to_datetime}"
respond_to do |format|
if @network_event.update(network_event_params)
format.html { redirect_to @network_event, notice: 'Event was successfully updated.' }
Expand Down Expand Up @@ -100,6 +101,7 @@ def copying_events?
def create_event
@network_event = NetworkEvent.new(network_event_params)
@network_event.user = current_user
@network_event.scheduled_at = "#{(params[:network_event][:scheduled_at_date] + ' ' + params[:network_event][:scheduled_at_time]).to_datetime}"
respond_to do |format|
if @network_event.save
@network_event.network_event_tasks.each do |task|
Expand All @@ -123,13 +125,18 @@ def create_event
end

def override_params

@override_params = network_event_params.select do |key, value|
if value.is_a? Array
value.present? && value.any?(&:present?)
else
value.present?
end
end
if params[:network_event][:scheduled_at_date].present? && params[:network_event][:scheduled_at_time].present?
@override_params[:scheduled_at] = "#{(params[:network_event][:scheduled_at_date] + ' ' + params[:network_event][:scheduled_at_time]).to_datetime}"
end
@override_params
end

# Use callbacks to share common setup or constraints between actions.
Expand All @@ -150,15 +157,15 @@ def filtered_events
else
events = events.default_date_range
end

# Filter events by uncompleted tasks
if params[:common_task_ids].present?
events = events.
joins(:network_event_tasks).
where(network_event_tasks: {common_task_id: params[:common_task_ids],
completed_at: nil})
end

# Filter events by cohort.
if params[:cohort_ids].present?
events = events.
Expand Down
20 changes: 15 additions & 5 deletions app/views/network_events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,21 @@
<div class="form-group">
<%= f.label :scheduled_at, class: "col-sm-2 control-label" %>
<div class="col-sm-10">
<div class="input-group date" id="event-datetimepicker">
<input type='text' class="form-control" name="network_event[scheduled_at]" id="network_event_scheduled_at" value="<%= @network_event.scheduled_at %>" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
<div class="col-sm-6" style="padding-left:0;">
<div class="input-group date" id="event-datepicker">
<input type='text' class="form-control" name="network_event[scheduled_at_date]" id="network_event_scheduled_at" value="<%= @network_event.scheduled_at %>" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
<div class="col-sm-6" style="padding-right: 0;">
<div class="input-group date" id="event-timepicker">
<input type='text' class="form-control" name="network_event[scheduled_at_time]" id="network_event_scheduled_at" value="<%= @network_event.scheduled_at %>" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vishwasja This time value does not seem to be working correctly. An event created with a scheduled time of 11:00am is showing as 8:00pm when edited.
ed_network
ed_network

<span class="input-group-addon">
<span class="glyphicon glyphicon-time"></span>
</span>
</div>
</div>
</div>
</div>
Expand Down
3 changes: 0 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,9 @@
t.datetime "due_date"
t.string "date_modifier"
t.integer "owner_id"
t.bigint "parent_id"
t.index ["common_task_id"], name: "index_network_event_tasks_on_common_task_id"
t.index ["network_event_id"], name: "index_network_event_tasks_on_network_event_id"
t.index ["owner_id"], name: "index_network_event_tasks_on_owner_id"
t.index ["parent_id"], name: "index_network_event_tasks_on_parent_id"
end

create_table "network_events", force: :cascade do |t|
Expand Down Expand Up @@ -315,5 +313,4 @@
t.datetime "updated_at", null: false
end

add_foreign_key "network_event_tasks", "network_event_tasks", column: "parent_id"
end
32 changes: 23 additions & 9 deletions test/controllers/network_events_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class NetworkEventsControllerTest < ActionController::TestCase
assert_pagination assigns(:network_events),
"Events json should be paginated."
end

test "should get index with pagination" do
get :index
assert_pagination assigns(:network_events),
"Events listing should be paginated."
end

test "should get index with default filter" do
get :index
assert_response :success
Expand Down Expand Up @@ -60,7 +60,7 @@ class NetworkEventsControllerTest < ActionController::TestCase
assert assigns(:network_events).present?
assert_equal 3, assigns(:network_events).length
end

test "should get index with uncompleted transportation task" do
get :index, params: {
common_task_ids: [common_tasks(:two).id],
Expand Down Expand Up @@ -106,7 +106,14 @@ class NetworkEventsControllerTest < ActionController::TestCase

test "should create network_event" do
assert_difference('NetworkEvent.count') do
post :create, params: { network_event: { location_id: @network_event.location_id, name: @network_event.name, scheduled_at: @network_event.scheduled_at, program_id: @network_event.program_id } }
post :create, params: { network_event: {
location_id: @network_event.location_id,
name: @network_event.name,
scheduled_at_date: @network_event.scheduled_at.to_date,
scheduled_at_time: @network_event.scheduled_at.to_time,
program_id: @network_event.program_id
}
}
end

assert_redirected_to network_event_path(assigns(:network_event))
Expand All @@ -130,13 +137,13 @@ class NetworkEventsControllerTest < ActionController::TestCase

assert_equal file_data('network_events.csv'), response.body
end

test "should get csv without pagination" do
time = Time.local(2016, 8, 1, 10, 5, 0)
Timecop.travel(time) do
get :index, params: { :format => :csv }
end

refute_pagination assigns(:network_events),
"Events csv export should not be paginated."
end
Expand All @@ -147,7 +154,14 @@ class NetworkEventsControllerTest < ActionController::TestCase
end

test "should update network_event" do
patch :update, params: { id: @network_event, network_event: { location_id: @network_event.location_id, name: @network_event.name, scheduled_at: @network_event.scheduled_at, program_id: @network_event.program_id } }
patch :update, params: { id: @network_event,
network_event: { location_id: @network_event.location_id,
name: @network_event.name,
scheduled_at_date: @network_event.scheduled_at.to_date,
scheduled_at_time: @network_event.scheduled_at.to_time,
program_id: @network_event.program_id
}
}
assert_redirected_to network_event_path(assigns(:network_event))
end

Expand All @@ -157,9 +171,9 @@ class NetworkEventsControllerTest < ActionController::TestCase
end
assert_redirected_to network_events_path
end

test "staff user shouldn't be able to delete network_event" do
user = User.create!(email: '[email protected]', staff: true, password: 'abcdef')
user = User.create!(email: '[email protected]', staff: true, password: 'abcdef')
ability = Ability.new(user)
assert ability.cannot? :delete, @network_event
end
Expand Down