Skip to content

Commit

Permalink
Arregla problema de generación de PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
germaaan committed Dec 1, 2015
1 parent 3356c99 commit 7bf1d81
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 13 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public/lib
# Directorio de hojas de estilo CSS generadas
public/style/css

# Directorio con los archivos de datos generados
public/data

# Directorio con el resultado de los tests de cobertura
coverage

Expand All @@ -18,9 +21,8 @@ app.min.js
*~

# Archivos binarios temporales
*.pdf
temp
data.tsv


# Configuración privada de Coveralls
.coveralls.yml
6 changes: 4 additions & 2 deletions doc/generarInforme.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ <h1>generarInforme.js</h1>

<div class="content"><div class='highlight'><pre> _.each(datos, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">valor</span>) </span>{
contenido += <span class="hljs-string">"· "</span> + valor.nombre + <span class="hljs-string">": "</span> + valor.frecuencia + <span class="hljs-string">"\n"</span>;
});</pre></div></div>
});

lxDocument.clear();</pre></div></div>

</li>

Expand Down Expand Up @@ -150,7 +152,7 @@ <h1>generarInforme.js</h1>

</div>

<div class="content"><div class='highlight'><pre> lxDocument.save(<span class="hljs-string">'public/data/gesco.pdf'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">result</span>) </span>{});
<div class="content"><div class='highlight'><pre> lxDocument.save(<span class="hljs-string">'public/data/data.pdf'</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">result</span>) </span>{});
};</pre></div></div>

</li>
Expand Down
41 changes: 34 additions & 7 deletions doc/informes.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ <h1>informes.js</h1>
</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">var</span> express = <span class="hljs-built_in">require</span>(<span class="hljs-string">'express'</span>);
<span class="hljs-keyword">var</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">"fs"</span>);
<span class="hljs-keyword">var</span> router = express.Router();

<span class="hljs-keyword">var</span> client = <span class="hljs-built_in">require</span>(appRoot + <span class="hljs-string">'/database/client'</span>);
<span class="hljs-keyword">var</span> informe = <span class="hljs-built_in">require</span>(appRoot + <span class="hljs-string">'/lib/generarInforme'</span>);</pre></div></div>
<span class="hljs-keyword">var</span> informe = <span class="hljs-built_in">require</span>(appRoot + <span class="hljs-string">'/lib/generarInforme'</span>);

<span class="hljs-keyword">var</span> file = appRoot + <span class="hljs-string">"/public/data/data.pdf"</span>;</pre></div></div>

</li>

Expand All @@ -93,11 +96,20 @@ <h1>informes.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a>
</div>
<p>Conecta a la base de datos</p>
<p>Comprobamos si el archivo existe porque será necesario borrarlo</p>

</div>

<div class="content"><div class='highlight'><pre> client.connect(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err, db</span>) </span>{</pre></div></div>
<div class="content"><div class='highlight'><pre> fs.stat(file, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err, stats</span>) </span>{
<span class="hljs-keyword">if</span> (err) {
<span class="hljs-built_in">console</span>.log(err);
<span class="hljs-keyword">return</span>;
}

<span class="hljs-keyword">if</span> (stats.isFile()) {
fs.unlinkSync(file);
}
});</pre></div></div>

</li>

Expand All @@ -108,11 +120,11 @@ <h1>informes.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a>
</div>
<p>Ejecuta consulta SQL</p>
<p>Conecta a la base de datos</p>

</div>

<div class="content"><div class='highlight'><pre> client.exec_sql(<span class="hljs-string">"ACTOR consultor(tareas) CREATE; SELECT * FROM tareas;"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err, datos</span>) </span>{</pre></div></div>
<div class="content"><div class='highlight'><pre> client.connect(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err, db</span>) </span>{</pre></div></div>

</li>

Expand All @@ -123,11 +135,11 @@ <h1>informes.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a>
</div>
<p>Cierra conexión</p>
<p>Ejecuta consulta SQL</p>

</div>

<div class="content"><div class='highlight'><pre> client.close();</pre></div></div>
<div class="content"><div class='highlight'><pre> client.exec_sql(<span class="hljs-string">"ACTOR consultor(tareas) CREATE; SELECT * FROM tareas;"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err, datos</span>) </span>{</pre></div></div>

</li>

Expand All @@ -138,6 +150,21 @@ <h1>informes.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a>
</div>
<p>Cierra conexión</p>

</div>

<div class="content"><div class='highlight'><pre> client.close();</pre></div></div>

</li>


<li id="section-8">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</a>
</div>
<p>Genera el informe con la información recuperada</p>

</div>
Expand Down
3 changes: 2 additions & 1 deletion lib/generarInforme.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ exports.generar = function(datos) {
contenido += "· " + valor.nombre + ": " + valor.frecuencia + "\n";
});

lxDocument.clear();
// Añade la información a distintos campos del documento
lxDocument.addContent('cliente', cliente);
lxDocument.addContent('fecha', fecha);
lxDocument.addContent('asunto', asunto);
lxDocument.addContent('contenido', contenido);

// Genera el documento
lxDocument.save('public/data/gesco.pdf', function(result) {});
lxDocument.save('public/data/data.pdf', function(result) {});
};
4 changes: 4 additions & 0 deletions routes/informes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

// Dependencias
var express = require('express');
var fs = require("fs");
var router = express.Router();

var client = require(appRoot + '/database/client');
var informe = require(appRoot + '/lib/generarInforme');

var file = appRoot + "/public/data/data.pdf";

// GET de la página de informes
router.get('/', function(req, res) {

// Conecta a la base de datos
client.connect(function(err, db) {
// Ejecuta consulta SQL
Expand Down
2 changes: 1 addition & 1 deletion views/informes.jade
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ extends layout
block content
.list-group
li.list-group-item.active.text-center.h2(style='text-align: center') Información de gestión
a.list-group-item(href='/data/gesco.pdf') Informe de frecuencias
a.list-group-item(href='/data/data.pdf') Informe de frecuencias

0 comments on commit 7bf1d81

Please sign in to comment.