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] # def index # @page_title = 'My Aggregations' # respond_to do |format| # format.html { @aggregations = Aggregation.find_all_by_user_id(current_user.id, :order => 'title ASC') # render(:layout => 'reader') } # format.opml { @aggregations = Aggregation.find_all_by_user_id(current_user.id, :include =>:feeds, :order => 'feeds.title ASC') # render(:layout => false) } # format.xml { @aggregations = Aggregation.find_all_by_user_id(current_user.id, :order => 'title ASC') # render :xml => @aggregations } # end # end # # def manage # @page_title = 'Manage' # @user = current_user # @aggregations = Aggregation.find_all_by_user_id(@user.id, :order => 'title ASC') # respond_to do |format| # format.html # format.xml { render :xml => @aggregations } # 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]) # # @rss_title = @aggregation.title # @rss_description = 'View entries from all entries marked by ' + @user.login + ' in the aggregation ' + @aggregation.title # @entries = Entry.get_marked_entries_for_aggregation_and_user(@aggregation.id, @user.id, :limit => @per_page, :offset => (@per_page * @page)) # @page_title = 'Entries marked for ' + @aggregation.title # respond_to do |format| # format.html { render(:template => 'aggregations/show', :layout => false) } # format.xml { render :xml => @entries } # format.rss { render(:template => 'aggregations/show', :layout => false) } # end # end # # def all # @page_title = 'View entries from all aggregations' # # @aggregation = Aggregation.new # @aggregation.title = @page_title # # @rss_title = @aggregation.title # @rss_description = 'View entries from all aggregations' # # @entries = Entry.get_entries_for_user(params[:user_id], :limit => @per_page, :offset => (@per_page * @page)) # respond_to do |format| # format.html { render(:template => 'aggregations/show', :layout => false) } # format.xml { render :xml => @entries } # format.rss { render(:template => 'aggregations/show', :layout => false) } # end # end # # def all_photos # @page_title = 'View photos from all aggregations' # @aggregation = Aggregation.new # @aggregation.title = @page_title # @photos = EntryImage.get_photos_for_user(params[:user_id], :limit => @per_page, :offset => (@per_page * @page)) # respond_to do |format| # format.html { render(:template => 'aggregations/photos', :layout => false) } # format.xml { render :xml => @photos } # end # end # # def photos # @aggregation = Aggregation.find(params[:id]) # @page_title = "View photos from #{@aggregation.title}" # @photos = EntryImage.get_entry_images_for_aggregation(@aggregation.id, :limit => @per_page, :offset => (@per_page * @page)) # respond_to do |format| # format.html { render(:template => 'aggregations/photos', :layout => false) } # format.xml { render :xml => @photos } # end # end # # def bookmarks # @aggregation = Aggregation.find(params[:id]) # @page_title = "View bookmarks from #{@aggregation.title}" # @entries = Entry.get_bookmarks_for_aggregation(@aggregation.id, -1, :limit => @per_page, :offset => (@per_page * @page)) # respond_to do |format| # format.html { render(:template => 'aggregations/bookmarks', :layout => false) } # format.xml { render :xml => @entries } # end # end # # def read_photos # @page_title = 'View photos from read entries' # @aggregation = Aggregation.new # @aggregation.title = @page_title # @photos = EntryImage.get_read_photos_for_user(params[:user_id], :limit => @per_page, :offset => (@per_page * @page)) | [] # respond_to do |format| # format.html { render(:template => 'aggregations/photos', :layout => false) } # format.xml { render :xml => @photos } # end # end # # def marked_photos # @page_title = 'View photos from marked entries' # @aggregation = Aggregation.new # @aggregation.title = @page_title # @photos = EntryImage.get_marked_photos_for_user(params[:user_id], :limit => @per_page, :offset => (@per_page * @page)) | [] # respond_to do |format| # format.html { render(:template => 'aggregations/photos', :layout => false) } # format.xml { render :xml => @photos } # end # end # # def marked # @page_title = 'View entries that I have marked' # @aggregation = Aggregation.new # @aggregation.title = @page_title # @user = User.find(params[:user_id]) # # @rss_title = @aggregation.title # @rss_description = 'View entries from all entries marked by ' + @user.login # # @entries = Entry.get_marked_entries_for_user(@user.id, :limit => @per_page, :offset => (@per_page * @page)) # respond_to do |format| # format.html { render(:template => 'aggregations/show', :layout => false) } # format.xml { render :xml => @entries } # format.rss { render(:template => 'aggregations/show', :layout => false) } # end # end # # def read # @page_title = 'View entries I have read' # @aggregation = Aggregation.new # @aggregation.title = @page_title # @entries = Entry.get_entries_read_for_user(current_user.id, :limit => @per_page, :offset => (@per_page * @page)) # respond_to do |format| # format.html { render(:template => 'aggregations/show', :layout => false) } # format.xml { render :xml => @entries } # end # end # # def duplicate # @page_title = 'Duplicate Aggregation' # # @aggregation = Aggregation.find(params[:id], :include => 'feeds') # @new_aggregation = Aggregation.new # # @new_aggregation.title = @aggregation.title # @new_aggregation.description = @aggregation.description # @new_aggregation.user_id = current_user.id # # success = false # if @new_aggregation.save # @page_title = 'Added aggregation ' + @new_aggregation.title # @aggregation.feeds.each do |feed| # @new_aggregation.feeds << feed # end # success = true # end # # respond_to do |format| # if success # flash[:notice] = "Successfully added the " + @new_aggregation.title + " to your aggregations" # format.html { redirect_to(CGI::unescape(params[:return_page])) if params[:return_page] } # format.xml { render :xml => @new_aggregation, :status => :created, :location => @new_aggregation } # else # flash[:notice] = "Some kind of bad thing happened when we tried to add the requested aggregation to your account. We'll look into it. If you want press the back button and try again. If that doesn't work yell at the computer for a bit, it always helps me feel better. Believe me we are just as upset about all this as you are." # format.html # format.xml { render :xml => @new_aggregation.errors } # end # end # end def new @page_title = I18n.t('muck.raker.new_aggregation') @service_categories = ServiceCategory.sorted.find(:all, :include => [:tag_services]) respond_to do |format| format.html { render :template => 'aggregations/new' } 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]) # flash[:notice] = 'Aggregation was successfully updated.' # format.html { redirect_to(manage_user_aggregations_path(:user_id => current_user.id)) } # format.xml { head :ok } # else # format.html { render :action => "edit" } # format.xml { render :xml => @aggregation.errors } # end # end # end # # def destroy # @aggregation = Aggregation.find(params[:id]) # @aggregation.destroy # # respond_to do |format| # flash[:notice] = @aggregation.title + ' has been removed.' # format.html { redirect_to(manage_user_aggregations_url(current_user)) } # format.xml { head :ok } # end # end # # associate an existing feed with an aggregation # def associate_feed # @aggregation = Aggregation.find(params[:id]) # @feed = Feed.find(params[:feed_id]) # current_feed = @aggregation.feeds.find(@feed) rescue nil # # if current_feed.nil? # @aggregation.feeds << @feed # notice = @feed.title + ' was successfully added to ' + @aggregation.title # else # notice = @feed.title + ' is already a part of ' + @aggregation.title # end # # respond_to do |format| # if params[:search_terms] # redirect_path = url_for({:controller => 'feeds', :action => 'search', :aggregation_id => @aggregation, :id => @feed, :search_terms => params[:search_terms]}) # else # redirect_path = aggregation_feeds_url(@aggregation) # end # # if @aggregation.save # flash[:notice] = notice # format.html { redirect_to(redirect_path) } # format.xml { render :xml => @aggregation, :status => :added_feed, :location => @aggregation } # else # flash[:notice] = 'Could not add ' + @feed.title + ' to ' + @aggregation.title # format.html { redirect_to(redirect_path) } # format.xml { render :xml => @aggregation.errors } # end # end # end # # #disassciates a feed from an aggregation # def remove_feed # @aggregation = Aggregation.find(params[:id]) # @feed = Feed.find(params[:feed_id]) # @aggregation.feeds.delete(@feed) # respond_to do |format| # if @aggregation.save # flash[:notice] = @feed.title + ' was successfully removed from ' + @aggregation.title # format.html { redirect_to(aggregation_feeds_path(@aggregation)) } # format.xml { render :xml => @aggregation, :status => :removed_feed, :location => @aggregation } # else # flash[:notice] = 'Could not remove ' + @feed.title + ' from ' + @aggregation.title # format.html { redirect_to(aggregation_feeds_path(@aggregation)) } # format.xml { render :xml => @aggregation.errors } # end # end # end protected def get_owner @parent = get_parent unless has_permission? permission_denied end end def get_aggregation @aggregation = Aggregation.find(params[:id]) end def has_aggregation_permission? if !@aggregation.can_edit?(current_user) message = I18n.t('muck.raker.cant_modify_aggregation') respond_to do |format| format.html do flash[:notice] = message redirect_back_or_default current_user end format.js { render(:update) {|page| page.alert message} } end end end def has_permission? if @parent.blank? admin? else @parent.can_edit?(current_user) end end end