Commit fbdb9b04 by Bui Minh Duc

optimize github import

parent 29b46411
...@@ -37,6 +37,7 @@ gem 'bootstrap-select-rails', '~> 1.6', '>= 1.6.3' ...@@ -37,6 +37,7 @@ gem 'bootstrap-select-rails', '~> 1.6', '>= 1.6.3'
gem 'bootstrap-table-rails', '~> 1.11' gem 'bootstrap-table-rails', '~> 1.11'
gem 'momentjs-rails', '>= 2.9.0' gem 'momentjs-rails', '>= 2.9.0'
gem 'bootstrap3-datetimepicker-rails', '~> 4.14.30' gem 'bootstrap3-datetimepicker-rails', '~> 4.14.30'
gem 'whenever', '~> 0.9.7'
group :development, :test do group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console # Call 'byebug' anywhere in the code to stop execution and get a debugger console
......
...@@ -52,6 +52,7 @@ GEM ...@@ -52,6 +52,7 @@ GEM
momentjs-rails (>= 2.8.1) momentjs-rails (>= 2.8.1)
builder (3.2.2) builder (3.2.2)
byebug (9.0.6) byebug (9.0.6)
chronic (0.10.2)
coffee-rails (4.2.1) coffee-rails (4.2.1)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.2.x) railties (>= 4.0.0, < 5.2.x)
...@@ -171,6 +172,8 @@ GEM ...@@ -171,6 +172,8 @@ GEM
websocket-driver (0.6.4) websocket-driver (0.6.4)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2) websocket-extensions (0.1.2)
whenever (0.9.7)
chronic (>= 0.6.3)
will_paginate (3.1.5) will_paginate (3.1.5)
PLATFORMS PLATFORMS
...@@ -198,6 +201,7 @@ DEPENDENCIES ...@@ -198,6 +201,7 @@ DEPENDENCIES
tzinfo-data tzinfo-data
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
web-console web-console
whenever (~> 0.9.7)
will_paginate (~> 3.1, >= 3.1.5) will_paginate (~> 3.1, >= 3.1.5)
BUNDLED WITH BUNDLED WITH
......
...@@ -19,5 +19,6 @@ ...@@ -19,5 +19,6 @@
//= require bootstrap/alert //= require bootstrap/alert
//= require bootstrap/dropdown //= require bootstrap/dropdown
//= require bootstrap-table //= require bootstrap-table
//= require extensions/bootstrap-table-export.js
//= require moment //= require moment
//= require bootstrap-datetimepicker //= require bootstrap-datetimepicker
/*The MIT License (MIT)
Copyright (c) 2014 https://github.com/kayalshri/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/
jQuery.base64 = ( function( $ ) {
var _PADCHAR = "=",
_ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
_VERSION = "1.0";
function _getbyte64( s, i ) {
// This is oddly fast, except on Chrome/V8.
// Minimal or no improvement in performance by using a
// object with properties mapping chars to value (eg. 'A': 0)
var idx = _ALPHA.indexOf( s.charAt( i ) );
if ( idx === -1 ) {
throw "Cannot decode base64";
}
return idx;
}
function _decode( s ) {
var pads = 0,
i,
b10,
imax = s.length,
x = [];
s = String( s );
if ( imax === 0 ) {
return s;
}
if ( imax % 4 !== 0 ) {
throw "Cannot decode base64";
}
if ( s.charAt( imax - 1 ) === _PADCHAR ) {
pads = 1;
if ( s.charAt( imax - 2 ) === _PADCHAR ) {
pads = 2;
}
// either way, we want to ignore this last block
imax -= 4;
}
for ( i = 0; i < imax; i += 4 ) {
b10 = ( _getbyte64( s, i ) << 18 ) | ( _getbyte64( s, i + 1 ) << 12 ) | ( _getbyte64( s, i + 2 ) << 6 ) | _getbyte64( s, i + 3 );
x.push( String.fromCharCode( b10 >> 16, ( b10 >> 8 ) & 0xff, b10 & 0xff ) );
}
switch ( pads ) {
case 1:
b10 = ( _getbyte64( s, i ) << 18 ) | ( _getbyte64( s, i + 1 ) << 12 ) | ( _getbyte64( s, i + 2 ) << 6 );
x.push( String.fromCharCode( b10 >> 16, ( b10 >> 8 ) & 0xff ) );
break;
case 2:
b10 = ( _getbyte64( s, i ) << 18) | ( _getbyte64( s, i + 1 ) << 12 );
x.push( String.fromCharCode( b10 >> 16 ) );
break;
}
return x.join( "" );
}
function _getbyte( s, i ) {
var x = s.charCodeAt( i );
if ( x > 255 ) {
throw "INVALID_CHARACTER_ERR: DOM Exception 5";
}
return x;
}
function _encode( s ) {
if ( arguments.length !== 1 ) {
throw "SyntaxError: exactly one argument required";
}
s = String( s );
var i,
b10,
x = [],
imax = s.length - s.length % 3;
if ( s.length === 0 ) {
return s;
}
for ( i = 0; i < imax; i += 3 ) {
b10 = ( _getbyte( s, i ) << 16 ) | ( _getbyte( s, i + 1 ) << 8 ) | _getbyte( s, i + 2 );
x.push( _ALPHA.charAt( b10 >> 18 ) );
x.push( _ALPHA.charAt( ( b10 >> 12 ) & 0x3F ) );
x.push( _ALPHA.charAt( ( b10 >> 6 ) & 0x3f ) );
x.push( _ALPHA.charAt( b10 & 0x3f ) );
}
switch ( s.length - imax ) {
case 1:
b10 = _getbyte( s, i ) << 16;
x.push( _ALPHA.charAt( b10 >> 18 ) + _ALPHA.charAt( ( b10 >> 12 ) & 0x3F ) + _PADCHAR + _PADCHAR );
break;
case 2:
b10 = ( _getbyte( s, i ) << 16 ) | ( _getbyte( s, i + 1 ) << 8 );
x.push( _ALPHA.charAt( b10 >> 18 ) + _ALPHA.charAt( ( b10 >> 12 ) & 0x3F ) + _ALPHA.charAt( ( b10 >> 6 ) & 0x3f ) + _PADCHAR );
break;
}
return x.join( "" );
}
return {
decode: _decode,
encode: _encode,
VERSION: _VERSION
};
}( jQuery ) );
(function($){
$.fn.extend({
tableExport: function(options) {
var defaults = {
separator: ',',
ignoreColumn: [],
tableName:'yourTableName',
type:'csv',
pdfFontSize:14,
pdfLeftMargin:20,
escape:'true',
htmlContent:'false',
consoleLog:'false'
};
var options = $.extend(defaults, options);
var el = this;
if(defaults.type == 'csv' || defaults.type == 'txt'){
// Header
var tdData ="";
$(el).find('thead').find('tr').each(function() {
tdData += "\n";
$(this).filter(':visible').find('th').each(function(index,data) {
if ($(this).css('display') != 'none'){
if(defaults.ignoreColumn.indexOf(index) == -1){
tdData += '"' + parseString($(this)) + '"' + defaults.separator;
}
}
});
tdData = $.trim(tdData);
tdData = $.trim(tdData).substring(0, tdData.length -1);
});
// Row vs Column
$(el).find('tbody').find('tr').each(function() {
tdData += "\n";
$(this).filter(':visible').find('td').each(function(index,data) {
if ($(this).css('display') != 'none'){
if(defaults.ignoreColumn.indexOf(index) == -1){
tdData += '"'+ parseString($(this)) + '"'+ defaults.separator;
}
}
});
//tdData = $.trim(tdData);
tdData = $.trim(tdData).substring(0, tdData.length -1);
});
//output
if(defaults.consoleLog == 'true'){
console.log(tdData);
}
var base64data = "base64," + $.base64.encode(tdData);
window.open('data:application/'+defaults.type+';filename=exportData;' + base64data);
}else if(defaults.type == 'sql'){
// Header
var tdData ="INSERT INTO `"+defaults.tableName+"` (";
$(el).find('thead').find('tr').each(function() {
$(this).filter(':visible').find('th').each(function(index,data) {
if ($(this).css('display') != 'none'){
if(defaults.ignoreColumn.indexOf(index) == -1){
tdData += '`' + parseString($(this)) + '`,' ;
}
}
});
tdData = $.trim(tdData);
tdData = $.trim(tdData).substring(0, tdData.length -1);
});
tdData += ") VALUES ";
// Row vs Column
$(el).find('tbody').find('tr').each(function() {
tdData += "(";
$(this).filter(':visible').find('td').each(function(index,data) {
if ($(this).css('display') != 'none'){
if(defaults.ignoreColumn.indexOf(index) == -1){
tdData += '"'+ parseString($(this)) + '",';
}
}
});
tdData = $.trim(tdData).substring(0, tdData.length -1);
tdData += "),";
});
tdData = $.trim(tdData).substring(0, tdData.length -1);
tdData += ";";
//output
//console.log(tdData);
if(defaults.consoleLog == 'true'){
console.log(tdData);
}
var base64data = "base64," + $.base64.encode(tdData);
window.open('data:application/sql;filename=exportData;' + base64data);
}else if(defaults.type == 'json'){
var jsonHeaderArray = [];
$(el).find('thead').find('tr').each(function() {
var tdData ="";
var jsonArrayTd = [];
$(this).filter(':visible').find('th').each(function(index,data) {
if ($(this).css('display') != 'none'){
if(defaults.ignoreColumn.indexOf(index) == -1){
jsonArrayTd.push(parseString($(this)));
}
}
});
jsonHeaderArray.push(jsonArrayTd);
});
var jsonArray = [];
$(el).find('tbody').find('tr').each(function() {
var tdData ="";
var jsonArrayTd = [];
$(this).filter(':visible').find('td').each(function(index,data) {
if ($(this).css('display') != 'none'){
if(defaults.ignoreColumn.indexOf(index) == -1){
jsonArrayTd.push(parseString($(this)));
}
}
});
jsonArray.push(jsonArrayTd);
});
var jsonExportArray =[];
jsonExportArray.push({header:jsonHeaderArray,data:jsonArray});
//Return as JSON
//console.log(JSON.stringify(jsonExportArray));
//Return as Array
//console.log(jsonExportArray);
if(defaults.consoleLog == 'true'){
console.log(JSON.stringify(jsonExportArray));
}
var base64data = "base64," + $.base64.encode(JSON.stringify(jsonExportArray));
window.open('data:application/json;filename=exportData;' + base64data);
}else if(defaults.type == 'xml'){
var xml = '<?xml version="1.0" encoding="utf-8"?>';
xml += '<tabledata><fields>';
// Header
$(el).find('thead').find('tr').each(function() {
$(this).filter(':visible').find('th').each(function(index,data) {
if ($(this).css('display') != 'none'){
if(defaults.ignoreColumn.indexOf(index) == -1){
xml += "<field>" + parseString($(this)) + "</field>";
}
}
});
});
xml += '</fields><data>';
// Row Vs Column
var rowCount=1;
$(el).find('tbody').find('tr').each(function() {
xml += '<row id="'+rowCount+'">';
var colCount=0;
$(this).filter(':visible').find('td').each(function(index,data) {
if ($(this).css('display') != 'none'){
if(defaults.ignoreColumn.indexOf(index) == -1){
xml += "<column-"+colCount+">"+parseString($(this))+"</column-"+colCount+">";
}
}
colCount++;
});
rowCount++;
xml += '</row>';
});
xml += '</data></tabledata>'
if(defaults.consoleLog == 'true'){
console.log(xml);
}
var base64data = "base64," + $.base64.encode(xml);
window.open('data:application/xml;filename=exportData;' + base64data);
}else if(defaults.type == 'excel' || defaults.type == 'doc'|| defaults.type == 'powerpoint' ){
//console.log($(this).html());
var excel="<table>";
// Header
$(el).find('thead').find('tr').each(function() {
excel += "<tr>";
$(this).filter(':visible').find('th').each(function(index,data) {
if ($(this).css('display') != 'none'){
if(defaults.ignoreColumn.indexOf(index) == -1){
excel += "<td>" + parseString($(this))+ "</td>";
}
}
});
excel += '</tr>';
});
// Row Vs Column
var rowCount=1;
$(el).find('tbody').find('tr').each(function() {
excel += "<tr>";
var colCount=0;
$(this).filter(':visible').find('td').each(function(index,data) {
if ($(this).css('display') != 'none'){
if(defaults.ignoreColumn.indexOf(index) == -1){
excel += "<td>"+parseString($(this))+"</td>";
}
}
colCount++;
});
rowCount++;
excel += '</tr>';
});
excel += '</table>'
if(defaults.consoleLog == 'true'){
console.log(excel);
}
var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:"+defaults.type+"' xmlns='http://www.w3.org/TR/REC-html40'>";
excelFile += "<head>";
excelFile += "<!--[if gte mso 9]>";
excelFile += "<xml>";
excelFile += "<x:ExcelWorkbook>";
excelFile += "<x:ExcelWorksheets>";
excelFile += "<x:ExcelWorksheet>";
excelFile += "<x:Name>";
excelFile += "{worksheet}";
excelFile += "</x:Name>";
excelFile += "<x:WorksheetOptions>";
excelFile += "<x:DisplayGridlines/>";
excelFile += "</x:WorksheetOptions>";
excelFile += "</x:ExcelWorksheet>";
excelFile += "</x:ExcelWorksheets>";
excelFile += "</x:ExcelWorkbook>";
excelFile += "</xml>";
excelFile += "<![endif]-->";
excelFile += "</head>";
excelFile += "<body>";
excelFile += excel;
excelFile += "</body>";
excelFile += "</html>";
var base64data = "base64," + $.base64.encode(excelFile);
window.open('data:application/vnd.ms-'+defaults.type+';filename=exportData.doc;' + base64data);
}else if(defaults.type == 'png'){
html2canvas($(el), {
onrendered: function(canvas) {
var img = canvas.toDataURL("image/png");
window.open(img);
}
});
}else if(defaults.type == 'pdf'){
var doc = new jsPDF('p','pt', 'a4', true);
doc.setFontSize(defaults.pdfFontSize);
// Header
var startColPosition=defaults.pdfLeftMargin;
$(el).find('thead').find('tr').each(function() {
$(this).filter(':visible').find('th').each(function(index,data) {
if ($(this).css('display') != 'none'){
if(defaults.ignoreColumn.indexOf(index) == -1){
var colPosition = startColPosition+ (index * 50);
doc.text(colPosition,20, parseString($(this)));
}
}
});
});
// Row Vs Column
var startRowPosition = 20; var page =1;var rowPosition=0;
$(el).find('tbody').find('tr').each(function(index,data) {
rowCalc = index+1;
if (rowCalc % 26 == 0){
doc.addPage();
page++;
startRowPosition=startRowPosition+10;
}
rowPosition=(startRowPosition + (rowCalc * 10)) - ((page -1) * 280);
$(this).filter(':visible').find('td').each(function(index,data) {
if ($(this).css('display') != 'none'){
if(defaults.ignoreColumn.indexOf(index) == -1){
var colPosition = startColPosition+ (index * 50);
doc.text(colPosition,rowPosition, parseString($(this)));
}
}
});
});
// Output as Data URI
doc.output('datauri');
}
function parseString(data){
if(defaults.htmlContent == 'true'){
content_data = data.html().trim();
}else{
content_data = data.text().trim();
}
if(defaults.escape == 'true'){
content_data = escape(content_data);
}
return content_data;
}
}
});
})(jQuery);
...@@ -2,26 +2,27 @@ class MainController < ApplicationController ...@@ -2,26 +2,27 @@ class MainController < ApplicationController
def index def index
@repos = @repos || Repository.all @repos = @repos || Repository.all
@selected_repos = Repository.where(selected: true) @selected_repos_name = Other.where(data_type: 0).map{ |other| other.data }
@selected_repos = Repository.where(name: @selected_repos_name)
@label_filter = ["ventura", "priority-ugent", "priority-high", "priority-low"] @label_filter = ["ventura", "priority-ugent", "priority-high", "priority-low"]
@col_label_names = [ @col_label_names = [
"discussion", "todo", "inprogress", "discussion", "todo", "inprogress",
"vnreview", "jpreview", "ready", "vnreview", "jpreview", "ready",
"done", "releasefailed", "pending", "ventura"] "done", "releasefailed", "pending", "ventura", "prioritylow", "priorityhigh", "priorityurgent"]
@selected_repos_name = []
@data_table = [] @data_table = []
@selected_repos.each do |repo| @selected_repos.each do |repo|
@selected_repos_name.append(repo.name)
row_table = Hash.new row_table = Hash.new
row_table[:name] = repo.name row_table[:name] = repo.name
row_table[:link] = repo.html_url row_table[:link] = repo.html_url
row_table[:having_data] = false
repo.issues.each do |issue| repo.issues.each do |issue|
issue.labels.each do |label| issue.labels.each do |label|
label_name = standardize_string(label[:name]) label_name = standardize_string(label[:name])
@col_label_names.each do |col_label| @col_label_names.each do |col_label|
if label_name == col_label if label_name == col_label
row_table[:having_data] = true
cell = row_table[label_name] || Hash.new cell = row_table[label_name] || Hash.new
if cell[:count].nil? if cell[:count].nil?
cell[:count] = 1 cell[:count] = 1
...@@ -38,25 +39,28 @@ class MainController < ApplicationController ...@@ -38,25 +39,28 @@ class MainController < ApplicationController
end end
end end
end end
@data_table.append(row_table) if row_table[:having_data]
@data_table.append(row_table)
end
end end
end end
def update_repo_selected def update_repo_selected
repos_picked = Repository.where(name: params[:selected]) Other.destroy_all(data_type: 0)
repos_picked.each do |repo| params[:selected].each do |selected_repo_name|
repo.selected = true db_selected = Other.new
repo.save db_selected.data = selected_repo_name
end db_selected.data_type = 0
repos_not_picked = Repository.where.not(name: params[:selected]) db_selected.save
repos_not_picked.each do |repo|
repo.selected = false
repo.save
end end
redirect_to action: "index" redirect_to action: "index"
end end
def update_label_selected
Other.destroy_all(data_type: 1)
end
def load_repo_selected def load_repo_selected
# @repos = Repository.find() # @repos = Repository.find()
end end
......
...@@ -13,4 +13,25 @@ module MainHelper ...@@ -13,4 +13,25 @@ module MainHelper
mm.to_s + " minutes ago" mm.to_s + " minutes ago"
end end
end end
def get_text_color(bg_color)
r = bg_color[0, 2]
g = bg_color[2, 2]
b = bg_color[4, 2]
r = r.to_i(16)
g = g.to_i(16)
b = b.to_i(16)
a = 1 - (0.299 * r + 0.587 * g + 0.114 * b) / 255;
if a < 0.5
"000000"
else
"ffffff"
end
end
def format_html_id(text)
text.gsub(/[-._]+/, "")
end
end end
class Other < ApplicationRecord
end
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'tableExport' %>
</head> </head>
<body> <body>
......
...@@ -9,37 +9,9 @@ ...@@ -9,37 +9,9 @@
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="navbar-brand" href="#">GHR</a> <a class="navbar-brand" href="<%= root_url %>">GHR</a>
</div> </div>
<div id="navbar" class="navbar-collapse collapse"> <div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li><a href="#">Separated link</a></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="../navbar/">Default</a></li>
<li><a href="../navbar-static-top/">Static top</a></li>
<li class="active"><a href="./">Fixed top</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Settings <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Repositories</a></li>
</ul>
</li>
</ul>
</div> </div>
</div> </div>
</nav> </nav>
...@@ -48,6 +20,7 @@ ...@@ -48,6 +20,7 @@
<div class="container"> <div class="container">
<!-- content --> <!-- content -->
<div class="form-group"> <div class="form-group">
<label>Select repository</label>
<select class="selectpicker" id="selectpicker1" multiple data-live-search="true" multiple data-selected-text-format="count > 3"> <select class="selectpicker" id="selectpicker1" multiple data-live-search="true" multiple data-selected-text-format="count > 3">
<% @repos.each do |repo| %> <% @repos.each do |repo| %>
<option><%= repo.name %></option> <option><%= repo.name %></option>
...@@ -56,28 +29,40 @@ ...@@ -56,28 +29,40 @@
<button id="repo_apply" class="btn btn-default">Apply</button> <button id="repo_apply" class="btn btn-default">Apply</button>
</div> </div>
<form class="form-inline"> <div id="toolbar">
<div class="form-group"> <form class="form-inline">
<label for="from">From</label> <div class="form-group">
<div class='input-group date' id='datetimepicker1'> <label for="from">From</label>
<input type='text' class="form-control" /> <div class='input-group date' id='datetimepicker1'>
<span class="input-group-addon"> <input type='text' class="form-control" />
<span class="glyphicon glyphicon-calendar"></span> <span class="input-group-addon">
</span> <span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div> </div>
</div> <div class="form-group">
<div class="form-group"> <select class="selectpicker" multiple data-live-search="true">
<select class="selectpicker" multiple data-live-search="true"> <% @label_filter.each do |label| %>
<% @label_filter.each do |label| %> <option><%= label %></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"> <div style="margin-top: 20px">
<table class="table"> <table data-toolbar="#toolbar"
<thead class="thead-inverse"> data-toggle="table"
data-search="true"
data-show-export="true"
data-show-columns="true"
data-show-export="true"
data-minimum-count-columns="2"
data-show-pagination-switch="true"
data-pagination="true"
data-id-field="id"
data-page-list="[10, 25, 50, 100, ALL]">
<thead>
<tr> <tr>
<th></th> <th></th>
<% @col_label_names.each do |label| %> <% @col_label_names.each do |label| %>
...@@ -91,9 +76,9 @@ ...@@ -91,9 +76,9 @@
<td><%= link_to row[:name], row[:link] %></td> <td><%= link_to row[:name], row[:link] %></td>
<% @col_label_names.each do |label| %> <% @col_label_names.each do |label| %>
<% if row[label].nil? %> <% if row[label].nil? %>
<th>0</th> <td>0</td>
<% else %> <% else %>
<th><a href="" data-toggle="modal" data-target="#<%= row[:name] + label %>"><%= row[label][:count] %></a></th> <td><a href="" data-toggle="modal" data-target="#<%= format_html_id(row[:name] + label) %>"><%= row[label][:count] %></a></td>
<% end %> <% end %>
<% end %> <% end %>
...@@ -103,10 +88,11 @@ ...@@ -103,10 +88,11 @@
</table> </table>
</div> </div>
<% @data_table.each do |row| %> <% @data_table.each do |row| %>
<% @col_label_names.each do |label| %> <% @col_label_names.each do |label| %>
<% if !row[label].nil? %> <% 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 id="<%= format_html_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-dialog modal-lg">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
...@@ -123,7 +109,7 @@ ...@@ -123,7 +109,7 @@
<td> <td>
<a href="<%= issue[:html_url] %>"><%= issue[:title] %></a> <a href="<%= issue[:html_url] %>"><%= issue[:title] %></a>
<% issue.labels.each do |label| %> <% issue.labels.each do |label| %>
<span class="label label-default" style="background-color: #<%= label[:color] %>"><%= label[:name] %></span> <span class="label label-default" style="background-color: #<%= label[:color] %>; color: #<%= get_text_color(label[:color]) %>;"><%= label[:name] %></span>
<% end %> <% end %>
</td> </td>
<td><%= issue[:created_at] %></td> <td><%= issue[:created_at] %></td>
...@@ -156,6 +142,8 @@ ...@@ -156,6 +142,8 @@
$('#selectpicker1').selectpicker(); // init picker $('#selectpicker1').selectpicker(); // init picker
$('#selectpicker1').selectpicker('val', <%= @selected_repos_name.to_s.html_safe %>); $('#selectpicker1').selectpicker('val', <%= @selected_repos_name.to_s.html_safe %>);
$('#selectpicker2').selectpicker(); // init picker
}); });
$("#repo_apply").click(function() { $("#repo_apply").click(function() {
......
...@@ -9,3 +9,4 @@ Rails.application.config.assets.version = '1.0' ...@@ -9,3 +9,4 @@ Rails.application.config.assets.version = '1.0'
# Precompile additional assets. # Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
# Rails.application.config.assets.precompile += %w( search.js ) # Rails.application.config.assets.precompile += %w( search.js )
Rails.application.config.assets.precompile += %w( tableExport.js )
# Use this file to easily define all of your cron jobs.
#
# It's helpful, but not entirely necessary to understand cron before proceeding.
# http://en.wikipedia.org/wiki/Cron
# Example:
#
# set :output, "/path/to/my/cron_log.log"
#
# every 2.hours do
# command "/usr/bin/some_great_command"
# runner "MyModel.some_method"
# rake "some:great:rake:task"
# end
#
# every 4.days do
# runner "AnotherModel.prune_old_records"
# end
# Learn more: http://github.com/javan/whenever
set :environment, "development"
every 1.hour do
rake "github:insert_github_data"
end
class AddHtmlUrlToIssue < ActiveRecord::Migration[5.0]
def change
add_column :issues, :html_url, :string
end
end
class AddOpenToIssue < ActiveRecord::Migration[5.0]
def change
add_column :issues, :open, :boolean
end
end
class CreateOthers < ActiveRecord::Migration[5.0]
def change
create_table :others do |t|
t.string :data
t.string :data1
t.string :data2
t.integer :data_type
t.timestamps
end
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20161125072404) do ActiveRecord::Schema.define(version: 20161202062857) do
create_table "issues", force: :cascade do |t| create_table "issues", force: :cascade do |t|
t.string "url" t.string "url"
...@@ -22,6 +22,8 @@ ActiveRecord::Schema.define(version: 20161125072404) do ...@@ -22,6 +22,8 @@ ActiveRecord::Schema.define(version: 20161125072404) do
t.integer "user_id" t.integer "user_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "html_url"
t.boolean "open"
t.index ["repository_id"], name: "index_issues_on_repository_id" t.index ["repository_id"], name: "index_issues_on_repository_id"
t.index ["user_id"], name: "index_issues_on_user_id" t.index ["user_id"], name: "index_issues_on_user_id"
end end
...@@ -51,6 +53,15 @@ ActiveRecord::Schema.define(version: 20161125072404) do ...@@ -51,6 +53,15 @@ ActiveRecord::Schema.define(version: 20161125072404) do
t.index ["repository_id"], name: "index_labels_on_repository_id" t.index ["repository_id"], name: "index_labels_on_repository_id"
end end
create_table "others", force: :cascade do |t|
t.string "data"
t.string "data1"
t.string "data2"
t.integer "data_type"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "repositories", force: :cascade do |t| create_table "repositories", force: :cascade do |t|
t.string "name" t.string "name"
t.string "full_name" t.string "full_name"
......
# Logfile created on 2016-12-02 13:00:03 +0700 by logger.rb/54362
I, [2016-12-02T13:00:03.288942 #29541] INFO -- : Begin task insert database from github
I, [2016-12-02T13:34:06.230990 #31710] INFO -- : Begin task insert database from github
I, [2016-12-02T13:34:06.231070 #31710] INFO -- : Insert repos
I, [2016-12-02T13:34:11.550128 #31710] INFO -- : Insert users
I, [2016-12-02T13:34:17.182645 #31710] INFO -- : Insert labels
I, [2016-12-02T13:37:33.545951 #31710] INFO -- : Insert issues
I, [2016-12-02T13:41:30.251754 #31710] INFO -- : begin transaction
I, [2016-12-02T13:41:38.143381 #31710] INFO -- : Finished transaction in 7.891519882s
I, [2016-12-02T13:41:38.143464 #31710] INFO -- : Finished task import in 451.912390186s
I, [2016-12-02T14:00:02.847767 #1467] INFO -- : Begin task insert database from github
I, [2016-12-02T14:00:02.847859 #1467] INFO -- : Insert repos
I, [2016-12-02T14:00:09.153822 #1467] INFO -- : Insert users
I, [2016-12-02T14:00:14.818216 #1467] INFO -- : Insert labels
I, [2016-12-02T14:03:32.620611 #1467] INFO -- : Insert issues
I, [2016-12-02T14:07:32.849635 #1467] INFO -- : begin transaction
I, [2016-12-02T14:07:41.663683 #1467] INFO -- : Finished transaction in 8.81394648s
I, [2016-12-02T14:07:41.663766 #1467] INFO -- : Finished task import in 458.815903477s
I, [2016-12-02T15:00:03.257443 #4602] INFO -- : Begin task insert database from github
I, [2016-12-02T15:00:03.257537 #4602] INFO -- : Insert repos
I, [2016-12-02T15:00:08.729564 #4602] INFO -- : Insert users
I, [2016-12-02T15:00:14.719315 #4602] INFO -- : Insert labels
I, [2016-12-02T15:03:34.365760 #4602] INFO -- : Insert issues
I, [2016-12-02T15:07:33.471646 #4602] INFO -- : begin transaction
I, [2016-12-02T15:07:41.060408 #4602] INFO -- : Finished transaction in 7.588661961s
I, [2016-12-02T15:07:41.060487 #4602] INFO -- : Finished task import in 457.802947713s
I, [2016-12-02T16:00:02.753796 #6484] INFO -- : Begin task insert database from github
I, [2016-12-02T16:00:02.753898 #6484] INFO -- : Insert repos
I, [2016-12-02T16:00:08.666020 #6484] INFO -- : Insert users
I, [2016-12-02T16:00:15.404047 #6484] INFO -- : Insert labels
I, [2016-12-02T16:03:38.395456 #6484] INFO -- : Insert issues
I, [2016-12-02T16:07:35.285332 #6484] INFO -- : begin transaction
I, [2016-12-02T17:00:03.663033 #25408] INFO -- : Begin task insert database from github
I, [2016-12-02T17:00:03.663126 #25408] INFO -- : Insert repos
I, [2016-12-02T17:00:09.540618 #25408] INFO -- : Insert users
I, [2016-12-02T17:00:15.378630 #25408] INFO -- : Insert labels
I, [2016-12-02T17:03:33.861877 #25408] INFO -- : Insert issues
I, [2016-12-02T17:07:38.445501 #25408] INFO -- : begin transaction
I, [2016-12-02T17:07:46.215986 #25408] INFO -- : Finished transaction in 7.770369701s
I, [2016-12-02T17:07:46.216065 #25408] INFO -- : Finished task import in 462.55293774s
namespace :github do namespace :github do
$org = "ZIGExN" $org = "ZIGExN"
$logger = Logger.new("github.log")
desc "Task description"
task task_test: :environment do
# logger = Logger.new("test.log")
# logger.info "a message"
end
desc "Insert Zigexn Github data" desc "Insert Zigexn Github data"
task insert_github_data: :environment do task insert_github_data: :environment do
insert_repos($client) $logger.info "Begin task insert database from github"
insert_users($client) start_time = Time.now
list_db_repo = insert_repos($client)
list_db_user = insert_users($client)
list_db_label = insert_labels($client)
list_db_issue = insert_issues($client, list_db_user, list_db_label)
$logger.info "begin transaction"
start_time_transaction = Time.now
ActiveRecord::Base.transaction do
Repository.destroy_all
list_db_repo.each do |db_repo|
db_repo.save
end
db_repos = Repository.all User.destroy_all
# db_repos = Repository.where(name: "socialtools") list_db_user.each do |db_user|
db_repos.each do |db_repo| db_user.save
insert_labels(db_repo, $client) end
end
db_repos.each do |db_repo| Label.destroy_all
insert_issues(db_repo, $client) list_db_label.each do |db_label|
db_label.save
end
Issue.destroy_all
list_db_issue.each do |db_issue|
db_issue.save
end
end end
$logger.info "Finished transaction in #{Time.now - start_time_transaction}s"
$logger.info "Finished task import in #{Time.now - start_time}s"
end end
def insert_repos(client) def insert_repos(client)
$logger.info "Insert repos"
repos = client.org_repos($org) repos = client.org_repos($org)
last_page = 1 last_page = 1
unless client.last_response.headers[:link].nil? unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
end end
list_db_repo = []
for i in (1..last_page) for i in (1..last_page)
repos = client.org_repos($org, {type: 'all', page: i}) repos = client.org_repos($org, {type: 'all', page: i})
repos.each do |repo| repos.each do |repo|
db_repo = Repository.where(id: repo.id).first db_repo = Repository.new
new_flag = false db_repo.id = repo.id
if db_repo.nil? db_repo.name = repo.name
db_repo = Repository.new db_repo.full_name = repo.full_name
new_flag = true db_repo.private = repo.private
db_repo.id = repo.id db_repo.description = repo.description
db_repo.name = repo.name db_repo.url = repo.url
db_repo.full_name = repo.full_name db_repo.html_url = repo.html_url
db_repo.private = repo.private db_repo.created_at = repo.created_at
db_repo.description = repo.description db_repo.updated_at = repo.updated_at
db_repo.url = repo.url
db_repo.html_url = repo.html_url list_db_repo.append(db_repo)
db_repo.created_at = repo.created_at
db_repo.updated_at = repo.updated_at
end
if db_repo.save
if new_flag
puts "Insert repo success: " + repo.name
else
puts "Update repo success: " + repo.name
end
else
puts "Repo >> An error occured: " + repo.name
end
end end
end end
list_db_repo
end end
def insert_labels(repo, client) def insert_labels(client)
labels = client.labels($org + "/" + repo.name) $logger.info "Insert labels"
last_page = 1 db_repos = Repository.all
unless client.last_response.headers[:link].nil? list_db_label = []
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i db_repos.each do |repo|
end labels = client.labels($org + "/" + repo.name)
last_page = 1
unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
end
for i in (1..last_page) for i in (1..last_page)
labels = client.labels($org + "/" + repo.name, {page: i}) labels = client.labels($org + "/" + repo.name, {page: i})
labels.each do |label| labels.each do |label|
db_label = Label.where(id: label.id).first
new_flag = false
if db_label.nil?
new_flag = true
db_label = Label.new db_label = Label.new
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 db_label.repository_id = repo.id
end db_label.name = label.name
db_label.color = label.color
db_label.default = label.default
db_label.name = label.name list_db_label.append(db_label)
db_label.color = label.color
db_label.default = label.default
if db_label.save
if new_flag
puts "Insert label success: " + label.name
else
puts "Update label success: " + label.name
end
else
puts "Label >> An error occured: " + label.name
end end
end end
end end
list_db_label
end end
def insert_users(client) def insert_users(client)
$logger.info "Insert users"
users = client.org_members($org) users = client.org_members($org)
last_page = 1 last_page = 1
unless client.last_response.headers[:link].nil? unless client.last_response.headers[:link].nil?
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
end end
list_db_user = []
for i in (1..last_page) for i in (1..last_page)
users = client.org_members($org, {page: i}) users = client.org_members($org, {page: i})
users.each do |user| users.each do |user|
db_user = User.where(id: user.id).first db_user = User.new
new_flag = false db_user.id = user.id
if db_user.nil? db_user.login = user.login
new_flag = true db_user.url = user.url
db_user = User.new db_user.html_url = user.html_url
db_user.id = user.id
db_user.login = user.login
db_user.url = user.url
db_user.html_url = user.html_url
end
if db_user.save list_db_user.append(db_user)
if new_flag
puts "Insert user success: " + user.login
else
puts "Update user success: " + user.login
end
else
puts "User >> An error occured: " + user.login
end
end end
end end
list_db_user
end end
def insert_issues(repo, client) def insert_issues(client, list_db_user, list_db_label)
issues = client.list_issues($org + "/" + repo.name) $logger.info "Insert issues"
last_page = 1 db_repos = Repository.all
unless client.last_response.headers[:link].nil? list_db_issue = []
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
end
for i in (1..last_page) db_repos.each do |repo|
issues = client.list_issues($org + "/" + repo.name, {page: i}) issues = client.list_issues($org + "/" + repo.name)
issues.each do |issue| last_page = 1
db_issue = Issue.where(id: issue.id).first unless client.last_response.headers[:link].nil?
new_flag = false last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
if db_issue.nil? end
new_flag = true
for i in (1..last_page)
issues = client.list_issues($org + "/" + repo.name, {page: i})
issues.each do |issue|
db_issue = Issue.new db_issue = Issue.new
db_issue.id = issue.id db_issue.id = issue.id
db_issue.url = issue.url db_issue.url = issue.url
...@@ -148,36 +149,38 @@ namespace :github do ...@@ -148,36 +149,38 @@ namespace :github do
db_issue.number = issue.number db_issue.number = issue.number
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 db_issue.title = issue.title
issue.labels.each do |label| db_issue.body = issue.body
db_label = Label.find_by(id: label.id) db_issue.html_url = issue.html_url
db_issue.labels.append(db_label) db_issue.created_at = issue.created_at
end db_issue.updated_at = issue.updated_at
db_issue.users.clear db_issue.labels.clear
issue.assignees.each do |assignee| issue.labels.each do |label|
db_assignee = User.find_by(id: assignee.id) list_db_label.each do |db_label|
db_issue.users.append(db_assignee) if db_label.id == label.id
end db_issue.labels.append(db_label)
break
end
end
end
if db_issue.save db_issue.users.clear
if new_flag issue.assignees.each do |assignee|
puts "Insert issue success: " + issue.title list_db_user.each do |db_user|
else if db_user.id == assignee.id
puts "Update issue success: " + issue.title db_issue.users.append(db_user)
break
end
end
end end
else
puts "Issue >> an error occured: " + issue.title list_db_issue.append(db_issue)
end end
end end
end end
list_db_issue
end end
end end
# Logfile created on 2016-12-02 11:19:00 +0700 by logger.rb/54362
I, [2016-12-02T11:19:07.703083 #25281] INFO -- : hehe
I, [2016-12-02T11:19:52.361449 #25310] INFO -- : hehe
I, [2016-12-02T11:24:03.083031 #25649] INFO -- : a message
I, [2016-12-02T11:25:02.479040 #25730] INFO -- : a message
I, [2016-12-02T11:26:02.943313 #25804] INFO -- : a message
I, [2016-12-02T11:27:03.334729 #25905] INFO -- : a message
I, [2016-12-02T11:28:02.757002 #26087] INFO -- : a message
I, [2016-12-02T11:29:03.248269 #26204] INFO -- : a message
I, [2016-12-02T11:30:02.654350 #26288] INFO -- : a message
I, [2016-12-02T11:31:03.096512 #26515] INFO -- : a message
I, [2016-12-02T11:31:03.111374 #26514] INFO -- : a message
I, [2016-12-02T11:32:02.562251 #26659] INFO -- : a message
I, [2016-12-02T11:32:02.563612 #26658] INFO -- : a message
I, [2016-12-02T11:33:03.022162 #26860] INFO -- : a message
I, [2016-12-02T11:33:03.108266 #26859] INFO -- : a message
I, [2016-12-02T11:34:02.530958 #26973] INFO -- : a message
I, [2016-12-02T12:37:03.189093 #28382] INFO -- : a message
I, [2016-12-02T12:38:02.729618 #28506] INFO -- : a message
I, [2016-12-02T12:40:03.237176 #28785] INFO -- : a message
I, [2016-12-02T12:41:02.772334 #28923] INFO -- : a message
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
data: MyString
data1: MyString
data2: MyString
data_type: 1
two:
data: MyString
data1: MyString
data2: MyString
data_type: 1
require 'test_helper'
class OtherTest < ActiveSupport::TestCase
# 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