Web Resource module
This commit is contained in:
parent
70c99b941d
commit
e0f7d92d7a
|
@ -1,4 +0,0 @@
|
|||
class Admin::WebLinksController < ApplicationController
|
||||
def index
|
||||
end
|
||||
end
|
|
@ -0,0 +1,94 @@
|
|||
class Admin::WebResourcesController < OrbitAdminController
|
||||
before_action ->(module_app = @app_title) { set_variables module_app }
|
||||
before_action :set_link, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@tags = @module_app.tags
|
||||
@categories = @module_app.categories
|
||||
|
||||
@filter_fields = {
|
||||
:status=>[{:title=>"is_top",:id=>"is_top"},{:title=>"is_hot",:id=>"is_hot"},{:title=>"is_hidden",:id=>"is_hidden"}],
|
||||
:category=>@categories.map{|c| {:title=>c.title, :id=>c.id}},
|
||||
:tags=>@tags.map{|tag| {:title=>tag.name, :id=>tag.id}}
|
||||
}
|
||||
end
|
||||
|
||||
def index_table
|
||||
status = params[:filters][:status].blank? ? [] : params[:filters][:status] rescue []
|
||||
categories = params[:filters][:category].blank? ? [] : params[:filters][:category] rescue []
|
||||
tags = params[:filters][:tags].blank? ? [] : params[:filters][:tags] rescue []
|
||||
|
||||
@links = Kaminari.paginate_array(
|
||||
WebLink.order_by(sort).with_categories(categories).with_tags(tags).with_status(status)
|
||||
).page(params[:page]).per(10)
|
||||
|
||||
@table_fields = [:status, :category, :title]
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
def sort
|
||||
unless params[:sort].blank?
|
||||
case params[:sort]
|
||||
when "status"
|
||||
@sort = [[:is_top, params[:order]],
|
||||
[:is_hot, params[:order]],
|
||||
[:is_hidden,params[:order]]]
|
||||
when "category"
|
||||
@sort = {:category_id=>params[:order]}
|
||||
when "title"
|
||||
@sort = {:title=>params[:order]}
|
||||
when "start_date"
|
||||
@sort = {:postdate=>params[:order]}
|
||||
when "end_date"
|
||||
@sort = {:deadline=>params[:order]}
|
||||
when "last_modified"
|
||||
@sort = {:update_user_id=>params[:order]}
|
||||
end
|
||||
else
|
||||
@sort = {:created_at=>'desc'}
|
||||
end
|
||||
@sort
|
||||
end
|
||||
|
||||
def new
|
||||
@tags =@module_app.tags
|
||||
@categories = @module_app.categories
|
||||
@statuses = []
|
||||
@link = WebLink.new
|
||||
end
|
||||
|
||||
def create
|
||||
link = WebLink.new(link_params)
|
||||
link.create_user_id = current_user.id
|
||||
link.update_user_id = current_user.id
|
||||
link.save
|
||||
redirect_to admin_web_resources_path
|
||||
end
|
||||
|
||||
def edit
|
||||
@tags =@module_app.tags
|
||||
@categories = @module_app.categories
|
||||
@statuses = []
|
||||
end
|
||||
|
||||
def update
|
||||
@link.update_attributes(link_params)
|
||||
@link.save
|
||||
redirect_to admin_web_resources_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
@link.destroy
|
||||
redirect_to admin_web_resources_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_link
|
||||
@link = WebLink.find(params[:id])
|
||||
end
|
||||
|
||||
def link_params
|
||||
params.require(:web_link).permit!
|
||||
end
|
||||
end
|
|
@ -0,0 +1,31 @@
|
|||
class WebResourcesController < ApplicationController
|
||||
|
||||
def index
|
||||
links = WebLink.order_by(:created_at=>'desc')
|
||||
web_link = links.collect do |link|
|
||||
{
|
||||
"title" => link.title,
|
||||
"link_to_show" => link.url
|
||||
}
|
||||
end
|
||||
{
|
||||
"data" => web_link,
|
||||
"extras" => {"widget-title"=>"Web Resource"}
|
||||
}
|
||||
end
|
||||
|
||||
def widget
|
||||
links = WebLink.order_by(:created_at=>'desc')
|
||||
web_link = links.collect do |link|
|
||||
{
|
||||
"title" => link.title,
|
||||
"link_to_show" => link.url
|
||||
}
|
||||
end
|
||||
{
|
||||
"data" => web_link,
|
||||
"extras" => {"widget-title"=>"Web Resource"}
|
||||
}
|
||||
end
|
||||
|
||||
end
|
|
@ -1,4 +1,30 @@
|
|||
# encoding: utf-8
|
||||
class WebLink
|
||||
include Mongoid::Document
|
||||
field :title, type: String
|
||||
end
|
||||
include Mongoid::Timestamps
|
||||
|
||||
include OrbitModel::Status
|
||||
include OrbitTag::Taggable
|
||||
include OrbitCategory::Categorizable
|
||||
|
||||
field :title, localize: true
|
||||
field :context, localize: true
|
||||
|
||||
field :url, localize: true
|
||||
field :create_user_id
|
||||
field :update_user_id
|
||||
|
||||
scope :can_display, ->{where(is_hidden: false)}
|
||||
|
||||
before_validation :add_http
|
||||
validates :url, :presence => true, :format => /\A(http|https):\/\/(([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5})|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:[0-9]{1,5})?(\/.*)?\Z/i
|
||||
|
||||
protected
|
||||
|
||||
def add_http
|
||||
unless self.url[/^http:\/\//] || self.url[/^https:\/\//]
|
||||
self.url = 'http://' + self.url
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,2 +0,0 @@
|
|||
<h1>Admin::WebLinks#index</h1>
|
||||
<p>Find me in app/views/admin/web_links/index.html.erb</p>
|
|
@ -0,0 +1,139 @@
|
|||
<% content_for :page_specific_css do %>
|
||||
<%= stylesheet_link_tag "lib/main-forms" %>
|
||||
<% end %>
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
|
||||
<%= javascript_include_tag "lib/module-area" %>
|
||||
<% end %>
|
||||
|
||||
<!-- Input Area -->
|
||||
<div class="input-area">
|
||||
|
||||
<!-- Module Tabs -->
|
||||
<div class="nav-name"><strong><%= t(:module) %></strong></div>
|
||||
<ul class="nav nav-pills module-nav">
|
||||
<li class="active"><a href="#basic" data-toggle="tab"><%= t(:basic) %></a></li>
|
||||
<li><a href="#status" data-toggle="tab"><%= t(:status) %></a></li>
|
||||
<li><a href="#tag" data-toggle="tab"><%= t(:tags) %></a></li>
|
||||
</ul>
|
||||
|
||||
<!-- Module -->
|
||||
<div class="tab-content module-area">
|
||||
|
||||
<!-- Basic Module -->
|
||||
<div class="tab-pane fade in active" id="basic">
|
||||
|
||||
<!-- Category -->
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t(:category) %></label>
|
||||
<div class="controls">
|
||||
<%= f.select :category_id, @categories.collect{|t| [ t.title, t.id ]} %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Status Module -->
|
||||
<div class="tab-pane fade" id="status">
|
||||
|
||||
<!-- Status -->
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t(:status) %></label>
|
||||
<div class="controls" data-toggle="buttons-checkbox">
|
||||
<label class="checkbox inline btn <%= 'active' if @link.is_top? %>">
|
||||
<%= f.check_box :is_top %> <%= t(:top) %>
|
||||
</label>
|
||||
<label class="checkbox inline btn <%= 'active' if @link.is_hot? %>">
|
||||
<%= f.check_box :is_hot %> <%= t(:hot) %>
|
||||
</label>
|
||||
<label class="checkbox inline btn <%= 'active' if @link.is_hidden? %>">
|
||||
<%= f.check_box :is_hidden %> <%= t(:hide) %>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<%# end %>
|
||||
|
||||
<!-- Tag Module -->
|
||||
<div class="tab-pane fade" id="tag">
|
||||
|
||||
<!-- Tag -->
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t(:tags) %></label>
|
||||
<div class="controls" data-toggle="buttons-checkbox">
|
||||
<% @tags.each do |tag| %>
|
||||
<label class="checkbox inline btn <%= 'active' if @link.tags.include?(tag) %>">
|
||||
<%= check_box_tag 'web_link[tags][]', tag.id, @link.tags.include?(tag) %> <%= tag.name %>
|
||||
</label>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Language Tabs -->
|
||||
<div class="nav-name"><strong><%= t(:language) %></strong></div>
|
||||
<ul class="nav nav-pills language-nav">
|
||||
<% Site.first.in_use_locales.each_with_index do |locale, i| %>
|
||||
<li class="<%= 'active' if i == 0 %>">
|
||||
<a data-toggle="tab" href=".<%= locale %>"><%= t(locale) %></a>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<!-- Language -->
|
||||
<div class="tab-content language-area">
|
||||
|
||||
<% Site.first.in_use_locales.each_with_index do |locale, i| %>
|
||||
|
||||
<div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>">
|
||||
|
||||
<!-- Title-->
|
||||
<div class="control-group input-title">
|
||||
<label class="control-label muted"><%= t(:title) %></label>
|
||||
<div class="controls">
|
||||
<%= f.fields_for :title_translations do |f| %>
|
||||
<%= f.text_field locale, class: "input-block-level", placeholder: t(:title), value: (@link.title_translations[locale] rescue nil) %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Context-->
|
||||
<div class="control-group input-title">
|
||||
<label class="control-label muted"><%= t(:description) %></label>
|
||||
<div class="controls">
|
||||
<%= f.fields_for :context_translations do |f| %>
|
||||
<%= f.text_area locale, rows: 5, class: "input-block-level", value: (@link.context_translations[locale] rescue nil) %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Url-->
|
||||
<div class="control-group input-title">
|
||||
<label class="control-label muted"><%= t(:url) %></label>
|
||||
<div class="controls">
|
||||
<%= f.fields_for :url_translations do |f| %>
|
||||
<%= f.text_field locale, class: "input-block-level", placeholder: t(:url), value: (@link.url_translations[locale] rescue nil) %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Form Actions -->
|
||||
<div class="form-actions">
|
||||
<%= f.submit t('submit'), class: 'btn btn-primary' %>
|
||||
<%= link_to t('cancel'), admin_web_resources_path, :class=>"btn" %>
|
||||
</div>
|
||||
|
||||
</div>
|
|
@ -0,0 +1,5 @@
|
|||
<%= form_for @link, url: admin_web_resource_path(@link), html: {class: "form-horizontal main-forms previewable"} do |f| %>
|
||||
<fieldset>
|
||||
<%= render :partial => 'form', locals: {f: f} %>
|
||||
</fieldset>
|
||||
<% end %>
|
|
@ -0,0 +1,89 @@
|
|||
<% content_for :right_nav do %>
|
||||
<ul class="nav nav-pills filter-nav pull-right">
|
||||
<% @filter_fields.keys.each do |field| %>
|
||||
<li class="accordion-group">
|
||||
<div class="accordion-heading">
|
||||
<a href="#collapse-<%= field %>" data-toggle="collapse" data-parent="#filter" class="accordion-toggle"><%= t(field) %></a>
|
||||
</div>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<div class="filter-group accordion-group">
|
||||
<% @filter_fields.keys.each do |field| %>
|
||||
<div class="accordion-body collapse" id="collapse-<%= field %>">
|
||||
<div class="accordion-inner pagination-right" data-toggle="buttons-checkbox">
|
||||
<% @filter_fields[field].each do |val| %>
|
||||
<%= link_to t(val[:title]), "#", :onclick => "addFilter('filters[#{field}][]=#{val[:id]}')", :class => "btn btn-small #{is_filter_active?(field, val[:id])}" %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="filter-clear">
|
||||
<a href="" class="btn btn-link btn-small"><i class="icons-cycle"></i> <%= t(:clear) %></a>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<span id="index_table">
|
||||
</span>
|
||||
|
||||
<%= render 'layouts/delete_modal', delete_options: @delete_options %>
|
||||
|
||||
<script type="text/javascript">
|
||||
filters=[];
|
||||
table_url="";
|
||||
|
||||
$(function(){
|
||||
init();
|
||||
update_table();
|
||||
});
|
||||
|
||||
var init = function(){
|
||||
filters = window.location.search.replace('?','').split('&');
|
||||
table_url = "";
|
||||
if(window.location.search==""){
|
||||
filters = [];
|
||||
table_url = window.location.pathname+'/index_table';
|
||||
}else{
|
||||
table_url = window.location.pathname+'/index_table';
|
||||
}
|
||||
};
|
||||
|
||||
var update_table = function(url){
|
||||
if(url==null){
|
||||
if(filters.length==0){
|
||||
url = table_url;
|
||||
}else{
|
||||
url = table_url+'?'+filters.join('&');
|
||||
}
|
||||
}
|
||||
|
||||
$.get(url,function(data){
|
||||
history.pushState(null, null, decodeURIComponent(url.replace('/index_table','')) );
|
||||
init();
|
||||
$("#index_table").html(data);
|
||||
|
||||
$(".pagination a").click(function(){
|
||||
update_table($(this).attr('href'));
|
||||
return false;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var addFilter = function(filter){
|
||||
url = "";
|
||||
$.each(filters,function(idx,data){
|
||||
if(data.indexOf("page=")>-1) filters.splice(idx,1);
|
||||
});
|
||||
|
||||
if( (index = filters.indexOf(filter) ) > -1){
|
||||
table_url = table_url.replace(filter,'');
|
||||
filters.splice(index,1);
|
||||
}else{
|
||||
filters.push(filter);
|
||||
}
|
||||
|
||||
update_table();
|
||||
return false;
|
||||
};
|
||||
</script>
|
|
@ -0,0 +1,32 @@
|
|||
<table class="table main-list">
|
||||
<thead>
|
||||
<tr class="sort-header">
|
||||
<% @table_fields.each do |f| %>
|
||||
<%= thead(f) %>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @links.each do |link| %>
|
||||
<tr>
|
||||
<td><%= link.status_for_table %></td>
|
||||
<td><%= link.category.title %></td>
|
||||
<td>
|
||||
<a href="#" target="_blank"><%= link.title %></a>
|
||||
<div class="quick-edit">
|
||||
<ul class="nav nav-pills">
|
||||
<li><a href="/admin/web_resources/<%=link.id.to_s%>/edit"><%= t(:edit) %></a></li>
|
||||
<li><a href="#" class="delete text-error" rel="/admin/web_resources/<%=link.id.to_s%>"><%= t(:delete_) %></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%=
|
||||
content_tag :div, class: "bottomnav clearfix" do
|
||||
content_tag :div, paginate(@links), class: "pagination pagination-centered"
|
||||
end
|
||||
%>
|
|
@ -0,0 +1,5 @@
|
|||
<%= form_for @link, url: admin_web_resources_path, html: {class: "form-horizontal main-forms previewable"} do |f| %>
|
||||
<fieldset>
|
||||
<%= render :partial => 'form', locals: {f: f} %>
|
||||
</fieldset>
|
||||
<% end %>
|
|
@ -0,0 +1 @@
|
|||
<%= render_view %>
|
|
@ -0,0 +1 @@
|
|||
<%= render_view %>
|
|
@ -3,9 +3,10 @@ Rails.application.routes.draw do
|
|||
locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_locales
|
||||
|
||||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||
namespace :admin do
|
||||
resources :web_links
|
||||
end
|
||||
namespace :admin do
|
||||
get 'web_resources/index_table' => 'web_resources#index_table'
|
||||
resources :web_resources
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
module Links
|
||||
module WebResource
|
||||
class Engine < ::Rails::Engine
|
||||
initializer "links" do
|
||||
OrbitApp.registration "Links", :type => "ModuleApp" do
|
||||
module_label "links.links"
|
||||
initializer "web_resource" do
|
||||
OrbitApp.registration "WebResource", :type => "ModuleApp" do
|
||||
module_label "link"
|
||||
base_url File.expand_path File.dirname(__FILE__)
|
||||
|
||||
taggable "WebLink"
|
||||
|
@ -10,12 +10,24 @@ module Links
|
|||
authorizable
|
||||
|
||||
side_bar do
|
||||
head_label_i18n 'faq.faq', icon_class: "icons-link"
|
||||
head_label_i18n 'link',:icon_class=>"icons-link"
|
||||
available_for [:admin,:manager,:sub_manager]
|
||||
active_for_controllers ({:private=>['web_links']})
|
||||
head_link_path "admin_web_links_path"
|
||||
end
|
||||
active_for_controllers ({:private=>['web_resource']})
|
||||
head_link_path "admin_web_resources_path"
|
||||
|
||||
context_link 'list_',
|
||||
:link_path=>"admin_web_resources_path" ,
|
||||
:priority=>1,
|
||||
:active_for_action=>{'admin/web_resources'=>'index'},
|
||||
:available_for => [:all]
|
||||
|
||||
context_link 'add',
|
||||
:link_path=>"new_admin_web_resource_path" ,
|
||||
:priority=>2,
|
||||
:active_for_action=>{'admin/web_resources'=>'new'},
|
||||
:available_for => [:sub_manager]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue