oxidized-web 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of oxidized-web might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Rakefile +7 -3
- data/lib/oxidized/web.rb +4 -2
- data/lib/oxidized/web/mig.rb +149 -0
- data/lib/oxidized/web/public/css/dataTables.bootstrap.css +2 -0
- data/lib/oxidized/web/public/css/dataTables.colVis.css +171 -0
- data/lib/oxidized/web/public/images/diff_15x17.png +0 -0
- data/lib/oxidized/web/public/images/versioning_18px.png +0 -0
- data/lib/oxidized/web/public/scripts/dataTables.colVis.js +1123 -0
- data/lib/oxidized/web/public/scripts/script-migration.js +15 -0
- data/lib/oxidized/web/views/diffs.haml +69 -0
- data/lib/oxidized/web/views/migration.haml +41 -0
- data/lib/oxidized/web/views/nodes.haml +29 -13
- data/lib/oxidized/web/views/sass/oxidized.sass +88 -0
- data/lib/oxidized/web/views/version.haml +19 -0
- data/lib/oxidized/web/views/versions.haml +54 -0
- data/lib/oxidized/web/webapp.rb +158 -0
- data/oxidized-web.gemspec +1 -1
- metadata +12 -2
@@ -0,0 +1,15 @@
|
|
1
|
+
var number = 1;
|
2
|
+
|
3
|
+
function add_file_upload(){
|
4
|
+
number++;
|
5
|
+
document.getElementById('number').value = number;
|
6
|
+
var table = document.getElementById("files");
|
7
|
+
var row = table.insertRow(-1);
|
8
|
+
var group = row.insertCell(0);
|
9
|
+
group.id = "file";
|
10
|
+
var file = row.insertCell(1);
|
11
|
+
file.id = "file";
|
12
|
+
group.innerHTML = '<input type="text" name="group' + number +'" value="default">';
|
13
|
+
file.innerHTML = '<input type="file" name="file' + number +'" required >';
|
14
|
+
|
15
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
!=haml :head
|
2
|
+
%body
|
3
|
+
%h4
|
4
|
+
- node_full = ''
|
5
|
+
- if @info[:group] != ''
|
6
|
+
- node_full = "#{@info[:group] + '/' + @info[:node]}"
|
7
|
+
- else
|
8
|
+
- node_full = "#{@info[:node]}"
|
9
|
+
%a{:href=>url_for("/node/version?node_full=#{node_full}")} versions
|
10
|
+
\/ Diff version #{@info[:num]} - #{@info[:num2]} for Node
|
11
|
+
%span{:class=>'node_title'} #{@info[:node]}
|
12
|
+
- date_version = Time.parse @info[:date]
|
13
|
+
Date of version: #{date_version.strftime("%d-%m-%y at %r")}
|
14
|
+
%br
|
15
|
+
Number of lines changed:
|
16
|
+
%span{:class=>'added'}added #{@stat[0]}
|
17
|
+
%span{:class=>'deleted'}removed #{@stat[1]}
|
18
|
+
%br
|
19
|
+
%br
|
20
|
+
%form{ :action => "/node/version/diffs?node=#{@info[:node]}&group=#{@info[:group]}&oid=#{@info[:oid]}&date=#{@info[:date]}&num=#{@info[:num]}", :method => "post"}
|
21
|
+
%select{:name => "oid2", :id => "oid2"}
|
22
|
+
- diff2 = {}
|
23
|
+
- num = @oids_dates.count + 1
|
24
|
+
- next_id = false
|
25
|
+
- @oids_dates.each do |x|
|
26
|
+
%option{:value => x[:oid]} Version #{num -= 1} (#{time_from_now x[:date]})
|
27
|
+
- if (x[:oid].to_s == @info[:oid2]) || (next_id)
|
28
|
+
- diff2 = {:num => num, :date => x[:date]}
|
29
|
+
- next_id = false
|
30
|
+
- elsif (x[:oid].to_s == @info[:oid]) && !(@info[:oid2])
|
31
|
+
- next_id = true
|
32
|
+
|
33
|
+
|
34
|
+
%input{:type => "submit", :value => "Get diffs !"}
|
35
|
+
%br
|
36
|
+
%div{:class=>'old_version_title'} Version #{diff2[:num]} (#{time_from_now diff2[:date]})
|
37
|
+
|
38
|
+
%div{:class=>'new_version_title'} Version #{@info[:num]} (#{time_from_now @info[:date]})
|
39
|
+
%br
|
40
|
+
%div{:class=>'diffs_old', :id=>'Test'}
|
41
|
+
- @diff[:old_diff].each do |line|
|
42
|
+
- if /^\+.*/.match(line)
|
43
|
+
%div{:class=>'added',:id=>'Test'} #{line}
|
44
|
+
|
45
|
+
- elsif /^\-.*/.match(line)
|
46
|
+
%div{:class=>'deleted'} #{line}
|
47
|
+
|
48
|
+
- elsif /^@@\s.*@@.*$/.match(line)
|
49
|
+
%div{:class=>'diff-index', :id=>'Test'} #{line}
|
50
|
+
- elsif /^empty_line /.match(line)
|
51
|
+
- line.slice! "empty_line"
|
52
|
+
%div{:class=>'diff-empty'} #{line}
|
53
|
+
- else
|
54
|
+
%div #{line}
|
55
|
+
%div{:class=>'diffs_new'}
|
56
|
+
- @diff[:new_diff].each do |line|
|
57
|
+
- if /^\+.*/.match(line)
|
58
|
+
%div{:class=>'added'} #{line}
|
59
|
+
|
60
|
+
- elsif /^\-.*/.match(line)
|
61
|
+
%div{:class=>'deleted'} #{line}
|
62
|
+
|
63
|
+
- elsif /^@@\s.*@@.*$/.match(line)
|
64
|
+
%div{:class=>'diff-index'} #{line}
|
65
|
+
- elsif /^empty_line /.match(line)
|
66
|
+
- line.slice! "empty_line"
|
67
|
+
%div{:class=>'diff-empty'} #{line}
|
68
|
+
- else
|
69
|
+
%div #{line}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
!=haml :head
|
2
|
+
%script{:src=>url_for('/scripts/script-migration.js')}
|
3
|
+
%body
|
4
|
+
|
5
|
+
%span{:id=>"migration_span"}
|
6
|
+
Here you can migrate from your Rancid to Oxidized.
|
7
|
+
%br
|
8
|
+
To do it, just execute te following actions :
|
9
|
+
%br
|
10
|
+
%br
|
11
|
+
%form(method="post" enctype="multipart/form-data")
|
12
|
+
%label{:for=>"path_new_file"} Set the path for your future equipement file in .db format
|
13
|
+
%br
|
14
|
+
%input{:type=>"text", :name=>"path_new_file", :value=>"Path/to_file/here.db"}
|
15
|
+
%br
|
16
|
+
%br
|
17
|
+
%label{:for=>"cloginrc"} Select your .cloginrc file, must be readeable
|
18
|
+
%input{:type=>"file", :name=>"cloginrc"}
|
19
|
+
%br
|
20
|
+
%label{:for=>"files"} Select all your router.db fies of rancid, and add their group (Click "Add file" if you have multiple files)
|
21
|
+
%table{:id=>"files", :name=>"files"}
|
22
|
+
%th{:id=>"file"} Group
|
23
|
+
%th{:id=>"file"} File
|
24
|
+
%tbody
|
25
|
+
%tr
|
26
|
+
%td{:id=>"file"}
|
27
|
+
%input{:type=>"text", :name=>"group1", :value=>"default"}
|
28
|
+
%td{:id=>"file"}
|
29
|
+
%input{:type=>"file", :name=>"file1", :required=>""}
|
30
|
+
%br
|
31
|
+
%input(type='button' value ='Add file' onclick="add_file_upload();")
|
32
|
+
%br
|
33
|
+
%br
|
34
|
+
%label{:for=>"upload_button"}Then Click "Migrate" to do your migration
|
35
|
+
%br
|
36
|
+
%input(type='submit' value='Migrate !' id="upload_button")
|
37
|
+
/
|
38
|
+
used to know the numbers of files router.db
|
39
|
+
%input(type='hidden' value='1' id='number' name='number')
|
40
|
+
|
41
|
+
|
@@ -1,22 +1,34 @@
|
|
1
1
|
%script{:src=>url_for('/scripts/jquery-2.1.1.min.js')}
|
2
2
|
%script{:src=>url_for('/scripts/jquery.dataTables.min.js')}
|
3
3
|
%script{:src=>url_for('/scripts/dataTables.bootstrap.js')}
|
4
|
+
%script{:src=>url_for('/scripts/dataTables.colVis.js')}
|
4
5
|
%link{:rel=>'stylesheet', :href=>url_for('/css/dataTables.bootstrap.css')}
|
6
|
+
%link{:rel=>'stylesheet', :href=>url_for('/css/dataTables.colVis.css')}
|
5
7
|
:javascript
|
6
8
|
$(function() {
|
7
9
|
$('#nodesTable').dataTable({
|
8
|
-
|
9
|
-
"lengthMenu": [[50, 250, 500, -1], [50, 250, 500, "All"]]
|
10
|
+
dom: 'C<"clear">lfrtip',
|
11
|
+
"lengthMenu": [[50, 250, 500, -1], [50, 250, 500, "All"]],
|
12
|
+
columnDefs: [
|
13
|
+
{ visible: false, targets: 1 },
|
14
|
+
{type: "string", targets: 3}
|
15
|
+
],
|
16
|
+
colVis: {
|
17
|
+
exclude: [ 0, 5 ]
|
18
|
+
}
|
10
19
|
});
|
11
20
|
});
|
12
21
|
%div{:class=>'row tbl-header'}
|
13
22
|
%div{:class=>'col-xs-12 col-md-2'}
|
14
23
|
%h4 nodes /
|
15
|
-
|
16
|
-
|
17
|
-
%span{:class=>"glyphicon glyphicon-repeat"}
|
18
|
-
Refresh
|
24
|
+
%button{:onclick => "location.href='/migration'" }
|
25
|
+
%span migration
|
19
26
|
%div{:class=>'row'}
|
27
|
+
%div{:class=>'refresh-div'}
|
28
|
+
%form
|
29
|
+
%button{:class => "ColVis_Button", :type => "button", :onclick => "history.go();"}
|
30
|
+
%span{:class=>"glyphicon glyphicon-repeat"}
|
31
|
+
Refresh
|
20
32
|
%table{:id=>'nodesTable', :class=>'table table-responsive tablesorter'}
|
21
33
|
%thead
|
22
34
|
%tr
|
@@ -25,8 +37,8 @@
|
|
25
37
|
%th Group
|
26
38
|
%th Last Status
|
27
39
|
%th Last Update
|
28
|
-
%th
|
29
|
-
|
40
|
+
%th Actions
|
41
|
+
|
30
42
|
%tbody
|
31
43
|
-trclass = %w(even odd)
|
32
44
|
-@data.sort_by{|e|e[:name]}.each do |node|
|
@@ -36,11 +48,15 @@
|
|
36
48
|
%a{:href => url_for("/node/show/#{node[:name]}") } #{node[:name]}
|
37
49
|
%td= node[:ip]
|
38
50
|
%td= node[:group]
|
39
|
-
%td
|
51
|
+
%td
|
52
|
+
%div{:title=>node[:status], :class=>node[:status]}
|
40
53
|
%td= node[:time]
|
41
54
|
%td
|
42
|
-
%a{:href => url_for("/node/fetch/#{node[:full_name]}") }
|
55
|
+
%a{:title => "configuration", :href => url_for("/node/fetch/#{node[:full_name]}") }
|
43
56
|
%span{:class=>'glyphicon glyphicon-cloud-download'}
|
44
|
-
|
45
|
-
%a{:href => url_for("/node/
|
46
|
-
%
|
57
|
+
|
58
|
+
%a{:title => "versions", :href => url_for("/node/version?node_full=#{node[:full_name]}") }
|
59
|
+
%img{:src=>url_for('/images/versioning_18px.png')}
|
60
|
+
|
61
|
+
%a{:title => "update", :href => url_for("/node/next/#{node[:full_name]}") }
|
62
|
+
%span{:class=>'glyphicon glyphicon-repeat'}
|
@@ -43,3 +43,91 @@ input#search
|
|
43
43
|
|
44
44
|
input#search .focused
|
45
45
|
border-bottom: 1px dotted #FFA600 !important
|
46
|
+
|
47
|
+
.added
|
48
|
+
background-color: #DBFFDB
|
49
|
+
|
50
|
+
.deleted
|
51
|
+
background-color: #FFDDDD
|
52
|
+
|
53
|
+
.diff-index
|
54
|
+
background-color: #FFFF99
|
55
|
+
|
56
|
+
.diff-empty
|
57
|
+
background-color: #F0F0F0
|
58
|
+
|
59
|
+
.diffs
|
60
|
+
background-color: FAFAFA
|
61
|
+
border: 2px solid #ccc
|
62
|
+
border-radius: 5px
|
63
|
+
padding: 3px
|
64
|
+
|
65
|
+
.diffs_old
|
66
|
+
@extend .diffs
|
67
|
+
float: left
|
68
|
+
width: 49%
|
69
|
+
white-space: nowrap
|
70
|
+
overflow: auto
|
71
|
+
|
72
|
+
.diffs_new
|
73
|
+
@extend .diffs
|
74
|
+
margin-left: 51%
|
75
|
+
width: 49%
|
76
|
+
white-space: nowrap
|
77
|
+
overflow: auto
|
78
|
+
|
79
|
+
.node_title
|
80
|
+
@extend .diffs
|
81
|
+
border-radius: 0px
|
82
|
+
|
83
|
+
.old_version_title
|
84
|
+
float: left
|
85
|
+
width: 49%
|
86
|
+
font-weight: bold
|
87
|
+
.new_version_title
|
88
|
+
margin-left: 51%
|
89
|
+
font-weight: bold
|
90
|
+
|
91
|
+
.refresh-div
|
92
|
+
float: right
|
93
|
+
padding-left: 5px
|
94
|
+
|
95
|
+
|
96
|
+
.status
|
97
|
+
float: right
|
98
|
+
width: 15px
|
99
|
+
height: 15px
|
100
|
+
border: 1px solid
|
101
|
+
margin-right: 70%
|
102
|
+
margin-bottom: 0px
|
103
|
+
border-radius: 2px
|
104
|
+
.success
|
105
|
+
@extend .status
|
106
|
+
background-color: #64FE2E
|
107
|
+
|
108
|
+
.no_connection
|
109
|
+
@extend .status
|
110
|
+
background-color: #FF0000
|
111
|
+
.never
|
112
|
+
@extend .status
|
113
|
+
background-color: #58ACFA
|
114
|
+
|
115
|
+
a:hover
|
116
|
+
text-decoration: none
|
117
|
+
|
118
|
+
#migration_span
|
119
|
+
font-size: 20px
|
120
|
+
font-weight: bold
|
121
|
+
|
122
|
+
table#files
|
123
|
+
width: 70%
|
124
|
+
border: 1px solid
|
125
|
+
|
126
|
+
th#file
|
127
|
+
width: 50%
|
128
|
+
height: 30px
|
129
|
+
text-align: center
|
130
|
+
|
131
|
+
td#file
|
132
|
+
@extend th#file
|
133
|
+
padding: 15px
|
@@ -0,0 +1,19 @@
|
|
1
|
+
!=haml :head
|
2
|
+
%body
|
3
|
+
%h4
|
4
|
+
- if @info[:group] != ''
|
5
|
+
%a{:href=>url_for("/node/version?node_full=#{@info[:group] + '/' + @info[:node]}")} versions
|
6
|
+
- else
|
7
|
+
%a{:href=>url_for("/node/version?node_full=#{@info[:node]}")} versions
|
8
|
+
\/ version #{@info[:num]} for Node
|
9
|
+
%span{:class=>'node_title'} #{@info[:node]}
|
10
|
+
|
11
|
+
- date_version = Time.parse @info[:date]
|
12
|
+
Date of version: #{date_version.strftime("%d-%m-%y at %r")}
|
13
|
+
%br
|
14
|
+
%br
|
15
|
+
%div{:class=>'diffs'}
|
16
|
+
- @data.each_line do |line|
|
17
|
+
%div #{line}
|
18
|
+
|
19
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
%script{:src=>url_for('/scripts/jquery-2.1.1.min.js')}
|
2
|
+
%script{:src=>url_for('/scripts/jquery.dataTables.min.js')}
|
3
|
+
%script{:src=>url_for('/scripts/dataTables.bootstrap.js')}
|
4
|
+
%script{:src=>url_for('/scripts/dataTables.colVis.js')}
|
5
|
+
%link{:rel=>'stylesheet', :href=>url_for('/css/dataTables.bootstrap.css')}
|
6
|
+
%link{:rel=>'stylesheet', :href=>url_for('/css/dataTables.colVis.css')}
|
7
|
+
:javascript
|
8
|
+
$(function() {
|
9
|
+
$('#versionsTable').dataTable({
|
10
|
+
dom: 'C<"clear">lfrtip',
|
11
|
+
"order": [[ 0, "desc" ]],
|
12
|
+
colVis: {
|
13
|
+
exclude: [ 2 ]
|
14
|
+
}
|
15
|
+
});
|
16
|
+
});
|
17
|
+
%div{:class=>'row tbl-header'}
|
18
|
+
%div{:class=>'col-xs-12 '}
|
19
|
+
%h4
|
20
|
+
%a{:href=>url_for('/nodes')} nodes
|
21
|
+
\/ Versions for Node
|
22
|
+
%span{:class=>'node_title'} #{@node}
|
23
|
+
|
24
|
+
%div{:class=>'row'}
|
25
|
+
%div{:class=>'refresh-div'}
|
26
|
+
%form
|
27
|
+
%button{:class => "ColVis_Button", :type => "button", :onclick => "history.go();"}
|
28
|
+
%span{:class=>"glyphicon glyphicon-repeat"}
|
29
|
+
Refresh
|
30
|
+
%table{:id=>'versionsTable', :class=>'table table-responsive tablesorter'}
|
31
|
+
%thead
|
32
|
+
%tr
|
33
|
+
%th Version
|
34
|
+
%th Dates
|
35
|
+
%th Actions
|
36
|
+
|
37
|
+
%tbody
|
38
|
+
-trclass = %w(even odd)
|
39
|
+
- nb = @data.count + 1
|
40
|
+
- @data.each do |x|
|
41
|
+
%tr
|
42
|
+
%td
|
43
|
+
#{nb -= 1}
|
44
|
+
%td
|
45
|
+
#{time_from_now x[:date]}
|
46
|
+
%td
|
47
|
+
%a{:title => "configuration", :href => url_for("/node/version/view?node=#{@node}&group=#{@group}&oid=#{x[:oid]}&date=#{x[:date]}&num=#{nb}") }
|
48
|
+
%span{:class=>'glyphicon glyphicon-cloud-download'}
|
49
|
+
|
50
|
+
%a{:title => "diff", :href => url_for("/node/version/diffs?node=#{@node}&group=#{@group}&oid=#{x[:oid]}&date=#{x[:date]}&num=#{nb}") }
|
51
|
+
%img{:src=>url_for('/images/diff_15x17.png')}
|
52
|
+
|
53
|
+
|
54
|
+
|
data/lib/oxidized/web/webapp.rb
CHANGED
@@ -4,6 +4,8 @@ require 'sinatra/url_for'
|
|
4
4
|
require 'haml'
|
5
5
|
require 'sass'
|
6
6
|
require 'pp'
|
7
|
+
require 'pp'
|
8
|
+
require 'oxidized/web/mig'
|
7
9
|
module Oxidized
|
8
10
|
module API
|
9
11
|
class WebApp < Sinatra::Base
|
@@ -84,11 +86,104 @@ module Oxidized
|
|
84
86
|
@data = nodes.show node
|
85
87
|
out :node
|
86
88
|
end
|
89
|
+
|
90
|
+
#redirect to the web page for rancid - oxidized migration
|
91
|
+
get '/migration' do
|
92
|
+
out :migration
|
93
|
+
end
|
94
|
+
|
95
|
+
#get the files send
|
96
|
+
post '/migration' do
|
97
|
+
number = params[:number].to_i
|
98
|
+
cloginrc_file = params['cloginrc'][:tempfile]
|
99
|
+
path_new_file = params['path_new_file']
|
100
|
+
|
101
|
+
router_db_files = Array.new
|
102
|
+
|
103
|
+
i = 1
|
104
|
+
while i <= number do
|
105
|
+
router_db_files.push({:file=>(params["file"+i.to_s][:tempfile]), :group=>params["group"+i.to_s]})
|
106
|
+
i = i+1
|
107
|
+
end
|
87
108
|
|
109
|
+
migration = Mig.new(router_db_files, cloginrc_file, path_new_file)
|
110
|
+
migration.go_rancid_migration
|
111
|
+
redirect url_for("//nodes")
|
112
|
+
|
113
|
+
end
|
114
|
+
|
88
115
|
get '/css/*.css' do
|
89
116
|
sass "sass/#{params[:splat].first}".to_sym
|
90
117
|
end
|
91
118
|
|
119
|
+
#show the lists of versions for a node
|
120
|
+
get '/node/version' do
|
121
|
+
@data = nil
|
122
|
+
@group = nil
|
123
|
+
@node = nil
|
124
|
+
node_full = params[:node_full]
|
125
|
+
if node_full.include? "/"
|
126
|
+
node_full = node_full.split('/')
|
127
|
+
@group = node_full[0]
|
128
|
+
@node = node_full[1]
|
129
|
+
@data = nodes.version @node, @group
|
130
|
+
else
|
131
|
+
@node = node_full
|
132
|
+
@data = nodes.version @node, nil
|
133
|
+
end
|
134
|
+
out :versions
|
135
|
+
end
|
136
|
+
|
137
|
+
#show the blob of a version
|
138
|
+
get '/node/version/view' do
|
139
|
+
node, @json = route_parse :node
|
140
|
+
@info = {:node => node, :group => params[:group],:oid => params[:oid],:date => params[:date],:num => params[:num]}
|
141
|
+
@data = nodes.get_version node, @info[:group], @info[:oid]
|
142
|
+
out :version
|
143
|
+
end
|
144
|
+
|
145
|
+
#show diffs between 2 version
|
146
|
+
get '/node/version/diffs' do
|
147
|
+
node, @json = route_parse :node
|
148
|
+
@data = nil
|
149
|
+
@info = {:node => node, :group => params[:group],:oid => params[:oid],:date => params[:date],:num => params[:num], :num2 => (params[:num].to_i - 1)}
|
150
|
+
group = nil
|
151
|
+
if @info[:group] != ''
|
152
|
+
group = @info[:group]
|
153
|
+
end
|
154
|
+
@oids_dates = nodes.version node, group
|
155
|
+
if params[:oid2]
|
156
|
+
@info[:oid2] = params[:oid2]
|
157
|
+
oid2 = nil
|
158
|
+
num = @oids_dates.count + 1
|
159
|
+
@oids_dates.each do |x|
|
160
|
+
num -= 1
|
161
|
+
if x[:oid].to_s == params[:oid2]
|
162
|
+
oid2 = x[:oid]
|
163
|
+
@info[:num2] = num
|
164
|
+
break
|
165
|
+
end
|
166
|
+
end
|
167
|
+
@data = nodes.get_diff node, @info[:group], @info[:oid], oid2
|
168
|
+
else
|
169
|
+
@data = nodes.get_diff node, @info[:group], @info[:oid], nil
|
170
|
+
end
|
171
|
+
@stat = ["null","null"]
|
172
|
+
if @data != 'no diffs' && @data != nil
|
173
|
+
@stat = @data[:stat]
|
174
|
+
@data = @data[:patch]
|
175
|
+
else
|
176
|
+
@data = "no available"
|
177
|
+
end
|
178
|
+
@diff = diff_view @data
|
179
|
+
out :diffs
|
180
|
+
end
|
181
|
+
|
182
|
+
#used for diff between 2 distant commit
|
183
|
+
post '/node/version/diffs' do
|
184
|
+
redirect url_for("/node/version/diffs?node=#{params[:node]}&group=#{params[:group]}&oid=#{params[:oid]}&date=#{params[:date]}&num=#{params[:num]}&oid2=#{params[:oid2]}")
|
185
|
+
end
|
186
|
+
|
92
187
|
private
|
93
188
|
|
94
189
|
def out template=:default
|
@@ -115,6 +210,69 @@ module Oxidized
|
|
115
210
|
end
|
116
211
|
[e.join('.'), json]
|
117
212
|
end
|
213
|
+
|
214
|
+
#give the time enlapsed between now and a date
|
215
|
+
def time_from_now date
|
216
|
+
if date
|
217
|
+
#if the + is missing
|
218
|
+
unless date.include? "+"
|
219
|
+
date.insert(21, "+")
|
220
|
+
end
|
221
|
+
date = DateTime.parse date
|
222
|
+
now = DateTime.now
|
223
|
+
t = ((now - date) * 24 * 60 * 60).to_i
|
224
|
+
mm, ss = t.divmod(60)
|
225
|
+
hh, mm = mm.divmod(60)
|
226
|
+
dd, hh = hh.divmod(24)
|
227
|
+
if dd > 0
|
228
|
+
date = "#{dd} days #{hh} hours ago"
|
229
|
+
elsif hh > 0
|
230
|
+
date = "#{hh} hours #{mm} min ago"
|
231
|
+
else
|
232
|
+
date = "#{mm} min #{ss} sec ago"
|
233
|
+
end
|
234
|
+
end
|
235
|
+
date
|
236
|
+
end
|
237
|
+
|
238
|
+
#method the give diffs in separate view (the old and the new) as in github
|
239
|
+
def diff_view diff
|
240
|
+
old_diff = []
|
241
|
+
new_diff = []
|
242
|
+
|
243
|
+
diff.each_line do |line|
|
244
|
+
if /^\+/.match(line)
|
245
|
+
new_diff.push(line)
|
246
|
+
elsif /^\-/.match(line)
|
247
|
+
old_diff.push(line)
|
248
|
+
else
|
249
|
+
new_diff.push(line)
|
250
|
+
old_diff.push(line)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
length_o = old_diff.count
|
255
|
+
length_n = new_diff.count
|
256
|
+
for i in 0..[length_o, length_n].max
|
257
|
+
if i > [length_o, length_n].min
|
258
|
+
break
|
259
|
+
end
|
260
|
+
if (/^\-.*/.match(old_diff[i])) && !(/^\+.*/.match(new_diff[i]))
|
261
|
+
#tag removed latter to add color syntax
|
262
|
+
insert = 'empty_line'
|
263
|
+
#ugly way to avoid asymmetry if at display the line takes 2 line on the screen
|
264
|
+
insert = " \n"
|
265
|
+
new_diff.insert(i,insert)
|
266
|
+
length_n += 1
|
267
|
+
elsif !(/^\-.*/.match(old_diff[i])) && (/^\+.*/.match(new_diff[i]))
|
268
|
+
insert = 'empty_line'
|
269
|
+
insert = " \n"
|
270
|
+
old_diff.insert(i,insert)
|
271
|
+
length_o += 1
|
272
|
+
end
|
273
|
+
end
|
274
|
+
both_diff = {:old_diff => old_diff, :new_diff => new_diff}
|
275
|
+
end
|
118
276
|
end
|
119
277
|
end
|
120
278
|
end
|