From 29cf948a9cbf8cf0d200214ac7c5991a31903614 Mon Sep 17 00:00:00 2001 From: Victor Mocelin <vm13@inf.ufpr.br> Date: Thu, 24 Mar 2016 11:30:06 -0300 Subject: [PATCH] =?UTF-8?q?Adicionado=20funcionamento=20b=C3=A1sico=20das?= =?UTF-8?q?=20listas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Criado um serviço para tratar da lista de palestras e outro para a lista de pessoas. Implementado adição de palestra e de pessoas (usando o scanner), mas ainda não é permanente. --- package.json | 9 +++-- www/index.html | 2 +- www/js/controllers.js | 34 +++++++++++++----- www/js/routes.js | 33 ++++++++++++----- www/js/services.js | 45 +++++++++++++++++++++++- www/templates/ceitificator.html | 6 ++-- www/templates/listaDePresenAEventoX.html | 8 ++--- www/templates/novoEvento.html | 8 ++--- 8 files changed, 110 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index 9e92728..82c6818 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,10 @@ "cordova-plugin-whitelist", "cordova-plugin-splashscreen", "cordova-plugin-statusbar", - "ionic-plugin-keyboard" + "ionic-plugin-keyboard", + "cordova-plugin-barcodescanner" ], - "cordovaPlatforms": [] -} \ No newline at end of file + "cordovaPlatforms": [ + "android" + ] +} diff --git a/www/index.html b/www/index.html index e817c43..9af5b46 100644 --- a/www/index.html +++ b/www/index.html @@ -21,7 +21,7 @@ <script src="js/services.js"></script> <script src="js/directives.js"></script> - <!-- Only required for Tab projects w/ pages in multiple tabs + <!-- Only required for Tab projects w/ pages in multiple tabs <script src="lib/ionicuirouter/ionicUIRouter.js"></script> --> diff --git a/www/js/controllers.js b/www/js/controllers.js index 8d53c9c..ae2aeab 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -1,14 +1,32 @@ angular.module('app.controllers', []) - -.controller('ceitificatorCtrl', function($scope) { +.controller('ceitificatorCtrl', function($scope, events) { + $scope.events = events; }) - -.controller('novoEventoCtrl', function($scope) { +.controller('novoEventoCtrl', function($scope, events) { + $scope.formData = {}; + $scope.addNewEvent = function (){ + if ((!$scope.formData.newEvent || $scope.formData.newEvent.length === 0 || !$scope.formData.newEvent.trim()) || + (!$scope.formData.speaker || $scope.formData.speaker.length === 0 || !$scope.formData.speaker.trim())) + alert("WTF?"); + else + events.push({id: 3, name: $scope.formData.newEvent, speaker: $scope.formData.speaker}); + }; }) - -.controller('listaDePresenAEventoXCtrl', function($scope) { -}) - \ No newline at end of file +.controller('listaDePresenAEventoXCtrl', function($scope, people) { + $scope.people = people; + $scope.scan = function(){ + cordova.plugins.barcodeScanner.scan( + function (result) { + $scope.$apply(function(){ + people.push({id: '5', data: result.text}); + }); + }, + function (error) { + alert("Scanning failed: " + error); + } + ); + }; +}); diff --git a/www/js/routes.js b/www/js/routes.js index 5a18251..ded662c 100644 --- a/www/js/routes.js +++ b/www/js/routes.js @@ -7,29 +7,44 @@ angular.module('app.routes', []) // Set up the various states which the app can be in. // Each state's controller can be found in controllers.js $stateProvider - - - .state('ceitificator', { + + + .state('ceitificator', { url: '/home', templateUrl: 'templates/ceitificator.html', - controller: 'ceitificatorCtrl' + controller: 'ceitificatorCtrl', + resolve: { + events: function(EventsService) { + return EventsService.getEvents(); + } + } }) .state('novoEvento', { url: '/novo-evento', templateUrl: 'templates/novoEvento.html', - controller: 'novoEventoCtrl' + controller: 'novoEventoCtrl', + resolve: { + events: function(EventsService) { + return EventsService.getEvents(); + } + } }) .state('listaDePresenAEventoX', { url: '/presenca', templateUrl: 'templates/listaDePresenAEventoX.html', - controller: 'listaDePresenAEventoXCtrl' + controller: 'listaDePresenAEventoXCtrl', + resolve: { + people: function(PeopleService) { + return PeopleService.getPeople(); + } + } }) -$urlRouterProvider.otherwise('/home') +$urlRouterProvider.otherwise('/home'); + - -}); \ No newline at end of file +}); diff --git a/www/js/services.js b/www/js/services.js index 8ce6039..c38daf1 100644 --- a/www/js/services.js +++ b/www/js/services.js @@ -6,5 +6,48 @@ angular.module('app.services', []) .service('BlankService', [function(){ -}]); +}]) + +.service('EventsService', function($q) { + return { + events: [ + { + id: '1', + name: 'Pick up apples', + speaker: 'hue' + }, + { + id: '2', + name: 'Mow the lawn', + speaker: 'lol' + } + ], + getEvents: function() { + return this.events; + }, + addEvent: function(event){ + this.events.push(event); + } + }; +}) +.service('PeopleService', function($q) { + return { + people: [ + { + id: '1', + data: 'Lol' + }, + { + id: '2', + data: 'hue' + } + ], + getPeople: function() { + return this.people; + }, + addPerson: function(person){ + this.people.push(person); + } + } +}); diff --git a/www/templates/ceitificator.html b/www/templates/ceitificator.html index d9cbc41..22af4ca 100644 --- a/www/templates/ceitificator.html +++ b/www/templates/ceitificator.html @@ -5,11 +5,9 @@ <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> <ion-list> - <ion-item ui-sref="listaDePresenAEventoX">Item 1</ion-item> - <ion-item ui-sref="listaDePresenAEventoX">Item 2</ion-item> - <ion-item ui-sref="listaDePresenAEventoX">Item 3</ion-item> + <ion-item ui-sref="listaDePresenAEventoX" ng-repeat="event in events">{{event.name}} - {{event.speaker}}</ion-item> </ion-list> </div> </div> </ion-content> -</ion-view> \ No newline at end of file +</ion-view> diff --git a/www/templates/listaDePresenAEventoX.html b/www/templates/listaDePresenAEventoX.html index 8347eaa..0722ce3 100644 --- a/www/templates/listaDePresenAEventoX.html +++ b/www/templates/listaDePresenAEventoX.html @@ -2,13 +2,11 @@ <ion-content overflow-scroll="true" padding="true" class="has-header"> <div class="list card"> <div class="item item-body"> - <button id="listaDePresenAEventoX-button9" class="button button-positive button-block icon-right ion-qr-scanner">Adicionar</button> + <button id="listaDePresenAEventoX-button9" class="button button-positive button-block icon-right ion-qr-scanner" ng-click="scan()">Adicionar</button> <ion-list> - <ion-item>Item 1</ion-item> - <ion-item>Item 2</ion-item> - <ion-item>Item 3</ion-item> + <ion-item ng-repeat="person in people">{{person.data}}</ion-item> </ion-list> </div> </div> </ion-content> -</ion-view> \ No newline at end of file +</ion-view> diff --git a/www/templates/novoEvento.html b/www/templates/novoEvento.html index 9c8cbf8..bf69039 100644 --- a/www/templates/novoEvento.html +++ b/www/templates/novoEvento.html @@ -5,20 +5,20 @@ <form class="list"> <label class="item item-input"> <span class="input-label">Palestra</span> - <input type="text" placeholder=""> + <input type="text" placeholder="" ng-model="formData.newEvent"/> </label> <label class="item item-input"> <span class="input-label">Palestrante</span> - <input type="text" placeholder=""> + <input type="text" placeholder="" ng-model="formData.speaker"/> </label> <div class="spacer" style="width: 255px; height: 32px;"></div> </form> <div class="button-bar"> - <a ui-sref="ceitificator" id="novoEvento-button6" class="button button-positive button-block button-outline icon-left ion-checkmark">Salvar</a> + <a ui-sref="ceitificator" id="novoEvento-button6" class="button button-positive button-block button-outline icon-left ion-checkmark" ng-click="addNewEvent()">Salvar</a> <a ui-sref="ceitificator" id="novoEvento-button8" class="button button-assertive button-block button-outline icon-left ion-android-cancel">Cancelar</a> </div> </div> </div> <form class="list"></form> </ion-content> -</ion-view> \ No newline at end of file +</ion-view> -- GitLab