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

Merge in badging frontend from Feature.nutmeg/badges #28

Open
wants to merge 11 commits into
base: develop/nutmeg.master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
29,103 changes: 641 additions & 28,462 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,20 @@
"@reduxjs/toolkit": "1.8.1",
"classnames": "2.3.1",
"core-js": "3.21.1",
"iframe-resizer": "^4.3.2",
"js-cookie": "3.0.1",
"lodash.camelcase": "4.3.0",
"lodash.snakecase": "^4.1.1",
"mime-types": "^2.1.34",
"moment": "^2.29.1",
"moment-timezone": "^0.5.34",
"prop-types": "15.8.1",
"react": "16.14.0",
"react-dom": "16.14.0",
"react-download-link": "^2.3.0",
"react-helmet": "6.1.0",
"react-markdown": "^8.0.0",
"react-moment": "^1.1.1",
"react-redux": "7.2.8",
"react-router": "5.2.1",
"react-router-dom": "5.3.0",
Expand Down
49 changes: 49 additions & 0 deletions src/course-home/badges-tab/BadgeLeaderboardTab.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
// import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
// import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { useModel } from '../../generic/model-store';

import { BadgeTabsNavigation } from './badge-header';

// {
// intl
// }
function BadgeLeaderboardTab() {
const {
courseId,
} = useSelector(state => state.courseHome);

const { administrator, username } = getAuthenticatedUser();

const {
enrollmentMode,
} = useModel('courses', courseId);

const activeTabSlug = 'leaderboard';

return (
<>
<main className="d-flex flex-column">
<BadgeTabsNavigation className="mb-3 py-2" activeTabSlug={activeTabSlug} />
<div className="container-fluid">
<section>
<div className="mb-4">
the user is {username} and they are enrolled as an {enrollmentMode} learner
{administrator
&& <div><p>the user is admin</p></div>}
</div>
</section>
</div>
</main>
</>
);
}

// BadgeLeaderboardTab.propTypes = {
// intl: intlShape.isRequired,
// };

// export default injectIntl(BadgeLeaderboardTab);
export default BadgeLeaderboardTab;
142 changes: 142 additions & 0 deletions src/course-home/badges-tab/BadgeProgressTab.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import React, { useEffect, useState } from 'react';
// import PropTypes from 'prop-types';
import snakeCase from 'lodash.snakecase';
import { useSelector } from 'react-redux';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { StatusAlert } from '@edx/paragon';
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faExclamationCircle } from '@fortawesome/free-solid-svg-icons';

import { useModel } from '../../generic/model-store';

import { BadgeTabsNavigation } from './badge-header';
import { BadgeProgressBanner, BadgeProgressCard, BadgeProgressCourseList } from './badge-progress';

import { headingMapper } from './utils';

function BadgeProgressTab({ intl }) { // eslint-disable-line
const activeTabSlug = 'progress';

const {
courseId,
} = useSelector(state => state.courseHome);

const {
administrator,
username,
roles // eslint-disable-line
} = getAuthenticatedUser();

const hasInstructorStaffRights = () => administrator;

const [progress, setProgress] = useState([]);

const {
id,
...badgeProgressState
} = useModel('badge-progress', courseId);

const hasBadgeProgress = () => progress && progress.length > 0;
useEffect(() => {
let classProgressExists = 0;
let badgeProgress = Object.values(badgeProgressState); // eslint-disable-line
if (hasInstructorStaffRights()) {
badgeProgress.forEach(student => {
if (student.progress.length) {
classProgressExists += 1;
}
});
if (classProgressExists) {
setProgress(badgeProgress);
}
} else {
setProgress(badgeProgress);
}
}, [courseId, administrator]);

const renderBadgeProgress = () => {
const defaultAssignmentFilter = 'All';

if (hasInstructorStaffRights()) {
return (
<>
<BadgeTabsNavigation className="mb-3 py-2" activeTabSlug={activeTabSlug} />
<BadgeProgressBanner
hasProgress={hasBadgeProgress()}
hasRights={hasInstructorStaffRights()}
/>
<BadgeProgressCourseList
data={progress}
headings={headingMapper(defaultAssignmentFilter, progress)(progress[0])}
/>
</>
);
}

/*
<section>
<div className="mb-4">
the user is {username} and they are enrolled as an {enrollmentMode} learner
{administrator
&& <div><p>the user is admin</p></div>}
</div>
</section>
*/
return (
<>
<div className="d-flex flex-column">
<BadgeTabsNavigation className="mb-3 py-2" activeTabSlug={activeTabSlug} />
<BadgeProgressBanner hasProgress={hasBadgeProgress()} hasRights={hasInstructorStaffRights()} />
<div className="container-fluid">
<section className="row">
<div className="col-sm-12 col-md-12 col-lg-12 col-xl-12">
{progress && (
<div className="row equal-col-height">
{progress.map(learnerProgress => {
const itemKey = snakeCase(`card ${learnerProgress.blockDisplayName} ${username}`);
return (
<BadgeProgressCard key={`${itemKey}`} data={learnerProgress} />
);
})}
</div>
)}
</div>
</section>
</div>
</div>
</>
);
};

const renderNoBadgeProgress = () => (
<StatusAlert
dialog={(
<>
<FontAwesomeIcon icon={faExclamationCircle} className="mr-2" />
There is no course badge progress to show.
</>
)}
alertType="info"
dismissible={false}
open
/>
);

return (
<>
{hasBadgeProgress() && (
renderBadgeProgress()
)}
{!hasBadgeProgress() && (
renderNoBadgeProgress()
)}
</>
);
}

BadgeProgressTab.propTypes = {
intl: intlShape.isRequired,
};

export default injectIntl(BadgeProgressTab);
Loading
Loading