Layout improvements and mission cover image uploader

jamesperet 10 年之前
父节点
当前提交
ec2d29c3a0

+ 1 - 0
Gemfile

@@ -55,6 +55,7 @@ gem 'redcarpet'
55 55
 gem 'summernote-rails'
56 56
 gem 'figaro'
57 57
 gem "mini_magick"
58
+gem "rmagick"
58 59
 gem 'fog'
59 60
 gem "carrierwave"
60 61
 gem 'carrierwave_backgrounder'

+ 2 - 0
Gemfile.lock

@@ -212,6 +212,7 @@ GEM
212 212
       redis-namespace (~> 1.0)
213 213
       sinatra (>= 0.9.2)
214 214
       vegas (~> 0.1.2)
215
+    rmagick (2.13.4)
215 216
     rspec (3.1.0)
216 217
       rspec-core (~> 3.1.0)
217 218
       rspec-expectations (~> 3.1.0)
@@ -333,6 +334,7 @@ DEPENDENCIES
333 334
   redis
334 335
   rename
335 336
   resque (~> 1.22.0)
337
+  rmagick
336 338
   rspec
337 339
   rspec-rails
338 340
   sass-rails

+ 7 - 3
app/assets/javascripts/missions.js.coffee

@@ -1,3 +1,7 @@
1
-# Place all the behaviors and hooks related to the matching controller here.
2
-# All this logic will automatically be available in application.js.
3
-# You can use CoffeeScript in this file: http://coffeescript.org/
1
+# Missions JS
2
+
3
+attachRatingHandler = ->
4
+
5
+    
6
+$(document).ready attachRatingHandler
7
+$(document).on "page:load", attachRatingHandler

+ 4 - 0
app/controllers/agents_controller.rb

@@ -6,5 +6,9 @@ class AgentsController < ApplicationController
6 6
   def list
7 7
     @users = User.all
8 8
   end
9
+  
10
+  def show
11
+    @user = User.find_by_id(params[:id])
12
+  end
9 13
 
10 14
 end

+ 4 - 0
app/models/mission.rb

@@ -1,9 +1,13 @@
1 1
 class Mission < ActiveRecord::Base
2
+  
2 3
   belongs_to :owner, :class_name => "User"
3 4
   has_many :mission_agents, :dependent => :destroy
4 5
   has_many :agent_steps, :through => :mission_agents
5 6
   accepts_nested_attributes_for :mission_agents, allow_destroy:true
6 7
   
8
+  mount_uploader :cover_img, MissionCoverUploader
9
+  process_in_background :cover_img
10
+  
7 11
   def agent_position_count
8 12
     return self.mission_agents.count
9 13
   end

+ 79 - 0
app/uploaders/mission_cover_uploader.rb

@@ -0,0 +1,79 @@
1
+# encoding: utf-8
2
+
3
+class MissionCoverUploader < CarrierWave::Uploader::Base
4
+
5
+  # Include RMagick or MiniMagick support:
6
+  include CarrierWave::RMagick
7
+  # include CarrierWave::MiniMagick
8
+  include CarrierWave::MimeTypes
9
+  
10
+  include ::CarrierWave::Backgrounder::Delay
11
+
12
+  # Choose what kind of storage to use for this uploader:
13
+  
14
+  if Rails.env.test? or Rails.env.cucumber?
15
+      storage :file
16
+  end
17
+
18
+  if Rails.env.development?
19
+      storage :file
20
+  end
21
+
22
+  if Rails.env.production?
23
+      # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility if using fog: 
24
+      # include Sprockets::Rails::Helper
25
+      include Sprockets::Helpers  
26
+      storage :fog
27
+  end
28
+  
29
+  process :set_content_type
30
+
31
+  # Override the directory where uploaded files will be stored.
32
+  # This is a sensible default for uploaders that are meant to be mounted:
33
+  def store_dir
34
+    "uploads/#{mounted_as}/#{model.id}"
35
+  end
36
+  
37
+  def root
38
+    "#{Rails.root}/public"
39
+  end
40
+  
41
+  def cache_dir
42
+    "#{Rails.root}/tmp/uploads/#{mounted_as}/"
43
+  end
44
+
45
+  # Provide a default URL as a default if there hasn't been a file uploaded:
46
+  # def default_url
47
+  #   # For Rails 3.1+ asset pipeline compatibility:
48
+  #   # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
49
+  #
50
+  #   "/images/fallback/" + [version_name, "default.png"].compact.join('_')
51
+  # end
52
+
53
+  # Process files as they are uploaded:
54
+  # process :scale => [200, 300]
55
+  #
56
+  # def scale(width, height)
57
+  #   # do something
58
+  # end
59
+
60
+  # Create different versions of your uploaded files:
61
+
62
+  version :feature do 
63
+    process :convert => 'jpg'
64
+    process :resize_to_fill => [1200, 780, gravity = ::Magick::CenterGravity]
65
+  end 
66
+  
67
+  version :thumb do 
68
+    process :convert => 'jpg' 
69
+    process :resize_to_fill => [400, 300, gravity = ::Magick::CenterGravity]
70
+  end 
71
+
72
+  # Add a white list of extensions which are allowed to be uploaded.
73
+  # For images you might use something like this:
74
+  def extension_white_list
75
+    %w(jpg jpeg gif png)
76
+  end
77
+
78
+
79
+end

