Yet another multicolumn layout - rocks!

20 August, 2007

test.jpgOne chasm between traditional desktop application development and web application development is layout/forms design. It's my constant pain point "I just want a 2 column layout, with a data table in the middle" - many hours later you're still tearing your hair out trying to get it working. It should not be this way (and that's just for prototyping). To get a production tested basic grid/column based layout, that looks reasonable across all browsers and is flexible enough to grow as the app grows - well we all know how much a top notch HTML/CSS wizard is going to cost us right ? Why for every project the same ground of IE hacks and cross browser issues are solved over and over again ? This is half the reason that a sandbox environment like AIR is very appealing - don't deal with it, just get your users to use a standard environment. Enter from stage left, in the why hasn't anyone thought about it before category, are two CSS frameworks that I happened upon on Friday. One called Blueprint which is getting a bit of attention, and one with the rather confusing name of YAML. After seeing all of the examples of YAML, and reviewing the documentation I thought what the heck lets give this a go. YAML is designed for 'standard' column based layouts. It essentially says 'create your main div structure this way, in a predefined page/top nav/nav/main body/footer layout. Then within your main body div, you have options for creating 1-3 columns, and then sub columns within those columns. Whilst I haven't tested the limits, I'm sure so long as it fits within a grid you could use YAML to create it. It's not designed for your highly creative CSS award winning page with umpteem divs all over it - however that audience wouldn't be reading this blog. But for your standard store/blog/cms/other application I can see a huge head start in having the CSS pain removed from your desk. So I put the theory to the test - 4 hours later, I had a couple of layouts running and working across IE 6, IE 7, Firefox, Safari... un-fricking-believable. About 30mins of that 4 hours was the actual job of getting the css setup with the basic grid structure - the rest, playing about with colours, table styles, and creating actual views. I abhor front end CSS work and this abstracted away all of the pain, leaving me just to get on with the job. I'm not going to attempt to write a how-to or tutorial, as the original docs are so good I'll leave well enough alone - the only caveat is don't just blindly copy and paste, make sure you skim read the docs, you need to know where to put the appropriate patch files etc. yaml.jpgBut wait there's more ! Does the thought of manually constructing even your basic div structure seem a little off putting to you. Dirk Jesse (YAML's wizard) has a browser based builder for constructing your layout and outputting the CSS. Very nice indeed !. Just jump to his site and check it out. So you can expect to see some XChain screenshots gracing this site shortly.

Read More

The satisfaction of Rails

13 August, 2007

More work on XChain. In some spare hours on the weekend I implemented the basic structure of price catalogues for products. I can't tell you how long this took when previously doing it in PHP a few years back! (or even worse ASP a few years further back still). I'm sold on BDD, it was so quick to bang this out starting with the spec it first approach, mainly because all you need to do is 'rake spec', and bingo your code is tested... As follows, note code is cut down a little, but you get the picture:
# A product itself does not contain any price information, it has many price's in a 'pricing' model, that is linked
# to price types, eg "Standard Distributor" "Standard Retail"
class Product < ActiveRecord::Base
  has_many :pricings
  has_many :price_types, :through => :pricings
  belongs_to :order_line
end

#The pricing table, not only links to a product and price_type, it also has a discount
#model associated with it..
class Pricing < ActiveRecord::Base
  set_table_name 'pricing'
  belongs_to :product
  belongs_to :price_type
  belongs_to :discount
end

# discount linked to the pricing, and discount tables to enable volume based discounting.
class Discount < ActiveRecord::Base
  has_many :pricing
  has_many :discount_tables, :order => "qty ASC"
  #note that I don't want to do queries every time I ask get_discount, so I just iterate over the
  # tables to find the discount, rather than doing a find each time.
  def get_discount(qty)
    discount_tables.each do |dt|
      return dt.discount_applied if qty <= dt.qty
    end
    return discount_tables.last.discount_applied
  end
end


# In order to calculate price, we need to determine the pricing model for the order (taken from price type)
# then look up the unit price for the product according to the price type
# finally get the discount for the volume at that price type.
class OrderLine < ActiveRecord::Base
  belongs_to :order
  belongs_to :product
  def get_price(price_type)
    @pricing = product.get_pricing(price_type)
    price_as_ordered = ( get_unit_price * qty_ordered ) * get_discount
  end

  protected
  def get_unit_price
    @pricing.get_unit_price()
  end

  def get_discount
    @pricing.discount.get_discount(self.qty_ordered)
  end
You feel like you accomplished something when you sit down to work for a few hours and you get this...
=====================
rowans-computer:~/work/xchain rowan$ rake spec;
(in /Users/rowan/work/xchain)

DiscountTable
- should be valid

Discount when loading existing discount
- should return a max discount of 0.25 for a quantity of 10000
- should return a discount of 1 for a quantity of 20
- should return a discount of 1.5 for a quantity of 5
- should respond to get discount
- should have a discount table
- should have a name
- should belong to a pricing

Order when finding existing order
- should have a customer
- should have a billing address
- should have 3 order lines
- should have a purchase order number
- should have id = 1

Order with a single, invalid order line added
- should after changing the quantity be able to be saved
- should not be able to be saved as it has incorrect quantity
- should calculate to a correct amount

Order new draft order
- should be in the order collection list
- should belong to the correct customer
- should have an associated user who created it
- should be able to have it's address changed
- should be able to be changed to a new status

Order when creating a new order
- should when valid and saved, have one order status history item
- should be able to have an order line added
- should throw an error that it doesn't have line items
- should calculate return 0 dollars
- should have a default price type matching customer price type
- should be able to prefill an address
- should default to draft status
- should be able to instantiate

OrderStatus using a draft order status a super user
- should have a list of all available statuses

OrderStatus using a draft order status with no super user
- should not have all statuses available
- should have a list of next available status, when flow next is false, only including itself and the next higher status

OrderStatus
- should be able to find standard statuses

Product when using Product ID 1
- should be valid

OrderLine with valid order line
- should return correct discount levels (NOT IMPLEMENTED)
- should after changing qty return a different price (NOT IMPLEMENTED)
- should return a price of for x price type and y qty with a discountable price type
- should return a price of for x price type and y qty with a non-discountable price type
- should respond to get_price
- should be valid

Finished in 1.72758 seconds

40 examples, 0 failures, 2 not implemented

Read More

XChain is now running on rSpec

10 August, 2007

Whilst I wait to sort out the UI issues I'm building up the specs' for XChain. I'm using RSpec, so it's a lot more 'self documenting' about what you can expect the application to do. Starting on a fresh project, it's immensely enjoyable to get into the spec -> code -> test -> repeat cycle. If you're at all hesitant about getting into them feel free to go browse the source of my specs. I only spent a little time on it last night but already starting to see progress - a lot of the schema is getting cleaned up as a result of the specs. Here's the doc out put so far (which is about a fraction of what the finished specs will look like !).
Order when creating a new order
- should be able to instantiate
- should default to draft status
- should be able to prefill an address
- should have a default price type matching customer price type
- should calculate return 0 dollars
- should throw an error that it doesn't have line items
- should be able to be edited
- should be able to have an order line added

Order when finding existing order
- should have id = 1
- should have a purchase order number
- should have 3 order lines
- should have a billing address
- should have a customer
To get the specs running. 1. Grab a latest copy of xchain from subversion http://xchain.googlecode.com/svn/trunk/. 2. Dump all databases, then create, and run migrations. 3. Install rpsec using instructions from here 4. Run rake rspec 5. You should (at time of writing) get 13 examples with 1 failure (to work on!) By the end of the weekend there should be a healthy amount of specs in there and fair portion of the model structure of orders, pricing, customer management done. Heres a sample chunk of code
require File.dirname(__FILE__) + '/../spec_helper'


describe Order, "when creating a new order" do
  fixtures :orders, :order_lines, :customers, :addresses, :addressables, :products

  it "should be able to instantiate" do
    @order = Order.new
  end

  it "should default to draft status" do
    @order = Order.new
    @order.order_status_id.should == 10
  end

  it "should be able to prefill an address" do
    @customer = Customer.find(1)
    @order = Order.new
    @order.should respond_to(:prefill_address)
    @order.prefill_address(Customer.find(1))
    @order.billing_address.should eql(@customer.addresses.default_billing.address)
    @order.billing_city.should eql(@customer.addresses.default_billing.city)
    @order.billing_postcode.should eql(@customer.addresses.default_billing.postcode)
    @order.shipping_address.should eql(@customer.addresses.default_shipping.address)
    @order.shipping_city.should eql(@customer.addresses.default_shipping.city)
    @order.shipping_postcode.should eql(@customer.addresses.default_shipping.postcode)
  end
end
If you want an introduction on rspec follow your nose to either the rpsec docs (which are fairly self explanatory) or if you're the visual sort the head on over to http://peepcode.com/products/rspec-basics for a screencast (disclaimer, haven't watched it, but judging on Peepcode's previous efforts it should be good).

Read More

Flex vs HTML part 2 .. how big ?

09 August, 2007

Following on from my post yesterday, I'm asking the question to the community, how big can Flex apps get. This is probably the great unknown which makes it hard (on this project) to commit to Flex. I'm not sure if I'm going to get halfway in and strike performance problems or such like (this is just conjecture!). HTML it's easy, it doesn't matter how big the app gets you're always just firing down a single page to the browser - you just have to manage page load times, this (for myself, and I guess anyone getting into Flex) is a little unknown. The questions are 1) Am I crazy trying to develop 1 person ~15hrs a week, given the apps functional list below, over ~6 months 2) Whats a good example app close to this size. 3) What kind of performance impact (if any) is there in adding each new functional area I've gone through the ever growing showcase and I've picked out the nearest one size wise Studio Cloud, but there doesn't seem to be a lot of them that get this 'big'. Where my definition is big is a large number of different functional areas. To give you an idea of what I'm building.. (this list is about 6mths long I guess, rebuilding an existing system which has approx 2/3 of these functional areas). Note that this is all backed by a Rails backend so all of the order calculations, report calculations will be coming from Rails, this just has to pick it up via AMF/HTTPService/WebORB. I'm a full time Rails web team lead so this is definitely cake for me to do the backend.
[Public View]
- Catalog
  - Product List
  - Product View
     - Application views
  - Cart
  - Checkout
