From 2cdb18d338e9762c3235f6740560810b28b55d28 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 9 May 2018 13:56:37 +0630 Subject: [PATCH 1/3] menu cache for menu category --- app/assets/javascripts/addorder.js | 235 +-------------- .../origami/addorders_controller.rb | 19 +- app/views/origami/addorders/detail.html.erb | 285 +++++++++++------- app/views/origami/home/index.html.erb | 1 - app/views/origami/home/show.html.erb | 22 +- config/routes.rb | 2 +- 6 files changed, 201 insertions(+), 363 deletions(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 71cf182e..87124f55 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -2,6 +2,7 @@ $(function() { var role = $('#role').val(); type = window.location.href.indexOf("quick_service"); modify_order = window.location.href.indexOf("modify_order"); + //click menu sidebar menu category $(".product").on("click", function(){ var url = $(this).attr('data-ref'); @@ -101,6 +102,7 @@ $(function() { $('.sub_category_list').addClass("hidden"); var menu_id = $(this).attr("data-id"); var url = "get_menu_category/"+menu_id; + console.log(menu_id); show_menu_item_list(url,menu_id); var sub_id = $(this).attr("data-sub-id"); if (sub_id == "true") { @@ -133,117 +135,6 @@ $(function() { for(var ii in categories) { if (categories[ii]["id"] == menu_id) { var menu_items = categories[ii]["items"]; - // for(var field in menu_items) { - // if (menu_items[field].is_sub_item == false) { - // instances = menu_items[field].instances ; - - // if (!instances.length > 0) { - // swal("Hello Please Check!","Does not have instance item in this menu items ("+ menu_items[field].name+")","warning"); - // } - // if (instances.length > 0) { - // qty = 1; - // options = []; - // price = 0; - - // if (JSON.stringify(menu_items[field].item_sets)!='[]') { - // fa_plus = ''; - // add = ''; - // menu_item_box = 'add_icon'; - // data_target = 'sx_item_set_detailModal'; - // data_modal = 'modal' - // add_icon = "set_item_box" - // code = menu_items[field].code; - // name = menu_items[field].name; - // instances = menu_items[field].instances; - // $(instances).each(function(i){ - // if (instances[i].is_default == true) { - // price = parseFloat(instances[i].price).toFixed(2); - // }else{ - // price = 0; - // } - // }); - // is_available = menu_items[field].is_available ; - // is_on_promotion = 0; - // item_attributes = menu_items[field].attributes; - // promotion_price = menu_items[field].promotion_price; - // }else{ - // fa_plus = 'material-icons'; - // add = 'view_list' - // menu_item_box = 'menu_item_box'; - // data_target = 'sx_item_detailModal'; - // data_modal = '' - // add_icon = "add_icon" - - // $(instances).each(function(i){ - // if (instances[i].is_default === true) { - // code = instances[i].code; - // name = instances[i].name; - // price = parseFloat(instances[i].price).toFixed(2); - // is_available = instances[i].is_available ; - // is_on_promotion = instances[i].is_on_promotion; - // item_attributes = instances[i].values; - // promotion_price = instances[i].promotion_price; - // code = instances[i].code; - // } - // }); - // } - - // if (menu_items[field].image) { - // if (modify_order) { - // image_path = "../../"+menu_items[field].image; - // }else{ - // image_path = menu_items[field].image; - // } - - // }else{ - // if (modify_order) { - // image_path = "../../image/logo.png"; - // }else{ - // image_path = "image/logo.png"; - // } - // } - - // row = '
' - // +'
' - // +'
'+ menu_items[field].name +'
' - // +"
" - // +"" - // +add+ '' - // +'
' - // +'
' - // +"
" - - // // +"
" - // // +"" - // // +"
" - - // +'' - // +'
'; - // $('.menu_items_list').append(row); - // } - // //end instances in menu-items alest 1 instance - // } - // //end is_sub_item false - // } show_menu_list(menu_items); } } @@ -272,118 +163,7 @@ $(function() { var menu_items_list = $('.menu_items_list'); menu_items_list.empty(); menu_items = data.menu_items; -show_menu_list(menu_items); - // for(var field in menu_items) { - // if (menu_items[field].is_sub_item == false) { - // instances = menu_items[field].instances ; - - // if (!instances.length > 0) { - // swal("Hello Please Check!","Does not have instance item in this menu items ("+ menu_items[field].name+")","warning"); - // } - // if (instances.length > 0) { - // qty = 1; - // options = []; - // price = 0; - - // if (JSON.stringify(menu_items[field].item_sets)!='[]') { - // fa_plus = ''; - // add = ''; - // menu_item_box = 'add_icon'; - // data_target = 'sx_item_set_detailModal'; - // data_modal = 'modal' - // add_icon = "set_item_box" - // code = menu_items[field].code; - // name = menu_items[field].name; - // instances = menu_items[field].instances; - // $(instances).each(function(i){ - // if (instances[i].is_default == true) { - // price = parseFloat(instances[i].price).toFixed(2); - // }else{ - // price = 0; - // } - // }); - // is_available = menu_items[field].is_available ; - // is_on_promotion = 0; - // item_attributes = menu_items[field].attributes; - // promotion_price = menu_items[field].promotion_price; - // }else{ - // fa_plus = 'material-icons'; - // add = 'view_list' - // menu_item_box = 'menu_item_box'; - // data_target = 'sx_item_detailModal'; - // data_modal = '' - // add_icon = "add_icon" - - // $(instances).each(function(i){ - // if (instances[i].is_default === true) { - // code = instances[i].code; - // name = instances[i].name; - // price = parseFloat(instances[i].price).toFixed(2); - // is_available = instances[i].is_available ; - // is_on_promotion = instances[i].is_on_promotion; - // item_attributes = instances[i].values; - // promotion_price = instances[i].promotion_price; - // code = instances[i].code; - // } - // }); - // } - - // if (menu_items[field].image) { - // if (modify_order) { - // image_path = "../../"+menu_items[field].image; - // }else{ - // image_path = menu_items[field].image; - // } - - // }else{ - // if (modify_order) { - // image_path = "../../image/logo.png"; - // }else{ - // image_path = "image/logo.png"; - // } - // } - - // row = '
' - // +'
' - // +'
'+ menu_items[field].name +'
' - // +"
" - // +"" - // +add+ '' - // +'
' - // +'
' - // +"
" - - // // +"
" - // // +"" - // // +"
" - - // +'' - // +'
'; - // $('.menu_items_list').append(row); - // } - // //end instances in menu-items alest 1 instance - // } - // //end is_sub_item false - // } + show_menu_list(menu_items); } }); //end Ajax @@ -1376,7 +1156,6 @@ show_menu_list(menu_items); $(".keypress_qty").on('keyup change', function (){ // $('.keypress_qty').keyup(function(e){ - id = $(this).attr('id'); value = $(this).val(); @@ -1429,11 +1208,7 @@ show_menu_list(menu_items); for(var j in menus) { var categories = menus[j]["categories"]; for(var ii in categories) { - if (menu_id == categories[ii]["parent_id"]) { - console.log("parrrrrrrrrrrrrrrrr"); - console.log(categories[ii]["parent_id"]); - console.log(menu_id); - + if (menu_id == categories[ii]["parent_id"]) { $(sub_category).removeClass('hidden'); row = '' ; $(sub_category).append(row); diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index fd298fb3..e4e17328 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -18,14 +18,17 @@ class Origami::AddordersController < BaseOrigamiController if check_mobile @webview = true end - - # if params[:menus].present? - # @menus = JSON.parse(params[:menus], object_class: OpenStruct) - # @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') - # else - @menus = Menu.all - @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') - # end +puts params[:menu] +puts "sssssssssssssssssssssssssss" + if params[:menus].present? + @menus = JSON.parse(params[:menus], object_class: OpenStruct) + @menu = JSON.parse(params[:category], object_class: OpenStruct) + puts @menus.to_json + puts @menu.to_json + else + @menus = Menu.all + @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') + end @table_id = params[:id] @table = DiningFacility.find(@table_id) diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 43ab6db0..46847924 100644 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -5,29 +5,16 @@ <% type = request.path_info.include?('quick_service')%> <% modify_order = request.path_info.include?('modify_order')%> -
+
-
- -
  • +
  • - <%= @menus[0].name %> - -
  • - -
    -
    -
    -
    - +
    + + + + + +
    +
    +
    +
    + + <%end %>
    +
    -
    +
    <% if type && modify_order%>