diff --git a/assets/javascripts/discourse/components/explorer-schema-enuminfo.js.es6 b/assets/javascripts/discourse/components/explorer-schema-enuminfo.js.es6 new file mode 100644 index 0000000..702abc0 --- /dev/null +++ b/assets/javascripts/discourse/components/explorer-schema-enuminfo.js.es6 @@ -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') +}); diff --git a/assets/javascripts/discourse/components/explorer-schema-onetable.js.es6 b/assets/javascripts/discourse/components/explorer-schema-onetable.js.es6 index fd736f3..7435ba5 100644 --- a/assets/javascripts/discourse/components/explorer-schema-onetable.js.es6 +++ b/assets/javascripts/discourse/components/explorer-schema-onetable.js.es6 @@ -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') }); diff --git a/assets/javascripts/discourse/components/explorer-schema.js.es6 b/assets/javascripts/discourse/components/explorer-schema.js.es6 index 8120cc4..677cc4c 100644 --- a/assets/javascripts/discourse/components/explorer-schema.js.es6 +++ b/assets/javascripts/discourse/components/explorer-schema.js.es6 @@ -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; diff --git a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs index c4184f0..111c4e7 100644 --- a/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs +++ b/assets/javascripts/discourse/templates/admin/plugins-explorer.hbs @@ -45,14 +45,14 @@
-
- {{ace-editor content=selectedItem.sql mode="sql"}} -
{{explorer-schema schema=schema}}
+
+ {{ace-editor content=selectedItem.sql mode="sql"}} +
diff --git a/assets/javascripts/discourse/templates/components/explorer-schema-enuminfo.hbs b/assets/javascripts/discourse/templates/components/explorer-schema-enuminfo.hbs new file mode 100644 index 0000000..8166832 --- /dev/null +++ b/assets/javascripts/discourse/templates/components/explorer-schema-enuminfo.hbs @@ -0,0 +1,7 @@ +
    + {{#each enuminfo as |enum|}} +
  1. + {{enum.name}} +
  2. + {{/each}} +
diff --git a/assets/javascripts/discourse/templates/components/explorer-schema-onetable.hbs b/assets/javascripts/discourse/templates/components/explorer-schema-onetable.hbs index fed0a58..b54e34d 100644 --- a/assets/javascripts/discourse/templates/components/explorer-schema-onetable.hbs +++ b/assets/javascripts/discourse/templates/components/explorer-schema-onetable.hbs @@ -19,10 +19,13 @@
{{col.data_type}} - {{#if col.notes}} + {{#if col.havetypeinfo}}
{{col.notes}} + {{#if col.enum}} + {{explorer-schema-enuminfo col=col}} + {{/if}} {{/if}}
diff --git a/assets/stylesheets/explorer.scss b/assets/stylesheets/explorer.scss index c0d546c..748d1e9 100644 --- a/assets/stylesheets/explorer.scss +++ b/assets/stylesheets/explorer.scss @@ -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) ": "; + } + } + } } } } diff --git a/plugin.rb b/plugin.rb index cf10a5d..ce0db7a 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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