Trying to give the possibility to generate a pdf in xpages
The code I have :
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.resources>
<xp:script src="generate.js" clientSide="true"></xp:script>
</xp:this.resources>
<script type='text/javascript' src='js/jspdf.min.js'></script>
<script type="text/javascript" src="js/jspdf.plugin.autotable.js"></script>
<button onclick="generate()">Generate PDF</button>
<xp:br></xp:br>
<xp:br></xp:br>
<table id="basic-table" >
<thead>
<tr>
<th>ID</th>
<th>First name</th>
<th>Last name</th>
<th>Email</th>
<th>Country</th>
<th>IP-address</th>
</tr>
</thead>
<tbody>
<tr>
<td align="right">1</td>
<td>Donna</td>
<td>Moore</td>
<td>dmoore0#furl.net</td>
<td>China</td>
<td>211.56.242.221</td>
</tr>
<tr>
<td align="right">2</td>
<td>Janice</td>
<td>Henry</td>
<td>jhenry1#theatlantic.com</td>
<td>Ukraine</td>
<td>38.36.7.199</td>
</tr>
<tr>
<td align="right">3</td>
<td>Ruth</td>
<td>Wells</td>
<td>rwells2#constantcontact.com</td>
<td>Trinidad and Tobago</td>
<td>19.162.133.184</td>
</tr>
<tr>
<td align="right">4</td>
<td>Jason</td>
<td>Ray</td>
<td>jray3#psu.edu</td>
<td>Brazil</td>
<td>10.68.11.42</td>
</tr>
<tr>
<td align="right">5</td>
<td>Jane</td>
<td>Stephens</td>
<td>jstephens4#go.com</td>
<td>United States</td>
<td>47.32.129.71</td>
</tr>
<tr>
<td align="right">6</td>
<td>Adam</td>
<td>Nichols</td>
<td>anichols5#com.com</td>
<td>Canada</td>
<td>18.186.38.37</td>
</tr>
</tbody>
</table>
<xp:br></xp:br>
</xp:view>
I'm getting an error in the console :
Uncaught ReferenceError: jsPDF is not defined
at generate (generate:3)
at HTMLButtonElement.onclick (test_pdf2.xsp:20)
generate # generate:3
onclick # test_pdf2.xsp:20
and line 3 of generate.js = var doc = new jsPDF('p','pt');
When I have a look at the sources I can see under js the 2 libraries
What's wrong ?
jsPDF uses AMD. Here's a snippet from the jspdf.min.js source code where AMD is used:
function"==typeof define&&define.amd?define(e)
Unfortunately AMD loading conflicts with Dojo in XPages. See this answer on how to remove AMD loading.
You need to change the AMD loading part by changing the code in jspdf.min.js to this:
function"==typeof define&&false?define(e)
jspdf.plugin.autotable.js uses AMD too. Here you need to replace define.amd with false too.
Related
Here is the HTML I don't have any control over. This is condensed HTML of the real page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Little League</title>
</head>
<body>
<table>
<span>lot of unrelated text</span>
</table>
<table>
<span>lot of unrelated text</span>
</table>
<table>
<span>lot of unrelated text</span>
</table>
<table>
<tbody>
<tr>
<td class="rightTD">
<p>
<span id="teams_players">Player Teams</span>
</p>
</td>
</tr>
<tr>
<td>
<table border="1" cellspacing="0" cellpadding="0" class="tableBorder table table-bordered" width="100%">
<tbody>
<tr>
<td>
<table border="0" width="100%" class="tableData">
<tbody>
<tr id="team_listings">
<td colspan="3">Team Listings
<br>
<br>
</td>
</tr>
<tr>
<td>(a) </td>
<td colspan="2">Team Name </td>
</tr>
<tr>
<td></td>
<td colspan="2">
<span class="blue_color">Foxes</span>
</td>
</tr>
<tr>
<td>(b) </td>
<td colspan="2">Team Rank</td>
</tr>
<tr>
<td></td>
<td colspan="2">
<span class="blue_color">1</span>
</td>
</tr>
<tr>
<td>(c) </td>
<td colspan="2">Team Location
</td>
</tr>
<tr>
<td></td>
<td colspan="2">
<table width="100%">
<tbody>
<tr>
<td>City:
<br>
<span class="blue_color">Tualatin</span>
</td>
<td>State:
<br>
<span class="blue_colorLined"></span>
<br>
<span class="blue_color">Oregon</span>
</td>
<td>Country:
<br>
<span class="blue_colorLined"></span>
<br>
<span class="blue_color">United States</span>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<br>
<table border="1" cellspacing="0" cellpadding="0" class="tableBorder table table-bordered" width="100%">
<tbody>
<tr>
<td>
<table border="0" width="100%" class="tableData">
<tbody>
<tr>
<td>(a) </td>
<td colspan="2">Team Name </td>
</tr>
<tr>
<td></td>
<td colspan="2">
<span class="blue_color">Tigers</span>
</td>
</tr>
<tr>
<td>(b) </td>
<td colspan="2">Team Rank</td>
</tr>
<tr>
<td></td>
<td colspan="2">
<span class="blue_color">3</span>
</td>
</tr>
<tr>
<td>(c) </td>
<td colspan="2">Team Location
</td>
</tr>
<tr>
<td></td>
<td colspan="2">
<table width="100%">
<tbody>
<tr>
<td>City:
<br>
<span class="blue_color">Tigard</span>
</td>
<td>State:
<br>
<span class="blue_colorLined"></span>
<br>
<span class="blue_color">Oregon</span>
</td>
<td>Country:
<br>
<span class="blue_colorLined"></span>
<br>
<span class="blue_color">United States</span>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>
I am trying to get to the table tag immediately preceding the span tag with id team_players.
I tried these but failed -
//table/span[#id="teams_players"]
ancestor::table[span[#id="teams_players"][position() = 1]]
This works but is not elegant and I prefer not to hardcode it -
//span[#id="teams_players"]/../../../../..
While //table[#class="tableData"] this might seem like it should work, there are many such tables in the HTML that has the same class with unrelated data. So this is ruled out.
Here is the code so far with my attempts (definitely not efficient, once I find a way of fetching both tables, I plan on looping through them to extract the data -
def parse_team():
# team data structure
teams = []
team_dict = { 'team': '', 'rank': '', 'location': { 'city': '', 'state': '', 'country': '' } }
filename = f'team.html'
f = open(filename, encoding="utf8").read()
parser = etree.HTMLParser()
tree = etree.parse(StringIO(f), parser)
# fetch the table dom and parse each team table
# fetch the parent table that contains teams_players span id
team_tables = tree.xpath('ancestor::table[span[#id="teams_players"][position() = 1]]')
print(team_tables)
root_tables = tree.xpath('//table/span[#id="teams_players"]')
print("root tables", root_tables)
# this provides each team table but in full html, the same class is being used for other unrelated data
name = tree.xpath('//table[#class="tableData"]')
print(name)
eachvaltr = name[0].xpath('.//tr')
teamname = name[0].xpath('.//td[contains(text(),"Team Name")]//parent::tr/following-sibling::tr[1]//span[#class="blue_color"]/text()')
print("teamname", teamname)
teamrank = name[0].xpath(
'.//td[contains(text(),"Team Rank")]//parent::tr/following-sibling::tr[1]//span[#class="blue_color"]/text()')
print("teamrank", teamrank)
city = name[0].xpath(
'.//td[contains(text(),"City")]//span[#class="blue_color"]/text()')
state = name[0].xpath(
'.//td[contains(text(),"State")]//span[#class="blue_color"]/text()')
country = name[0].xpath(
'.//td[contains(text(),"Country")]//span[#class="blue_color"]/text()')
print(city[0], state[0], country[0])
team_dict['team'] = teamname
team_dict['rank'] = teamrank
team_dict['location']['city'] = city[0]
team_dict['location']['state'] = state[0]
team_dict['location']['country'] = country[0]
print(team_dict)
Desired output is a list of teams where each team is a dict.
[{'team': ['Foxes'], 'rank': ['1'], 'location': {'city': 'Tualatin', 'state': 'Oregon', 'country': 'United States'}}]
//table[.//span[#id="teams_players"]]
or
//span[#id="teams_players"]/ancestor::table
I'm working on adding an export/downloading feature to a Laravel 5 application. I found the Laravel-Excel library (http://www.maatwebsite.nl/laravel-excel/docs), which seems perfect -- ideally, I will be able to take a Laravel View or html and make a downloadable Excel file.
So far, I've gotten the creation and storage to work. I can create an Excel file, and it's okay (it's the right data and View), and on the server in storage/exports/ I see "Report.xls" - which is right save path. The issue I'm having is I cannot seem to download the file through the browser after creating it.
The Laravel-Excel library has ->download('xls') and ->export('xls') methods, but these only seems to return the raw content, which is visible in the developer's console:
On the right, you can see the file was created and stored as "Report.xls", and presumably the raw content is the right content - but I don't know why it's just spitting raw content into the console. I can open the Report.xls file in Excel, so I know it's not corrupted.
I also tried to use the Laravel 5 Response::download() function and set headers for the download, but it also spit out raw content in the console instead of downloading the file:
The code I'm using is an AJAX call that hits a Controller method, and the controller method just triggers a Service method called "downloadReportFile()":
public function downloadReportFile($requestData, $fileType) {
$configJSON = \Report::loadConfigFile($requestData['reportName']);
$today = Carbon::today()->format('Y-m-d');
$FileViewdata = array(
'config' => $configJSON,
'html' => $requestData['report_html']
);
\Excel::create("Report", function($excel) use ($FileViewdata) {
$excel->setTitle($FileViewdata['config']['title']);
$excel->setDescription($FileViewdata['config']['description']);
$excel->sheet("page 1", function($sheet) {
$sheet->loadView("reports.sample");
});
})->store('xls', storage_path('exports')); // ->export('xls');
$report_excelFilepath = storage_path('exports') . "/Report.xls";
return response()->download($report_excelFilepath, "Report.xls", [
'Content-Type' => 'application/vnd.ms-excel',
'Content-Disposition' => "attachment; filename='Report.xls'"
]);
}
The View being made into the Excel file is a simple table - the same table as in the screenshots. Here's the template/HTML of the View:
<div class="container full-width-container">
<link href="http://192.168.33.10/css/reports.css" rel="stylesheet">
<div id="results" class="row">
<div class="col-xs-12">
<h2 class="report-title">Active Products </h2>
<br>
<div class="row">
<div class="col-xs-12">
<div class="table-responsive report-component" name="table" template="table">
<table id="report-table" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td class="report-table-th">ENGINE</td>
<td class="report-table-th">PRODUCT COUNT</td>
<td class="report-table-th">PRODUCT PRICE</td>
</tr>
</thead>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Meows</p>
</td>
<td class="report-table-cell">
<p>1,234</p>
</td>
<td class="report-table-cell">
<p>781230.00</p>
</td>
</tr>
</tbody>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Paws</p>
</td>
<td class="report-table-cell">
<p>10,777</p>
</td>
<td class="report-table-cell">
<p>3919823.00</p>
</td>
</tr>
</tbody>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Meow Mobile</p>
</td>
<td class="report-table-cell">
<p>177</p>
</td>
<td class="report-table-cell">
<p>334323.00</p>
</td>
</tr>
</tbody>
<tbody>
<tr class="results-cell">
<td class="report-table-cell">
<p>Tails Cloud</p>
</td>
<td class="report-table-cell">
<p>335</p>
</td>
<td class="report-table-cell">
<p>378918923.00</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
Does anyone see what I might be missing to download an XLS file?
Thanks for your time!
EDIT
After doing some more research, it seems that my original workflow for downloading -- using an AJAX call to trigger -- is part of the problem. For example Download a file from Servlet using Ajax talks about AJAX storing results in JavaScript memory, which would explain why I get content in my console and not a file.
Try to add code below before Excel::create():
ob_end_clean();
ob_start();
Example code:
ob_end_clean();
ob_start();
Excel::create($filename, function($excel) use($records, $sheetname, $data) {}
This works for me.
I need some TVs (weight, dimensions, etc) I've associated with my products to appear in the Cart page of my SimpleCart site.
Problem is I have no idea how to do this. I don't understand how the SimpleCart cart is built and there isn't documentation for this.
Would anyone know how I can show TVs associated with each product in the cart output chunk?
The cart snippet has the following code which gets data from the cart and puts it into Chunks:
$sc = $modx->getService('simplecart','SimpleCart',$modx->getOption('simplecart.core_path',null,$modx->getOption('core_path').'components/simplecart/').'model/simplecart/',$scriptProperties);
if (!($sc instanceof SimpleCart)) return '';
$controller = $sc->loadController('Cart');
$output = $controller->run($scriptProperties);
The output Chunk looks like:
<div id="simplecart">
<form action="[[~[[*id]]]]" method="post" id="form_cartoverview">
<input type="hidden" name="updatecart" value="true" />
<table>
<tr>
<th class="desc">[[%simplecart.cart.description]]</th>
<th class="price">[[%simplecart.cart.price]]</th>
<th class="quantity">[[%simplecart.cart.quantity]]</th>
[[+cart.total.vat_total:notempty=`<th class="quantity">[[%simplecart.cart.vat]]</th>`:isempty=``]]
<th class="subtotal">[[%simplecart.cart.subtotal]]</th>
<th> </th>
</tr>
[[+cart.wrapper]]
[[+cart.total.discount:notempty=`<tr class="total first discount">
<td colspan="[[+cart.total.vat_total:notempty=`3`:isempty=`2`]]"> </td>
<td class="label">[[%simplecart.cart.discount]]</td>
<td class="value">- [[+cart.total.discount_formatted]]</td>
<td class="extra">[[+cart.total.discount_percent:notempty=`([[+cart.total.discount_percent]]%)`:isempty=` `]]</td>
</tr>`:isempty=``]]
[[+cart.total.vat_total:notempty=`
<tr class="total [[+cart.total.discount:notempty=`second`:isempty=`first`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_ex_vat]]</td>
<td class="value">[[+cart.total.price_ex_vat_formatted]]</td>
<td class="extra"> </td>
</tr>
[[+cart.vat_rates]]
<tr class="total [[+cart.total.discount:notempty=`third`:isempty=`second`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_vat]]</td>
<td class="value">[[+cart.total.vat_total_formatted]]</td>
<td class="extra"> </td>
</tr>
<tr class="total [[+cart.total.discount:notempty=`fourth`:isempty=`third`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_in_vat]]</td>
<td class="value">[[+cart.total.price_formatted]]</td>
<td class="extra"> </td>
</tr>
`:isempty=`
<tr class="total [[+cart.total.discount:notempty=`second`:isempty=`first`]]">
<td colspan="2"> </td>
<td class="label">[[%simplecart.cart.total]]</td>
<td class="value">[[+cart.total.price_formatted]]</td>
<td class="extra"> </td>
</tr>
`]]
</table>
<div class="submit">
<input type="submit" value="[[%simplecart.cart.update]]" />
</div>
</form>
This does appear to be documented:
Product Options (TVs)
and to output them:
Modifying the Product Template
It appears that you would just output them normally [[*myProductOptions]]
Though, it appears that your template is using a placeholder, I would try
[[+cart.myProductOptions] as well. If all else fails you might try debugging the simplecart class and dump the array of product data before it populates the chunk, there might be a clue in there.
Found (through trial and error) you must use:
[[+product.tv.name_of_tv]]
I have a table in JSF Page:
<table cellpadding="0" cellspacing="0" border="1" align="center">
<col width="300"/>
<col width="150"/>
<col width="150" span="3"/>
<thead>
<tr>
<th rowspan="3" > </th>
<th rowspan="3" >A</th>
<th colspan="3" >B</th>
</tr>
<tr>
<th colspan="2">C</th>
<th rowspan="2">D</th>
</tr>
<tr>
<th>E</th>
<th>F</th>
</tr>
</thead>
<tbody>
<c:forEach items="${indexbean.regions}" var="r">
<tr>
<td colspan="5" >#{r.region}</td>
</tr>
<c:forEach items="${indexbean.table_data}" var="s">
<c:if test="${s.reg eq r.region}">
<tr>
<td>#{s.rowname}</td>
<td>#{s.d1}</td>
<td>#{s.d2}</td>
<td>#{s.d3}</td>
<td>#{s.d4}</td>
</tr>
</c:if>
</c:forEach>
</c:forEach>
</tbody>
</table>
These codes work properly. But i want to use primefaces p:dataExporter (for download this table as Excel), that is why i must create this table with p:dataTable. I can't find solution what i can replace 2 forEach method in p:dataTable.
How can i create this table with Primefaces p:dataTable? Please, help me.
I'm trying to send cppcheck report on an email using email-ext plugin from a Jenkins build. So far, only way seems to be by creating a custom template -- jelly or groovy. From this post -- "Can I configure jenkins to send an email with a static analysis report summary?" -- it looks like I should be able to instantiate CppcheckBuildAction and use its methods but for some reason, it doesn't seem to instantiate (ie. the object is null). Here's the code I've put in the jelly template to check this:
<j:set var="cppcBuildAction" value="${it.getAction('com.thalesgroup.hudson.plugins.cppcheck.CppcheckBuildAction')}"/>
<j:if test="${cppcBuildAction==null}">
<p><i>cppcBuildAction is null!</i></p>
</j:if>
(I also tried hudson.plugins.cppcheck.CppcheckBuildAction)
And, sure enough, I get cpppcBuildAction is null! in the build result email. (I had to put in "if" clause to test this on jelly because it doesn't throw out any error, otherwise. In groovy template, I actually get the error message like "Exception: javax.script.ScriptException: java.lang.NullPointerException: Cannot get property 'getResult' on null object" if I try to call getResult method on the object).
Has anybody tried sending Cppcheck result/report over email using this email-ext plugin or otherwise?
BTW, there is another post where someone else is trying to do what I'm trying to do but the thread doesn't seem to be active or there's no real interaction going on there -- "What's wrong with following jelly script template for cppcheck in email-ext plugin of hudson"
You just use wrong namespace, right one is: org.jenkinsci.plugins.cppcheck.CppcheckBuildAction.
For debugging you could use the following code:
<j:forEach var="a" items="${build.getActions()}">
action: ${a.getClass().getName()}
<BR/>
</j:forEach>
And finally the following code works for me:
<!-- CppCheck TEMPLATE -->
<j:set var="cppcheckAction" value="${it.getAction('org.jenkinsci.plugins.cppcheck.CppcheckBuildAction')}" />
<j:if test="${cppcheckAction!=null}">
<j:set var="cppcheckResult" value="${cppcheckAction.getResult()}" />
<j:if test="${cppcheckResult!=null}">
<TABLE width="100%">
<TR><TD class="bg1" colspan="2"><B>CPPCHECK RESULT</B></TD></TR>
<TR bgcolor="white"><TD class="test_failed" colspan="2"><B><li>Found: ${cppcheckResult.report.getNumberTotal()}</li></B></TD></TR>
</TABLE>
<BR/>
</j:if>
</j:if>
Enjoy!
I found myself wanting to do the same thing: Send a email-ext email with the results of the cppcheck analysis.
This jelly script works with what Sergey provided above and makes a table similar to the one found in the results page.
Hopefully this will save someone an hour somewhere.
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
<html>
<j:set var="cppcheckAction" value="${it.getAction('org.jenkinsci.plugins.cppcheck.CppcheckBuildAction')}" />
<j:if test="${cppcheckAction!=null}">
<j:set var="cppcheckResult" value="${cppcheckAction.getResult()}" />
<j:if test="${cppcheckResult!=null}">
<h2>Summary</h2>
<style type="text/css">
#cppcheckStatistics { width: auto; }
#cppcheckStatistics .number { text-align: right; }
</style>
<table class="pane sortable" id="cppcheckStatistics">
<thead>
<tr>
<td class="pane-header">Severity</td>
<td class="pane-header">Count</td>
<td class="pane-header">Delta</td>
</tr>
</thead>
<tbody>
<tr>
<td class="pane">Error</td>
<td class="pane number">${cppcheckResult.statistics.getNumberErrorSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberErrorSeverity()}</td>
</tr>
<tr>
<td class="pane">Warning</td>
<td class="pane number">${cppcheckResult.statistics.getNumberWarningSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberWarningSeverity()}</td>
</tr>
<tr>
<td class="pane">Style</td>
<td class="pane number">${cppcheckResult.statistics.getNumberStyleSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberStyleSeverity()}</td>
</tr>
<tr>
<td class="pane">Performance</td>
<td class="pane number">${cppcheckResult.statistics.getNumberPerformanceSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberPerformanceSeverity()}</td>
</tr>
<tr>
<td class="pane">Portability</td>
<td class="pane number">${cppcheckResult.statistics.getNumberPortabilitySeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberPortabilitySeverity()}</td>
</tr>
<tr>
<td class="pane">Information</td>
<td class="pane number">${cppcheckResult.statistics.getNumberInformationSeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberInformationSeverity()}</td>
</tr>
<tr>
<td class="pane">No category</td>
<td class="pane number">${cppcheckResult.statistics.getNumberNoCategorySeverity()}</td>
<td class="pane number">${cppcheckResult.getDiff().getNumberNoCategorySeverity()}</td>
</tr>
</tbody>
<tfoot>
<tr class="sortbottom">
<td class="pane-header">Total</td>
<td class="pane-header number"><B>${cppcheckResult.report.getNumberTotal()}</B></td>
<td class="pane-header number"><B>${cppcheckResult.getDiff().getNumberTotal()}</B></td>
</tr>
</tfoot>
</table>
</j:if>
</j:if>
</html>
</j:jelly>