Commit be16d564 authored by Victor Mocelin's avatar Victor Mocelin

Adicionada opção de salvar evento em um arquivo

Salva os dados da palestra e das pessoas presentes em um arquivo.
Segue o formato de #1. Fixes #1 and #5.
parent 7ce528f7
Pipeline #2150 skipped
......@@ -8,50 +8,93 @@ angular.module('app.controllers', [])
$scope.events = EventsService.getEvents();
$scope.$broadcast('scroll.refreshComplete');
$scope.$apply();
};
};
})
.controller('novoEventoCtrl', function($scope, EventsService) {
$scope.formData = {};
checkEmpty = function(string){
if (!string || string.length === 0 || !string.trim())
return true;
return false;
};
$scope.addNewEvent = function() {
// insere um novo evento no banco
if ((!$scope.formData.eventName || $scope.formData.eventName.length === 0 || !$scope.formData.eventName.trim()) ||
(!$scope.formData.eventDesc || $scope.formData.eventDesc.length === 0 || !$scope.formData.eventDesc.trim()) ||
(!$scope.formData.eventDate || $scope.formData.eventDate.length === 0 || !$scope.formData.eventDate.trim()) ||
(!$scope.formData.eventPlace || $scope.formData.eventPlace.length === 0 || !$scope.formData.eventPlace.trim()) ||
(!$scope.formData.eventHours || $scope.formData.eventHours.length === 0 || !$scope.formData.eventHours.trim()))
if (checkEmpty($scope.formData.eventName) ||
checkEmpty($scope.formData.eventDesc) ||
checkEmpty($scope.formData.eventDate) ||
checkEmpty($scope.formData.eventPlace) ||
checkEmpty($scope.formData.eventHours))
alert("WTF?"); // se deixou algum campo em branco, leva um alert na cara
else // se tá tudo certo, manda inserir o novo evento no banco
EventsService.addNewEvent({eventName: $scope.formData.eventName, eventDesc: $scope.formData.eventDesc, eventDate: $scope.formData.eventDate, eventPlace: $scope.formData.eventPlace, eventHours: $scope.formData.eventHours});
EventsService.addNewEvent({
eventName: $scope.formData.eventName,
eventDesc: $scope.formData.eventDesc,
eventDate: $scope.formData.eventDate,
eventPlace: $scope.formData.eventPlace,
eventHours: $scope.formData.eventHours
});
};
$scope.showCertText = function() {
// mostra o texto final (ou quase) que ficará no certificado
alert("Certificamos que !NOME! participou " + $scope.formData.eventDesc + " " + $scope.formData.eventName + ", realizada " + $scope.formData.eventDate + " na Universidade Federal do Paraná, " + $scope.formData.eventPlace + ", em Curitiba – PR, com a carga horária total de " + $scope.formData.eventHours + ".");
alert("Certificamos que !NOME! participou " +
$scope.formData.eventDesc + " " + $scope.formData.eventName +
", realizada " + $scope.formData.eventDate +
" na Universidade Federal do Paraná, " +
$scope.formData.eventPlace +
", em Curitiba – PR, com a carga horária total de " +
$scope.formData.eventHours + ".");
};
})
.controller('listaDePresenAEventoXCtrl', function($scope, PeopleService, eventX) {
$scope.eventX = eventX;
.controller('listaDePresenAEventoXCtrl', function($scope, $cordovaFile, PeopleService, eventX) {
$scope.eventX = eventX;
$scope.people = PeopleService.getPeople(eventX.id);
$scope.scan = function() {
// faz o scan do qr code e marca a presença da pessoa
cordova.plugins.barcodeScanner.scan(
function (result) {
function(result) {
if (result && result.text.split(',').length == 3) {
// pega o que veio do scanner, separa nos devidos campos e insere no banco
PeopleService.addPersonInEvent({name: result.text.split(',')[0].trim(), grr: result.text.split(',')[1].trim(), email: result.text.split(',')[2].trim()}, eventX.id)
PeopleService.addPersonInEvent({
name: result.text.split(',')[0].trim(),
grr: result.text.split(',')[1].trim(),
email: result.text.split(',')[2].trim()
}, eventX.id)
.then(function(result) {
// atualiza a view
$scope.people = PeopleService.getPeople(eventX.id);
}, function(err){
// se deu erro, não precisa atualizar a view
}, function(err) {
// se deu erro, não precisa atualizar a view
console.log(err);
});
}
},
function (error) {
function(error) {
alert("Scanning failed: " + error);
}
);
};
$scope.storeData = function() {
var string = $scope.eventX.desc + "\n" +
$scope.eventX.name + "\n" +
$scope.eventX.date + "\n" +
$scope.eventX.place + "\n" +
$scope.eventX.hours + "\n";
for (var i = 0; i < $scope.people.length; i++){
string += $scope.people[i].name + "#" +
$scope.people[i].email + "\n";
}
$cordovaFile.writeFile( cordova.file.externalDataDirectory,
$scope.eventX.name.replace(" ", "_") + ".txt",
string, true)
.then(function (success) {
// success
console.log("Salvou");
}, function (error) {
// error
console.log("Não salvou");
});
};
});
......@@ -13,7 +13,8 @@ angular.module('app.services', [])
getEvents: function() {
// pega no banco todos os eventos e retorna
var events = [];
var db = $cordovaSQLite.openDB({name: 'ceitificator.db', iosDatabaseLocation: 'default'});
var db = $cordovaSQLite.openDB({name: 'ceitificator.db',
iosDatabaseLocation: 'default'});
$cordovaSQLite.execute(db, "SELECT * FROM events")
.then(function(res) {
for(var i = 0; i < res.rows.length; i++) {
......@@ -26,19 +27,25 @@ angular.module('app.services', [])
},
addNewEvent: function(event) {
// adiciona um novo evento no banco
var db = $cordovaSQLite.openDB({name: 'ceitificator.db', iosDatabaseLocation: 'default'});
var db = $cordovaSQLite.openDB({name: 'ceitificator.db',
iosDatabaseLocation: 'default'});
var query = "INSERT INTO events (name, desc, date, place, hours) VALUES (?,?,?,?,?)";
$cordovaSQLite.execute(db, query, [event.eventName, event.eventDesc, event.eventDate, event.eventPlace, event.eventHours])
$cordovaSQLite.execute(db, query, [event.eventName,
event.eventDesc,
event.eventDate,
event.eventPlace,
event.eventHours])
.then(function(res) {
console.log("res: " + res);
}, function(err) {
console.error(err);
console.error(err);
});
},
getEventById: function(eventId) {
// dado um id, retorna a palestra com o mesmo id
var dfd = $q.defer();
var db = $cordovaSQLite.openDB({name: 'ceitificator.db', iosDatabaseLocation: 'default'});
var db = $cordovaSQLite.openDB({name: 'ceitificator.db',
iosDatabaseLocation: 'default'});
var query = "SELECT * FROM events WHERE id=\"" + eventId + "\"";
$cordovaSQLite.execute(db, query)
.then(function(res) {
......@@ -57,7 +64,8 @@ angular.module('app.services', [])
getPeople: function(eventId) {
// pega no banco todas as pessoas
var people = [];
var db = $cordovaSQLite.openDB({name: 'ceitificator.db', iosDatabaseLocation: 'default'});
var db = $cordovaSQLite.openDB({name: 'ceitificator.db',
iosDatabaseLocation: 'default'});
$cordovaSQLite.execute(db, "SELECT people.* FROM people, people_events WHERE people.id=people_events.person_id AND people_events.event_id=" + eventId)
.then(function(res) {
for(var i = 0; i < res.rows.length; i++) {
......@@ -71,14 +79,19 @@ angular.module('app.services', [])
addPersonInEvent: function(person, eventId) {
// procura a pessoa, se existir, insere direto na tabela people_events, se não existir, cria a pessoa primeiro
var dfd = $q.defer();
var db = $cordovaSQLite.openDB({name: 'ceitificator.db', iosDatabaseLocation: 'default'});
var query = "SELECT * FROM people WHERE name=\"" + person.name + "\"AND grr=\"" + person.grr + "\"AND email=\"" + person.email + "\"";
var db = $cordovaSQLite.openDB({name: 'ceitificator.db',
iosDatabaseLocation: 'default'});
var query = "SELECT * FROM people WHERE name=\"" + person.name +
"\"AND grr=\"" + person.grr + "\"AND email=\"" +
person.email + "\"";
$cordovaSQLite.execute(db, query)
.then(function(res) {
if (res.rows.length == 0) {
console.log("pessoa não existe");
query = "INSERT INTO people (name, grr, email) VALUES (?,?,?)";
$cordovaSQLite.execute(db, query, [person.name, person.grr, person.email])
$cordovaSQLite.execute(db, query, [person.name,
person.grr,
person.email])
.then(function(res) {
console.log("id: " + res.insertId);
query = "INSERT INTO people_events (event_id, person_id) VALUES (?,?)";
......
......@@ -9,6 +9,7 @@
<p><strong>Horas:</strong> {{eventX.hours}}</p>
</div>
<div class="item item-body">
<button id="listaDePresenAEventoX-button2" class="button button-positive button-block icon-right ion-ios-download" on-touch="storeData()">Salvar para arquivo</button>
<button id="listaDePresenAEventoX-button1" class="button button-positive button-block icon-right ion-qr-scanner" on-touch="scan()">Adicionar</button>
<ion-list>
<ion-item ng-repeat="person in people">{{person.name}} - {{person.grr}} - {{person.email}}</ion-item>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment