Include enum values in schema

This commit is contained in:
Kane York 2015-07-09 15:46:19 -07:00
parent 3422415ef6
commit 2bbe69d67e
8 changed files with 104 additions and 7 deletions

View File

@ -0,0 +1,14 @@
export default Ember.Component.extend({
classNames: ['fa', 'fa-info', 'enum-info'],
tagName: 'i',
enuminfo: function() {
const hash = this.get('col.enum');
let result = [];
for (let key in hash) {
if (!hash.hasOwnProperty(key)) { continue; }
result.push({value: key, name: hash[key]});
}
return result;
}.property('col.enum')
});

View File

@ -6,8 +6,13 @@ export default Ember.Component.extend({
_bindClicks: function() {
const self = this;
this.$()./*children('.schema-table-name').*/click(function() {
this.$().find('.schema-table-name').click(function(e) {
self.set('open', !self.get('open'));
e.preventDefault();
});
}.on('didInsertElement')
}.on('didInsertElement'),
_cleanup: function() {
this.$().find('.schema-table-name').off('click');
}.on('willDestroyElement')
});

View File

@ -22,7 +22,13 @@ export default Ember.Component.extend({
}
if (notes) {
col.notes = notes;
col.havetypeinfo = true;
}
if (col.enum) {
col.havetypeinfo = true;
}
});
}
return schema;

View File

@ -45,14 +45,14 @@
<div class="query-editor">
<div class="editor-panel">
{{ace-editor content=selectedItem.sql mode="sql"}}
</div>
<div class="right-panel">
<div class="schema grippie-target">
{{explorer-schema schema=schema}}
</div>
</div>
<div class="editor-panel">
{{ace-editor content=selectedItem.sql mode="sql"}}
</div>
<div class="grippie"></div>
<div class="clear"></div>
</div>

View File

@ -0,0 +1,7 @@
<ol>
{{#each enuminfo as |enum|}}
<li value="{{enum.value}}">
{{enum.name}}
</li>
{{/each}}
</ol>

View File

@ -19,10 +19,13 @@
</dt>
<dd>
{{col.data_type}}
{{#if col.notes}}
{{#if col.havetypeinfo}}
<br>
<span class="schema-typenotes">
{{col.notes}}
{{#if col.enum}}
{{explorer-schema-enuminfo col=col}}
{{/if}}
</span>
{{/if}}
</dd>

View File

@ -76,6 +76,29 @@
.schema-typenotes {
color: dark-light-diff($primary, $secondary, 50%, -20%);
font-style: italic;
ol { display: none; }
&:hover ol { display: block; }
.enum-info {
ol {
position: absolute;
padding: 5px;
padding-right: calc(5px + 2em);
border: 1px solid;
background: white;
list-style: none;
left: -12em;
top: 10px;
z-index: 10;
> li {
width: 150%;
}
> li:before {
content: attr(value) ": ";
}
}
}
}
}
}

View File

@ -162,6 +162,7 @@ email_logs.reply_key
api_keys.key
site_settings.value
users.auth_token
users.password_hash
users.salt
@ -190,6 +191,8 @@ SQL
by_table = {}
# Massage the results into a nicer form
results.each do |hash|
full_col_name = "#{hash['table_name']}.#{hash['column_name']}"
if hash['is_nullable'] == "YES"
hash['is_nullable'] = true
else
@ -211,9 +214,12 @@ SQL
hash['column_default'] = $1
end
if sensitive_column_names.include? "#{hash['table_name']}.#{hash['column_name']}"
if sensitive_column_names.include? full_col_name
hash['sensitive'] = true
end
if enum_info.include? full_col_name
hash['enum'] = enum_info[full_col_name]
end
tname = hash.delete('table_name')
by_table[tname] ||= []
@ -233,6 +239,39 @@ SQL
sorted_by_table
end
end
def self.enums
@enums ||= {
:'category_groups.permission_type' => CategoryGroup.permission_types,
:'directory_items.period_type' => DirectoryItem.period_types,
:'groups.alias_level' => Group::ALIAS_LEVELS,
:'groups.id' => Group::AUTO_GROUPS,
:'notifications.notification_type' => Notification.types,
:'posts.cook_method' => Post.cook_methods,
:'posts.hidden_reason_id' => Post.hidden_reasons,
:'posts.post_type' => Post.types,
:'post_actions.post_action_type_id' => PostActionType.types,
:'post_action_types.id' => PostActionType.types,
:'queued_posts.state' => QueuedPost.states,
:'site_settings.data_type' => SiteSetting.types,
:'topic_users.notification_level' => TopicUser.notification_levels,
:'topic_users.notifications_reason_id' => TopicUser.notification_reasons,
:'user_histories.action' => UserHistory.actions,
:'users.trust_level' => TrustLevel.levels,
}.with_indifferent_access
end
def self.enum_info
@enum_info ||= begin
enum_info = {}
enums.map do |key,enum|
# https://stackoverflow.com/questions/10874356/reverse-a-hash-in-ruby
enum_info[key] = Hash[enum.to_a.map(&:reverse)]
end
enum_info
end
end
end
# Reimplement a couple ActiveRecord methods, but use PluginStore for storage instead