Commit 4e21255b by Bui Minh Duc

implemented setting 1

parent 3d7b1ef9
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
// Place all the styles related to the settings controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
......@@ -39,6 +39,55 @@ class IssuesController < ApplicationController
@comments = @issue.comments
@rv_comments = @issue.review_comments
@label_data = {
"discussion" => nil,
"todo" => nil,
"inprogress" => nil,
"vnreview" => nil,
"jpreview" => nil,
"ready" => nil,
"done" => nil,
"releasefailed" => nil,
"pending" => nil
}
timelines = @issue.timelines
timelines.each do |timeline|
if @label_data[timeline.label].nil?
@label_data[timeline.label] = { "time" => 0, "data" => [] }
end
time = 0
if timeline.end_time.nil? # task is not finished
time = Time.now - timeline.started_time
else
time = timeline.end_time - timeline.started_time
end
@label_data[timeline.label]["time"] += time
@label_data[timeline.label]["data"].append(timeline)
end
@started_time = nil
start = timelines.where(label: "inprogress").first
unless start.nil?
@started_time = start.started_time
end
@end_time = nil
end_t = timelines.where(label: "done").first
unless end_t.nil?
@end_time = end_t.started_time
end
@duration = nil
if @started_time.nil?
@duration = "---"
elsif @end_time.nil?
@duration = Time.now - @started_time
else
@duration = @end_time - @started_time
end
@options = [
{id: 0, type: "None"},
{id: 1, type: "Small"},
......
class SettingsController < ApplicationController
def index
@repos = Repository.all
end
def update_setting_1
$repos_to_update = params[:selected]
end
end
module SettingsHelper
end
......@@ -21,6 +21,7 @@ class RepositoryJob < ApplicationJob
list_db_issue.each do |db_issue|
db_issue.save
# byebug
end
list_db_comment.each do |db_comment|
......
......@@ -7,5 +7,7 @@ class Issue < ApplicationRecord
has_many :review_comments
has_many :pull_requests, class_name: "Issue", foreign_key: "issue_id"
belongs_to :issue, class_name: "Issue"
belongs_to :issue, class_name: "Issue", optional: true
has_many :timelines
end
......@@ -66,24 +66,24 @@
</ul>
</div>
<table class="table table-bordered">
<!-- <thead>
<tr>
<th class="col-md-6">Started Time</th>
<th class="col-md-6">End Time</th>
</tr>
</thead> -->
<tbody>
<tr>
<td class="col-md-4">Started Time</td>
<td class="col-md-8">20/12/2016</td>
<td class="col-md-8">
<%= @started_time %>
</td>
</tr>
<tr>
<td class="col-md-4">End Time</td>
<td class="col-md-8">---</td>
<td class="col-md-8">
<%= @end_time %>
</td>
</tr>
<tr>
<td class="col-md-4">Duration</td>
<td class="col-md-8">10 days (66.67%)</td>
<td class="col-md-8">
<%= @duration %>
</td>
</tr>
<tr>
<td class="col-md-4">Estimate</td>
......@@ -95,38 +95,30 @@
<thead>
<tr>
<th class="col-md-4">Label</th>
<th class="col-md-8">Duration</th>
<th class="col-md-4">Duration</th>
<th class="col-md-4">Time</th>
</tr>
</thead>
<tbody>
<tr>
<td>discussion</td>
<td>10 hours</td>
</tr>
<tr>
<td>todo</td>
<td>10 hours</td>
</tr>
<tr>
<td>inprogress</td>
<td>3 hours</td>
</tr>
<tr>
<td>vnreview</td>
<td>3 hours</td>
</tr>
<tr>
<td>jpreview</td>
<td>3 hours</td>
</tr>
<tr>
<td>ready</td>
<td>3 hours</td>
</tr>
<tr>
<td>done</td>
<td>3 hours</td>
</tr>
<% @label_data.each do |key, value| %>
<tr>
<td><%= key %></td>
<% if value.nil? %>
<td>---</td>
<td>---</td>
<% else %>
<td><%= value["time"].to_i %></td>
<td>
<select>
<% value["data"].each do |x| %>
<option><%= x.started_time.to_s + " - " + x.end_time.to_s %></option>
<% end %>
</select>
</td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<div>
......
......@@ -14,6 +14,7 @@
<ul class="nav navbar-nav navbar-right">
<li><%= link_to "User", user_path %></li>
<li><%= link_to "Repository", repositories_path %></li>
<li><%= link_to "Settings", settings_path %></li>
</ul>
</div>
</div>
......
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<h4>Settings 1</h4>
</div>
<div class="panel-body">
<p>Please choose some repositories. Picked repositories will be updated every 1 hour.</p>
<select class="selectpicker" id="selectpicker" multiple data-live-search="true" data-selected-text-format="count > 3" data-actions-box="true" style="display: none;">
<% @repos.each do |repo| %>
<option><%= repo.name %></option>
<% end %>
</select>
<button class="btn btn-default" id="btn1">Save</button>
<br><br>
<% if $repos_to_update.class == Array %>
<% $repos_to_update.each do |repo| %>
<span class="label label-primary"><%= repo %></span>
<% end %>
<% end %>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#selectpicker').selectpicker(); // init picker
<% if $repos_to_update.class == Array %>
$('#selectpicker').selectpicker('val', <%= $repos_to_update.to_s.html_safe %>);
<% end %>
});
$("#btn1").click(function() {
var selectedRepos = $('#selectpicker').selectpicker('val');
$.ajax({
method: "POST",
url: "<%= settings_1_path %>",
data: { selected: selectedRepos },
success: function(res) {
location.reload();
}
});
});
</script>
$client = Octokit::Client.new(access_token: Rails.application.secrets.GITHUB_TOKEN)
$repos_to_update = []
......@@ -10,4 +10,7 @@ Rails.application.routes.draw do
resources :pulls
resources :repositories
resources :comments
get "/settings", to: "settings#index"
post "/settings/1", to: "settings#update_setting_1"
end
......@@ -20,6 +20,10 @@
# Learn more: http://github.com/javan/whenever
set :environment, "development"
every 2.hour do
rake "github:insert_github_data"
# every 2.hour do
# rake "github:insert_github_data"
# end
every 1.hour do
rake "github:insert_github_data_for_specific_repos"
end
No preview for this file type

