Skip to content

Commit

Permalink
Merge pull request #703 from ubc/#693-fix-user-dropdown-sorting
Browse files Browse the repository at this point in the history
Fix user dropdown order
  • Loading branch information
andrew-gardener authored Feb 6, 2018
2 parents 2c85f2c + c365fa2 commit c08bdc6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 27 deletions.
26 changes: 17 additions & 9 deletions compair/static/modules/assignment/assignment-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ module.controller("AssignmentViewController",
$scope.canManageAssignment = resolvedData.canManageAssignment;
$scope.allStudents = resolvedData.students.objects;
$scope.instructors = resolvedData.instructorLabels.instructors;
$scope.users = [];

$scope.AnswerCommentType = AnswerCommentType;
$scope.PairingAlgorithm = PairingAlgorithm;
Expand Down Expand Up @@ -1137,12 +1138,17 @@ module.controller("AssignmentViewController",
);
};

$scope.resetStudents = function(students) {
$scope.students = _.sortBy(students, 'name');
$scope.students.unshift({
id: "top-picks",
name: "Instructor's top picks"
});
$scope.resetUsers = function(instructors, students, addTopPicks) {
addTopPicks = addTopPicks !== undefined ? addTopPicks : true;
instructors = _.sortBy(instructors, 'name');
students = _.sortBy(students, 'name');
$scope.users = [].concat(instructors, students);
if (addTopPicks) {
$scope.users.unshift({
id: "top-picks",
name: "Instructor's top picks"
});
}
};

$scope.updateAnswerList = function() {
Expand All @@ -1168,7 +1174,7 @@ module.controller("AssignmentViewController",
});
};
$scope.updateAnswerList();
$scope.resetStudents($scope.allStudents);
$scope.resetUsers($scope.allInstructionals, $scope.allStudents);

