Skip to content

Commit

Permalink
feat(odk): implement ODK Central Link
Browse files Browse the repository at this point in the history
This commit implements the ODK Central link with BHIMA, developped
during the `prosani-sprint`.  The goal is to have a functional, optional
link to ODK Central that can be merged into the BHIMA repository.

Closes #6235.
  • Loading branch information
jniles committed Jan 28, 2022
1 parent 39ceb33 commit 774b12a
Show file tree
Hide file tree
Showing 20 changed files with 1,087 additions and 23 deletions.
6 changes: 4 additions & 2 deletions client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"CANCEL_EDIT": "Cancel Edit",
"CASHBOX_MANAGEMENT": "Cashbox Management",
"CLEAR": "Clear",
"SYNC" : "Sync",
"CLEAR_GRID_CONFIGURATION": "Clear Grid Configuration",
"CLOSE": "Close",
"COLLAPSE_RECORDS" : "Collapse Records",
Expand Down Expand Up @@ -552,8 +553,7 @@
"LAST_NAME": "Last Name",
"LAST_PAGE": "Last Page Visited",
"LATITUDE": "Latitude",
"LEGEND" : "Legend",
"LEVEL_OF_STUDY" : "Level of study",
"LEVEL_OF_STUDY" : "Level of study",
"LIMIT": "Limit",
"LIST_STRUCTURE": "List structure",
"LOCATION_REGISTER": "Location Register",
Expand Down Expand Up @@ -911,6 +911,7 @@
"CASHBOX": "Enter the cashbox",
"CHOICE_FILTER": "Choice Filter",
"CODE": "Enter code",
"CONDITION": "Condition",
"COUNTRY": "Enter country",
"CREDITOR": "Enter creditor",
"CURRENCY": "Select currency",
Expand All @@ -920,6 +921,7 @@
"DEFAULT_PURCHASE_ORDER_INTERVAL": "The default purchase order interval for calculating Maximum stock",
"DESCRIPTION": "Enter description",
"DOCUMENT_NAME": "Enter document name",
"ORIGIN": "Origin",
"PATIENT_GROUP": "Enter patient group",
"EMAIL": "Enter email",
"LOT":"Enter Batch Number",
Expand Down
25 changes: 25 additions & 0 deletions client/src/i18n/en/odk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"ODK" : {
"CONFIG_SETTINGS" : "ODK Central Configuration",
"IMPORTED_SUCCESSFULLY" : "Records successfully imported",
"LOAD_FOSA_DATA" : "Load data of FOSA",
"NO_RECORD_FOUND" : "No record found",
"ODK_ADMIN_PASSWORD" : "ODK Central Admin Password",
"ODK_ADMIN_USER" : "ODK Central Admin Email",
"ODK_CENTRAL_URL" : "ODK Central Server URL",
"ODK_INTEGRATION_SETTINGS" : "ODK Integration Settings",
"PROJECT_DETAILS" : "Project Details",
"PROJECT_FORMS" : "Number of Forms",
"PROJECT_ID" : "Project ID",
"PROJECT_NAME" : "Project Name",
"QRCODE" : "ODK QR Code",
"SHOW_QRCODE" : "Show QR Code",
"SYNC_ENTERPRISE" : "Synchronize enterprise settings",
"SYNC_FORMS" : "Synchronize forms",
"SYNC_SETTINGS" : "Synchronization Settings",
"SYNC_SUBMISSIONS" : "Synchronize submissions",
"SYNC_USERS" : "Synchronize users",
"TOTAL_APP_USERS" : "Number of App Users",
"TOTAL_FOUND" : "Total records found"
}
}
1 change: 1 addition & 0 deletions client/src/i18n/en/tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
"STOCK_REPORT" : "Stock Inventories",
"STOCK_REQUISITION":"Requisition",
"STOCK_SETTINGS": "Stock Settings",
"ODK_SETTINGS" : "ODK Settings",
"STOCK" : "Stock",
"STOCK_VALUE" : "Stock Value Report",
"SUBSIDY" : "Subsidy Management",
Expand Down
6 changes: 4 additions & 2 deletions client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"BACK": "Précédent",
"BREAKDOWNS_PERCENTAGES": "Ventilation en pourcentage",
"CANCEL": "Annuler",
"SYNC" : "Synchroniser",
"CANCEL_EDIT": "Annuler Modifier",
"CASHBOX_MANAGEMENT": "Gestion des Caisses",
"CLEAR": "Effacer",
Expand Down Expand Up @@ -556,8 +557,7 @@
"LAST_NAME": "Nom",
"LAST_PAGE": "La dernière page visitée",
"LATITUDE": "Latitude",
"LEGEND" : "Legende",
"LEVEL_OF_STUDY" : "Niveau d'étude",
"LEVEL_OF_STUDY" : "Niveau d'étude",
"LIMIT": "Limite",
"LIST_STRUCTURE": "Liste",
"LOCATION_REGISTER": "Enregistrer une localisation",
Expand Down Expand Up @@ -913,6 +913,7 @@
"CHOICE_FILTER": "Filtre",
"CODE": "Entrer le code",
"COUNTRY": "Entrer le nom du pays",
"CONDITION": "Condition",
"CREDITOR": "Entrer un Créditeur",
"CURRENCY": "Sélectionner la monnaie",
"DEBTOR": "Entrer un Débiteur",
Expand All @@ -929,6 +930,7 @@
"MAX_CREDIT": "Entrer le crédit maximale",
"NAME": "Entrer le nom",
"NOTES": "Commentaire",
"ORIGIN": "Origine",
"PASSWORD": "Entrer le mot de passe",
"PATIENT_ID": "Entrer identifiant patient",
"PATIENT_NAME": "Entrer nom patient",
Expand Down
25 changes: 25 additions & 0 deletions client/src/i18n/fr/odk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"ODK" : {
"CONFIG_SETTINGS" : "ODK Central Configuration",
"IMPORTED_SUCCESSFULLY" : "Données importées avec succès",
"LOAD_FOSA_DATA" : "Chargement des données des FOSA",
"NO_RECORD_FOUND" : "Aucun enregistrement trouvé",
"ODK_ADMIN_PASSWORD" : "Mot de passe de l'administrateur",
"ODK_ADMIN_USER" : "Adressse mail de l'administrateur",
"ODK_CENTRAL_URL" : "URL du serveur ODK Central",
"ODK_INTEGRATION_SETTINGS" : "Paramètres d'intégration ODK",
"PROJECT_DETAILS" : "Détails du projet",
"PROJECT_FORMS" : "Nombre de formulaire",
"PROJECT_ID" : "ID Projet",
"PROJECT_NAME" : "Nom du projet",
"QRCODE" : "ODK QR Code",
"SHOW_QRCODE" : "Afficher QR Code",
"SYNC_ENTERPRISE" : "Synchroniser les paramètres d'entreprise",
"SYNC_FORMS" : "Synchroniser les formulaires",
"SYNC_SETTINGS" : "Synchroniser les paramètres",
"SYNC_SUBMISSIONS" : "Synchroniser les soumissions des formulaires",
"SYNC_USERS" : "Synchroniser les utilisateurs",
"TOTAL_APP_USERS" : "Nombre des utilisateurs mobiles",
"TOTAL_FOUND" : "Total des enregistrements trouvés"
}
}
1 change: 1 addition & 0 deletions client/src/i18n/fr/tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
"STOCK_REQUISITION":"Réquisition",
"STOCK_MOVEMENT_REPORT": "Rapport graphique des mouvements",
"STOCK_SETTINGS": "Paramètres de stock",
"ODK_SETTINGS" : "Paramètres de l'ODK",
"SUBSIDY":"Gestion des subventions",
"TAGS" : "Gestion des étiquettes",
"TRANSACTION_TYPE":"Types de Transaction",
Expand Down
139 changes: 139 additions & 0 deletions client/src/modules/odk-settings/odk-settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<div class="flex-header">
<div class="bhima-title">
<ol class="headercrumb">
<li class="static" translate>TREE.ADMIN</li>
<li class="title" translate>TREE.ODK_SETTINGS</li>
</ol>
</div>
</div>

