Skip to content

Commit

Permalink
Merge pull request #707 from mahajanmahesh935/joincourseissue
Browse files Browse the repository at this point in the history
TASK #228992 : Votting List and Learnathon Votting flow
  • Loading branch information
paritshivani authored Oct 21, 2024
2 parents 656da4f + c4101a1 commit bb19b76
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 54 deletions.
5 changes: 4 additions & 1 deletion packages/nulp_elite/public/locales/be/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,8 @@
"VOTE_COUNT":"ভোটের সংখ্যা",
"VOTE_NOW":"এখনই ভোট দিন",
"SEARCH_SUBMISSION":"অনুসন্ধান জমা",
"VIEW_SUBMISSIONS":"সাবমিশন দেখুন"
"VIEW_SUBMISSIONS":"সাবমিশন দেখুন",
"VOTIGN_DEADLINE":"ভোটের সময়সীমা",
"VIEW_AND_VOTE":"দেখুন এবং ভোট দিন",
"VOTE_FOR_THIS_CONTENT":"এই কন্টেন্ট জন্য ভোট"
}
5 changes: 4 additions & 1 deletion packages/nulp_elite/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,5 +331,8 @@
"VOTE_COUNT":"Vote Count",
"VOTE_NOW":"Vote Now",
"SEARCH_SUBMISSION":"Search Submission",
"VIEW_SUBMISSIONS":"View Submissions"
"VIEW_SUBMISSIONS":"View Submissions",
"VOTIGN_DEADLINE":"Votting Deadline",
"VIEW_AND_VOTE":"View and vote",
"VOTE_FOR_THIS_CONTENT":"Vote for this content"
}
5 changes: 4 additions & 1 deletion packages/nulp_elite/public/locales/gg/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,8 @@
"VOTE_COUNT":"મત ગણતરી",
"VOTE_NOW":"હવે મત આપો",
"SEARCH_SUBMISSION":"સર્ચ સબમિશન",
"VIEW_SUBMISSIONS":"સબમિશન જુઓ"
"VIEW_SUBMISSIONS":"સબમિશન જુઓ",
"VOTIGN_DEADLINE":"મતદાનની અંતિમ તારીખ",
"VIEW_AND_VOTE":"જુઓ અને મત આપો",
"VOTE_FOR_THIS_CONTENT":"આ સામગ્રી માટે મત આપો"
}
5 changes: 4 additions & 1 deletion packages/nulp_elite/public/locales/hi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,8 @@
"VOTE_COUNT":"मतदान गणना",
"VOTE_NOW":"अभी वोट करें",
"SEARCH_SUBMISSION":"खोज सबमिशन",
"VIEW_SUBMISSIONS":"सबमिशन देखें"
"VIEW_SUBMISSIONS":"सबमिशन देखें",
"VOTIGN_DEADLINE":"मतदान की समय सीमा",
"VIEW_AND_VOTE":"देखें और वोट करें",
"VOTE_FOR_THIS_CONTENT":"इस सामग्री के लिए वोट करें"
}
5 changes: 4 additions & 1 deletion packages/nulp_elite/public/locales/ma/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@
"VOTE_COUNT":"मतांची संख्या",
"VOTE_NOW":"आता मतदान करा",
"SEARCH_SUBMISSION":"शोध सबमिशन",
"VIEW_SUBMISSIONS":"सबमिशन पहा"
"VIEW_SUBMISSIONS":"सबमिशन पहा",
"VOTIGN_DEADLINE":"मतदानाची अंतिम मुदत",
"VIEW_AND_VOTE":"पहा आणि मत द्या",
"VOTE_FOR_THIS_CONTENT":"या सामग्रीसाठी मत द्या"
}

