Skip to content

Commit

Permalink
turbo changes and misc styling
Browse files Browse the repository at this point in the history
  • Loading branch information
puglet5 committed Jul 7, 2022
1 parent 55c95df commit 234d27f
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 107 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def update
def destroy
@user.destroy
flash[:success] = 'User was successfully deleted'
redirect_to admin_users_path
redirect_to admin_users_path, status: :see_other
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def update
# DELETE /categories/1
def destroy
@category.destroy
redirect_to categories_url, notice: 'Category was successfully deleted.'
redirect_to categories_url, notice: 'Category was successfully deleted.', status: :see_other
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Authorization
extend ActiveSupport::Concern

included do
include Pundit
include Pundit::Authorization

rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized

Expand Down
5 changes: 1 addition & 4 deletions app/controllers/discussions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ def update
# DELETE /discussions/1.json
def destroy
@discussion.destroy
respond_to do |format|
format.html { redirect_to discussions_url, notice: 'Discussion was successfully deleted.' }
format.json { head :no_content }
end
redirect_to discussions_url, notice: 'Discussion was successfully deleted.', status: :see_other
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/replies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def new; end
def destroy
@reply = @discussion.replies.find(params[:id])
@reply.destroy
redirect_to discussion_path(@discussion)
redirect_to discussion_path(@discussion), status: :see_other
end

def edit
Expand Down
36 changes: 15 additions & 21 deletions app/controllers/uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,26 @@ def edit; end
def create
@upload = current_user.uploads.build(upload_params)

respond_to do |format|
if @upload.save
flash[:success] = 'Upload was successfully created'
format.html { redirect_to @upload }
else
format.html { render :new, status: :unprocessable_entity }
end
if @upload.save
flash[:success] = 'Upload was successfully created'
redirect_to @upload
else
render :new, status: :unprocessable_entity
end
end

def update
@upload.user = current_user if @upload.user.nil?
respond_to do |format|
if @upload.update(upload_params.reject { |k| k['images'] })
if upload_params[:images].present?
upload_params[:images].each do |image|
@upload.images.attach(image)
end
if @upload.update(upload_params.reject { |k| k['images'] })
if upload_params[:images].present?
upload_params[:images].each do |image|
@upload.images.attach(image)
end
flash[:success] = 'Upload was successfully updated'
format.html { redirect_to @upload }
else
format.html { render :edit, status: :unprocessable_entity }
end
flash[:success] = 'Upload was successfully updated'
redirect_to @upload
else
render :edit, status: :unprocessable_entity
end
end

Expand All @@ -79,10 +75,8 @@ def update_status

def destroy
@upload.destroy
respond_to do |format|
flash[:success] = 'Upload was successfully deleted'
format.html { redirect_to uploads_url }
end
flash[:success] = 'Upload was successfully deleted'
redirect_to uploads_url, status: :see_other
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def auth_helper(tag_type, style = '', _active_class)
if user_signed_in?
auth_links << "<#{tag_type}>#{link_to 'Profile page', "/#{locale}/users/#{current_user.slug}", class: style.to_s}</#{tag_type}>"

auth_links << "<#{tag_type}>#{link_to t('auth.logout'), destroy_user_session_path, method: :delete, class: style}</#{tag_type}>"
auth_links << "<#{tag_type}>#{link_to t('auth.logout'), destroy_user_session_path, turbo_method: :delete, class: style}</#{tag_type}>"

