Skip to content

Commit

Permalink
Merge pull request thedevdojo#961 from abdgad/prefillNewTable
Browse files Browse the repository at this point in the history
Fix databaseTypes.getType getting displayed as a type category
  • Loading branch information
marktopper authored Mar 17, 2017
2 parents ecb8b48 + 65f398f commit 6ca6f0d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion publishable/assets/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function bootstrapAlerter(customOptions) {
'</div>';

$(options.alertsContainer).append(alert);
};
}

return {
success(message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
return $.extend({
name: '',
oldName: '',
type: databaseTypes.getType('integer'),
type: getDbType('integer'),
length: null,
fixed: false,
unsigned: false,
Expand All @@ -32,18 +32,18 @@
addTimestamps() {
this.addColumn(this.makeColumn({
name: 'created_at',
type: databaseTypes.getType('timestamp')
type: getDbType('timestamp')
}));

this.addColumn(this.makeColumn({
name: 'updated_at',
type: databaseTypes.getType('timestamp')
type: getDbType('timestamp')
}));
},
addSoftDeletes() {
this.addColumn(this.makeColumn({
name: 'deleted_at',
type: databaseTypes.getType('timestamp')
type: getDbType('timestamp')
}));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,25 @@
<script>
let databaseTypes = {!! json_encode($db->types) !!};

databaseTypes.getType = function (name) {
function getDbType(name) {
let type;
name = name.toLowerCase().trim();

for (category in databaseTypes) {
if (Array.isArray(databaseTypes[category])) {
type = databaseTypes[category].find(function(type) {
return name == type.name.toLowerCase();
});
type = databaseTypes[category].find(function (type) {
return name == type.name.toLowerCase();
});

if (type) {
return type;
}
if (type) {
return type;
}
}

toastr.error("Unknown type: " + name);

// fallback to a default type
return databaseTypes.Numbers[0];
};
}

Vue.component('database-types', {
props: {
Expand All @@ -59,7 +57,7 @@
this.$emit('typeChanged', this.getType(event.target.value));
},
getType(name) {
return this.dbTypes.getType(name);
return getDbType(name);
}
}
});
Expand Down

0 comments on commit 6ca6f0d

Please sign in to comment.