diff --git a/app/css/app.css b/app/css/app.css index 0732dbd..02007e2 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -14,6 +14,15 @@ html { text-align: center; } +.list .item.item-button-right { + padding-right: 45px; +} + +.list .item.item-no-avatar { + padding: 10px; + padding-right: 45px; +} + .icon-spin { -webkit-animation: spin 2s infinite linear; -moz-animation: spin 2s infinite linear; @@ -46,4 +55,4 @@ html { to { transform: rotate(360deg); } -} \ No newline at end of file +} diff --git a/app/js/app.js b/app/js/app.js index 63cf150..464c2c3 100644 --- a/app/js/app.js +++ b/app/js/app.js @@ -23,6 +23,7 @@ angular.module('ui.gravatar').config([ ]); locksmithApp.run(function($rootScope, $state, $localStorage) { + console.log('app.run'); $rootScope.$state = $state; window.settings = $rootScope.$settings = $localStorage; @@ -44,6 +45,9 @@ locksmithApp.run(function($rootScope, $state, $localStorage) { if (typeof window.settings.bookmarks === 'undefined') { window.settings.bookmarks = []; } + if (typeof window.settings.favorites === 'undefined') { + window.settings.favorites = []; + } $rootScope.jobs = 0; @@ -59,6 +63,7 @@ locksmithApp.run(function($rootScope, $state, $localStorage) { locksmithApp.config([ '$stateProvider', '$urlRouterProvider', '$httpProvider', function($stateProvider, $urlRouterProvider, $httpProvider) { + console.log('app.config'); $httpProvider.interceptors.push(function($rootScope) { return { request: function(config) { @@ -101,11 +106,36 @@ locksmithApp.config([ controller: 'BookmarkIndexController', templateUrl: 'partials/bookmarks/list.html' }). + state('bookmarks.favorites', { + url: '', + controller: 'FavoritesIndexController', + templateUrl: 'partials/favorites/list.html' + }). state('bookmarks.show', { url: '/:bookmarkId', controller: 'BookmarkShowController', templateUrl: 'partials/bookmarks/show.html' }). + state('favorites', { + abstract: true, + url: '/favorites', + views: { + header: { + templateUrl: 'partials/header/favorites.html' + }, + main: { + templateUrl: 'partials/favorites/index.html' + }, + footer: { + templateUrl: 'partials/footer/footer.html' + } + } + }). + state('favorites.list', { + url: '', + controller: 'FavoritesIndexController', + templateUrl: 'partials/favorites/list.html' + }). state('accounts', { abstract: true, url: '/accounts', @@ -168,6 +198,5 @@ locksmithApp.config([ }); $urlRouterProvider.otherwise('/bookmarks'); - } ]); diff --git a/app/js/controllers.js b/app/js/controllers.js index 78f0264..581685c 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -130,25 +130,55 @@ locksmithControllers.controller( } }); - $scope.bookmarks = Bookmark.query(); - if (typeof $scope.bookmarks.$promise !== 'undefined') { - $scope.bookmarks.$promise.then(function(bookmarks) { - window.settings.bookmarks = bookmarks.bookmarks; - }); - } + Bookmark.query().$promise.then(function(bookmarks) { + // loop through all bookmarks, and check if they are included + // in the favorites. If so, mark them as such + for (i = 0; i < bookmarks.bookmarks.length; i++) { + var bookmark = bookmarks.bookmarks[i]; + bookmarks.bookmarks[i].is_favorite = false; + if (window.settings.favorites.includes(parseInt(bookmark.id))) { + bookmarks.bookmarks[i].is_favorite = true; + } + } + $scope.bookmarks = bookmarks; + + if (typeof $scope.bookmarks.$promise !== 'undefined') { + $scope.bookmarks.$promise.then(function(bookmarks) { + window.settings.bookmarks = bookmarks.bookmarks; + }); + } + }); + $scope.orderProp = 'name'; $('#search').focus(); } ]); +locksmithControllers.controller( + 'FavoritesIndexController', ['$rootScope', '$scope', '$state', 'Bookmark', '$location', 'signin', '$ionicPopup', '$controller', + + function($rootScope, $scope, $state, Bookmark, $location, signin, $ionicPopup, $controller) { + angular.extend(this, $controller('BookmarkIndexController', { + $scope: $scope + })); + + + } + + ]); + + locksmithControllers.controller( 'BookmarkShowController', ['$scope', '$state', 'Bookmark', '$stateParams', function($scope, $state, Bookmark, $stateParams) { $scope.bookmarkId = $stateParams.bookmarkId; - $scope.bookmark = Bookmark.query({ + Bookmark.query({ bookmarkId: $scope.bookmarkId + }).$promise.then(function(bookmark) { + bookmark.is_favorite = window.settings.favorites.includes(parseInt(bookmark.id)); + $scope.bookmark = bookmark; }); $scope.save = function() { @@ -158,6 +188,16 @@ locksmithControllers.controller( $scope.bookmark.$create(); } + if ($scope.bookmark.is_favorite) { + if (!window.settings.favorites.includes(parseInt($scope.bookmark.id))) { + window.settings.favorites.push(parseInt($scope.bookmarkId)); + } + } else { + window.settings.favorites = window.settings.favorites.filter(function(id) { + return parseInt(id) != parseInt($scope.bookmarkId); + }); + } + $state.go('bookmarks.list'); }; @@ -171,6 +211,7 @@ locksmithControllers.controller( } ]); + locksmithControllers.controller( 'AccountIndexController', ['$scope', 'Account', '$location', function($scope, Account, $location) { diff --git a/app/partials/bookmarks/list.html b/app/partials/bookmarks/list.html index c2e139e..d99f31c 100644 --- a/app/partials/bookmarks/list.html +++ b/app/partials/bookmarks/list.html @@ -10,15 +10,15 @@ /> - - + +

{{bookmark.name}}

{{bookmark.account_number}}/{{bookmark.role_name}}

+ diff --git a/app/partials/favorites/index.html b/app/partials/favorites/index.html new file mode 100644 index 0000000..b1ae398 --- /dev/null +++ b/app/partials/favorites/index.html @@ -0,0 +1,3 @@ + +
+
diff --git a/app/partials/favorites/list.html b/app/partials/favorites/list.html new file mode 100644 index 0000000..921916a --- /dev/null +++ b/app/partials/favorites/list.html @@ -0,0 +1,20 @@ + +
+ + +

{{bookmark.name}}

+

{{bookmark.account_number}}/{{bookmark.role_name}}

+ +
+ diff --git a/app/partials/footer/footer.html b/app/partials/footer/footer.html index 299821a..ef1615a 100644 --- a/app/partials/footer/footer.html +++ b/app/partials/footer/footer.html @@ -1,10 +1,19 @@
+ + + + > + > -
\ No newline at end of file + > + diff --git a/app/partials/header/favorites.html b/app/partials/header/favorites.html new file mode 100644 index 0000000..95efd5a --- /dev/null +++ b/app/partials/header/favorites.html @@ -0,0 +1 @@ +

Favorites

diff --git a/app/partials/settings.html b/app/partials/settings.html index eb8f150..5b64072 100644 --- a/app/partials/settings.html +++ b/app/partials/settings.html @@ -5,7 +5,7 @@ - +
Locksmith
@@ -35,6 +35,7 @@
+
+
+
Interface
+ +
+ Hide avatars + +
+ +
+ Use Favorites + +
+ + +
+