socialforge/app/controllers/statistics_controller.rb

123 lines
3.4 KiB
Ruby
Raw Normal View History

2018-02-05 12:03:35 +08:00
class StatisticsController < ApplicationController
# GET /statistics
# GET /statistics.json
2018-02-06 17:41:39 +08:00
layout 'base_statistic'
before_filter :get_date, :only => [:index, :new]
2018-02-06 17:41:39 +08:00
2018-02-05 12:03:35 +08:00
def index
2018-02-08 15:12:36 +08:00
if params[:sub_category_id].present?
@statistics = Statistic.where(:sub_category_id => params[:sub_category_id])
else
@statistics = Statistic.all
end
@statistics_count = @statistics.count
@limit = 10
@is_remote = true
@statistics_pages = Paginator.new @statistics_count, @limit, params['page'] || 1
@offset ||= @statistics_pages.offset
@statistics = paginateHelper @statistics, @limit
2018-02-05 12:03:35 +08:00
respond_to do |format|
2018-02-08 15:12:36 +08:00
format.js
2018-02-05 12:03:35 +08:00
format.html # index.html.erb
format.json { render json: @statistics }
end
end
def search
end
2018-02-05 12:03:35 +08:00
# GET /statistics/1
# GET /statistics/1.json
def show
@statistic = Statistic.find(params[:id])
2018-02-05 15:13:03 +08:00
@attachments = @statistic.attachments
2018-02-05 12:03:35 +08:00
respond_to do |format|
format.html # show.html.erb
format.json { render json: @statistic }
end
end
# GET /statistics/new
# GET /statistics/new.json
def new
@statistic = Statistic.new
2018-02-08 10:28:45 +08:00
@sub_categories = @main_categories.first.sub_categories
2018-02-05 12:03:35 +08:00
respond_to do |format|
format.html # new.html.erb
format.json { render json: @statistic }
end
end
# GET /statistics/1/edit
def edit
@main_categories = MainCategory.all
2018-02-05 12:03:35 +08:00
@statistic = Statistic.find(params[:id])
main_category = MainCategory.find(@statistic.main_category_id)
@sub_categories = main_category.sub_categories
2018-02-05 12:03:35 +08:00
end
# POST /statistics
# POST /statistics.json
def create
@statistic = Statistic.new(params[:statistic])
2018-02-08 11:24:04 +08:00
@statistic.user_id = User.current.id
2018-02-05 15:13:03 +08:00
@statistic.save_attachments_containers(params[:attachments], User.current, true)
2018-02-05 12:03:35 +08:00
respond_to do |format|
if @statistic.save
format.html { redirect_to @statistic, notice: 'Statistic was successfully created.' }
format.json { render json: @statistic, status: :created, location: @statistic }
else
format.html { render action: "new" }
format.json { render json: @statistic.errors, status: :unprocessable_entity }
end
end
end
# PUT /statistics/1
# PUT /statistics/1.json
def update
@statistic = Statistic.find(params[:id])
respond_to do |format|
if @statistic.update_attributes(params[:statistic])
format.html { redirect_to @statistic, notice: 'Statistic was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @statistic.errors, status: :unprocessable_entity }
end
end
end
# DELETE /statistics/1
# DELETE /statistics/1.json
def destroy
@statistic = Statistic.find(params[:id])
@statistic.destroy
respond_to do |format|
format.html { redirect_to statistics_url }
format.json { head :no_content }
end
end
def get_sub_category
2018-02-08 15:37:30 +08:00
if params[:main_category_id] == "-1"
@sub_categories = SubCategory.all
else
main_category = MainCategory.find(params[:main_category_id])
@sub_categories = main_category.sub_categories
end
respond_to do |format|
format.js
end
end
private
def get_date
@main_categories = MainCategory.all
@sub_categories = params[:main_category_id].present? ? SubCategory.where(:main_category_id => params[:main_category_id]) : SubCategory.all
end
2018-02-05 12:03:35 +08:00
end