update menu import/export ui

This commit is contained in:
Aung Myo
2018-03-21 10:30:28 +06:30
parent f51d193d47
commit 9db3ec07cc
4 changed files with 20 additions and 11 deletions

View File

@@ -72,8 +72,11 @@ class Settings::MenusController < ApplicationController
end
def import
Menu.import(params[:file])
redirect_to settings_menus_path, notice: "imported"
if params[:file]
Menu.import(params[:file])
redirect_to settings_menus_path, notice: "Menu was successfully Imported"
end
end
private

View File

@@ -7,12 +7,6 @@
</span>
</ol>
</div>
<h4>Import</h4>
<%= form_tag import_settings_menus_path, multipart:true do%>
<%=file_field_tag :file%>
<%=submit_tag "Import CSV"%>
<%end%>
<%= link_to "Export users as spreadsheet", settings_menus_path(format: "xlsx") %>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
<br><br>
@@ -30,7 +24,16 @@
</div>
<div class="col-xs-12 col-sm-12 col-md-7 col-lg-7">
<div class="m-b-10 clearfix">
<div class="float-left">
<%= form_tag import_settings_menus_path,class:"col-md-", multipart:true do%>
<%=file_field_tag :file, :class => "img-thumbnail col-md-7" %>
<%=submit_tag "Import",:class => 'btn btn-primary btn-lg waves-effect' %>
<%end%>
</div>
<%= link_to t("views.btn.new"),new_settings_menu_path,:class => 'btn btn-primary btn-lg float-right waves-effect"' %>
<%= link_to "Export", settings_menus_path(format: "xlsx"),:class => 'btn btn-info btn-lg waves-effect float-right m-r-10' %>
</div>
<div class="card">
<table class="table table-striped">

View File

@@ -1,6 +1,7 @@
wb = xlsx_package.workbook
wb.styles do |s|
date = s.add_style(:format_code => "yyyy-mm-dd", :border => Axlsx::STYLE_THIN_BORDER)
time_format = wb.styles.add_style :format_code => 'hh:mm:ss'
wrap_text = s.add_style :sz => 11,
:alignment => { :horizontal => :left,:vertical => :center ,
:wrap_text => true}
@@ -43,7 +44,7 @@ wb.styles do |s|
wb.add_worksheet(name: "Menu") do |sheet|
sheet.add_row %w( id name is_active valid_days valid_time_from valid_time_to created_by ), :style=>header_text
@settings_menus.each do |menu|
sheet.add_row [ menu.id, menu.name, menu.is_active, menu.valid_days, menu.valid_time_from,menu.valid_time_to, menu.created_by], :style=>[wrap_text]
sheet.add_row [ menu.id, menu.name, menu.is_active, menu.valid_days, menu.valid_time_from,menu.valid_time_to, menu.created_by], :style=>[wrap_text,time_format]
end
end

View File

@@ -293,7 +293,9 @@ scope "(:locale)", locale: /en|mm/ do
resources :employees
#menu
resources :menus do
#menu_categories
collection do
post :import
end
resources :menu_categories, only: [:new, :create, :edit, :delete]
end