Commit b821a634 by Bui Minh Duc

implemented loading repositories

parent e6813b53
......@@ -31,6 +31,10 @@ gem 'jbuilder', '~> 2.5'
# gem 'capistrano-rails', group: :development
gem 'bootstrap-sass', '~> 3.3.6'
gem 'octokit', '~> 4.6', '>= 4.6.2'
gem 'will_paginate', '~> 3.1', '>= 3.1.5'
gem 'bootstrap-select-rails', '~> 1.6', '>= 1.6.3'
gem 'bootstrap-table-rails', '~> 1.11'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
......
......@@ -38,12 +38,16 @@ GEM
i18n (~> 0.7)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.5.0)
public_suffix (~> 2.0, >= 2.0.2)
arel (7.1.4)
autoprefixer-rails (6.4.1)
execjs
bootstrap-sass (3.3.6)
autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4)
bootstrap-select-rails (1.6.3)
bootstrap-table-rails (1.11.0)
builder (3.2.2)
byebug (9.0.6)
coffee-rails (4.2.1)
......@@ -57,6 +61,8 @@ GEM
debug_inspector (0.0.2)
erubis (2.7.0)
execjs (2.7.0)
faraday (0.10.0)
multipart-post (>= 1.2, < 3)
ffi (1.9.14)
globalid (0.3.7)
activesupport (>= 4.1.0)
......@@ -82,9 +88,13 @@ GEM
mini_portile2 (2.1.0)
minitest (5.9.1)
multi_json (1.12.1)
multipart-post (2.0.0)
nio4r (1.2.1)
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
octokit (4.6.2)
sawyer (~> 0.8.0, >= 0.5.3)
public_suffix (2.0.4)
puma (3.6.1)
rack (2.0.1)
rack-test (0.6.3)
......@@ -123,6 +133,9 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sawyer (0.8.1)
addressable (>= 2.3.5, < 2.6)
faraday (~> 0.8, < 1.0)
spring (2.0.0)
activesupport (>= 4.2)
spring-watcher-listen (2.0.1)
......@@ -154,17 +167,21 @@ GEM
websocket-driver (0.6.4)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
will_paginate (3.1.5)
PLATFORMS
ruby
DEPENDENCIES
bootstrap-sass (~> 3.3.6)
bootstrap-select-rails (~> 1.6, >= 1.6.3)
bootstrap-table-rails (~> 1.11)
byebug
coffee-rails (~> 4.2)
jbuilder (~> 2.5)
jquery-rails
listen (~> 3.0.5)
octokit (~> 4.6, >= 4.6.2)
puma (~> 3.0)
rails (~> 5.0.0, >= 5.0.0.1)
sass-rails (~> 5.0)
......@@ -175,6 +192,7 @@ DEPENDENCIES
tzinfo-data
uglifier (>= 1.3.0)
web-console
will_paginate (~> 3.1, >= 3.1.5)
BUNDLED WITH
1.13.6
......@@ -14,3 +14,8 @@
//= require jquery_ujs
//= require turbolinks
//= require_tree .
//= require bootstrap-sprockets
//= require bootstrap-select
//= require bootstrap/alert
//= require bootstrap/dropdown
//= require bootstrap-table
# 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/
......@@ -12,5 +12,6 @@
*
*= require_tree .
*= require_self
*= require bootstrap-table
*/
......@@ -2,6 +2,6 @@
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
@import "bootstrap-sprockets";
@import "bootstrap";
@import "bootstrap-select";
// Place all the styles related to the repository controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
@import "bootstrap-sprockets";
@import "bootstrap";
class MainController < ApplicationController
def index
@repos = Repository.all
end
end
class RepositoryController < ApplicationController
def index
@repos = Repository.paginate(:page => params[:page], :per_page => 10)
end
end
module RepositoryHelper
end
class Repository < ApplicationRecord
end
<div>
<h1>Hello</h1>
<!-- Fixed navbar -->
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">GHR</a>
</div>
<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>
</nav>
<div class="container">
<!-- content -->
<select class="selectpicker" multiple data-live-search="true" multiple data-selected-text-format="count > 3">
<% @repos.each do |repo| %>
<option><%= repo.name %></option>
<% end %>
</select>
<button>Apply</button>
</div>
<script type="text/javascript">
var selected_repos = $('.selectpicker').selectpicker('val');
</script>
</div>
<div class="container">
<% @repos.each do |repo| %>
<li>
<div>
<h3><%= link_to repo.name, repo.html_url %></h3>
</div>
<div>
<p><%= repo.description %></p>
</div>
</li>
<% end %>
<%= will_paginate @repos %>
</div>
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root "main#index"
get "/repo", to: "repository#index"
# resource :repository
end
class CreateRepositories < ActiveRecord::Migration[5.0]
def change
create_table :repositories do |t|
t.integer :repo_id
t.string :name
t.string :full_name
t.string :html_url
t.string :description
t.string :url
t.boolean :selected
t.timestamps
end
end
end
......@@ -10,6 +10,18 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 0) do
ActiveRecord::Schema.define(version: 20161122095355) do
create_table "repositories", force: :cascade do |t|
t.integer "repo_id"
t.string "name"
t.string "full_name"
t.string "html_url"
t.string "description"
t.string "url"
t.boolean "selected"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
namespace :github do
desc "Insert Zigexn repository"
task insert_repos: :environment do
org = "ZIGExN"
client = Octokit::Client.new(access_token: Rails.application.secrets.GITHUB_TOKEN)
repos = client.org_repos(org)
last_page = client.last_response.headers[:link].split(' ')[2][-3].to_i
for i in (1..last_page)
repos = client.org_repos(org, {type: 'all', page: i})
repos.each do |repo|
db_repo = Repository.new
db_repo.repo_id = repo.id
db_repo.name = repo.name
db_repo.full_name = repo.full_name
db_repo.html_url = repo.html_url
db_repo.description = repo.description
db_repo.url = repo.url
db_repo.created_at = repo.created_at
db_repo.updated_at = repo.updated_at
if db_repo.save
puts "Insert repo success"
else
puts "Repo exist"
end
end
end
end
end
require 'test_helper'
class RepositoryControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
repo_id: 1
name: MyString
full_name: MyString
html_url: MyString
description: MyString
url: MyString
selected: false
two:
repo_id: 1
name: MyString
full_name: MyString
html_url: MyString
description: MyString
url: MyString
selected: false
require 'test_helper'
class RepositoryTest < 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