Sha256: 8e1e0c39e840c48870fb8a8832bca6621bb91595e2a916d9642d6d87847c587f

Contents?: true

Size: 1.56 KB

Versions: 11

Compression:

Stored size: 1.56 KB

Contents

# = require lunr/lunr

define ['./states/index', './presenter'], (templates, presenter) ->

  # TODO move lunar and lunr to an extension
  luna =
    index : null
    store : Map()
    fields: ['name', 'description']
    sandbox:
      search:
       index: lunr
    initialize: (records) ->
      throw 'no records provided' unless records?

      @sample = records[0]
      @index  = @sandbox.search.index(@indexate)

      for record in records
        @index.add record
        @store.set record._id, record

      @store.all = records

    # TODO put bold face on matched texts
    search: (params...) ->
      findings = @index.search params...

      results = []
      results.push @store.get finding.ref for finding in findings

      @index.eventEmitter.emit 'searched', results
      results

    indexate: () ->
      sample = luna.sample
      fields = luna.fields

      sample[name] and @field name for name in fields
      @ref '_id'
      true


  # Widget Prototype

  type: 'Base'

  initialize: (options) ->
    widget  = @
    sandbox = @sandbox
    sandbox.logger.log "initialized!"

    record = sandbox.models[options.model]

    # Will also initialize sandbox!
    @html templates.default
    @$el.addClass 'list widget'

    # Forward the models to the presenter

    model.all (records) ->

      # Bind presenter to template
      presentation = presenter records, luna

      luna.initialize presentation.list.items
      luna.index.on 'searched', (results) ->
        sandbox.emit 'list.searched', results


      sandbox.view.bind widget.$el.children(), presentation

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
ende-0.2.3 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.2.2 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.2.1 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.2.0 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.1.14 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.1.13 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.1.12 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.1.11 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.1.10 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.1.9 lib/assets/javascripts/widgets/list/main.js.coffee
ende-0.1.8 lib/assets/javascripts/widgets/list/main.js.coffee