implement education version of Neocities

This commit is contained in:
Kyle Drake 2015-05-09 22:16:15 -07:00
parent c5d62b19a3
commit 977ba19610
12 changed files with 91 additions and 49 deletions

View file

@ -1,6 +1,16 @@
get '/browse/?' do get '/browse/?' do
@current_page = params[:current_page]
@current_page = @current_page.to_i
@current_page = 1 if @current_page == 0
params.delete 'tag' if params[:tag].nil? || params[:tag].strip.empty? params.delete 'tag' if params[:tag].nil? || params[:tag].strip.empty?
site_dataset = browse_sites_dataset
if is_education?
site_dataset = education_sites_dataset
else
site_dataset = browse_sites_dataset
end
site_dataset = site_dataset.paginate @current_page, Site::BROWSE_PAGINATION_LENGTH site_dataset = site_dataset.paginate @current_page, Site::BROWSE_PAGINATION_LENGTH
@page_count = site_dataset.page_count || 1 @page_count = site_dataset.page_count || 1
@sites = site_dataset.all @sites = site_dataset.all
@ -10,11 +20,14 @@ get '/browse/?' do
erb :browse erb :browse
end end
def browse_sites_dataset def education_sites_dataset
@current_page = params[:current_page] site_dataset = Site.filter is_deleted: false
@current_page = @current_page.to_i site_dataset = site_dataset.association_join(:tags).select_all(:sites)
@current_page = 1 if @current_page == 0 params[:tag] = current_site.tags.first.name
site_dataset.where! ['tags.name = ?', params[:tag]]
end
def browse_sites_dataset
site_dataset = Site.filter(is_deleted: false, is_banned: false, is_crashing: false).filter(site_changed: true) site_dataset = Site.filter(is_deleted: false, is_banned: false, is_crashing: false).filter(site_changed: true)
if current_site if current_site

View file

@ -2,6 +2,8 @@ get '/?' do
if current_site if current_site
require_login require_login
redirect '/dashboard' if current_site.is_education
@suggestions = current_site.suggestions @suggestions = current_site.suggestions
@current_page = params[:current_page].to_i @current_page = params[:current_page].to_i

View file

@ -9,6 +9,8 @@ get '/site/:username/?' do |username|
# TODO: There should probably be a "this site was deleted" page. # TODO: There should probably be a "this site was deleted" page.
not_found if site.nil? || site.is_banned || site.is_deleted not_found if site.nil? || site.is_banned || site.is_deleted
redirect '/' if site.is_education
@title = site.title @title = site.title
@current_page = params[:current_page] @current_page = params[:current_page]

View file

@ -15,6 +15,10 @@ def csrf_token
session[:_csrf_token] ||= SecureRandom.base64(32) session[:_csrf_token] ||= SecureRandom.base64(32)
end end
def is_education?
current_site && current_site.is_education
end
def require_login def require_login
redirect '/' unless signed_in? redirect '/' unless signed_in?
if session[:banned] || current_site.is_banned || parent_site.is_banned if session[:banned] || current_site.is_banned || parent_site.is_banned

View file

@ -30,7 +30,7 @@ describe 'signup' do
it 'succeeds with valid data' do it 'succeeds with valid data' do
fill_in_valid fill_in_valid
click_button 'Create My Site' click_button 'Create My Site'
page.must_have_content 'Welcome to Neocities' page.must_have_content /Welcome to your new site/
index_file_path = File.join Site::SITE_FILES_ROOT, @site[:username], 'index.html' index_file_path = File.join Site::SITE_FILES_ROOT, @site[:username], 'index.html'
File.exist?(index_file_path).must_equal true File.exist?(index_file_path).must_equal true

View file

@ -10,9 +10,11 @@
<ul class="tiny h-Nav"> <ul class="tiny h-Nav">
<li><a href="/about">About</a></li> <li><a href="/about">About</a></li>
<li><a href="/donate">Donate</a></li> <li><a href="/donate">Donate</a></li>
<li><a href="/blog">Blog</a></li> <% unless is_education? %>
<li><a href="/api">API</a></li> <li><a href="/blog">Blog</a></li>
<li><a href="/press">Press</a></li> <li><a href="/api">API</a></li>
<li><a href="/press">Press</a></li>
<% end %>
<li><a href="/terms" rel="nofollow">Terms</a></li> <li><a href="/terms" rel="nofollow">Terms</a></li>
<li><a href="/privacy" rel="nofollow">Privacy</a></li> <li><a href="/privacy" rel="nofollow">Privacy</a></li>
<li><a href="/contact" rel="nofollow">Contact</a></li> <li><a href="/contact" rel="nofollow">Contact</a></li>

