Search in sources :

Example 1 with InstructorStudentListPageCourseData

use of teammates.ui.datatransfer.InstructorStudentListPageCourseData in project teammates by TEAMMATES.

the class InstructorStudentListPageAction method execute.

@Override
public ActionResult execute() {
    gateKeeper.verifyInstructorPrivileges(account);
    String searchKey = getRequestParamValue(Const.ParamsNames.SEARCH_KEY);
    Boolean displayArchive = getRequestParamAsBoolean(Const.ParamsNames.DISPLAY_ARCHIVE);
    Map<String, InstructorAttributes> instructors = new HashMap<>();
    List<CourseAttributes> courses = logic.getCoursesForInstructor(account.googleId);
    // Sort by creation date
    courses.sort(Comparator.comparing(course -> course.createdAt));
    // Get instructor attributes
    List<InstructorAttributes> instructorList = logic.getInstructorsForGoogleId(account.googleId);
    for (InstructorAttributes instructor : instructorList) {
        instructors.put(instructor.courseId, instructor);
    }
    if (courses.isEmpty()) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.INSTRUCTOR_NO_COURSE_AND_STUDENTS, StatusMessageColor.WARNING));
    }
    statusToAdmin = "instructorStudentList Page Load<br>" + "Total Courses: " + courses.size();
    List<InstructorStudentListPageCourseData> coursesToDisplay = new ArrayList<>();
    for (CourseAttributes course : courses) {
        InstructorAttributes instructor = instructors.get(course.getId());
        boolean isInstructorAllowedToModify = instructor.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
        boolean isCourseDisplayed = displayArchive || !instructor.isArchived;
        if (isCourseDisplayed) {
            coursesToDisplay.add(new InstructorStudentListPageCourseData(course, instructor.isArchived, isInstructorAllowedToModify));
        }
    }
    InstructorStudentListPageData data = new InstructorStudentListPageData(account, sessionToken, searchKey, displayArchive, coursesToDisplay);
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_STUDENT_LIST, data);
}
Also used : List(java.util.List) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Const(teammates.common.util.Const) Map(java.util.Map) InstructorStudentListPageCourseData(teammates.ui.datatransfer.InstructorStudentListPageCourseData) StatusMessage(teammates.common.util.StatusMessage) HashMap(java.util.HashMap) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) StatusMessageColor(teammates.common.util.StatusMessageColor) Comparator(java.util.Comparator) InstructorStudentListPageData(teammates.ui.pagedata.InstructorStudentListPageData) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage) InstructorStudentListPageCourseData(teammates.ui.datatransfer.InstructorStudentListPageCourseData) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorStudentListPageData(teammates.ui.pagedata.InstructorStudentListPageData)

Example 2 with InstructorStudentListPageCourseData

use of teammates.ui.datatransfer.InstructorStudentListPageCourseData in project teammates by TEAMMATES.

the class InstructorStudentListPageDataTest method initializeDataWithSearchKey.

private InstructorStudentListPageData initializeDataWithSearchKey() {
    acct = AccountAttributes.builder().withGoogleId(// only googleId is used
    "valid.id").build();
    searchKey = "<script>alert(\"A search key\");</script>";
    shouldDisplayArchive = false;
    // only course ID and name are used
    sampleCourse = CourseAttributes.builder("validCourseId", "Sample course name", ZoneId.of("UTC")).build();
    isCourseArchived = false;
    isInstructorAllowedToModify = true;
    coursesToDisplay = new ArrayList<>();
    coursesToDisplay.add(new InstructorStudentListPageCourseData(sampleCourse, isCourseArchived, isInstructorAllowedToModify));
    return new InstructorStudentListPageData(acct, dummySessionToken, searchKey, shouldDisplayArchive, coursesToDisplay);
}
Also used : InstructorStudentListPageCourseData(teammates.ui.datatransfer.InstructorStudentListPageCourseData) InstructorStudentListPageData(teammates.ui.pagedata.InstructorStudentListPageData)

Aggregations

InstructorStudentListPageCourseData (teammates.ui.datatransfer.InstructorStudentListPageCourseData)2 InstructorStudentListPageData (teammates.ui.pagedata.InstructorStudentListPageData)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)1 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)1 Const (teammates.common.util.Const)1 StatusMessage (teammates.common.util.StatusMessage)1 StatusMessageColor (teammates.common.util.StatusMessageColor)1