Skip to content

Commit

Permalink
search functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnycrab committed Jun 30, 2013
1 parent d8a1765 commit 7bf1b65
Show file tree
Hide file tree
Showing 31 changed files with 5,612 additions and 108 deletions.
8 changes: 5 additions & 3 deletions app/app/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ define [

($, _, Backbone, Handlebars) ->



app =
root: '/'
pendingTemplateReqs: {}
JST = window.JST = window.JST || {}
JST = app.JST = app.JST || {}

Backbone.NMLayout = Backbone.Layout.extend
# this function checks if the layout has initially been rendered. This is useful for setting views in a layout later,
Expand All @@ -28,6 +26,10 @@ define [
@.setView selector, view
if @.__manager__.hasRendered then view.render()

insertViewAndRenderMaybe: (selector, view) ->
@insertView selector, view
if @.__manager__.hasRendered then view.render()

Backbone.Layout.configure
manage: true

Expand Down
8 changes: 7 additions & 1 deletion app/app/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/app/config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ require.config
'plugins/backbone.JJRestApi' : ['backbone']

'modules/NMMarkdownParser' : ['plugins/editor/jquery.jjmarkdown']

'plugins/visualsearch/jquery.ui.autocomplete' : ['plugins/visualsearch/jquery.ui.widget']
'plugins/visualsearch/jquery.ui.menu' : ['plugins/visualsearch/jquery.ui.widget']
'plugins/visualsearch/visualsearch' : ['plugins/backbone.layoutmanager', 'plugins/visualsearch/jquery.ui.core', 'plugins/visualsearch/jquery.ui.autocomplete', 'plugins/visualsearch/jquery.ui.menu']

5 changes: 4 additions & 1 deletion app/app/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions app/app/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,15 @@ require [
app.resolveClassTypeByHash = (uglyHash) ->
@.Config.ClassEnc[uglyHash.substr(0,1)]

app.wholePortfolioJSON = ->
wholePortfolio = @Cache.WholePortfolio
unless @Cache.WholePortfolioJSON
tmp = []
for model in wholePortfolio
tmp.push model.toJSON()
@Cache.WholePortfolioJSON = tmp
@Cache.WholePortfolioJSON

app.bindListeners()


Expand Down
14 changes: 14 additions & 0 deletions app/app/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 4 additions & 9 deletions app/app/modules/DataRetrieval.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,17 @@ define [
returnDfd.resolve()
returnDfd.promise()


# function that takes a search term used to filter the whole portfolio
filterProjectTypesBySearchTerm: (searchTerm) ->
wholePortfolio = app.Cache.WholePortfolio

# because of simplicity reasons we iterate over an array of json objects. let's cache the whole json portfolio
unless app.Cache.WholePortfolioJSON
tmp = []
for model in wholePortfolio
tmp.push model.toJSON()
app.Cache.WholePortfolioJSON = tmp

# transform the searchTerm
searchObj = ProjectSearch.transformSearchTerm searchTerm
console.log searchObj
console.log 'Search obj found by data retrieval: %o', searchObj

result = _.filter app.Cache.WholePortfolioJSON, (model) ->
# because of simplicity reasons we iterate over an array of json objects.
result = _.filter app.wholePortfolioJSON(), (model) ->
result = true
_.each searchObj, (vals, key) ->
if not ProjectSearch.test(model, key, vals) then result = false
Expand Down
14 changes: 3 additions & 11 deletions app/app/modules/DataRetrieval.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 41 additions & 4 deletions app/app/modules/Portfolio.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,25 @@ define [
Backbone.Events.on 'search', @handleSearch, @

handleSearch: (searchResults) ->
console.log 'searched for: %o', searchResults
console.log @
if @__manager__.hasRendered
@triggerSearchOnChildren searchResults
else
@searchResults = searchResults
@doSearchAfterRender = true

triggerSearchOnChildren: (searchResults) ->
console.log searchResults
# iterate over child views and check if their model is present in the search results
_.each @views['.packery'], (childView) ->
model = childView.model
# always show when there is no search
unless searchResults
childView.doShow()
else
found = _.find searchResults, (result) ->
return result is childView.model
method = if found then 'doShow' else 'doHide'
childView[method]()


beforeRender: ->
Expand All @@ -32,15 +49,27 @@ define [
@.insertView '.packery', new Portfolio.Views.ListItem({ model: model, linkTo: @.options.linkTo })

_afterRender: ->
console.log @
if @doSearchAfterRender
@triggerSearchOnChildren @searchResults
@doSearchAfterRender = false
@searchResults = null
# debugger


Portfolio.Views.ListItem = Backbone.View.extend
tagName: 'article'
className: 'packery-item resizable'
template: 'packery-list-item'
serialize: () ->

doShow: ->
console.log 'showing %o', @model
@.$el.removeClass 'hidden'

doHide: ->
console.log 'hiding %o', @model
@.$el.addClass 'hidden'

serialize: ->
data = if @.model then @.model.toJSON() else {}
data.Persons = _.sortBy data.Persons, (person) ->
return person.Surname
Expand Down Expand Up @@ -117,6 +146,14 @@ define [
else
return niceDate

Handlebars.registerHelper 'SpaceAndLocation', ->
out = []
if @Space then out.push @Space
if @Location then out.push @Location
out.join ', '
if out
"<p>#{out}</p>"

Handlebars.registerHelper 'portfoliolist', (items, title, options) ->
if not options
options = title
Expand Down
54 changes: 51 additions & 3 deletions app/app/modules/Portfolio.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7bf1b65

Please sign in to comment.