<div class="flex-content">
<div class="container-fluid">
<div class="col-xs-12 col-md-6 col-lg-4">
<form
name="ODKSettingsForm"
bh-submit="ODKSettingsCtrl.submit(ODKSettingsForm)"
ng-model-options="{ updateOn: 'blur' }" novalidate>
<div class="panel panel-primary">
<div class="panel-heading">
<i class="fa fa-server"></i>
<span translate>ODK.ODK_INTEGRATION_SETTINGS</span>
</div>
<div class="panel-body">
<div class="form-group" ng-class="{ 'has-error' : ODKSettingsForm.$submitted && ODKSettingsForm.odk_central_url.$invalid }">
<label class="control-label" translate>ODK.ODK_CENTRAL_URL</label>
<input
type="text"
class="form-control"
name="odk_central_url"
ng-model="ODKSettingsCtrl.settings.odk_central_url"
autocomplete="off">
<div class="help-block" ng-messages="ODKSettingsForm.odk_central_url.$error" ng-show="ODKSettingsForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>

<div class="form-group" ng-class="{ 'has-error' : ODKSettingsForm.$submitted && ODKSettingsForm.odk_admin_user.$invalid }">
<label class="control-label" translate>ODK.ODK_ADMIN_USER</label>
<input
type="email"
class="form-control"
name="odk_admin_user"
ng-model="ODKSettingsCtrl.settings.odk_admin_user"
autocomplete="off"
ng-required="!!ODKSettings.settings.odk_central_url">
<div class="help-block" ng-messages="ODKSettingsForm.odk_admin_user.$error" ng-show="ODKSettingsForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>

<div class="form-group" ng-class="{ 'has-error' : ODKSettingsForm.$submitted && ODKSettingsForm.odk_admin_password.$invalid }">
<label class="control-label" translate>ODK.ODK_ADMIN_PASSWORD</label>
<input
type="password"
class="form-control"
name="odk_admin_password"
ng-model="ODKSettingsCtrl.settings.odk_admin_password"
autocomplete="off"
ng-required="!!ODKSettings.settings.odk_admin_user">
<div class="help-block" ng-messages="ODKSettingsForm.odk_admin_password.$error" ng-show="ODKSettingsForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>
</div>
<div class="panel-footer text-right">
<bh-loading-button loading-state="ODKSettingsForm.$loading">
<span translate>FORM.BUTTONS.UPDATE</span>
</bh-loading-button>
</div>
</div>
</div>
</form>


<div class="col-xs-12 col-md-6 col-lg-4">
<div class="panel panel-danger">
<div class="panel-heading">
<i class="fa fa-cloud-upload"></i>
<span translate>ODK.SYNC_SETTINGS</span>
</div>

<div class="panel-body">
<div class="form-group">
<label class="control-label" translate>ODK.SYNC_ENTERPRISE</label>
<button type="button" class="btn btn-default btn-xs pull-right" ng-click="ODKSettingsCtrl.syncEnterprise()" translate>FORM.BUTTONS.SYNC</button>
</div>

<hr>

<div class="form-group">
<label class="control-label" translate>ODK.SYNC_USERS</label>
<button type="button" class="btn btn-default btn-xs pull-right" ng-click="ODKSettingsCtrl.syncUsers()" translate>FORM.BUTTONS.SYNC</button>
</div>


<hr>

<div class="form-group">
<label class="control-label" translate>ODK.SYNC_FORMS</label>
<button type="button" class="btn btn-default btn-xs pull-right" ng-click="ODKSettingsCtrl.syncForms()" translate>FORM.BUTTONS.SYNC</button>
</div>

<hr>

<div class="form-group">
<label class="control-label" translate>ODK.SYNC_SUBMISSIONS</label>
<button type="button" class="btn btn-default btn-xs pull-right" ng-click="ODKSettingsCtrl.syncSubmissions()" translate>FORM.BUTTONS.SYNC</button>
</div>

</div>
</div>
</div>

<div class="col-xs-12 col-md-6 col-lg-4">
<div class="panel panel-success">
<div class="panel-heading">
<i class="fa fa-cogs"></i>
<span translate>ODK.CONFIG_SETTINGS</span>
</div>