else
auth_items.each do |item|
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/users/_user.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
<td><% user.roles.all.each do |role| %> <span><%= role.name %></span><% end %></td>
<td><%= time_ago_in_words(user.created_at) %> ago</td>
<td>
<%= link_to "Delete", admin_user_path(user), class: "button red", data: { method: :delete, confirm: "Are you sure?" } %></td>
<%= link_to "Delete", admin_user_path(user), class: "button red", data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %></td>
</tr>
3 changes: 1 addition & 2 deletions app/views/categories/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<h1>Categories</h1>
<table>
<thead>
Expand All @@ -13,7 +12,7 @@
<td><%= category.category_name %></td>
<td><%= link_to "Show", category %></td>
<td><%= link_to "Edit", edit_category_path(category) %></td>
<td><%= link_to "Delete", category, method: :delete, data: { confirm: "Are you sure?" }, class: "btn red" %></td>
<td><%= link_to "Delete", category, data: {turbo_method: :delete, turbo_confirm: "Are you sure?" }, class: "btn red" %></td>
</tr>
<% end %>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<% end %>
<!--
<h3>Cancel my account</h3>
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: {turbo_method: :delete, turbo_confirm: "Are you sure?" } %></p>
<%= link_to "Back", :back %>
-->
</div>
56 changes: 22 additions & 34 deletions app/views/discussions/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,46 +1,34 @@
<div class="row">

<div class="col s12 m4 l3"> <!-- Note that "m4 l3" was added -->

<%= render "sidebar" %>

</div>

<div class="col s12 m8 l9"> <!-- Note that "m8 l9" was added -->
<link href="https://vjs.zencdn.net/7.11.4/video-js.css" rel="stylesheet" />


<h1 class=""><%= @discussion.title %></h1>
<h3 class="">by <%= @discussion&.user.first_name %> in <%= link_to @discussion.category.category_name, @discussion.category %></h3>
<div class="">
<div class=""></div>
<h1 class=""><%= @discussion.title %></h1>
<h3 class="">by <%= @discussion&.user.first_name %> in <%= link_to @discussion.category.category_name, @discussion.category %></h3>
<div class="">
<div class=""></div>
<div class="">
<% if discussion_author(@discussion) %>
<div class="">
<% if discussion_author(@discussion) %>
<div class="">
<%= link_to "Edit Discussion", edit_discussion_path(@discussion), class: "button" %>
<%= link_to "Delete", discussion_path(@discussion), method: :delete, data: { confirm: "Delete discussion?" }, class: "btn red" %>
</div>
<% end %>
<%= link_to "Edit Discussion", edit_discussion_path(@discussion), class: "button" %>
<%= link_to "Delete", discussion_path(@discussion), data: {turbo_method: :delete, turbo_confirm: "Delete discussion?" }, class: "btn red" %>
</div>
</div>
<div class=""><%= @discussion.content %></div>
<h2 class=""><%= @discussion.replies.count %> Replies</h2>
<div id="discussion-replies">
<%= render @discussion.replies %>
</div>
<h3 class="">Leave a reply</h3>
<% if user_signed_in? %>
<%= render "replies/form" %>
<% else %>
<p>To reply you need to <%= link_to "login", new_user_session_path %>. Don't have an account?
<%= link_to "Sign up", new_user_registration_path %> for one.</p>
<% end %>

</div>
</div>
<div class=""><%= @discussion.content %></div>
<h2 class=""><%= @discussion.replies.count %> Replies</h2>
<div id="discussion-replies">
<%= render @discussion.replies %>
</div>
<h3 class="">Leave a reply</h3>
<% if user_signed_in? %>
<%= render "replies/form" %>
<% else %>
<p>To reply you need to <%= link_to "login", new_user_session_path %>. Don't have an account?
<%= link_to "Sign up", new_user_registration_path %> for one.</p>
<% end %>
<script src="https://vjs.zencdn.net/7.11.4/video.min.js"></script>

</div>

</div>



