rademade_admin 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/rademade_admin.coffee +1 -0
- data/app/assets/javascripts/rademade_admin/app/common/cropper.coffee +0 -4
- data/app/assets/javascripts/rademade_admin/app/common/image-preview.coffee +33 -0
- data/app/assets/javascripts/rademade_admin/app/templates/image-preview-popup.jst.ejs +3 -0
- data/app/assets/javascripts/rademade_admin/app/templates/related-item.jst.ejs +2 -2
- data/app/assets/javascripts/rademade_admin/library/ckeditor/config.js +1 -0
- data/app/assets/stylesheets/edit.css +15 -0
- data/app/assets/stylesheets/rademade_admin/base/main.sass +45 -39
- data/app/assets/stylesheets/rademade_admin/blocks/buttons/main.sass +6 -1
- data/app/assets/stylesheets/rademade_admin/blocks/form/select2.sass +85 -60
- data/app/controllers/rademade_admin/model_controller.rb +3 -0
- data/app/helpers/rademade_admin/field_helper.rb +25 -13
- data/app/helpers/rademade_admin/form_helper.rb +4 -6
- data/app/helpers/rademade_admin/uri_helper.rb +3 -3
- data/app/services/csv_service.rb +38 -0
- data/app/services/linker.rb +3 -1
- data/app/services/model_controller/instance_options.rb +7 -2
- data/app/services/model_controller/notifier.rb +15 -19
- data/app/services/model_controller/templates.rb +1 -0
- data/app/services/saver.rb +6 -1
- data/app/services/template_service.rb +38 -19
- data/app/services/upload/preview_service.rb +2 -1
- data/app/views/rademade_admin/_blocks/_form.html.erb +6 -5
- data/app/views/rademade_admin/_blocks/button/_hide.html.erb +2 -2
- data/app/views/rademade_admin/_layouts/main.html.erb +3 -6
- data/app/views/rademade_admin/abstract/index.html.erb +4 -2
- data/config/locales/rademade_admin.en.yml +2 -1
- data/config/locales/rademade_admin.ru.yml +2 -1
- data/lib/rademade_admin/{hrml_buffer.rb → html_buffer.rb} +0 -0
- data/lib/rademade_admin/input/related_select_input/related_list.rb +8 -5
- data/lib/rademade_admin/model/adapter/data/mongoid.rb +1 -1
- data/lib/rademade_admin/model/adapter/query/active_record.rb +1 -1
- data/lib/rademade_admin/model/configuration.rb +17 -1
- data/lib/rademade_admin/model/configuration/csv_fields.rb +12 -0
- data/lib/rademade_admin/model/configuration/list_field.rb +5 -1
- data/lib/rademade_admin/model/info.rb +10 -1
- data/lib/rademade_admin/model/info/data_item.rb +31 -13
- data/lib/rademade_admin/model/info/data_item/initializer.rb +37 -0
- data/lib/rademade_admin/model/info/data_items.rb +11 -1
- data/lib/rademade_admin/model/info/fields.rb +39 -26
- data/lib/rademade_admin/version.rb +1 -1
- metadata +22 -4
- data/app/assets/javascripts/rademade_admin/library/jquery/jquery.tablednd.js +0 -1
@@ -65,12 +65,10 @@ module RademadeAdmin::FormHelper
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def default_field_type(data_item)
|
68
|
-
if data_item.
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
:'rademade_admin/related_select'
|
73
|
-
end
|
68
|
+
if data_item.gallery_relation?
|
69
|
+
:'rademade_admin/gallery'
|
70
|
+
elsif data_item.has_relation?
|
71
|
+
:'rademade_admin/related_select'
|
74
72
|
elsif data_item.has_uploader?
|
75
73
|
:'rademade_admin/file'
|
76
74
|
elsif data_item.date_time?
|
@@ -10,10 +10,10 @@ module RademadeAdmin::UriHelper
|
|
10
10
|
RademadeAdmin::Engine.routes.url_helpers.send(route_url, opts)
|
11
11
|
end
|
12
12
|
|
13
|
-
def admin_list_uri(model)
|
14
|
-
admin_model_url_for(model, {
|
13
|
+
def admin_list_uri(model, opts = {})
|
14
|
+
admin_model_url_for(model, opts.merge({
|
15
15
|
:action => :index
|
16
|
-
})
|
16
|
+
}))
|
17
17
|
end
|
18
18
|
|
19
19
|
def admin_autocomplete_uri(model, opts = {})
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
module RademadeAdmin
|
5
|
+
class CsvService
|
6
|
+
|
7
|
+
def initialize(model_info, items)
|
8
|
+
@model_info = model_info
|
9
|
+
@items = items
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_csv
|
13
|
+
::CSV.generate(col_sep: ',', encoding: 'utf-8') do |csv|
|
14
|
+
csv << column_names
|
15
|
+
@items.each do |item|
|
16
|
+
csv << item_data(item)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def column_names
|
22
|
+
@model_info.data_items.csv_fields.map(&:label)
|
23
|
+
end
|
24
|
+
|
25
|
+
def item_data(item)
|
26
|
+
data = []
|
27
|
+
@model_info.data_items.csv_fields.each do |field|
|
28
|
+
data << field_value(field, item)
|
29
|
+
end
|
30
|
+
data
|
31
|
+
end
|
32
|
+
|
33
|
+
def field_value(field, item)
|
34
|
+
return field.csv_preview_handler.call(item) unless field.csv_preview_handler.nil?
|
35
|
+
item.send(field.csv_preview_accessor).to_s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/app/services/linker.rb
CHANGED
@@ -13,7 +13,9 @@ module RademadeAdmin
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def unlink(id)
|
16
|
-
process_link { |old_data|
|
16
|
+
process_link { |old_data|
|
17
|
+
old_data.delete_if { |data_item| data_item.id.to_s == id.to_s }
|
18
|
+
}
|
17
19
|
end
|
18
20
|
|
19
21
|
private
|
@@ -2,9 +2,14 @@
|
|
2
2
|
module RademadeAdmin
|
3
3
|
module InstanceOptions
|
4
4
|
|
5
|
-
attr_reader :model_info,
|
5
|
+
attr_reader :model_info,
|
6
|
+
:model_class,
|
7
|
+
:model_name,
|
8
|
+
:item_name,
|
6
9
|
:list_fields,
|
7
|
-
|
10
|
+
# TODO form_fields refactor
|
11
|
+
:form_fields_without_locale,
|
12
|
+
:form_fields_with_locale
|
8
13
|
|
9
14
|
def load_model_options
|
10
15
|
@model_info = self.class.model_info
|
@@ -2,6 +2,8 @@
|
|
2
2
|
module RademadeAdmin
|
3
3
|
module Notifier
|
4
4
|
|
5
|
+
# TODO use responder (respond with)
|
6
|
+
|
5
7
|
def success_action
|
6
8
|
render :json => {
|
7
9
|
:message => I18n.t('rademade_admin.success_message')
|
@@ -11,43 +13,28 @@ module RademadeAdmin
|
|
11
13
|
def success_insert(item)
|
12
14
|
respond_to do |format|
|
13
15
|
format.html { redirect_to admin_edit_uri(item) }
|
14
|
-
format.json {
|
15
|
-
if params.has_key?(:create_and_return)
|
16
|
-
data = { :redirect_to => admin_list_uri(item.class) }
|
17
|
-
else
|
18
|
-
data = { :form_action => admin_update_uri(item) }
|
19
|
-
end
|
20
|
-
success_message(item, I18n.t('rademade_admin.success_insert_message'), data)
|
21
|
-
}
|
16
|
+
format.json { success_message(item, I18n.t('rademade_admin.success_insert_message'), success_data(item)) }
|
22
17
|
end
|
23
18
|
end
|
24
19
|
|
25
20
|
def success_update(item)
|
26
21
|
respond_to do |format|
|
27
22
|
format.html { redirect_to admin_edit_uri(item) }
|
28
|
-
format.json {
|
29
|
-
data = {}
|
30
|
-
data[:redirect_to] = admin_list_uri(item.class) if params.has_key?(:create_and_return)
|
31
|
-
success_message(item, I18n.t('rademade_admin.success_update_message'), data)
|
32
|
-
}
|
23
|
+
format.json { success_message(item, I18n.t('rademade_admin.success_update_message'), success_data(item)) }
|
33
24
|
end
|
34
25
|
end
|
35
26
|
|
36
27
|
def success_delete(item)
|
37
28
|
respond_to do |format|
|
38
29
|
format.html { redirect_to admin_list_uri(item) }
|
39
|
-
format.json {
|
40
|
-
success_message(item, I18n.t('rademade_admin.success_delete_message'))
|
41
|
-
}
|
30
|
+
format.json { success_message(item, I18n.t('rademade_admin.success_delete_message')) }
|
42
31
|
end
|
43
32
|
end
|
44
33
|
|
45
34
|
def success_status_change(item)
|
46
35
|
respond_to do |format|
|
47
36
|
format.html { redirect_to admin_list_uri(item) }
|
48
|
-
format.json {
|
49
|
-
success_message(item, t('rademade_admin.success_status_update_message'))
|
50
|
-
}
|
37
|
+
format.json { success_message(item, t('rademade_admin.success_status_update_message')) }
|
51
38
|
end
|
52
39
|
end
|
53
40
|
|
@@ -70,5 +57,14 @@ module RademadeAdmin
|
|
70
57
|
}.merge(additional_data)
|
71
58
|
end
|
72
59
|
|
60
|
+
def success_data(item)
|
61
|
+
data = {}
|
62
|
+
if params.has_key?(:create_and_return)
|
63
|
+
data[:redirect_to] = admin_list_uri(item.class)
|
64
|
+
else
|
65
|
+
data[:form_action] = admin_update_uri(item) # TODO check JS. Rename for update
|
66
|
+
end
|
67
|
+
data
|
68
|
+
end
|
73
69
|
end
|
74
70
|
end
|
data/app/services/saver.rb
CHANGED
@@ -68,7 +68,12 @@ module RademadeAdmin
|
|
68
68
|
unless image_path.blank?
|
69
69
|
full_image_path = "#{CarrierWave.root}#{image_path}"
|
70
70
|
begin
|
71
|
-
|
71
|
+
if item.try(:translation).respond_to? data_item.setter
|
72
|
+
entity = item.translation
|
73
|
+
else
|
74
|
+
entity = item
|
75
|
+
end
|
76
|
+
entity.send(data_item.setter, File.open(full_image_path))
|
72
77
|
rescue
|
73
78
|
# rm_todo clear image
|
74
79
|
end
|
@@ -2,6 +2,25 @@
|
|
2
2
|
module RademadeAdmin
|
3
3
|
class TemplateService
|
4
4
|
|
5
|
+
attr_accessor :index_template,
|
6
|
+
:inner_layout,
|
7
|
+
:main_layout,
|
8
|
+
:inner_form_layout,
|
9
|
+
:form_block,
|
10
|
+
:form_control_block,
|
11
|
+
:form_lang_panel_block,
|
12
|
+
:form_separator_block,
|
13
|
+
:pagination_block ,
|
14
|
+
:on_page_select_block,
|
15
|
+
:sort_reset_block,
|
16
|
+
:search_block,
|
17
|
+
:header_block,
|
18
|
+
:menu_block,
|
19
|
+
:sub_menu_block,
|
20
|
+
:sub_menu_link_block,
|
21
|
+
:table_head_block,
|
22
|
+
:cancel_button
|
23
|
+
|
5
24
|
def initialize(root_dir)
|
6
25
|
@root_dir = root_dir
|
7
26
|
end
|
@@ -11,75 +30,75 @@ module RademadeAdmin
|
|
11
30
|
end
|
12
31
|
|
13
32
|
def index_template
|
14
|
-
abstract_template 'index'
|
33
|
+
@index_template ||= abstract_template 'index'
|
15
34
|
end
|
16
35
|
|
17
36
|
def inner_layout
|
18
|
-
layout_path 'inner'
|
37
|
+
@inner_layout ||= layout_path 'inner'
|
19
38
|
end
|
20
39
|
|
21
40
|
def main_layout
|
22
|
-
layout_path 'main'
|
41
|
+
@main_layout ||= layout_path 'main'
|
23
42
|
end
|
24
43
|
|
25
44
|
def inner_form_layout
|
26
|
-
layout_path 'inner/form'
|
45
|
+
@inner_form_layout ||= layout_path 'inner/form'
|
27
46
|
end
|
28
47
|
|
29
48
|
def form_block
|
30
|
-
block_path 'form'
|
49
|
+
@form_block ||= block_path 'form'
|
31
50
|
end
|
32
51
|
|
33
52
|
def form_control_block
|
34
|
-
block_path 'form/control'
|
53
|
+
@form_control_block ||= block_path 'form/control'
|
35
54
|
end
|
36
55
|
|
37
56
|
def form_lang_panel_block
|
38
|
-
block_path 'form/lang_panel'
|
57
|
+
@form_lang_panel_block ||= block_path 'form/lang_panel'
|
39
58
|
end
|
40
59
|
|
41
60
|
def form_separator_block
|
42
|
-
block_path 'form/separator'
|
61
|
+
@form_separator_block ||= block_path 'form/separator'
|
43
62
|
end
|
44
63
|
|
45
64
|
def pagination_block
|
46
|
-
block_path 'pagination'
|
65
|
+
@pagination_block ||= block_path 'pagination'
|
47
66
|
end
|
48
67
|
|
49
68
|
def on_page_select_block
|
50
|
-
block_path 'on_page_select'
|
69
|
+
@on_page_select_block ||= block_path 'on_page_select'
|
51
70
|
end
|
52
71
|
|
53
72
|
def sort_reset_block
|
54
|
-
block_path 'sort_reset'
|
73
|
+
@sort_reset_block ||= block_path 'sort_reset'
|
55
74
|
end
|
56
75
|
|
57
76
|
def search_block
|
58
|
-
block_path 'search'
|
77
|
+
@search_block ||= block_path 'search'
|
59
78
|
end
|
60
79
|
|
61
80
|
def header_block
|
62
|
-
block_path 'header'
|
81
|
+
@header_block ||= block_path 'header'
|
63
82
|
end
|
64
83
|
|
65
84
|
def menu_block
|
66
|
-
block_path 'menu'
|
85
|
+
@menu_block ||= block_path 'menu'
|
67
86
|
end
|
68
87
|
|
69
88
|
def sub_menu_block
|
70
|
-
block_path 'sub_menu'
|
89
|
+
@sub_menu_block ||= block_path 'sub_menu'
|
71
90
|
end
|
72
91
|
|
73
92
|
def sub_menu_link_block
|
74
|
-
block_path 'sub_menu/link'
|
93
|
+
@sub_menu_link_block ||= block_path 'sub_menu/link'
|
75
94
|
end
|
76
95
|
|
77
96
|
def table_head_block
|
78
|
-
block_path 'table/head'
|
97
|
+
@table_head_block ||= block_path 'table/head'
|
79
98
|
end
|
80
99
|
|
81
100
|
def cancel_button
|
82
|
-
block_path 'button/cancel'
|
101
|
+
@cancel_button ||= block_path 'button/cancel'
|
83
102
|
end
|
84
103
|
|
85
104
|
private
|
@@ -97,4 +116,4 @@ module RademadeAdmin
|
|
97
116
|
end
|
98
117
|
|
99
118
|
end
|
100
|
-
end
|
119
|
+
end
|
@@ -12,7 +12,7 @@ module RademadeAdmin
|
|
12
12
|
|
13
13
|
def preview_html
|
14
14
|
content_tag(:div, :class => ['preview-wrapper', preview_style_class].join(' ')) do
|
15
|
-
if @uploader.blank?
|
15
|
+
if @uploader.blank? || @uploader.size.zero?
|
16
16
|
empty_file_html
|
17
17
|
else
|
18
18
|
uploaded_file_html
|
@@ -63,6 +63,7 @@ module RademadeAdmin
|
|
63
63
|
def uploaded_image_preview
|
64
64
|
content_tag(:img, '', {
|
65
65
|
:src => @uploader.resize(230, 130),
|
66
|
+
:'full-url' => @uploader.url,
|
66
67
|
:class => 'image-preview',
|
67
68
|
:width => 230,
|
68
69
|
:height => 130,
|
@@ -1,10 +1,11 @@
|
|
1
1
|
<%
|
2
2
|
show_buttons = show_buttons.nil? ? true : show_buttons
|
3
3
|
buttons_template ||= @template_service.form_control_block
|
4
|
-
%><%= admin_form(@item, @model_class) do |
|
4
|
+
%><%= admin_form(@item, @model_class) do |form| %><%
|
5
5
|
@form_fields_without_locale.each do |form_field|
|
6
|
-
admin_field(
|
6
|
+
admin_field(form, form_field, @model_info)
|
7
7
|
end
|
8
|
-
concat
|
9
|
-
concat render
|
10
|
-
|
8
|
+
concat yield(:additional_fields) if content_for?(:additional_fields)
|
9
|
+
concat render @template_service.form_lang_panel_block, { :f => form }
|
10
|
+
concat render buttons_template, { :f => form } if show_buttons
|
11
|
+
end %>
|
@@ -2,11 +2,11 @@
|
|
2
2
|
if @model_info.hideable? && can?(:edit, @model)
|
3
3
|
element_id = "hide_#{item.id}"
|
4
4
|
toggle_url = admin_url_for(
|
5
|
-
:controller => :status,
|
5
|
+
:controller => :"rademade_admin/status",
|
6
6
|
:action => :toggle,
|
7
7
|
:model => @model,
|
8
8
|
:id => item.id
|
9
|
-
) #todo via native method. Add route
|
9
|
+
) #todo via native method. Add route resource
|
10
10
|
|
11
11
|
%><div class="view-option">
|
12
12
|
<input id="<%=element_id%>" data-toggle-url="<%= toggle_url %>" type="checkbox"<%
|
@@ -1,13 +1,10 @@
|
|
1
|
-
<% content_for :head do %>
|
2
|
-
<%= stylesheet_link_tag(:rademade_admin, :media => 'all', 'data-turbolinks-track' => true) %>
|
3
|
-
<%= javascript_include_tag(:rademade_admin, 'data-turbolinks-track' => true) %>
|
4
|
-
<% end %>
|
5
|
-
|
6
1
|
<!DOCTYPE html>
|
7
2
|
<html>
|
8
3
|
<head>
|
9
4
|
<title>Rademade Admin</title>
|
10
|
-
<%=
|
5
|
+
<%= javascript_include_tag(:rademade_admin, 'data-turbolinks-track' => true) %>
|
6
|
+
<%= yield(:head) if content_for?(:head) %>
|
7
|
+
<%= stylesheet_link_tag(:rademade_admin, :media => 'all', 'data-turbolinks-track' => true) %>
|
11
8
|
<%= csrf_meta_tags %>
|
12
9
|
</head>
|
13
10
|
|
@@ -4,8 +4,10 @@
|
|
4
4
|
|
5
5
|
<% content_for :nav_buttons do %><%
|
6
6
|
new_uri = admin_new_uri(@model_info)
|
7
|
-
if new_uri
|
8
|
-
|
7
|
+
concat link_to(t('rademade_admin.new_record') + '+', new_uri, :class => 'btn yellow-btn fl-l') if new_uri
|
8
|
+
if @model_info.has_csv?
|
9
|
+
csv_uri = admin_list_uri(@model_info, :format => :csv)
|
10
|
+
concat link_to(t('rademade_admin.export_to_csv'), csv_uri, :class => 'btn green-btn fl-l l-margin') if csv_uri
|
9
11
|
end
|
10
12
|
end %>
|
11
13
|
|
File without changes
|
@@ -37,17 +37,20 @@ module RademadeAdmin
|
|
37
37
|
|
38
38
|
def related_list_item_edit_html(serialized_value)
|
39
39
|
if serialized_value[:editurl]
|
40
|
-
template.content_tag(
|
41
|
-
:
|
42
|
-
:'
|
43
|
-
)
|
40
|
+
template.content_tag(:button, I18n.t('rademade_admin.edit_related_item'), {
|
41
|
+
:'data-edit' => serialized_value[:editurl],
|
42
|
+
:class => 'select2-item-edit'
|
43
|
+
})
|
44
44
|
else
|
45
45
|
''
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
49
|
def related_list_item_remove_html
|
50
|
-
template.content_tag(:button, I18n.t('rademade_admin.destroy'),
|
50
|
+
template.content_tag(:button, I18n.t('rademade_admin.destroy'), {
|
51
|
+
:'data-remove' => '',
|
52
|
+
:class => 'select2-item-remove'
|
53
|
+
})
|
51
54
|
end
|
52
55
|
|
53
56
|
def related_list_link_html
|