Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: fix: show orphaned student tasks #520

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions sencha-workspace/SlateTasksStudent/app/view/TaskTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,33 +186,44 @@ Ext.define('SlateTasksStudent.view.TaskTree', {
store = me.getStore(),
items = [],

rootTasks = store.queryBy(function(studentTask) {
return !studentTask.get('Task').ParentTaskID;
topLevelTaskIds = [],
topLevelTasks = store.queryBy(function(studentTask) {
if (!studentTask.get('Task').ParentTaskID) {
topLevelTaskIds.push(studentTask.get('TaskID'));
nbey marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
return false;
}),
topLevelTasksLength = topLevelTasks.getCount(),
topLevelTasksIndex = 0,

orphanedTasks = store.queryBy(function(studentTask) {
return topLevelTaskIds.indexOf(studentTask.get('TaskID')) === -1;
}),
rootTasksLength = rootTasks.getCount(),
rootTasksIndex = 0,
rootTask, rootTaskId, subTasks;
orphanedTasksLength = orphanedTasks.getCount(),
orphanedTasksIndex = 0,
topLevelTask, topLevelTaskId, subTasks;

// build tree of top-level tasks and subtasks
for (; rootTasksIndex < rootTasksLength; rootTasksIndex++) {
rootTask = rootTasks.getAt(rootTasksIndex);
rootTaskId = rootTask.get('TaskID');
for (; topLevelTasksIndex < topLevelTasksLength; topLevelTasksIndex++) {
topLevelTask = topLevelTasks.getAt(topLevelTasksIndex);
topLevelTaskId = topLevelTask.get('TaskID');

subTasks = store.queryBy(function(studentTask) { // eslint-disable-line no-loop-func
return studentTask.get('Task').ParentTaskID == rootTaskId && !studentTask.get('filtered');
return studentTask.get('Task').ParentTaskID == topLevelTaskId && !studentTask.get('filtered');
});

if (subTasks.getCount() > 0) {
rootTask.set('filtered', false); // do not filter parent tasks that have unfiltered subtasks
}
items.push({
studentTask: topLevelTask.getData(),
expanded: Boolean(expandedTasks[topLevelTask.getId()]),
subTasks: Ext.Array.pluck(subTasks.getRange(), 'data')
});
}

if (!rootTask.get('filtered')) {
items.push({
studentTask: rootTask.getData(),
expanded: Boolean(expandedTasks[rootTask.getId()]),
subTasks: Ext.Array.pluck(subTasks.getRange(), 'data')
});
}
for (; orphanedTasksIndex < orphanedTasksLength; orphanedTasksIndex++) {
items.push({
studentTask: orphanedTasks.getAt(orphanedTasksIndex).getData()
});
}

// render markup
Expand Down