5 changes: 4 additions & 1 deletion packages/nulp_elite/public/locales/mal/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -329,5 +329,8 @@
"VOTE_COUNT":"വോട്ട് കൗണ്ട്",
"VOTE_NOW":"ഇപ്പോൾ വോട്ട് ചെയ്യുക",
"SEARCH_SUBMISSION":"തിരയൽ സമർപ്പിക്കൽ",
"VIEW_SUBMISSIONS":"സമർപ്പിക്കലുകൾ കാണുക"
"VIEW_SUBMISSIONS":"സമർപ്പിക്കലുകൾ കാണുക",
"VOTIGN_DEADLINE":"വോട്ടിംഗ് സമയപരിധി",
"VIEW_AND_VOTE":"കാണുക, വോട്ട് ചെയ്യുക",
"VOTE_FOR_THIS_CONTENT":"ഈ ഉള്ളടക്കത്തിന് വോട്ട് ചെയ്യുക"
}
5 changes: 4 additions & 1 deletion packages/nulp_elite/public/locales/te/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,8 @@
"VOTE_COUNT":"ఓట్ల లెక్కింపు",
"VOTE_NOW":"ఇప్పుడే ఓటు వేయండి",
"SEARCH_SUBMISSION":"శోధన సమర్పణ",
"VIEW_SUBMISSIONS":"సమర్పణలను వీక్షించండి"
"VIEW_SUBMISSIONS":"సమర్పణలను వీక్షించండి",
"VOTIGN_DEADLINE":"ఓటింగ్ గడువు",
"VIEW_AND_VOTE":"వీక్షించి ఓటు వేయండి",
"VOTE_FOR_THIS_CONTENT":"ఈ కంటెంట్ కోసం ఓటు వేయండి"
}
78 changes: 77 additions & 1 deletion packages/nulp_elite/src/pages/content/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import AccordionSummary from '@mui/material/AccordionSummary';
import AccordionDetails from '@mui/material/AccordionDetails';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import md5 from 'md5';
import { isEmpty } from "lodash";
const urlConfig = require("../../configs/urlConfig.json");

