diff --git a/app/controllers/admin/web_links_controller.rb b/app/controllers/admin/web_links_controller.rb deleted file mode 100644 index 23486ee..0000000 --- a/app/controllers/admin/web_links_controller.rb +++ /dev/null @@ -1,4 +0,0 @@ -class Admin::WebLinksController < ApplicationController - def index - end -end diff --git a/app/controllers/admin/web_resources_controller.rb b/app/controllers/admin/web_resources_controller.rb new file mode 100644 index 0000000..526e89b --- /dev/null +++ b/app/controllers/admin/web_resources_controller.rb @@ -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 diff --git a/app/controllers/web_resources_controller.rb b/app/controllers/web_resources_controller.rb new file mode 100644 index 0000000..d131ee8 --- /dev/null +++ b/app/controllers/web_resources_controller.rb @@ -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 diff --git a/app/models/web_link.rb b/app/models/web_link.rb index d035c59..5ab0740 100644 --- a/app/models/web_link.rb +++ b/app/models/web_link.rb @@ -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 \ No newline at end of file diff --git a/app/views/admin/web_links/index.html.erb b/app/views/admin/web_links/index.html.erb deleted file mode 100644 index 1fab4b7..0000000 --- a/app/views/admin/web_links/index.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -
Find me in app/views/admin/web_links/index.html.erb
diff --git a/app/views/admin/web_resources/_form.html.erb b/app/views/admin/web_resources/_form.html.erb new file mode 100644 index 0000000..09d3622 --- /dev/null +++ b/app/views/admin/web_resources/_form.html.erb @@ -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 %> + + +<%= link.status_for_table %> | +<%= link.category.title %> | +
+ <%= link.title %>
+
+
+
+ |
+