Search in sources :

Example 6 with SectionDetailsBundle

use of teammates.common.datatransfer.SectionDetailsBundle in project teammates by TEAMMATES.

the class CoursesLogic method getSectionsForCourseWithoutStats.

/**
 * Returns a list of {@link SectionDetailsBundle} for a given course using courseId.
 */
public List<SectionDetailsBundle> getSectionsForCourseWithoutStats(String courseId) throws EntityDoesNotExistException {
    verifyCourseIsPresent(courseId);
    List<StudentAttributes> students = studentsLogic.getStudentsForCourse(courseId);
    StudentAttributes.sortBySectionName(students);
    List<SectionDetailsBundle> sections = new ArrayList<>();
    SectionDetailsBundle section = null;
    int teamIndexWithinSection = 0;
    for (int i = 0; i < students.size(); i++) {
        StudentAttributes s = students.get(i);
        if (section == null) {
            // First student of first section
            section = new SectionDetailsBundle();
            section.name = s.section;
            section.teams.add(new TeamDetailsBundle());
            section.teams.get(teamIndexWithinSection).name = s.team;
            section.teams.get(teamIndexWithinSection).students.add(s);
        } else if (s.section.equals(section.name)) {
            if (s.team.equals(section.teams.get(teamIndexWithinSection).name)) {
                section.teams.get(teamIndexWithinSection).students.add(s);
            } else {
                teamIndexWithinSection++;
                section.teams.add(new TeamDetailsBundle());
                section.teams.get(teamIndexWithinSection).name = s.team;
                section.teams.get(teamIndexWithinSection).students.add(s);
            }
        } else {
            // first student of subsequent section
            sections.add(section);
            teamIndexWithinSection = 0;
            section = new SectionDetailsBundle();
            section.name = s.section;
            section.teams.add(new TeamDetailsBundle());
            section.teams.get(teamIndexWithinSection).name = s.team;
            section.teams.get(teamIndexWithinSection).students.add(s);
        }
        boolean isLastStudent = i == students.size() - 1;
        if (isLastStudent) {
            sections.add(section);
        }
    }
    return sections;
}
Also used : TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) SectionDetailsBundle(teammates.common.datatransfer.SectionDetailsBundle)

Example 7 with SectionDetailsBundle

use of teammates.common.datatransfer.SectionDetailsBundle in project teammates by TEAMMATES.

the class InstructorSearchPageData method createStudentRows.

private List<StudentListSectionData> createStudentRows(String courseId, StudentSearchResultBundle studentSearchResultBundle) {
    List<StudentListSectionData> rows = new ArrayList<>();
    List<StudentAttributes> studentsInCourse = filterStudentsByCourse(courseId, studentSearchResultBundle);
    Map<String, Set<String>> sectionNameToTeamNameMap = new HashMap<>();
    Map<String, List<StudentAttributes>> teamNameToStudentsMap = new HashMap<>();
    Map<String, String> emailToPhotoUrlMap = new HashMap<>();
    for (StudentAttributes student : studentsInCourse) {
        String teamName = student.team;
        String sectionName = student.section;
        String viewPhotoLink = addUserIdToUrl(student.getPublicProfilePictureUrl());
        emailToPhotoUrlMap.put(student.email, viewPhotoLink);
        teamNameToStudentsMap.computeIfAbsent(teamName, key -> new ArrayList<>()).add(student);
        sectionNameToTeamNameMap.computeIfAbsent(sectionName, key -> new HashSet<>()).add(teamName);
    }
    List<SectionDetailsBundle> sections = new ArrayList<>();
    sectionNameToTeamNameMap.forEach((sectionName, teamNameList) -> {
        SectionDetailsBundle sdb = new SectionDetailsBundle();
        sdb.name = sectionName;
        ArrayList<TeamDetailsBundle> teams = new ArrayList<>();
        for (String teamName : teamNameList) {
            TeamDetailsBundle tdb = new TeamDetailsBundle();
            tdb.name = teamName;
            tdb.students = teamNameToStudentsMap.get(teamName);
            teams.add(tdb);
        }
        sdb.teams = teams;
        sections.add(sdb);
    });
    for (SectionDetailsBundle section : sections) {
        InstructorAttributes instructor = studentSearchResultBundle.courseIdInstructorMap.get(courseId);
        boolean isAllowedToViewStudentInSection = instructor.isAllowedForPrivilege(section.name, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS);
        boolean isAllowedToModifyStudent = instructor.isAllowedForPrivilege(section.name, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
        rows.add(new StudentListSectionData(section, isAllowedToViewStudentInSection, isAllowedToModifyStudent, emailToPhotoUrlMap, account.googleId, getSessionToken()));
    }
    return rows;
}
Also used : InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Const(teammates.common.util.Const) SearchStudentsTable(teammates.ui.template.SearchStudentsTable) QuestionTable(teammates.ui.template.QuestionTable) HashMap(java.util.HashMap) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FeedbackResponseCommentSearchResultBundle(teammates.common.datatransfer.FeedbackResponseCommentSearchResultBundle) Map(java.util.Map) StudentListSectionData(teammates.ui.template.StudentListSectionData) SectionDetailsBundle(teammates.common.datatransfer.SectionDetailsBundle) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) SearchFeedbackSessionDataTable(teammates.ui.template.SearchFeedbackSessionDataTable) Set(java.util.Set) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) ZoneId(java.time.ZoneId) TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) List(java.util.List) StudentSearchResultBundle(teammates.common.datatransfer.StudentSearchResultBundle) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) FeedbackSessionRow(teammates.ui.template.FeedbackSessionRow) FeedbackResponseCommentRow(teammates.ui.template.FeedbackResponseCommentRow) ResponseRow(teammates.ui.template.ResponseRow) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) SectionDetailsBundle(teammates.common.datatransfer.SectionDetailsBundle) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) StudentListSectionData(teammates.ui.template.StudentListSectionData) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 8 with SectionDetailsBundle

use of teammates.common.datatransfer.SectionDetailsBundle in project teammates by TEAMMATES.

the class InstructorStudentListAjaxPageAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String courseIndexString = getRequestParamValue(Const.ParamsNames.COURSE_INDEX);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_INDEX, courseIndexString);
    gateKeeper.verifyInstructorPrivileges(account);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    CourseAttributes course = logic.getCourse(courseId);
    gateKeeper.verifyAccessible(instructor, course);
    List<SectionDetailsBundle> courseSectionDetails = logic.getSectionsForCourse(courseId);
    int courseIndex = Integer.parseInt(courseIndexString);
    boolean hasSection = logic.hasIndicatedSections(courseId);
    Map<String, String> emailPhotoUrlMapping = new HashMap<>();
    Map<String, Map<String, Boolean>> sectionPrivileges = new HashMap<>();
    for (SectionDetailsBundle sectionDetails : courseSectionDetails) {
        for (TeamDetailsBundle teamDetails : sectionDetails.teams) {
            for (StudentAttributes student : teamDetails.students) {
                String studentPhotoUrl = student.getPublicProfilePictureUrl();
                studentPhotoUrl = Url.addParamToUrl(studentPhotoUrl, Const.ParamsNames.USER_ID, account.googleId);
                emailPhotoUrlMapping.put(student.email, studentPhotoUrl);
            }
        }
        Map<String, Boolean> sectionPrivilege = new HashMap<>();
        sectionPrivilege.put(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS, instructor.isAllowedForPrivilege(sectionDetails.name, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS));
        sectionPrivilege.put(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT, instructor.isAllowedForPrivilege(sectionDetails.name, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT));
        sectionPrivileges.put(sectionDetails.name, sectionPrivilege);
    }
    InstructorStudentListAjaxPageData data = new InstructorStudentListAjaxPageData(account, sessionToken, courseId, courseIndex, hasSection, courseSectionDetails, sectionPrivileges, emailPhotoUrlMapping);
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_STUDENT_LIST_AJAX, data);
}
Also used : HashMap(java.util.HashMap) InstructorStudentListAjaxPageData(teammates.ui.pagedata.InstructorStudentListAjaxPageData) SectionDetailsBundle(teammates.common.datatransfer.SectionDetailsBundle) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) HashMap(java.util.HashMap) Map(java.util.Map) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Example 9 with SectionDetailsBundle