const Player = () => {
Expand All @@ -55,9 +56,12 @@ const Player = () => {
const [assessEvents, setAssessEvents] =useState ([]);
const [propLength, setPropLength] =useState();
const _userId = util.userId();

const[isLearnathon,setIsLearnathon]=useState(false)
const[alreadyVoted,setAlreadyVoted] = useState(false)
const[pollId,setPollId] = useState()
const queryString = location.search;
let contentId = queryString.startsWith("?do_") ? queryString.slice(1) : null;

// Check if contentId ends with '=' and remove it
if (contentId && contentId.endsWith("=")) {
contentId = contentId.slice(0, -1);
Expand Down Expand Up @@ -170,6 +174,7 @@ const attemptid = ()=>{
return hashValue;
}


const updateContentStateForAssessment = async () => {
await updateContentState(2);
try {
Expand Down Expand Up @@ -246,6 +251,8 @@ const updateContentStateForAssessment = async () => {
fetchUserData();
}, [contentId, consumedContent, fetchUserData, updateContentState]);



useEffect(() => {
if (isCompleted) {
updateContentState(2);
Expand All @@ -258,6 +265,56 @@ const updateContentStateForAssessment = async () => {
navigate(-1); // Navigate back in history
};

const CheckLearnathonContent=async()=>{
try{
const url = `${urlConfig.URLS.LEARNATHON.LIST}`;
const requestBody = {
request : {
filters : {
content_id :contentId,
status : "Live",
// start_date:start_date,
// end_date:end_date,

}
}
}

const response = await axios.post(url, requestBody);
if(response?.data?.result?.totalCount > 0){
setPollId(response?.data?.result?.data[0]?.poll_id)
setIsLearnathon(true)
}
}catch (error) {
console.error("Error fetching course data:", error);
}

}

const CheckAlreadyVoted=async()=>{
try{
const url = `${urlConfig.URLS.POLL.GET_USER_POLL}?poll_id=${pollId}&user_id=${_userId}`;
const response = await axios.get(url);
if(Array.isArray(response?.data?.result) && response?.data?.result.length !== 0){
setAlreadyVoted(true)
}
}catch (error) {
console.error("Error fetching course data:", error);
}

}

useEffect(() => {
CheckLearnathonContent();
},[contentId])
useEffect(() => {
CheckAlreadyVoted();
},[pollId])

const handleClick = (poll_id) => {
navigate(`/webapp/pollDetails?${poll_id}`);
};

return (
<div>
<Header />
Expand Down Expand Up @@ -461,6 +518,25 @@ const updateContentStateForAssessment = async () => {
paddingBottom: "2%",
marginTop: '2%'
}}>
{isLearnathon &&
<div className="vote-section">
<Button
type="button"
className="custom-btn-primary ml-20"
onClick={() => handleClick(pollId)}
disabled={alreadyVoted} // Disable button if alreadyVoted is true
>
{t("VOTE_FOR_THIS_CONTENT")}
</Button>

{/* Conditionally render the message if alreadyVoted is true */}
{alreadyVoted && (
<Typography variant="body1" color="error" className="ml-20">
{t("You have already voted")}
</Typography>
)}
</div>
}
<Accordion defaultExpanded
>
<AccordionSummary
Expand Down
59 changes: 29 additions & 30 deletions packages/nulp_elite/src/pages/learnathon/lernVotingList.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ import Footer from "components/Footer";
import Header from "components/header";
import Paper from "@mui/material/Paper";
import Grid from "@mui/material/Grid";
const routeConfig = require("../../configs/routeConfig.json");
const urlConfig = require("../../configs/urlConfig.json");

const LernVotingList = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const [data, setData] = useState([]);
const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(5);
const [rowsPerPage, setRowsPerPage] = useState(10);
const [totalRows, setTotalRows] = useState(0);
const [search, setSearch] = useState("");
const [pollData, setPollData] = useState([]);
const [voteCounts, setVoteCounts] = useState({}); // Object to store vote counts
const[pageNumber,setPageNumber] = useState(1);
const[currentPage,setCurrentPage] = useState(1)

useEffect(() => {
fetchData();
}, [page, rowsPerPage, search]);
}, [currentPage, rowsPerPage, search]);

const fetchData = async () => {
const assetBody = {
Expand All @@ -46,12 +50,12 @@ const LernVotingList = () => {
},

limit: rowsPerPage,
offset: page * rowsPerPage,
offset: 10 * (currentPage-1),
search: search,
},
};
try {
const response = await fetch("/polls/list", {
const response = await fetch(`${urlConfig.URLS.POLL.LIST}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -67,7 +71,7 @@ const LernVotingList = () => {
setData(result.result.data);
const pollIds = result.result.data.map((poll) => poll.poll_id);
setPollData(pollIds);
setTotalRows(result.result.totalCount);
setTotalRows(Math.ceil(result.result.totalCount / 10));

// Fetch vote counts for each poll
getVoteCounts(pollIds);
Expand All @@ -78,7 +82,7 @@ const LernVotingList = () => {

const getVoteCounts = async (pollIds) => {
try {
const url = "/polls/all/get_poll";
const url = `${urlConfig.URLS.POLL.GET_VOTTING_LIST}`;
const body = {
poll_ids: pollIds,
};
Expand All @@ -102,17 +106,16 @@ const LernVotingList = () => {
setPage(0); // Reset to first page on search
};

const handlePageChange = (event, newPage) => {
setPage(newPage);
const handleClick = (contentId) => {
navigate(`${routeConfig.ROUTES.PLAYER_PAGE.PLAYER}?${contentId}`);
};

const handleRowsPerPageChange = (event) => {
setRowsPerPage(parseInt(event.target.value, 10));
setPage(0);
};

const handleClick = (poll_id) => {
navigate(`/webapp/pollDetails?${poll_id}`);
const handleChange = (event, value) => {
if (value !== pageNumber) {
setPageNumber(value);
setCurrentPage(value);
fetchData();
}
};

return (
Expand Down Expand Up @@ -164,16 +167,15 @@ const LernVotingList = () => {
</TableCell>
<TableCell>{voteCounts[row.poll_id] || 0}</TableCell>
<TableCell>
<img
src={require("assets/votting.png")}
alt="Voting"
style={{
width: "100px",
height: "40px",
cursor: "pointer"
}}
onClick={() => handleClick(row.poll_id)}
/>
<Box>
<Button
type="button"
className="custom-btn-primary ml-20"
onClick={() => handleClick(row.content_id)}
>
{t("VIEW_AND_VOTE")}
</Button>
</Box>
</TableCell>
</TableRow>
))}
Expand All @@ -182,12 +184,9 @@ const LernVotingList = () => {
</TableContainer>

<Pagination
component="div"
count={totalRows}
page={page}
onPageChange={handlePageChange}
rowsPerPage={rowsPerPage}
onRowsPerPageChange={handleRowsPerPageChange}
page={pageNumber}
onChange={handleChange}
/>
</Paper>
<Footer />
Expand Down
25 changes: 9 additions & 16 deletions packages/nulp_elite/src/pages/voting/votingDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,15 @@ const VotingDetails = () => {
{poll.title}
</Link>
</Breadcrumbs>
<Box>
<Button
type="button"
className="custom-btn-primary ml-20"
onClick={handleGoBack}
>
{t("BACK")}
</Button>
</Box>
<Grid
container
spacing={2}
Expand Down Expand Up @@ -630,22 +639,6 @@ const VotingDetails = () => {
className="event-h2-title pl-20 mb-20"
style={{ fontWeight: "400" }}
>
{poll && poll.category === "Learnathon" && (
<Box>
<Button
type="button"
className="custom-btn-primary"
onClick={() =>
window.open("/webapp/player?" + poll.content_id, "_blank")
}
sx={{ marginTop: "24px" }}

// disabled={!selectedOption} // Disable the button if no option is selected
>
{t("VIEW_SUBMISSIONS")}
</Button>
</Box>
)}
<Box className="mt-20">
{poll.description}
</Box>
Expand Down

0 comments on commit bb19b76

Please sign in to comment.