+ 14 - 0
app/views/agents/show.html.erb

@@ -0,0 +1,14 @@
1
+<%= content_tag(:div, class: 'container top-container') do %>
2
+	<%= content_tag(:div, class: 'row') do %>
3
+		<%= content_tag(:div, class: 'span12') do %>
4
+			<% # Page Content %>
5
+			<%= bootstrap_flash %>
6
+			<%= content_tag(:div, class: 'page-header page-header-type') do %>
7
+				<%= content_tag(:small, (t 'mission.agent')+':') %>
8
+				<%= content_tag(:h1) do %>
9
+					<%=  @user.full_name %>
10
+				<% end %>
11
+			<% end %>
12
+		<% end %>
13
+	<% end %>
14
+<% end %>

+ 13 - 4
app/views/blog_posts/edit.html.erb

@@ -1,6 +1,15 @@
1 1
 <% title (t 'blog.edit_post') + ' - ' + @blog_post.title %>
2
-<div class="page-header">
3
-  <h1><%= t "blog.edit_post" %></h1>
4
-</div>
5 2
 
6
-<%= render 'form' %>
3
+<%= content_tag(:div, class: 'container top-container container-last') do %>
4
+	<%= content_tag(:div, class: 'row') do %>
5
+		<%= content_tag(:div, class: 'span12') do %>
6
+
7
+			<div class="page-header">
8
+			  <h1><%= t "blog.edit_post" %></h1>
9
+			</div>
10
+
11
+			<%= render 'form' %>
12
+			
13
+		<% end %>
14
+	<% end %>		
15
+<% end %>

+ 13 - 4
app/views/blog_posts/new.html.erb

@@ -1,6 +1,15 @@
1 1
 <% title (t "blog.new_post") + ' - ' + @config.website_name %>
2
-<div class="page-header">
3
-  <h1><%= t "blog.new_post" %></h1>
4
-</div>
5 2
 
6
-<%= render 'form' %>
3
+<%= content_tag(:div, class: 'container top-container container-last') do %>
4
+	<%= content_tag(:div, class: 'row') do %>
5
+		<%= content_tag(:div, class: 'span12') do %>
6
+
7
+			<div class="page-header">
8
+			  <h1><%= t "blog.new_post" %></h1>
9
+			</div>
10
+
11
+			<%= render 'form' %>
12
+			
13
+		<% end %>
14
+	<% end %>		
15
+<% end %>

+ 1 - 0
app/views/layouts/_navigation_links.html.erb

@@ -17,6 +17,7 @@
17 17
 				<% if current_user.admin %>
18 18
 					<li><%= link_to (t "nav.admin_panel"), admin_dashboard_path, :id => 'navlink_admin_panel' %></li>
19 19
 				<% end %>
20
+				<li><%= link_to (t "nav.profile"), show_agent_path(current_user) %></li>
20 21
 	  			<li><%= link_to (t "nav.account"), edit_user_registration_path %></li>
21 22
 	  			<li><%= link_to (t "nav.logout"), destroy_user_session_path, method: :delete %></li>
22 23
 			</ul>

+ 14 - 11
app/views/missions/_form.html.erb

