Skip to content
This repository was archived by the owner on May 10, 2022. It is now read-only.

Commit c88eeec

Browse files
committed
sending for columns for use in pdf generation
1 parent bc024c6 commit c88eeec

File tree

5 files changed

+125
-5
lines changed

5 files changed

+125
-5
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Modules\ReportGenerator\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Http\Response;
7+
use Illuminate\Routing\Controller;
8+
9+
class PdfController extends Controller
10+
{
11+
/**
12+
* Display a listing of the resource.
13+
* @return Response
14+
*/
15+
public function index(Request $request)
16+
{
17+
dd($request->column_names);
18+
return view('reportgenerator::index');
19+
}
20+
21+
/**
22+
* Show the form for creating a new resource.
23+
* @return Response
24+
*/
25+
public function create()
26+
{
27+
return view('reportgenerator::create');
28+
}
29+
30+
/**
31+
* Store a newly created resource in storage.
32+
* @param Request $request
33+
* @return Response
34+
*/
35+
public function store(Request $request)
36+
{
37+
}
38+
39+
/**
40+
* Show the specified resource.
41+
* @return Response
42+
*/
43+
public function show()
44+
{
45+
return view('reportgenerator::show');
46+
}
47+
48+
/**
49+
* Show the form for editing the specified resource.
50+
* @return Response
51+
*/
52+
public function edit()
53+
{
54+
return view('reportgenerator::edit');
55+
}
56+
57+
/**
58+
* Update the specified resource in storage.
59+
* @param Request $request
60+
* @return Response
61+
*/
62+
public function update(Request $request)
63+
{
64+
}
65+
66+
/**
67+
* Remove the specified resource from storage.
68+
* @return Response
69+
*/
70+
public function destroy()
71+
{
72+
}
73+
}

Modules/ReportGenerator/Http/Controllers/ReportGeneratorController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function showReport($option_ids, $hide = False)
8686
}
8787

8888
$data = []; // store the retrieved data
89-
$column_names = []; // st
89+
$column_names = []; // store the column_names
9090
foreach ($column_list as $columns) { // $columns has the list of columns for each component.
9191
$table_name = $columns[0]; // get table name to which each column list points to.
9292
for($i = 1; $i < count($columns); $i++) { // foreach list of columns

Modules/ReportGenerator/Http/routes.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
Route::group(['middleware' => 'web', 'prefix' => 'reportgenerator', 'namespace' => 'Modules\ReportGenerator\Http\Controllers'], function()
44
{
5-
Route::get('pdf_report', function(){
6-
return view('');
7-
});
5+
Route::get('/pdf_report', 'PdfController@index');
86

97
Route::get('/', 'ReportGeneratorController@index');
108

Modules/ReportGenerator/Resources/views/report.blade.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
<button type="button" class="btn btn-info" data-toggle="modal" data-target="#add-report-format">Save report as</button>&nbsp;
1717
@endif
1818
<button type="button" class="btn btn-info" onclick="printReport('report_div')">Print</button>&nbsp;
19-
<a type="button" class="btn btn-info" href="{{ asset('pdf_report.php') }}">PDF</a>&nbsp;
19+
<form method="get" action="{{ url('reportgenerator/pdf_report') }}">
20+
@foreach($column_names as $key => $column_name)
21+
<input name="column_names[]" class="column_names" id="column_names[]" type="hidden" value="{{ $column_name }}" align="absmiddle" />
22+
@endforeach
23+
<button type="submit" class="btn btn-info" id="pdf-button">PDF</button>
24+
</form>&nbsp;
2025
<button type="button" class="btn btn-info">TXT</button>&nbsp;
2126
<button type="button" class="btn btn-info">CSV</button>&nbsp;
2227
<button type="button" class="btn btn-info">ODT</button>

public/assets/js/master.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,33 @@ function generate(IDs) {
6666
});
6767
}
6868

69+
/* This function gets the column_names of all columns in a displayed report for pdf use.
70+
* @params: array: column_names
71+
* @return: Display these column_names
72+
*/
73+
function pdf_report_generate(column_names) {
74+
$.ajaxSetup({
75+
headers: {
76+
'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
77+
}
78+
});
79+
$.ajax({
80+
url: 'reportgenerator/pdf_report',
81+
type: 'get',
82+
data: { column_names: column_names },
83+
dataType: 'json',
84+
success: function(response){
85+
console.log(response);
86+
//jQuery('.alert').show();
87+
//jQuery('.alert').html(response.column_names);
88+
window.location.href = response.redirecturl; // your action should return an object having [redirecturl] property
89+
},
90+
error: function (httpRequest, textStatus, errorThrown) { // detailed error messsage
91+
alert("Error: " + textStatus + " " + errorThrown + " " + httpRequest);
92+
}
93+
});
94+
}
95+
6996
/* This function prints the report.
7097
* @params: DOM element: report_div
7198
* @return: Boolean: True
@@ -105,6 +132,23 @@ $(document).ready(function() {
105132
}
106133
});
107134

135+
/*** PDF code from PDF button ***/
136+
$('#pdf-button').click(function(e) {
137+
e.preventDefault();
138+
var column_names = [];
139+
140+
$("input[name='column_names[]'].column_names").each(function() { // get all the column_names from that foreach loop in report.blade.php
141+
column_names[] = $(this).val();
142+
//column_names.push($(this).val());
143+
});
144+
145+
if (jQuery.isEmptyObject(column_names)) { // check if the user has dropped any component before trying to generate a report
146+
alert("Cannot generate pdf of report! Please try again.");
147+
} else {
148+
pdf_report_generate(column_names); // Call the generate function above when the generate button is clicked
149+
}
150+
});
151+
108152
/*** Edit system feature ***/
109153
$('#edit-system-feature').on('show.bs.modal', function(e){
110154
$('#edit-system-feature #feature_name').val($(e.relatedTarget).data('feature_name'));

0 commit comments

Comments
 (0)