use of teammates.common.datatransfer.SectionDetailsBundle in project teammates by TEAMMATES.

the class InstructorCourseDetailsPageData method init.

public void init(InstructorAttributes currentInstructor, CourseDetailsBundle courseDetails, List<InstructorAttributes> instructors) {
    this.currentInstructor = currentInstructor;
    this.courseDetails = courseDetails;
    this.instructors = instructors;
    boolean isDisabled = !currentInstructor.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
    String courseId = sanitizeForJs(courseDetails.course.getId());
    String href = sanitizeForJs(getInstructorCourseRemindLink(courseDetails.course.getId()));
    courseRemindButton = createButton(null, "btn btn-primary", "button_remind", href, Const.Tooltips.COURSE_REMIND, "tooltip", courseId, isDisabled);
    String hrefDeleteStudents = sanitizeForJs(getInstructorCourseStudentDeleteAllLink(courseId));
    courseDeleteAllButton = createButton(null, "btn btn-danger course-student-delete-all-link", "button-delete-all", hrefDeleteStudents, null, null, courseId, isDisabled);
    this.sections = new ArrayList<>();
    for (SectionDetailsBundle section : courseDetails.sections) {
        Map<String, String> emailPhotoUrlMapping = new HashMap<>();
        for (TeamDetailsBundle teamDetails : section.teams) {
            for (StudentAttributes student : teamDetails.students) {
                String studentPhotoUrl = student.getPublicProfilePictureUrl();
                studentPhotoUrl = Url.addParamToUrl(studentPhotoUrl, Const.ParamsNames.USER_ID, account.googleId);
                emailPhotoUrlMapping.put(student.email, studentPhotoUrl);
            }
        }
        boolean isAllowedToViewStudentInSection = currentInstructor.isAllowedForPrivilege(section.name, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS);
        boolean isAllowedToModifyStudent = currentInstructor.isAllowedForPrivilege(section.name, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
        this.sections.add(new StudentListSectionData(section, isAllowedToViewStudentInSection, isAllowedToModifyStudent, emailPhotoUrlMapping, account.googleId, getSessionToken()));
    }
    if (sections.size() == 1) {
        StudentListSectionData section = sections.get(0);
        this.hasSection = !"None".equals(section.getSectionName());
    } else {
        this.hasSection = true;
    }
}
Also used : TeamDetailsBundle(teammates.common.datatransfer.TeamDetailsBundle) HashMap(java.util.HashMap) StudentListSectionData(teammates.ui.template.StudentListSectionData) SectionDetailsBundle(teammates.common.datatransfer.SectionDetailsBundle) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Aggregations

SectionDetailsBundle (teammates.common.datatransfer.SectionDetailsBundle)9 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)7 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)3 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)3 Map (java.util.Map)2 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)2 InstructorStudentListAjaxPageData (teammates.ui.pagedata.InstructorStudentListAjaxPageData)2 StudentListSectionData (teammates.ui.template.StudentListSectionData)2 ZoneId (java.time.ZoneId)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Test (org.testng.annotations.Test)1 FeedbackResponseCommentSearchResultBundle (teammates.common.datatransfer.FeedbackResponseCommentSearchResultBundle)1 StudentSearchResultBundle (teammates.common.datatransfer.StudentSearchResultBundle)1 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)1 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)1