Commit 7ce528f7 authored by Victor Mocelin's avatar Victor Mocelin

Modificado o retorno do service para atender #4.

A view da lista de presença agora atualiza a cada inserção de pessoa.
Na tela inicial, foi criado um botão "atualizar" temporariamente, até encontrar uma forma de fazer automático.
parent 7cac6189
Pipeline #1438 skipped
angular.module('app.controllers', [])
.controller('ceitificatorCtrl', function($scope, $ionicPlatform, EventsService) {
$ionicPlatform.ready(function () {
$ionicPlatform.ready(function() {
$scope.events = EventsService.getEvents();
});
$scope.doRefresh = function() {
$scope.events = EventsService.getEvents();
$scope.$broadcast('scroll.refreshComplete');
$scope.$apply();
};
})
.controller('novoEventoCtrl', function($scope, EventsService) {
$scope.formData = {};
$scope.addNewEvent = function () {
$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()) ||
......@@ -19,7 +24,7 @@ angular.module('app.controllers', [])
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});
};
$scope.showCertText = function () {
$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 + ".");
};
......@@ -34,13 +39,19 @@ angular.module('app.controllers', [])
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
console.log(err);
});
}
},
function (error) {
alert("Scanning failed: " + error);
}
);
$scope.people = PeopleService.getPeople(eventX.id);
};
});
......@@ -31,7 +31,7 @@ angular.module('app.services', [])
$cordovaSQLite.execute(db, query, [event.eventName, event.eventDesc, event.eventDate, event.eventPlace, event.eventHours])
.then(function(res) {
console.log("res: " + res);
}, function (err) {
}, function(err) {
console.error(err);
});
},
......@@ -47,12 +47,12 @@ angular.module('app.services', [])
}, function(err) {
console.log(err);
});
return dfd.promise
return dfd.promise;
}
}
})
.service('PeopleService', function($cordovaSQLite) {
.service('PeopleService', function($cordovaSQLite, $q) {
return {
getPeople: function(eventId) {
// pega no banco todas as pessoas
......@@ -70,6 +70,7 @@ 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 + "\"";
$cordovaSQLite.execute(db, query)
......@@ -84,11 +85,14 @@ angular.module('app.services', [])
$cordovaSQLite.execute(db, query, [eventId, res.insertId])
.then(function(res) {
console.log("inseriu em people_events");
}, function (err) {
dfd.resolve(res);
}, function(err) {
console.error(err);
dfd.resolve(err);
});
}, function (err) {
}, function(err) {
console.error(err);
dfd.resolve(err);
});
}
else{
......@@ -98,13 +102,17 @@ angular.module('app.services', [])
$cordovaSQLite.execute(db, query, [eventId, res.rows.item(0).id])
.then(function(res) {
console.log("inseriu em people_events");
}, function (err) {
dfd.resolve(res);
}, function(err) {
console.error(err);
dfd.resolve(err);
});
}
}, function (err) {
}, function(err) {
console.error(err);
dfd.resolve(err);
});
return dfd.promise;
}
}
});
<ion-view title="Ceitificator">
<ion-content overflow-scroll="true" padding="true" scroll="false" class="has-header">
<ion-content overflow-scroll="true" padding="true" class="has-header">
<h1 id="ceitificator-heading1" style="color:#000000;text-align:center;">Ceitificator</h1>
<div class="list card">
<div class="item item-body">
<a ui-sref="novoEvento" id="ceitificator-button2" class="button button-positive button-block icon-right ion-android-add-circle">Criar Novo</a>
<a ui-sref="novoEvento" id="ceitificator-button1" class="button button-positive button-block icon-right ion-android-add-circle">Criar Novo</a>
<ion-list>
<ion-item ng-repeat="event in events" ui-sref='listaDePresenAEventoX({eventId: event.id})'>{{event.id}}: {{event.name}} - {{event.date}} - {{event.hours}}</ion-item>
</ion-list>
<button id="ceitificator-button2" class="button button-positive button-block icon-right ion-ios-refresh" on-touch="doRefresh()">Atualizar</button>
</div>
</div>
</ion-content>
......
......@@ -9,7 +9,7 @@
<p><strong>Horas:</strong> {{eventX.hours}}</p>
</div>
<div class="item item-body">
<button id="listaDePresenAEventoX-button9" class="button button-positive button-block icon-right ion-qr-scanner" ng-click="scan()">Adicionar</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>
</ion-list>
......
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