Skip to content

Commit

Permalink
MOTECH-2732 Migrated module install Workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
shanmukhm committed Jul 27, 2016
1 parent 067e06f commit fb810be
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 6 deletions.
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"jquery-timepicker-addon": "^1.3.1",
"jquery-ui": "^1.11.4",
"messageformat": "^0.3.1",
"jasny-bootstrap": "git://github.com/jasny/bootstrap"
"jasny-bootstrap": "git://github.com/jasny/bootstrap",
"form": "git://github.com/malsup/form/"
},
"overrides": {
"angular-bootstrap": {
Expand Down
124 changes: 124 additions & 0 deletions src/admin/bundles/bundle-install.directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
(function(){
'use-strict';

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

moduleInstall.$inject = ['ServerService'];
function moduleInstall(ServerService) {
return {
restrict: 'E',
replace: true,
templateUrl: '/admin/bundles/install-modules.html',
controller: controller,
link: function(scope, element, attrs) {
var url = $("#bundleUploadForm").attr("action");
url = ServerService.formatURL(url);
$("#bundleUploadForm").attr("action", url);
}
};
}

controller.$inject = ['$scope', '$rootScope', '$state', 'BundlesFactory', 'LoadingModal', 'ModalFactory'];
function controller($scope, $rootScope, $state, BundlesFactory, LoadingModal, ModalFactory) {
$scope.moduleSources = [
'Repository',
'File'
];

$scope.moduleSource = $scope.moduleSources[0];

$scope.mavenStr = function(artifactId) {
return 'org.motechproject:'.concat(artifactId).concat(':').concat($scope.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.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');
}
};

$scope.submitBundle = function () {
if (!$scope.isNoModuleOrFileSelected()) {
LoadingModal.open();
$('#bundleUploadForm').ajaxSubmit({
success: function (data, textStatus, jqXHR) {
if (jqXHR.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');
});
}
},
error:function (response) {
ModalFactory.showErrorWithStackTrace('admin.error', 'admin.bundles.error.start', response);
LoadingModal.close();
}
});
} else if ($scope.moduleSource === 'Repository') {
ModalFactory.showErrorAlert('admin.bundles.error.moduleNotSelected', 'admin.error');
} else {
ModalFactory.showErrorAlert('admin.bundles.error.fileNotSelected', 'admin.error');
}
};

$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');
};
}
})();
7 changes: 3 additions & 4 deletions src/admin/bundles/bundles-list.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
angular.module('motech-admin')
.controller('BundlesListController', bundlesListController);

bundlesListController.$inject = ['$scope', '$rootScope', 'BundlesFactory'];
function bundlesListController ($scope, $rootScope, BundlesFactory) {
BundlesFactory.query(function(bundles){
bundlesListController.$inject = ['$scope', 'BundlesFactory'];
function bundlesListController ($scope, BundlesFactory) {
BundlesFactory.query(function (bundles) {
$scope.bundles = bundles;
});
}

})();
3 changes: 3 additions & 0 deletions src/admin/bundles/bundles-list.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<install-modules>
</install-modules>

<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;
}
30 changes: 30 additions & 0 deletions src/admin/bundles/install-modules.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<form id="bundleUploadForm" action="/module/admin/api/bundles/upload" enctype="multipart/form-data" method="POST">
<div class="form-inline">
<div class="form-group">
<label><b>{{msg('admin.bundles.upload')}} {{msg('admin.import.from')}} </b></label>
</div>
<div class="form-group offset-1">
<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 offset-1" 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="">{{msg('admin.bundles.selectModule')}}</option>
</select>
</div>
<div class="form-group offset-1">
<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="form-group offset-1" data-toggle="buttons-checkbox">
<button type="button" class="btn btn-default start-on-upload" ng-click="startOnUpload()">
<i class="fa fa-fw fa-check-square-o"></i> {{msg('admin.bundles.startOnInstall')}}
</button>
<input type="checkbox" id="startBundle" name="startBundle" ng-checked="startUpload"
style="display: none;"/>
</div>
<div class="form-group offset-1">
<span ng-click="submitBundle()" class="btn btn-success">{{msg('admin.bundles.installOrUpdate')}}</span>
</div>
</div>
</form>
4 changes: 3 additions & 1 deletion 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 @@ -126,3 +125,6 @@ Styleguide 1.3
.icon-check{
@include icon(check);
}
.icon-file{
@include icon(file);
}

0 comments on commit fb810be

Please sign in to comment.