From 0a0647cce8b6dfbd7284a94e7e8590ccecf5604c Mon Sep 17 00:00:00 2001 From: shanmukhm Date: Tue, 26 Jul 2016 12:36:12 +0530 Subject: [PATCH 1/3] MOTECH-2732 Migrated module install Workflow --- bower.json | 3 +- src/admin/bundles/bundle-install.directive.js | 124 ++++++++++++++++++ src/admin/bundles/bundles-list.controller.js | 1 - src/admin/bundles/bundles-list.html | 3 + src/admin/bundles/bundles.scss | 10 ++ src/admin/bundles/install-modules.html | 30 +++++ src/common/base/base.icons.scss | 7 +- 7 files changed, 174 insertions(+), 4 deletions(-) create mode 100644 src/admin/bundles/bundle-install.directive.js create mode 100644 src/admin/bundles/install-modules.html diff --git a/bower.json b/bower.json index c4e49b0..7bf41bd 100644 --- a/bower.json +++ b/bower.json @@ -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": { diff --git a/src/admin/bundles/bundle-install.directive.js b/src/admin/bundles/bundle-install.directive.js new file mode 100644 index 0000000..14d6ec7 --- /dev/null +++ b/src/admin/bundles/bundle-install.directive.js @@ -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'); + }; + } +})(); diff --git a/src/admin/bundles/bundles-list.controller.js b/src/admin/bundles/bundles-list.controller.js index 841a8b4..e202e45 100644 --- a/src/admin/bundles/bundles-list.controller.js +++ b/src/admin/bundles/bundles-list.controller.js @@ -59,5 +59,4 @@ } }; } - })(); \ No newline at end of file diff --git a/src/admin/bundles/bundles-list.html b/src/admin/bundles/bundles-list.html index 165a616..c4249b2 100644 --- a/src/admin/bundles/bundles-list.html +++ b/src/admin/bundles/bundles-list.html @@ -1,3 +1,6 @@ + + +
diff --git a/src/admin/bundles/bundles.scss b/src/admin/bundles/bundles.scss index 212662e..ee2a020 100644 --- a/src/admin/bundles/bundles.scss +++ b/src/admin/bundles/bundles.scss @@ -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; } \ No newline at end of file diff --git a/src/admin/bundles/install-modules.html b/src/admin/bundles/install-modules.html new file mode 100644 index 0000000..2ef2608 --- /dev/null +++ b/src/admin/bundles/install-modules.html @@ -0,0 +1,30 @@ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+
+ + +
+
+ {{msg('admin.bundles.installOrUpdate')}} +
+
+
\ No newline at end of file diff --git a/src/common/base/base.icons.scss b/src/common/base/base.icons.scss index d777768..bf25401 100644 --- a/src/common/base/base.icons.scss +++ b/src/common/base/base.icons.scss @@ -110,7 +110,6 @@ Styleguide 1.3 .icon-arrow-down{ @include icon(caret-down); } - .icon-pause{ @include icon(pause); } @@ -128,4 +127,8 @@ Styleguide 1.3 } .icon-file{ @include icon(file); - } \ No newline at end of file +<<<<<<< HEAD + } +======= +} +>>>>>>> MOTECH-2732 Migrated module install Workflow From 09786b588cc776f2d55289949c13b643ac36a746 Mon Sep 17 00:00:00 2001 From: shanmukhm Date: Mon, 1 Aug 2016 19:38:31 +0530 Subject: [PATCH 2/3] Put the installation form in a ModalWindow --- src/admin/bundles/bundle-install.directive.js | 89 +++++++++++-------- src/admin/bundles/bundles-list.controller.js | 28 ++++-- src/admin/bundles/bundles-list.html | 3 +- src/admin/bundles/install-modules.html | 37 ++++---- 4 files changed, 90 insertions(+), 67 deletions(-) diff --git a/src/admin/bundles/bundle-install.directive.js b/src/admin/bundles/bundle-install.directive.js index 14d6ec7..5e9255e 100644 --- a/src/admin/bundles/bundle-install.directive.js +++ b/src/admin/bundles/bundle-install.directive.js @@ -1,4 +1,4 @@ -(function(){ +(function () { 'use-strict'; angular.module('motech-admin') @@ -8,28 +8,34 @@ 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); + 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', '$state', 'BundlesFactory', 'LoadingModal', 'ModalFactory']; - function controller($scope, $rootScope, $state, BundlesFactory, LoadingModal, ModalFactory) { + 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($scope.msg('server.version')); + $scope.mavenStr = function (artifactId) { + return 'org.motechproject:'.concat(artifactId).concat(':').concat($rootScope.msg('server.version')); }; $scope.modules = {}; @@ -57,22 +63,27 @@ $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) { + $("#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 { @@ -92,17 +103,21 @@ 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.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 () { diff --git a/src/admin/bundles/bundles-list.controller.js b/src/admin/bundles/bundles-list.controller.js index e202e45..2caa278 100644 --- a/src/admin/bundles/bundles-list.controller.js +++ b/src/admin/bundles/bundles-list.controller.js @@ -4,23 +4,25 @@ 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')}). - success(function (data) { - $scope.bundlesWithSettings = data; - }); + $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) { @@ -58,5 +60,15 @@ LoadingModal.close(); } }; + + var installModal; + $scope.openInstallModulesModal = function () { + installModal = ModalWindow($compile('')($scope), "Install Modules"); + installModal.open(); + }; + + $scope.hideInstallModulesModal = function () { + installModal.close(); + }; } })(); \ No newline at end of file diff --git a/src/admin/bundles/bundles-list.html b/src/admin/bundles/bundles-list.html index c4249b2..e304064 100644 --- a/src/admin/bundles/bundles-list.html +++ b/src/admin/bundles/bundles-list.html @@ -1,5 +1,4 @@ - - + diff --git a/src/admin/bundles/install-modules.html b/src/admin/bundles/install-modules.html index 2ef2608..7e2a63b 100644 --- a/src/admin/bundles/install-modules.html +++ b/src/admin/bundles/install-modules.html @@ -1,30 +1,27 @@ -
-
+
- +
-
- +
+
-
- +
-
-
+
+
-
- - -
-
- {{msg('admin.bundles.installOrUpdate')}} +
+
-
+ + \ No newline at end of file From 298840b0c620b2fc1cea12011e0dd6f3390af0ef Mon Sep 17 00:00:00 2001 From: shanmukhm Date: Wed, 3 Aug 2016 14:41:44 +0530 Subject: [PATCH 3/3] Removed malsup/form from bower --- bower.json | 3 +-- src/admin/bundles/bundles-list.controller.js | 24 ++++++++++++-------- src/common/base/base.icons.scss | 4 ---- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/bower.json b/bower.json index 7bf41bd..c4e49b0 100644 --- a/bower.json +++ b/bower.json @@ -41,8 +41,7 @@ "jquery-timepicker-addon": "^1.3.1", "jquery-ui": "^1.11.4", "messageformat": "^0.3.1", - "jasny-bootstrap": "git://github.com/jasny/bootstrap", - "form": "git://github.com/malsup/form/" + "jasny-bootstrap": "git://github.com/jasny/bootstrap" }, "overrides": { "angular-bootstrap": { diff --git a/src/admin/bundles/bundles-list.controller.js b/src/admin/bundles/bundles-list.controller.js index 2caa278..e17bb0f 100644 --- a/src/admin/bundles/bundles-list.controller.js +++ b/src/admin/bundles/bundles-list.controller.js @@ -13,12 +13,10 @@ $scope.bundlesWithSettings = []; - $http({ - method: 'GET', - url: ServerService.formatURL('/module/admin/api/settings/bundles/list') - }).success(function (data) { - $scope.bundlesWithSettings = data; - }); + $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 || @@ -37,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; }; @@ -53,7 +57,7 @@ } }); 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); } diff --git a/src/common/base/base.icons.scss b/src/common/base/base.icons.scss index bf25401..95b7c57 100644 --- a/src/common/base/base.icons.scss +++ b/src/common/base/base.icons.scss @@ -127,8 +127,4 @@ Styleguide 1.3 } .icon-file{ @include icon(file); -<<<<<<< HEAD - } -======= } ->>>>>>> MOTECH-2732 Migrated module install Workflow