Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
Work in progress for integrating Twitter Bootstrap and jQuery into
Branston, as well as removing Prototype and any refers to Rails JS
helpers which will help if we decide to switch to Padrino
  • Loading branch information
Stuart Chinery committed Dec 11, 2012
1 parent bff694f commit b158894
Show file tree
Hide file tree
Showing 83 changed files with 1,063 additions and 9,336 deletions.
10 changes: 5 additions & 5 deletions app/controllers/iterations_controller.rb
Expand Up @@ -27,9 +27,9 @@ class IterationsController < ApplicationController
# GET /iterations/1.xml
def show
@iteration = Iteration.find(params[:id])

respond_to do |format|
format.html { render :layout => 'burndown' }
format.html #{ render :layout => 'burndown' }
format.xml { render :xml => @iteration }
end
end
Expand All @@ -55,11 +55,11 @@ def edit
def create
@iteration = Iteration.new(params[:iteration])
@iteration.project = @project

respond_to do |format|
if @iteration.save
flash[:notice] = 'Iteration was successfully created.'
format.html { redirect_to project_iteration_path(@project, @iteration) }
format.html { redirect_to project_path(@project) }
format.xml { render :xml => @iteration, :status => :created, :location => @iteration }
else
find_project
Expand All @@ -78,7 +78,7 @@ def update
respond_to do |format|
if @iteration.update_attributes(params[:iteration])
flash[:notice] = 'Iteration was successfully updated.'
format.html { redirect_to project_iteration_path(@project, @iteration) }
format.html { redirect_to project_path(@project) }
format.xml { head :ok }
else
find_project
Expand Down
21 changes: 8 additions & 13 deletions app/controllers/projects_controller.rb
Expand Up @@ -5,25 +5,20 @@ class ProjectsController < ApplicationController
layout 'main'

def index
if current_user
if current_user.role == 'client'
@projects = current_user.projects
else
@projects = Project.all
end

respond_to do |format|
format.html
format.xml { render :xml => @projects }
end
if current_user.has_role?("admin")
@projects = Project.alphabetical
else
redirect_to '/sessions/new'
@projects = current_user.projects.alphabetical
end

respond_to do |format|
format.html
format.xml { render :xml => @projects }
end
end

def show
@project = Project.find(params[:id])
@page_title = @project.name
@iterations = Iteration.find(:all, :conditions => ["project_id = ?", params[:id]])

respond_to do |format|
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/sessions_controller.rb
Expand Up @@ -19,7 +19,7 @@ class SessionsController < ApplicationController

# render new.rhtml
def new

end

def create
Expand Down Expand Up @@ -52,7 +52,7 @@ def destroy
protected
# Track failed login attempts
def note_failed_signin
flash[:error] = "Couldn't log you in as '#{params[:login]}'"
@error = "Couldn't log you in as '#{params[:login]}'"
logger.warn "Failed login for '#{params[:login]}' from #{request.remote_ip} at #{Time.now.utc}"
end
end
Expand Down
11 changes: 4 additions & 7 deletions app/controllers/users_controller.rb
Expand Up @@ -23,15 +23,13 @@ class UsersController < ApplicationController
before_filter :capture_participations, :only => [:create, :update]

def index
@page_title = "Users"
@users = User.find(:all)
end

def new
@page_title = "New User"
@user = User.new
@user.password = @user.password_confirmation = nil
@projects = Project.all
@projects = Project.alphabetical
end

def create
Expand All @@ -43,16 +41,15 @@ def create
flash[:notice] = "User created."
else
flash[:error] = "We couldn't set up that account, sorry. Please try again, or contact an admin (link is above)."
@projects = Project.all
@projects = Project.alphabetical
render :action => 'new'
end
end

def edit
@user = User.find(params[:id])
@page_title = "Edit #{@user.login}"
@user.password = @user.password_confirmation = nil
@projects = Project.all
@projects = Project.alphabetical
end

def update
Expand All @@ -62,7 +59,7 @@ def update
add_participations(@user)
redirect_to users_path
else
@projects = Project.all
@projects = Project.alphabetical
render :action => 'edit'
end
end
Expand Down
34 changes: 31 additions & 3 deletions app/helpers/application_helper.rb
@@ -1,8 +1,18 @@
module ApplicationHelper

# Applies an html class attribute where the controller name contains the 'tab_name'.
def tab_on(tab_name, html_class="current_page_item")
controller_name.match(Regexp.new("#{tab_name}")) ? " class=\"#{html_class}\"" : ''
#
#
#
# @returns [String] -
#
def is_active?(*controllers)
controllers.each do |controller|
if controller_name.match(Regexp.new("#{controller}"))
return true
end
end

return false
end

# Produces a string id using the type and id of obj plus any field suffix supplied useful when
Expand Down Expand Up @@ -39,5 +49,23 @@ def clippy(text, bgcolor='#FFFFFF')
EOF
end

# Translates default Padrino flash keys into default Twitter Bootstrap
# alert CSS class name extension.
#
# @param [Symbol] flash - The flash key
# @return [String] the CSS class name
def bootstrap_alert_for(flash)
case flash
when :error
return "error"
when :warning
return "block"
when :notice
return "success"
when :info
return "info"
end
end

end

2 changes: 0 additions & 2 deletions app/helpers/outcomes_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/preconditions_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/projects_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/releases_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/sessions_helper.rb

This file was deleted.

10 changes: 7 additions & 3 deletions app/models/project.rb
Expand Up @@ -2,10 +2,14 @@ class Project < ActiveRecord::Base
has_many :iterations
has_many :participations
has_many :participants, :through => :participations, :source => :user

validates_presence_of :name
validates_uniqueness_of :name


# scopes
#
named_scope :alphabetical, :order => "name ASC"

def self.permit?(role, action)
case action
when :create
Expand All @@ -16,5 +20,5 @@ def self.permit?(role, action)
return (role == 'admin' ? true : false)
end
end

end
2 changes: 1 addition & 1 deletion app/views/iterations/_burndown_chart.html.erb
@@ -1,4 +1,4 @@
<% content_for :js_includes do %>
<% content_for :page_end do %>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", { packages:["corechart"] })
Expand Down
64 changes: 35 additions & 29 deletions app/views/iterations/_form.html.erb
@@ -1,34 +1,40 @@
<%= error_messages_for :object => @iteration,
:header_tag => 'h3',
:id => "errors",
:class => "errors",
:header_message => "Whoops!",
:message => "We had some problems saving this iteration."
:class => "alert alert-error",
:header_message => "",
:message => "We had some problems saving this iteration"
-%>
<div class="form">
<p class="form-fields">
<%= f.label :name %>
<%= f.text_field :name %>
</p>
<p class="form-fields">
<%= f.label :velocity %>
<%= f.text_field :velocity, :size => 4, :onkeypress => "return Branston.Form.numericOnly(event);" %>
</p>
<p class="form-fields">
<%= f.label :start_date %>
<%= f.calendar_date_select :start_date, :time => false, :popup => 'force' %>
</p>
<p class="form-fields">
<%= f.label :end_date %>
<%= f.calendar_date_select :end_date, :time => false, :popup => 'force' %>
</p>
<!--
TODO: Currently not showing releases as these need some reworking.
<% unless @releases.nil? -%>
<p class="form-fields">
<%= f.label :release %>
<%= f.select :release_id, @releases.map {|release| [release.release_date.strftime('%d/%m/%Y'), release.id]} %>
</p>
-->
<% end -%>

<div class="control-group">
<%= form.label :name, nil, :class => "control-label" %>
<div class="controls">
<%= form.text_field :name, :class => "input-xxlarge" %>
</div>
</div>

<div class="control-group">
<%= form.label :velocity, nil, :class => "control-label" %>
<div class="controls">
<%= form.text_field :velocity, :class => "input-xxlarge", :onkeypress => "return branston.forms.numericOnly(event);", :size => 4 %>
</div>
</div>

<div class="control-group">
<%= form.label :start_date, nil, :class => "control-label" %>
<div class="controls">
<%= form.text_field :start_date, :class => "input-xxlarge" %> Add calendar select
</div>
</div>

<div class="control-group">
<%= form.label :end_date, nil, :class => "control-label" %>
<div class="controls">
<%= form.text_field :end_date, :class => "input-xxlarge" %> Add calendar select
</div>
</div>

<div class="form-actions">
<button type="submit" class="btn btn-primary">Save</button>
<button type="button" class="btn" onclick="window.location='<%= projects_path %>';">Cancel</button>
</div>
33 changes: 22 additions & 11 deletions app/views/iterations/edit.html.erb
@@ -1,16 +1,27 @@
<% @page_title = "Edit #{@iteration.name}" %>
<h2><%=h @page_title %></h2>

<div id="actions">
<ul>
<li><%= link_to 'Back', project_path(@project) %></li>
<li><%= link_to 'Show', project_iteration_path(@project, @iteration) %></li>
</ul>
<div class="row">
<div class="span12">
<ul class="breadcrumb">
<li><a href="<%= projects_path %>">Projects</a> <span class="divider">/</span></li>
<li><a href="<%= project_path(@project) %>"><%= @project.name %></a> <span class="divider">/</span></li>
<li class="active"><%= @page_title %></li>
</ul>
</div>
</div>

<% form_for :iteration, :url => project_iteration_path(@project, @iteration),
:html => { :method => 'PUT' } do |f| %>
<%= render :partial => 'form', :locals => {:f => f } %>
<p><%= f.submit 'Update' %></p>
<% end %>
<div class="row heading">
<div class="span12">
<h1 class="muted"><%=h @page_title %></h1>
</div>
</div>

<div class="row">
<div class="span12">
<% form_for :iteration, :url => project_iteration_path(@project, @iteration),
:html => { :method => 'PUT', :class => "form-horizontal"} do |form| %>
<%= render :partial => 'form', :locals => {:form => form} %>
<% end %>
</div>
</div>

31 changes: 21 additions & 10 deletions app/views/iterations/new.html.erb
@@ -1,15 +1,26 @@
<% @page_title = "New Iteration" %>
<h2><%=h @page_title %></h2>

<div id="actions">
<ul>
<li><%= link_to 'Back', project_path(@project) %></li>
</ul>
<div class="row">
<div class="span12">
<ul class="breadcrumb">
<li><a href="<%= projects_path %>">Projects</a> <span class="divider">/</span></li>
<li><a href="<%= project_path(@project) %>"><%= @project.name %></a> <span class="divider">/</span></li>
<li class="active"><%= @page_title %></li>
</ul>
</div>
</div>

<% form_for :iteration, :url => project_iterations_path(@project),
:html => { :method => 'POST' } do |f| %>
<%= render :partial => 'form', :locals => {:f => f } %>
<p><%= f.submit 'Create' %></p>
<% end %>
<div class="row heading">
<div class="span12">
<h1 class="muted"><%=h @page_title %></h1>
</div>
</div>

<div class="row">
<div class="span12">
<% form_for :iteration, :url => project_iterations_path(@project),
:html => { :method => 'POST', :class => "form-horizontal" } do |form| %>
<%= render :partial => 'form', :locals => {:form => form} %>
<% end %>
</div>
</div>

0 comments on commit b158894

Please sign in to comment.