Commit 2217176fdf6670c5558882734afdfade795ffdda
Committed by
Rafael Manzo
1 parent
6347d197
Exists in
colab
and in
4 other branches
Add image for project
Showing
14 changed files
with
101 additions
and
10 deletions
Show diff stats
Gemfile
| ... | ... | @@ -37,7 +37,7 @@ gem 'kalibro_gatekeeper_client', '~> 1.0.0' |
| 37 | 37 | gem "pg", "~> 0.17.0" |
| 38 | 38 | |
| 39 | 39 | # Twitter Bootstrap for layout |
| 40 | -gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git' | |
| 40 | +gem 'twitter-bootstrap-rails', :git => 'https://github.com/seyhunak/twitter-bootstrap-rails.git' | |
| 41 | 41 | |
| 42 | 42 | # Chart generation |
| 43 | 43 | gem "chart-js-rails", "~> 0.0.6" | ... | ... |
Gemfile.lock
17.4 KB
app/controllers/projects_controller.rb
| ... | ... | @@ -22,6 +22,7 @@ class ProjectsController < ApplicationController |
| 22 | 22 | @project = Project.new(project_params) |
| 23 | 23 | respond_to do |format| |
| 24 | 24 | create_and_redir(format) |
| 25 | + add_image_url(project_params[:image_url], @project.id) | |
| 25 | 26 | end |
| 26 | 27 | end |
| 27 | 28 | |
| ... | ... | @@ -30,16 +31,19 @@ class ProjectsController < ApplicationController |
| 30 | 31 | def show |
| 31 | 32 | set_project |
| 32 | 33 | @project_repositories = @project.repositories |
| 34 | + @project_image = ProjectImage.find_by_project_id(@project.id).image_url | |
| 33 | 35 | end |
| 34 | 36 | |
| 35 | 37 | # GET /projects/1/edit |
| 36 | 38 | # GET /projects/1/edit.json |
| 37 | 39 | def edit |
| 38 | 40 | set_project |
| 39 | - end | |
| 41 | + check_no_image(@project.id) | |
| 42 | + end | |
| 40 | 43 | |
| 41 | 44 | def update |
| 42 | 45 | set_project |
| 46 | + update_image_url(project_params[:image_url], @project.id) | |
| 43 | 47 | if @project.update(project_params) |
| 44 | 48 | redirect_to(project_path(@project.id)) |
| 45 | 49 | else |
| ... | ... | @@ -82,4 +86,26 @@ class ProjectsController < ApplicationController |
| 82 | 86 | format.json { render json: @project.errors, status: :unprocessable_entity } |
| 83 | 87 | end |
| 84 | 88 | end |
| 89 | + | |
| 90 | + def add_image_url url,project_id | |
| 91 | + if url.blank? | |
| 92 | + url = "no-image-available.png" | |
| 93 | + end | |
| 94 | + ProjectImage.create(image_url: url,project_id: project_id ) | |
| 95 | + end | |
| 96 | + | |
| 97 | + def update_image_url url,project_id | |
| 98 | + if url.blank? | |
| 99 | + url = "no-image-available.png" | |
| 100 | + end | |
| 101 | + ProjectImage.find_by_project_id(project_id).update(image_url: url) | |
| 102 | + end | |
| 103 | + | |
| 104 | + def check_no_image project_id | |
| 105 | + @project_image = ProjectImage.find_by_project_id(project_id).image_url | |
| 106 | + if @project_image == "no-image-available.png" | |
| 107 | + @project_image = "" | |
| 108 | + end | |
| 109 | + end | |
| 110 | + | |
| 85 | 111 | end | ... | ... |
app/models/module_result.rb
| ... | ... | @@ -23,4 +23,4 @@ class ModuleResult < KalibroGatekeeperClient::Entities::ModuleResult |
| 23 | 23 | def find_grade_by_metric_name(metric_results, name) |
| 24 | 24 | metric_results.each { |metric_result| return metric_result.value if metric_result.metric_configuration_snapshot.metric.name == name } |
| 25 | 25 | end |
| 26 | -end | |
| 27 | 26 | \ No newline at end of file |
| 27 | +end | ... | ... |
app/models/project.rb
| ... | ... | @@ -3,7 +3,7 @@ require "validators/kalibro_uniqueness_validator.rb" |
| 3 | 3 | class Project < KalibroGatekeeperClient::Entities::Project |
| 4 | 4 | include KalibroRecord |
| 5 | 5 | |
| 6 | - attr_accessor :name | |
| 6 | + attr_accessor :name,:image_url | |
| 7 | 7 | validates :name, presence: true, kalibro_uniqueness: true |
| 8 | 8 | |
| 9 | 9 | def repositories | ... | ... |
app/views/projects/_form.html.erb
| ... | ... | @@ -16,6 +16,15 @@ |
| 16 | 16 | <%= f.text_area :description, class: 'text-area form-control' %> |
| 17 | 17 | </div> |
| 18 | 18 | </div> |
| 19 | + | |
| 20 | + <div class="form-row"> | |
| 21 | + <div class="field-container"> | |
| 22 | + <%= f.label "Image url", class: 'control-label' %><br> | |
| 23 | + <%= f.text_field :image_url, class: 'text-area', value: @project_image %> | |
| 24 | + </div> | |
| 25 | + </div> | |
| 26 | + | |
| 27 | + | |
| 19 | 28 | </div> |
| 20 | 29 | </div> |
| 21 | 30 | <div class="row margin-left-none" style="margin-top: 20px"> | ... | ... |
app/views/projects/edit.html.erb
| ... | ... | @@ -2,4 +2,12 @@ |
| 2 | 2 | <h1>Edit Project</h1> |
| 3 | 3 | </div> |
| 4 | 4 | |
| 5 | -<%= render 'form' %> | |
| 6 | 5 | \ No newline at end of file |
| 6 | +<%= render 'form' %> | |
| 7 | + | |
| 8 | +<div class="page-header"> | |
| 9 | + <div class="media"> | |
| 10 | + <a class="pull-left"> | |
| 11 | + <%= image_tag "#{@project_image}", size:"64x64" %> | |
| 12 | + </a> | |
| 13 | + </div> | |
| 14 | +</div> | ... | ... |
app/views/projects/show.html.erb
| 1 | + | |
| 1 | 2 | <div class="page-header"> |
| 2 | - <h1><%= @project.name %></h1> | |
| 3 | + <div class="media"> | |
| 4 | + <a class="pull-left"> | |
| 5 | + <%= image_tag "#{@project_image}", size:"64x64" %> | |
| 6 | + </a> | |
| 7 | + <div class="media-body"> | |
| 8 | + <h4 class="media-heading"> | |
| 9 | + <h1 class="col-md-1"><%= @project.name %></h1> | |
| 10 | + </h4> | |
| 11 | + </div> | |
| 12 | + </div> | |
| 3 | 13 | </div> |
| 4 | 14 | |
| 5 | 15 | <p> |
| ... | ... | @@ -7,8 +17,6 @@ |
| 7 | 17 | <%= @project.description %> |
| 8 | 18 | </p> |
| 9 | 19 | |
| 10 | -<hr /> | |
| 11 | - | |
| 12 | 20 | <h2>Repositories</h2> |
| 13 | 21 | |
| 14 | 22 | <% if project_owner? @project.id %><%= link_to 'New Repository', new_project_repository_path(@project,), class: 'btn btn-primary' %><% end %> | ... | ... |
db/schema.rb
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | # |
| 12 | 12 | # It's strongly recommended that you check this file into your version control system. |
| 13 | 13 | |
| 14 | -ActiveRecord::Schema.define(version: 20140124124835) do | |
| 14 | +ActiveRecord::Schema.define(version: 20141009000324) do | |
| 15 | 15 | |
| 16 | 16 | create_table "mezuro_configuration_ownerships", force: true do |t| |
| 17 | 17 | t.integer "user_id" |
| ... | ... | @@ -20,6 +20,13 @@ ActiveRecord::Schema.define(version: 20140124124835) do |
| 20 | 20 | t.datetime "updated_at" |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | + create_table "project_images", force: true do |t| | |
| 24 | + t.integer "project_id" | |
| 25 | + t.string "image_url" | |
| 26 | + t.datetime "created_at" | |
| 27 | + t.datetime "updated_at" | |
| 28 | + end | |
| 29 | + | |
| 23 | 30 | create_table "project_ownerships", force: true do |t| |
| 24 | 31 | t.integer "user_id" |
| 25 | 32 | t.integer "project_id" |
| ... | ... | @@ -27,6 +34,10 @@ ActiveRecord::Schema.define(version: 20140124124835) do |
| 27 | 34 | t.datetime "updated_at" |
| 28 | 35 | end |
| 29 | 36 | |
| 37 | + create_table "projects", force: true do |t| | |
| 38 | + t.string "image_url" | |
| 39 | + end | |
| 40 | + | |
| 30 | 41 | create_table "reading_group_ownerships", force: true do |t| |
| 31 | 42 | t.integer "user_id" |
| 32 | 43 | t.integer "reading_group_id" | ... | ... |