Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOTECH-2732 Migrated module install Workflow #39

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions src/admin/bundles/bundle-install.directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
(function () {
'use-strict';

angular.module('motech-admin')
.directive('installModules', moduleInstall);

moduleInstall.$inject = ['ServerService'];
function moduleInstall(ServerService) {
return {
restrict: 'E',
templateUrl: '/admin/bundles/install-modules.html',
controller: controller,
link: function (scope) {
scope.startOnUpload = function () {
if (scope.startUpload !== true) {
scope.startUpload = true;
$('.start-on-upload').find('i').removeClass("fa-square-o").addClass('fa-check-square-o');
} else {
scope.startUpload = false;
$('.start-on-upload').find('i').removeClass("fa-check-square-o").addClass('fa-square-o');
}
};
}
};
}

controller.$inject = ['$scope', '$rootScope', '$timeout', '$state', 'BundlesFactory', 'LoadingModal', 'ModalFactory', 'ModalWindow', 'ServerService'];
function controller($scope, $rootScope, $timeout, $state, BundlesFactory, LoadingModal, ModalFactory, ModalWindow, ServerService) {
$scope.moduleSources = [
'Repository',
'File'
];
$scope.startUpload = true;
$scope.moduleSource = $scope.moduleSources[0];
var MODULE_LIST_REFRESH_TIMEOUT = 6000;

$scope.mavenStr = function (artifactId) {
return 'org.motechproject:'.concat(artifactId).concat(':').concat($rootScope.msg('server.version'));
};

$scope.modules = {};
$scope.modules[$scope.mavenStr('alerts')] = 'Alerts';
$scope.modules[$scope.mavenStr('appointments')] = 'Appointments';
$scope.modules[$scope.mavenStr('atom-client')] = 'Atom Client';
$scope.modules[$scope.mavenStr('csd')] = 'Care Services Directory';
$scope.modules[$scope.mavenStr('cms-lite')] = 'CMS Lite';
$scope.modules[$scope.mavenStr('commcare')] = 'Commcare';
$scope.modules[$scope.mavenStr('dhis2')] = 'DHIS2';
$scope.modules[$scope.mavenStr('event-logging')] = 'Event Logging';
$scope.modules[$scope.mavenStr('http-agent')] = 'Http Agent';
$scope.modules[$scope.mavenStr('ihe-interop')] = 'IHE Interop';
$scope.modules[$scope.mavenStr('ivr')] = 'IVR';
$scope.modules[$scope.mavenStr('message-campaign')] = 'Message Campaign';
$scope.modules[$scope.mavenStr('metrics')] = 'Metrics';
$scope.modules[$scope.mavenStr('mtraining')] = 'mTraining';
$scope.modules[$scope.mavenStr('motech-tasks')] = 'Tasks';
$scope.modules[$scope.mavenStr('odk')] = 'Open Data Kit';
$scope.modules[$scope.mavenStr('openmrs')] = 'OpenMRS';
$scope.modules[$scope.mavenStr('pill-reminder')] = 'Pill Reminder';
$scope.modules[$scope.mavenStr('motech-scheduler')] = 'Scheduler';
$scope.modules[$scope.mavenStr('schedule-tracking')] = 'Schedule Tracking';
$scope.modules[$scope.mavenStr('sms')] = 'SMS';

$scope.module = "";

$scope.submitBundle = function () {
$("#bundleUploadForm").submit(function(event){
if (!$scope.isNoModuleOrFileSelected()) {
LoadingModal.open();

var formData = {
moduleSource: $scope.moduleSource,
moduleId: $scope.module,
file: $('#bundleUploadForm input[name=file]').val(),
startBundle: $scope.startBundle
},
url = "/module/admin/api/bundles/upload";

url = ServerService.formatURL(url);

$.ajax({
type: 'POST',
data: formData,
url: url
}).done(function (data, status, xhr) {
if (xhr.status === 0 && data) {
ModalFactory.showErrorWithStackTrace('admin.error', 'admin.bundles.error.start', data);
LoadingModal.close();
} else {
$scope.bundles = BundlesFactory.query(function () {
if ($scope.startUpload) {
$timeout(function () {
$scope.$emit('lang.refresh');
$scope.refreshModuleList();
LoadingModal.close();
}, MODULE_LIST_REFRESH_TIMEOUT);
} else {
$state.reload();
LoadingModal.close();
}
$scope.module = "";
$('#bundleUploadForm .fileinput').fileinput('clear');
ModalFactory.showSuccessAlert('admin.bundles.successInstall', 'admin.bundles.installNewModule');
});
}
$scope.hideInstallModulesModal();
})
.fail(function (response) {
ModalFactory.showErrorWithStackTrace('admin.error', 'admin.bundles.error.start', response);
LoadingModal.close();
$scope.hideInstallModulesModal();
});
} else if ($scope.moduleSource === 'Repository') {
ModalFactory.showErrorAlert('admin.bundles.error.moduleNotSelected', 'admin.error');
} else {
ModalFactory.showErrorAlert('admin.bundles.error.fileNotSelected', 'admin.error');
}
$scope.hideInstallModulesModal();
event.preventDefault();
});
};

$scope.isNoModuleOrFileSelected = function () {
if ($scope.moduleSource === 'Repository') {
return !$scope.module;
} else if ($scope.moduleSource === 'File') {
if ($("#bundleUploadForm #fileInput").val() === '') {
return true;
} else {
return false;
}
}
};

$scope.refreshModuleList = function () {
$scope.$emit('module.list.refresh');
};
}
})();
35 changes: 25 additions & 10 deletions src/admin/bundles/bundles-list.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
angular.module('motech-admin')
.controller('BundlesListController', bundlesListController);

bundlesListController.$inject = ['$scope', '$rootScope', '$state', '$http', 'BundlesFactory', 'LoadingModal', 'ServerService'];
function bundlesListController ($scope, $rootScope, $state, $http, BundlesFactory, LoadingModal, ServerService) {
bundlesListController.$inject = ['$scope', '$compile', '$state', '$http', 'BundlesFactory', 'LoadingModal', 'ServerService', 'ModalWindow'];
function bundlesListController($scope, $compile, $state, $http, BundlesFactory, LoadingModal, ServerService, ModalWindow) {

BundlesFactory.query(function(bundles){
BundlesFactory.query(function (bundles) {
$scope.bundles = bundles;
});

$scope.bundlesWithSettings = [];

$http({method:'GET', url:ServerService.formatURL('/module/admin/api/settings/bundles/list')}).
$http({method: 'GET', url: ServerService.formatURL('/module/admin/api/settings/bundles/list')}).
success(function (data) {
$scope.bundlesWithSettings = data;
});

$scope.showSettings = function (bundle) {
return $.inArray(bundle.symbolicName, $scope.bundlesWithSettings) >= 0 ||
(bundle.settingsURL && bundle.settingsURL.length !== 0);
(bundle.settingsURL && bundle.settingsURL.length !== 0);
};

$scope.loadBundleSettingsPage = function loadBundleSettingsPage(bundle) {
Expand All @@ -35,9 +35,15 @@

$scope.goToSettingsURL = function (moduleName, url) {
var convertUrl = function (urlParam) {
if(urlParam.indexOf('/') === 0) {urlParam = urlParam.replace('/', '');}
if(urlParam.indexOf('/') > 0) {urlParam = urlParam.replace('/', '.');}
if(urlParam.indexOf('/') > 0) {urlParam = urlParam.replace(/(\/)\w+((\/)\w*)*/i, '');}
if (urlParam.indexOf('/') === 0) {
urlParam = urlParam.replace('/', '');
}
if (urlParam.indexOf('/') > 0) {
urlParam = urlParam.replace('/', '.');
}
if (urlParam.indexOf('/') > 0) {
urlParam = urlParam.replace(/(\/)\w+((\/)\w*)*/i, '');
}
return urlParam;
};

Expand All @@ -51,13 +57,22 @@
}
});
if (url.indexOf('admin/bundleSettings/') > 0) {
$state.go('admin.bundleSettings', {'bundleId': url.substring(url.lastIndexOf("/")+1)});
$state.go('admin.bundleSettings', {'bundleId': url.substring(url.lastIndexOf("/") + 1)});
} else {
$state.go(convertUrl(url), $state.params);
}
LoadingModal.close();
}
};
}

var installModal;
$scope.openInstallModulesModal = function () {
installModal = ModalWindow($compile('<install-modules></install-modules>')($scope), "Install Modules");
installModal.open();
};

$scope.hideInstallModulesModal = function () {
installModal.close();
};
}
})();
2 changes: 2 additions & 0 deletions src/admin/bundles/bundles-list.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<button class="button-primary" ng-click="openInstallModulesModal()">Install Modules</button>

<motech-list>
<motech-list-item ng-repeat="bundle in bundles" >
<div column-title="Name" class="bundle-main">
Expand Down
10 changes: 10 additions & 0 deletions src/admin/bundles/bundles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@
right: 0.5em;
top: -0.25em;
}
}

form{
padding: 0.5em;
}
.form-inline .form-group label{
position: static !important;
}
#bundleUploadForm .fileinput {
margin-bottom: 0;
}
27 changes: 27 additions & 0 deletions src/admin/bundles/install-modules.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<form id="bundleUploadForm" enctype="multipart/form-data" method="POST">
<div class="form-group">
<label><b>{{'admin.bundles.upload' | translate}} {{'admin.import.from' | translate}} </b></label>
</div>
<div class="form-group">
<select class="form-control form-control-select" name="moduleSource" ng-model="moduleSource"
ng-options="item for item in moduleSources track by item"></select>
</div>
<div class="form-group" ng-show="moduleSource=='Repository'">
<select class="form-control form-control-select" name="moduleId" ng-model="module"
ng-options="key as value for (key, value) in modules track by key"
ng-show="moduleSource=='Repository'">
<option value="">{{'admin.bundles.selectModule' | translate}}</option>
</select>
</div>
<div class="form-group">
<div class="input-append btn-group fileinput fileinput-new" data-provides="fileinput"
ng-show="moduleSource=='File'">
<motech-file-upload></motech-file-upload>
</div>
</div>
<div class="checkbox">
<label><input type="checkbox" id="startBundle" name="startBundle" ng-model="startBundle" ng-checked="startUpload"/>{{'admin.bundles.startOnInstall' | translate}}</label>
</div>
<button ng-click="hideInstallModulesModal()">Close</button>
<input type="submit" ng-click="submitBundle()">
</form>
3 changes: 1 addition & 2 deletions src/common/base/base.icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ Styleguide 1.3
.icon-arrow-down{
@include icon(caret-down);
}

.icon-pause{
@include icon(pause);
}
Expand All @@ -128,4 +127,4 @@ Styleguide 1.3
}
.icon-file{
@include icon(file);
}
}