14.4 KB | W: | H:

15.9 KB | W: | H:

design.png
design.png
design.png
design.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -146,17 +146,19 @@ class GithubLoader
new_label = db_issue.labels.find_by(name: col_labels)
if old_label.nil?
unless new_label.nil?
timeline = Timeline.new
timeline.issue_id = db_issue.id
timeline.label = new_label.name
timeline.started_time = Time.now
timeline.save
$logger.info "Hello"
new_timeline(db_issue.id, new_label.name)
end
elsif new_label.name != old_label.name
timeline = Timeline.where(issue_id: db_issue.id, label: old_label.name).first
timeline.end_time = Time.now
timeline.save
new_timeline(db_issue.id, new_label.name)
elsif new_label.name == old_label.name
timeline = Timeline.where(issue_id: db_issue.id, label: new_label.name).first
if timeline.nil?
new_timeline(db_issue.id, new_label.name)
end
end
# end TODO
......@@ -275,10 +277,18 @@ class GithubLoader
end
end
def update_repo(repositories)
repositories.each do |repo|
# def update_repo(repositories)
# repositories.each do |repo|
end
# end
# end
def new_timeline(issue_id, label)
timeline = Timeline.new
timeline.issue_id = issue_id
timeline.label = label
timeline.started_time = Time.now
timeline.save
end
end
......@@ -55,6 +55,62 @@ namespace :github do
$logger.info "Finished task import in #{Time.now - start_time}s"
end
desc "Insert github with some repositories selected before"
task insert_github_data_for_specific_repos: :environment do
loader = GithubLoader.new
start_time = Time.now
$logger.info "Begin task update " + $repos_to_update.to_s
list_db_repo = Repository.where(name: $repos_to_update)
list_db_user = User.all
list_db_label = Label.all
list_db_issue = loader.insert_issues($client, list_db_user, list_db_label, list_db_repo)
list_db_comment = loader.insert_comments($client, list_db_repo)
list_db_rv_comment = loader.insert_review_comments($client, list_db_repo)
logger.info "begin transaction"
start_time_transaction = Time.now
ActiveRecord::Base.transaction do
list_db_issue.each do |db_issue|
db_issue.save
end
list_db_comment.each do |db_comment|
db_comment.save
end
list_db_rv_comment.each do |db_rv_comment|
db_rv_comment.save
end
end
logger.info "Finished transaction in #{Time.now - start_time_transaction}s"
logger.info "Finished task update in #{Time.now - start_time}s"
end
desc "Insert Repository only"
task insert_repo_only: :environment do
loader = GithubLoader.new
$logger.info "Begin task insert repository"
list_db_repo = loader.insert_repos($client)
# list_db_user = loader.insert_users($client)
list_db_label = loader.insert_labels($client, list_db_repo)
ActiveRecord::Base.transaction do
list_db_repo.each do |db_repo|
db_repo.save
end
# list_db_user.each do |db_user|
# db_user.save
# end
list_db_label.each do |db_label|
db_label.save
end
end
$logger.info "Finished task insert repository"
end
desc "Insert comments only"
task insert_comment_data: :environment do
loader = GithubLoader.new
......@@ -78,8 +134,6 @@ namespace :github do
$logger.info "Finished task import comments in #{Time.now - start_time}s"
end
desc "Update issue pull association"
task update_issue_pull: :environment do
loader = GithubLoader.new
......
require 'test_helper'
class SettingsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# 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