|
| 1 | +/* |
| 2 | + * Copyright 2015-2018 Jeeva Kandasamy ([email protected]) |
| 3 | + * and other contributors as indicated by the @author tags. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +// don't forget to declare this service module as a dependency in your main app constructor! |
| 18 | +//http://js2.coffee/#coffee2js |
| 19 | +//https://coderwall.com/p/r_bvhg/angular-ui-bootstrap-alert-service-for-angular-js |
| 20 | + |
| 21 | +'use strict'; |
| 22 | + |
| 23 | +angular.module('adf.widget.myc-os-commands', []) |
| 24 | + .config(function(dashboardProvider){ |
| 25 | + dashboardProvider |
| 26 | + .widget('mycOsCommands', { |
| 27 | + title: 'OS Commands', |
| 28 | + description: 'Create buttons to run Operating System Commands', |
| 29 | + templateUrl: 'controllers/adf-widgets/adf-myc-os/view.html?mcv=${mc.gui.version}', |
| 30 | + controller: 'mycOsCommandController', |
| 31 | + controllerAs: 'mycOsBtns', |
| 32 | + config: { |
| 33 | + minBtnHeight:30, |
| 34 | + minBtnWidth:90, |
| 35 | + buttonsJson:"[\n]", |
| 36 | + }, |
| 37 | + edit: { |
| 38 | + templateUrl: 'controllers/adf-widgets/adf-myc-os/edit.html?mcv=${mc.gui.version}', |
| 39 | + controller: 'mycOsCommandEditController', |
| 40 | + controllerAs: 'mycOsBtnsEdit', |
| 41 | + } |
| 42 | + }); |
| 43 | + }) |
| 44 | + .controller('mycOsCommandController', function($scope, $interval, config, mchelper, $uibModal, $filter, OSCommandFactory, CommonServices){ |
| 45 | + var mycOsBtns = this; |
| 46 | + |
| 47 | + mycOsBtns.showLoading = false; |
| 48 | + $scope.tooltipEnabled = false; |
| 49 | + $scope.cs = CommonServices; |
| 50 | + mycOsBtns.buttons = angular.fromJson(config.buttonsJson); |
| 51 | + |
| 52 | + // execute OS command directly |
| 53 | + $scope.executeOsCommandDirect = function(button){ |
| 54 | + var request = {}; |
| 55 | + request.os = button.os; |
| 56 | + request.command = button.command; |
| 57 | + OSCommandFactory.execute(request, function(response){ |
| 58 | + if(response.error === undefined){ |
| 59 | + alertService.success(response.result); |
| 60 | + }else { |
| 61 | + alertService.danger(angular.toJson(response)); |
| 62 | + } |
| 63 | + },function(error){ |
| 64 | + displayRestError.display(error); |
| 65 | + }); |
| 66 | + }; |
| 67 | + |
| 68 | + // execute OS command with confirmation check |
| 69 | + $scope.executeOsCommand = function (button) { |
| 70 | + if(button.confirmation === true){ |
| 71 | + var addModalInstance = $uibModal.open({ |
| 72 | + templateUrl: 'controllers/adf-widgets/adf-myc-os/confirmation-modal.html?mcv=${mc.gui.version}', |
| 73 | + controller: 'CommandConfirmationController', |
| 74 | + resolve: {button: button} |
| 75 | + }); |
| 76 | + |
| 77 | + addModalInstance.result.then(function () { |
| 78 | + $scope.executeOsCommandDirect(button); |
| 79 | + }), |
| 80 | + function () { |
| 81 | + //console.log('Modal dismissed at: ' + new Date()); |
| 82 | + } |
| 83 | + } else { |
| 84 | + $scope.executeOsCommandDirect(button); |
| 85 | + } |
| 86 | + }; |
| 87 | + |
| 88 | + |
| 89 | + }).controller('mycOsCommandEditController', function($scope, $interval, config, mchelper, $filter, CommonServices){ |
| 90 | + var mycOsBtnsEdit = this; |
| 91 | + mycOsBtnsEdit.cs = CommonServices; |
| 92 | + |
| 93 | + }).controller('CommandConfirmationController', function ($scope, $uibModalInstance, $filter, button) { |
| 94 | + $scope.header = $filter('translate')('OS_COMMAND_EXECTION_CONFIRMATION_TITLE'); |
| 95 | + $scope.button = button; |
| 96 | + $scope.reboot = function() {$uibModalInstance.close(); }; |
| 97 | + $scope.cancel = function () { $uibModalInstance.dismiss('cancel'); } |
| 98 | +}); |
0 commit comments