@@ -1,16 +1,19 @@
1
-<%= simple_form_for(@mission) do |f| %>
2
-  <%= f.error_notification %>
1
+<%= bootstrap_form_for(@mission) do |f| %>
2
+  <%= f.alert_message "Please fix the errors below." %>
3 3
 
4 4
   <div class="form-inputs">
5
-    <%= f.association :mission_agents %>
6
-    <%= f.input :title %>
7
-    <%= f.input :objective %>
8
-    <%= f.input :briefing %>
9
-    <%= f.association :owner %>
10
-    <%= f.input :status %>
11
-    <%= f.input :launched %>
12
-    <%= f.input :language %>
13
-    <%= f.input :cover_img %>
5
+    <%= f.text_field :title %>
6
+    <%= f.text_field :objective %>
7
+    <%= f.text_area :briefing %>
8
+    <%= f.text_field :language %>
9
+		<div class="fileupload fileupload-new" data-provides="fileupload" style="margin-top: 5px;">
10
+			<div class="fileupload-preview thumbnail" data-trigger="fileinput" style="width: 230px; height: 145px;"><%=  image_tag @mission.cover_img.to_s if @mission.cover_img? %></div>
11
+			<span class="btn btn-default btn-file btn-mini" >
12
+				<span class="fileinput-new"></span>
13
+				<span class="fileinput-exists"></span>
14
+				<%= f.file_field :cover_img, class: 'hidden', label: (t 'blog.select_image') %>
15
+			</span>
16
+		</div>
14 17
   </div>
15 18
 
16 19
   <div class="form-actions">

+ 3 - 1
app/views/missions/_mission_box.html.erb

@@ -1,6 +1,8 @@
1 1
 <%= content_tag(:li, class: 'span4') do %>
2 2
 	<% content_tag(:div, class: 'thumbnail') do %>
3
-		<%= image_tag('http://placehold.it/400x300')%>
3
+		<%= link_to mission_path(mission) do %>
4
+			<%= mission.cover_img? ? (image_tag mission.cover_img.thumb, size: '400x300') : image_tag('http://placehold.it/400x300') %>
5
+		<% end %>
4 6
 		<%= content_tag(:div, class: 'thumbnail-content') do%>
5 7
 	          <%= content_tag(:h3, link_to(mission.title, mission)) %>
6 8
 			<%= content_tag(:p, mission.owner.full_name, class: 'mission-director-name') %>

+ 10 - 5
app/views/missions/_mission_details.html.erb

@@ -17,11 +17,16 @@
17 17
 			<% end %>
18 18
 		<% end %>
19 19
 		<%= content_tag(:div, class: 'row') do %>
20
-			<%= content_tag(:div, class: 'span8') do %>	
21
-				<div class="videoWrapper">
22
-				    <!-- Copy & Pasted from YouTube -->
23
-				    <iframe width="1280" height="720" src="https://www.youtube.com/embed/DvLYOcXUYgU?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
24
-				</div>
20
+			<%= content_tag(:div, class: 'span8') do %>
21
+				<% youtube_video = false %>
22
+				<% if youtube_video == true %>
23
+					<div class="videoWrapper">
24
+					    <!-- Copy & Pasted from YouTube -->
25
+					    <iframe width="1280" height="720" src="https://www.youtube.com/embed/DvLYOcXUYgU?rel=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe>
26
+					</div>
27
+				<% else %>
28
+					<%= mission.cover_img? ? (image_tag mission.cover_img.feature) : image_tag('http://placehold.it/1200x780') %>
29
+				<% end %>
25 30
 			<% end %>
26 31
 			<%= content_tag(:div, class: 'span4 mission-stats') do %>
27 32
 				<%= content_tag(:span,'145', class: 'mission-timer timer-large') %>

+ 20 - 3
app/views/missions/edit.html.erb

@@ -1,6 +1,23 @@
1 1
 <h1>Editing mission</h1>
2 2
 
3
-<%= render 'form' %>
3
+<%= content_tag(:div, class: 'container top-container container-last') do %>
4
+	<%= content_tag(:div, class: 'row') do %>
5
+		<%= content_tag(:div, class: 'span12') do %>
4 6
 
