YaleSTC / reservations

Manage equipment loans & reservations. Who can borrow what, for how long?
yalestc.github.io/reservations
MIT License
139 stars 57 forks source link

[Fix Cart Latency] Design specs for newly architected cart functionality #586

Closed squidgetx closed 10 years ago

squidgetx commented 10 years ago

PROPOSED WORKFLOW

squidgetx commented 10 years ago

New Cart Model

require 'spec_helper'

describe Cart do

  context "General validations" do
    it { should validate_presence_of(:reserver_id) }
    it { should validate_presence_of(:start_date) }
    it { should validate_presence_of(:due_date) }
    it "should validate that start date is < due date"
  end

  describe ".initialize" do
    it "has no items"
    it "starts today "
    it "is due tomorrow"
    it "has no reserver"
  end

  describe "Item handling" do
    describe ".add_item" do
      it "adds an item to the array"
    end

    describe ".remove_item" do
      it "removes an item from array"
    end
  end

  describe ".empty?" do
    it "is true when there are no items in cart"
    it "is false when there are some items in cart"
  end

  describe ".prepare_all" do
    it "returns an array of reservations"
    describe "reservations in array returned" do
      it "inherits the cart start date"
      it "inherits the cart end date"
      it "inherits the cart reserver"
      it "inherits the cart items"
    end
  end

  describe ".purge_all" do
    it "empties the cart"
  end

  describe ".models_with_quantities" do
    it "returns a hash of models as keys and quantities as values"
    #do we really need this?
  end

  describe ".check_availability" do
    context "items are good to go" do
      it "sets the flash to success"
    end
    context "items are not good to go" do
      it "sets the flash to detailed error message"
    end
  end
end
squidgetx commented 10 years ago

Current workflow for adding an item to the cart


Proposed Changes

removing is similar

squidgetx commented 10 years ago

Useful links, perhaps

shippy commented 10 years ago

Note of caution: the only thing that ReservationsController#create takes from in-database CartReservations is equipment-model IDs. It takes start date and due date from params[:reservation], which is a hidden field on the submission page. As this is expected behavior in the refactoring, I just wanted to document it here.

squidgetx commented 10 years ago

What if we simply split up the validations between the fields that they're relevant to?

If we remove cart reservations and write custom methods to check these validations (that take arrays of equipment model id's or something as arguments instead of reservation objects) I think it has a chance at being fast enough.

squidgetx commented 10 years ago

Update cart spec and model are on branch 587_fix_cart_latency

squidgetx commented 10 years ago

At this point we should have a working, fast cart that doesn't autosubmit its data fields for validation. Discussion of what options from here should go in #586.

  1. Reimplement choice autovalidations. We may have made things fast enough that the light and important validations run quickly enough to not be a distraction to the user. On date changes, we could run available and blackoutdate validations, and on item adding/removing we could run max_count type validations. This would most closely resemble our current workflow.
  2. Reinvent the reservation confirm page a la #237. We could also add some form of calendar view (#12) so the user has all the information he/she needs to edit their reservation. This would offer the fastest workflow for users: after the user has added all their equipment, they only need to go through typically one more page (the confirm page) to finalize their reservation instead of hunting for valid dates via constant form resubmission.
  3. Add a check-availability button to the cart, by the Make Reservation button. This has the advantage of being quite easy to implement but is probably the least user friendly

These three options really aren't mutually exclusive, though I think that if we implement 2, both 1 and 3 are unnecessary, and similarly if we implement 1 we don't need 3 (and vice versa)

Discuss here. (@shippy, @dgoerger @mnquintana @orenyk ).

squidgetx commented 10 years ago

SOME BENCHMARKING

using some js timestamps created at points when the cart would pause and resume we can actually benchmark which parts of the cart updating takes so long (ActiveAdmin routes disabled)

(note in the above scenarios the user has 0 other reservations)

squidgetx commented 10 years ago

Are front end validations possible?

squidgetx commented 10 years ago

Since we made such great progress in #628, I don't think we need to implement such drastic changes. After we finish #574 and #573 I think we'll be good to go on the cart.