Menu Item Groups
This commit is contained in:
3
app/assets/javascripts/api/menu_item_groups.coffee
Normal file
3
app/assets/javascripts/api/menu_item_groups.coffee
Normal file
@@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
3
app/assets/javascripts/settings/menu_item_groups.coffee
Normal file
3
app/assets/javascripts/settings/menu_item_groups.coffee
Normal file
@@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
3
app/assets/stylesheets/api/menu_item_groups.scss
Normal file
3
app/assets/stylesheets/api/menu_item_groups.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the api/menu_item_groups controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
3
app/assets/stylesheets/settings/menu_item_groups.scss
Normal file
3
app/assets/stylesheets/settings/menu_item_groups.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the settings/menu_item_groups controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
8
app/controllers/api/menu_item_groups_controller.rb
Normal file
8
app/controllers/api/menu_item_groups_controller.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class Api::MenuItemGroupsController < ApplicationController
|
||||
def index
|
||||
# @groups = Lookup.where(lookup_type:'menu_item_groups')
|
||||
# @group = @groups.group_by(&:name).map { |k, v| { k => v.map { |l| m = eval(l.value); { m[:menu_category] => m[:menu_items] } }.inject({}) { |h, v| p h; h.merge!(v) } } }
|
||||
@group = Lookup.where(lookup_type:'menu_item_groups')
|
||||
@group = @group.group_by(&:name).map{|k ,v| { k => v.map{|k, v| JSON.parse(k.value)}.inject({}) { |h, v| p h; h.merge!(v) }}}.inject({}) { |h, v| p h; h.merge!(v) }
|
||||
end
|
||||
end
|
||||
59
app/controllers/settings/menu_item_groups_controller.rb
Normal file
59
app/controllers/settings/menu_item_groups_controller.rb
Normal file
@@ -0,0 +1,59 @@
|
||||
class Settings::MenuItemGroupsController < ApplicationController
|
||||
def index
|
||||
@menu_item_group = Lookup.where(lookup_type:'menu_item_groups')
|
||||
end
|
||||
def new
|
||||
@settings_menu_item_group = Lookup.new
|
||||
@menu_category = MenuCategory.order(:name)
|
||||
end
|
||||
def create
|
||||
@settings_menu_item_group = Lookup.new(settings_lookup_params)
|
||||
menu_item = settings_lookup_params[:value].reject(&:empty?)
|
||||
menu_category = "{\"#{settings_lookup_params[:lookup_type]}\" : #{menu_item} }"
|
||||
@settings_menu_item_group.lookup_type = "menu_item_groups"
|
||||
@settings_menu_item_group.value = menu_category
|
||||
respond_to do |format|
|
||||
if @settings_menu_item_group.save
|
||||
format.html { redirect_to settings_menu_item_groups_path, notice: 'Menu item group was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @settings_menu_item_group }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: settings_menu_item_groups_path.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
def edit
|
||||
@settings_menu_item_group = Lookup.find(params[:id])
|
||||
@menu_category = MenuCategory.order(:name)
|
||||
end
|
||||
def update
|
||||
@settings_menu_item_group = Lookup.find(params[:id])
|
||||
menu_item = settings_lookup_params[:value].reject(&:empty?)
|
||||
menu_category = "{\"#{settings_lookup_params[:lookup_type]}\" : #{menu_item} }"
|
||||
@settings_menu_item_group.lookup_type = "menu_item_groups"
|
||||
@settings_menu_item_group.value = menu_category
|
||||
@settings_menu_item_group.name = settings_lookup_params[:name]
|
||||
respond_to do |format|
|
||||
if @settings_menu_item_group.save
|
||||
format.html { redirect_to settings_menu_item_groups_path, notice: 'Menu item group was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @settings_menu_item_group }
|
||||
else
|
||||
format.html { render :edit }
|
||||
format.json { render json: settings_menu_item_groups_path.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
def destroy
|
||||
@settings_menu_item_group = Lookup.find(params[:id])
|
||||
if @settings_menu_item_group.destroy
|
||||
flash[:notice] = 'Menu item group was successfully deleted.'
|
||||
redirect_to settings_menu_item_groups_path
|
||||
end
|
||||
end
|
||||
private
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def settings_lookup_params
|
||||
params.require(:lookup).permit(:lookup_type, :name, :value=>[])
|
||||
end
|
||||
end
|
||||
2
app/helpers/api/menu_item_groups_helper.rb
Normal file
2
app/helpers/api/menu_item_groups_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module Api::MenuItemGroupsHelper
|
||||
end
|
||||
2
app/helpers/settings/menu_item_groups_helper.rb
Normal file
2
app/helpers/settings/menu_item_groups_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module Settings::MenuItemGroupsHelper
|
||||
end
|
||||
2
app/views/api/menu_item_groups/index.json.jbuilder
Normal file
2
app/views/api/menu_item_groups/index.json.jbuilder
Normal file
@@ -0,0 +1,2 @@
|
||||
json.status true
|
||||
json.data @group
|
||||
70
app/views/settings/menu_item_groups/edit.html.erb
Executable file
70
app/views/settings/menu_item_groups/edit.html.erb
Executable file
@@ -0,0 +1,70 @@
|
||||
|
||||
<div class="page-header">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="<%= dashboard_path %>">Home</a></li>
|
||||
<li class="breadcrumb-item"><a href="<%= settings_menu_item_groups_path %>">Menu Item Groups</a></li>
|
||||
<li class="breadcrumb-item active">Edit</li>
|
||||
<span class="float-right">
|
||||
<%= link_to t('.back', :default => t("views.btn.back")), settings_menu_item_groups_path %>
|
||||
</span>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
|
||||
<%= simple_form_for ([:settings,@settings_menu_item_group]), :url => settings_menu_item_group_path do |f| %>
|
||||
<%= f.error_notification %>
|
||||
<div class="form-inputs p-l-15">
|
||||
<%= f.input :name, :label => "Group Name" ,input_html: {required: true }%>
|
||||
<%= f.label :lookup_type, label: 'Menu Category', :class => "control-label string optional bmd-label-static" %>
|
||||
<%= f.collection_select :lookup_type, @menu_category, :id, :name, {}, {:class =>"form-control"} %>
|
||||
<%= f.label :value, label: 'Menu Items', :class => "control-label string optional bmd-label-static" %>
|
||||
<%= f.grouped_collection_select :value, @menu_category, :menu_items, :name, :item_code, :name, {}, {:class =>"form-control", :multiple=> true} %>
|
||||
</div>
|
||||
|
||||
<div class="form-actions p-l-15">
|
||||
<%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
|
||||
<div class="card">
|
||||
<div class="body">
|
||||
<h5><i class="material-icons md-18">view_headline <%= t("views.right_panel.header.page_detail") %></i></h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.detail.lookup") + " " + t("views.right_panel.detail.type_txt") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.lookup_txt") %> <br>
|
||||
2) <%= t("views.right_panel.detail.name") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.name_txt2") %> <br>
|
||||
3) <%= t("views.right_panel.detail.value") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.value_txt") %> <br>
|
||||
</p>
|
||||
<h5><i class="material-icons md-18">list <%= t("views.right_panel.header.button_lists") %></i> </h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.button.submit") %> - <%= t("views.right_panel.detail.submit_btn_txt") %> <%= t("views.right_panel.detail.lookup_txt") %> <br>
|
||||
</p>
|
||||
<h5><i class="material-icons md-18">list <%= t("views.right_panel.header.link_lists") %></i> </h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %> <br>
|
||||
2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.lookup_txt") %> <br>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
jQuery(function() {
|
||||
$( document ).ready(function() {
|
||||
menu_items = $("#lookup_value").html();
|
||||
menu_category = $('#lookup_lookup_type :selected').text();
|
||||
options = $(menu_items).filter('optgroup[label="' + menu_category + '"]').html();
|
||||
$('#lookup_value').html(options)
|
||||
$('#lookup_lookup_type').change(function() {
|
||||
menu_category = $('#lookup_lookup_type :selected').text();
|
||||
options = $(menu_items).filter('optgroup[label="' + menu_category + '"]').html();
|
||||
if (options != null)
|
||||
$('#lookup_value').html(options);
|
||||
else
|
||||
$('#lookup_value').empty();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
69
app/views/settings/menu_item_groups/index.html.erb
Normal file
69
app/views/settings/menu_item_groups/index.html.erb
Normal file
@@ -0,0 +1,69 @@
|
||||
|
||||
<div class="page-header">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="<%= dashboard_path %>">Home</a></li>
|
||||
<li class="breadcrumb-item active">Menu Item Group</li>
|
||||
<span class="float-right">
|
||||
<%= link_to t('.back', :default => t("views.btn.back")), dashboard_path %>
|
||||
</span>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-12 col-md-9 col-lg-9">
|
||||
<div class="m-b-10 clearfix">
|
||||
<%= link_to t("views.btn.new"),new_settings_menu_item_group_path,:class => 'btn btn-primary btn-lg float-right waves-effect"' %>
|
||||
</div>
|
||||
<div class="card" id="custom-slimscroll">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= t("views.right_panel.detail.menu_item_groups") %></th>
|
||||
<th><%= t("views.right_panel.detail.group_names") %></th>
|
||||
<th><%= t("views.right_panel.detail.menu_items") %></th>
|
||||
<th><%= t("views.right_panel.detail.actions") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @menu_item_group.each do |menu_item_group| %>
|
||||
<tr>
|
||||
<td><%= menu_item_group.lookup_type %></td>
|
||||
<td><%= menu_item_group.name %></td>
|
||||
<td><%= menu_item_group.value %></td>
|
||||
<td>
|
||||
<%= link_to t("views.btn.edit"), edit_settings_menu_item_group_path(menu_item_group),:class => 'btn btn-primary btn-sm waves-effect' %>
|
||||
<%= link_to t("views.btn.delete"), settings_menu_item_group_path(menu_item_group),:class => 'btn btn-danger btn-sm waves-effect', method: :delete, data: {confirm: 'Are you sure you want to delete this row ?'} %>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-12 col-md-3 col-lg-3">
|
||||
<div class="card">
|
||||
<div class="body">
|
||||
<h5><i class="material-icons md-18">view_headline <%= t("views.right_panel.header.page_detail") %></i></h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.detail.lookup") + " " + t("views.right_panel.detail.type_txt") %> - <%= t("views.right_panel.detail.type_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.lookup_txt") %> <br>
|
||||
2) <%= t("views.right_panel.detail.name") %> - <%= t("views.right_panel.detail.name_txt2") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.lookup_txt") %> <br>
|
||||
3) <%= t("views.right_panel.detail.value") %> - <%= t("views.right_panel.detail.value_txt") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.lookup_txt") %> <br>
|
||||
4) <%= t("views.right_panel.detail.actions") %> - <%= t("views.right_panel.detail.actions_txt") %> <%= t("views.right_panel.detail.lookup_txt") %> <br>
|
||||
</p>
|
||||
<h5><i class="material-icons md-18">list <%= t("views.right_panel.header.button_lists") %></i> </h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.button.new") %> - <%= t("views.right_panel.detail.new_btn_txt") %> <%= t("views.right_panel.detail.lookup_txt") %> <br>
|
||||
2) <%= t("views.right_panel.button.edit") %> - <%= t("views.right_panel.detail.edit_btn_txt") %> <%= t("views.right_panel.detail.lookup_txt") %> <br>
|
||||
</p>
|
||||
<h5><i class="material-icons md-18">list <%= t("views.right_panel.header.link_lists") %></i> </h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %> <br>
|
||||
2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.dashboard_txt") %> <br>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
70
app/views/settings/menu_item_groups/new.html.erb
Normal file
70
app/views/settings/menu_item_groups/new.html.erb
Normal file
@@ -0,0 +1,70 @@
|
||||
|
||||
<div class="page-header">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="<%= dashboard_path %>">Home</a></li>
|
||||
<li class="breadcrumb-item"><a href="<%= settings_menu_item_groups_path %>">Menu Item Group</a></li>
|
||||
<li class="breadcrumb-item active">New</li>
|
||||
<span class="float-right">
|
||||
<%= link_to t('.back', :default => t("views.btn.back")), settings_menu_item_groups_path %>
|
||||
</span>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
|
||||
<%= simple_form_for ([:settings,@settings_menu_item_group]), :url => settings_menu_item_groups_path do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="form-inputs p-l-15">
|
||||
<%= f.input :name, :label => "Group Name" ,input_html: {required: true }%>
|
||||
<%= f.label :lookup_type, label: 'Menu Category', :class => "control-label string optional bmd-label-static" %>
|
||||
<%= f.collection_select :lookup_type, @menu_category, :id, :name, {}, {:class =>"form-control"} %>
|
||||
<%= f.label :value, label: 'Menu Items', :class => "control-label string optional bmd-label-static" %>
|
||||
<%= f.grouped_collection_select :value, @menu_category, :menu_items, :name, :item_code, :name, {}, {:class =>"form-control", :multiple=> true} %>
|
||||
</div>
|
||||
|
||||
<div class="form-actions p-l-15">
|
||||
<%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
|
||||
<div class="card">
|
||||
<div class="body">
|
||||
<h5><i class="material-icons md-18">view_headline <%= t("views.right_panel.header.page_detail") %></i></h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.detail.lookup") + " " + t("views.right_panel.detail.type_txt") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.lookup_txt") %> <br>
|
||||
2) <%= t("views.right_panel.detail.name") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.name_txt2") %> <br>
|
||||
3) <%= t("views.right_panel.detail.value") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.value_txt") %> <br>
|
||||
</p>
|
||||
<h5><i class="material-icons md-18">list <%= t("views.right_panel.header.button_lists") %></i> </h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.button.submit") %> - <%= t("views.right_panel.detail.submit_btn_txt") %> <%= t("views.right_panel.detail.lookup_txt") %> <br>
|
||||
</p>
|
||||
<h5><i class="material-icons md-18">list <%= t("views.right_panel.header.link_lists") %></i> </h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %> <br>
|
||||
2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.lookup_txt") %> <br>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
jQuery(function() {
|
||||
$( document ).ready(function() {
|
||||
menu_items = $("#lookup_value").html();
|
||||
menu_category = $('#lookup_lookup_type :selected').text();
|
||||
options = $(menu_items).filter('optgroup[label="' + menu_category + '"]').html();
|
||||
$('#lookup_value').html(options)
|
||||
$('#lookup_lookup_type').change(function() {
|
||||
menu_category = $('#lookup_lookup_type :selected').text();
|
||||
options = $(menu_items).filter('optgroup[label="' + menu_category + '"]').html();
|
||||
if (options != null)
|
||||
$('#lookup_value').html(options);
|
||||
else
|
||||
$('#lookup_value').empty();
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -44,7 +44,7 @@ scope "(:locale)", locale: /en|mm/ do
|
||||
#Session Login and Logout
|
||||
post 'authenticate' => "authenticate#create"
|
||||
delete 'authenticate' => "authenticate#destroy"
|
||||
|
||||
get "menu_item_groups" => "menu_item_groups#index"
|
||||
namespace :restaurant do
|
||||
get 'zones' => "zones#index"
|
||||
resources :menu, only: [:index, :show]
|
||||
@@ -461,6 +461,8 @@ scope "(:locale)", locale: /en|mm/ do
|
||||
resources :products
|
||||
#lookups
|
||||
resources :lookups
|
||||
#menu_item_groups
|
||||
resources :menu_item_groups
|
||||
#cashier_terminals
|
||||
resources :cashier_terminals
|
||||
#order_job_stations
|
||||
|
||||
5
spec/controllers/api/menu_item_groups_controller_spec.rb
Normal file
5
spec/controllers/api/menu_item_groups_controller_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Api::MenuItemGroupsController, type: :controller do
|
||||
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Settings::MenuItemGroupsController, type: :controller do
|
||||
|
||||
end
|
||||
15
spec/helpers/api/menu_item_groups_helper_spec.rb
Normal file
15
spec/helpers/api/menu_item_groups_helper_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'rails_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the Api::MenuItemGroupsHelper. For example:
|
||||
#
|
||||
# describe Api::MenuItemGroupsHelper do
|
||||
# describe "string concat" do
|
||||
# it "concats two strings with spaces" do
|
||||
# expect(helper.concat_strings("this","that")).to eq("this that")
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
RSpec.describe Api::MenuItemGroupsHelper, type: :helper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
15
spec/helpers/settings/menu_item_groups_helper_spec.rb
Normal file
15
spec/helpers/settings/menu_item_groups_helper_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'rails_helper'
|
||||
|
||||
# Specs in this file have access to a helper object that includes
|
||||
# the Settings::MenuItemGroupsHelper. For example:
|
||||
#
|
||||
# describe Settings::MenuItemGroupsHelper do
|
||||
# describe "string concat" do
|
||||
# it "concats two strings with spaces" do
|
||||
# expect(helper.concat_strings("this","that")).to eq("this that")
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
RSpec.describe Settings::MenuItemGroupsHelper, type: :helper do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
||||
Reference in New Issue
Block a user