Skip to content

Commit

Permalink
Merged source-list branch into master
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 874b5d1
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Wed Aug 7 15:07:29 2013 -0700

    Added brief descriptions of multi array controller and source list view

commit ba8fffc
Merge: 81d7201 0ceaf9b
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Wed Aug 7 12:52:37 2013 -0700

    Merge branch 'source-list' of github.com:realityendshere/emberella into source-list

commit 81d7201
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Wed Aug 7 12:33:09 2013 -0700

    Made `arrangedContent` computation function length 2

commit 7f750a0
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Mon Aug 5 15:53:50 2013 -0700

    Reduced selection change event triggering

commit d89aa49
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Mon Aug 5 12:55:06 2013 -0700

    Improved computation of "active" selection

    The "active" selection is typically the intersection of the current selection set and the current content array. That is, an item only appears actively selected when it is both in the selection set and the content.

    A new `getActiveContent` method for determining the content array from which active selections must be a member of was added to allow multi array controllers and the selectable mixin to work together.

commit 5345e2a
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Mon Aug 5 12:13:15 2013 -0700

    Added `getFlattenedContent` method to multi array controller

    Method flattens content across arrays/sub-arrays recursively to return a single array of items.

commit e6bbfcd
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Mon Aug 5 12:09:22 2013 -0700

    Moved source list item template definition to item class

    Item view templates are no longer inherited from the containing source list view.

    This maintains consistency with Ember's built in collection views.

commit aa4d73e
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Fri Aug 2 16:46:53 2013 -0700

    Added class to base source list; prevented element ID from being copied to child lists

commit 715e113
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Fri Aug 2 16:26:39 2013 -0700

    Added emberella-source-collection class name

commit c88f3a8
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Fri Aug 2 16:18:18 2013 -0700

    Refactored source list view to render heading independently of listing

    Added a bit of binding complexity… but...

    Duplicate headings are much more unlikely (if not impossible)

    Headings don't flicker when items are added to or removed from the list

    Added a computed property for finding the root source listing

commit 38fc34c
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Thu Aug 1 21:14:37 2013 -0700

    Fixed a bug that would cause extra content to appear in multi arrays

commit be95f74
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Thu Aug 1 20:45:02 2013 -0700

    Added documentation (comments) and minor refactoring

commit 93ddad5
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Thu Aug 1 18:11:21 2013 -0700

    Created multi array controller and source list view

commit 0ceaf9b
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Wed Aug 7 12:33:09 2013 -0700

    Made `arrangedContent` computation function length 2

commit b04d152
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Mon Aug 5 15:53:50 2013 -0700

    Reduced selection change event triggering

commit cb5d6a7
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Mon Aug 5 12:55:06 2013 -0700

    Improved computation of "active" selection

    The "active" selection is typically the intersection of the current selection set and the current content array. That is, an item only appears actively selected when it is both in the selection set and the content.

    A new `getActiveContent` method for determining the content array from which active selections must be a member of was added to allow multi array controllers and the selectable mixin to work together.

commit 32b17fa
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Mon Aug 5 12:13:15 2013 -0700

    Added `getFlattenedContent` method to multi array controller

    Method flattens content across arrays/sub-arrays recursively to return a single array of items.

commit 5c00af8
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Mon Aug 5 12:09:22 2013 -0700

    Moved source list item template definition to item class

    Item view templates are no longer inherited from the containing source list view.

    This maintains consistency with Ember's built in collection views.

commit 3bc63cb
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Fri Aug 2 16:46:53 2013 -0700

    Added class to base source list; prevented element ID from being copied to child lists

commit 0fb02a8
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Fri Aug 2 16:26:39 2013 -0700

    Added emberella-source-collection class name

commit 0a5a77c
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Fri Aug 2 16:18:18 2013 -0700

    Refactored source list view to render heading independently of listing

    Added a bit of binding complexity… but...

    Duplicate headings are much more unlikely (if not impossible)

    Headings don't flicker when items are added to or removed from the list

    Added a computed property for finding the root source listing

commit e2ce558
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Thu Aug 1 21:14:37 2013 -0700

    Fixed a bug that would cause extra content to appear in multi arrays

commit 627e531
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Thu Aug 1 20:45:02 2013 -0700

    Added documentation (comments) and minor refactoring

commit 74e8188
Author: Dana Franklin <danaf@mediaartslab.com>
Date:   Thu Aug 1 18:11:21 2013 -0700

    Created multi array controller and source list view
  • Loading branch information
Dana Franklin committed Aug 7, 2013
1 parent 4dede8e commit a52183c
Show file tree
Hide file tree
Showing 5 changed files with 654 additions and 11 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ While waiting for data to load, the SparseArrayController will return
placeholder objects. Loaded records are "cached" in a sparse array until the
`reset` or `unset` methods get called.

**Emberella.MultiArrayController**

Nest multiple array controllers into a single controller. The array of arrays
can be used to structure data for a source listing view.

### Helper(s)

**big_data_helpers**
Expand Down Expand Up @@ -235,6 +240,10 @@ image is about to be fetched and when loading is complete.

A wrapper for a "range" type input.

**Emberella.SourceListView**

Renders a source list view that renders multiple lists with headings.

**Emberella.StarRating**

