summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-10-04 22:17:14 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-10-04 22:18:26 +0300
commit6fe7659274fdc975df5570a7726bb68bdc00aa77 (patch)
tree43d65f35ae0cba6bc834460955a7fb36c5ae7f39
parent8f02b908a3bd83ede3c27b8bae2840475d6f1bb4 (diff)
downloadgitlab-ci-6fe7659274fdc975df5570a7726bb68bdc00aa77.tar.gz
will paginate, run route
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock2
-rw-r--r--app.rb21
-rw-r--r--lib/helper.rb4
-rw-r--r--views/index.haml2
-rw-r--r--views/project.haml9
6 files changed, 30 insertions, 9 deletions
diff --git a/Gemfile b/Gemfile
index 8a1a1c9..e19ea46 100644
--- a/Gemfile
+++ b/Gemfile
@@ -11,6 +11,7 @@ gem 'resque'
gem 'foreman'
gem 'pry'
gem 'stamp'
+gem 'will_paginate', '~> 3.0'
# DB
gem 'sqlite3'
diff --git a/Gemfile.lock b/Gemfile.lock
index 2ee3834..329e163 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -68,6 +68,7 @@ GEM
tzinfo (0.3.33)
vegas (0.1.11)
rack (>= 1.0.0)
+ will_paginate (3.0.1)
PLATFORMS
ruby
@@ -84,3 +85,4 @@ DEPENDENCIES
sqlite3
stamp
thin
+ will_paginate (~> 3.0)
diff --git a/app.rb b/app.rb
index 48aba36..75b448e 100644
--- a/app.rb
+++ b/app.rb
@@ -7,6 +7,8 @@ require 'sinatra'
require 'sinatra/base'
require "sinatra/reloader"
require 'sinatra/activerecord'
+require 'will_paginate'
+require 'will_paginate/active_record'
$: << File.dirname(__FILE__) + "/lib"
require 'project'
@@ -17,10 +19,11 @@ class GitlabCi < Sinatra::Base
configure :development do
register Sinatra::Reloader
end
+ register Sinatra::ActiveRecordExtension
include Helper
+ include WillPaginate::Sinatra::Helpers
- register Sinatra::ActiveRecordExtension
set :haml, format: :html5
set layout: true
@@ -29,13 +32,9 @@ class GitlabCi < Sinatra::Base
get '/' do
@projects = Project.all
- @projects.each do |project|
- Resque.enqueue(Runner, project.id)
- end
-
haml :index
end
-
+
get '/projects/new' do
# add project
haml :new
@@ -43,12 +42,13 @@ class GitlabCi < Sinatra::Base
get '/projects/new' do
# add project
+
haml :new
end
get '/projects/:name' do
@project = Project.find_by_name(params[:name])
- @builds = @project.builds.order('id DESC')
+ @builds = @project.builds.order('id DESC').paginate(:page => params[:page], :per_page => 30)
haml :project
end
@@ -59,6 +59,13 @@ class GitlabCi < Sinatra::Base
haml :edit
end
+ get '/projects/:name/run' do
+ @project = Project.find_by_name(params[:name])
+ Resque.enqueue(Runner, @project.id)
+
+ redirect project_path @project
+ end
+
get '/:id/status' do
# build status badge
end
diff --git a/lib/helper.rb b/lib/helper.rb
index c9549a9..f4b05ad 100644
--- a/lib/helper.rb
+++ b/lib/helper.rb
@@ -19,6 +19,10 @@ module Helper
end
end
+ def run_project_path project
+ "/projects/#{project.name}/run"
+ end
+
def project_path project
"/projects/#{project.name}"
end
diff --git a/views/index.haml b/views/index.haml
index 344ed38..ff9b0d5 100644
--- a/views/index.haml
+++ b/views/index.haml
@@ -8,7 +8,7 @@
#{project.human_status}
.body
%a.btn.btn-small{href: project_path(project)} Builds
- %a.btn.btn-small Run
+ %a.btn.btn-small{href: run_project_path(project)} Run
%a.btn.btn-small{href: edit_project_path(project)}
%i.icon-edit
Edit
diff --git a/views/project.haml b/views/project.haml
index f9b11be..f8bd1a0 100644
--- a/views/project.haml
+++ b/views/project.haml
@@ -1,4 +1,10 @@
-%h3 Project: #{@project.name}
+%h3
+ Project: #{@project.name}
+ .right
+ %a.btn.btn-small{href: run_project_path(@project)} Run
+ %a.btn.btn-small{href: edit_project_path(@project)}
+ %i.icon-edit
+ Edit
#accordion2.accordion
- @builds.each do |build|
.accordion-group
@@ -16,6 +22,7 @@
= preserve do
= build.trace
+ = will_paginate @builds
- if @builds.empty?
.alert
No builds yet