Include enum values in schema
This commit is contained in:
parent
3422415ef6
commit
2bbe69d67e
|
@ -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')
|
||||||
|
});
|
|
@ -6,8 +6,13 @@ export default Ember.Component.extend({
|
||||||
|
|
||||||
_bindClicks: function() {
|
_bindClicks: function() {
|
||||||
const self = this;
|
const self = this;
|
||||||
this.$()./*children('.schema-table-name').*/click(function() {
|
this.$().find('.schema-table-name').click(function(e) {
|
||||||
self.set('open', !self.get('open'));
|
self.set('open', !self.get('open'));
|
||||||
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
}.on('didInsertElement')
|
}.on('didInsertElement'),
|
||||||
|
|
||||||
|
_cleanup: function() {
|
||||||
|
this.$().find('.schema-table-name').off('click');
|
||||||
|
}.on('willDestroyElement')
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,7 +22,13 @@ export default Ember.Component.extend({
|
||||||
}
|
}
|
||||||
if (notes) {
|
if (notes) {
|
||||||
col.notes = notes;
|
col.notes = notes;
|
||||||
|
col.havetypeinfo = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (col.enum) {
|
||||||
|
col.havetypeinfo = true;
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return schema;
|
return schema;
|
||||||
|
|
|
@ -45,14 +45,14 @@
|
||||||
|
|
||||||
|
|
||||||
<div class="query-editor">
|
<div class="query-editor">
|
||||||
<div class="editor-panel">
|
|
||||||
{{ace-editor content=selectedItem.sql mode="sql"}}
|
|
||||||
</div>
|
|
||||||
<div class="right-panel">
|
<div class="right-panel">
|
||||||
<div class="schema grippie-target">
|
<div class="schema grippie-target">
|
||||||
{{explorer-schema schema=schema}}
|
{{explorer-schema schema=schema}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="editor-panel">
|
||||||
|
{{ace-editor content=selectedItem.sql mode="sql"}}
|
||||||
|
</div>
|
||||||
<div class="grippie"></div>
|
<div class="grippie"></div>
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<ol>
|
||||||
|
{{#each enuminfo as |enum|}}
|
||||||
|
<li value="{{enum.value}}">
|
||||||
|
{{enum.name}}
|
||||||
|
</li>
|
||||||
|
{{/each}}
|
||||||
|
</ol>
|
|
@ -19,10 +19,13 @@
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
{{col.data_type}}
|
{{col.data_type}}
|
||||||
{{#if col.notes}}
|
{{#if col.havetypeinfo}}
|
||||||
<br>
|
<br>
|
||||||
<span class="schema-typenotes">
|
<span class="schema-typenotes">
|
||||||
{{col.notes}}
|
{{col.notes}}
|
||||||
|
{{#if col.enum}}
|
||||||
|
{{explorer-schema-enuminfo col=col}}
|
||||||
|
{{/if}}
|
||||||
</span>
|
</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</dd>
|
</dd>
|
||||||
|
|
|
@ -76,6 +76,29 @@
|
||||||
.schema-typenotes {
|
.schema-typenotes {
|
||||||
color: dark-light-diff($primary, $secondary, 50%, -20%);
|
color: dark-light-diff($primary, $secondary, 50%, -20%);
|
||||||
font-style: italic;
|
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) ": ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
41
plugin.rb
41
plugin.rb
|
@ -162,6 +162,7 @@ email_logs.reply_key
|
||||||
api_keys.key
|
api_keys.key
|
||||||
site_settings.value
|
site_settings.value
|
||||||
|
|
||||||
|
users.auth_token
|
||||||
users.password_hash
|
users.password_hash
|
||||||
users.salt
|
users.salt
|
||||||
|
|
||||||
|
@ -190,6 +191,8 @@ SQL
|
||||||
by_table = {}
|
by_table = {}
|
||||||
# Massage the results into a nicer form
|
# Massage the results into a nicer form
|
||||||
results.each do |hash|
|
results.each do |hash|
|
||||||
|
full_col_name = "#{hash['table_name']}.#{hash['column_name']}"
|
||||||
|
|
||||||
if hash['is_nullable'] == "YES"
|
if hash['is_nullable'] == "YES"
|
||||||
hash['is_nullable'] = true
|
hash['is_nullable'] = true
|
||||||
else
|
else
|
||||||
|
@ -211,9 +214,12 @@ SQL
|
||||||
hash['column_default'] = $1
|
hash['column_default'] = $1
|
||||||
end
|
end
|
||||||
|
|
||||||
if sensitive_column_names.include? "#{hash['table_name']}.#{hash['column_name']}"
|
if sensitive_column_names.include? full_col_name
|
||||||
hash['sensitive'] = true
|
hash['sensitive'] = true
|
||||||
end
|
end
|
||||||
|
if enum_info.include? full_col_name
|
||||||
|
hash['enum'] = enum_info[full_col_name]
|
||||||
|
end
|
||||||
|
|
||||||
tname = hash.delete('table_name')
|
tname = hash.delete('table_name')
|
||||||
by_table[tname] ||= []
|
by_table[tname] ||= []
|
||||||
|
@ -233,6 +239,39 @@ SQL
|
||||||
sorted_by_table
|
sorted_by_table
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
# Reimplement a couple ActiveRecord methods, but use PluginStore for storage instead
|
# Reimplement a couple ActiveRecord methods, but use PluginStore for storage instead
|
||||||
|
|
Loading…
Reference in New Issue