Skip to content

Commit

Permalink
add catagory
Browse files Browse the repository at this point in the history
  • Loading branch information
silverneko committed Jun 22, 2014
1 parent 6681d07 commit e2ad558
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 10 deletions.
7 changes: 6 additions & 1 deletion app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ class ArticlesController < ApplicationController
before_action :set_article, only: [:show, :edit, :update, :destroy]

def index
@articles = Article.where("era = ?", get_era).order("id DESC").page(params[:page])
@articles = Article.where("catagory = 0 AND pinned = true AND era = ?", get_era).order("id DESC")
@articles += Article.where("catagory = 0 AND pinned != true AND era = ?", get_era).order("id DESC")
@courses = Article.where("catagory = 1 AND pinned = true AND era = ?", get_era).order("id DESC")
@courses += Article.where("catagory = 1 AND pinned != true AND era = ?", get_era).order("id DESC")
end

def create
Expand Down Expand Up @@ -81,6 +84,8 @@ def article_params
:title,
:content,
:page,
:pinned,
:catagory,
attachments_attributes:
[
:id,
Expand Down
2 changes: 2 additions & 0 deletions app/models/attachment.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Attachment < ActiveRecord::Base
default_scope order('id ASC')

belongs_to :article

mount_uploader :path, AttachmentUploader
Expand Down
2 changes: 2 additions & 0 deletions app/models/contest_problem_joint.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ContestProblemJoint < ActiveRecord::Base
default_scope order('id ASC')

belongs_to :contest
belongs_to :problem
end
2 changes: 2 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Post < ActiveRecord::Base
default_scope order('id ASC')

belongs_to :problem
has_many :comments, dependent: :destroy

Expand Down
2 changes: 2 additions & 0 deletions app/models/problem.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Problem < ActiveRecord::Base
default_scope order('id ASC')

has_many :submissions, dependent: :destroy
has_many :testdata, dependent: :destroy
has_many :posts, dependent: :destroy
Expand Down
1 change: 1 addition & 0 deletions app/models/testdata_set.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class TestdataSet < ActiveRecord::Base
default_scope order('id ASC')
belongs_to :problem
end
2 changes: 2 additions & 0 deletions app/models/testdatum.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class Testdatum < ActiveRecord::Base
default_scope order('id ASC')

belongs_to :problem
has_one :limit, dependent: :destroy
accepts_nested_attributes_for :limit, :allow_destroy => true
Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class User < ActiveRecord::Base
default_scope order('id ASC')
has_many :submissions#, :dependent => :destroy
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
Expand Down
12 changes: 12 additions & 0 deletions app/views/articles/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
</div>
<% end %>

<div class="field">
<%= f.check_box :pinned %><%= f.label :pinned, "Pin to top" %>
</div>

<div>
<%= f.label :catagory %><br>
<%= f.select :catagory, options_for_select([
["Announcements", 0],
["Course Materials", 1]
], params[:catagory]) %>
</div>

<div class="field">
<%= f.label :title %><br>
<%= f.text_field :title %>
Expand Down
48 changes: 43 additions & 5 deletions app/views/articles/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<h4 class="page-header">Announcements</h4>
<h4 class="page-header">Bulletin</h4>

<%= select_tag :era_select, options_for_select([[2014,2014],[2013,2013],[2012,2012]], params[:era]) %>
<br>

<% if user_signed_in? && current_user.admin == true %>
<br><%= link_to 'New Article', new_article_path(:era => params[:era]) %>
<%= link_to 'New Announcement', new_article_path(:era => params[:era], :catagory => 0) %><br>
<% end %>

<%= select_tag :era_select, options_for_select([[2014,2014],[2013,2013]], params[:era]) %>

<script>
$('#era_select').bind('change', function() { window.location.href = '<%= articles_path.to_s + "?era=" %>' + $(this).val() });
</script>

<strong>Announcements</strong>
<table class="table">
<thead>
<tr>
<th></th>
<th>Title</th>
<th>Arthur</th>
<th>Time</th>
<th>Arthur</th>
<% if user_signed_in? && current_user.admin == true %>
<th></th>
<th></th>
Expand All @@ -25,9 +28,44 @@
<tbody>
<% @articles.each do |a| %>
<tr>
<td><%= image_tag("DrawingPin1_Blue.png", size: "20x20") if a.pinned and a.pinned == true %></td>
<td><%= link_to a.title, article_path(a) %></td>
<td><%= a.created_at.to_s(:clean) %></td>
<td><%= link_to a.arthur_id, user_path(a.arthur_id) %></td>
<% if user_signed_in? && current_user.admin == true %>
<td><%= link_to 'Edit', edit_article_path(a), :class => 'btn btn-info btn-xs' %></td>
<td><%= link_to 'Destroy', a, method: :delete, data: { confirm: 'Are you sure?' }, :class=>'btn btn-xs btn-danger' %></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>

<% if user_signed_in? && current_user.admin == true %>
<%= link_to 'New Course Material', new_article_path(:era => params[:era], :catagory => 1) %><br>
<% end %>

<strong>Course Materials</strong>
<table class="table">
<thead>
<tr>
<th></th>
<th>Title</th>
<th>Time</th>
<th>Arthur</th>
<% if user_signed_in? && current_user.admin == true %>
<th></th>
<th></th>
<% end %>
</tr>
</thead>
<tbody>
<% @courses.each do |a| %>
<tr>
<td><%= image_tag("DrawingPin1_Blue.png", size: "20x20") if a.pinned and a.pinned == true %></td>
<td><%= link_to a.title, article_path(a) %></td>
<td><%= a.created_at.to_s(:clean) %></td>
<td><%= link_to a.arthur_id, user_path(a.arthur_id) %></td>
<% if user_signed_in? && current_user.admin == true %>
<td><%= link_to 'Edit', edit_article_path(a), :class => 'btn btn-info btn-xs' %></td>
<td><%= link_to 'Destroy', a, method: :delete, data: { confirm: 'Are you sure?' }, :class=>'btn btn-xs btn-danger' %></td>
Expand Down
4 changes: 2 additions & 2 deletions app/views/contests/dashboard.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 class='page-header'>
<h4 class="page-header">
Dashboard : <%= @contest.title %>
</h1>
</h4>
<div class="well well-lg">
<table class="table">
<thead>
Expand Down
2 changes: 1 addition & 1 deletion app/views/contests/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1>Editing contest</h1>
<h4 class="page-header">Editing contest</h4>

<%= render 'form' %>

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20140622065458_add_pinned_to_articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPinnedToArticles < ActiveRecord::Migration
def change
add_column :articles, :pinned, :bool
end
end
5 changes: 5 additions & 0 deletions db/migrate/20140622073308_add_catagory_to_articles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCatagoryToArticles < ActiveRecord::Migration
def change
add_column :articles, :catagory, :integer
end
end
4 changes: 3 additions & 1 deletion 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: 20140622041407) do
ActiveRecord::Schema.define(version: 20140622073308) do

create_table "articles", force: true do |t|
t.string "title"
Expand All @@ -20,6 +20,8 @@
t.datetime "created_at"
t.datetime "updated_at"
t.integer "era"
t.boolean "pinned"
t.integer "catagory"
end

create_table "attachments", force: true do |t|
Expand Down
Binary file added public/images/DrawingPin1_Blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e2ad558

Please sign in to comment.