diff --git a/app/controllers/admin/archive_files_controller.rb b/app/controllers/admin/archive_files_controller.rb index bda9d99..1fa8d50 100644 --- a/app/controllers/admin/archive_files_controller.rb +++ b/app/controllers/admin/archive_files_controller.rb @@ -1,4 +1,99 @@ -class Admin::ArchiveFilesController < ApplicationController +class Admin::ArchiveFilesController < OrbitAdminController + def index + @table_fields = ["Status","Category","Title"] + @categories = @module_app.categories + @tags = @module_app.tags + @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}} + } + 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 [] + + @archives = Kaminari.paginate_array(ArchiveFile.order_by(sort).with_categories(categories).with_tags(tags).with_status(status)).page(params[:page]).per(10) + + if request.xhr? + render :partial => "index" + end + end + + def new + @archive_file = ArchiveFile.new + @tags = @module_app.tags + @categories = @module_app.categories + end + + def edit + @archive_file = ArchiveFile.find(params[:id]) + @tags = @module_app.tags + @categories = @module_app.categories + end + + def create + @archive_file = ArchiveFile.new(archive_vars) + @archive_file.create_user_id = current_user.id + @archive_file.update_user_id = current_user.id + + respond_to do |format| + if @archive_file.save + format.html { redirect_to(admin_archive_files_path) } + format.xml { render :xml => @archive_file, :status => :created, :location => @archive_file } + else + @tags = @module_app.tags + format.html { render :action => "new" } + format.xml { render :xml => @archive_file.errors, :status => :unprocessable_entity } + end + end + end + + # PUT /archive_files/1 + # PUT /archive_files/1.xml + def update + @archive_file = ArchiveFile.find(params[:id]) + + @archive_file.update_user_id = current_user.id + + respond_to do |format| + if @archive_file.update_attributes(archive_vars) + format.html { redirect_to(admin_archive_files_path(:page => params[:page])) } + format.xml { head :ok } + else + format.html { render :action => "edit" } + format.xml { render :xml => @archive_file.errors, :status => :unprocessable_entity } + end + end + end + + private + + def archive_vars + params[:archive_file][:tags] ||=[] + params.require(:archive_file).permit! + end + + def setup_vars + @module_app = ModuleApp.where(:key => "archive").first + 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 "last_modified" + @sort = {:update_user_id=>params[:order]} + end + else + @sort = {:created_at=>'desc'} + end + @sort end end diff --git a/app/controllers/archives_controller.rb b/app/controllers/archives_controller.rb new file mode 100644 index 0000000..a2ffd5d --- /dev/null +++ b/app/controllers/archives_controller.rb @@ -0,0 +1,50 @@ +class ArchivesController < ApplicationController + def index + categories = OrbitHelper.page_categories + @categories = [] + if categories.first == "all" + module_app = OrbitHelper.this_module_app + # debugger + @categories = module_app.categories.collect do |cat| + { + "title" => cat.title, + "id" => cat.id.to_s + } + end + else + categories.each do |cat| + c = Category.find(cat) + @categories << {"title" => c.title, "id" => c.id.to_s} + end + end + cats = @categories.collect do |cat| + archives = ArchiveFile.where(:category_id => cat["id"]).collect do |archive| + statuses = archive.statuses.collect do |status| + { + "archive-status" => status + } + end + files = archive.archive_file_multiples.collect do |file| + { + "file-name" => file.file_title, + "file-type" => file.file.file.extension.downcase, + "file-url" => file.file.url + } + end + { + "archive-title" => archive.title, + "status" => statuses, + "files" => files + } + end + { + "category-title" => cat["title"], + "archives" => archives + } + end + { + "categories" => cats, + "extras" => {"widget-title" => "Archives"} + } + end +end \ No newline at end of file diff --git a/app/models/archive_file.rb b/app/models/archive_file.rb index 510558e..ea2e331 100644 --- a/app/models/archive_file.rb +++ b/app/models/archive_file.rb @@ -1,4 +1,94 @@ +# encoding: utf-8 class ArchiveFile include Mongoid::Document - field :title, type: String + include Mongoid::Timestamps + + include OrbitCategory::Categorizable + include OrbitModel::Status + include OrbitTag::Taggable + include Slug + + + # include Tire::Model::Search + # include Tire::Model::Callbacks + + # BelongsToCategory = :archive_file_category + + # PAYMENT_TYPES = @site_valid_locales + + + field :title, as: :slug_title, localize: true + field :create_user_id + field :update_user_id + field :postdate , :type => DateTime, :default => Time.now + field :deadline , :type => DateTime + field :uid, type: String + field :sort_number, type: Integer + + # scope :can_display,where(is_hidden: false) + + # belongs_to :archive_file_category + + has_many :archive_file_multiples, :autosave => true, :dependent => :destroy + + accepts_nested_attributes_for :archive_file_multiples, :allow_destroy => true + + # validates :title, :at_least_one => true + + after_save :save_archive_file_multiples + + # def to_indexed_json + # self.to_json + # end + + # search_in :title + + # searchable do + # text :titles do + # title_translations.to_a.collect{|t| t[1]} +# end + # boolean :frontend_search do + # !is_hidden + # end + + # end + + + # def self.search( category_id = nil ) + + # if category_id.to_s.size > 0 + + # find(:all, :conditions => {archive_file_category_id: category_id}).desc( :is_top, :title ) + + # else + + # find(:all).desc( :is_top, :title) + + # end + + # end + + def self.find_by_param(input) + self.find_by(uid: input) + end + + def self.widget_datas + + where( :is_hidden => false ).desc(:is_top, :title) + + end + + + def get_file_icon( file_data ) + file_icon = "#{file_data.split('.')[-1]}".html_safe + end + + def save_archive_file_multiples + self.archive_file_multiples.each do |t| + if t.should_destroy + t.destroy + end + end + end + end diff --git a/app/models/archive_file_multiple.rb b/app/models/archive_file_multiple.rb new file mode 100644 index 0000000..b5993d9 --- /dev/null +++ b/app/models/archive_file_multiple.rb @@ -0,0 +1,27 @@ +class ArchiveFileMultiple + + include Mongoid::Document + include Mongoid::Timestamps + + mount_uploader :file, AssetUploader + + field :file_title, localize: true + # field :description + field :choose_lang, :type => Array, :default => nil + + field :should_destroy, :type => Boolean + field :sort_number, :type => Integer + + # default_scope asc(:sort_number) + + def choose_lang_display(lang) + self.choose_lang.include?(lang) + end + + belongs_to :archive_file + + # has_many :archive_file_multiple_langs, :autosave => true, :dependent => :destroy + + # accepts_nested_attributes_for :archive_file_multiple_langs, :allow_destroy => true + +end diff --git a/app/views/admin/archive_files/_form.html.erb b/app/views/admin/archive_files/_form.html.erb new file mode 100644 index 0000000..6a04b95 --- /dev/null +++ b/app/views/admin/archive_files/_form.html.erb @@ -0,0 +1,194 @@ +<% # encoding: utf-8 %> +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/fileupload" %> + <%= stylesheet_link_tag "lib/main-list" %> +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/bootstrap-fileupload" %> + <%= javascript_include_tag "lib/file-type" %> + <%= javascript_include_tag "lib/module-area" %> +<% end %> + + <%#= f.error_messages %> + + +
+ <%= hidden_field_tag 'archive_file_multiple_field_count', @archive_file.archive_file_multiples.count %> + <%= t(:add) %> +
+ ++ <%= archive.status_for_table %> + | ++ <%= archive.category.title %> + | +
+ <%= archive.title %>
+
+
+
+ |
+
Find me in app/views/admin/archive_files/index.html.erb
+<%= render_filter @filter_fields %> +