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 1 commit
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
8 changes: 5 additions & 3 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 @@ -230,7 +233,7 @@ async function getStack(htmlString, questionCounter) {
nextLine = `${envVariables.baseURL}` + src;
}
count++;

}
}
if (!nextLine)
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
37 changes: 19 additions & 18 deletions src/service/print/docxHelper.js
Original file line number Diff line number Diff line change
@@ -1,13 +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: 'I', ii: 'II', iii: 'III', iv: 'IV'},
hindi: {i: 'क', ii: 'ख', iii: 'ग', iv: 'घ'},
english: {i: 'I', ii: 'II', iii: 'III', iv: 'IV'},
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are the using the keys as i, ii, iii, iv, why can't it be just an array of strings?

optionLabelling = {
"en": ["I", "II", "III" ......],
"hi": ["क", "ख", "ग" ......]
}

This should be configuration driven. should not hardcode here. Later if we want another language, it should be config change. Code should work.

Copy link
Author

Choose a reason for hiding this comment

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

Yes will be implementing this.

Copy link
Author

Choose a reason for hiding this comment

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

Shall I resolve this conversation, as this one is implemented?

hindi: {i: 'क', ii: 'ख', iii: 'ग', iv: 'घ'},
}
const defaultLanguage = 'english'

var {
docDefinition,
Expand Down Expand Up @@ -241,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 @@ -274,20 +275,20 @@ async function renderMCQ(question, questionCounter, marks) {
typeof questionOptions[0][0] === "object"
) {
if (questionOptions[0][0].text) {
questionOpt.push([`${getLanguageKey(question.medium[0].toLowerCase(), 'i')+")"}`, questionOptions[0][0].text[1]]);
questionOpt.push([`${getLanguageKey(printLanguage, 'i')+")"}`, questionOptions[0][0].text[1]]);
Copy link
Contributor

Choose a reason for hiding this comment

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

@vaivk369 suggest the better approach of pushing the question to the array.

imageProperties.push({
width: 0,
height: 0,
});
} else {
questionOpt.push([`${getLanguageKey(question.medium[0].toLowerCase(), 'i')+")"}`, questionOptions[0][0].image]);
questionOpt.push([`${getLanguageKey(printLanguage, 'i')+")"}`, questionOptions[0][0].image]);
imageProperties.push({
width: questionOptions[0][0].width,
height: questionOptions[0][0].height,
});
}
} else {
questionOpt.push([`${getLanguageKey(question.medium[0].toLowerCase(), 'i')+")"}`, questionOptions[0][0]]);
questionOpt.push([`${getLanguageKey(printLanguage, 'i')+")"}`, questionOptions[0][0]]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't you move the entire this logic into different function as pass the index to it
for loop
setOption(index, questionOptions)

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

Copy link
Contributor

Choose a reason for hiding this comment

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

This way if there are only 2 option or more than 4 also the code will works.

Copy link
Author

Choose a reason for hiding this comment

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

This is done @vinukumar-vs

Copy link
Author

Choose a reason for hiding this comment

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

Shall I resolve this conversation, as this is implemented too?

imageProperties.push({
width: 0,
height: 0,
Expand All @@ -301,20 +302,20 @@ async function renderMCQ(question, questionCounter, marks) {
typeof questionOptions[1][0] === "object"
) {
if (questionOptions[1][0].text) {
questionOpt.push([`${getLanguageKey(question.medium[0].toLowerCase(), 'ii')+")"}`, questionOptions[1][0].text[1]]);
questionOpt.push([`${getLanguageKey(printLanguage, 'ii')+")"}`, questionOptions[1][0].text[1]]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why should I use the same key "II" for all the languages.

Copy link
Author

Choose a reason for hiding this comment

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

Cause there must be default options labeling in case of undefined language.

Copy link
Author

Choose a reason for hiding this comment

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

Shall I resolve this conversation?

imageProperties.push({
width: 0,
height: 0,
});
} else {
questionOpt.push([`${getLanguageKey(question.medium[0].toLowerCase(), 'ii')+")"}`, questionOptions[1][0].image]);
questionOpt.push([`${getLanguageKey(printLanguage, 'ii')+")"}`, questionOptions[1][0].image]);
imageProperties.push({
width: questionOptions[1][0].width,
height: questionOptions[1][0].height,
});
}
} else {
questionOpt.push([`${getLanguageKey(question.medium[0].toLowerCase(), 'ii')+")"}`, questionOptions[1][0]]);
questionOpt.push([`${getLanguageKey(printLanguage, 'ii')+")"}`, questionOptions[1][0]]);
imageProperties.push({
width: 0,
height: 0,
Expand All @@ -328,20 +329,20 @@ async function renderMCQ(question, questionCounter, marks) {
typeof questionOptions[2][0] === "object"
) {
if (questionOptions[2][0].text) {
questionOpt.push([`${getLanguageKey(question.medium[0].toLowerCase(), 'iii')+")"}`, questionOptions[2][0].text[1]]);
questionOpt.push([`${getLanguageKey(printLanguage, 'iii')+")"}`, questionOptions[2][0].text[1]]);
imageProperties.push({
width: 0,
height: 0,
});
} else {
questionOpt.push([`${getLanguageKey(question.medium[0].toLowerCase(), 'iii')+")"}`, questionOptions[2][0].image]);
questionOpt.push([`${getLanguageKey(printLanguage, 'iii')+")"}`, questionOptions[2][0].image]);
imageProperties.push({
width: questionOptions[2][0].width,
height: questionOptions[2][0].height,
});
}
} else {
questionOpt.push([`${getLanguageKey(question.medium[0].toLowerCase(), 'iii')+")"}`, questionOptions[2][0]]);
questionOpt.push([`${getLanguageKey(printLanguage, 'iii')+")"}`, questionOptions[2][0]]);
imageProperties.push({
width: 0,
height: 0,
Expand All @@ -355,20 +356,20 @@ async function renderMCQ(question, questionCounter, marks) {
typeof questionOptions[3][0] === "object"
) {
if (questionOptions[3][0].text) {
questionOpt.push([`${getLanguageKey(question.medium[0].toLowerCase(), 'iv')+")"}`, questionOptions[3][0].text[1]]);
questionOpt.push([`${getLanguageKey(printLanguage, 'iv')+")"}`, questionOptions[3][0].text[1]]);
imageProperties.push({
width: 0,
height: 0,
});
} else {
questionOpt.push([`${getLanguageKey(question.medium[0].toLowerCase(), 'iv')+")"}`, questionOptions[3][0].image]);
questionOpt.push([`${getLanguageKey(printLanguage, 'iv')+")"}`, questionOptions[3][0].image]);
imageProperties.push({
width: questionOptions[3][0].width,
height: questionOptions[3][0].height,
});
}
} else {
questionOpt.push([`${getLanguageKey(question.medium[0].toLowerCase(), 'iv')+")"}`, questionOptions[3][0]]);
questionOpt.push([`${getLanguageKey(printLanguage, 'iv')+")"}`, questionOptions[3][0]]);
imageProperties.push({
width: 0,
height: 0,
Expand Down Expand Up @@ -503,9 +504,9 @@ async function renderMTF(question, questionCounter, marks, Type) {
return mtfData;
}
function getLanguageKey(lang, key) {
return optionLabelling[lang] && optionLabelling[lang][key] ?
optionLabelling[lang][key] :
optionLabelling['english'][key]
return optionLabelling[lang] && optionLabelling[lang][key] ?
optionLabelling[lang][key] :
optionLabelling[defaultLanguage][key]
}

module.exports = {
Expand Down
19 changes: 9 additions & 10 deletions src/service/print/getdocxdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ const basicDetails={
}

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

const doc = new Document({
sections: [
Expand Down Expand Up @@ -235,9 +234,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 @@ -720,8 +719,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 @@ -1002,11 +1001,11 @@ function optionsTabel(testimage) {
}

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

module.exports = {
create,
};
};