| 211 | } |
| 212 | |
| 213 | sortMembers (highestUserLevelCountMap, userConceptsMap) { |
| 214 | // Progress sort precedence: most completed concepts, most started concepts, most levels, name sort |
| 215 | if ((this.members == null) || (this.memberSort == null)) { return } |
| 216 | switch (this.memberSort) { |
| 217 | case 'nameDesc': |
| 218 | this.members.comparator = (a, b) => (b.get('name') || 'Anonymous').localeCompare(a.get('name') || 'Anonymous') |
| 219 | break |
| 220 | case 'progressAsc': |
| 221 | this.members.comparator = function (a, b) { |
| 222 | let concept, state |
| 223 | const aComplete = ((() => { |
| 224 | const result = [] |
| 225 | for (concept in userConceptsMap[a.id]) { |
| 226 | state = userConceptsMap[a.id][concept] |
| 227 | if (state === 'complete') { |
| 228 | result.push(concept) |
| 229 | } |
| 230 | } |
| 231 | return result |
| 232 | })()) |
| 233 | const bComplete = ((() => { |
| 234 | const result1 = [] |
| 235 | for (concept in userConceptsMap[b.id]) { |
| 236 | state = userConceptsMap[b.id][concept] |
| 237 | if (state === 'complete') { |
| 238 | result1.push(concept) |
| 239 | } |
| 240 | } |
| 241 | return result1 |
| 242 | })()) |
| 243 | const aStarted = ((() => { |
| 244 | const result2 = [] |
| 245 | for (concept in userConceptsMap[a.id]) { |
| 246 | state = userConceptsMap[a.id][concept] |
| 247 | if (state === 'started') { |
| 248 | result2.push(concept) |
| 249 | } |
| 250 | } |
| 251 | return result2 |
| 252 | })()) |
| 253 | const bStarted = ((() => { |
| 254 | const result3 = [] |
| 255 | for (concept in userConceptsMap[b.id]) { |
| 256 | state = userConceptsMap[b.id][concept] |
| 257 | if (state === 'started') { |
| 258 | result3.push(concept) |
| 259 | } |
| 260 | } |
| 261 | return result3 |
| 262 | })()) |
| 263 | if (aComplete < bComplete) { |
| 264 | return -1 |
| 265 | } else if (aComplete > bComplete) { |
| 266 | return 1 |
| 267 | } else if (aStarted < bStarted) { |
| 268 | return -1 |
| 269 | } else if (aStarted > bStarted) { return 1 } |
| 270 | if (highestUserLevelCountMap[a.id] < highestUserLevelCountMap[b.id]) { |