<div class="panel-body">
<div ng-show="ODKSettingsCtrl.loading" class="text-center">
<loading-indicator></loading-indicator>
</div>
<dl ng-hide="ODKSettingsCtrl.loading">
<dt translate>ODK.PROJECT_DETAILS</dt>
<dd><span translate>ODK.PROJECT_NAME</span>: {{ODKSettingsCtrl.project.name}} </dd>
<dd><span translate>ODK.PROJECT_ID</span>: {{ODKSettingsCtrl.project.id}} </dd>
<dd><span translate>ODK.PROJECT_FORMS</span>: {{ODKSettingsCtrl.project.forms}} </dd>
<dd><span translate>FORM.LABELS.CREATED</span>: {{ODKSettingsCtrl.project.createdAt | date}} </dd>
<dd><span translate>ODK.TOTAL_APP_USERS</span>: {{ODKSettingsCtrl.appUsers.length | number}} </dd>
</dl>
</div>

</div>
</div>


</div>
</div>
103 changes: 103 additions & 0 deletions client/src/modules/odk-settings/odk-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
angular.module('bhima.controllers')
.controller('ODKSettingsController', ODKSettingsController);

ODKSettingsController.$inject = [
'ODKSettingsService', 'util', 'NotifyService', 'SessionService', '$state',
];

/**
* ODK Settings Controller
*
* Provides configuration parameters for the link to ODK.
*/
function ODKSettingsController(
ODKSettings, util, Notify, Session, $state,
) {
const vm = this;

vm.enterprise = Session.enterprise;
vm.settings = { };

// bind methods
vm.submit = submit;
vm.syncEnterprise = () => {
ODKSettings.syncEnterprise()
.then(() => { $state.reload(); })
.catch(Notify.handleError);
};

vm.syncUsers = () => {
ODKSettings.syncUsers()
.then(() => ODKSettings.syncAppUsers())
.then(() => { $state.reload(); })
.catch(Notify.handleError);
};

vm.syncForms = () => {
ODKSettings.syncForms()
.then(() => { $state.reload(); })
.catch(Notify.handleError);
};

vm.syncSubmissions = () => {
ODKSettings.syncSubmissions()
.then(() => { $state.reload(); })
.catch(Notify.handleError);
};

// fired on startup
function startup() {
ODKSettings.read()
.then(settings => {
if (settings.length > 0) {
[vm.settings] = settings;
}
})
.catch(Notify.handleError);

vm.loading = true;

ODKSettings.getProjectSettings()
.then(project => {
vm.project = project;
})
.catch(Notify.handleError)
.finally(() => { vm.loading = false; });

ODKSettings.getAppUsers()
.then(appUsers => {
vm.appUsers = appUsers;
})
.catch(Notify.handleError)
.finally(() => { vm.loading = false; });

// ODKSettings.getUserSettings()
// .then(users => {
// vm.users = users;
// })
// .catch(Notify.handleError);
}

// form submission
function submit(form) {
if (form.$invalid) {
Notify.danger('FORM.ERRORS.HAS_ERRORS');
return 0;
}

// make sure only fresh data is sent to the server.
if (form.$pristine) {
Notify.warn('FORM.WARNINGS.NO_CHANGES');
return 0;
}

const changes = angular.copy(vm.settings);

return ODKSettings.create(changes)
.then(() => Notify.success('FORM.INFO.UPDATE_SUCCESS'))
.then(() => $state.reload()) // Should we just refresh the stock settings in the Session?
.catch(Notify.handleError);
}

startup();
}
9 changes: 9 additions & 0 deletions client/src/modules/odk-settings/odk-settings.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
angular.module('bhima.routes')
.config(['$stateProvider', $stateProvider => {
$stateProvider
.state('odkSettings', {
url : '/admin/odk-settings',
controller : 'ODKSettingsController as ODKSettingsCtrl',
templateUrl : 'modules/odk-settings/odk-settings.html',
});
}]);
Loading

0 comments on commit 774b12a

Please sign in to comment.