diff --git a/res/app/components/stf/common-ui/fatal-message/fatal-message-service.js b/res/app/components/stf/common-ui/fatal-message/fatal-message-service.js new file mode 100644 index 00000000..ca3b54b9 --- /dev/null +++ b/res/app/components/stf/common-ui/fatal-message/fatal-message-service.js @@ -0,0 +1,41 @@ +module.exports = function FatalMessageServiceFactory($modal, $location, $route) { + var FatalMessageService = {} + + + var ModalInstanceCtrl = function ($scope, $modalInstance, device) { + $scope.ok = function () { + $modalInstance.close(5) + $route.reload() + //$location.path('/control/' + device.serial) + } + + $scope.second = function () { + $location.path('/devices/') + } + + $scope.cancel = function () { + $modalInstance.dismiss('cancel') + } + } + + FatalMessageService.open = function (device) { + var modalInstance = $modal.open({ + template: require('./fatal-message.jade'), + controller: ModalInstanceCtrl, + resolve: { + device: device, + items: function () { + return 10 + } + } + }) + + modalInstance.result.then(function (selectedItem) { + console.log(selectedItem) + }, function () { + console.log('Modal dismissed at: ' + new Date()) + }) + } + + return FatalMessageService +} diff --git a/res/app/components/stf/common-ui/fatal-message/fatal-message-spec.js b/res/app/components/stf/common-ui/fatal-message/fatal-message-spec.js new file mode 100644 index 00000000..281d7cfe --- /dev/null +++ b/res/app/components/stf/common-ui/fatal-message/fatal-message-spec.js @@ -0,0 +1,11 @@ +describe('FatalMessageService', function() { + + beforeEach(module('stf.fatal-message')); + + it('should ...', inject(function(FatalMessageService) { + + //expect(FatalMessageService.doSomething()).toEqual('something'); + + })); + +}) \ No newline at end of file diff --git a/res/app/components/stf/common-ui/fatal-message/fatal-message.jade b/res/app/components/stf/common-ui/fatal-message/fatal-message.jade new file mode 100644 index 00000000..499fd69e --- /dev/null +++ b/res/app/components/stf/common-ui/fatal-message/fatal-message.jade @@ -0,0 +1,8 @@ +.modal-header + h3.modal-title(translate) Device was disconnected + .modal-body + h4 Device is not in use anymore + .modal-footer + button.btn.btn-primary(translate, ng-click='ok()') Try to reconnect + button.btn.btn-success(translate, ng-click='second()') Go to Device List + button.btn.btn-warning(translate, ng-click='cancel()') Close diff --git a/res/app/components/stf/common-ui/fatal-message/index.js b/res/app/components/stf/common-ui/fatal-message/index.js new file mode 100644 index 00000000..20fa83b1 --- /dev/null +++ b/res/app/components/stf/common-ui/fatal-message/index.js @@ -0,0 +1,4 @@ +module.exports = angular.module('stf.fatal-message', [ + +]) + .factory('FatalMessageService', require('./fatal-message-service')) diff --git a/res/app/components/stf/common-ui/index.js b/res/app/components/stf/common-ui/index.js index 98c02311..a7211da5 100644 --- a/res/app/components/stf/common-ui/index.js +++ b/res/app/components/stf/common-ui/index.js @@ -7,5 +7,6 @@ module.exports = angular.module('stf/common-ui', [ require('./notifications').name, require('./ng-enter').name, require('./tooltips').name, - require('./tree').name -]) \ No newline at end of file + require('./tree').name, + require('./fatal-message').name +]) diff --git a/res/app/control-panes/control-panes-controller.js b/res/app/control-panes/control-panes-controller.js index 3b9aac34..9b6a0dc6 100644 --- a/res/app/control-panes/control-panes-controller.js +++ b/res/app/control-panes/control-panes-controller.js @@ -1,4 +1,4 @@ -module.exports = function ($scope, gettext, $routeParams, $location, DeviceService, GroupService, ControlService) { +module.exports = function ($scope, gettext, $routeParams, $location, DeviceService, GroupService, ControlService, FatalMessageService) { var sharedTabs = [ { @@ -122,4 +122,15 @@ module.exports = function ($scope, gettext, $routeParams, $location, DeviceServi .catch(function () { $location.path('/') }) + + + $scope.$watch('device.state', function (newValue, oldValue) { + if (newValue !== oldValue) { + if (oldValue === 'using') { + FatalMessageService.open(angular.copy($scope.device)) + } else { + + } + } + }, true) } diff --git a/res/app/layout/layout-controller.js b/res/app/layout/layout-controller.js index b70204ce..59a15943 100644 --- a/res/app/layout/layout-controller.js +++ b/res/app/layout/layout-controller.js @@ -1,2 +1,3 @@ -module.exports = function LayoutCtrl() { +module.exports = function LayoutCtrl(FatalMessageService) { + }