continuing the refactor of the admin section
This commit is contained in:
@@ -2,5 +2,9 @@ module Admin
|
||||
class ApplicationController < ::ApplicationController
|
||||
before_filter :authenticate_administrator!
|
||||
layout 'administrator'
|
||||
private
|
||||
def set_locale
|
||||
I18n.locale = :en
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -44,6 +44,7 @@ module Admin
|
||||
# POST /lists.json
|
||||
def create
|
||||
@list = List.new(params[:list])
|
||||
@list.supplier_id = params[:list][:supplier_id]
|
||||
|
||||
respond_to do |format|
|
||||
if @list.save
|
||||
|
||||
@@ -44,6 +44,7 @@ module Admin
|
||||
# POST /product_categories.json
|
||||
def create
|
||||
@product_category = ProductCategory.new(params[:product_category])
|
||||
@product_category.supplier_id = params[:product_category][:supplier_id]
|
||||
|
||||
respond_to do |format|
|
||||
if @product_category.save
|
||||
|
||||
@@ -44,6 +44,7 @@ module Admin
|
||||
# POST /products.json
|
||||
def create
|
||||
@product = Product.new(params[:product])
|
||||
@product.supplier_id = params[:product][:supplier_id]
|
||||
|
||||
respond_to do |format|
|
||||
if @product.save
|
||||
|
||||
@@ -44,6 +44,7 @@ module Admin
|
||||
# POST /sections.json
|
||||
def create
|
||||
@section = Section.new(params[:section])
|
||||
@section.supplier_id = params[:section][:supplier_id]
|
||||
|
||||
respond_to do |format|
|
||||
if @section.save
|
||||
|
||||
@@ -44,6 +44,7 @@ module Admin
|
||||
# POST /tables.json
|
||||
def create
|
||||
@table = Table.new(params[:table])
|
||||
@table.supplier_id = params[:table][:supplier_id]
|
||||
|
||||
respond_to do |format|
|
||||
if @table.save
|
||||
|
||||
@@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
protect_from_forgery
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def broadcast_user(uid, event, data = {})
|
||||
message = {channel: "/user/#{uid}", data: {event: event, data: data}}
|
||||
|
||||
@@ -2,4 +2,6 @@ class Administrator
|
||||
include SimplyStored::Couch
|
||||
include Devise::Orm::SimplyStored
|
||||
devise :database_authenticatable, :rememberable #, :recoverable, :rememberable, :trackable, :registerable
|
||||
|
||||
view :by_email, key: :email
|
||||
end
|
||||
|
||||
@@ -17,6 +17,8 @@ class List
|
||||
belongs_to :section
|
||||
has_and_belongs_to_many :users, storing_keys: true
|
||||
|
||||
attr_protected :supplier_id
|
||||
|
||||
validates :table_id, presence: true
|
||||
validates :supplier_id, presence: true
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@ class Product
|
||||
belongs_to :supplier # direct! category is an aid
|
||||
has_many :product_orders
|
||||
|
||||
attr_protected :supplier_id
|
||||
|
||||
validates :name, presence: true
|
||||
validates :supplier_id, presence: true
|
||||
validates :price, presence: true, numericality: true
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ class ProductCategory
|
||||
|
||||
attr_protected :supplier_id
|
||||
|
||||
validates :name, presence: true
|
||||
validates :position, numericality: true
|
||||
validates :supplier_id, presence: true
|
||||
|
||||
|
||||
@@ -8,5 +8,6 @@ class ProductOrder
|
||||
belongs_to :order
|
||||
|
||||
view :by_product_id, key: :product_id
|
||||
view :by_order_id, key: :order_id
|
||||
|
||||
end
|
||||
|
||||
@@ -2,7 +2,6 @@ class Section
|
||||
include SimplyStored::Couch
|
||||
|
||||
property :title
|
||||
|
||||
property :path, type: Array, default: []
|
||||
|
||||
belongs_to :supplier
|
||||
@@ -12,6 +11,7 @@ class Section
|
||||
|
||||
attr_protected :supplier_id
|
||||
|
||||
validates :title, presence: true
|
||||
validates :supplier_id, presence: true
|
||||
|
||||
# Probably faster to directly retreive the document and return nil
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
= form_for @list, html: {class: 'form-horizontal' } do |f|
|
||||
= form_for [:admin, @list], html: {class: 'form-horizontal' } do |f|
|
||||
= render 'error_messages', target: @list
|
||||
.control-group class=(@list.errors[:state].any? ? 'error' : nil)
|
||||
= f.label :state, class: 'control-label'
|
||||
@@ -27,4 +27,4 @@
|
||||
.form-actions
|
||||
= f.submit nil, class: 'btn btn-primary'
|
||||
'
|
||||
= link_to t("helpers.links.cancel"), lists_path, class: 'btn'
|
||||
= link_to t("helpers.links.cancel"), admin_lists_path, class: 'btn'
|
||||
@@ -15,18 +15,18 @@ div.page-header= title :index, model_class
|
||||
tbody
|
||||
- @lists.each do |list|
|
||||
tr
|
||||
td= link_to list.state, list
|
||||
td= list.needs_help
|
||||
td= list.needs_payment
|
||||
td= link_to list.state, [:admin, list]
|
||||
td= show_boolean list.needs_help
|
||||
td= show_boolean list.needs_payment
|
||||
td= list.closed_at
|
||||
td= link_to_if list.table.present?, list.table.try(:number), list.table
|
||||
td= link_to_if list.supplier.present?, list.supplier.try(:name), list.supplier
|
||||
td= link_to_if list.table.present?, list.table.try(:number), [:admin, list.table]
|
||||
td= link_to list.supplier.name, [:admin, list.supplier]
|
||||
td=l list.created_at, format: :short
|
||||
td
|
||||
= link_to t('helpers.links.edit'), [:edit, list], class: 'btn btn-mini'
|
||||
= link_to t('helpers.links.edit'), [:edit, :admin, list], class: 'btn btn-mini'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), list, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
|
||||
= link_to t("helpers.links.destroy"), [:admin, list], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
|
||||
- else
|
||||
= no_content_given model_class
|
||||
= link_to t("helpers.links.new"), new_list_path, class: 'btn btn-primary'
|
||||
= link_to t("helpers.links.new"), new_admin_list_path, class: 'btn btn-primary'
|
||||
|
||||
@@ -12,14 +12,13 @@ dl.dl-horizontal.show-list
|
||||
dd= @list.closed_at
|
||||
- if @list.table.present?
|
||||
dt= Table.model_name.human
|
||||
dd= link_to @list.table.number, @list.table
|
||||
- if @list.supplier.present?
|
||||
dt= Supplier.model_name.human
|
||||
dd= link_to @list.supplier.name, @list.supplier
|
||||
dd= link_to @list.table.number, [:admin, @list.table]
|
||||
dt= Supplier.model_name.human
|
||||
dd= link_to @list.supplier.name, [:admin, @list.supplier]
|
||||
|
||||
.form-actions
|
||||
= link_to t("helpers.links.back"), lists_path, class: 'btn'
|
||||
= link_to t("helpers.links.back"), admin_lists_path, class: 'btn'
|
||||
'
|
||||
= link_to t('helpers.links.edit'), [:edit, @list], class: 'btn'
|
||||
= link_to t('helpers.links.edit'), [:edit, :admin, @list], class: 'btn'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), @list, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger'
|
||||
= link_to t("helpers.links.destroy"), [:admin, @list], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger'
|
||||
@@ -0,0 +1,12 @@
|
||||
= simple_form_for [:admin, @product_category], html: {class: 'form-horizontal' } do |f|
|
||||
= render 'error_messages', target: @product_category
|
||||
= f.input :name
|
||||
= f.input :position
|
||||
.control-group class=(@product_category.errors[:supplier_id].any? ? 'error' : nil)
|
||||
= f.label :supplier_id, Supplier.model_name.human, class: 'control-label'
|
||||
.controls
|
||||
= f.collection_select :supplier_id, @suppliers, :id, :name, include_blank: nil
|
||||
.form-actions
|
||||
= f.submit nil, class: 'btn btn-primary'
|
||||
'
|
||||
= link_to t("helpers.links.cancel"), admin_product_categories_path, class: 'btn'
|
||||
+1
-2
@@ -1,4 +1,3 @@
|
||||
- model_class = ProductCategory
|
||||
.page-header
|
||||
= title :edit, model_class
|
||||
.page-header= title :edit, model_class
|
||||
= render 'form'
|
||||
+5
-5
@@ -12,15 +12,15 @@
|
||||
tbody
|
||||
- @product_categories.each do |product_category|
|
||||
tr
|
||||
td.link= link_to product_category.name, product_category
|
||||
td.link= link_to product_category.name, [:admin, product_category]
|
||||
td= product_category.position
|
||||
td.link= link_to_if product_category.supplier.present?, product_category.supplier.try(:name), product_category.supplier
|
||||
td.link= link_to product_category.supplier.name, [:admin, product_category.supplier]
|
||||
td.timestamp=l product_category.created_at, format: :short
|
||||
td.actions
|
||||
= link_to t('helpers.links.edit'), [:edit, product_category], class: 'btn btn-mini'
|
||||
= link_to t('helpers.links.edit'), [:edit, :admin, product_category], class: 'btn btn-mini'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), product_category, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
|
||||
= link_to t("helpers.links.destroy"), [:admin, product_category], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
|
||||
- else
|
||||
= no_content_given model_class
|
||||
= link_to t("helpers.links.new"), new_product_category_path, class: 'btn btn-primary'
|
||||
= link_to t("helpers.links.new"), new_admin_product_category_path, class: 'btn btn-primary'
|
||||
|
||||
+1
-2
@@ -1,4 +1,3 @@
|
||||
- model_class = ProductCategory
|
||||
.page-header
|
||||
= title :new, model_class
|
||||
.page-header= title :new, model_class
|
||||
= render 'form'
|
||||
@@ -0,0 +1,17 @@
|
||||
- model_class = ProductCategory
|
||||
.page-header= title :show, @product_category
|
||||
|
||||
dl.dl-horizontal.show-list
|
||||
dt= model_class.human_attribute_name(:name)
|
||||
dd= @product_category.name
|
||||
dt= model_class.human_attribute_name(:position)
|
||||
dd= @product_category.position
|
||||
dt= Supplier.model_name.human
|
||||
dd= link_to @product_category.supplier.name, [:admin, @product_category.supplier]
|
||||
|
||||
.form-actions
|
||||
= link_to t("helpers.links.back"), admin_product_categories_path, class: 'btn'
|
||||
'
|
||||
= link_to t('helpers.links.edit'), [:edit, :admin, @product_category], class: 'btn'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), [:admin, @product_category], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger'
|
||||
@@ -0,0 +1,11 @@
|
||||
= simple_form_for [:admin, @section], html: {class: 'form-horizontal' } do |f|
|
||||
= render 'error_messages', target: @section
|
||||
= f.input :title
|
||||
.control-group class=(@section.errors[:supplier_id].any? ? 'error' : nil)
|
||||
= f.label :supplier_id, Supplier.model_name.human, class: 'control-label'
|
||||
.controls
|
||||
= f.collection_select :supplier_id, @suppliers, :id, :name, include_blank: nil
|
||||
.form-actions
|
||||
= f.submit nil, class: 'btn btn-primary'
|
||||
'
|
||||
= link_to t("helpers.links.cancel"), admin_sections_path, class: 'btn'
|
||||
@@ -5,22 +5,20 @@
|
||||
thead
|
||||
tr
|
||||
th= model_class.human_attribute_name(:title)
|
||||
th= model_class.human_attribute_name(:path)
|
||||
th= Supplier.model_name.human
|
||||
th= model_class.human_attribute_name(:created_at)
|
||||
th=t 'helpers.actions'
|
||||
tbody
|
||||
- @sections.each do |section|
|
||||
tr
|
||||
td= link_to section.title, section
|
||||
td= section.path
|
||||
td= link_to_if section.supplier.present?, section.supplier.try(:name), section.supplier
|
||||
td= link_to section.title, [:admin, section]
|
||||
td= link_to_if section.supplier.present?, section.supplier.try(:name), [:admin, section.supplier]
|
||||
td=l section.created_at, format: :short
|
||||
td
|
||||
= link_to t('helpers.links.edit'), [:edit, section], class: 'btn btn-mini'
|
||||
= link_to t('helpers.links.edit'), [:edit, :admin, section], class: 'btn btn-mini'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), section, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
|
||||
= link_to t("helpers.links.destroy"), [:admin, section], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
|
||||
- else
|
||||
= no_content_given model_class
|
||||
= link_to t("helpers.links.new"), new_section_path, class: 'btn btn-primary'
|
||||
= link_to t("helpers.links.new"), new_admin_section_path, class: 'btn btn-primary'
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
- model_class = Section
|
||||
.page-header= title :new, model_class
|
||||
= render 'form'
|
||||
@@ -0,0 +1,17 @@
|
||||
- model_class = Section
|
||||
.page-header= title :show, @section
|
||||
|
||||
dl.dl-horizontal.show-list
|
||||
dt= model_class.human_attribute_name(:title)
|
||||
dd= @section.title
|
||||
dt= model_class.human_attribute_name(:path)
|
||||
dd= @section.path.to_json
|
||||
dt= Supplier.model_name.human
|
||||
dd= link_to @section.supplier.name, [:admin, @section.supplier]
|
||||
|
||||
.form-actions
|
||||
= link_to t("helpers.links.back"), admin_sections_path, class: 'btn'
|
||||
'
|
||||
= link_to t('helpers.links.edit'), [:edit, :admin, @section], class: 'btn'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), [:admin, @section], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger'
|
||||
@@ -35,6 +35,7 @@ html lang="en"
|
||||
b.caret
|
||||
ul.child-menu.dropdown-menu
|
||||
li= link_to Supplier.model_name.human_plural, admin_suppliers_path
|
||||
li= link_to Section.model_name.human_plural, admin_sections_path
|
||||
li= link_to Table.model_name.human_plural, admin_tables_path
|
||||
li= link_to Product.model_name.human_plural, admin_products_path
|
||||
li= link_to List.model_name.human_plural, admin_lists_path
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
= form_for @product_category, html: {class: 'form-horizontal' } do |f|
|
||||
= render 'error_messages', target: @product_category
|
||||
.control-group class=(@product_category.errors[:name].any? ? 'error' : nil)
|
||||
= f.label :name, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :name, class: 'text_field'
|
||||
.control-group class=(@product_category.errors[:position].any? ? 'error' : nil)
|
||||
= f.label :position, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :position, class: 'text_field'
|
||||
.control-group class=(@product_category.errors[:supplier_id].any? ? 'error' : nil)
|
||||
= f.label :supplier_id, Supplier.model_name.human, class: 'control-label'
|
||||
.controls
|
||||
= f.collection_select :supplier_id, @suppliers, :id, :name, include_blank: nil
|
||||
.form-actions
|
||||
= f.submit nil, class: 'btn btn-primary'
|
||||
'
|
||||
= link_to t("helpers.links.cancel"), product_categories_path, class: 'btn'
|
||||
@@ -1,18 +0,0 @@
|
||||
- model_class = ProductCategory
|
||||
.page-header= title :show, @product_category
|
||||
|
||||
dl.dl-horizontal.show-list
|
||||
dt= model_class.human_attribute_name(:name)
|
||||
dd= @product_category.name
|
||||
dt= model_class.human_attribute_name(:position)
|
||||
dd= @product_category.position
|
||||
- if @product_category.supplier.present?
|
||||
dt= Supplier.model_name.human
|
||||
dd= link_to @product_category.supplier.name, @product_category.supplier
|
||||
|
||||
.form-actions
|
||||
= link_to t("helpers.links.back"), product_categories_path, class: 'btn'
|
||||
'
|
||||
= link_to t('helpers.links.edit'), [:edit, @product_category], class: 'btn'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), @product_category, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger'
|
||||
@@ -1,18 +0,0 @@
|
||||
= form_for @section, html: {class: 'form-horizontal' } do |f|
|
||||
= render 'error_messages', target: @section
|
||||
.control-group class=(@section.errors[:title].any? ? 'error' : nil)
|
||||
= f.label :title, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :title, class: 'text_field'
|
||||
.control-group class=(@section.errors[:path].any? ? 'error' : nil)
|
||||
= f.label :path, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :path, class: 'text_field'
|
||||
.control-group class=(@section.errors[:supplier_id].any? ? 'error' : nil)
|
||||
= f.label :supplier_id, Supplier.model_name.human, class: 'control-label'
|
||||
.controls
|
||||
= f.collection_select :supplier_id, @suppliers, :id, :name, include_blank: nil
|
||||
.form-actions
|
||||
= f.submit nil, class: 'btn btn-primary'
|
||||
'
|
||||
= link_to t("helpers.links.cancel"), sections_path, class: 'btn'
|
||||
@@ -1,4 +0,0 @@
|
||||
- model_class = Section
|
||||
.page-header
|
||||
= title :new, model_class
|
||||
= render 'form'
|
||||
@@ -1,18 +0,0 @@
|
||||
- model_class = Section
|
||||
.page-header= title :show, @section
|
||||
|
||||
dl.dl-horizontal.show-list
|
||||
dt= model_class.human_attribute_name(:title)
|
||||
dd= @section.title
|
||||
dt= model_class.human_attribute_name(:path)
|
||||
dd= @section.path
|
||||
- if @section.supplier.present?
|
||||
dt= Supplier.model_name.human
|
||||
dd= link_to @section.supplier.name, @section.supplier
|
||||
|
||||
.form-actions
|
||||
= link_to t("helpers.links.back"), sections_path, class: 'btn'
|
||||
'
|
||||
= link_to t('helpers.links.edit'), [:edit, @section], class: 'btn'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), @section, method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger'
|
||||
Reference in New Issue
Block a user