Skip to content
Snippets Groups Projects
Commit 9a70b62d authored by Allen Gilliland's avatar Allen Gilliland
Browse files

tidy up our angular DatabaseEdit controller and remove statically coded values...

tidy up our angular DatabaseEdit controller and remove statically coded values from frontend and pull it via form_input endpoint.
parent 92bbbdfc
Branches
Tags
No related merge requests found
......@@ -46,20 +46,32 @@ DatabasesControllers.controller('DatabaseList', ['$scope', 'Metabase', function(
DatabasesControllers.controller('DatabaseEdit', ['$scope', '$routeParams', '$location', 'Metabase', function($scope, $routeParams, $location, Metabase) {
$scope.ENGINES = {
postgres: {
name: "Postgres",
example: "host=[ip address] port=5432 dbname=examples user=corvus password=******"
},
h2: {
name: "H2",
example: "file:[filename]"
$scope.save = function(database) {
if ($routeParams.databaseId) {
// updating existing database
Metabase.db_update(database, function(updated_database) {
$scope.database = updated_database;
}, function(error) {
console.log('error loading database', error);
if (error.status == 404) {
$location.path('/admin/databases/');
}
});
} else {
// creating a new database
database.org = $scope.currentOrg.id;
Metabase.db_create(database, function(new_database) {
$location.path('/' + $scope.currentOrg.slug + '/admin/databases/' + new_database.id);
}, function(error) {
console.log('error creating database', error);
});
}
};
Metabase.db_form_input(function(form_input) {
// load our form input data
Metabase.db_form_input(function (form_input) {
$scope.form_input = form_input;
}, function(error) {
}, function (error) {
console.log('error getting database form_input', error);
});
......@@ -67,9 +79,9 @@ DatabasesControllers.controller('DatabaseEdit', ['$scope', '$routeParams', '$loc
// load existing database for editing
Metabase.db_get({
'dbId': $routeParams.databaseId
}, function(database) {
}, function (database) {
$scope.database = database;
}, function(error) {
}, function (error) {
console.log('error loading database', error);
if (error.status == 404) {
$location.path('/admin/databases/');
......@@ -83,26 +95,4 @@ DatabasesControllers.controller('DatabaseEdit', ['$scope', '$routeParams', '$loc
"details": {}
};
}
$scope.save = function(database) {
if ($routeParams.databaseId) {
// updating existing database
Metabase.db_update(database, function(updated_database) {
$scope.database = updated_database;
}, function(error) {
console.log('error loading database', error);
if (error.status == 404) {
$location.path('/admin/databases/');
}
});
} else {
// creating a new database
database.org = $scope.currentOrg.id;
Metabase.db_create(database, function(new_database) {
$location.path('/' + $scope.currentOrg.slug + '/admin/databases/' + new_database.id);
}, function(error) {
console.log('error creating database', error);
});
}
};
}]);
\ No newline at end of file
}]);
......@@ -12,7 +12,7 @@
<tr>
<th>Type</th>
<td>
<select class="Select my2" ng-model="database.engine" ng-options="type as properties.name for (type, properties) in ENGINES"></select>
<select class="Select my2" ng-model="database.engine" ng-options="type as properties.name for (type, properties) in form_input.engines"></select>
</td>
</tr>
<tr>
......@@ -26,7 +26,7 @@
<tr>
<th>Connection String</th>
<td>
<input class="input block full" type="text" placeholder="{{ENGINES[database.engine].example}}" ng-model="database.details.conn_str">
<input class="input block full" type="text" placeholder="{{form_input.engines[database.engine].example}}" ng-model="database.details.conn_str">
</td>
</tr>
</table>
......
......@@ -18,7 +18,7 @@
(defannotation DBEngine
"Param must be a valid database engine type, e.g. `h2` or `postgres`."
[symb value :nillable]
(checkp-contains? (set (map first driver/available-drivers)) symb value))
(checkp-contains? (set (map name (keys driver/available-drivers))) symb value))
(defendpoint GET "/"
"Fetch all `Databases` for an `Org`."
......
......@@ -10,9 +10,14 @@
(def available-drivers
"DB drivers that are available (pairs of `[namespace user-facing-name]`)."
[["h2" "H2"]
["postgres" "PostgreSQL"]])
"DB drivers that are available as a dictionary. Each key is a driver with dictionary of attributes.
ex: `:h2 {:id \"h2\" :name \"H2\"}`"
{:h2 {:id "h2"
:name "H2"
:example "file:[filename]"}
:postgres {:id "postgres"
:name "Postgres"
:example "host=[ip address] port=5432 dbname=examples user=corvus password=******"}})
;; TODO lazily requiring this way is a bit wonky.
;; We should rewrite this to load all sub-namespaces on first load like `metabase.task` does
......
......@@ -18,8 +18,12 @@
;; ## GET /api/meta/db/form_input
(expect
{:engines [["h2" "H2"]
["postgres" "PostgreSQL"]]
{:engines {:h2 {:id "h2"
:name "H2"
:example "file:[filename]"}
:postgres {:id "postgres"
:name "Postgres"
:example "host=[ip address] port=5432 dbname=examples user=corvus password=******"}}
:timezones ["GMT"
"UTC"
"US/Alaska"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment