Sha256: 3d0a9a09dd62887faa69177831711029facfb181b705cc7a2add3682acf3db0b

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

module YeshuaCrm
  module Liquid
    class CellsDrop < ::Liquid::Drop

      def self.default_drop
        self.new Cell.visible.order(:name)
      end

      def initialize(cells)
        @cells = cells
      end

      def before_method(identifier)
        cell = @cells.where(:identifier => identifier).first || Cell.new
        CellDrop.new cell
      end

      def all
        @all ||= @cells.map do |cell|
          CellDrop.new cell
        end
      end

      def active
        @active ||= @cells.select(&:active?).map do |cell|
          CellDrop.new cell
        end
      end

      def each(&block)
        all.each(&block)
      end

      def size
        @cells.size
      end
    end

    class CellDrop < ::Liquid::Drop
      include ActionView::Helpers::UrlHelper

      delegate :id,
               :identifier,
               :name,
               :is_public,
               :description,
               :visible?,
               :active?,
               :archived?,
               :short_description,
               :start_date,
               :due_date,
               :overdue?,
               :completed_percent,
               :to => :@cell

      def initialize(cell)
        @cell = cell
      end

      def link
        link_to @cell.name, self.url
      end

      def url
        Rails.application.routes.url_helpers.cell_path(@cell)
      end

      def issues
        @issues ||= IssuesDrop.new @cell.issues.visible
      end

      def users
        @users ||= UsersDrop.new @cell.users
      end

      def subcells
        @subcells ||= CellsDrop.new @cell.children
      end

      def custom_field_values
        @cell.custom_field_values
      end         
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yeshua_crm-1.0.1 lib/yeshua_crm/liquid/drops/cells_drop.rb
yeshua_crm-1.0.0 lib/yeshua_crm/liquid/drops/cells_drop.rb