CourseResource.getInstructionals({'id': $scope.courseId}).$promise.then(
function(ret) {
Expand All @@ -1179,6 +1185,8 @@ module.controller("AssignmentViewController",
.sortBy(function(o) { return o.name; })
.sortBy(function(o) { return o.role; })
.value();

$scope.resetUsers($scope.allInstructionals, $scope.allStudents);
}
);

Expand All @@ -1189,11 +1197,11 @@ module.controller("AssignmentViewController",
$scope.answerFilters.author = null;
}
if ($scope.answerFilters.group == null) {
$scope.resetStudents($scope.allStudents);
$scope.resetUsers($scope.allInstructionals, $scope.allStudents);
} else {
GroupResource.get({'courseId': $scope.courseId, 'groupName': $scope.answerFilters.group},
function (ret) {
$scope.resetStudents(ret.students);
$scope.resetUsers([], ret.students, false);
}
);
}
Expand Down
30 changes: 17 additions & 13 deletions compair/static/modules/assignment/assignment-module_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ describe('assignment-module', function () {
]
};

var mockInstructors = {
"objects": [{
"group_name": null,
"id": "15bcABC123-abcABC123_Z",
"name": "One, Instructor",
"role": "Instructor"
}]
};

var mockInstructorLabels = {
"instructors": {
"1": "Instructor"
Expand Down Expand Up @@ -793,20 +802,15 @@ describe('assignment-module', function () {
});
$httpBackend.expectGET('/api/courses/1abcABC123-abcABC123_Z/groups').respond(mockGroups);
$httpBackend.expectGET('/api/courses/1abcABC123-abcABC123_Z/assignments/1abcABC123-abcABC123_Z/answers?page=1&perPage=20').respond(mockAnswers);
$httpBackend.expectGET('/api/courses/1abcABC123-abcABC123_Z/users/instructionals').respond({
"objects": [{
"group_name": null,
"id": "1",
"name": "One, Instructor",
"role": "Instructor"
}]
});
$httpBackend.expectGET('/api/courses/1abcABC123-abcABC123_Z/users/instructionals').respond(mockInstructors);
$httpBackend.flush();
});

it('should be correctly initialized', function () {
var expectedInstructors = angular.copy(mockInstructors.objects)
var expectedStudents = _.sortBy(angular.copy(mockStudents.objects), 'name');
expectedStudents.unshift({
var expectedUsers = [].concat(expectedInstructors, expectedStudents)
expectedUsers.unshift({
id: "top-picks",
name: "Instructor's top picks"
});
Expand All @@ -815,7 +819,7 @@ describe('assignment-module', function () {
expect($rootScope.courseId).toEqual(mockCourse.id);

expect($rootScope.allStudents).toEqual(mockStudents.objects);
expect($rootScope.students).toEqual(expectedStudents);
expect($rootScope.users).toEqual(expectedUsers);

expect($rootScope.totalNumAnswers).toEqual(mockAnswers.total);

Expand Down Expand Up @@ -1207,7 +1211,7 @@ describe('assignment-module', function () {
$rootScope.date.astart.date.setDate($rootScope.date.astart.date.getDate()+1);
$rootScope.date.aend.date = new Date();
$rootScope.date.aend.date.setDate($rootScope.date.aend.date.getDate()+8);

$rootScope.date.aend.date = $rootScope.date.astart.date;
$rootScope.date.aend.time = $rootScope.date.astart.time;
var currentPath = $location.path();
Expand Down Expand Up @@ -1245,7 +1249,7 @@ describe('assignment-module', function () {
$rootScope.assignment = angular.copy(mockAssignment);
$rootScope.assignment.id = undefined;
$rootScope.assignment.availableCheck = true;

// no default dates set. populate with values before proceeding
$rootScope.date.astart.date = new Date();
$rootScope.date.astart.date.setDate($rootScope.date.astart.date.getDate()+1);
Expand All @@ -1267,7 +1271,7 @@ describe('assignment-module', function () {
it('should enable save button even if save failed', function() {
$rootScope.assignment = angular.copy(mockAssignment);
$rootScope.assignment.id = undefined;

// no default dates set. populate with values before proceeding
$rootScope.date.astart.date = new Date();
$rootScope.date.astart.date.setDate($rootScope.date.astart.date.getDate()+1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ <h2>All answers
<option value="">All groups</option>
</select>
<select id="answers-filter" ng-model="answerFilters.author" class="nullable" chosen
ng-options="u.id as u.name for u in [].concat(allInstructionals).concat(students)">
ng-options="u.id as u.name for u in users">
<option value="">All answers</option>
</select>
</span><br />
Expand Down
14 changes: 11 additions & 3 deletions compair/static/modules/comparison/comparison-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,29 @@ module.controller(
CourseResource.getStudents({'id': $scope.courseId}).$promise.then(
function (ret) {
$scope.allStudents = ret.objects;
$scope.users = ret.objects;
userIds = $scope.getUserIds(ret.objects);
$scope.resetUsers($scope.allInstructionals, $scope.allStudents);
}
);

CourseResource.getInstructionals({'id': $scope.courseId}).$promise.then(
function(ret) {
$scope.allInstructionals = ret.objects;
instructionalIds = $scope.getUserIds(ret.objects);
$scope.resetUsers($scope.allInstructionals, $scope.allStudents);
}
);

$scope.isInstructional = function(user_id) {
return user_id in instructionalIds;
}

$scope.resetUsers = function(instructors, students) {
instructors = _.sortBy(instructors, 'name');
students = _.sortBy(students, 'name');
$scope.users = [].concat(instructors, students);
};

$scope.loadAnswerByAuthor = function(author_id) {
if (_.find($scope.answers, {user_id: author_id})) return;
AnswerResource.get({'courseId': $scope.courseId, 'assignmentId': $scope.assignmentId, 'author': author_id}, function(response) {
Expand All @@ -410,11 +417,11 @@ module.controller(
$scope.comparisonFilters.author = null;
$scope.comparisonFilters.page = 1;
if ($scope.comparisonFilters.group == null) {
$scope.users = $scope.allStudents;
$scope.resetUsers($scope.allInstructionals, $scope.allStudents);
} else {
GroupResource.get({'courseId': $scope.courseId, 'groupName': $scope.comparisonFilters.group}).$promise.then(
function (ret) {
$scope.users = ret.students;
$scope.resetUsers([], ret.students);
}
);
}
Expand All @@ -437,6 +444,7 @@ module.controller(
});
};
$scope.updateList();
$scope.resetUsers($scope.allInstructionals, $scope.allStudents);
}]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h2>All comparisons
<option value="">All groups</option>
</select>
<select id="comparison-filter" ng-model="comparisonFilters.author" class="nullable" chosen
ng-options="u.id as u.name for u in [].concat(users).concat(allInstructionals) | orderBy: 'name'">
ng-options="u.id as u.name for u in users | orderBy: 'name'">
<option value="">All</option>
</select>
</span>
Expand Down

0 comments on commit c08bdc6

Please sign in to comment.