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

Issue #CO-229 #CO-230 #CO-316 fix: {Reraising PR on release-6.0.0} #303

Merged
merged 7 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 4 additions & 2 deletions src/service/print/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ const buildCSVWithCallback = async (id, callback) => {
let error = false;
let errorMsg = "";
let totalMarks = 0;
getQuestionSet(id)
const config = {
id: id
}
getQuestionSet(config)
.then(async (data) => {
if (data.error) {
callback(null, data.error, data.errorMsg, null);
Expand Down Expand Up @@ -392,7 +395,6 @@ async function renderMCQ(
questionOptions.forEach(( quesOpt , i)=>{
data[`Option${i+1}`] = quesOpt[0]
})

return data;
}

Expand Down
151 changes: 46 additions & 105 deletions src/service/print/docxHelper.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
var cheerio = require("cheerio");
var cheerioTableparser = require("cheerio-tableparser");
const sizeOf = require("image-size");
const { compact } = require("lodash");
const ProgramServiceHelper = require("../../helpers/programHelper");
const programServiceHelper = new ProgramServiceHelper();
const optionLabelling = {
english: ['i', 'ii', 'iii', 'iv'],
hindi: ['क', 'ख', 'ग', 'घ'],
}
const defaultLanguage = 'english'

var {
docDefinition,
Expand Down Expand Up @@ -237,6 +241,7 @@ async function getStack(htmlString) {
}

async function renderMCQ(question, questionCounter, marks) {
const printLanguage = (question.medium && question.medium.length) ? question.medium[0].toLowerCase() : defaultLanguage;
const questionOptions = [];
let questionTitle;
for (const [index, qo] of question.editorState.options.entries()) {
Expand Down Expand Up @@ -264,113 +269,11 @@ async function renderMCQ(question, questionCounter, marks) {

let questionOpt = [];
let imageProperties = [];
if (questionOptions[0] !== undefined) {
if (
questionOptions[0][0] !== undefined &&
typeof questionOptions[0][0] === "object"
) {
if (questionOptions[0][0].text) {
questionOpt.push(["I.", questionOptions[0][0].text[1]]);
imageProperties.push({
width: 0,
height: 0,
});
} else {
questionOpt.push(["I.", questionOptions[0][0].image]);
imageProperties.push({
width: questionOptions[0][0].width,
height: questionOptions[0][0].height,
});
}
} else {
questionOpt.push(["I.", questionOptions[0][0]]);
imageProperties.push({
width: 0,
height: 0,
});
}
}

if (questionOptions[1] !== undefined) {
if (
questionOptions[1][0] !== undefined &&
typeof questionOptions[1][0] === "object"
) {
if (questionOptions[1][0].text) {
questionOpt.push(["II.", questionOptions[1][0].text[1]]);
imageProperties.push({
width: 0,
height: 0,
});
} else {
questionOpt.push(["II.", questionOptions[1][0].image]);
imageProperties.push({
width: questionOptions[1][0].width,
height: questionOptions[1][0].height,
});
}
} else {
questionOpt.push(["II.", questionOptions[1][0]]);
imageProperties.push({
width: 0,
height: 0,
});
}
for (let i = 0; i < questionOptions.length; i++) {
setOptions(questionOptions, questionOpt, imageProperties, printLanguage, i)
}

if (questionOptions[2] !== undefined) {
if (
questionOptions[2][0] !== undefined &&
typeof questionOptions[2][0] === "object"
) {
if (questionOptions[2][0].text) {
questionOpt.push(["III.", questionOptions[2][0].text[1]]);
imageProperties.push({
width: 0,
height: 0,
});
} else {
questionOpt.push(["III.", questionOptions[2][0].image]);
imageProperties.push({
width: questionOptions[2][0].width,
height: questionOptions[2][0].height,
});
}
} else {
questionOpt.push(["III.", questionOptions[2][0]]);
imageProperties.push({
width: 0,
height: 0,
});
}
}

if (questionOptions[3] !== undefined) {
if (
questionOptions[3][0] !== undefined &&
typeof questionOptions[3][0] === "object"
) {
if (questionOptions[3][0].text) {
questionOpt.push(["IV.", questionOptions[3][0].text[1]]);
imageProperties.push({
width: 0,
height: 0,
});
} else {
questionOpt.push(["IV.", questionOptions[3][0].image]);
imageProperties.push({
width: questionOptions[3][0].width,
height: questionOptions[3][0].height,
});
}
} else {
questionOpt.push(["IV.", questionOptions[3][0]]);
imageProperties.push({
width: 0,
height: 0,
});
}
}
let data = {
QuestionIndex: questionCounter,
Questions: questionTitle,
Expand All @@ -394,6 +297,36 @@ async function renderMCQ(question, questionCounter, marks) {
return data;
}

function setOptions(questionOptions, questionOpt, imageProperties, printLanguage, i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope you enjoyed writing the code.. looks fine.

@vaivk369 @shubhambansaltarento

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i did, Thank you for guidance.

console.log('printLanguage', printLanguage);
if (questionOptions[i] !== undefined) {
if (
questionOptions[i][0] !== undefined &&
typeof questionOptions[i][0] === "object"
) {
if (questionOptions[i][0].text) {
questionOpt.push([`${getLanguageKey(printLanguage, i)+")"}`, questionOptions[i][0].text[1]]);
imageProperties.push({
width: 0,
height: 0,
});
} else {
questionOpt.push([`${getLanguageKey(printLanguage, i)+")"}`, questionOptions[i][0].image]);
imageProperties.push({
width: questionOptions[i][0].width,
height: questionOptions[i][0].height,
});
}
} else {
questionOpt.push([`${getLanguageKey(printLanguage, i)+")"}`, questionOptions[i][0]]);
imageProperties.push({
width: 0,
height: 0,
});
}
}
}

async function renderQuestion(question, questionCounter, marks, Type) {
let data;
$ = cheerio.load(question.editorState.question);
Expand Down Expand Up @@ -498,6 +431,14 @@ async function renderMTF(question, questionCounter, marks, Type) {

return mtfData;
}
function getLanguageKey(lang, index) {
console.log('KKK', index);
rekhaDevs marked this conversation as resolved.
Show resolved Hide resolved
if (optionLabelling.hasOwnProperty(lang) && optionLabelling[lang].length > index) {
return optionLabelling[lang][index];
}

return optionLabelling[defaultLanguage][index];
}

module.exports = {
renderComprehension,
Expand Down
18 changes: 13 additions & 5 deletions src/service/print/getdocxdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const {
const _ = require("lodash");

function create(data, paperData) {
const language = (paperData && paperData.language) ? paperData.language.toLowerCase(): defaultLanguage;

const doc = new Document({
sections: [
{
Expand Down Expand Up @@ -226,9 +228,9 @@ function create(data, paperData) {
count++;
});
arr.push(
new Paragraph({
children: [], // Just newline without text
})
// new Paragraph({
// children: [], // Just newline without text
// })
);
arr.push(optionsTabel(testimage));
arr.push(
Expand Down Expand Up @@ -711,8 +713,8 @@ function displayNumber(data) {
type: WidthType.DXA,
},
margins: {
top: convertInchesToTwip(0.0693701),
bottom: convertInchesToTwip(0.0693701),
top: convertInchesToTwip(0.0093701),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the right way of fixing the margins. It should be common across all sides. Any specific reason why the margins are different for the document.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While printing paper having MCQ questions, the line height between line 1 of options and line 2 of options was a bit higher. It was done to reduce the line height space to consume less physical paper.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not convinced.. Can you share the snapshot of the UI.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without altering Margin:
image
With altering Margin:
image

bottom: convertInchesToTwip(0.0093701),
left: convertInchesToTwip(0.3493701),
right: convertInchesToTwip(0.0693701),
},
Expand Down Expand Up @@ -992,6 +994,12 @@ function optionsTabel(testimage) {
});
}

function getLanguageKey(lang, key) {
return basicDetails[lang] && basicDetails[lang][key] ?
basicDetails[lang][key] :
basicDetails[defaultLanguage][key]
}

module.exports = {
create,
};
9 changes: 9 additions & 0 deletions src/service/print/lang/english.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"studentName" : "Student Name",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files should be taken from blob rather than adding to the code repo. Any new language should not require any code code, it will be configuration driven.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where must i save these language files and how we will be using them. If there is any reference, please share.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vaivk369 , please help me with this if you can.

"rollNo": "Roll Number",
"subject": "Subject",
"class": "Class",
"time": "Time",
"marks": "Marks",
"instructionHead": "Instructions"
}
9 changes: 9 additions & 0 deletions src/service/print/lang/hindi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"studentName" : "विद्यार्थी का नाम",
"rollNo": "रोल न",
"subject": "विषय",
"class": "कक्षा",
"time": "समय",
"marks": "कुल अंक",
"instructionHead": "निर्देश"
}