- Orders
- Support
[Backoffice view]
- Dashboard (upcoming orders, tickets, shipments, forecasts)
- Orders
  - List orders (search/archive/filtering)
      - Manufacturing sub view
  - View orders (new/edit/view)
      - Order Sub View (audit trail, shipping status, invoices, order calculation summary)
- Customers
  - List customers (search/archive/filtering)
  - View customers (new/edit/view)
     - Customer Tracking Tickets (list/view/respond)
- Agents/Distributors
  - List
  - View
    - View Customers
    - View Orders
- Reports
  - Reports List
    - Individual report charts ~5-10
    - Individual report list based ~5-10
- Admin
  - Catalog management
     - Categories
     - Products
  - Price List Management
     - List
     - Price matrix update (products vs price category)
  - System Options

I'm sure it's doable, I'm not sure of the workload or performance of this. I'm not overly concerned of the swf file size, what I am concerned with is, will each additional functional area have an impact on overall performance and am I nuts for attempting this as my first large Flex project. I have knocked out a couple of small little Flex projects which weren't too bad, definitely didn't need frameworks for them. Any comments would be appreciated; again all of the source is going to be freely available to everyone by a Mozilla Public License, so anyone who's thinking of going down this path and wants to contribute please feel free to leave a comment (big *hint* if there's any Flex UI designers out there - I would absolutely love to have a clean skin like this one...http://coenraets.org/blog/2007/07/new-version-of-salesbuilder-flex-air-application/ world fame could be yours ;) )

