Comparison bug when deleting builds

This commit is contained in:
Colin McLeod
2015-05-26 00:18:37 -07:00
parent 0993a72d25
commit f54130f6a2
6 changed files with 53 additions and 10 deletions

View File

@@ -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) { 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'; $rootScope.title = 'Coriolis - Compare';
$scope.predicate = 'ship.name'; // Sort by ship name as default $scope.predicate = 'name'; // Sort by ship name as default
$scope.desc = true; $scope.desc = false;
$scope.facetSortOpts = { containment: '#facet-container', orderChanged: function () { $scope.saved = false; } }; $scope.facetSortOpts = { containment: '#facet-container', orderChanged: function () { $scope.saved = false; } };
$scope.builds = []; $scope.builds = [];
$scope.unusedBuilds = []; $scope.unusedBuilds = [];
@@ -99,7 +99,7 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
} }
}); });
Persist.saveComparison($scope.name, $scope.builds, selectedFacets); 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; $scope.saved = true;
}; };
@@ -111,22 +111,41 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
$state.go('compare', {name: null}, {location:'replace', reload:true}); $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.nameChange = function() {
$scope.saved = false; $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) { $scope.selectBuilds = function(s, e) {
e.stopPropagation(); e.stopPropagation();
$scope.showBuilds = s; $scope.showBuilds = s;
}; };
/**
* Show the permalink modal
* @param {Event} e Event object
*/
$scope.permalink = function(e) { $scope.permalink = function(e) {
e.stopPropagation(); e.stopPropagation();
$state.go('modal.link', {url: genPermalink()}); $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) { $scope.embed = function(e) {
e.stopPropagation(); e.stopPropagation();
// Make a request to goo.gl to shorten the URL, returns a promise
var promise = Utils.shortenUrl( genPermalink()).then( var promise = Utils.shortenUrl( genPermalink()).then(
function (shortUrl) { function (shortUrl) {
return Utils.comparisonBBCode(facets, $scope.builds, 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'}); $state.go('modal.export', {promise: promise, title:'Forum BBCode'});
}; };
/**
* Generates the long permalink URL
* @return {string} The long permalink URL
*/
function genPermalink() { function genPermalink() {
var selectedFacets = []; var selectedFacets = [];
facets.forEach(function(f) { facets.forEach(function(f) {
@@ -202,11 +225,10 @@ angular.module('app').controller('ComparisonController', ['lodash', '$rootScope'
throw { type: 'bad-comparison', message: e.message, details: e }; throw { type: 'bad-comparison', message: e.message, details: e };
} }
} }
// Replace fmt with actual format function as defined in rootScope and retain original index // 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; }); 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 // 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); }); _.pullAt(facets, defaultFacets).forEach(function (f) { f.active = true; facets.unshift(f); });
$scope.builds = $filter('orderBy')($scope.builds, $scope.predicate, $scope.desc);
}]); }]);

View File

@@ -12,18 +12,15 @@ angular.module('app')
$scope.msgPost = 'Not Found'; $scope.msgPost = 'Not Found';
break; break;
case 'no-ship': case 'no-ship':
//$rootScope.bodyClass = 'docking-bay';
$scope.msgPre = 'Ship'; $scope.msgPre = 'Ship';
$scope.msgHighlight = $p.message; $scope.msgHighlight = $p.message;
$scope.msgPost = 'does not exist'; $scope.msgPost = 'does not exist';
break; break;
case 'build-fail': case 'build-fail':
//$rootScope.bodyClass = 'ship-explode'; // TODO: create background imag for this
$scope.msgPre = 'Build Failure!'; $scope.msgPre = 'Build Failure!';
$scope.details = $p.details; $scope.details = $p.details;
break; break;
default: default:
//$rootScope.bodyClass = 'thargoid'; // TODO: create background imag for this
$scope.msgPre = "Uh, Jameson, we have a problem.."; $scope.msgPre = "Uh, Jameson, we have a problem..";
$scope.errorMessage = $p.message; $scope.errorMessage = $p.message;
$scope.details = $p.details; $scope.details = $p.details;

View File

@@ -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}); $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.bnChange = function(){
$scope.savedCode = Persist.getBuild(ship.id, $scope.buildName); $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) { $scope.toggleCost = function(item) {
item.incCost = !item.incCost; item.incCost = !item.incCost;
ship.updateTotals(); ship.updateTotals();
}; };
/**
* Toggle the power on/off for the selected component
* @param {object} item The component being toggled
*/
$scope.togglePwr = function(item) { $scope.togglePwr = function(item) {
item.enabled = !item.enabled; item.enabled = !item.enabled;
ship.updateTotals(); ship.updateTotals();

View File

@@ -28,11 +28,15 @@ angular.module('app').directive('shipyardHeader', ['lodash','$window','$rootScop
scope.openedMenu = null; scope.openedMenu = null;
}); });
// Listen to close event to close opened menus or modals
$rootScope.$on('close', function () { $rootScope.$on('close', function () {
scope.openedMenu = null; scope.openedMenu = null;
$rootScope.showAbout = false; $rootScope.showAbout = false;
}); });
/**
* Save selected insurance option in localstorage
*/
scope.updateInsurance = function(){ scope.updateInsurance = function(){
$window.localStorage.setItem('insurance', $rootScope.insurance.current.name); $window.localStorage.setItem('insurance', $rootScope.insurance.current.name);
}; };

View File

@@ -72,7 +72,16 @@ angular.module('app').service('Persist', ['$window','lodash', function ($window,
} }
// Persist updated build collection to localStorage // Persist updated build collection to localStorage
localStorage.setItem(LS_KEY_BUILDS, angular.toJson(this.builds)); 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
}
}
}
} }
}; };

View File

@@ -1,6 +1,6 @@
{ {
"name": "coriolis_shipyard", "name": "coriolis_shipyard",
"version": "0.7.5", "version": "0.7.7",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/cmmcleod/coriolis" "url": "https://github.com/cmmcleod/coriolis"