View file

@ -30,15 +30,17 @@
</span> </span>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a href="/site/<%= current_site.username %>">Profile</a></li> <% unless is_education? %>
<li> <li><a href="/site/<%= current_site.username %>">Profile</a></li>
<a href="/?activity=mine"><span class="float-Left">Activity</span> <li>
<% if current_site.unseen_notifications_count > 0 %> <a href="/?activity=mine"><span class="float-Left">Activity</span>
<span class="notification-value"><%= current_site.unseen_notifications_count %></span> <% if current_site.unseen_notifications_count > 0 %>
<% end %> <span class="notification-value"><%= current_site.unseen_notifications_count %></span>
</a> <% end %>
</li> </a>
<li class="divider"></li> </li>
<li class="divider"></li>
<% end %>
<li><a href="/dashboard">Edit Site</a></li> <li><a href="/dashboard">Edit Site</a></li>
<li><a href="<%= current_site.uri %>" target="_blank">View Site</a></li> <li><a href="<%= current_site.uri %>" target="_blank">View Site</a></li>
<li class="divider"></li> <li class="divider"></li>

View file

@ -6,12 +6,16 @@
<li> <li>
<a href="/browse">Websites</a> <a href="/browse">Websites</a>
</li> </li>
<% unless is_education? %>
<li> <li>
<a href="/activity">Activity</a> <a href="/activity">Activity</a>
</li> </li>
<% end %>
<li> <li>
<a href="/tutorials">Learn</a> <a href="/tutorials">Learn</a>
</li> </li>
<% unless is_education? %>
<li> <li>
<a href="/plan">Support Us<i class="fa fa-heart"><i class="fa fa-heart"></i></i></a> <a href="/plan">Support Us<i class="fa fa-heart"><i class="fa fa-heart"></i></i></a>
</li> </li>
<% end %>

View file

