Skip to content

Commit

Permalink
Persistencia das preferências do usuário em cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
juniorconte committed Apr 20, 2017
1 parent ee6f0cf commit b9eaad3
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/firebase/firebase.js"></script>
<script src="bower_components/angularfire/dist/angularfire.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<!-- endbower -->
<!-- endbuild -->

Expand Down
1 change: 1 addition & 0 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
angular
.module('todoApp', [
'ngAnimate',
'ngCookies',
'ngRoute',
'firebase'
])
Expand Down
8 changes: 6 additions & 2 deletions app/scripts/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
* Controller of the todoApp
*/
angular.module('todoApp')
.controller('MainCtrl', function ($scope, $firebaseArray) {
.controller('MainCtrl', function ($scope, $firebaseArray, $cookies) {

var ref = firebase.database().ref().child('todos');

$scope.hide = false;
$scope.hide = $cookies.get('hide') === 'true' || false;
$scope.todos = $firebaseArray(ref);

$scope.addTodo = function(title) {
Expand All @@ -36,4 +36,8 @@ angular.module('todoApp')
});
};

$scope.saveHide = function() {
$cookies.put('hide', $scope.hide);
};

});
2 changes: 1 addition & 1 deletion app/views/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h1>Firetasks</h1>
<div class="col-xs-6">
<button type="button"
class="btn btn-warning btn-block"
ng-click="hide = !hide">
ng-click="hide = !hide; saveHide()">
{{hide && 'Exibir' || 'Esconder'}} concluídas
</button>
</div>
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"bootstrap": "^3.2.0",
"angular-animate": "^1.4.0",
"angular-route": "^1.4.0",
"angularfire": "^2.3.0"
"angularfire": "^2.3.0",
"angular-cookies": "^1.6.4"
},
"devDependencies": {
"angular-mocks": "^1.4.0"
Expand Down
1 change: 1 addition & 0 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = function(config) {
'bower_components/angular-route/angular-route.js',
'bower_components/firebase/firebase.js',
'bower_components/angularfire/dist/angularfire.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-mocks/angular-mocks.js',
// endbower
'app/scripts/**/*.js',
Expand Down

0 comments on commit b9eaad3

Please sign in to comment.