Skip to content

Commit

Permalink
Ability to add Enum UI value set - Fixes #1243
Browse files Browse the repository at this point in the history
  • Loading branch information
wellingguzman committed Aug 25, 2016
1 parent b79e2ac commit 93be0ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 13 additions & 1 deletion api/core/Directus/Db/TableGateway/AclAwareTableGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,20 @@ protected function addTableColumn($tableName, $columnData) {
$comment = $columnData['comment'];

if (array_key_exists('char_length', $columnData)) {
$data_type = $data_type.'('.$columnData['char_length'].')';
$charLength = $columnData['char_length'];
// SET and ENUM data type has its values in the char_length attribute
// each value are separated by commas
// it must be wrap into quotes
if (strpos($charLength, ',') !== false) {
$charLength = implode(',', array_map(function($value) {
return "'". trim($value) . "'";
}, explode(',', $charLength)));
}

$data_type = $data_type.'('.$charLength.')';
}

// TODO: wrap this into an abstract DDL class
$sql = "ALTER TABLE `$tableName` ADD COLUMN `$column_name` $data_type COMMENT '$comment'";

$this->adapter->query( $sql )->execute();
Expand Down
10 changes: 6 additions & 4 deletions app/modules/settings/views/TablesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,14 @@ function(app, Backbone, Directus, BasePageView, TableModel, ColumnModel, UIManag
data.data_types.push(item);
});

//Check if we need length field
if(['VARCHAR', 'CHAR', 'ENUM'].indexOf(this.selectedDataType) > -1)
{
// Check if the data type needs length
// ENUM and SET doesn't actually needs a LENGTH,
// but the "length" value is a list of string separate by comma
if (['VARCHAR', 'CHAR', 'ENUM', 'SET'].indexOf(this.selectedDataType) > -1) {
data.SHOW_CHAR_LENGTH = true;
if (!this.model.get('char_length')) {
this.model.set({char_length: 100});
var charLength = ['ENUM', 'SET'].indexOf(this.selectedDataType) > -1 ? '' : 100;
this.model.set({char_length: charLength});
}
data.char_length = this.model.get('char_length');
} else {
Expand Down

0 comments on commit 93be0ca

Please sign in to comment.