mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
- Based on the SuperFlat admin theme (I bought the extended license). - All pages are now full-width to give your data the room it deserves. - Various UX improvements (althuogh there is still room for improvement).
96 lines
2.9 KiB
JavaScript
96 lines
2.9 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
var directives = angular.module('redash.directives');
|
|
|
|
// Angular strips data- from the directive, so data-source-form becomes sourceForm...
|
|
directives.directive('sourceForm', ['$http', 'growl', '$q', '$location', 'Events', function ($http, growl, $q, $location, Events) {
|
|
return {
|
|
restrict: 'E',
|
|
replace: true,
|
|
templateUrl: '/views/data_sources/form.html',
|
|
scope: {
|
|
'dataSource': '='
|
|
},
|
|
link: function ($scope) {
|
|
var setType = function(types) {
|
|
if ($scope.dataSource.type === undefined) {
|
|
$scope.dataSource.type = types[0].type;
|
|
return types[0];
|
|
}
|
|
|
|
$scope.type = _.find(types, function (t) {
|
|
return t.type == $scope.dataSource.type;
|
|
});
|
|
};
|
|
|
|
$scope.files = {};
|
|
|
|
$scope.$watchCollection('files', function() {
|
|
_.each($scope.files, function(v, k) {
|
|
if (v) {
|
|
$scope.dataSource.options[k] = v.base64;
|
|
}
|
|
});
|
|
});
|
|
|
|
var typesPromise = $http.get('api/data_sources/types');
|
|
|
|
$q.all([typesPromise, $scope.dataSource.$promise]).then(function(responses) {
|
|
var types = responses[0].data;
|
|
setType(types);
|
|
|
|
$scope.dataSourceTypes = types;
|
|
|
|
_.each(types, function (type) {
|
|
_.each(type.configuration_schema.properties, function (prop, name) {
|
|
if (name == 'password' || name == 'passwd') {
|
|
prop.type = 'password';
|
|
}
|
|
|
|
if (_.string.endsWith(name, "File")) {
|
|
prop.type = 'file';
|
|
}
|
|
|
|
if (prop.type == 'boolean') {
|
|
prop.type = 'checkbox';
|
|
}
|
|
|
|
prop.required = _.contains(type.configuration_schema.required, name);
|
|
});
|
|
});
|
|
});
|
|
|
|
$scope.$watch('dataSource.type', function(current, prev) {
|
|
if (prev !== current) {
|
|
if (prev !== undefined) {
|
|
$scope.dataSource.options = {};
|
|
}
|
|
setType($scope.dataSourceTypes);
|
|
}
|
|
});
|
|
|
|
$scope.saveChanges = function() {
|
|
$scope.dataSource.$save(function() {
|
|
growl.addSuccessMessage("Saved.");
|
|
}, function() {
|
|
growl.addErrorMessage("Failed saving.");
|
|
});
|
|
}
|
|
|
|
$scope.deleteDataSource = function() {
|
|
Events.record(currentUser, "delete", "datasource", $scope.dataSource.id);
|
|
|
|
$scope.dataSource.$delete(function(resource) {
|
|
growl.addSuccessMessage("Data source deleted successfully.");
|
|
$location.path('/data_sources/');
|
|
}.bind(this), function(httpResponse) {
|
|
console.log("Failed to delete data source: ", httpResponse.status, httpResponse.statusText, httpResponse.data);
|
|
growl.addErrorMessage("Failed to delete data source.");
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}]);
|
|
})();
|