@ -6,7 +6,11 @@
$.post('/create_validate_all', $(obj.target).serialize(), function(errors) { $.post('/create_validate_all', $(obj.target).serialize(), function(errors) {
if(errors.length == 0) { if(errors.length == 0) {
$.post('/create', $('#createSiteForm').serialize(), function(res) { $.post('/create', $('#createSiteForm').serialize(), function(res) {
window.location.href = '/welcome' if($('input[name=is_education]').val() == 'true') {
window.location.href = '/dashboard'
} else {
window.location.href = '/welcome'
}
}) })
} else { } else {
for(var i=0; i<errors.length;i++) { for(var i=0; i<errors.length;i++) {

View file

@ -21,32 +21,37 @@
<form id="search_criteria" action="/browse" method="GET"> <form id="search_criteria" action="/browse" method="GET">
<div class="col col-50 filter"> <div class="col col-50 filter">
<fieldset class="grouping"> <fieldset class="grouping">
<label class="text-Label" for="sort_by">Sort by:</label> <% unless is_education? %>
<div class="select-Container"> <label class="text-Label" for="sort_by">Sort by:</label>
<select name="sort_by" id="sort_by" class="input-Select"> <div class="select-Container">
<option value="last_updated" <%= params[:sort_by] == 'last_updated' ? 'selected' : '' %>>Last Updated</option> <select name="sort_by" id="sort_by" class="input-Select">
<option value="featured" <%= params[:sort_by] == 'featured' ? 'selected' : '' %>>Featured</option> <option value="last_updated" <%= params[:sort_by] == 'last_updated' ? 'selected' : '' %>>Last Updated</option>
<option value="views" <%= params[:sort_by] == 'views' ? 'selected' : '' %>>Most Views</option> <option value="featured" <%= params[:sort_by] == 'featured' ? 'selected' : '' %>>Featured</option>
<option value="hits" <%= params[:sort_by] == 'hits' ? 'selected' : '' %>>Most Hits</option> <option value="views" <%= params[:sort_by] == 'views' ? 'selected' : '' %>>Most Views</option>
<option value="newest" <%= params[:sort_by] == 'newest' ? 'selected' : '' %>>Newest</option> <option value="hits" <%= params[:sort_by] == 'hits' ? 'selected' : '' %>>Most Hits</option>
<option value="oldest" <%= params[:sort_by] == 'oldest' ? 'selected' : '' %>>Oldest</option> <option value="newest" <%= params[:sort_by] == 'newest' ? 'selected' : '' %>>Newest</option>
<option value="random" <%= params[:sort_by] == 'random' ? 'selected' : '' %>>Random</option> <option value="oldest" <%= params[:sort_by] == 'oldest' ? 'selected' : '' %>>Oldest</option>
</select> <option value="random" <%= params[:sort_by] == 'random' ? 'selected' : '' %>>Random</option>
</div> </select>
<!-- </div>
<div>
<input name="is_nsfw" type="checkbox" value="true" <%= params[:is_nsfw].to_s == 'true' ? 'checked' : '' %>> Show 18+ content <!--
</div> <div>
--> <input name="is_nsfw" type="checkbox" value="true" <%= params[:is_nsfw].to_s == 'true' ? 'checked' : '' %>> Show 18+ content
</div>
-->
<input class="btn-Action" type="submit" value="Update"> <input class="btn-Action" type="submit" value="Update">
<% end %>
</fieldset> </fieldset>
</div> </div>
<div class="col col-50 filter"> <div class="col col-50 filter">
<form method="GET" action="browse"> <form method="GET" action="browse">
<fieldset class="grouping"> <fieldset class="grouping">
<label class="text-Label" for="tag"><span class="hide-on-mobile">Search by </span>Tag:</label> <% unless is_education? %>
<input class="input-Area typeahead" id="tag" name="tag" type="text" placeholder="pokemon" value="<%= params[:tag] %>" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" dir="auto"> <label class="text-Label" for="tag"><span class="hide-on-mobile">Search by </span>Tag:</label>
<input style="vertical-align: -4px;margin-left: 4px;" type="submit" class="btn-Action" value="Search"> <input class="input-Area typeahead" id="tag" name="tag" type="text" placeholder="pokemon" value="<%= params[:tag] %>" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" dir="auto">
<input style="vertical-align: -4px;margin-left: 4px;" type="submit" class="btn-Action" value="Search">
<% end %>
</fieldset> </fieldset>
</div> </div>
</div> </div>
@ -142,12 +147,14 @@
<% end %> <% end %>
<% end %> <% end %>
<% unless is_education? %>
<div class="row website-Gallery content int-Gall tags"> <div class="row website-Gallery content int-Gall tags">
<h3>Popular Tags</h3> <h3>Popular Tags</h3>
<p> <p>
<% Tag.popular_names(100).each do |tag| %> <% Tag.popular_names(100).each do |tag| %>
<a href="/browse?tag=<%= Rack::Utils.escape tag[:name] %>"><%= tag[:name] %></a>&nbsp;&nbsp; <a href="/browse?tag=<%= Rack::Utils.escape tag[:name] %>"><%= tag[:name] %></a>&nbsp;&nbsp;
<% end %> <% end %>
</p> </p>
</div> </div>
<% end %>
</div> </div>

View file

@ -38,7 +38,7 @@
<% end %> <% end %>
<li>Using <strong><%= current_site.space_percentage_used %>% (<%= current_site.total_space_used.to_space_pretty %>) of your <%= current_site.maximum_space.to_space_pretty %></strong>. <li>Using <strong><%= current_site.space_percentage_used %>% (<%= current_site.total_space_used.to_space_pretty %>) of your <%= current_site.maximum_space.to_space_pretty %></strong>.
<br> <br>
<% if !current_site.supporter? %>Need more space? <a href="/plan">Become a Supporter!</a><% end %></li> <% unless current_site.is_education || current_site.supporter? %>Need more space? <a href="/plan">Become a Supporter!</a><% end %></li>
<li><strong><%= current_site.views.format_large_number %></strong> views</li> <li><strong><%= current_site.views.format_large_number %></strong> views</li>
</ul> </ul>
</div> </div>
@ -188,8 +188,10 @@
<% if !current_site.plan_feature(:no_file_restrictions) %> <% if !current_site.plan_feature(:no_file_restrictions) %>
<a href="/site_files/allowed_types">Allowed file types</a> | <a href="/site_files/allowed_types">Allowed file types</a> |
<% end %> <% end %>
<a href="/site_files/<%= current_site.username %>.zip">Download entire site</a> | <a href="/site_files/<%= current_site.username %>.zip">Download entire site</a>
<a href="/site_files/mount_info">Mount your site as a drive on your computer!</a> <% unless is_education? %>
| <a href="/site_files/mount_info">Mount your site as a drive on your computer!</a>
<% end %>
</div> </div>
</div> </div>