This file contains hidden or 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
| <div class="container"> | |
| <div id="divMensagemRetorno" class="row" style="display: none;"> | |
| <h4 id="mensagemRetorno"></h4> | |
| </div> | |
| <hr class="my-4"> | |
| <div id="divItens" class="row"></div> | |
| </div> |
This file contains hidden or 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
| $(document).ready(function(){ | |
| let Itens = [];//Variavel para adicionar os itens retornado do backend | |
| let divItens = document.getElementById("divItens");//Selecionando a div que irá receber o conteúdo gerado automaticamente | |
| //Chamada do Ajax para trazer os detalhes da ordem | |
| $.ajax({ | |
| url: '/secured/vagas/', //selecionando o endereço que iremos acessar no backend | |
| type: 'GET', //selecionando o tipo de requesição, PUT,GET,POST,DELETE | |
| sucess: function(){},//Em caso de sucesso | |
| error: function(err){//Em caso de erro | |
| console.log(err);//Exibir o erro no console JS do navegador |
This file contains hidden or 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
| $(document).ready(function(){ | |
| //Exemplo de detecção de um botão, cujo o class é exampleClass | |
| $('.exampleClass').on('click',function(){ | |
| //Examplo pegando os dados enviados por parametro | |
| var jsonObjeto = [{teste:$(this).data('teste'), nome:$(this).data('nome')}]; | |
| //Examplo pegando os dados diretamente de algum campo | |
| var jsonObjeto = [{teste:$('.classCampo').val(), nome:$('#idCampo').val()}]; | |
| //Chamada do Ajax para trazer os detalhes da ordem | |
| $.ajax({ | |
| url: 'example/post', //selecionando o endereço que iremos acessar no backend |
This file contains hidden or 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
| let fs = require('fs'); | |
| /* No exemplo abaixo, informamos o local que será criado o arquivo | |
| toda a informação que esse arquivo conterá, e por ultimo temos nossa função callback */ | |
| fs.writeFile("./files/example.txt",'Um breve texto aqui!', function(err){ | |
| //Caro ocorra algum erro | |
| if(err){ | |
| return console.log('erro') | |
| } | |
| //Caso não tenha erro, retornaremos a mensagem de sucesso |
This file contains hidden or 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
| //Efetuando a leitura do arquivo | |
| fs.readFile('./files/FILE_NAME','utf8', function(err,data){ | |
| //Enviando para o console o resultado da leitura | |
| console.log(data); | |
| }); |
This file contains hidden or 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
| //Enviando o caminho do arquivo que queremos renomear e o caminho/nome para sua nova situação | |
| fs.rename('./files/example.txt', './files/007.txt', function(err){ | |
| //Caso a execução encontre algum erro | |
| if(err){ | |
| //A execução irá parar e mostrará o erro | |
| throw err; | |
| }else{ | |
| //Caso não tenha erro, apenas a mensagem será exibida no terminal | |
| console.log('Arquivo renomeado'); | |
| } |
This file contains hidden or 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
| //Informando o endereço do arquivo para remoção do mesmo | |
| fs.unlink("./files/example.txt"); |
This file contains hidden or 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
| //JSON of data | |
| let materialKey = db.datastore.key('material');// Chave cloud para a entidade | |
| let material = { | |
| key: materialKey, | |
| data: req.body, | |
| }; | |
| db.datastore.save(material).then(function(item) { | |
| console.log('Material ${materialKey.id} created successfully.'); | |
| console.log(item[0].mutationResults[0]);//Se você quiser acessar os dados enviado |
This file contains hidden or 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
| //Cenário onde retornaremos todas as entidades salvas na base | |
| let query = db.datastore.createQuery('material');//Configurando a entidade que iremos buscar | |
| db.datastore.runQuery(query).then(materials => { | |
| console.log(materials[0]);//Dessa forma, acessamos todos os dados retornados pela query | |
| }); | |
| //Nesse cenário, iremos filtrar por algum atributo da entidade | |
| db.datastore.runQuery(query) | |
| .filter('name', '=', 'Exemplo')//Filtraremos por todos dados cadastrados que tenham no atributo name o dado Exemplo | |
| .filter('quantity', '>', 10)//E que tenham a quantidade maior que 10 | |
| .then(materials => { |
This file contains hidden or 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
| //Filtrando o item pelo seu ID enviado do método POST | |
| let filter = db.datastore.key(['material', db.datastore.int(req.param('id'))]); | |
| db.datastore.get(filter, function(err, material){ | |
| //Caso, o item or encontrado | |
| if (material) { | |
| /* Para atualizar os dados de um documento no Datastore, podemos utilizar a mesma função de criação save | |
| * ou até mesmo as equivalentes update e upsert, que atualizam ou criam caso o documento não exista */ | |
| let item = { | |
| key : filter,//iremos reaproveitar a variável, para o Datastore entender que iremos inserir dados para um documento existente | |
| data : req.body |