-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin1.sh
executable file
·215 lines (162 loc) · 6.08 KB
/
admin1.sh
1
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env bash
echo ~----------~----------Startingd $HOSTNAME, pwd: `pwd`, dlr0: "$0", bashsource0: "${BASH_SOURCE[0]}", $(date +"%Y-%m-%d_%H.%M.%S")
### admin1 .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#echo "gem 'rails_admin', :git => 'https://github.com/dgleba/rails_admin.git'" >> Gemfile
# 2017-05-21 got error with git repo. Missing template rails_admin/main/dashboard, rails_admin/application/dashboard with...
# changed to v 1.1.1...
echo "gem 'rails_admin'" >> Gemfile
#
bundle update
# gem1="gem 'activeadmin', github: 'activeadmin'"
# echo "$gem1" >> Gemfile
#echo "gem 'administrate'" >> Gemfile
#echo "gem 'bourbon'" >> Gemfile
bundle update
# active admin..
# rails g active_admin:install --skip-users
# rake db:migrate
# rake db:seed
# rails generate active_admin:resource Product
# rails destroy active_admin:resource Products
# administrate by thoughtbot
#rails generate administrate:install
# error..
# /Users/dg/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.7.1/lib/rails/generators/named_base.rb:102:in
# `block in class_name': undefined method `camelize' for nil:NilClass (NoMethodError)
#
# named_base.rb`block in class_name': undefined method `camelize' for nil:NilClass (NoMethodError)
#
# ans.. must add administrate after data is added.
git add -A # Add all files and commit them
git commit -m "install admin1"
### admin2 .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# rails_admin..
# + expect
# spawn rails g rails_admin:install
# couldn't execute "rails g rails_admin:install": no such file or directory
# while executing
# "spawn "rails g rails_admin:install""
# ---
# question for .. rails g rails_admin:install
# ? Where do you want to mount rails_admin? Press <enter> for [admin] >
#
# prog='rails g rails_admin:install'
# expect <<EOF
# spawn "$prog"
# expect "[admin] >"
# send "radmin\n"
# expect eof
# exit
# EOF
# works..
printf 'radmin\n' | rails g rails_admin:install
sleep 1
git add -A # Add all files and commit them
git commit -m "install admin"
# _____________ custom layout for rails_admin list
# https://github.com/sferik/rails_admin/wiki/Horizontally-scrolling-table-with-frozen-columns-in-list-view
mkdir -p app/assets/javascripts/rails_admin/custom
# $ not working... single quote the heredoc label to prevent and expansion...
cat << 'HEREDOC' > app/assets/javascripts/rails_admin/custom/ui.js
$(document).on('rails_admin.dom_ready', function(){
var $table = $('#bulk_form').find('table');
var table = $table[0];
// Abort if there's nothing to do. Don't repeat ourselves, either.
if (!table || $table.hasClass('js-horiz-scroll')) { return; }
// Add our indicator class. Also some enhancements.
$table.addClass('js-horiz-scroll table-hover');
////
// Make the table horizontally scrollable.
// Inspiration from bootstrap's table-responsive.
////
var tableWrapper = document.createElement('DIV');
//tableWrapper.className = 'table-responsive';
//tableWrapper.style.width = '100%';
tableWrapper.style.overflowX = 'auto';
tableWrapper.style.marginBottom = table.style.marginBottom;
table.style.marginBottom = '0';
//tableWrapper.style.overflowY = 'hidden';
table.parentElement.insertBefore(tableWrapper, table);
tableWrapper.appendChild(table);
$table.find('th.last,td.last').each(function(index, td){
var tr = td.parentElement;
tr.insertBefore(td, tr.children[1]);
});
////
// Freeze the left columns.
// Inspiration from http://stackoverflow.com/questions/1312236/how-do-i-create-an-html-table-with-fixed-frozen-left-column-and-scrollable-body
////
var $trs = $table.find('tr');
var $headerTr = $trs.first();
var $headerTds = $headerTr.children('th,td');
var i, $td, pos;
var offsets = [];
var widths = [];
for (i = 0; i < 3; i++) {
$td = $($headerTds[i]);
pos = $td.position();
offsets.push(pos.left);
widths.push($td.outerWidth());
}
$trs.each(function(index, tr){
for (i = 0; i < 3; i++) {
tr.children[i].style.position = 'absolute';
tr.children[i].style.left = offsets[i]+'px';
tr.children[i].style.width = widths[i]+'px';
}
});
$td = $($headerTds[2]);
var margin = $td.position().left + $td.outerWidth() - $(tableWrapper).position().left;
tableWrapper.style.marginLeft = margin+'px';
tableWrapper.style.borderLeft = '1px solid black';
// Bottom-align the headers.
var trHeight = $headerTr.height();
for (i = 0; i < 3; i++) {
$td = $($headerTr[0].children[i]);
$td.css('padding-top', (trHeight - $td.height() - 4)+'px');
}
// Remove main browser window's horizontal scrollbar.
$('body').css('overflow-x', 'hidden');
});
HEREDOC
# bump version to get custom layout to load...
#
# remove line containing '[global]' and replace the line completely with the new text...
# sed -i 's/.*global].*/[global]\n\nunix extensions = no/g' /etc/samba/smb.conf
patrn1='Rails.application.config.assets.version'
# patrn1='version'
patrn2='Rails.application.config.assets.version = \"1.2\"'
# patrn2='Railsxxxxx'
sed -i -e "s/.*$patrn1.*/$patrn2/" config/initializers/assets.rb
# add configs...
# sed -i '/CLIENTSCRIPT/a \ \ CLIENTSCRIPT2' file # add line after pattern - include leading spaces like so - escape them.. '\ '
patrn='RailsAdmin.config'
addln='\ \ config.total_columns_width = 9999999'
sed -i "/$patrn/a$addln" config/initializers/rails_admin.rb
# Change this line.. config.authorize_with :cancan
#
# replace whole complete entire line if line matches patrn using ruby...
#
filetarg='config/initializers/rails_admin.rb'
cat $filetarg
r1tmp="/tmp/_temprubyrunner_${USER}.rb"
cat << 'HEREDOC' > $r1tmp
patrn='config.authorize_with :cancan'
repl2 = %Q{
config.authorize_with :cancancan
config.parent_controller = 'ApplicationController'
}
ARGF.each do |line|
if line =~ /#{Regexp.escape(patrn)}/
puts repl2
else
puts line
end
end
HEREDOC
ruby $r1tmp $filetarg > $filetarg.tmp
cat $filetarg.tmp
cp $filetarg.tmp $filetarg; rm $filetarg.tmp
sleep 1
git add -A # Add all files and commit them
git commit -m "configure customized admin"