Read More

Flex vs HTML vs Time

08 August, 2007

The old simple triangle of time vs features vs quality has reared it's ugly head again. After one particularly unproductive weekend I've made the decision to place a hold on the Flex interface for XChain, in favour of a raw HTML interface, sprinkled with AJAX. I personally hate the decision, being enamored with Flex, I don't want to make it, but I look at the forward progress I've made in the past couple of weeks and it's been more or less stationary. I'm not trying to deliver the 'richest' interface possible, I'm going to deliver a working application. What impacts my client most, is that they can get their job done. Granted I am learning Flex, and grappling with the Cairngorm/No Cairngorm decision. I decided to go ahead with Cairngorm, particularly after reading the usual tales of woe 'i decided not to use it, now I've rebuild my app and am using it..'. However holy sh-t do you have to produce a lot of code to get things done, okay there are code generators out there, but still. For a pet project this blows out the window the time required to do the job. Sure if this was a 40hr work week project I'd be writing a completely different post right now. This makes me appreciate the elegant nature of Ruby and Rails™ so much more. It just gets out of your way and lets you get on with producing productive code. In just one hour I can do so much more. Firing up textmate I feel instantly at home. Is this a language familiarity thing, or a complexity problem, or am I using the right tool for the right job, within the given constraints, (probably not). I had a big discussion about it with a colleague at work, and it always boils down to trade-offs and compromises, there's no one magic silver bullet (unfortunately). Rails is fantastic at backend work, and helps some with front end work, Flex has some great time savers, rich interface components like datagrid which are cake to wire up and get working - but then you're spending a tonne of time on event and ui management. Where is the happy median ? Something like a super rich js framework ? What am I sorely missing from flex in going 'back' to HTML ? - Rich components - Consistent styling - Reduced network traffic A random thought floating through my mind is to publish it in AIR, that way I can still use an HTML interface hooked up to my back end, but a few extra features that might be very useful (drag n drop support, offline storage). More to investigate.. Grumpy but moving forward.

