From 94b4454a1b3342b084025220865b69c664578dc9 Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 18 Dec 2013 19:21:39 +0100 Subject: [PATCH] add receive to order screen, and distinguish between finished and closed orders to put it in nicely --- app/controllers/orders_controller.rb | 5 ++- app/views/orders/index.html.haml | 63 ++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 578327f1..0df7eecb 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -8,7 +8,8 @@ class OrdersController < ApplicationController # List orders def index - @open_orders = Order.open + @open_orders = Order.open.includes(:supplier) + @orders_in_progress = Order.finished_not_closed.includes(:supplier) @per_page = 15 if params['sort'] sort = case params['sort'] @@ -20,7 +21,7 @@ class OrdersController < ApplicationController else sort = "ends DESC" end - @orders = Order.page(params[:page]).per(@per_page).order(sort).where("state != 'open'").includes(:supplier) + @orders = Order.closed.page(params[:page]).per(@per_page).includes(:supplier).order(sort) end # Gives a view for the results to a specific order diff --git a/app/views/orders/index.html.haml b/app/views/orders/index.html.haml index 34b428af..6df1d96b 100644 --- a/app/views/orders/index.html.haml +++ b/app/views/orders/index.html.haml @@ -10,8 +10,13 @@ %li= link_to supplier.name, new_order_path(supplier_id: supplier.id), tabindex: -1 .well - %h2= t '.open_orders' - - unless @open_orders.empty? + - if not @open_orders.empty? + %h2= t '.open_orders' + - elsif not @orders_in_progress.empty? + %h2= t '.orders_in_progress' + - else + = t '.no_open_orders' + - unless @open_orders.empty? and @orders_in_progress.empty? %table.table.table-striped %thead %tr @@ -20,23 +25,45 @@ %th= heading_helper Order, :note %th{colspan: "2"} %tbody - - for order in @open_orders - - tr_class = " active" if order.expired? - %tr{class: tr_class} - %td= order.name - %td= format_time(order.ends) unless order.ends.nil? - %td= truncate(order.note) - %td= link_to t('.action_end'), finish_order_path(order), - confirm: t('.confirm_end', order: order.name), method: :post, - class: 'btn btn-small btn-success' + - unless @open_orders.empty? + - for order in @open_orders + - tr_class = " active" if order.expired? + %tr{class: tr_class} + %td= order.name + %td= format_time(order.ends) unless order.ends.nil? + %td= truncate(order.note) + %td= link_to t('.action_end'), finish_order_path(order), + confirm: t('.confirm_end', order: order.name), method: :post, + class: 'btn btn-small btn-success' - %td - = link_to t('ui.show'), order, class: 'btn btn-small' - = link_to t('ui.edit'), edit_order_path(order), class: 'btn btn-small' - = link_to t('ui.delete'), order, confirm: t('.confirm_delete'), method: :delete, - class: 'btn btn-small btn-danger' - - else - = t '.no_open_orders' + %td + = link_to t('ui.edit'), edit_order_path(order), class: 'btn btn-small' + = link_to t('ui.show'), order, class: 'btn btn-small' + = link_to t('ui.delete'), order, confirm: t('.confirm_delete'), method: :delete, + class: 'btn btn-small btn-danger' + + - unless @orders_in_progress.empty? + - unless @open_orders.empty? + %tr + %td{colspan: 6} + %h2= t '.orders_in_progress' + - for order in @orders_in_progress + %tr + %td= order.name + %td= format_time(order.ends) + %td= truncate(order.note) + %td + -# TODO btn-success class only if not received before + = link_to t('.receive'), edit_finance_receive_path(order), class: 'btn btn-small btn-success' + + %td + = link_to t('ui.edit'), '#', class: 'btn btn-small disabled' + = link_to t('ui.show'), order, class: 'btn btn-small' + = link_to t('ui.delete'), order, confirm: t('.confirm_delete'), method: :delete, + class: 'btn btn-small btn-danger' + - else + %tr + %td{colspan: 6}= t '.no_orders_in_progress' %h2= t '.ended_orders' #orders_table