Skip to content

Commit

Permalink
Add queueimage show and progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyMorugin committed Dec 22, 2015
1 parent 04ba71b commit 19b6cd0
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 48 deletions.
24 changes: 24 additions & 0 deletions app/assets/stylesheets/custom.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -664,3 +664,27 @@ aside {
border-radius: 15px; /* закругление углов для всех, кто понимает */
padding: 2px;
}

.progressBar {
height: 20px; /* Can be anything */
position: relative;
background: #555;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
border-radius: 25px;
//padding: 10px;
box-shadow: inset 0 -1px 1px rgba(255,255,255,0.3);
span {
display: block;
height: 20px;
border-top-right-radius: 8px;
border-bottom-right-radius: 8px;
border-top-left-radius: 20px;
border-bottom-left-radius: 20px;
//background-color: rgb(43,194,83);
//position: relative;
//overflow: hidden;
background-color: #f1a165;
background-image: linear-gradient(to bottom, #f1a165, #f36d0a);
}
}
2 changes: 1 addition & 1 deletion app/controllers/queue_images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def index
# GET /queue_images/1
# GET /queue_images/1.json
def show

authorize @queue_image
end

# GET /queue_images/new
Expand Down
3 changes: 2 additions & 1 deletion app/jobs/image_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ImageJob
@hostname = "localhost"
@username = "root"
@password = "123"
@remote_neural_path = "~/neural-style-master"
@remote_neural_path = "~/neural-style"
@iteration_count = 10
@local_tmp_path = '~/tmp/output'
@worker_name = :server1
Expand Down Expand Up @@ -301,6 +301,7 @@ def wait_images(item)
sleep 2
download_n_save_result(iter,item)
iter += 1
item.update(progress: iter/@iteration_count*100)
next
end
end
Expand Down
1 change: 1 addition & 0 deletions app/models/client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Client < ActiveRecord::Base
include ConstHelper
has_many :queue_images
has_many :likes
mount_uploader :avatar, AvatarUploader
# Include default devise modules. Others available are:
# :, :lockable, :timeoutable and :omniauthable :confirmable,
Expand Down
2 changes: 2 additions & 0 deletions app/models/like.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
class Like < ActiveRecord::Base
belongs_to :queue_image
belongs_to :client
end
1 change: 1 addition & 0 deletions app/models/queue_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class QueueImage < ActiveRecord::Base
belongs_to :client
belongs_to :content
belongs_to :style
has_many :likes, foreign_key: "queue_id"
#mount_uploader :content_image, AvatarUploader
#mount_uploader :style_image, AvatarUploader
scope :last_n_days, lambda {|d| where('ftime > ?' , Time.now - d.days)}
Expand Down
2 changes: 1 addition & 1 deletion app/policies/queue_image_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def index?
# GET /queue_images/1
# GET /queue_images/1.json
def show?
false
!user.nil? && user.admin?
end

# GET /queue_images/new
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin_pages/_item_view_4.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
<span class="textAboutStyle"><%= item.client.email if !item.client.nil? %></span>
<span class="textAboutStyle"><%= (item.created_at+10800).strftime("%d.%m.%Y %H:%M:%S")%></span><br>
<span class="textAboutStyle"><%= "like: #{Like.where(queue_id: item.id).count}" %></span>

<div id="qi_status_<%= item.id %>">
<span class="textAboutStyle"><%= get_queue_item_status(item) %></span>
</div>
<%= link_to 'SHOW', queue_image_path(item) %><br>
</div>

</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="container">
<div class="row">
<div class="col-lg-offset-4 col-lg-4 col-md-12 col-sm-12 col-xs-12">

<p> Все поля являются обязательными для заполнения!</p>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>

Expand Down
2 changes: 2 additions & 0 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<li><%= link_to "Admin", admin_pages_main_path %></li>
<% end %>
<% if client_signed_in? %>

<li><%= link_to "Добавить изображения", new_queue_image_path, class: "btn btn-primary" %></li>

<li><%= link_to "Моя коллекция", queue_images_path %></li>
<% end %>
<li><%= link_to "Лента", lenta_path %></li>
Expand Down
12 changes: 8 additions & 4 deletions app/views/queue_images/_item_view_3.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@
</div>

<div class=" col-lg-2 col-md-2 col-sm-3 col-xs-3 ">
<span class="textAboutStyle"><p><%= (item.created_at+10800).strftime("%d.%m.%Y %H:%M:%S")%></p> </span>
<span class="textAboutStyle"><%= get_queue_item_status(item) %></span>
<br>
<span class="textAboutStyle"><%= (item.created_at+10800).strftime("%d.%m.%Y %H:%M:%S")%></span><br>
<span class="textAboutStyle"><%= get_queue_item_status(item) %></span><br>
<span class="textAboutStyle">
<br>
<% if policy(item).destroy? %>
<%= link_to "УДАЛИТЬ", item, method: :delete, data: { confirm: "Вы точно хотите удалить?" } %>
<% end %><br>
Expand All @@ -47,7 +45,13 @@
<% if policy(item).visible? %>
<%= link_to "ПОКАЗАТЬ", "/queue_images/#{item.id}/visible", method: :put %>
<% end %>

</span>
<% if item.status == ConstHelper::STATUS_IN_PROCESS %>
<div class="progressBar">
<span style="width: <%= item.progress.to_i%>%"></span>
</div>
<% end %>
</div>

</div>
Expand Down
100 changes: 67 additions & 33 deletions app/views/queue_images/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,34 +1,68 @@
<p id="notice"><%= notice %></p>

<p>
<strong>User:</strong>
<%= @queue_image.user_id %>
</p>

<p>
<strong>Content image:</strong>
<%= @queue_image.content_image %>
</p>

<p>
<strong>Style image:</strong>
<%= @queue_image.style_image %>
</p>

<p>
<strong>Init str:</strong>
<%= @queue_image.init_str %>
</p>

<p>
<strong>Status:</strong>
<%= @queue_image.status %>
</p>

<p>
<strong>Result:</strong>
<%= @queue_image.result %>
</p>

<%= link_to 'Edit', edit_queue_image_path(@queue_image) %> |
<%item = @queue_image %>
<%res_img = item.result_image %>

<%= link_to 'Back', queue_images_path %>
<div class="container">
<div class="row styleRow2-lg">

<div class="col-lg-2 col-md-2 col-sm-3 col-xs-3 userAvatarStyle-lg" >
<%= link_to(image_tag(item.content.image.thumb200.url, alt:item.content.image, class: "imagesStyle"), item.content.image.url, class: "imagesStyle") %>
</div>
<div class="col-lg-2 col-md-2 col-sm-3 col-xs-3 userAvatarStyle-lg">
<%= link_to(image_tag(item.style.image.thumb200.url, alt:item.style.image, class: "imagesStyle"), item.style.image.url, class: "imagesStyle") %>
</div>

<div class="col-lg-2 col-md-2 col-sm-3 col-xs-3 userAvatarStyle-lg">
<div class="" >
<%= link_to(image_tag(res_img.imageurl.thumb400.url, alt:res_img.imageurl, class: "imagesStyle"), res_img.imageurl.url, class: "imagesStyle") if res_img %>
</div>
</div>

<div class=" col-lg-2 col-md-2 col-sm-3 col-xs-3 ">
<span class="textAboutStyle"><%= item.client.email if !item.client.nil? %></span>
<span class="textAboutStyle"><%= (item.created_at+10800).strftime("%d.%m.%Y %H:%M:%S")%></span><br>
<span class="textAboutStyle"><%= "like: #{Like.where(queue_id: item.id).count} #{item.likes_count}" %></span>

<div id="qi_status_<%= item.id %>">
<span class="textAboutStyle"><%= get_queue_item_status(item) %></span>
</div>

</div>

</div>

<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<%= item.init_str if !item.init_str.blank? %>
</div>
</div>

<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<%= render partial: 'admin_pages/statuses', :locals => {item: item} %>
</div>
</div>

<div class="row">
<br>Likes:<br>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 userAvatarStyle-lg ">

<% item.likes.each do |il| %>
<%= il.client.email %><br>

<% end %>
</div>
</div>

<div class="row">
<% item.pimages.each do |pi| %>
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-4 userAvatarStyle-lg ">
<%= link_to(image_tag(pi.imageurl.url, alt:pi.imageurl, class: "imagesStyle"), pi.imageurl.url, class: "imagesStyle")%>
</div>
<% end %>
</div>


</div>


5 changes: 5 additions & 0 deletions db/migrate/20151222172729_add_progress_to_queue_images.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddProgressToQueueImages < ActiveRecord::Migration
def change
add_column :queue_images, :progress, :float, default: 0
end
end
15 changes: 8 additions & 7 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20151207202330) do
ActiveRecord::Schema.define(version: 20151222172729) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -70,19 +70,20 @@
end

create_table "queue_images", force: :cascade do |t|
t.integer "client_id", null: false
t.integer "client_id", null: false
t.string "init_str", default: ""
t.integer "status", default: 0
t.string "result", default: ""
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.time "ptime"
t.datetime "stime"
t.datetime "ftime"
t.integer "style_id", default: 0, null: false
t.integer "content_id", default: 0, null: false
t.integer "end_status", default: 11, null: false
t.integer "style_id", default: 0, null: false
t.integer "content_id", default: 0, null: false
t.integer "end_status", default: 11, null: false
t.integer "likes_count", default: 0
t.float "progress", default: 0.0
end

create_table "styles", force: :cascade do |t|
Expand Down

0 comments on commit 19b6cd0

Please sign in to comment.