5
-<%= link_to 'Show', @mission %> |
6
-<%= link_to 'Back', missions_path %>
7
+			<%= content_tag(:div, class: 'page-header page-header-type') do %>
8
+				<%= content_tag(:small, (t 'mission.edit_mission')+':') %>
9
+				<%= content_tag(:h1) do %>
10
+					<%=  @mission.title %>
11
+					<%= link_to (t 'nav.back'), missions_path, class: 'btn btn-mini' %>
12
+					<%= status(@mission.status) %>
13
+				<% end %>
14
+			<% end %>
15
+
16
+			<%= render 'form' %>
17
+
18
+			<%= link_to 'Show', @mission %> |
19
+			<%= link_to 'Back', missions_path %>
20
+			
21
+		<% end %>
22
+	<% end %>		
23
+<% end %>

+ 3 - 1
app/views/missions/index.html.erb

@@ -16,7 +16,9 @@
16 16
 
17 17
 			<%= content_tag(:div, class: 'row-fluid box') do %>
18 18
 				<%= content_tag(:div, class: 'span8') do %>
19
-					<%= image_tag('http://placehold.it/1200x780')%>
19
+					<%= link_to mission_path(@featured_missions) do %>
20
+						<%= @featured_missions.cover_img? ? (image_tag @featured_missions.cover_img.feature) : image_tag('http://placehold.it/1200x780') %>
21
+					<% end %>
20 22
 				<% end %>
21 23
 				<%= content_tag(:div, class: 'span4') do %>
22 24
 					<%= content_tag(:div, class: 'box-content') do%>

+ 17 - 4
app/views/missions/new.html.erb

@@ -1,5 +1,18 @@
1
-<h1>New mission</h1>
1
+<%= content_tag(:div, class: 'container top-container container-last') do %>
2
+	<%= content_tag(:div, class: 'row') do %>
3
+		<%= content_tag(:div, class: 'span12') do %>
4
+			
5
+			<%= content_tag(:div, class: 'page-header') do %>
6
+				<%= content_tag(:h1) do %>
7
+					<%= t 'mission.create_mission' %> 
8
+					<%= link_to (t 'nav.back'), missions_path, class: 'btn btn-mini' %>
9
+				<% end %>
10
+			<% end %>
11
+			
12
+			<%= render 'form' %>
2 13
 
3
-<%= render 'form' %>
4
-
5
-<%= link_to 'Back', missions_path %>
14
+			<%= link_to 'Back', missions_path %>
15
+			
16
+		<% end %>
17
+	<% end %>		
18
+<% end %>

+ 8 - 2
config/initializers/redis.rb

@@ -1,2 +1,8 @@
1
-uri = URI.parse(ENV["REDISTOGO_URL"])
2
-REDIS_WORKER = Redis.new(host: uri.host, port: uri.port, password: uri.password)
1
+if Rails.env.production? || Rails.env.test?
2
+  uri = URI.parse('http://localhost:6379')
3
+  REDIS_WORKER = Redis.new(host: uri.host, port: uri.port)
4
+else
5
+  uri = URI.parse(ENV["REDISTOGO_URL"])
6
+  REDIS_WORKER = Redis.new(host: uri.host, port: uri.port, password: uri.password)
7
+end
8
+

+ 3 - 2
config/routes.rb

@@ -29,8 +29,9 @@ Avalanche2::Application.routes.draw do
29 29
   get 'missions/:id/agents/:agent/take_agent_role', to: 'missions#take_agent_role', as: :take_agent_role
30 30
   
31 31
   # Agents
32
-  get 'dashboard', to: 'agents#dashboard', as: :dashboard
33
-  get 'agents', to: 'agents#list', as: :agent_list
32
+  get 'dashboard' => 'agents#dashboard', as: :dashboard
33
+  get 'agents' => 'agents#list', as: :agent_list
34
+  get 'agent/:id' => 'agents#show', as: :show_agent
34 35
 
35 36
   # Admin Panel
36 37
   get "admin/dashboard" => "admin_panel#dashboard", :as => :admin_dashboard

+ 2 - 2
config/unicorn.rb

@@ -1,8 +1,8 @@
1 1
 # config/unicorn.rb
2 2
  
3 3
 # See comment by @paulelliott
4
-worker_processes 3
5
-timeout 30
4
+worker_processes 2
5
+timeout 45
6 6
 preload_app true
7 7
  
8 8
 before_fork do |server, worker|