Skip to content

Commit

Permalink
Fix organization delete - ensure there is a chance to confirm and tha…
Browse files Browse the repository at this point in the history
…t it works in one step. (#4851)

* new confirm modal for removing organizations, rearrange inventory deletion so as to not try to remove org before the org is empty

* linting

* update translations and css

* lint

---------

Co-authored-by: Alex Swindler <[email protected]>
Co-authored-by: Katherine Fleming <[email protected]>
  • Loading branch information
3 people authored Dec 10, 2024
1 parent 207b4e6 commit b6bf91d
Show file tree
Hide file tree
Showing 18 changed files with 872 additions and 77 deletions.
Binary file modified locale/en_US/LC_MESSAGES/django.mo
Binary file not shown.
153 changes: 153 additions & 0 deletions locale/en_US/LC_MESSAGES/django.po

Large diffs are not rendered by default.

Binary file modified locale/es/LC_MESSAGES/django.mo
Binary file not shown.
155 changes: 154 additions & 1 deletion locale/es/LC_MESSAGES/django.po

Large diffs are not rendered by default.

Binary file modified locale/fr_CA/LC_MESSAGES/django.mo
Binary file not shown.
153 changes: 153 additions & 0 deletions locale/fr_CA/LC_MESSAGES/django.po

Large diffs are not rendered by default.

49 changes: 26 additions & 23 deletions seed/static/seed/js/controllers/admin_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ angular.module('SEED.controller.admin', []).controller('admin_controller', [
'users_payload',
'Notification',
'$window',
'urls',
'$translate',
// eslint-disable-next-line func-names
function (
Expand All @@ -34,6 +35,7 @@ angular.module('SEED.controller.admin', []).controller('admin_controller', [
users_payload,
Notification,
$window,
urls,
$translate
) {
$scope.is_superuser = auth_payload.auth.requires_superuser;
Expand Down Expand Up @@ -286,30 +288,31 @@ angular.module('SEED.controller.admin', []).controller('admin_controller', [
}
};

$scope.delete_org = (org) => {
org.progress = 0;
organization_service.delete_organization(org.org_id).then((data) => {
uploader_service.check_progress_loop(
data.progress_key,
0,
1,
() => {
org.remove_message = 'success';
if (parseInt(org.id, 10) === parseInt(user_service.get_organization().id, 10)) {
// Reload page if deleting current org.
$window.location.reload();
} else {
get_organizations().then(() => {
$scope.$emit('organization_list_updated');
});
}
},
() => {
// Do nothing
},
org
);
$scope.confirm_delete_org = (org) => {
const modal_instance = $uibModal.open({
templateUrl: `${urls.static_url}seed/partials/confirm_organization_deletion_modal.html`,
controller: 'confirm_organization_deletion_modal_controller',
size: 'md',
resolve: {
org: () => org
}
});

modal_instance.result
.then(() => {
org.remove_message = 'success';
if (parseInt(org.id, 10) === parseInt(user_service.get_organization().id, 10)) {
// Reload page if deleting current org.
$window.location.reload();
} else {
get_organizations().then(() => {
$scope.$emit('organization_list_updated');
});
}
})
.catch(() => {

});
};

process_organizations(organizations_payload);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
* SEED Platform (TM), Copyright (c) Alliance for Sustainable Energy, LLC, and other contributors.
* See also https://github.com/SEED-platform/seed/blob/main/LICENSE.md
*/
angular.module('SEED.controller.confirm_organization_deletion_modal', []).controller('confirm_organization_deletion_modal_controller', [
'$scope',
'$state',
'$uibModalInstance',
'org',
'organization_service',
'$interval',
'uploader_service',
'$window',
'$log',
// eslint-disable-next-line func-names
function (
$scope,
$state,
$uibModalInstance,
org,
organization_service,
$interval,
uploader_service,
$window,
$log
) {
$scope.org = org;
$scope.step = {
number: 1
};

$scope.progressBar = {
progress: 0
};

$scope.goto_step = (step) => {
$scope.step.number = step;
};

$scope.confirm_and_delete_org = () => {
$scope.state = 'pending';
organization_service.delete_organization(org.org_id)
.then((result) => {
$scope.state = 'evaluating';
$scope.interval = $interval(() => {
if ($scope.state === 'running') {
$scope.updateTime();
} else {
$scope.setRunningState();
}
}, 1000);
$scope.updateTime();
uploader_service.check_progress_loop(
result.progress_key,
0,
1,
() => {
$scope.result = `Completed in ${$scope.elapsed}`;
$scope.state = 'done';
$interval.cancel($scope.interval);
},
() => {
// Do nothing
},
$scope.progressBar
);
})
.catch((err) => {
$log.error(err);
$scope.result = 'Failed to remove organiazation';
$scope.state = 'done';
$interval.cancel($scope.interval);
});
};

$scope.cancel = () => {
$uibModalInstance.dismiss();
};

$scope.elapsedFn = () => {
const diff = moment().diff($scope.startTime);
return $scope.formatTime(moment.duration(diff));
};

$scope.etaFn = () => {
if ($scope.progressBar.completed_records) {
if (!$scope.initialCompleted) {
$scope.initialCompleted = $scope.progressBar.completed_records;
}
const diff = moment().diff($scope.startTime);
const progress = ($scope.progressBar.completed_records - $scope.initialCompleted) / ($scope.progressBar.total_records - $scope.initialCompleted);
if (progress) {
return $scope.formatTime(moment.duration(diff / progress - diff));
}
}
};

$scope.setRunningState = () => {
$scope.eta = $scope.etaFn();
if ($scope.eta) {
$scope.state = 'running';
$scope.startTime = moment();
}
};

$scope.updateTime = () => {
$scope.elapsed = $scope.elapsedFn();
$scope.eta = $scope.etaFn();
};

$scope.formatTime = (duration) => {
const h = Math.floor(duration.asHours());
const m = duration.minutes();
const s = duration.seconds();

if (h > 0) {
const mPadded = m.toString().padStart(2, '0');
const sPadded = s.toString().padStart(2, '0');
return `${h}:${mPadded}:${sPadded}`;
}
if (m > 0) {
const sPadded = s.toString().padStart(2, '0');
return `${m}:${sPadded}`;
}
return `${s}s`;
};

$scope.refresh = () => {
$window.onbeforeunload = null;
$window.location.reload();
};

$scope.org_name = () => $scope.org.name;
}

]);
1 change: 1 addition & 0 deletions seed/static/seed/js/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'SEED.controller.column_mappings',
'SEED.controller.column_settings',
'SEED.controller.confirm_column_settings_modal',
'SEED.controller.confirm_organization_deletion_modal',
'SEED.controller.create_column_modal',
'SEED.controller.create_organization_modal',
'SEED.controller.create_sub_organization_modal',
Expand Down
Loading

0 comments on commit b6bf91d

Please sign in to comment.