diff --git a/static/js/decrypt.js b/static/js/decrypt.js index 9ed22ac..5e0b164 100644 --- a/static/js/decrypt.js +++ b/static/js/decrypt.js @@ -63,6 +63,19 @@ form.addEventListener('submit', async function(e) { resultDiv.appendChild(exportXMLBtn); + const exportHTMLBtn = document.createElement('button'); + exportHTMLBtn.textContent = 'Exportar como HTML'; + exportHTMLBtn.className = 'btn-secondary'; + exportHTMLBtn.style.marginTop = '0.5rem'; + + exportHTMLBtn.onclick = () => exportDecryptAsHTML( + payload.encoding_matrix, + payload.encrypted_matrix, + result.decrypted_message +); + +document.getElementById('result').appendChild(exportHTMLBtn); + } catch (error) { showError(error.message); } @@ -70,8 +83,6 @@ form.addEventListener('submit', async function(e) { generateBtn.click(); -const json = prettyJson(matrixA, 4); - function exportDecryptAsJSON(encodingMatrix, encryptedMatrix, decryptedMessage) { const json = `{ @@ -92,8 +103,6 @@ function exportDecryptAsJSON(encodingMatrix, encryptedMatrix, decryptedMessage) URL.revokeObjectURL(url); } -const xml = prettyXML(matrix, tagName); - function exportDecryptAsXML(encodingMatrix, encryptedMatrix, decryptedMessage) { const xml = ` @@ -111,5 +120,40 @@ function exportDecryptAsXML(encodingMatrix, encryptedMatrix, decryptedMessage) { a.download = 'desencriptacao.xml'; a.click(); + URL.revokeObjectURL(url); +} + +function exportDecryptAsHTML(encodingMatrix, encryptedMatrix, decryptedMessage) { + const html = +` + + + + Desencriptação + + +

Operação: Decrypt

+ +

Matriz de Codificação

+ ${prettyHTML(encodingMatrix, 'encodingMatrix')} + +

Matriz Encriptada

+ ${prettyHTML(encryptedMatrix, 'encryptedMatrix')} + +

Mensagem Desencriptada

+

+ ${decryptedMessage} +

+ +`; + + const blob = new Blob([html], { type: 'text/html' }); + const url = URL.createObjectURL(blob); + + const a = document.createElement('a'); + a.href = url; + a.download = 'desencriptacao.html'; + a.click(); + URL.revokeObjectURL(url); } \ No newline at end of file diff --git a/static/js/determinant.js b/static/js/determinant.js index 3aa20c6..cb25ad4 100644 --- a/static/js/determinant.js +++ b/static/js/determinant.js @@ -55,6 +55,18 @@ form.addEventListener('submit', async function(e) { resultDiv.appendChild(exportXMLBtn); + const exportHTMLBtn = document.createElement('button'); + exportHTMLBtn.textContent = 'Exportar como HTML'; + exportHTMLBtn.className = 'btn-secondary'; + exportHTMLBtn.style.marginTop = '0.5rem'; + + exportHTMLBtn.onclick = () => exportDeterminantAsHTML( + payload.matrix, + result.result +); + + document.getElementById('result').appendChild(exportHTMLBtn); + } catch (error) { showError(error.message); } @@ -62,8 +74,6 @@ form.addEventListener('submit', async function(e) { generateBtn.click(); -const json = prettyJson(matrixA, 4); - function exportDeterminantAsJSON(matrix, determinant) { const json = `{ @@ -83,8 +93,6 @@ function exportDeterminantAsJSON(matrix, determinant) { URL.revokeObjectURL(url); } -const xml = prettyXML(matrix, tagName); - function exportDeterminantAsXML(matrix, determinant) { const xml = ` @@ -103,3 +111,32 @@ function exportDeterminantAsXML(matrix, determinant) { URL.revokeObjectURL(url); } + +function exportDeterminantAsHTML(matrix, determinant) { + const html = +` + + + + Determinante + + +

Operação: Determinante

+ + ${prettyHTML(matrix, 'Matriz')} + +

Resultado

+

${determinant}

+ +`; + + const blob = new Blob([html], { type: 'text/html' }); + const url = URL.createObjectURL(blob); + + const a = document.createElement('a'); + a.href = url; + a.download = 'determinante.html'; + a.click(); + + URL.revokeObjectURL(url); +} diff --git a/static/js/encrypt.js b/static/js/encrypt.js index 9b3c8c4..09c11cc 100644 --- a/static/js/encrypt.js +++ b/static/js/encrypt.js @@ -61,6 +61,20 @@ form.addEventListener('submit', async function(e) { document.getElementById('result').appendChild(exportXMLBtn); + const exportHTMLBtn = document.createElement('button'); + exportHTMLBtn.textContent = 'Exportar como HTML'; + exportHTMLBtn.className = 'btn-secondary'; + exportHTMLBtn.style.marginTop = '0.5rem'; + + exportHTMLBtn.onclick = () => exportEncryptAsHTML( + payload.message, + payload.encoding_matrix, + result.encrypted_matrix +); + +document.getElementById('result').appendChild(exportHTMLBtn); + + } catch (error) { showError(error.message); } @@ -68,8 +82,6 @@ form.addEventListener('submit', async function(e) { generateBtn.click(); -const json = prettyJson(matrixA, 4); - function exportEncryptAsJSON(message, encodingMatrix, encryptedMatrix) { const json = `{ @@ -90,8 +102,6 @@ function exportEncryptAsJSON(message, encodingMatrix, encryptedMatrix) { URL.revokeObjectURL(url); } -const xml = prettyXML(matrix, tagName); - function exportEncryptAsXML(message, encodingMatrix, encryptedMatrix) { const xml = ` @@ -110,4 +120,34 @@ function exportEncryptAsXML(message, encodingMatrix, encryptedMatrix) { a.click(); URL.revokeObjectURL(url); -} \ No newline at end of file +} + +function exportEncryptAsHTML(message, encodingMatrix, encryptedMatrix) { + const html = +` + + + + Encriptação + + +

Operação: Encriptação

+ +

Mensagem Original

+

${message}

+ + ${prettyHTML(encodingMatrix, 'Matriz de Codificação')} + ${prettyHTML(encryptedMatrix, 'Matriz Encriptada')} + +`; + + const blob = new Blob([html], { type: 'text/html' }); + const url = URL.createObjectURL(blob); + + const a = document.createElement('a'); + a.href = url; + a.download = 'encriptacao.html'; + a.click(); + + URL.revokeObjectURL(url); +} diff --git a/static/js/inverse.js b/static/js/inverse.js index 9c7a1dd..c4a775d 100644 --- a/static/js/inverse.js +++ b/static/js/inverse.js @@ -50,7 +50,19 @@ form.addEventListener('submit', async function(e) { ); document.getElementById('result').appendChild(exportXMLBtn); - + + const exportHTMLBtn = document.createElement('button'); + exportHTMLBtn.textContent = 'Exportar como HTML'; + exportHTMLBtn.className = 'btn-secondary'; + exportHTMLBtn.style.marginTop = '0.5rem'; + + exportHTMLBtn.onclick = () => exportInverseAsHTML( + payload.matrix, + decimalMatrix(result.result, 2) +); + +document.getElementById('result').appendChild(exportHTMLBtn); + } catch (error) { showError(error.message); } @@ -80,8 +92,6 @@ function exportInverseAsJSON(originalMatrix, inverseMatrix) { URL.revokeObjectURL(url); } -const xml = prettyXML(matrix, tagName); - function exportInverseAsXML(originalMatrix, inverseMatrix) { const xml = ` @@ -99,4 +109,31 @@ ${prettyXML(inverseMatrix, 'inverseMatrix')} a.click(); URL.revokeObjectURL(url); -} \ No newline at end of file +} + +function exportInverseAsHTML(originalMatrix, inverseMatrix) { + const html = +` + + + + Matriz Inversa + + +

Operação: Matriz Inversa

+ + ${prettyHTML(originalMatrix, 'Matriz Original')} + ${prettyHTML(inverseMatrix, 'Matriz Inversa')} + +`; + + const blob = new Blob([html], { type: 'text/html' }); + const url = URL.createObjectURL(blob); + + const a = document.createElement('a'); + a.href = url; + a.download = 'matriz_inversa.html'; + a.click(); + + URL.revokeObjectURL(url); +} diff --git a/static/js/multiply.js b/static/js/multiply.js index e360a65..874eaa0 100644 --- a/static/js/multiply.js +++ b/static/js/multiply.js @@ -65,6 +65,20 @@ form.addEventListener('submit', async function(e) { ); document.getElementById('result').appendChild(exportXMLBtn); + + const exportHTMLBtn = document.createElement('button'); + exportHTMLBtn.textContent = 'Exportar como HTML'; + exportHTMLBtn.className = 'btn-secondary'; + exportHTMLBtn.style.marginTop = '0.5rem'; + + exportHTMLBtn.onclick = () => exportMultiplyAsHTML( + payload.matrix_a, + payload.matrix_b, + result.result +); + +document.getElementById('result').appendChild(exportHTMLBtn); + } catch (error) { showError(error.message); } @@ -72,8 +86,6 @@ document.getElementById('result').appendChild(exportXMLBtn); generateBtn.click(); -const json = prettyJson(matrixA, 4); - function exportMultiplyAsJSON(matrixA, matrixB, resultMatrix) { const json = `{ @@ -94,8 +106,6 @@ function exportMultiplyAsJSON(matrixA, matrixB, resultMatrix) { URL.revokeObjectURL(url); } -const xml = prettyXML(matrix, tagName); - function exportMultiplyAsXML(matrixA, matrixB, resultMatrix) { const xml = ` @@ -114,4 +124,32 @@ ${prettyXML(resultMatrix, 'result')} a.click(); URL.revokeObjectURL(url); -} \ No newline at end of file +} + +function exportMultiplyAsHTML(matrixA, matrixB, resultMatrix) { + const html = +` + + + + Multiplicação de Matrizes + + +

Operação: Multiplicação de Matrizes (A × B)

+ + ${prettyHTML(matrixA, 'Matriz A')} + ${prettyHTML(matrixB, 'Matriz B')} + ${prettyHTML(resultMatrix, 'Resultado')} + +`; + + const blob = new Blob([html], { type: 'text/html' }); + const url = URL.createObjectURL(blob); + + const a = document.createElement('a'); + a.href = url; + a.download = 'multiplicacao_matrizes.html'; + a.click(); + + URL.revokeObjectURL(url); +} diff --git a/static/js/scalar.js b/static/js/scalar.js index 4f74f4f..26bde4d 100644 --- a/static/js/scalar.js +++ b/static/js/scalar.js @@ -55,6 +55,19 @@ form.addEventListener('submit', async function(e) { document.getElementById('result').appendChild(exportXMLBtn); + const exportHTMLBtn = document.createElement('button'); + exportHTMLBtn.textContent = 'Exportar como HTML'; + exportHTMLBtn.className = 'btn-secondary'; + exportHTMLBtn.style.marginTop = '0.5rem'; + + exportHTMLBtn.onclick = () => exportScalarAsHTML( + payload.scalar, + payload.matrix, + result.result +); + +document.getElementById('result').appendChild(exportHTMLBtn); + } catch (error) { showError(error.message); } @@ -62,8 +75,6 @@ document.getElementById('result').appendChild(exportXMLBtn); generateBtn.click(); -const json = prettyJson(matrixA, 4); - function exportScalarAsJSON(scalar, matrix, resultMatrix) { const json = `{ @@ -84,8 +95,6 @@ function exportScalarAsJSON(scalar, matrix, resultMatrix) { URL.revokeObjectURL(url); } -const xml = prettyXML(matrix, tagName); - function exportScalarAsXML(scalar, matrix, resultMatrix) { const xml = ` @@ -104,4 +113,32 @@ ${prettyXML(resultMatrix, 'result')} a.click(); URL.revokeObjectURL(url); -} \ No newline at end of file +} + +function exportScalarAsHTML(scalar, matrix, resultMatrix) { + const html = +` + + + + Multiplicação por Escalar + + +

Operação: Multiplicação por Escalar

+

Escalar: ${scalar}

+ + ${prettyHTML(matrix, 'Matriz Original')} + ${prettyHTML(resultMatrix, 'Resultado')} + +`; + + const blob = new Blob([html], { type: 'text/html' }); + const url = URL.createObjectURL(blob); + + const a = document.createElement('a'); + a.href = url; + a.download = 'scalar_multiplication.html'; + a.click(); + + URL.revokeObjectURL(url); +} diff --git a/static/js/sum-sub.js b/static/js/sum-sub.js index 9178623..2a8acbe 100644 --- a/static/js/sum-sub.js +++ b/static/js/sum-sub.js @@ -59,6 +59,20 @@ form.addEventListener('submit', async function(e) { document.getElementById('result').appendChild(exportXMLBtn); + const exportHTMLBtn = document.createElement('button'); + exportHTMLBtn.textContent = 'Exportar como HTML'; + exportHTMLBtn.className = 'btn-secondary'; + exportHTMLBtn.style.marginTop = '0.5rem'; + + exportHTMLBtn.onclick = () => exportAsHTML( + payload.matrix_a, + payload.matrix_b, + result.result, + payload.operation +); + +document.getElementById('result').appendChild(exportHTMLBtn); + } catch (error) { showError(error.message); } @@ -66,8 +80,6 @@ document.getElementById('result').appendChild(exportXMLBtn); generateBtn.click(); -const json = formatMatrix(matrixA, 4); - function exportAsJSON(matrixA, matrixB, matrixResult, operation) { const json = `{ @@ -88,8 +100,6 @@ function exportAsJSON(matrixA, matrixB, matrixResult, operation) { URL.revokeObjectURL(url); } -const xml = prettyXML(matrix, tagName); - function exportAsXML(matrixA, matrixB, matrixResult, operation) { const xml = ` @@ -107,5 +117,33 @@ function exportAsXML(matrixA, matrixB, matrixResult, operation) { a.download = 'matrizes.xml'; a.click(); + URL.revokeObjectURL(url); +} + +function exportAsHTML(matrixA, matrixB, matrixResult, operation) { + const html = +` + + + + Resultado da Operação + + +

Operação: ${operation}

+ + ${prettyHTML(matrixA, 'Matriz A')} + ${prettyHTML(matrixB, 'Matriz B')} + ${prettyHTML(matrixResult, 'Resultado')} + +`; + + const blob = new Blob([html], { type: 'text/html' }); + const url = URL.createObjectURL(blob); + + const a = document.createElement('a'); + a.href = url; + a.download = 'matrizes.html'; + a.click(); + URL.revokeObjectURL(url); } \ No newline at end of file diff --git a/static/js/transpose.js b/static/js/transpose.js index 7c068f7..1f6aab7 100644 --- a/static/js/transpose.js +++ b/static/js/transpose.js @@ -50,15 +50,27 @@ form.addEventListener('submit', async function(e) { ); document.getElementById('result').appendChild(exportXMLBtn); + + const exportHTMLBtn = document.createElement('button'); + exportHTMLBtn.textContent = 'Exportar como HTML'; + exportHTMLBtn.className = 'btn-secondary'; + exportHTMLBtn.style.marginTop = '0.5rem'; + + exportHTMLBtn.onclick = () => exportTransposeAsHTML( + payload.matrix, + result.result +); + +document.getElementById('result').appendChild(exportHTMLBtn); + + } catch (error) { showError(error.message); } }); generateBtn.click(); - -const json = prettyJson(matrixA, 4); - + function exportTransposeAsJSON(matrix, transposedMatrix) { const json = `{ @@ -78,8 +90,6 @@ function exportTransposeAsJSON(matrix, transposedMatrix) { URL.revokeObjectURL(url); } -const xml = prettyXML(matrix, tagName); - function exportTransposeAsXML(matrix, transposedMatrix) { const xml = ` @@ -96,5 +106,33 @@ ${prettyXML(transposedMatrix, 'result')} a.download = 'matriz_transposta.xml'; a.click(); + URL.revokeObjectURL(url); +} + +function exportTransposeAsHTML(matrix, transposedMatrix) { + const html = +` + + + + Matriz Transposta + + +

Operação: Transposta

+ + ${prettyHTML(matrix, 'Matriz Original')} + ${prettyHTML(transposedMatrix, 'Matriz Transposta')} + + +`; + + const blob = new Blob([html], { type: 'text/html' }); + const url = URL.createObjectURL(blob); + + const a = document.createElement('a'); + a.href = url; + a.download = 'matriz_transposta.html'; + a.click(); + URL.revokeObjectURL(url); } \ No newline at end of file diff --git a/static/js/utils.js b/static/js/utils.js index e0748b5..b075911 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -68,4 +68,20 @@ function prettyXML(matrix, tagName) { xml += ` \n`; return xml; +} + +function prettyHTML(matrix, title) { + let html = `

${title}

`; + html += ''; + + matrix.forEach(row => { + html += ''; + row.forEach(value => { + html += ``; + }); + html += ''; + }); + + html += '
${value}
'; + return html; } \ No newline at end of file