Read More

XChain - it has a name, license, and home.

23 July, 2007

XchainThe open source Rails/Flex eCommerce application now has a name - XChain - pronounced cross-chain. I had some air travel time over the weekend and put it to good use coming up with a name, the basic premise being that the app should really be classified as a Supply Chain Management system as it deals with a lot more than simply taking peoples money for a product. (Order fulfillment, shipment tracking, eventually CRM and inventory management), and being a cross of two major technologies it seems to fit. Catchy enough and has meaning. Well I think so anyway, others might disagree - (that's what the comments form at the bottom is for...), only downer is XChain.com is taken by some spammer, but I've snapped up .ca and other appropriate domains. To this end, I've also created a home for it here http://code.google.com/p/xchain/ which seems to be a good location for now, satisfies the free and accessible by SVN requirements. Alas no RSS feed, so stick to here for the updates. I'm not a lawyer by any stretch, and have to a little more digging, but have basically decided on a license for it. The Mozilla Public License. My wish is that anyone will be able to use it for either non-commercial and commercial applications free of charge. The only restriction is if you extend it, you have to provide source code back to the community. I believe this is fair enough as you will be getting a tonne of usable code out of the box to start with. I just need to check that we can provide mechanisms for companies sensitive proprietary processes - to make sure these can be wrapped up in a separate lib, or DSL stored in the db, to make sure that doesn't need to be opened up to the outside world. Final decision of the day is to go with Cairngorm - this has more exposure so will hopefully appeal to a wider base of developers, and seems more suited to the scale of this application. I also found a Cairngorm Rails code generator via onrails.org which looks like it will do the business saving time generating code. Right, time to get some code into that repository.... in the meantime feel free to let me know your thoughts on the name and license choice.

Read More

Open Source Rails & Flex eCommerce Application

17 July, 2007

[Announcement] Rowan Hick Consulting, Canada and Ron Hanley of Fastmount LTD, New Zealand are pleased to annouce that their new Rails/Flex/MySQL eCommerce application will be released to the community under an Open Source license. The application, is a successor to a PHP/MySQL based application developed by Rowan Hick and James McGlinn of Nerdsinc Ltd New Zealand.

After nearly 2 years in production, with the advent of Rails, Flex, and the rapidly growing business needs of Fastmount, the current application no longer meets the business needs of Fastmount. We made the decision early this year to re-write a new application and have been developing requirements for the application as well as evaluating technologies. The application is a business to business eCommerce system. Allowing a marine manufacturing company in New Zealand to service it's agents, distributors and customers world wide. The existing application facilitates order management from creation through to shipping tracking, along with customer management and some reporting elements. Why are we open sourcing ? We made the conscious decision that we don't want to sell the application, as such being closed and proprietary we gain no extra business value by keeping it internal (this doesn't preclude the possibility of a hosted version being provided down the road). The application contains no proprietary information to Fastmount Ltd so there is no harm by open sourcing it. Having done a number of eCommerce solutions, the problems faced and solutions tend to be very similar regardless of domain. Thus the app's tend to look very similar. Why reinvent the wheel, over and over again? My personal vision is that a vibrant community will flourish around the application. If it can become an option for people when putting together an eCommerce solution then I would be ecstatic. Currently I haven't seen an active Rails based open source eCommerce engine out there so there's hope that this may become one of many possible standard 'engines' for people to use. Through our background in the widget ordering domain - solving business problems beyond the simple shopping cart such as; multiple price catalogues, multiple currencies, product/ package combination, agents, sales by regions etc - this may help to be a learning tool for those who aren't familiar with the problems at hand, introducing real world solutions beyond your standard learning materials and tutorials. Also by opening it up, and allowing public scrutiny will likely ensure that a higher standard of coding is reached within the application - there's nothing like judgement from your peers to keep those nasty kludges out of the codebase. Why Flex ? Flex, does at first glance seem to be an odd coupling with Rails in terms of philosophical approach. However as a business tool, this application needs to work perfectly, regardless of browser incompatibilities. In my own opinion, the time saved by not having to deal with these issues, along the extra interface richness granted by Flex, warrants the extra upfront time in creating the Flex interface. What should be noted here is this application is more of a business to business, rather than business to consumer type system - thus we can expect less casual browsing/ordering as in the case of a product catalog/ecommerce app versus a very defined business process for ordering. Having said all this, whilst the app has a Flex front end by using some Rails niceties there will be no stopping anyone developing an HTML front end for the app (infact the app will already have some front end work in HTML), so the core Rails application will become the engine and any various front end(s) that may appear can be bolted on. We're using a REST based approach to facilitate this. Roadmap Current Status: Initial development of Order management stories; Creating, editing, listing orders and customers. Evaluating implementing microframeworks for the Flex front end (Cairngorm or Model Glue Flex). Evaluating communication methods (HTTPService, WebOrb, RubyAMF). Release 1: Production ready system - Revamp of existing system in Rails and Flex, all existing user stories maintained. Streamlined order entry system, customer management, order payment processing (via ActiveMerchant), shipment tracking (via UPS). Release 2: Customer Relationship Management enhancements Release 3: Inventory Management, manufacturing enhancements. Community Release The application will be released to the community under an Open Source license (license to be decided), the only caveat from our production system will be licensed assets (such as icons) stripped out for community release with placeholders for people to find their own. I haven't as yet investigated a trac (or trac like system) that's impervious to spam, so for any community members that have any ideas reading this post feel free to drop us a comment. This will likely happen in the next month. Community Contributions We will welcome contributions and commit back into the core, so long as they don't negatively impact core functionality. Process as yet undecided. To ensure fair attribution - the credits page of the app will include your name as a contributor. Whatever license is decided upon will require that any modifications are publicly available as open source. Share and share alike principles. The Name? Undecided - if you want to throw out an idea feel free! Keep Informed All announcements will be made here on this blog. Keep informed, keep your RSS readers locked to http://feeds.feedburner.com/rowanhick In closing I'm personally very excited about providing this to the community and hope good things will come out of it.

Read More

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.