diff --git a/app/assets/javascripts/network_events.coffee b/app/assets/javascripts/network_events.coffee index 7a334d2..1527528 100644 --- a/app/assets/javascripts/network_events.coffee +++ b/app/assets/javascripts/network_events.coffee @@ -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 }) diff --git a/app/controllers/network_events_controller.rb b/app/controllers/network_events_controller.rb index 0dc7d86..01c2edf 100644 --- a/app/controllers/network_events_controller.rb +++ b/app/controllers/network_events_controller.rb @@ -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.' } @@ -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| @@ -123,6 +125,7 @@ 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?) @@ -130,6 +133,10 @@ def override_params 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. @@ -150,7 +157,7 @@ def filtered_events else events = events.default_date_range end - + # Filter events by uncompleted tasks if params[:common_task_ids].present? events = events. @@ -158,7 +165,7 @@ def filtered_events 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. diff --git a/app/views/network_events/_form.html.erb b/app/views/network_events/_form.html.erb index f4bfb8a..e05eefc 100644 --- a/app/views/network_events/_form.html.erb +++ b/app/views/network_events/_form.html.erb @@ -154,11 +154,21 @@
<%= f.label :scheduled_at, class: "col-sm-2 control-label" %>
-
- - - - +
+
+ + + + +
+
+
+
+ + + + +
diff --git a/db/schema.rb b/db/schema.rb index 5187df4..0e4d279 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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| @@ -315,5 +313,4 @@ t.datetime "updated_at", null: false end - add_foreign_key "network_event_tasks", "network_event_tasks", column: "parent_id" end diff --git a/test/controllers/network_events_controller_test.rb b/test/controllers/network_events_controller_test.rb index 3bfd121..a61d6e2 100644 --- a/test/controllers/network_events_controller_test.rb +++ b/test/controllers/network_events_controller_test.rb @@ -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 @@ -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], @@ -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)) @@ -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 @@ -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 @@ -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: 'test@example.com', staff: true, password: 'abcdef') + user = User.create!(email: 'test@example.com', staff: true, password: 'abcdef') ability = Ability.new(user) assert ability.cannot? :delete, @network_event end