rails_admin_json_editor 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  //= require rails_admin_json_editor/vue.0.11.4
2
2
  //= require rails_admin_json_editor/lodash.2.4.1
3
+ //= require rails_admin_json_editor/markdown
3
4
 
4
5
  var vm;
5
6
 
@@ -14,6 +15,10 @@ $(document).on('rails_admin.dom_ready', function() {
14
15
  jsonResult = { components: [] };
15
16
  }
16
17
 
18
+ Vue.filter('markdown', function(value) {
19
+ return markdown.toHTML(value);
20
+ });
21
+
17
22
  // Setup templates for models
18
23
  var components = {};
19
24
  _.each(jsonScheme.models, function(model) {
@@ -21,7 +26,8 @@ $(document).on('rails_admin.dom_ready', function() {
21
26
  template: '#template-fields-for-' + model.name,
22
27
  data: function() {
23
28
  return {
24
- expanded: true
29
+ expanded: true,
30
+ showPreview: false
25
31
  };
26
32
  },
27
33
  computed: {
@@ -91,7 +97,7 @@ $(document).on('rails_admin.dom_ready', function() {
91
97
  },
92
98
 
93
99
  nestedModelIsAllowed: function(model, allowedModels) {
94
- return _.contains(allowedModels, model.name)
100
+ return _.contains(allowedModels, model.name);
95
101
  }
96
102
  }
97
103
  };
@@ -4,11 +4,27 @@ body.rails_admin .form-horizontal.denser .json-editor {
4
4
  margin-bottom: 15px;
5
5
  }
6
6
 
7
- .form-control {
7
+ .form-control:not([type="checkbox"]) {
8
8
  width: 90%;
9
9
  }
10
10
 
11
11
  .btn-toggle-json {
12
12
  margin-left: 15px;
13
13
  }
14
+
15
+ .markdown-field {
16
+ position: relative;
17
+ button {
18
+ position: absolute;
19
+ right: 0;
20
+ bottom: 0;
21
+ }
22
+ }
23
+
24
+ .markdown-preview {
25
+ margin-top: 5px;
26
+ background: #EEE;
27
+ padding: 10px;
28
+ border-radius:5px;
29
+ }
14
30
  }
@@ -35,7 +35,7 @@
35
35
  <%= content_tag :p, model.help, class: "help-block" unless model.help.nil? %>
36
36
 
37
37
  <% model.fields.each do |f| %>
38
- <div class="control-group row">
38
+ <div class="control-group row <%= f.css_class %>">
39
39
  <label class="col-sm-2 control-label"><%= f.label %></label>
40
40
 
41
41
  <div class="controls col-sm-10">
@@ -47,10 +47,33 @@
47
47
  <textarea v-model="component.properties.<%= f.name %>" class="form-control"></textarea>
48
48
  <% end %>
49
49
 
50
+ <% if f.type == :markdown %>
51
+ <div class="markdown-field">
52
+ <textarea v-model="component.properties.<%= f.name %>" class="form-control" rows="10"></textarea>
53
+
54
+ <button v-on="click: showPreview = !showPreview" type="button" class="btn btn-default">
55
+ <i class="icon-eye-open"></i>
56
+ </button>
57
+ </div>
58
+
59
+ <div class="markdown-preview" v-show="showPreview">
60
+ <div v-html="component.properties.<%= f.name %> | markdown"></div>
61
+ </div>
62
+ <% end %>
63
+
64
+ <% if f.type == :boolean %>
65
+ <input type="checkbox" v-model="component.properties.<%= f.name %>" class="form-control">
66
+ <% end %>
67
+
50
68
  <% if f.type == :picker %>
51
69
  <select v-on="change: onChangePicker($event, '<%= f.name %>')" class="form-control record-picker">
52
70
  <option value=""></option>
53
- <% f.picker_records.each do |record| %>
71
+ <%
72
+ records = Rails.cache.fetch("record-picker-#{f.picker_model_name}") {
73
+ f.picker_model_name.constantize.send(:all)
74
+ }
75
+ %>
76
+ <% records.each do |record| %>
54
77
  <option
55
78
  v-attr="selected: pickerOptionIsSelected('<%= f.name %>', '<%= f.picker_label %>', '<%= record.send(f.picker_label) %>')"
56
79
  value="<%= record.send(f.picker_label) %>"
@@ -70,24 +93,24 @@
70
93
  </div>
71
94
 
72
95
  <!-- Add nested component -- one model allowed -->
73
- <% if f.allowed_nested_models.count == 1 %>
96
+ <% if f.list_model_names.count == 1 %>
74
97
  <a href="#"
75
98
  class="btn btn-info"
76
99
  v-repeat="model: $root.scheme.models"
77
- v-show="nestedModelIsAllowed(model, <%= f.allowed_nested_models.map { |nct| nct.to_s } %>)"
100
+ v-show="nestedModelIsAllowed(model, <%= f.list_model_names %>)"
78
101
  v-on="click: addComponent($event, '<%= f.name %>', model)">
79
102
  Add {{ model.label | lowercase }}
80
103
  </a>
81
104
  <% end %>
82
105
 
83
106
  <!-- Add nested component -- multiple models allowed -->
84
- <% if f.allowed_nested_models.count > 1 %>
107
+ <% if f.list_model_names.count > 1 %>
85
108
  <div class="dropdown">
86
109
  <a class="dropdown-toggle btn btn-info" data-toggle="dropdown" href="#">Add component <b class="caret"></b></a>
87
110
  <ul class="dropdown-menu">
88
111
  <li v-repeat="model: $root.scheme.models">
89
112
  <a href="#"
90
- v-if="nestedModelIsAllowed(model, <%= f.allowed_nested_models.map { |nct| nct.to_s } %>)"
113
+ v-if="nestedModelIsAllowed(model, <%= f.list_model_names %>)"
91
114
  v-on="click: addComponent($event, '<%= f.name %>', model)">
92
115
  {{ model.label }}
93
116
  </a>
@@ -64,26 +64,22 @@ module RailsAdmin
64
64
  end
65
65
 
66
66
  class Field
67
- attr_accessor :name, :type
68
- attr_accessor :label, :help
69
- attr_accessor :picker_label
70
- attr_accessor :picker_records
71
- attr_accessor :allowed_nested_models
67
+ attr_accessor :name,
68
+ :type
69
+
70
+ attr_accessor :label,
71
+ :help,
72
+ :css_class
73
+
74
+ attr_accessor :picker_label,
75
+ :picker_model_name
76
+
77
+ attr_accessor :list_model_names
72
78
 
73
79
  def initialize(name, type, options = {})
74
80
  @name = name
75
81
  @type = type
76
82
  @label = name.to_s.humanize
77
-
78
- if type == :list
79
- allowed = options[:models].nil? ? [options[:model]] : options[:models]
80
-
81
- if allowed.nil?
82
- raise "At least one model should be set for JsonEditor::Field with type => :list"
83
- end
84
-
85
- @allowed_nested_models = allowed.map { |m| m.name.gsub("::","__") }
86
- end
87
83
  end
88
84
 
89
85
  def label(s = nil)
@@ -94,9 +90,17 @@ module RailsAdmin
94
90
  if s.nil? then return @help else @help = s end
95
91
  end
96
92
 
97
- def setup_picker(label, records)
98
- @picker_label = label
99
- @picker_records = records
93
+ def css_class(s = nil)
94
+ if s.nil? then return @css_class else @css_class = s end
95
+ end
96
+
97
+ def picker(options)
98
+ @picker_label = options[:label]
99
+ @picker_model_name = options[:model].name
100
+ end
101
+
102
+ def list(models)
103
+ @list_model_names = Array(models).map { |m| m.name.gsub("::","___") }
100
104
  end
101
105
  end
102
106
  end
@@ -1,3 +1,3 @@
1
1
  module RailsAdminJsonEditor
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_json_editor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jasper Haggenburg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-25 00:00:00.000000000 Z
11
+ date: 2015-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,7 @@ files:
66
66
  - README.md
67
67
  - Rakefile
68
68
  - app/assets/javascripts/rails_admin_json_editor/lodash.2.4.1.js
69
+ - app/assets/javascripts/rails_admin_json_editor/markdown.js
69
70
  - app/assets/javascripts/rails_admin_json_editor/rails_admin_json_editor.js
70
71
  - app/assets/javascripts/rails_admin_json_editor/vue.0.11.4.js
71
72
  - app/assets/stylesheets/rails_admin_json_editor/rails_admin_json_editor.css.scss