-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2568 from SEED-platform/feat/ui-delete-cycle
feat: add ui for deleting cycles
- Loading branch information
Showing
8 changed files
with
144 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
seed/static/seed/js/controllers/delete_cycle_modal_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* :copyright (c) 2014 - 2020, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Department of Energy) and contributors. All rights reserved. | ||
* :author | ||
*/ | ||
angular.module('BE.seed.controller.delete_cycle_modal', []) | ||
.controller('delete_cycle_modal_controller', [ | ||
'$scope', | ||
'$window', | ||
'$state', | ||
'$q', | ||
'$uibModalInstance', | ||
'inventory_service', | ||
'cycle_service', | ||
'cycle_id', | ||
'cycle_name', | ||
function ($scope, $window, $state, $q, $uibModalInstance, inventory_service, cycle_service, cycle_id, cycle_name) { | ||
$scope.cycle_id = cycle_id; | ||
$scope.cycle_name = cycle_name; | ||
|
||
$scope.cycle_has_properties = null; | ||
$scope.cycle_has_taxlots = null; | ||
$scope.cycle_has_inventory = null; | ||
$scope.delete_cycle_success = null; | ||
|
||
// determine if there are any properties or tax lots in the cycle | ||
// when fetching inventory, to reduce overhead ask for only 1 inventory per page and first page | ||
$q.all([ | ||
inventory_service.get_properties(1, 1, {id: $scope.cycle_id}, null, null, false), | ||
inventory_service.get_taxlots(1, 1, {id: $scope.cycle_id}, null, null, false) | ||
]).then(function(responses) { | ||
$scope.cycle_has_properties = responses[0].results.length > 0; | ||
$scope.cycle_has_taxlots = responses[1].results.length > 0; | ||
$scope.cycle_has_inventory = $scope.cycle_has_properties || $scope.cycle_has_taxlots; | ||
}); | ||
|
||
// open an inventory list page in a new tab | ||
$scope.goToInventoryList = function(inventory_type) { | ||
inventory_service.save_last_cycle($scope.cycle_id); | ||
const inventory_url = $state.href('inventory_list', {inventory_type: inventory_type}); | ||
$window.open(inventory_url,'_blank'); | ||
}; | ||
|
||
$scope.cancel = function () { | ||
$uibModalInstance.dismiss(); | ||
}; | ||
|
||
// user confirmed deletion of cycle | ||
$scope.confirmDelete = function () { | ||
cycle_service.delete_cycle($scope.cycle_id) | ||
.then(function(res) { | ||
$scope.delete_cycle_success = true; | ||
}) | ||
.catch(function(res) { | ||
console.error('Failed to delete cycle: ') | ||
console.error(res) | ||
$scope.delete_cycle_success = false; | ||
}) | ||
}; | ||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<div class="modal-header"> | ||
<h4 class="modal-title" translate>Delete Cycle?</h4> | ||
</div> | ||
<div class="modal-body"> | ||
<div ng-if="cycle_has_inventory == null" class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-sm-12"> | ||
<i class="fa fa-spinner fa-pulse fa-fw" style="padding-right: 0"></i>Searching for Properties and Tax Lots in this Cycle... | ||
</div> | ||
</div> | ||
</div> | ||
<div ng-if="cycle_has_inventory == true" class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-sm-12"> | ||
Unable to delete cycle <em>{$ cycle_name $}</em>. You must delete all existing Properties and Tax Lots in <em>{$ cycle_name $}</em> before you can delete this cycle. | ||
</div> | ||
</div> | ||
<div ng-if="cycle_has_properties == true" class="row"> | ||
<div class="col-sm-8 col-sm-offset-2" style="padding-top: 5px; padding-bottom: 5px;"> | ||
<button type="button" class="btn btn-info" ng-click="goToInventoryList('properties')">View Properties in this cycle</a> | ||
</div> | ||
</div> | ||
<div ng-if="cycle_has_taxlots == true" class="row"> | ||
<div class="col-sm-8 col-sm-offset-2" style="padding-top: 5px;"> | ||
<button type="button" class="btn btn-info" ng-click="goToInventoryList('taxlots')">View Tax Lots in this cycle</a> | ||
</div> | ||
</div> | ||
</div> | ||
<div ng-if="cycle_has_inventory == false && delete_cycle_success == null" class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-sm-12"> | ||
Are you sure you want to delete cycle <em>{$ cycle_name $}</em>? It has no Property or Tax Lot data. | ||
</div> | ||
</div> | ||
</div> | ||
<div ng-if="delete_cycle_success == true" class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-sm-12"> | ||
Successfully deleted <em>{$ cycle_name $}</em>. | ||
</div> | ||
</div> | ||
</div> | ||
<div ng-if="delete_cycle_success == false" class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-sm-12"> | ||
Sorry, something unexpected happened. Please refresh the page and try again. If the problem persists please contact the SEED Platform management team. | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-default" ng-click="cancel()">{$delete_cycle_success == null ? 'Cancel' : 'Close'$}</button> | ||
<button ng-if="cycle_has_inventory == false && delete_cycle_success == null" type="button" class="btn btn-danger" ng-click="confirmDelete()" autofocus translate>Yes, Delete Cycle</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters