Created
March 13, 2014 22:16
-
-
Save anonymous/9538224 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for [@accomplishment.project, @accomplishment] do |f| %> | |
<% if @accomplishment.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(@accomplishment.errors.count, "error") %> prohibited this accomplishment from being saved:</h2> | |
<ul> | |
<% @accomplishment.errors.full_messages.each do |msg| %> | |
<li><%= msg %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% end %> | |
<table class="FormTable"> | |
<tr> | |
<th colspan="2" class="TitleRow"><%= @formTitle %></td> | |
</tr> | |
<tr> | |
<td> </td> | |
<td class="labeldesc"> </td> | |
</tr> | |
<tr> | |
<td class="label">Description:</td> | |
<td class="data"><%= f.text_field :description %></td> | |
</tr> | |
<tr> | |
<td> </td> | |
<td class="labeldesc"> </td> | |
</tr> | |
<tr> | |
<td class="label">Rating:</td> | |
<td class="data"><%= f.select :rating, 1..5, { include_blank: 'Please select a rating' } %></td> | |
</tr> | |
<% if @formMode == "new" then %> | |
<%= f.fields_for :images.last do |builder| %> | |
<%= render 'image_fields', :f => builder %> | |
<% end %> | |
<% end %> | |
<tr> | |
<td> </td> | |
<td class="labeldesc"> </td> | |
</tr> | |
<tr class="BottomButtonRow"> | |
<td colspan="2"> | |
<table> | |
<tr> | |
<td class="left"> | |
<%= link_to 'Cancel', project_accomplishments_path %> | |
</td> | |
<td class="right"> | |
<input name="" type="submit" value="Save" /> | |
</td> | |
</tr> | |
</table> | |
</td> | |
</tr> | |
</table> | |
<% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<tr> | |
<td> </td> | |
<td class="labeldesc"> </td> | |
</tr> | |
<tr> | |
<td class="label">Image URL:</td> | |
<td class="data"><%= f.text_field :url %></td> | |
</tr> | |
<tr> | |
<td> </td> | |
<td class="labeldesc"> </td> | |
</tr> | |
<tr> | |
<td class="label">Image Caption:</td> | |
<td class="data"><%= f.text_field :caption %></td> | |
</tr> | |
<tr> | |
<td> </td> | |
<td class="labeldesc"> </td> | |
</tr> | |
<tr> | |
<td class="label">Image Thumbnail:</td> | |
<td class="data"><%= image_tag "", id: "thumbnail", class: "thumbnail" %></td> | |
</tr> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# == Schema Information | |
# | |
# Table name: accomplishments | |
# | |
# id :integer not null, primary key | |
# description :string(255) | |
# project_id :integer | |
# created_by :integer | |
# modified_by :integer | |
# created_at :datetime | |
# updated_at :datetime | |
# rating :integer | |
# | |
class Accomplishment < ActiveRecord::Base | |
belongs_to :project | |
# belongs_to :creator, :class_name => "User", :foreign_key => "created_by" | |
# belongs_to :updater, :class_name => "User", :foreign_key => "updated_by" | |
has_many :images, through: :project | |
accepts_nested_attributes_for :images, reject_if: lambda { |i| i[:url].blank? && i[:caption].blank? } | |
validates :description, presence: true | |
validates_associated :images | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AccomplishmentsController < ApplicationController | |
before_action :set_accomplishment, only: [:show, :edit, :update, :destroy] | |
# GET /accomplishments | |
# GET /accomplishments.json | |
def index | |
@project = Project.find(params[:project_id]) | |
@accomplishments = @project.accomplishments.order("rating DESC") | |
end | |
# GET /accomplishments/1 | |
# GET /accomplishments/1.json | |
def show | |
end | |
# GET /accomplishments/new | |
def new | |
if current_user.can_add_accomplishments?(params[:project_id]) then | |
@project = Project.find(params[:project_id]) | |
@accomplishment = Accomplishment.new(:project=>@project) | |
@accomplishment.images.create | |
else | |
redirect_to project_accomplishments_url, flash: { error: 'You do not have access to add accomplishments to this project.' } | |
end | |
end | |
# GET /accomplishments/1/edit | |
def edit | |
if current_user.can_edit_accomplishments?(params[:project_id]) then | |
@project = Project.find(params[:project_id]) | |
else | |
redirect_to project_accomplishments_url, flash: { error: 'You do not have access to edit accomplishments for this project.' } | |
end | |
end | |
# POST /accomplishments | |
# POST /accomplishments.json | |
def create | |
if current_user.can_add_accomplishments?(params[:project_id]) then | |
@accomplishment = Accomplishment.new(accomplishment_params) | |
@accomplishment.project_id = params[:project_id] | |
# @accomplishment.created_by = 1 | |
# @accomplishment.modified_by = 1 | |
@project = @accomplishment.project | |
respond_to do |format| | |
if @accomplishment.save | |
format.html { redirect_to project_accomplishments_url, notice: 'The Accomplishment has been added.' } | |
format.json { render action: 'show', status: :created, location: @accomplishment } | |
else | |
format.html { render action: 'new' } | |
format.json { render json: @accomplishment.errors, status: :unprocessable_entity } | |
end | |
end | |
else | |
redirect_to project_accomplishments_url, flash: { error: 'You do not have access to add accomplishments to this project.' } | |
end | |
end | |
# PATCH/PUT /accomplishments/1 | |
# PATCH/PUT /accomplishments/1.json | |
def update | |
if current_user.can_edit_accomplishments?(params[:project_id]) then | |
respond_to do |format| | |
if @accomplishment.update(accomplishment_params) | |
format.html { redirect_to project_accomplishments_url, notice: 'The Accomplishment has been updated.' } | |
format.json { head :no_content } | |
else | |
format.html { render action: 'edit' } | |
format.json { render json: @accomplishment.errors, status: :unprocessable_entity } | |
end | |
end | |
else | |
redirect_to project_accomplishments_url, flash: { error: 'You do not have access to edit accomplishments for this project.' } | |
end | |
end | |
# DELETE /accomplishments/1 | |
# DELETE /accomplishments/1.json | |
def destroy | |
if current_user.can_delete_accomplishments? then | |
@accomplishment.destroy | |
respond_to do |format| | |
format.html { redirect_to project_accomplishments_url, notice: 'The Accomplishment has been deleted.' } | |
format.json { head :no_content } | |
end | |
else | |
redirect_to project_accomplishments_url, flash: { error: 'You do not have access to delete accomplishments for this project.' } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_accomplishment | |
@accomplishment = Accomplishment.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def accomplishment_params | |
params.require(:accomplishment).permit(:description, :project_id, :rating, :image_url, :image_caption, images_attributes: [:url, :caption]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# == Schema Information | |
# | |
# Table name: images | |
# | |
# id :integer not null, primary key | |
# url :string(255) | |
# caption :string(255) | |
# project_id :integer | |
# created_at :datetime | |
# updated_at :datetime | |
# | |
class Image < ActiveRecord::Base | |
belongs_to :project | |
validates :url, presence: true, if: "!caption.blank? || controller == 'images'" | |
validates :caption, presence: true, if: "!url.blank? || controller == 'images'" | |
def controller | |
@controller | |
end | |
def controller=(val) | |
@controller = val | |
end | |
def show_on_page | |
@show_on_page | |
end | |
def show_on_page=(val) | |
@show_on_page = val | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% @formTitle = "New Accomplishment" %> | |
<% @formMode = "new" %> | |
<%= render 'form' %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# == Schema Information | |
# | |
# Table name: projects | |
# | |
# id :integer not null, primary key | |
# title :string(255) | |
# executive_summary :string(255) | |
# ba_disasters :string(255) | |
# ba_ecological_forecasting :string(255) | |
# ba_health_air_quality :string(255) | |
# ba_water_resources :string(255) | |
# ba_agriculture :string(255) | |
# ba_climate :string(255) | |
# ba_energy :string(255) | |
# ba_oceans :string(255) | |
# ba_weather :string(255) | |
# created_at :datetime | |
# updated_at :datetime | |
# funding_source :string(255) | |
# official_start_date :datetime | |
# | |
class Project < ActiveRecord::Base | |
# belongs_to :creator, :class_name => "User", :foreign_key => "created_by" | |
# belongs_to :updater, :class_name => "User", :foreign_key => "updated_by" | |
has_many :deliverables | |
has_many :risks | |
has_many :accomplishments | |
has_many :weekly_updates | |
has_many :budget_updates | |
has_many :schedule_updates | |
has_many :milestones | |
has_many :project_arls | |
has_many :images | |
has_many :user_project_roles | |
has_many :users, through: :user_project_roles | |
has_many :roles, through: :user_project_roles | |
has_many :organizations, through: :user_project_roles | |
accepts_nested_attributes_for :images, reject_if: lambda { |i| i[:url].blank? && i[:caption].blank? } | |
validates :title, presence: true | |
validates :executive_summary, presence: true | |
# validates :start_arl, :current_arl, presence: true, | |
# numericality: { only_integer: true, greater_than: 0, less_than: 11 } | |
validates :ba_disasters, inclusion: { in: %w(0 L M H) }, length: { is: 1 }, allow_blank: true | |
validates :ba_ecological_forecasting, inclusion: { in: %w(0 L M H) }, length: { is: 1 }, allow_blank: true | |
validates :ba_health_air_quality, inclusion: { in: %w(0 L M H) }, length: { is: 1 }, allow_blank: true | |
validates :ba_water_resources, inclusion: { in: %w(0 L M H) }, length: { is: 1 }, allow_blank: true | |
validates :ba_agriculture, inclusion: { in: %w(0 L M H) }, length: { is: 1 }, allow_blank: true | |
validates :ba_climate, inclusion: { in: %w(0 L M H) }, length: { is: 1 }, allow_blank: true | |
validates :ba_energy, inclusion: { in: %w(0 L M H) }, length: { is: 1 }, allow_blank: true | |
validates :ba_oceans, inclusion: { in: %w(0 L M H) }, length: { is: 1 }, allow_blank: true | |
validates :ba_weather, inclusion: { in: %w(0 L M H) }, length: { is: 1 }, allow_blank: true | |
validates_associated :images | |
def poc | |
self.users.where("role_id = ?", Role.where("name = 'POC'").first.id).first | |
end | |
def pm | |
self.users.where("role_id = ?", Role.where("name = 'PM'").first.id).first | |
end | |
def pc | |
self.users.where("role_id = ?", Role.where("name = 'PC'").first.id).first | |
end | |
def start_arl | |
self.project_arls.order("created_at").first.arl | |
end | |
def current_arl | |
self.project_arls.order("created_at").last.arl | |
end | |
def current_risk_id | |
self.risks.order("created_at").last.project_risk_id | |
end | |
def arl=(val) | |
arl = ProjectArl.new | |
arl.project_id = self.id | |
arl.arl = val | |
arl.save | |
end | |
def team | |
self.organizations.group(:short_name).map { |o| o.short_name }.join(", ") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment