-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aplicação .NET Web com as funções de converter, validar e limpar
- Loading branch information
1 parent
e669971
commit e5b7ca3
Showing
7 changed files
with
127 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,35 @@ | |
ViewData["Title"] = "Home Page"; | ||
} | ||
|
||
<div class="text-center"> | ||
<h1 class="display-4">Welcome</h1> | ||
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p> | ||
</div> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>App Converter JSON</title> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous"> | ||
</head> | ||
<body> | ||
|
||
<div class="container" id="app_converter"> | ||
<div class="content-form"> | ||
<form> | ||
<textarea class="form-control" id="textJSON" rows="6" placeholder="Digite ou cole aqui seu texto JSON:"></textarea> | ||
<div class="d-grid gap-3"> | ||
<br> | ||
<button type="submit" class="btn btn-outline-success">Converter</button> | ||
<button type="button" id="btn-limpar" class="btn btn-outline-secondary">Limpar</button> | ||
<br> | ||
</div> | ||
</form> | ||
</div> | ||
<div class="content-form"> | ||
<textarea class="form-control" id="textCSV" rows="6" disabled | ||
placeholder="Seu texto convertido em CSV aparecerá aqui."></textarea> | ||
</div> | ||
</div> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script> | ||
<script src="./js/siteConverter.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@{ | ||
ViewData["Title"] = "Repositório da Aplicação"; | ||
} | ||
<h1>@ViewData["Title"]</h1> | ||
|
||
<div class="container"> | ||
<p>Caso deseja consultar o código-fonte será possível através do respositório que se encontra no <a href="https://github.com/marquescharlon/JSON_to_CSV_Converter" target="_blank">https://github.com/marquescharlon/JSON_to_CSV_Converter</a>.</p> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" /> | ||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" /> | ||
<link rel="stylesheet" href="~/AppConverter.styles.css" asp-append-version="true" /> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous"> | ||
</head> | ||
<body> | ||
<header> | ||
|
@@ -23,7 +24,7 @@ | |
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a> | ||
</li> | ||
<li class="nav-item"> | ||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a> | ||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Repositorio">Repositório GitHub</a> | ||
</li> | ||
</ul> | ||
</div> | ||
|
@@ -38,12 +39,14 @@ | |
|
||
<footer class="border-top footer text-muted"> | ||
<div class="container"> | ||
© 2023 - AppConverter - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a> | ||
|
||
© 2023 - AppConverter - <a asp-area="" asp-controller="Home" asp-action="Repositorio">Repositório</a> | ||
</div> | ||
</footer> | ||
<script src="~/lib/jquery/dist/jquery.min.js"></script> | ||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script> | ||
<script src="~/js/site.js" asp-append-version="true"></script> | ||
@await RenderSectionAsync("Scripts", required: false) | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script> | ||
</body> | ||
</html> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification | ||
// for details on configuring this project to bundle and minify static web assets. | ||
|
||
// Write your JavaScript code. | ||
|
||
var appConverterForm = document.querySelector("#app_converter form"); | ||
var btnConverterLimpar = document.getElementById("btn-limpar"); | ||
|
||
appConverterForm.onsubmit = AppConverter; | ||
btnConverterLimpar.onclick = LimparTela; | ||
|
||
function AppConverter(e) { | ||
e.preventDefault(); | ||
|
||
var textJSON = document.getElementById("textJSON"); | ||
var textCSV = document.getElementById("textCSV"); | ||
textCSV.innerHTML = ''; | ||
|
||
if (!validarTextoJson(textJSON.value)) return; | ||
|
||
var dados = JSON.parse(textJSON.value); | ||
|
||
var campos = []; | ||
var primeiraLinha = JSON.stringify(dados[0]).split(","); | ||
for (item of primeiraLinha) { | ||
let nomes = item.split('"'); | ||
campos.push(nomes[1]); | ||
} | ||
|
||
var montar_csv = []; | ||
montar_csv[0] = ''; | ||
for (item of campos) { | ||
montar_csv[0] += '"' + item + '",'; | ||
} | ||
|
||
for (var i = 0; i < dados.length; i++) { | ||
montar_csv[i + 1] = ''; | ||
for (item of campos) { | ||
montar_csv[i + 1] += '"' + dados[i][item] + '",'; | ||
} | ||
} | ||
|
||
var texto_csv = ''; | ||
for (item of montar_csv) { | ||
texto_csv += item + "\n"; | ||
} | ||
textCSV.innerHTML = texto_csv; | ||
} | ||
|
||
function LimparTela() { | ||
document.getElementById("textJSON").value = ''; | ||
document.getElementById("textCSV").value = ''; | ||
alert("Formulário limpo conforme solicitado!"); | ||
document.location.reload(true); | ||
} | ||
|
||
function validarTextoJson(texto_json) { | ||
if (texto_json.length === 0) { | ||
alert("Necessário informar o texto JSON a ser convertido."); | ||
return false; | ||
} | ||
|
||
try { | ||
var json_val = JSON.parse(texto_json); | ||
} | ||
catch (e) { | ||
alert("O JSON está no formato inválido!"); | ||
return false; | ||
} | ||
return true; | ||
} |