added news updates ui
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
(function() {
|
(function() {
|
||||||
Danbooru.News = {};
|
Danbooru.NewsUpdate = {};
|
||||||
|
|
||||||
Danbooru.News.initialize = function() {
|
Danbooru.NewsUpdate.initialize = function() {
|
||||||
var key = $("#news-ticker").data("updated-at");
|
var key = $("#news-updates").data("updated-at");
|
||||||
|
|
||||||
if (Danbooru.Cookie.get("news-ticker") === key) {
|
if (Danbooru.Cookie.get("news-ticker") === key) {
|
||||||
$("#news-ticker").hide();
|
$("#news-updates").hide();
|
||||||
} else {
|
} else {
|
||||||
$("#close-news-ticker-link").click(function(e) {
|
$("#close-news-ticker-link").click(function(e) {
|
||||||
$("#news-ticker").hide();
|
$("#news-updates").hide();
|
||||||
Danbooru.Cookie.put("news-ticker", key);
|
Danbooru.Cookie.put("news-ticker", key);
|
||||||
|
|
||||||
// need to reset the more link
|
// need to reset the more link
|
||||||
@@ -20,6 +20,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
Danbooru.News.initialize();
|
Danbooru.NewsUpdate.initialize();
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
div#news-ticker {
|
div#news-updates {
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
background: #EEE;
|
background: #EEE;
|
||||||
border-bottom: 2px solid #666;
|
border-bottom: 2px solid #666;
|
||||||
|
|||||||
4
app/assets/stylesheets/news_updates.css
Normal file
4
app/assets/stylesheets/news_updates.css
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
/*
|
||||||
|
Place all the styles related to the matching controller here.
|
||||||
|
They will automatically be included in application.css.
|
||||||
|
*/
|
||||||
38
app/controllers/news_updates_controller.rb
Normal file
38
app/controllers/news_updates_controller.rb
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
class NewsUpdatesController < ApplicationController
|
||||||
|
before_filter :admin_only
|
||||||
|
respond_to :html
|
||||||
|
|
||||||
|
def index
|
||||||
|
@news_updates = NewsUpdate.paginate(params[:page])
|
||||||
|
respond_with(@news_updates)
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@news_update = NewsUpdate.find(params[:id])
|
||||||
|
respond_with(@news_update)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@news_update = NewsUpdate.find(params[:id])
|
||||||
|
@news_update.update_attributes(params[:news_update])
|
||||||
|
respond_with(@news_update, :location => news_updates_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@news_update = NewsUpdate.new
|
||||||
|
respond_with(@news_update)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@news_update = NewsUpdate.create(params[:news_update])
|
||||||
|
respond_with(@news_update, :location => news_updates_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@news_update = NewsUpdate.find(params[:id])
|
||||||
|
@news_update.destroy
|
||||||
|
respond_with(@news_update) do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
2
app/helpers/news_updates_helper.rb
Normal file
2
app/helpers/news_updates_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module NewsUpdatesHelper
|
||||||
|
end
|
||||||
15
app/models/news_update.rb
Normal file
15
app/models/news_update.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class NewsUpdate < ActiveRecord::Base
|
||||||
|
belongs_to :creator, :class_name => "User"
|
||||||
|
belongs_to :udpater, :class_name => "User"
|
||||||
|
scope :recent, order("created_at desc").limit(5)
|
||||||
|
before_validation :initialize_creator, :on => :create
|
||||||
|
before_validation :initialize_updater
|
||||||
|
|
||||||
|
def initialize_creator
|
||||||
|
self.creator_id = CurrentUser.id
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize_updater
|
||||||
|
self.updater_id = CurrentUser.id
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header id="top">
|
<header id="top">
|
||||||
<%= render "news/listing" %>
|
<%= render "news_updates/listing" %>
|
||||||
|
|
||||||
<h1><%= link_to Danbooru.config.app_name, "/" %></h1>
|
<h1><%= link_to Danbooru.config.app_name, "/" %></h1>
|
||||||
<nav>
|
<nav>
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
<% unless cookies["news-ticker"] == "2011-09-01" %>
|
|
||||||
<div id="news-ticker" data-updated-at="2011-09-01">
|
|
||||||
<ul>
|
|
||||||
<li>10/22: Database has been reset</li>
|
|
||||||
<li>Report issues on <a href="https://github.com/r888888888/danbooru/issues/new">Github</a> or the <a href="http://danbooru.donmai.us/forum/show/65870">forum</a></li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<a href="#" id="close-news-ticker-link">close</a>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
11
app/views/news_updates/_listing.html.erb
Normal file
11
app/views/news_updates/_listing.html.erb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<% cache("news-updates", :expires_in => 1.hour) do %>
|
||||||
|
<div id="news-updates" data-updated-at="<%= NewsUpdate.recent.first.try(:created_at).try(:strftime, "%m/%d/%Y") %>">
|
||||||
|
<ul>
|
||||||
|
<% NewsUpdate.recent.each do |news_update| %>
|
||||||
|
<li><%= news_update.created_at.strftime("%m/%d") %>: <%= news_update.message.html_safe %></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<a href="#" id="close-news-ticker-link">close</a>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
6
app/views/news_updates/_secondary_links.html.erb
Normal file
6
app/views/news_updates/_secondary_links.html.erb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<% content_for(:secondary_links) do %>
|
||||||
|
<menu>
|
||||||
|
<li><%= link_to "Listing", news_updates_path %></li>
|
||||||
|
<li><%= link_to "New", new_news_update_path %></li>
|
||||||
|
</menu>
|
||||||
|
<% end %>
|
||||||
1
app/views/news_updates/destroy.js.erb
Normal file
1
app/views/news_updates/destroy.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
$("#news-update-<%= @news_update.id %>").remove();
|
||||||
16
app/views/news_updates/edit.html.erb
Normal file
16
app/views/news_updates/edit.html.erb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<div id="c-news-updates">
|
||||||
|
<div id="a-new">
|
||||||
|
<h1>Edit Update</h1>
|
||||||
|
|
||||||
|
<%= simple_form_for(@news_update) do |f| %>
|
||||||
|
<%= f.input :message, :hint => "Use HTML for formatting", :input_html => {:size => "30x5"} %>
|
||||||
|
<%= f.button :submit, "Submit" %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= render "secondary_links" %>
|
||||||
|
|
||||||
|
<% content_for(:page_title) do %>
|
||||||
|
Edit Update - <%= Danbooru.config.app_name %>
|
||||||
|
<% end %>
|
||||||
32
app/views/news_updates/index.html.erb
Normal file
32
app/views/news_updates/index.html.erb
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<div id="c-news-updates">
|
||||||
|
<div id="a-index">
|
||||||
|
<h1>News Updates</h1>
|
||||||
|
|
||||||
|
<table class="striped" width="100%">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Creator</th>
|
||||||
|
<th>Message</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @news_updates.each do |news_update| %>
|
||||||
|
<tr id="news-update-<%= news_update.id %>">
|
||||||
|
<td><%= news_update.creator.name %></td>
|
||||||
|
<td><%= news_update.message %></td>
|
||||||
|
<td><%= link_to "Edit", edit_news_update_path(news_update) %> | <%= link_to "Delete", news_update_path(news_update), :method => :delete %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%= numbered_paginator(@news_updates) %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= render "secondary_links" %>
|
||||||
|
|
||||||
|
<% content_for(:page_title) do %>
|
||||||
|
News Updates - <%= Danbooru.config.app_name %>
|
||||||
|
<% end %>
|
||||||
16
app/views/news_updates/new.html.erb
Normal file
16
app/views/news_updates/new.html.erb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<div id="c-news-updates">
|
||||||
|
<div id="a-new">
|
||||||
|
<h1>New Update</h1>
|
||||||
|
|
||||||
|
<%= simple_form_for(@news_update) do |f| %>
|
||||||
|
<%= f.input :message, :hint => "Use HTML for formatting", :input_html => {:size => "30x5"} %>
|
||||||
|
<%= f.button :submit, "Submit" %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= render "secondary_links" %>
|
||||||
|
|
||||||
|
<% content_for(:page_title) do %>
|
||||||
|
New Update - <%= Danbooru.config.app_name %>
|
||||||
|
<% end %>
|
||||||
@@ -92,6 +92,7 @@ Danbooru::Application.routes.draw do
|
|||||||
resources :jobs
|
resources :jobs
|
||||||
resource :landing
|
resource :landing
|
||||||
resources :mod_actions
|
resources :mod_actions
|
||||||
|
resources :news_updates
|
||||||
resources :notes do
|
resources :notes do
|
||||||
collection do
|
collection do
|
||||||
get :search
|
get :search
|
||||||
|
|||||||
@@ -1983,6 +1983,39 @@ CREATE SEQUENCE mod_actions_id_seq
|
|||||||
ALTER SEQUENCE mod_actions_id_seq OWNED BY mod_actions.id;
|
ALTER SEQUENCE mod_actions_id_seq OWNED BY mod_actions.id;
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: news_updates; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE news_updates (
|
||||||
|
id integer NOT NULL,
|
||||||
|
message text NOT NULL,
|
||||||
|
creator_id integer NOT NULL,
|
||||||
|
updater_id integer NOT NULL,
|
||||||
|
created_at timestamp without time zone,
|
||||||
|
updated_at timestamp without time zone
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: news_updates_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE SEQUENCE news_updates_id_seq
|
||||||
|
START WITH 1
|
||||||
|
INCREMENT BY 1
|
||||||
|
NO MINVALUE
|
||||||
|
NO MAXVALUE
|
||||||
|
CACHE 1;
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: news_updates_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||||
|
--
|
||||||
|
|
||||||
|
ALTER SEQUENCE news_updates_id_seq OWNED BY news_updates.id;
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: note_versions; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
-- Name: note_versions; Type: TABLE; Schema: public; Owner: -; Tablespace:
|
||||||
--
|
--
|
||||||
@@ -2870,6 +2903,13 @@ ALTER TABLE janitor_trials ALTER COLUMN id SET DEFAULT nextval('janitor_trials_i
|
|||||||
ALTER TABLE mod_actions ALTER COLUMN id SET DEFAULT nextval('mod_actions_id_seq'::regclass);
|
ALTER TABLE mod_actions ALTER COLUMN id SET DEFAULT nextval('mod_actions_id_seq'::regclass);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
||||||
|
--
|
||||||
|
|
||||||
|
ALTER TABLE news_updates ALTER COLUMN id SET DEFAULT nextval('news_updates_id_seq'::regclass);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
@@ -3146,6 +3186,14 @@ ALTER TABLE ONLY mod_actions
|
|||||||
ADD CONSTRAINT mod_actions_pkey PRIMARY KEY (id);
|
ADD CONSTRAINT mod_actions_pkey PRIMARY KEY (id);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: news_updates_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||||
|
--
|
||||||
|
|
||||||
|
ALTER TABLE ONLY news_updates
|
||||||
|
ADD CONSTRAINT news_updates_pkey PRIMARY KEY (id);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: note_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
-- Name: note_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
|
||||||
--
|
--
|
||||||
@@ -4916,6 +4964,13 @@ CREATE UNIQUE INDEX index_ip_bans_on_ip_addr ON ip_bans USING btree (ip_addr);
|
|||||||
CREATE INDEX index_janitor_trials_on_user_id ON janitor_trials USING btree (user_id);
|
CREATE INDEX index_janitor_trials_on_user_id ON janitor_trials USING btree (user_id);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: index_news_updates_on_created_at; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE INDEX index_news_updates_on_created_at ON news_updates USING btree (created_at);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: index_note_versions_on_note_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
-- Name: index_note_versions_on_note_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||||
--
|
--
|
||||||
@@ -5440,4 +5495,6 @@ INSERT INTO schema_migrations (version) VALUES ('20110717010705');
|
|||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20110722211855');
|
INSERT INTO schema_migrations (version) VALUES ('20110722211855');
|
||||||
|
|
||||||
INSERT INTO schema_migrations (version) VALUES ('20110815233456');
|
INSERT INTO schema_migrations (version) VALUES ('20110815233456');
|
||||||
|
|
||||||
|
INSERT INTO schema_migrations (version) VALUES ('20111101212358');
|
||||||
@@ -26,7 +26,7 @@ class CreateUsers < ActiveRecord::Migration
|
|||||||
t.column :receive_email_notifications, :boolean, :null => false, :default => false
|
t.column :receive_email_notifications, :boolean, :null => false, :default => false
|
||||||
t.column :comment_threshold, :integer, :null => false, :default => -1
|
t.column :comment_threshold, :integer, :null => false, :default => -1
|
||||||
t.column :always_resize_images, :boolean, :null => false, :default => false
|
t.column :always_resize_images, :boolean, :null => false, :default => false
|
||||||
t.column :default_image_size, :string, :null => false, :default => "medium"
|
t.column :default_image_size, :string, :null => false, :default => "large"
|
||||||
t.column :favorite_tags, :text
|
t.column :favorite_tags, :text
|
||||||
t.column :blacklisted_tags, :text
|
t.column :blacklisted_tags, :text
|
||||||
t.column :time_zone, :string, :null => false, :default => "Eastern Time (US & Canada)"
|
t.column :time_zone, :string, :null => false, :default => "Eastern Time (US & Canada)"
|
||||||
|
|||||||
12
db/migrate/20111101212358_create_news_updates.rb
Normal file
12
db/migrate/20111101212358_create_news_updates.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
class CreateNewsUpdates < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :news_updates do |t|
|
||||||
|
t.column :message, :text, :null => false
|
||||||
|
t.column :creator_id, :integer, :null => false
|
||||||
|
t.column :updater_id, :integer, :null => false
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :news_updates, :created_at
|
||||||
|
end
|
||||||
|
end
|
||||||
3
test/factories/news_update.rb
Normal file
3
test/factories/news_update.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Factory.define(:news_update) do |f|
|
||||||
|
f.message "xxx"
|
||||||
|
end
|
||||||
59
test/functional/news_updates_controller_test.rb
Normal file
59
test/functional/news_updates_controller_test.rb
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class NewsUpdatesControllerTest < ActionController::TestCase
|
||||||
|
context "the news updates controller" do
|
||||||
|
setup do
|
||||||
|
@admin = Factory.create(:admin_user)
|
||||||
|
CurrentUser.user = @admin
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
@news_update = Factory.create(:news_update)
|
||||||
|
end
|
||||||
|
|
||||||
|
teardown do
|
||||||
|
CurrentUser.user = nil
|
||||||
|
CurrentUser.ip_addr = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
context "index action" do
|
||||||
|
should "render" do
|
||||||
|
get :index, {}, :user_id => @admin.id
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "new action" do
|
||||||
|
should "render" do
|
||||||
|
get :new, {}, :user_id => @admin.id
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "edit action" do
|
||||||
|
should "render" do
|
||||||
|
get :edit, {:id => @news_update.id}, {:user_id => @admin.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "update action" do
|
||||||
|
should "work" do
|
||||||
|
post :update, {:id => @news_update.id, :news_update => {:message => "zzz"}}, {:user_id => @admin.id}
|
||||||
|
assert_redirected_to(news_updates_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "create action" do
|
||||||
|
should "work" do
|
||||||
|
post :create, {:news_update => {:message => "zzz"}}, {:user_id => @admin.id}
|
||||||
|
assert_redirected_to(news_updates_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "destroy action" do
|
||||||
|
should "work" do
|
||||||
|
post :destroy, {:id => @news_update.id, :format => "js"}, {:user_id => @admin.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
4
test/unit/helpers/news_updates_helper_test.rb
Normal file
4
test/unit/helpers/news_updates_helper_test.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class NewsUpdatesHelperTest < ActionView::TestCase
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user