feeds new stuff

This commit is contained in:
Harry Bomrah 2015-11-10 01:38:30 +08:00
parent 504db2e0d3
commit 2fcd6abf82
7 changed files with 195 additions and 10 deletions

View File

@ -0,0 +1,3 @@
.channel-accordion {
background-color: #fff;
}

View File

@ -0,0 +1,116 @@
@import url(https://fonts.googleapis.com/css?family=Roboto);
.channel-accordion {
font-family: 'Roboto', sans-serif;
}
.channel-accordion-group {
border: none;
border-radius: 2px;
background-color: #fff;
margin-bottom: 10px;
}
.channel-accordion-heading {
position: relative;
}
.channel-accordion .channel-accordion-toggle {
background-color: #fff;
font-size: 16px;
padding: 16px;
border: none;
text-decoration: none;
-webkit-transition: .3s all ease-in-out;
-o-transition: .3s all ease-in-out;
transition: .3s all ease-in-out;
}
.channel-accordion .channel-accordion-toggle:hover {
outline: none;
padding-left: 30px;
color: #fff;
background-color: #08c;
}
.channel-accordion .channel-accordion-toggle:focus {
outline: none;
}
.channel-dropdown {
position: absolute;
right: 10px;
top: 12px;
}
.channel-dropdown-menu {
top: calc(100% + 5px);
right: 0;
left: auto;
z-index: 1200;
border-radius: 4px;
border-color: #ccc;
box-shadow: none;
padding: 20px;
}
.channel-name {
font-size: 18px;
margin-bottom: 8px;
display: inline-block;
}
.channel-sublist {
margin: 0;
padding: 0 0 0 10px;
list-style: square;
list-style-position: inside;
}
.channel-subitem {
padding: 10px 0;
border-top: 1px solid #eee;
overflow: hidden;
}
.channel-sublist:last-child .channel-subitem {
border-bottom: 1px solid #eee;
}
.channel-feedname {
font-size: 14px;
display: inline-block;
margin-right: 8px;
}
.channel-actions {
float: right;
}
.channel-form-horizontal .channel-control-group {
margin-bottom: 8px;
}
.channel-form-horizontal .channel-label {
float: none;
width: auto;
text-align: left;
display: block;
}
.channel-form-horizontal .channel-controls {
margin-left: 0;
}
.channel-source-name {
margin-left: 10px;
vertical-align: middle;
}
/* Utilities */
.list-unstyled {
margin: 0;
padding: 0;
list-style: none;
}

View File

@ -58,6 +58,15 @@ class Admin::FeedsController < OrbitAdminController
render :json => data_to_send.to_json
end
def channel_title
site_feeds = SiteFeed.where(:remote_site_url => params["url"])
site_feeds.each do |sf|
sf.channel_title_translations = params["channel_title_translations"]
sf.save
end
render :json => {"success" => true, "title" => params["channel_title_translations"][I18n.locale.to_s]}.to_json
end
def subscribe
site_feed = SiteFeed.new
site_feed.remote_site_url = params[:url].chomp("/")

View File

@ -5,6 +5,7 @@ class SiteFeed
field :remote_site_url
field :merge_with_category
field :channel_name
field :channel_title, :localize => true
field :channel_key
field :feed_name, localize: true
field :disabled, type: Boolean, default: false

View File

@ -1,13 +1,42 @@
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "index_channel" %>
<% end %>
<div>
<h3>Channel and feeds</h3>
</div>
<div class="accordion" id="feedAccordion">
<div class="accordion channel-accordion" id="feedAccordion">
<% @school_urls.each_with_index do |url,index| %>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#feedAccordion" href="#channel_<%= index.to_s %>">
<%= (index + 1).to_s %>. <%= url %>
<div class="accordion-group channel-accordion-group">
<div class="accordion-heading channel-accordion-heading">
<a class="accordion-toggle channel-accordion-toggle collapsed" data-toggle="collapse" data-parent="#feedAccordion" href="#channel_<%= index.to_s %>">
<span class="channel-url"><%= url %></span>
<% if !@site_feeds[url].first.channel_title.nil? && @site_feeds[url].first.channel_title != "" %>
<span class="channel-source-name label"><%= @site_feeds[url].first.channel_title %></span>
<% end %>
</a>
<div class="dropdown channel-dropdown">
<a class="channel-edit-form btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">Edit</a>
<a class="channel-save-form btn btn-primary dropdown-toggle hide" data-toggle="dropdown" href="#">Save</a>
<ul class="dropdown-menu channel-dropdown-menu" role="menu" aria-labelledby="dLabel">
<form class="form-horizontal channel-form-horizontal" method="post" action="/admin/feeds/channel_title" data-remote="true">
<h5>Source name</h5>
<div class="control-group channel-control-group">
<label class="control-label channel-label" for="inputEnglish">English</label>
<div class="controls channel-controls">
<input type="text" id="inputEnglish" placeholder="Source" name="channel_title_translations[en]">
</div>
</div>
<div class="control-group channel-control-group">
<label class="control-label channel-label" for="inputChinese">Chinese</label>
<div class="controls channel-controls">
<input type="text" id="inputChinese" placeholder="Source" name="channel_title_translations[zh_tw]">
</div>
<input type="hidden" name="url" value="<%= url %>" >
</div>
</form>
</ul>
</div>
</div>
<div id="channel_<%= index.to_s %>" class="accordion-body collapse">
<div class="accordion-inner">
@ -15,12 +44,18 @@
channel_names = channels.keys
channel_names.each do |name|
%>
<ul>
<li>
<%= name %>
<ul class="channel-list list-unstyled">
<li class="channel-item">
<span class="channel-name"><%= name %></span>
<% channels[name].each do |channel| %>
<ul>
<li><%= channel.feed_name %> <button class="btn <%= channel.disabled ? "btn-info" : "btn-warning" %> disable-feed-btn" data-feed-id="<%= channel.id.to_s %>"><%= channel.disabled ? "Enable" : "Disable" %></button> <button class="btn btn-danger unsubscribe-btn" data-feed-uid="<%= channel.feed_uid %>" data-feed-name="<%= channel.feed_name %>">Unsubscribe</button></li>
<ul class="channel-sublist">
<li class="channel-subitem" >
<span class="channel-feedname"><%= channel.feed_name %></span>
<span class="channel-actions">
<button class="btn <%= channel.disabled ? "btn-info" : "btn-warning" %> btn-small disable-feed-btn" data-feed-id="<%= channel.id.to_s %>"><%= channel.disabled ? "Enable" : "Disable" %></button>
<button class="btn btn-danger btn-small unsubscribe-btn" data-feed-uid="<%= channel.feed_uid %>" data-feed-name="<%= channel.feed_name %>">Unsubscribe</button>
</span>
</li>
</ul>
<% end %>
</li>
@ -61,6 +96,26 @@
})
})
$(".channel-edit-form").on("click",function(){
var edit = $(this),
save = $(this).next();
edit.addClass("hide");
save.removeClass("hide");
$(document).one("click",function(){
edit.removeClass("hide");
save.addClass("hide");
})
})
$(".channel-save-form").on("click",function(){
var save = $(this),
edit = $(this).prev(),
form = $(this).parent().find("form");
edit.removeClass("hide");
save.addClass("hide");
form.submit();
})
$(".unsubscribe-btn").on("click",function(){
var el = $(this);
if(confirm("Are you sure, you want to unsubscribe from " + el.data("feed-name"))){

View File

@ -10,6 +10,7 @@ Rails.application.routes.draw do
post "/feeds/subscribe", to: 'feeds#subscribe'
post "/feeds/unsubscribe", to: 'feeds#unsubscribe'
post "/feeds/disable", to: 'feeds#disable'
post "/feeds/channel_title", to: 'feeds#channel_title'
resources :feeds
end
end

View File