2 changes: 1 addition & 1 deletion app/views/kaminari/_gap.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<li class="">
<%= content_tag :a, raw(t "views.pagination.truncate"), class: "block py-2 px-3 leading-tight text-gray-500 bg-white rounded-r-lg border border-gray-300 hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white" %>
<%= content_tag :a, raw(t "views.pagination.truncate"), class: "block py-2 px-3 leading-tight text-gray-500 bg-white border border-gray-300 hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white" %>
</li>
44 changes: 22 additions & 22 deletions app/views/replies/_reply.html.erb
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<div class="">
<div class="">
<div class="">
<p>
<strong><%= reply.user&.first_name %></strong> <small><%= time_ago_in_words(reply.created_at) %></small>
<br/>
<%= reply.reply %>
</p>
</div>
<% if reply_author(reply) || has_role?(:admin) %>
<div class="">
<p>
<strong><%= reply.user&.first_name %></strong> <small><%= time_ago_in_words(reply.created_at) %></small>
<br/>
<%= reply.reply %>
</p>
<a class="">
<%= link_to edit_discussion_reply_path(reply.discussion, reply) do %>
edit comment
<% end %>
</a>
<br>
<a class="">
<%= link_to [reply.discussion, reply],
data: {turbo_method: :delete, turbo_confirm: "Are you sure ?" } do %>
delete comment
<% end %>
</a>
</div>
<% if reply_author(reply) || has_role?(:admin) %>
<div class="">
<a class="">
<%= link_to edit_discussion_reply_path(reply.discussion, reply) do %>
edit comment
<% end %>
</a>
<br>
<a class="">
<%= link_to [reply.discussion, reply],
method: :delete, data: { confirm: "Are you sure ?" } do %>
delete comment
<% end %>
</a>
</div>
<% end %>
</div>
<% end %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/shared/_application_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<span class="text-sm text-gray-500 sm:text-center dark:text-gray-400"><%= set_copyright %>
</span>
<a href="https://itmo.ru/" class="-m-4">
<%= image_tag "itmo_horiz_white_logo", class: "h-12", alt: "ITMO Logo" %>
<%= image_tag "itmo_horiz_white_logo.png", class: "h-12", alt: "ITMO Logo" %>
</a>
<ul class="flex flex-wrap items-center mt-3 text-sm text-gray-500 dark:text-gray-400 sm:mt-0">
<li>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_discussions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<% if discussion_author(discussion) || has_role?(:admin) %>
<div class="">
<%= link_to "Edit", edit_discussion_path(discussion), class: "" %>
<%= link_to "Delete", discussion, method: :delete, data: { confirm: "Are you sure?" }, class: "btn red" %>
<%= link_to "Delete", discussion, data: {turbo_method: :delete, turbo_confirm: "Are you sure?" }, class: "btn red" %>
</div>
<% end %>
</div>
Expand Down
1 change: 0 additions & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
require 'action_text/engine'
require 'action_view/railtie'
require 'action_cable/engine'
# require "sprockets/railtie"
# require 'rails/test_unit/railtie'

# Require the gems listed in Gemfile, including any gems
Expand Down
24 changes: 11 additions & 13 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

10.times do
user = User.create!(first_name: FFaker::Name.first_name,
last_name: FFaker::Name.last_name,
email: FFaker::Internet.email,
password: '123456')
last_name: FFaker::Name.last_name,
email: FFaker::Internet.email,
password: '123456')
user.save!
end

sample_user = User.create!(first_name: "Michael",
last_name: "Basmanov",
email: "puglet5@mail.ru",
password: '123456')
sample_user = User.create!(first_name: 'Michael',
last_name: 'Basmanov',
email: 'puglet5@mail.ru',
password: '123456')
sample_user.save!

Role.create!(name: 'admin')

sample_user.add_role("admin")
sample_user.add_role('admin')

PublicActivity.enabled = false

Expand All @@ -25,11 +25,9 @@
title = FFaker::Lorem.sentence
description = FFaker::Lorem.paragraph
body = FFaker::Lorem.paragraph
status = "draft"
status = 'draft'
users.each do |user|
up = Upload.create!(title: title, description: description, body: body, status: status, user_id: user.id)
up.thumbnail.attach(io: File.open(File.join(Rails.root,'public/images/rose.jpg')), filename: 'rose.jpg')
up = Upload.create!(title: title, description: description, body: body, status: status, user_id: user.id)
up.thumbnail.attach(io: File.open(File.join(Rails.root, 'public/images/rose.jpg')), filename: 'rose.jpg')
end
end


0 comments on commit 234d27f

Please sign in to comment.