Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
ventura-ghr
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
VeNtura
ventura-ghr
Commits
29b46411
Commit
29b46411
authored
Nov 28, 2016
by
Bui Minh Duc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed task load data from github, fixed controller and view
parent
23ed285d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
43 deletions
+140
-43
app/controllers/main_controller.rb
+47
-14
app/helpers/main_helper.rb
+14
-0
app/views/main/index.html.erb
+61
-19
lib/tasks/github.rake
+18
-10
No files found.
app/controllers/main_controller.rb
View file @
29b46411
...
@@ -3,18 +3,43 @@ class MainController < ApplicationController
...
@@ -3,18 +3,43 @@ class MainController < ApplicationController
def
index
def
index
@repos
=
@repos
||
Repository
.
all
@repos
=
@repos
||
Repository
.
all
@selected_repos
=
Repository
.
where
(
selected:
true
)
@selected_repos
=
Repository
.
where
(
selected:
true
)
@selected_repos_obj
=
[]
@label_filter
=
[
"ventura"
,
"priority-ugent"
,
"priority-high"
,
"priority-low"
]
@selected_repos
.
each
do
|
repo
|
repo_obj
=
Hash
.
new
repo_obj
[
:name
]
=
repo
.
name
repo_obj
[
:issues
]
=
$client
.
list_issues
(
"ZIGExN/"
+
repo
.
name
)
@selected_repos_obj
.
append
(
repo_obj
)
end
@labels
=
@label
||
Label
.
all
@cols
=
[
"discussion"
,
"todo"
,
"inprogress"
,
@col_label_names
=
[
"discussion"
,
"todo"
,
"inprogress"
,
"vnreview"
,
"jpreview"
,
"ready"
,
"vnreview"
,
"jpreview"
,
"ready"
,
"done"
,
"releasefailed"
,
"pending"
]
"done"
,
"releasefailed"
,
"pending"
,
"ventura"
]
@selected_repos_name
=
[]
@data_table
=
[]
@selected_repos
.
each
do
|
repo
|
@selected_repos_name
.
append
(
repo
.
name
)
row_table
=
Hash
.
new
row_table
[
:name
]
=
repo
.
name
row_table
[
:link
]
=
repo
.
html_url
repo
.
issues
.
each
do
|
issue
|
issue
.
labels
.
each
do
|
label
|
label_name
=
standardize_string
(
label
[
:name
])
@col_label_names
.
each
do
|
col_label
|
if
label_name
==
col_label
cell
=
row_table
[
label_name
]
||
Hash
.
new
if
cell
[
:count
].
nil?
cell
[
:count
]
=
1
else
cell
[
:count
]
=
cell
[
:count
]
+
1
end
if
cell
[
:issues
].
nil?
cell
[
:issues
]
=
[]
end
cell
[
:issues
].
append
(
issue
)
row_table
[
label_name
]
=
cell
break
end
end
end
end
@data_table
.
append
(
row_table
)
end
end
end
def
update_repo_selected
def
update_repo_selected
...
@@ -29,14 +54,22 @@ class MainController < ApplicationController
...
@@ -29,14 +54,22 @@ class MainController < ApplicationController
repo
.
save
repo
.
save
end
end
@repos
=
@repos
||
Repository
.
all
redirect_to
action:
"index"
@selected_repos
=
repos_picked
@labels
=
@label
||
Label
.
all
render
"index"
end
end
def
load_repo_selected
def
load_repo_selected
# @repos = Repository.find()
# @repos = Repository.find()
end
end
private
def
list_issues
(
label
,
repo
)
end
def
standardize_string
(
str
)
str
.
gsub!
(
/[^0-9A-Za-z]/
,
''
)
str
.
downcase!
str
end
end
end
app/helpers/main_helper.rb
View file @
29b46411
module
MainHelper
module
MainHelper
def
format_time
(
int_time
)
mm
,
ss
=
int_time
.
divmod
(
60
)
hh
,
mm
=
mm
.
divmod
(
60
)
dd
,
hh
=
hh
.
divmod
(
24
)
if
dd
!=
0
dd
.
to_s
+
" days ago"
elsif
hh
!=
0
hh
.
to_s
+
" hours ago"
else
mm
.
to_s
+
" minutes ago"
end
end
end
end
app/views/main/index.html.erb
View file @
29b46411
...
@@ -43,6 +43,7 @@
...
@@ -43,6 +43,7 @@
</div>
</div>
</div>
</div>
</nav>
</nav>
<!-- End navbar -->
<div
class=
"container"
>
<div
class=
"container"
>
<!-- content -->
<!-- content -->
...
@@ -66,45 +67,83 @@
...
@@ -66,45 +67,83 @@
</div>
</div>
</div>
</div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"to"
>
To
</label>
<div
class=
'input-group date'
id=
'datetimepicker2'
>
<input
type=
'text'
class=
"form-control"
/>
<span
class=
"input-group-addon"
>
<span
class=
"glyphicon glyphicon-calendar"
></span>
</span>
</div>
</div>
<div
class=
"form-group"
>
<select
class=
"selectpicker"
multiple
data-live-search=
"true"
>
<select
class=
"selectpicker"
multiple
data-live-search=
"true"
>
<%
@label
s
.
each
do
|
repo
|
%>
<%
@label
_filter
.
each
do
|
label
|
%>
<option>
<%=
repo
.
name
%>
</option>
<option>
<%=
label
%>
</option>
<%
end
%>
<%
end
%>
</select>
</select>
</div>
</div>
<input
type=
"submit"
class=
"btn btn-default"
>
<input
type=
"submit"
class=
"btn btn-default"
>
</form>
</form>
<div>
<div
style=
"margin-top: 20px"
>
<table
class=
"table"
>
<table
class=
"table"
>
<thead
class=
"thead-inverse"
>
<thead
class=
"thead-inverse"
>
<tr>
<tr>
<th></th>
<th></th>
<%
@
label
s
.
each
do
|
label
|
%>
<%
@
col_label_name
s
.
each
do
|
label
|
%>
<th>
<%=
label
.
name
%>
</th>
<th>
<%=
label
%>
</th>
<%
end
%>
<%
end
%>
</tr>
</tr>
</thead>
</thead>
<tbody>
<tbody>
<%
@
selected_repos
.
each
do
|
selected_repo
|
%>
<%
@
data_table
.
each
do
|
row
|
%>
<tr>
<tr>
<td>
<%=
link_to
selected_repo
.
name
,
selected_repo
.
html_url
%>
</td>
<td>
<%=
link_to
row
[
:name
],
row
[
:link
]
%>
</td>
<td>
Otto
</td>
<%
@col_label_names
.
each
do
|
label
|
%>
<td>
@mdo
</td>
<%
if
row
[
label
].
nil?
%>
<th>
0
</th>
<%
else
%>
<th><a
href=
""
data-toggle=
"modal"
data-target=
"#
<%=
row
[
:name
]
+
label
%>
"
>
<%=
row
[
label
][
:count
]
%>
</a></th>
<%
end
%>
<%
end
%>
</tr>
</tr>
<%
end
%>
<%
end
%>
</tbody>
</tbody>
</table>
</table>
</div>
</div>
<%
@data_table
.
each
do
|
row
|
%>
<%
@col_label_names
.
each
do
|
label
|
%>
<%
if
!
row
[
label
].
nil?
%>
<div
id=
"
<%=
row
[
:name
]
+
label
%>
"
class=
"modal fade bd-example-modal-lg"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"myLargeModalLabel"
aria-hidden=
"true"
>
<div
class=
"modal-dialog modal-lg"
>
<div
class=
"modal-content"
>
<div
class=
"modal-header"
>
<button
type=
"button"
class=
"close"
data-dismiss=
"modal"
aria-label=
"Close"
>
<span
aria-hidden=
"true"
>
×
</span>
</button>
<h4
class=
"modal-title"
id=
"myModalLabel"
>
<%=
row
[
:name
]
%>
</h4>
</div>
<div
class=
"modal-body"
>
<table
class=
"table"
>
<tbody>
<%
row
[
label
][
:issues
].
each
do
|
issue
|
%>
<tr>
<td>
<a
href=
"
<%=
issue
[
:html_url
]
%>
"
>
<%=
issue
[
:title
]
%>
</a>
<%
issue
.
labels
.
each
do
|
label
|
%>
<span
class=
"label label-default"
style=
"background-color: #
<%=
label
[
:color
]
%>
"
>
<%=
label
[
:name
]
%>
</span>
<%
end
%>
</td>
<td>
<%=
issue
[
:created_at
]
%>
</td>
<td>
<%=
format_time
(
Time
.
now
-
issue
[
:created_at
])
%>
</td>
</tr>
<%
end
%>
</tbody>
</table>
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-secondary"
data-dismiss=
"modal"
>
Close
</button>
</div>
</div>
</div>
</div>
<%
end
%>
<%
end
%>
<%
end
%>
</div>
</div>
</div>
<script
type=
"text/javascript"
>
<script
type=
"text/javascript"
>
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
...
@@ -114,6 +153,9 @@
...
@@ -114,6 +153,9 @@
$
(
'#datetimepicker2'
).
datetimepicker
({
$
(
'#datetimepicker2'
).
datetimepicker
({
format
:
"DD/MM/YYYY"
format
:
"DD/MM/YYYY"
});
});
$
(
'#selectpicker1'
).
selectpicker
();
// init picker
$
(
'#selectpicker1'
).
selectpicker
(
'val'
,
<%=
@selected_repos_name
.
to_s
.
html_safe
%>
);
});
});
$
(
"#repo_apply"
).
click
(
function
()
{
$
(
"#repo_apply"
).
click
(
function
()
{
...
@@ -124,7 +166,7 @@
...
@@ -124,7 +166,7 @@
url
:
"
<%=
update_repo_selected_path
%>
"
,
url
:
"
<%=
update_repo_selected_path
%>
"
,
data
:
{
selected
:
selected_repos
},
data
:
{
selected
:
selected_repos
},
success
:
function
(
res
)
{
success
:
function
(
res
)
{
console
.
log
(
res
);
//
console.log(res);
location
.
reload
();
location
.
reload
();
}
}
});
});
...
...
lib/tasks/github.rake
View file @
29b46411
...
@@ -7,6 +7,7 @@ namespace :github do
...
@@ -7,6 +7,7 @@ namespace :github do
insert_users
(
$client
)
insert_users
(
$client
)
db_repos
=
Repository
.
all
db_repos
=
Repository
.
all
# db_repos = Repository.where(name: "socialtools")
db_repos
.
each
do
|
db_repo
|
db_repos
.
each
do
|
db_repo
|
insert_labels
(
db_repo
,
$client
)
insert_labels
(
db_repo
,
$client
)
end
end
...
@@ -31,7 +32,6 @@ namespace :github do
...
@@ -31,7 +32,6 @@ namespace :github do
if
db_repo
.
nil?
if
db_repo
.
nil?
db_repo
=
Repository
.
new
db_repo
=
Repository
.
new
new_flag
=
true
new_flag
=
true
end
db_repo
.
id
=
repo
.
id
db_repo
.
id
=
repo
.
id
db_repo
.
name
=
repo
.
name
db_repo
.
name
=
repo
.
name
db_repo
.
full_name
=
repo
.
full_name
db_repo
.
full_name
=
repo
.
full_name
...
@@ -41,6 +41,8 @@ namespace :github do
...
@@ -41,6 +41,8 @@ namespace :github do
db_repo
.
html_url
=
repo
.
html_url
db_repo
.
html_url
=
repo
.
html_url
db_repo
.
created_at
=
repo
.
created_at
db_repo
.
created_at
=
repo
.
created_at
db_repo
.
updated_at
=
repo
.
updated_at
db_repo
.
updated_at
=
repo
.
updated_at
end
if
db_repo
.
save
if
db_repo
.
save
if
new_flag
if
new_flag
puts
"Insert repo success: "
+
repo
.
name
puts
"Insert repo success: "
+
repo
.
name
...
@@ -69,13 +71,15 @@ namespace :github do
...
@@ -69,13 +71,15 @@ namespace :github do
if
db_label
.
nil?
if
db_label
.
nil?
new_flag
=
true
new_flag
=
true
db_label
=
Label
.
new
db_label
=
Label
.
new
end
db_label
.
id
=
label
.
id
db_label
.
id
=
label
.
id
db_label
.
url
=
label
.
url
db_label
.
url
=
label
.
url
db_label
.
repository_id
=
repo
.
id
end
db_label
.
name
=
label
.
name
db_label
.
name
=
label
.
name
db_label
.
color
=
label
.
color
db_label
.
color
=
label
.
color
db_label
.
default
=
label
.
default
db_label
.
default
=
label
.
default
db_label
.
repository_id
=
repo
.
id
if
db_label
.
save
if
db_label
.
save
if
new_flag
if
new_flag
puts
"Insert label success: "
+
label
.
name
puts
"Insert label success: "
+
label
.
name
...
@@ -104,11 +108,12 @@ namespace :github do
...
@@ -104,11 +108,12 @@ namespace :github do
if
db_user
.
nil?
if
db_user
.
nil?
new_flag
=
true
new_flag
=
true
db_user
=
User
.
new
db_user
=
User
.
new
end
db_user
.
id
=
user
.
id
db_user
.
id
=
user
.
id
db_user
.
login
=
user
.
login
db_user
.
login
=
user
.
login
db_user
.
url
=
user
.
url
db_user
.
url
=
user
.
url
db_user
.
html_url
=
user
.
html_url
db_user
.
html_url
=
user
.
html_url
end
if
db_user
.
save
if
db_user
.
save
if
new_flag
if
new_flag
puts
"Insert user success: "
+
user
.
login
puts
"Insert user success: "
+
user
.
login
...
@@ -137,24 +142,28 @@ namespace :github do
...
@@ -137,24 +142,28 @@ namespace :github do
if
db_issue
.
nil?
if
db_issue
.
nil?
new_flag
=
true
new_flag
=
true
db_issue
=
Issue
.
new
db_issue
=
Issue
.
new
end
db_issue
.
id
=
issue
.
id
db_issue
.
id
=
issue
.
id
db_issue
.
url
=
issue
.
url
db_issue
.
url
=
issue
.
url
db_issue
.
repository_url
=
issue
.
repository_url
db_issue
.
repository_url
=
issue
.
repository_url
db_issue
.
number
=
issue
.
number
db_issue
.
number
=
issue
.
number
db_issue
.
title
=
issue
.
title
db_issue
.
body
=
issue
.
body
db_issue
.
repository_id
=
repo
.
id
db_issue
.
repository_id
=
repo
.
id
db_issue
.
user_id
=
issue
.
user
.
id
db_issue
.
user_id
=
issue
.
user
.
id
end
db_issue
.
title
=
issue
.
title
db_issue
.
body
=
issue
.
body
db_issue
.
created_at
=
issue
.
created_at
db_issue
.
updated_at
=
issue
.
updated_at
db_issue
.
labels
.
clear
issue
.
labels
.
each
do
|
label
|
issue
.
labels
.
each
do
|
label
|
db_label
=
Label
.
where
(
id:
label
.
id
).
first
db_label
=
Label
.
find_by
(
id:
label
.
id
)
db_issue
.
labels
.
append
(
db_label
)
db_issue
.
labels
.
append
(
db_label
)
end
end
db_issue
.
users
.
clear
issue
.
assignees
.
each
do
|
assignee
|
issue
.
assignees
.
each
do
|
assignee
|
db_assignee
=
User
.
where
(
id:
assignee
.
id
).
first
db_assignee
=
User
.
find_by
(
id:
assignee
.
id
)
db_issue
.
users
.
append
(
db_assignee
)
db_issue
.
users
.
append
(
db_assignee
)
end
end
...
@@ -165,7 +174,6 @@ namespace :github do
...
@@ -165,7 +174,6 @@ namespace :github do
puts
"Update issue success: "
+
issue
.
title
puts
"Update issue success: "
+
issue
.
title
end
end
else
else
byebug
puts
"Issue >> an error occured: "
+
issue
.
title
puts
"Issue >> an error occured: "
+
issue
.
title
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment