Commit 55e9704c by Tấn Trần Thanh

change logic ajax

parent e4270585
Pipeline #1574 failed with stages
in 0 seconds
...@@ -17,9 +17,7 @@ class WorkflowReportController < ApplicationController ...@@ -17,9 +17,7 @@ class WorkflowReportController < ApplicationController
result = fetch_data(project_ids, params[:year].to_i, params[:month].to_i, column_number: thead.size) result = fetch_data(project_ids, params[:year].to_i, params[:month].to_i, column_number: thead.size)
respond_to do |format| respond_to do |format|
format.html do format.js { render 'build_table', locals: {result: result, thead: thead} }
render partial: 'table_workflow_report', layout: false, locals: { result: result, thead: thead }
end
end end
end end
......
$("#data_workflow").html("<%= escape_javascript(render partial: 'table_workflow_report', locals: { result: result, thead: thead } ) %>")
<% if result.present? %>
$('button.export-button').removeClass('d-none')
<% else %>
$('button.export-button').addClass('d-none')
<% end %>
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
fieldset.box.tabular fieldset.box.tabular
legend legend
| EXPORT WORKFLOW | EXPORT WORKFLOW
= form_tag do = form_tag workflow_report_export_path, method: :get, remote: true, id: 'export-form' do
p p
= label :month, 'Month' = label :month, 'Month'
= select_tag :month ,options_for_select(1..12, Time.now.month),{ prompt: "Select month" } = select_tag :month,options_for_select(1..12, Time.now.month), { prompt: "Select month" }
p p
= label :year, 'Year' = label :year, 'Year'
= select_tag :year ,options_for_select((Time.now.year - 5)..(Time.now.year + 1), Time.now.year),{ prompt: "Select year" } = select_tag :year,options_for_select((Time.now.year - 5)..(Time.now.year + 1), Time.now.year), { prompt: "Select year" }
p p
= label :team, 'Team' = label :team, 'Team'
= select_tag :team, options_for_select(@team_options), { prompt: "Select team" } = select_tag :team, options_for_select(@team_options), { prompt: "Select team" }
......
window.addEventListener('load', function () { window.addEventListener('load', function () {
$('#export').click(function (event) { $('#export-form').submit(function () {
event.preventDefault()
const month = $('#month').val() const month = $('#month').val()
const year = $('#year').val() const year = $('#year').val()
const team = $('#team').val() const team = $('#team').val()
if (year === '' || month === '' || team === '') { if (month === '' || year === '' || team === '') {
alert('Please complete all the necessary fields.') alert('Please complete all the necessary fields.')
} else { return false
$.ajax({
url: 'workflow_report/export',
type: 'GET',
data: {month: month, year: year, team: team},
success: function (response) {
$('#data_workflow').html(response)
if ($('#data_workflow').has('table').length > 0 && $('button.export-button').hasClass("d-none")) {
$('button.export-button').removeClass('d-none')
} else {
$('button.export-button').addClass('d-none')
} }
},
error: function (error) {
console.log(error)
},
}) return true
} });
})
const download = function (data) { const download = function (data) {
const blob = new Blob([data], {type: 'text/csv'}) const blob = new Blob([data], {type: 'text/csv'})
...@@ -39,9 +23,8 @@ window.addEventListener('load', function () { ...@@ -39,9 +23,8 @@ window.addEventListener('load', function () {
} }
$(".export-button").on("click", function () { $(".export-button").on("click", function () {
exportToCSV(); exportToCSV()
})
});
function exportToCSV() { function exportToCSV() {
const table = $("table") const table = $("table")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment