Commit 29b46411 by Bui Minh Duc

fixed task load data from github, fixed controller and view

parent 23ed285d
......@@ -3,18 +3,43 @@ class MainController < ApplicationController
def index
@repos = @repos || Repository.all
@selected_repos = Repository.where(selected: true)
@selected_repos_obj = []
@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
@label_filter = ["ventura", "priority-ugent", "priority-high", "priority-low"]
@cols = ["discussion", "todo", "inprogress",
@col_label_names = [
"discussion", "todo", "inprogress",
"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
def update_repo_selected
......@@ -29,14 +54,22 @@ class MainController < ApplicationController
repo.save
end
@repos = @repos || Repository.all
@selected_repos = repos_picked
@labels = @label || Label.all
render "index"
redirect_to action: "index"
end
def load_repo_selected
# @repos = Repository.find()
end
private
def list_issues(label, repo)
end
def standardize_string(str)
str.gsub!(/[^0-9A-Za-z]/, '')
str.downcase!
str
end
end
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
......@@ -43,6 +43,7 @@
</div>
</div>
</nav>
<!-- End navbar -->
<div class="container">
<!-- content -->
......@@ -66,45 +67,83 @@
</div>
</div>
<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">
<% @labels.each do |repo| %>
<option><%= repo.name %></option>
<% @label_filter.each do |label| %>
<option><%= label %></option>
<% end %>
</select>
</div>
<input type="submit" class="btn btn-default">
</form>
<div>
<div style="margin-top: 20px">
<table class="table">
<thead class="thead-inverse">
<tr>
<th></th>
<% @labels.each do |label| %>
<th><%= label.name %></th>
<% @col_label_names.each do |label| %>
<th><%= label %></th>
<% end %>
</tr>
</thead>
<tbody>
<% @selected_repos.each do |selected_repo| %>
<% @data_table.each do |row| %>
<tr>
<td><%= link_to selected_repo.name, selected_repo.html_url %></td>
<td>Otto</td>
<td>@mdo</td>
<td><%= link_to row[:name], row[:link] %></td>
<% @col_label_names.each do |label| %>
<% 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>
<% end %>
</tbody>
</table>
</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">&times;</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>
<script type="text/javascript">
$(document).ready(function() {
......@@ -114,6 +153,9 @@
$('#datetimepicker2').datetimepicker({
format: "DD/MM/YYYY"
});
$('#selectpicker1').selectpicker(); // init picker
$('#selectpicker1').selectpicker('val', <%= @selected_repos_name.to_s.html_safe %>);
});
$("#repo_apply").click(function() {
......@@ -124,7 +166,7 @@
url: "<%= update_repo_selected_path %>",
data: { selected: selected_repos },
success: function(res) {
console.log(res);
// console.log(res);
location.reload();
}
});
......
......@@ -7,6 +7,7 @@ namespace :github do
insert_users($client)
db_repos = Repository.all
# db_repos = Repository.where(name: "socialtools")
db_repos.each do |db_repo|
insert_labels(db_repo, $client)
end
......@@ -31,16 +32,17 @@ namespace :github do
if db_repo.nil?
db_repo = Repository.new
new_flag = true
db_repo.id = repo.id
db_repo.name = repo.name
db_repo.full_name = repo.full_name
db_repo.private = repo.private
db_repo.description = repo.description
db_repo.url = repo.url
db_repo.html_url = repo.html_url
db_repo.created_at = repo.created_at
db_repo.updated_at = repo.updated_at
end
db_repo.id = repo.id
db_repo.name = repo.name
db_repo.full_name = repo.full_name
db_repo.private = repo.private
db_repo.description = repo.description
db_repo.url = repo.url
db_repo.html_url = repo.html_url
db_repo.created_at = repo.created_at
db_repo.updated_at = repo.updated_at
if db_repo.save
if new_flag
puts "Insert repo success: " + repo.name
......@@ -69,13 +71,15 @@ namespace :github do
if db_label.nil?
new_flag = true
db_label = Label.new
db_label.id = label.id
db_label.url = label.url
db_label.repository_id = repo.id
end
db_label.id = label.id
db_label.url = label.url
db_label.name = label.name
db_label.color = label.color
db_label.default = label.default
db_label.repository_id = repo.id
if db_label.save
if new_flag
puts "Insert label success: " + label.name
......@@ -104,11 +108,12 @@ namespace :github do
if db_user.nil?
new_flag = true
db_user = User.new
db_user.id = user.id
db_user.login = user.login
db_user.url = user.url
db_user.html_url = user.html_url
end
db_user.id = user.id
db_user.login = user.login
db_user.url = user.url
db_user.html_url = user.html_url
if db_user.save
if new_flag
puts "Insert user success: " + user.login
......@@ -137,24 +142,28 @@ namespace :github do
if db_issue.nil?
new_flag = true
db_issue = Issue.new
db_issue.id = issue.id
db_issue.url = issue.url
db_issue.repository_url = issue.repository_url
db_issue.number = issue.number
db_issue.repository_id = repo.id
db_issue.user_id = issue.user.id
end
db_issue.id = issue.id
db_issue.url = issue.url
db_issue.repository_url = issue.repository_url
db_issue.number = issue.number
db_issue.title = issue.title
db_issue.body = issue.body
db_issue.repository_id = repo.id
db_issue.user_id = issue.user.id
db_issue.created_at = issue.created_at
db_issue.updated_at = issue.updated_at
db_issue.labels.clear
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)
end
db_issue.users.clear
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)
end
......@@ -165,7 +174,6 @@ namespace :github do
puts "Update issue success: " + issue.title
end
else
byebug
puts "Issue >> an error occured: " + issue.title
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment