From f54130f6a228940ab7bb42889f98dc4d1845ceb8 Mon Sep 17 00:00:00 2001 From: Colin McLeod Date: Tue, 26 May 2015 00:18:37 -0700 Subject: [PATCH] Comparison bug when deleting builds --- app/js/controllers/controller-comparison.js | 32 +++++++++++++++++---- app/js/controllers/controller-error.js | 3 -- app/js/controllers/controller-outfit.js | 11 +++++++ app/js/directives/directive-header.js | 4 +++ app/js/service-persist.js | 11 ++++++- package.json | 2 +- 6 files changed, 53 insertions(+), 10 deletions(-) diff --git a/app/js/controllers/controller-comparison.js b/app/js/controllers/controller-comparison.js index 9f2bc253..3ac392e9 100755 --- a/app/js/controllers/controller-comparison.js +++ b/app/js/controllers/controller-comparison.js @@ -1,7 +1,7 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope', '$filter', '$scope', '$state', '$stateParams', 'Utils', 'ShipFacets', 'ShipsDB', 'Ship', 'Persist', 'Serializer', function (_, $rootScope, $filter, $scope, $state, $stateParams, Utils, ShipFacets, Ships, Ship, Persist, Serializer) { $rootScope.title = 'Coriolis - Compare'; - $scope.predicate = 'ship.name'; // Sort by ship name as default - $scope.desc = true; + $scope.predicate = 'name'; // Sort by ship name as default + $scope.desc = false; $scope.facetSortOpts = { containment: '#facet-container', orderChanged: function () { $scope.saved = false; } }; $scope.builds = []; $scope.unusedBuilds = []; @@ -99,7 +99,7 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope' } }); Persist.saveComparison($scope.name, $scope.builds, selectedFacets); - $state.go('compare', {name: $scope.name}, {location:'replace', reload:false}); + $state.go('compare', {name: $scope.name}, {location:'replace', notify:false}); $scope.saved = true; }; @@ -111,22 +111,41 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope' $state.go('compare', {name: null}, {location:'replace', reload:true}); }; + /** + * Set saved to false when the name of the comparison is changed. + */ $scope.nameChange = function() { $scope.saved = false; }; + /** + * Hide/Show the select builds menu + * @param {boolean} s Show true/false + * @param {Event} e Event Object + */ $scope.selectBuilds = function(s, e) { e.stopPropagation(); $scope.showBuilds = s; }; + /** + * Show the permalink modal + * @param {Event} e Event object + */ $scope.permalink = function(e) { e.stopPropagation(); $state.go('modal.link', {url: genPermalink()}); }; + /** + * Generate the forum embed code for the comparison + * and show the export modal. + * + * @param {Event} e Event object + */ $scope.embed = function(e) { e.stopPropagation(); + // Make a request to goo.gl to shorten the URL, returns a promise var promise = Utils.shortenUrl( genPermalink()).then( function (shortUrl) { return Utils.comparisonBBCode(facets, $scope.builds, shortUrl); @@ -138,6 +157,10 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope' $state.go('modal.export', {promise: promise, title:'Forum BBCode'}); }; + /** + * Generates the long permalink URL + * @return {string} The long permalink URL + */ function genPermalink() { var selectedFacets = []; facets.forEach(function(f) { @@ -202,11 +225,10 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope' throw { type: 'bad-comparison', message: e.message, details: e }; } } - // Replace fmt with actual format function as defined in rootScope and retain original index facets.forEach(function(f,i) { f.fmt = $rootScope[f.fmt]; f.index = i; }); // Remove default facets, mark as active, and add them back in selected order _.pullAt(facets, defaultFacets).forEach(function (f) { f.active = true; facets.unshift(f); }); - + $scope.builds = $filter('orderBy')($scope.builds, $scope.predicate, $scope.desc); }]); \ No newline at end of file diff --git a/app/js/controllers/controller-error.js b/app/js/controllers/controller-error.js index 409923d3..6264e2ef 100755 --- a/app/js/controllers/controller-error.js +++ b/app/js/controllers/controller-error.js @@ -12,18 +12,15 @@ angular.module('app') $scope.msgPost = 'Not Found'; break; case 'no-ship': - //$rootScope.bodyClass = 'docking-bay'; $scope.msgPre = 'Ship'; $scope.msgHighlight = $p.message; $scope.msgPost = 'does not exist'; break; case 'build-fail': - //$rootScope.bodyClass = 'ship-explode'; // TODO: create background imag for this $scope.msgPre = 'Build Failure!'; $scope.details = $p.details; break; default: - //$rootScope.bodyClass = 'thargoid'; // TODO: create background imag for this $scope.msgPre = "Uh, Jameson, we have a problem.."; $scope.errorMessage = $p.message; $scope.details = $p.details; diff --git a/app/js/controllers/controller-outfit.js b/app/js/controllers/controller-outfit.js index dbdacace..e26af50c 100755 --- a/app/js/controllers/controller-outfit.js +++ b/app/js/controllers/controller-outfit.js @@ -130,15 +130,26 @@ angular.module('app').controller('OutfitController', ['$rootScope','$scope', '$s $state.go('outfit', {shipId: ship.id, code: null, bn: null}, {location:'replace', reload:true}); }; + /** + * On build name change, retrieve the existing saved code if there is one + */ $scope.bnChange = function(){ $scope.savedCode = Persist.getBuild(ship.id, $scope.buildName); }; + /** + * Toggle cost of the selected component + * @param {object} item The component being toggled + */ $scope.toggleCost = function(item) { item.incCost = !item.incCost; ship.updateTotals(); }; + /** + * Toggle the power on/off for the selected component + * @param {object} item The component being toggled + */ $scope.togglePwr = function(item) { item.enabled = !item.enabled; ship.updateTotals(); diff --git a/app/js/directives/directive-header.js b/app/js/directives/directive-header.js index 5fc1a792..9fbc752d 100755 --- a/app/js/directives/directive-header.js +++ b/app/js/directives/directive-header.js @@ -28,11 +28,15 @@ angular.module('app').directive('shipyardHeader', ['lodash','$window','$rootScop scope.openedMenu = null; }); + // Listen to close event to close opened menus or modals $rootScope.$on('close', function () { scope.openedMenu = null; $rootScope.showAbout = false; }); + /** + * Save selected insurance option in localstorage + */ scope.updateInsurance = function(){ $window.localStorage.setItem('insurance', $rootScope.insurance.current.name); }; diff --git a/app/js/service-persist.js b/app/js/service-persist.js index ffa617e3..03be3193 100755 --- a/app/js/service-persist.js +++ b/app/js/service-persist.js @@ -72,7 +72,16 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window, } // Persist updated build collection to localStorage localStorage.setItem(LS_KEY_BUILDS, angular.toJson(this.builds)); - // TODO: Check if build exists in comparisons + // Check if the build was used in existing comparisons + var comps = this.comparisons; + for (var c in comps) { + for (var i = 0; i < comps[c].builds.length; i++) { // For all builds in the current comparison + if(comps[c].builds[i].shipId == shipId && comps[c].builds[i].buildName == name) { + comps[c].builds.splice(i,1); + break; // A build is unique ber comparison + } + } + } } }; diff --git a/package.json b/package.json index 036d4a4f..cae7ae4a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coriolis_shipyard", - "version": "0.7.5", + "version": "0.7.7", "repository": { "type": "git", "url": "https://github.com/cmmcleod/coriolis"