initial profile comments

This commit is contained in:
Kyle Drake 2014-04-29 01:17:17 -07:00
parent 44311e4008
commit 5bc66e2524
11 changed files with 92 additions and 16 deletions

17
app.rb
View file

@ -70,7 +70,22 @@ end
get '/profile/:sitename' do |sitename| get '/profile/:sitename' do |sitename|
@title = "#{sitename}.neocities.org" @title = "#{sitename}.neocities.org"
site = Site[username: sitename] site = Site[username: sitename]
erb :'profile', locals: {site: site} erb :'profile', locals: {site: site, is_current_site: site == current_site}
end
post '/profile/:sitename/comment' do |sitename|
require_login
site = Site[username: sitename]
DB.transaction do
site.add_profile_comment(
actioning_site_id: current_site.id,
message: params[:message]
)
end
redirect "/profile/#{sitename}"
end end
get '/tags_mockup' do get '/tags_mockup' do

View file

@ -0,0 +1,9 @@
Sequel.migration do
up {
DB.rename_table :changes, :site_changes
}
down {
DB.drop_column :site_changes, :changes
}
end

View file

@ -0,0 +1,19 @@
Sequel.migration do
up {
DB.rename_column :events, :comment_id, :profile_comment_id
DB.create_table! :profile_comments do
primary_key :id
Integer :site_id
Integer :actioning_site_id
Text :message
DateTime :created_at
DateTime :updated_at
end
}
down {
DB.rename_column :events, :profile_comment_id, :comment_id
DB.drop_table :profile_comments
}
end

View file

@ -1,3 +0,0 @@
class Change < Sequel::Model
many_to_one :site
end

View file

@ -1,9 +1,9 @@
class Event < Sequel::Model class Event < Sequel::Model
many_to_one :site many_to_one :site
many_to_one :follow one_to_one :follow
many_to_one :tip one_to_one :tip
many_to_one :tag one_to_one :tag
many_to_one :changes one_to_one :site_change
many_to_one :profile_comment
one_to_many :likes one_to_many :likes
one_to_many :comments
end end

View file

@ -0,0 +1,9 @@
class ProfileComment < Sequel::Model
one_to_one :event
many_to_one :site
many_to_one :actioning_site, :class => :Site
def after_create
self.event = Event.create site_id: site.id
end
end

View file

@ -52,6 +52,7 @@ class Site < Sequel::Model
LOSSLESS_IMAGE_REGEX = /png|bmp|gif/ LOSSLESS_IMAGE_REGEX = /png|bmp|gif/
LOSSY_IMAGE_REGEX = /jpg|jpeg/ LOSSY_IMAGE_REGEX = /jpg|jpeg/
HTML_REGEX = /htm|html/ HTML_REGEX = /htm|html/
MAX_COMMENT_SIZE = 420 # Used to be the limit for Facebook.. no comment (PUN NOT INTENDED).
SCREENSHOT_RESOLUTIONS = ['235x141', '105x63', '270x162', '37x37', '146x88', '302x182', '90x63', '82x62'] SCREENSHOT_RESOLUTIONS = ['235x141', '105x63', '270x162', '37x37', '146x88', '302x182', '90x63', '82x62']
THUMBNAIL_RESOLUTIONS = ['105x63'] THUMBNAIL_RESOLUTIONS = ['105x63']
@ -60,6 +61,9 @@ class Site < Sequel::Model
many_to_many :tags many_to_many :tags
one_to_many :profile_comments
one_to_many :profile_commentings, key: :actioning_site_id, class: :ProfileComment
one_to_many :follows one_to_many :follows
one_to_many :followings, key: :actioning_site_id, class: :Follow one_to_many :followings, key: :actioning_site_id, class: :Follow
@ -73,7 +77,7 @@ class Site < Sequel::Model
one_to_many :events one_to_many :events
one_to_many :changes one_to_many :site_changes
class << self class << self
def valid_login?(username, plaintext) def valid_login?(username, plaintext)

4
models/site_change.rb Normal file
View file

@ -0,0 +1,4 @@
class SiteChange < Sequel::Model
many_to_one :site
one_to_one :event
end

View file

@ -1,3 +1,11 @@
<% events.each do |event| %>
<% if event.profile_comment_id %>
<%== erb :'_news_profile_comment', layout: false, locals: {event: event} %>
<% end %>
<% end %>
<!--
<div class="news-item follow"> <div class="news-item follow">
<div class="title"> <div class="title">
<div class="icon"></div> <div class="icon"></div>
@ -92,3 +100,4 @@
<div class="actions"><a href="">Like (1)</a> <a href="">Reply</a></div> <div class="actions"><a href="">Like (1)</a> <a href="">Reply</a></div>
</div> </div>
</div> </div>
-->

View file

@ -0,0 +1,8 @@
<div class="news-item comment for-me">
<div class="title">
<div class="icon" style="background-image:url(https://neocities.org/site_screenshots/codeventurer.jpg);"></div>
<a href="" class="user">Foo</a>
<span class="date"><%= event.profile_comment.created_at.ago %></span>
<div class="comment"><%= event.profile_comment.message %></div>
</div>
</div>

View file

@ -29,10 +29,12 @@
<div class="container"> <div class="container">
<div class="content misc-page columns right-col"><div class="col-left"> <div class="content misc-page columns right-col"><div class="col-left">
<div class="col col-66"> <div class="col col-66">
<div class="post-comment"> <div class="post-comment">
<input class="" type="text" placeholder="Post on Derp's profile..."> <form method="POST" action="/profile/<%= site.username %>/comment">
<a href="" class="btn-Action">Post</a> <input name="csrf_token" type="hidden" value="<%= csrf_token %>">
<input name="message" type="text" placeholder="Post a message..." maxlength="<%= Site::MAX_COMMENT_SIZE %>">
<button class="btn-Action">Post</button>
</form>
</div> </div>
<% if site.latest_events.empty? %> <% if site.latest_events.empty? %>
@ -40,7 +42,7 @@
<p>No activity yet.</p> <p>No activity yet.</p>
</div> </div>
<% else %> <% else %>
<%= erb :'_profile_news', layout: false, locals: {events: events} %> <%== erb :'_news', layout: false, locals: {site: site, events: site.events} %>
<% end %> <% end %>
</div> </div>