app/controllers/muck/aggregations_controller.rb in muck-raker-0.1.33 vs app/controllers/muck/aggregations_controller.rb in muck-raker-0.1.35

- old
+ new

@@ -1,9 +1,12 @@ class Muck::AggregationsController < ApplicationController + unloadable + require 'cgi' + before_filter :login_required, :except => [:show] before_filter :get_owner, :only => [:index, :new, :create] before_filter :has_permission?, :only => [:index, :new, :create] before_filter :get_aggregation, :only => [:destroy, :update] before_filter :has_aggregation_permission?, :only => [:destroy, :update] @@ -27,29 +30,22 @@ # respond_to do |format| # format.html # format.xml { render :xml => @aggregations } # end # end - # - # def show - # @aggregation = Aggregation.find(params[:id]) - # user_id = -1 - # user_id = current_user.id unless current_user.nil? - # - # @rss_title = @aggregation.title - # @rss_description = @aggregation.description - # - # @entries = Entry.get_entries_for_aggregation(@aggregation.id, user_id, :limit => @per_page, :offset => (@per_page * @page)) - # @page_title = @aggregation.title - # respond_to do |format| - # format.html { render(:layout => false) } - # format.opml { render(:layout => false) } - # format.xml { render :xml => @entries } - # format.rss { render(:template => 'aggregations/show', :layout => false) } - # end - # end - # + + def show + @aggregation = Aggregation.find(params[:id]) + @page_title = @aggregation.title + @entries = @aggregation.feeds.entries.paginate(:page => @page, :per_page => @per_page) + respond_to do |format| + format.html { render(:template => 'aggregations/show') } + format.opml { render(:layout => false) } + format.rss {} + end + end + # def show_marked # # @user = User.find(params[:user_id]) # @aggregation = Aggregation.find(params[:id]) # @@ -200,32 +196,43 @@ respond_to do |format| format.html { render :template => 'aggregations/new' } end end - # def edit - # @aggregation = Aggregation.find(params[:id]) - # @page_title = 'Editing ' + @aggregation.title - # end - # - # def create - # @aggregation = Aggregation.new(params[:aggregation]) - # @aggregation.name = make_safe_uri(@aggregation.title) - # @aggregation.user = current_user - # - # respond_to do |format| - # if @aggregation.save - # flash[:notice] = @aggregation.title + ' created. Now add some feeds:' - # format.html { redirect_to(new_aggregation_feed_path(@aggregation)) } - # format.xml { render :xml => @aggregation, :status => :created, :location => @aggregation } - # else - # format.html { render :action => "new" } - # format.xml { render :xml => @aggregation.errors } - # end - # end - # end - # + def create + @aggregation = Aggregation.new(params[:aggregation]) + @aggregation.title = @aggregation.terms.humanize if @aggregation.terms + @aggregation.save! + + # build a list of feeds and associate them with the aggregation + @aggregation.add_feeds(current_user, params[:service_ids]) + + # associate the parent if present + @parent.aggregations << @aggregation if @parent + + respond_to do |format| + flash[:notice] = I18n.t('muck.raker.add_feeds_to_aggregation', :title => @aggregation.title) + format.html { redirect_to(edit_aggregation_path(@aggregation)) } + format.xml { render :xml => @aggregation, :status => :created, :location => @aggregation } + end + + rescue ActiveRecord::RecordInvalid => ex + respond_to do |format| + format.html { render :action => "aggregations/new" } + format.xml { render :xml => @aggregation.errors } + end + end + + def edit + @aggregation = Aggregation.find(params[:id]) + @service_categories = ServiceCategory.sorted.find(:all, :include => [:tag_services]) + @page_title = I18n.t('muck.raker.edit_aggregation_title', :title => @aggregation.title) + respond_to do |format| + format.html { render :template => 'aggregations/edit' } + end + end + # def update # @aggregation = Aggregation.find(params[:id]) # # respond_to do |format| # if @aggregation.update_attributes(params[:aggregation]) @@ -301,11 +308,14 @@ # end protected def get_owner - setup_parent + @parent = get_parent + unless has_permission? + permission_denied + end end def get_aggregation @aggregation = Aggregation.find(params[:id]) end @@ -322,9 +332,13 @@ end end end def has_permission? - @parent.can_edit?(current_user) + if @parent.blank? + admin? + else + @parent.can_edit?(current_user) + end end end