@@ -18,6 +18,15 @@ import Model from '@ember-data/model';
18
18
@private
19
19
*/
20
20
export default DataAdapter . extend ( {
21
+ /**
22
+ Specifies how records can be filtered based on the state of the record
23
+ Records returned will need to have a `filterValues`
24
+ property with a key for every name in the returned array
25
+ @public
26
+ @method getFilters
27
+ @return {Array } List of objects defining filters
28
+ The object should have a `name` and `desc` property
29
+ */
21
30
getFilters ( ) {
22
31
return [
23
32
{ name : 'isNew' , desc : 'New' } ,
@@ -26,10 +35,24 @@ export default DataAdapter.extend({
26
35
] ;
27
36
} ,
28
37
38
+ /**
39
+ Detect whether a class is a DS.Model
40
+ @public
41
+ @method detect
42
+ @param {DS.Model } typeClass
43
+ @return {Boolean } Whether the typeClass is a DS.Model class or not
44
+ */
29
45
detect ( typeClass ) {
30
46
return typeClass !== Model && Model . detect ( typeClass ) ;
31
47
} ,
32
48
49
+ /**
50
+ Creates a human readable string used for column headers
51
+ @public
52
+ @method columnNameToDesc
53
+ @param {String } name The attribute name
54
+ @return {String } Human readable string based on the attribute name
55
+ */
33
56
columnNameToDesc ( name ) {
34
57
return capitalize (
35
58
underscore ( name )
@@ -38,6 +61,15 @@ export default DataAdapter.extend({
38
61
) ;
39
62
} ,
40
63
64
+ /**
65
+ Get the columns for a given model type
66
+ @public
67
+ @method columnsForType
68
+ @param {DS.Model } typeClass
69
+ @return {Array } An array of columns of the following format:
70
+ name: {String} The name of the column
71
+ desc: {String} Humanized description (what would show in a table column name)
72
+ */
41
73
columnsForType ( typeClass ) {
42
74
let columns = [
43
75
{
@@ -57,6 +89,16 @@ export default DataAdapter.extend({
57
89
return columns ;
58
90
} ,
59
91
92
+ /**
93
+ Fetches all loaded records for a given type
94
+ @public
95
+ @method getRecords
96
+ @param {DS.Model } modelClass of the record
97
+ @param {String } modelName of the record
98
+ @return {Array } An array of DS.Model records
99
+ This array will be observed for changes,
100
+ so it should update when new records are added/removed
101
+ */
60
102
getRecords ( modelClass , modelName ) {
61
103
if ( arguments . length < 2 ) {
62
104
// Legacy Ember.js < 1.13 support
@@ -72,6 +114,14 @@ export default DataAdapter.extend({
72
114
return this . get ( 'store' ) . peekAll ( modelName ) ;
73
115
} ,
74
116
117
+ /**
118
+ Gets the values for each column
119
+ This is the attribute values for a given record
120
+ @public
121
+ @method getRecordColumnValues
122
+ @param {DS.Model } record to get values from
123
+ @return {Object } Keys should match column names defined by the model type
124
+ */
75
125
getRecordColumnValues ( record ) {
76
126
let count = 0 ;
77
127
let columnValues = { id : get ( record , 'id' ) } ;
@@ -85,6 +135,13 @@ export default DataAdapter.extend({
85
135
return columnValues ;
86
136
} ,
87
137
138
+ /**
139
+ Returns keywords to match when searching records
140
+ @public
141
+ @method getRecordKeywords
142
+ @param {DS.Model } record
143
+ @return {Array } Relevant keywords for search based on the record's attribute values
144
+ */
88
145
getRecordKeywords ( record ) {
89
146
let keywords = [ ] ;
90
147
let keys = A ( [ 'id' ] ) ;
@@ -93,6 +150,14 @@ export default DataAdapter.extend({
93
150
return keywords ;
94
151
} ,
95
152
153
+ /**
154
+ Returns the values of filters defined by `getFilters`
155
+ These reflect the state of the record
156
+ @public
157
+ @method getRecordFilterValues
158
+ @param {DS.Model } record
159
+ @return {Object } The record state filter values
160
+ */
96
161
getRecordFilterValues ( record ) {
97
162
return {
98
163
isNew : record . get ( 'isNew' ) ,
@@ -101,6 +166,14 @@ export default DataAdapter.extend({
101
166
} ;
102
167
} ,
103
168
169
+ /**
170
+ Returns a color that represents the record's state
171
+ @public
172
+ @method getRecordColor
173
+ @param {DS.Model } record
174
+ @return {String } The record color
175
+ Possible options: black, blue, green
176
+ */
104
177
getRecordColor ( record ) {
105
178
let color = 'black' ;
106
179
if ( record . get ( 'isNew' ) ) {
@@ -111,6 +184,15 @@ export default DataAdapter.extend({
111
184
return color ;
112
185
} ,
113
186
187
+ /**
188
+ Observes all relevant properties and re-sends the wrapped record
189
+ when a change occurs
190
+ @public
191
+ @method observerRecord
192
+ @param {DS.Model } record
193
+ @param {Function } recordUpdated Callback used to notify changes
194
+ @return {Function } The function to call to remove all observers
195
+ */
114
196
observeRecord ( record , recordUpdated ) {
115
197
let releaseMethods = A ( ) ;
116
198
let keysToObserve = A ( [ 'id' , 'isNew' , 'hasDirtyAttributes' ] ) ;
0 commit comments