Skip to content

Commit

Permalink
Allow updating ebp allowed organizations
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxvd committed Jan 8, 2025
1 parent 7f7d08c commit 7c863fc
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 2 deletions.
41 changes: 41 additions & 0 deletions client/scripts/controllers/EBPOrganizationsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require('../app').controller('EBPOrganizationsController', /* @ngInject */function ($scope, db, api, ngToast) {
const $ctrl = this
$ctrl.organizations = Object.values(db.organizations).map(
function (organization) {
return {
slug: organization.slug,
label: organization.toString(),
allowed: false
}
}
)

$ctrl.requestAllowedOrganizations = function () {
api.ebp.allowedOrganizations().then(function (res) {
$ctrl.organizations.forEach(function (organization) {
organization.allowed = res.includes(organization.slug)
})
})
}

$ctrl.save = function () {
const allowed = $ctrl.organizations
.filter(function (organization) {
return organization.allowed
})
.map(function (organization) {
return organization.slug
})
api.ebp.updateAllowedOrganizations(allowed).then(function () {
$scope.editform.$setPristine()
ngToast.create(
{
className: 'success',
content: 'Organizations updated'
})
$ctrl.requestAllowedOrganizations()
})
}

$ctrl.requestAllowedOrganizations()
})
2 changes: 1 addition & 1 deletion client/scripts/controllers/EBPSettingsController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require('../app').controller('EBPSettingsController', /* @ngInject */function ($scope, $q, $stateParams, EBPSpecies) {
require('../app').controller('EBPSettingsController', /* @ngInject */function ($scope, $stateParams) {
const $ctrl = this

$ctrl.selected = 'sources'
Expand Down
24 changes: 24 additions & 0 deletions client/scripts/services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,30 @@ require('../app').service('api', /* @ngInject */function ($log, $http, $resource
}
}

api.ebp = {
allowedOrganizations: function () {
return $http({
method: 'GET',
url: ENDPOINT_URL + '/ebp/organizations',
withCredentials: true
}).then(function (response) {
return response.data
})
},
updateAllowedOrganizations: function (allowed) {
return $http({
method: 'PUT',
url: ENDPOINT_URL + '/ebp/organizations',
data: {
items: allowed
},
withCredentials: true
}).then(function (response) {
return response.data
})
}
}

api.reports = {
daily: (date) => $http({
method: 'GET',
Expand Down
55 changes: 54 additions & 1 deletion client/views/ebp/organizations.html
Original file line number Diff line number Diff line change
@@ -1 +1,54 @@
<div>Organizations</div>
<div ng-controller="EBPOrganizationsController as $ctrl">
<form name="editform"
role="form"
class="table-responsive"
confirm-on-exit="editform.$dirty"
confirm-message-window="{{'SPECIES_UNSAVED_DATA_TITLE' | translate}}"
confirm-message-route="{{'SPECIES_UNSAVED_DATA_MESSAGE' | translate}}">
<table class="table table-hover table-striped table-responsive">
<thead>
<tr>
<th>#</th>
<th>Organization</th>
<th>Allowed</th>
<th class="btn-group btn-group-xs">
<button ng-disabled="editform.$pristine"
type="button"
class="btn btn-success btn-xs"
title="{{'SPECIES_BUTTON_SAVE' | translate}}"
ng-click="$ctrl.save()">
<i class="fa fa-check fa-fw"></i>
</button>
</th>
</tr>
</thead>
<tbody>
<tr class="hover" ng-repeat="item in $ctrl.organizations track by item.slug">
<td>{{$index}}</td>
<td>
{{item.label }}
</td>
<td colspan="2">
<input type="checkbox" ng-model="item.allowed" />
</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>#</th>
<th>Organization</th>
<th>Allowed</th>
<th class="btn-group btn-group-xs">
<button ng-disabled="editform.$pristine"
type="button"
class="btn btn-success btn-xs"
title="{{'SPECIES_BUTTON_SAVE' | translate}}"
ng-click="$ctrl.save()">
<i class="fa fa-check fa-fw"></i>
</button>
</th>
</tr>
</tfoot>
</table>
</form>
</div>

0 comments on commit 7c863fc

Please sign in to comment.