Want to give something 5 stars? That's what this view is for. You'll need to
Expand Down
95 changes: 95 additions & 0 deletions packages/emberella/lib/controllers/multi_array_controller.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
###
@module emberella
@submodule emberella-controllers
###

Emberella = window.Emberella
get = Ember.get
set = Ember.set

###
Assembles an array of array controllers.
@example
// Sets `arrangedContent` to an array containing the array controllers
// App.PeopleController, App.PlacesController, and App.ThingsController
App.SidebarController = Emberella.MultiArrayController.extend({
subArrays: ['people', 'places', 'things']
});
@class MultiArrayController
@namespace Emberella
@extends Ember.ArrayController
###
Emberella.MultiArrayController = Ember.ArrayController.extend
init: ->
@_subArraysDidChange()
@_super()

###
An array of strings describing the names of array controllers to include
as part of the `arrangedContent`. Sub-controllers will be arranged in the
order listed.
@property subArrays
@type Array
@default []
###
subArrays: []

arrangedContent: Ember.computed (key, value) ->
subArrays = Ember.A get(@, 'subArrays')
subArrays = subArrays.uniq() unless get(@, 'allowDuplicates')

selfContent = @_super(key, value)

[].concat((if Ember.isArray(selfContent) then selfContent else []), subArrays.map((name) =>
controller = get(@, 'controllers.' + name)
heading = Ember.String.capitalize(name)

Ember.Object.create({
heading: heading
children: controller
})
))
.property('content', 'sortProperties.@each', 'needs.@each', 'subArrays.@each')


###
Assembles array of objects contained in this mixed array controller and all
descendant arrays.
@method getFlattenedContent
@return Array
###
getFlattenedContent: ->
arrangedContent = get @, 'arrangedContent'

flatten = (input, arr = Ember.A()) ->
item = get(input, 'children') || input

if Ember.isArray(item)
item.forEach((value) ->
flatten(value, arr)
)
else
arr.push item

arr

flatten arrangedContent


###
@private
Ensure sub-arrays are also added to the `needs` array so they can be
accessed by this controller.
@method _subArraysDidChange
@chainable
###
_subArraysDidChange: Ember.observer ->
Ember.A(get(@, 'needs')).addObjects(Ember.A(get(@, 'subArrays')))
@
, 'subArrays', 'subArrays.@each'
2 changes: 2 additions & 0 deletions packages/emberella/lib/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@
#= require ./views/tags_input
#= require ./views/autocomplete
#= require ./views/autocomplete_tags
#= require ./views/source_list_view

#= require ./controllers/sparse_array_controller
#= require ./controllers/multi_array_controller
38 changes: 27 additions & 11 deletions packages/emberella/lib/mixins/selectable_mixin.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Emberella.SelectableMixin = Ember.Mixin.create
###
isSelectable: true #quack like a duck

init: ->
set @, '_selection', new Emberella.SelectionSet()
@_super()

# allowsSelection: true #TODO: Enable this setting

# allowsMultipleSelection: true #TODO: Enable this setting
Expand Down Expand Up @@ -56,21 +60,22 @@ Emberella.SelectableMixin = Ember.Mixin.create
_selection: null

###
Contains intersection of `_selection` and `content`. This allows a
selection to be retained even if, for example, a filter removes a selected
object from the `content` property. When the filter is removed, the
previously selected object will, once again, appear to be selected.
The "active" selection: an array of items selected by the user that are
also present in the content array. This allows the selection to be retained
even if, for example, a filter removes a selected object from the `content`
property. When the filter is removed, the previously selected object will,
once again, appear to be selected.
@property selection
@type Array
@default []
###
# TODO: Fix excessive array creation
selection: Ember.computed ->
content = get(@, 'content')
content = @getActiveContent()
selection = get(@, '_selection')
selection.filter((item) -> content.contains(item))
.property('_selection.[]', 'content.[]')
.property('_selection.[]', 'content.[]', 'arrangedContent.[]')

###
The first member of the content array that would be a valid selection. The
Expand All @@ -96,9 +101,18 @@ Emberella.SelectableMixin = Ember.Mixin.create
get(@, 'lastObject')
.property 'lastObject'

init: ->
set @, '_selection', new Emberella.SelectionSet()
@_super()
###
Retrieve an array of items that could appear in the active selection.
The default behavior is simply to return the `content` array. Override this
method to intorduce custom retrieval or assembly of the array of
potentially selectable items.
@method getActiveContent
@return Array
###
getActiveContent: ->
get(@, 'content')

###
Manipulate the selection set.
Expand Down Expand Up @@ -129,7 +143,7 @@ Emberella.SelectableMixin = Ember.Mixin.create

if toggle or range
if toggle
if @inSelection(item) then @deselectObjects(item) else @selectObjects(item)
if @inSelection(item) then @deselectObject(item) else @selectObject(item)
else if range
targetIdx = +@indexOf(item)
indexOfCursor = @indexOfCursor()
Expand All @@ -138,8 +152,10 @@ Emberella.SelectableMixin = Ember.Mixin.create
selectionRange = [start..end]
@selectObjects(selectionRange)
else
Ember.beginPropertyChanges(@)
@deselectAll() unless retainSelection
@selectObjects(item)
@selectObject(item)
Ember.endPropertyChanges(@)

@

Expand Down
Loading

0 comments on commit a52183c

Please sign in to comment.