class Ilog::Controllers::Index::Index
Constants
- GN
Public Class Methods
new()
click to toggle source
# File lib/ilog/controllers/index/index.rb, line 61 def initialize # puts 'here we go' + Ilog.configuration.namespaces.class.to_s @posts = ::Post.all # p 'getting posts = ' + @posts.to_s @stuffs = ::Stuff.all end
Public Instance Methods
call(params)
click to toggle source
# File lib/ilog/controllers/index/index.rb, line 100 def call(params) unless params[:page].nil? @page = params[:page] else @page = 0 end set_database params[:domain] self.perform(:retrive_all, params) end
next_page_url()
click to toggle source
# File lib/ilog/controllers/index/index.rb, line 71 def next_page_url if ( @last_page > @page.to_i) return '/index?page=' + (@page.to_i + 1).to_s end end
paginate(count, params, data)
click to toggle source
# File lib/ilog/controllers/index/index.rb, line 69 def paginate count, params, data @last_page = [(count / GN).ceil, 1].max def next_page_url if ( @last_page > @page.to_i) return '/index?page=' + (@page.to_i + 1).to_s end end def prev_page_url if (@page != 0) return '/index?page=' + [(@page.to_i - 1), 0].max.to_s else return nil end end return { 'current_page' => @page, 'data' => data, 'first_page_url' => '', # $this->url(1), 'from' => '', # $this->firstItem(), 'last_page' => @last_page, #$this->lastPage(), 'last_page_url' => '', #$this->url($this->lastPage()), 'next_page_url' => next_page_url, 'path' => '', # $this->path(), 'per_page' => GN, #$this->perPage(), 'prev_page_url' => prev_page_url, #$this->previousPageUrl(), 'to' => '', #$this->lastItem(), 'total' => count, } end
perform(function, params, input = nil)
click to toggle source
# File lib/ilog/controllers/index/index.rb, line 18 def perform function, params, input = nil timestamps = ::Dimensions::Timestamp.where(timestampable_type: 'Post').or(::Dimensions::Timestamp.where(timestampable_type: 'Stuff')).order(publish: :desc) data = {} puts 'how params is doing? ' + params.get(:id).to_s if params.get(:id).nil? puts 'wee are getting better' items_selected = timestamps.slice( GN * @page.to_i, GN ) items_selected.each_with_index do |item, index| piece = Object.const_get(item.timestampable_type.capitalize).find(item.timestampable_id) data[index] = JSON.parse(piece.to_json(:include => ['title', 'slug', 'timestamp', 'peoples', 'keywords'], :methods => [:kind, :uniq])) end else timestamp = ::Dimensions::Timestamp.where(timestampable_type: 'Post', timestampable_id: params[:id]).first retrive_index = timestamps.map(&:id).index(timestamp.id) @page = (timestamps.map(&:id).index(timestamp.id).to_i / GN).to_i items_selected = timestamps.slice( GN * @page.to_i, GN ) items_selected.each_with_index do |item, index| piece = Object.const_get(item.timestampable_type.capitalize).find(item.timestampable_id) data[index] = JSON.parse(piece.to_json(:include => ['title', 'slug', 'timestamp', 'peoples', 'keywords', 'thumbnail'], :methods => [:kind, :uniq])) if (item.id == timestamp.id) post = Object.const_get(timestamp.timestampable_type.capitalize).find(timestamp.timestampable_id) post.namespace = get_database params[:domain] data[index][:content] = post.content data[index][:view] = 'post_body' end end end @count = { 'posts' => 0, 'stuffs' => 0 } @stories = {} stories_timestamps = ::Dimensions::Timestamp.where(timestampable_type: 'Story', publish: (Time.now - 24.hours)..Time.now) stories_timestamps.each_with_index do |item, index| @stories[index] = Object.const_get(item.timestampable_type.capitalize).find(item.timestampable_id) end self.format = :json self.body = {:items => paginate(timestamps.count, params, data), :count => @count, :stories => @stories}.to_json end
prev_page_url()
click to toggle source
# File lib/ilog/controllers/index/index.rb, line 76 def prev_page_url if (@page != 0) return '/index?page=' + [(@page.to_i - 1), 0].max.to_s else return nil end end