rails_admin_content 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/site.css +13 -8
- data/app/controllers/rails_admin_content/develop/application_controller.rb +1 -2
- data/app/controllers/rails_admin_content/develop/manages_controller.rb +72 -72
- data/app/views/layouts/rails_admin_content/admin.html.slim +11 -11
- data/app/views/rails_admin_content/develop/manages/_filter.html.slim +3 -3
- data/app/views/rails_admin_content/develop/manages/_navbar.html.slim +21 -28
- data/app/views/rails_admin_content/develop/manages/edit_column.html.slim +1 -1
- data/lib/rails_admin_content/client.rb +88 -88
- data/lib/rails_admin_content/engine.rb +3 -3
- data/lib/rails_admin_content/helper.rb +54 -54
- data/lib/rails_admin_content/mysql/adapters/client.rb +12 -16
- data/lib/rails_admin_content/paginate.rb +48 -48
- data/lib/rails_admin_content/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4103f556cac609bbd974d482f1ffade527d6e69d
|
4
|
+
data.tar.gz: 871320bb364970a9a9eae8ebbc55103a245afe8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83f17018b372dd42e8491bb81c2b2f86da99c54c8ba142c1039c96be2858c62e9049e62184b3b758a5be14711601edeac47e6f66ff809e02c7f395254d18a181
|
7
|
+
data.tar.gz: f55104928888207b0cf1422a44f8412d5c48eab43bf2ddbd4bcaa21d4e0e322a3cedef434c8ff63171e12062fa25b6a9ed6daf13778e0bb028c39982bcbeabd9
|
@@ -359,9 +359,8 @@ span.author-name{
|
|
359
359
|
}
|
360
360
|
|
361
361
|
#main-menu {
|
362
|
-
bottom:
|
363
|
-
left:
|
364
|
-
margin-right: -500px;
|
362
|
+
bottom: 8px;
|
363
|
+
left: 311px;
|
365
364
|
position: absolute;
|
366
365
|
}
|
367
366
|
|
@@ -388,9 +387,8 @@ span.author-name{
|
|
388
387
|
white-space: nowrap;
|
389
388
|
}
|
390
389
|
#main-menu li a {
|
391
|
-
background: none repeat scroll 0 0 #507AAA;
|
390
|
+
/* background: none repeat scroll 0 0 #507AAA; */
|
392
391
|
font-weight: bold;
|
393
|
-
padding: 4px 10px;
|
394
392
|
}
|
395
393
|
#main-menu li a:hover {
|
396
394
|
background: none repeat scroll 0 0 #759FCF;
|
@@ -486,6 +484,13 @@ span.author-name{
|
|
486
484
|
overflow: hidden;
|
487
485
|
}
|
488
486
|
|
489
|
-
.navbar li{
|
490
|
-
|
491
|
-
}
|
487
|
+
.navbar li .section{
|
488
|
+
margin: 2px;
|
489
|
+
}
|
490
|
+
.navbar li .section a{
|
491
|
+
padding: 10px;
|
492
|
+
background-color: #759fcf;
|
493
|
+
}
|
494
|
+
|
495
|
+
|
496
|
+
|
@@ -1,76 +1,76 @@
|
|
1
1
|
class RailsAdminContent::Develop::ManagesController < RailsAdminContent::Develop::ApplicationController
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
3
|
+
before_filter :find_params, except: %w(update create new)
|
4
|
+
|
5
|
+
def index
|
6
|
+
@version = RailsAdminContent::Client.conn.origin_query("SELECT VERSION() as version").each
|
7
|
+
end
|
8
|
+
|
9
|
+
def query
|
10
|
+
@entries = RailsAdminContent::Client.query(RailsAdminContent::Client.query_str,@page, @per).each if RailsAdminContent::Client.query_str
|
11
|
+
rescue Exception => e
|
12
|
+
flash[:errors] = e.message
|
13
|
+
end
|
14
|
+
|
15
|
+
def filter
|
16
|
+
RailsAdminContent::Client.query_str = params[:q]
|
17
|
+
redirect_to action: :query
|
18
|
+
end
|
19
|
+
|
20
|
+
def show
|
21
|
+
@query_str = "SELECT * FROM #{params[:id]} ORDER BY id DESC"
|
22
|
+
@query_str = RailsAdminContent::Client.compose(params) if params[:field].present?
|
23
|
+
@fields = RailsAdminContent::Client.desc_table params[:id]
|
24
|
+
@entries = RailsAdminContent::Client.query(@query_str,@page, @per)
|
25
|
+
rescue Exception => e
|
26
|
+
flash[:errors] = e.message
|
27
|
+
end
|
28
|
+
|
29
|
+
def new;end
|
30
|
+
|
31
|
+
def edit; end
|
32
|
+
|
33
|
+
def edit_column
|
34
|
+
@fields = RailsAdminContent::Client.desc_table params[:id]
|
35
|
+
end
|
36
|
+
|
37
|
+
def details
|
38
|
+
@details = RailsAdminContent::Client.conn.origin_query("SHOW TABLE STATUS LIKE '#{params[:id]}'").each
|
39
|
+
end
|
40
|
+
|
41
|
+
def create
|
42
|
+
RailsAdminContent::Client.insert(params[:table_name], params[:field])
|
43
|
+
flash[:success] = "成功添加#{params[:table_name]}一条数据。"
|
44
|
+
rescue Exception => e
|
45
|
+
flash[:errors] = e.message
|
46
|
+
ensure
|
47
|
+
redirect_to develop_manage_path(params[:table_name])
|
48
|
+
end
|
49
|
+
|
50
|
+
def update
|
51
|
+
RailsAdminContent::Client.update(params[:table_name], params[:id], params[:field])
|
52
|
+
flash[:success] = "更新#{params[:id]}内容成功。"
|
53
|
+
rescue Exception => e
|
54
|
+
flash[:errors] = e.message
|
55
|
+
ensure
|
56
|
+
redirect_to develop_manage_path(params[:table_name])
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def update_field
|
61
|
+
RailsAdminContent::Client.conn.origin_query("UPDATE #{params[:table]} SET #{params[:field]} = REPLACE(REPLACE(REPLACE('#{params[:value]}', '&','&'), '>', '>'), '<', '<') WHERE id = #{params[:id]}")
|
62
|
+
render text: 'success'
|
63
|
+
end
|
64
|
+
|
65
|
+
def destroy
|
66
|
+
RailsAdminContent::Client.delete(params[:id], params[:edit_id]) if params[:edit_id].present?
|
67
|
+
render json: params[:edit_id]
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def find_params
|
73
|
+
@page, @per = (params[:page] || 1).to_i, (params[:per] || 100).to_i
|
74
|
+
end
|
75
75
|
|
76
76
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
doctype html
|
2
2
|
html
|
3
3
|
head
|
4
|
-
title
|
4
|
+
title RailsAdmin
|
5
5
|
meta name="key_words" content="template languagea"
|
6
6
|
= stylesheet_link_tag "rails_admin_content", media: "all"
|
7
7
|
= javascript_include_tag 'rails_admin_content'
|
@@ -11,8 +11,10 @@ html
|
|
11
11
|
#wrapper2
|
12
12
|
#wrapper3
|
13
13
|
#header
|
14
|
-
h1
|
14
|
+
h1 RailsAdmin
|
15
15
|
#main-menu
|
16
|
+
- unless action_name =~ /query/
|
17
|
+
= render 'navbar'
|
16
18
|
- if flash[:success]
|
17
19
|
.alert.alert-success
|
18
20
|
button data-dismiss="alert" class="close" type="button" x
|
@@ -38,15 +40,13 @@ html
|
|
38
40
|
.span2
|
39
41
|
= render 'menv'
|
40
42
|
.content.span10
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
.span11
|
49
|
-
= yield
|
43
|
+
|
44
|
+
- if action_name =~ /show/
|
45
|
+
= render 'filter'
|
46
|
+
- elsif action_name =~ /query/
|
47
|
+
= render 'form'
|
48
|
+
.span11 style="width:100%;margin: 0px;"
|
49
|
+
= yield
|
50
50
|
- if @entries.present?
|
51
51
|
#edit_tools
|
52
52
|
span
|
@@ -19,7 +19,7 @@
|
|
19
19
|
= content_field(column)
|
20
20
|
|
21
21
|
.span8
|
22
|
-
= field_set_tag "
|
22
|
+
= field_set_tag "Selection" do
|
23
23
|
= select_tag 'select_field', options_for_select_column_data(params[:id]), class: 'span2', name: '', :prompt => "Select Filter"
|
24
|
-
= button_tag '
|
25
|
-
= link_to '
|
24
|
+
= button_tag 'Apply', class: 'btn'
|
25
|
+
= link_to 'Clear', '#', class: 'btn clear'
|
@@ -1,34 +1,27 @@
|
|
1
1
|
.span10
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
.navbar
|
3
|
+
ul
|
4
|
+
li
|
5
|
+
span.section
|
6
|
+
= link_to 'Home', develop_manages_path, class: 'btn-icon', title: 'Home'
|
7
|
+
li
|
8
|
+
span.section
|
9
|
+
= link_to 'Add', new_develop_manage_path(id: RailsAdminContent::Client.table_name), class: 'btn-icon', title: 'add'
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
dd Add
|
13
|
-
|
14
|
-
li class="#{ 'active' if action_name =~ /show/ && controller_name =~ /manages/ }"
|
15
|
-
= link_to develop_manage_path(RailsAdminContent::Client.table_name), class: 'btn-icon', title: 'Content' do
|
16
|
-
dt = image_tag("content.png")
|
17
|
-
dd Content
|
11
|
+
li class="#{ 'active' if action_name =~ /show/ && controller_name =~ /manages/ }"
|
12
|
+
span.section
|
13
|
+
= link_to 'Content', develop_manage_path(RailsAdminContent::Client.table_name), class: 'btn-icon', title: 'Content'
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
dd Structure
|
15
|
+
li class="#{ 'active' if action_name =~ /edit_column/ && controller_name =~ /manages/ }"
|
16
|
+
span.section
|
17
|
+
= link_to 'Structure', edit_column_develop_manage_path(RailsAdminContent::Client.table_name), class: 'btn-icon', title: 'Structure'
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
dd Table info
|
19
|
+
li class="#{ 'active' if action_name =~ /details/ && controller_name =~ /manages/ }"
|
20
|
+
span.section
|
21
|
+
= link_to 'Table', details_develop_manage_path(RailsAdminContent::Client.table_name), class: 'btn-icon', title: 'Table info'
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
dd Query
|
23
|
+
li
|
24
|
+
span.section
|
25
|
+
= link_to 'Query', query_develop_manages_path, class: 'btn-icon', title: 'Query'
|
33
26
|
|
34
|
-
|
27
|
+
div style="clear:both"
|
@@ -1,93 +1,93 @@
|
|
1
1
|
class RailsAdminContent::Client < Mysql2::Client
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
3
|
+
Syntax = /limit\s+\d+,\d+|limit\s+\d+/
|
4
|
+
Syntax_table = /from\s+(\w+)/
|
5
|
+
|
6
|
+
cattr_accessor :query_str, :total_nums, :table_name
|
7
|
+
|
8
|
+
def self.select_field(type)
|
9
|
+
case type.gsub(/\(.*?\)/,'')
|
10
|
+
when "tinyint" then [['等于', '='], ['不等于', '≠']]
|
11
|
+
when "datetime" then [['等于', '='], ['不等于', '≠'], ['大于', '>'], ['小于','<']]
|
12
|
+
when "int" then [['等于', '='], ['不等于', '≠'], ['大于', '>'], ['小于','<'], ['含有', 'IN']]
|
13
|
+
else
|
14
|
+
[['等于', '='], ['不等于', '≠'], ['包含', 'LIKE']]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.conn
|
19
|
+
@client ||= new ActiveRecord::Base.connection_config
|
20
|
+
end
|
21
|
+
|
22
|
+
alias :origin_query :query
|
23
|
+
|
24
|
+
def self.query(query_sql, page=nil, stint=nil)
|
25
|
+
self.table_name = query_sql.downcase.match(Syntax_table)[1] if query_sql.downcase.match(Syntax_table)
|
26
|
+
self.total_nums = conn.origin_query(query_sql).size
|
27
|
+
query_sql = limit(query_sql, page, stint) if stint && page
|
28
|
+
query_sql = query_sql.gsub(/;/, '')
|
29
|
+
conn.origin_query(query_sql)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.limit(query_sql, page=1, stint)
|
33
|
+
page = page == 1 ? page = 0 : page.to_i*stint.to_i-stint.to_i
|
34
|
+
query_sql.downcase.match(Syntax).present? ? query_sql.downcase.gsub(Syntax, "LIMIT #{page},#{stint}") : "#{query_sql} LIMIT #{page},#{stint}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.get_tables
|
38
|
+
@tables ? @tables : @tables = conn.origin_query('SHOW TABLES')
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.compose(params)
|
42
|
+
"SELECT * FROM #{params[:id]} WHERE #{params["field"].inject([]){|a, (key,value)| a << compose_key(params["calc"][key],key, value); a }.join('and')}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.compose_key(calc,key,value)
|
46
|
+
case calc
|
47
|
+
when '=', '>', '<'
|
48
|
+
" `#{key}` #{calc} '#{value}' "
|
49
|
+
when 'IN'
|
50
|
+
" `#{key}` IN (#{value}) "
|
51
|
+
when '≠'
|
52
|
+
" `#{key}` != '#{value}' "
|
53
|
+
when 'LIKE'
|
54
|
+
" `#{key}` LIKE '%#{value}%' "
|
55
|
+
when '≥'
|
56
|
+
" `#{key}` >= '#{value}' "
|
57
|
+
when '≤'
|
58
|
+
" `#{key}` <= '#{value}' "
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def self.delete(table_name, ids)
|
64
|
+
conn.origin_query("DELETE FROM #{table_name} WHERE id IN (#{ids.join(',')})") if ids.is_a?(Array)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.insert(table_name, field)
|
68
|
+
conn.origin_query("INSERT INTO #{table_name} (#{field.keys.join(',')}) VALUES ('#{field.values.join("','")}')")
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.update(table_name, id, fields)
|
72
|
+
update_str = "UPDATE #{table_name} SET #{compose_update_sql(table_name, fields.to_a)} WHERE id = #{id}"
|
73
|
+
conn.origin_query update_str
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.compose_update_sql(table_name,fields)
|
77
|
+
columns = desc_table(table_name)
|
78
|
+
fields.inject([]) do |array, field|
|
79
|
+
columns.each do |column|
|
80
|
+
if field[0] == column["Field"]
|
81
|
+
array << (%w(int decimal tinyint).include?(column["Type"].gsub(/\(.*?\)/,'')) ? "#{field[0]} = #{field[1]}" : "#{field[0]} = REPLACE(REPLACE(REPLACE('#{field[1]}', '&','&'), '>', '>'), '<', '<')")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
array
|
85
|
+
end.join(',')
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.desc_table(table_name)
|
89
|
+
conn.origin_query("DESC #{table_name}").each
|
90
|
+
end
|
91
91
|
|
92
92
|
|
93
93
|
end
|
@@ -6,7 +6,7 @@ require 'rails_admin_content/client'
|
|
6
6
|
require 'rails_admin_content/helper'
|
7
7
|
|
8
8
|
module RailsAdminContent
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
class Engine < ::Rails::Engine
|
10
|
+
isolate_namespace RailsAdminContent
|
11
|
+
end
|
12
12
|
end
|
@@ -1,65 +1,65 @@
|
|
1
1
|
module ActionView
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
module Helpers
|
3
|
+
module DateHelper
|
4
|
+
def custom_paginate(scope, options = {})
|
5
|
+
paginate = RailsAdminContent::Paginate.new(scope, options.update(per_page: options[:stint]))
|
6
|
+
paginate.to_s
|
7
|
+
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
def format(value, limit=10)
|
10
|
+
value = value.is_a?(String) && value.size > limit ? value.truncate(limit) : value
|
11
|
+
value = value.is_a?(Time) ? value.to_s(:db) : value
|
12
|
+
value ||= "null"
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def menu_value(value, icon)
|
16
|
+
raw <<-HTML
|
17
|
+
<i class="#{icon}"></i><span class="hidden-tablet">#{value}</span>
|
18
|
+
HTML
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
def link_to_menu(*args, &block)
|
22
|
+
name = menu_value(args[0], args[1])
|
23
|
+
options = args[2] || {}
|
24
|
+
html_options = args[3]
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
html_options = convert_options_to_data_attributes(options, html_options)
|
27
|
+
url = url_for(options)
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
href = html_options['href']
|
30
|
+
tag_options = tag_options(html_options)
|
31
|
+
href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href
|
32
|
+
"<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
35
|
+
def edited(key, value, str='')
|
36
|
+
str << 'editable' unless key == 'id'
|
37
|
+
str << ' edit_datepicker' if value.is_a?(Time)
|
38
|
+
str
|
39
|
+
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
def options_for_select_column_data(table, selected=nil)
|
42
|
+
options_for_select RailsAdminContent::Client.desc_table(table).map{|a| [ a["Field"],a["Field"], column_type: a["Type"].gsub(/\(.*?\)/,'') ]}, selected
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
45
|
+
def content_field(column, value=nil)
|
46
|
+
type = column["Type"].gsub(/\(.*?\)/,'')
|
47
|
+
column["Default"] = value if value
|
48
|
+
column["Field"] = "field[#{column["Field"]}]"
|
49
|
+
case type
|
50
|
+
when 'text'
|
51
|
+
text_area_tag column["Field"], column["Default"], :size => "25x6", 'data-field' => column["Field"], class: "#{type} span10"
|
52
|
+
when 'varchar'
|
53
|
+
text_field_tag column["Field"], column["Default"], 'data-field' => column["Field"], class: "#{type} span10"
|
54
|
+
when 'int'
|
55
|
+
number_field_tag column["Field"], column["Default"], 'data-field' => column["Field"], class: "#{type} span10"
|
56
|
+
when 'tinyint'
|
57
|
+
select_tag column["Field"], options_for_select([['Yes',1],['No',0]], column["Default"]), 'data-field' => column["Field"], class: "#{type} span10"
|
58
|
+
else
|
59
|
+
text_field_tag column["Field"], column["Default"], 'data-field' => column["Field"], class: "#{type} span10"
|
60
|
+
end
|
61
|
+
end
|
62
62
|
|
63
|
-
|
64
|
-
|
63
|
+
end
|
64
|
+
end
|
65
65
|
end
|
@@ -1,18 +1,14 @@
|
|
1
1
|
module RailsAdminContent
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
2
|
+
module Mysql
|
3
|
+
module Adapters
|
4
|
+
class Client
|
5
|
+
def initialize
|
6
|
+
@client = client = Mysql2::Client.new ActiveRecord::Base.connection_config
|
7
|
+
end
|
8
|
+
def query(sql)
|
9
|
+
@client.query(sql).each
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
18
14
|
end
|
@@ -1,53 +1,53 @@
|
|
1
1
|
module RailsAdminContent
|
2
|
-
|
3
|
-
|
4
|
-
def initialize(scope, options = {})
|
5
|
-
@scope, @options = scope, options
|
6
|
-
end
|
2
|
+
class Paginate
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
# return "共#{RailsAdminContent::Client.total_nums}条数据" if total_pages <= 1
|
12
|
-
param_name = @options["param_name"] || "page"
|
13
|
-
url = @options["url"] || ""
|
14
|
-
helpers.content_tag :div, :class => "pagination" do
|
15
|
-
helpers.content_tag :ul do
|
16
|
-
result = ''
|
17
|
-
result += helpers.content_tag(:li, class: 'previous'){helpers.link_to("‹ 上一页","#{url}?#{param_name}=#{current_page-1}")} if current_page.to_i > 1
|
18
|
-
if total_pages > 8
|
19
|
-
1.upto(3) { |i| result << page_link(i, current_page) }
|
20
|
-
if current_page > 1 and current_page < total_pages
|
21
|
-
result << helpers.content_tag(:li, helpers.link_to("...",'#'), class: 'disabled') if current_page > 5
|
22
|
-
min = current_page > 4 ? current_page-1 : 4
|
23
|
-
max = current_page < total_pages-4 ? current_page+2 : total_pages-2
|
24
|
-
(min..max-1).each { |i| result << page_link(i, current_page) } if max >= min+1
|
25
|
-
result << helpers.content_tag(:li, helpers.link_to("...", "#"), class: 'disabled') if current_page < total_pages-4
|
26
|
-
else
|
27
|
-
result << helpers.content_tag(:li, helpers.link_to("...",'#'), class: 'disabled')
|
28
|
-
end
|
29
|
-
(total_pages-2..total_pages).each{ |i| result << page_link(i, current_page) }
|
30
|
-
else
|
31
|
-
(1..total_pages).each{ |i| result << page_link(i, current_page) }
|
32
|
-
end
|
33
|
-
result += helpers.content_tag(:li, class: "next"){helpers.link_to("下一页 ›", "#{url}?#{param_name}=#{current_page+1}")} if current_page < total_pages
|
34
|
-
result += helpers.content_tag(:li, class: 'disabled total_pages'){helpers.link_to "共#{RailsAdminContent::Client.total_nums}条数据", "#"}
|
35
|
-
result.html_safe
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
4
|
+
def initialize(scope, options = {})
|
5
|
+
@scope, @options = scope, options
|
6
|
+
end
|
40
7
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
8
|
+
def to_s
|
9
|
+
return "" unless @scope
|
10
|
+
current_page, total_pages = @options[:spage].to_i, RailsAdminContent::Client.total_nums / @options[:stint] + 1
|
11
|
+
# return "共#{RailsAdminContent::Client.total_nums}条数据" if total_pages <= 1
|
12
|
+
param_name = @options["param_name"] || "page"
|
13
|
+
url = @options["url"] || ""
|
14
|
+
helpers.content_tag :div, :class => "pagination" do
|
15
|
+
helpers.content_tag :ul do
|
16
|
+
result = ''
|
17
|
+
result += helpers.content_tag(:li, class: 'previous'){helpers.link_to("‹ 上一页","#{url}?#{param_name}=#{current_page-1}")} if current_page.to_i > 1
|
18
|
+
if total_pages > 8
|
19
|
+
1.upto(3) { |i| result << page_link(i, current_page) }
|
20
|
+
if current_page > 1 and current_page < total_pages
|
21
|
+
result << helpers.content_tag(:li, helpers.link_to("...",'#'), class: 'disabled') if current_page > 5
|
22
|
+
min = current_page > 4 ? current_page-1 : 4
|
23
|
+
max = current_page < total_pages-4 ? current_page+2 : total_pages-2
|
24
|
+
(min..max-1).each { |i| result << page_link(i, current_page) } if max >= min+1
|
25
|
+
result << helpers.content_tag(:li, helpers.link_to("...", "#"), class: 'disabled') if current_page < total_pages-4
|
26
|
+
else
|
27
|
+
result << helpers.content_tag(:li, helpers.link_to("...",'#'), class: 'disabled')
|
28
|
+
end
|
29
|
+
(total_pages-2..total_pages).each{ |i| result << page_link(i, current_page) }
|
30
|
+
else
|
31
|
+
(1..total_pages).each{ |i| result << page_link(i, current_page) }
|
32
|
+
end
|
33
|
+
result += helpers.content_tag(:li, class: "next"){helpers.link_to("下一页 ›", "#{url}?#{param_name}=#{current_page+1}")} if current_page < total_pages
|
34
|
+
result += helpers.content_tag(:li, class: 'disabled total_pages'){helpers.link_to "共#{RailsAdminContent::Client.total_nums}条数据", "#"}
|
35
|
+
result.html_safe
|
36
|
+
end
|
37
|
+
end
|
47
38
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def page_link(page, current_page)
|
43
|
+
param_name = @options["param_name"] || "page"
|
44
|
+
url = @options["url"] || ""
|
45
|
+
current_page == page ? helpers.content_tag(:li, page, :class => "active"){helpers.link_to page, '#'} : helpers.content_tag(:li, helpers.link_to("#{page}", "#{url}?#{param_name}=#{page}"))
|
46
|
+
end
|
47
|
+
|
48
|
+
def helpers
|
49
|
+
ActionController::Base.helpers
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_admin_content
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Terry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|