Пример #1
0
import 'angular-ui-bootstrap/src/modal/index-nocss';
import app from 'settings/app';
import core from 'common/core';

export default app.controller('RenameModalCtrl', ($scope, $uibModalInstance, serviceName) => {
	$scope.service = { name: serviceName };

	core.configurations.subscribe((configs) => {
		$scope.services = configs;
	});

	$scope.$watch('service.name', (name) => {
		$scope.exists = $scope.services ?
			$scope.services.filter((service) => service.name === name).length > 0 :
			false;
	});

	$scope.rename = function() {
		$uibModalInstance.close($scope.service.name);
	};
	$scope.cancel = function() {
		$uibModalInstance.dismiss('cancel');
	};
});
Пример #2
0
export default app.controller('SettingsCtrl', ($scope, $route) => {
	$scope.serviceId = null;
	$scope.serviceTypeId = null;

	const update = function() {
		if ($scope.view === 'service') {
			updateForExistingService();
		} else if ($scope.view === 'new') {
			updateForNewService();
		}
	};

	const updateForExistingService = function() {
		if ($scope.serviceTypes && $scope.serviceConfigs && $scope.serviceId) {
			$scope.config = find($scope.serviceConfigs, 'name', $scope.serviceId) || {};
			$scope.service = find($scope.serviceTypes, 'baseUrl', $scope.config.baseUrl);
		}
	};

	const updateForNewService = function() {
		if ($scope.serviceTypes && $scope.serviceId && $scope.serviceTypeId) {
			$scope.service = find($scope.serviceTypes, 'baseUrl', $scope.serviceTypeId);
			$scope.config = angular.copy($scope.service.defaultConfig);
			$scope.config.name = $scope.serviceId;
		} else {
			$scope.config = null;
			$scope.service = null;
		}
	};

	var find = function(list, field, value) {
		var item = list.filter(function(item) {
			return item[field] === value;
		})[0];
		return item ? item : null;
	};

	core.configurations.subscribe(function(configs) {
		$scope.$evalAsync(function() {
			$scope.serviceConfigs = configs;
			update();
		});
	});

	core.availableServices(function(types) {
		$scope.$evalAsync(function() {
			$scope.serviceTypes = types;
			update();
		});
	});

	$scope.$on('$routeChangeSuccess', function(event, routeData) {
		$scope.serviceId = routeData.params.serviceName || null;
		$scope.serviceTypeId = routeData.params.serviceTypeId || null;
		$scope.view = $route.current.view;
		update();
	});

});
Пример #3
0
import angular from 'angular';
import app from 'settings/app';
import core from 'common/core';

export default app.controller('NotificationsCtrl', ($scope) => {
	core.views.subscribe((config) => {
		$scope.$evalAsync(() => {
			$scope.config = config;
		});
	});

	$scope.setField = function(name, value) {
		const changed = $scope.config.notifications[name] !== value;
		if (changed) {
			$scope.config.notifications[name] = value;
			core.setViews(angular.copy($scope.config));
		}
	};


});