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

Added roboto font #840

Merged
merged 3 commits into from
Jun 11, 2024
Merged
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
32 changes: 16 additions & 16 deletions utilities/project-factory/src/server/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { getErrorCodes } from "./constants";
// Defining the HOST variable
const HOST = process.env.EGOV_HOST ||
"https://unified-qa.digit.org/";
"https://unified-dev.digit.org/";
// Checking if HOST is set, if not, exiting the process
if (!HOST) {
console.log("You need to set the HOST variable");
Expand Down Expand Up @@ -48,8 +48,8 @@ const config = {
DB_CONFIG: {
DB_USER: process.env.DB_USER || "postgres",
DB_HOST: process.env.DB_HOST?.split(':')[0] || "localhost",
DB_NAME: process.env.DB_NAME || "postgres2",
DB_PASSWORD: process.env.DB_PASSWORD || "1234",
DB_NAME: process.env.DB_NAME || "postgres",
DB_PASSWORD: process.env.DB_PASSWORD || "postgres",
DB_PORT: process.env.DB_PORT || "5432",
},
// Application configuration
Expand All @@ -73,20 +73,20 @@ const config = {
host: {
serverHost: HOST,
// Kafka broker host
KAFKA_BROKER_HOST: process.env.KAFKA_BROKER_HOST || "localhost:9092",
mdms: process.env.EGOV_MDMS_HOST || "https://unified-qa.digit.org/",
mdmsV2: process.env.EGOV_MDMS_V2_HOST || "https://unified-qa.digit.org/",
filestore: process.env.EGOV_FILESTORE_SERVICE_HOST || "https://unified-qa.digit.org/",
KAFKA_BROKER_HOST: process.env.KAFKA_BROKER_HOST || "kafka-v2.kafka-cluster:9092",
mdms: process.env.EGOV_MDMS_HOST || "https://unified-dev.digit.org/",
mdmsV2: process.env.EGOV_MDMS_V2_HOST || "https://unified-dev.digit.org/",
filestore: process.env.EGOV_FILESTORE_SERVICE_HOST || "https://unified-dev.digit.org/",
projectFactoryBff: "http://localhost:8080/",
idGenHost: process.env.EGOV_IDGEN_HOST || "https://unified-qa.digit.org/",
facilityHost: process.env.EGOV_FACILITY_HOST || "https://unified-qa.digit.org/",
boundaryHost: process.env.EGOV_BOUNDARY_HOST || "https://unified-qa.digit.org/",
projectHost: process.env.EGOV_PROJECT_HOST || "https://unified-qa.digit.org/",
userHost: process.env.EGOV_USER_HOST || "https://unified-qa.digit.org/",
productHost: process.env.EGOV_PRODUCT_HOST || "https://unified-qa.digit.org/",
hrmsHost: process.env.EGOV_HRMS_HOST || "https://unified-qa.digit.org/",
localizationHost: process.env.EGOV_LOCALIZATION_HOST || "https://unified-qa.digit.org/",
healthIndividualHost: process.env.EGOV_HEALTH_INDIVIDUAL_HOST || "https://unified-qa.digit.org/",
idGenHost: process.env.EGOV_IDGEN_HOST || "https://unified-dev.digit.org/",
facilityHost: process.env.EGOV_FACILITY_HOST || "https://unified-dev.digit.org/",
boundaryHost: process.env.EGOV_BOUNDARY_HOST || "https://unified-dev.digit.org/",
projectHost: process.env.EGOV_PROJECT_HOST || "https://unified-dev.digit.org/",
userHost: process.env.EGOV_USER_HOST || "https://unified-dev.digit.org/",
productHost: process.env.EGOV_PRODUCT_HOST || "https://unified-dev.digit.org/",
hrmsHost: process.env.EGOV_HRMS_HOST || "https://unified-dev.digit.org/",
localizationHost: process.env.EGOV_LOCALIZATION_HOST || "https://unified-dev.digit.org/",
healthIndividualHost: process.env.EGOV_HEALTH_INDIVIDUAL_HOST || "https://unified-dev.digit.org/",
},
// Paths for different services
paths: {
Expand Down
17 changes: 4 additions & 13 deletions utilities/project-factory/src/server/utils/campaignUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { campaignStatuses, headingMapping, resourceDataStatuses } from "../confi
import { getBoundaryColumnName, getBoundaryTabName } from "./boundaryUtils";
import { searchProjectTypeCampaignService } from "../service/campaignManageService";
import { validateBoundaryOfResouces } from "../validators/campaignValidators";
import { getExcelWorkbookFromFileURL, getNewExcelWorkbook, lockTargetFields } from "./excelUtils";
import { getExcelWorkbookFromFileURL, getNewExcelWorkbook, lockTargetFields, updateFontNameToRoboto } from "./excelUtils";
const _ = require('lodash');


Expand Down Expand Up @@ -243,6 +243,7 @@ function processErrorData(request: any, createAndSearchConfig: any, workbook: an

// Adjust the worksheet ref to include the last column
adjustRef(worksheet, lastColumn);
updateFontNameToRoboto(worksheet)
Copy link
Contributor

Choose a reason for hiding this comment

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

The call to updateFontNameToRoboto should be followed by error handling to ensure robustness.

- updateFontNameToRoboto(worksheet)
+ try {
+     updateFontNameToRoboto(worksheet);
+ } catch (error) {
+     logger.error('Failed to update font name to Roboto:', error);
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
updateFontNameToRoboto(worksheet)
try {
updateFontNameToRoboto(worksheet);
} catch (error) {
logger.error('Failed to update font name to Roboto:', error);
}


workbook.xlsx.writeBuffer();
}
Expand Down Expand Up @@ -277,6 +278,7 @@ function processErrorDataForTargets(request: any, createAndSearchConfig: any, wo
}

request.body.additionalDetailsErrors = additionalDetailsErrors;
updateFontNameToRoboto(desiredSheet)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the previous comment, add error handling around the updateFontNameToRoboto function call.

- updateFontNameToRoboto(desiredSheet)
+ try {
+     updateFontNameToRoboto(desiredSheet);
+ } catch (error) {
+     logger.error('Failed to update font name to Roboto in desiredSheet:', error);
+ }

workbook.worksheets[sheetName] = desiredSheet;
}

Expand Down Expand Up @@ -1245,6 +1247,7 @@ async function getCodesTarget(request: any, localizationMap?: any) {
}
});
}
logger.info("Boundary target mapping " + JSON.stringify(boundaryTargetMapping));
return boundaryTargetMapping;
}

Expand Down Expand Up @@ -1380,10 +1383,6 @@ async function createNewSheet(request: any, workbook: any, newSheetData: any, un

// const targetColumnNumber = localizedHeaders.findIndex((header: any) => header == getLocalizedHeaders(config?.targetColumnsForSpecificCampaigns?.smcCampaignColumns, localizationMap));
const boundaryCodeColumnIndex = localizedHeaders.findIndex((header: any) => header === getLocalizedName("HCM_ADMIN_CONSOLE_BOUNDARY_CODE", localizationMap));
// if (targetColumnNumber > -1) {
// // Change the target column background color
// changeFirstRowColumnColour(newSheet, 'B6D7A8', targetColumnNumber + 1);
// }
const responseFromCampaignSearch = await getCampaignSearchResponse(request);
const campaignType = responseFromCampaignSearch?.CampaignDetails[0]?.projectType;
const mdmsResponse = await callMdmsTypeSchema(request, request?.query?.tenantId, request?.query?.type, campaignType)
Expand Down Expand Up @@ -1711,11 +1710,6 @@ const getConfigurableColumnHeadersBasedOnCampaignType = async (request: any, loc
const responseFromCampaignSearch = await getCampaignSearchResponse(request);
const campaignType = responseFromCampaignSearch?.CampaignDetails[0]?.projectType;

// const filters = {
// "title": request?.query?.type || request?.body?.ResourceDetails?.type,
// "campaignType": campaignType
// }
// Call the MDMSV2 API to get data
const mdmsResponse = await callMdmsTypeSchema(request, request?.query?.tenantId || request?.body?.ResourceDetails?.tenantId, request?.query?.type || request?.body?.ResourceDetails?.type, campaignType)
// const mdmsResponse = await callMdmsV2Data(request, config?.values?.moduleName, request?.query?.type || request?.body?.ResourceDetails?.type, request?.query?.tenantId || request?.body?.ResourceDetails?.tenantId, filters);
if (!mdmsResponse || mdmsResponse?.columns.length === 0) {
Expand All @@ -1725,9 +1719,6 @@ const getConfigurableColumnHeadersBasedOnCampaignType = async (request: any, loc
// Extract columns from the response
const columnsForGivenCampaignId = mdmsResponse?.columns;

// // Extract the names of columns and insert them into an array
// const sortedColumnNames = columnsForGivenCampaignId?.map((column: any) => column.name);

// Get localized headers based on the column names
const headerColumnsAfterHierarchy = getLocalizedHeaders(columnsForGivenCampaignId, localizationMap);
if (!headerColumnsAfterHierarchy.includes(getLocalizedName(config.boundary.boundaryCode, localizationMap))) {
Expand Down
20 changes: 19 additions & 1 deletion utilities/project-factory/src/server/utils/excelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ const getExcelWorkbookFromFileURL = async (
return workbook;
};

function updateFontNameToRoboto(worksheet: ExcelJS.Worksheet) {
worksheet.eachRow({ includeEmpty: true }, (row) => {
row.eachCell({ includeEmpty: true }, (cell) => {
// Preserve existing font properties
const existingFont = cell.font || {};

// Update only the font name to Roboto
cell.font = {
...existingFont, // Spread existing properties
name: 'Roboto' // Update the font name
};
});
});
}

function formatWorksheet(worksheet: any, datas: any, headerSet: any) {
// Add empty rows after the main header
worksheet.addRow([]);
Expand Down Expand Up @@ -158,6 +173,7 @@ function addDataToSheet(sheet: any, sheetData: any, firstRowColor: any = '93C47D
if (frozeWholeSheet) {
performFreezeWholeSheet(sheet);
}
updateFontNameToRoboto(sheet);
}


Expand All @@ -171,11 +187,13 @@ function lockTargetFields(newSheet: any, columnsNotToBeFreezed: any, boundaryCod

// // Get headers in the first row and filter out empty items
const headers = newSheet.getRow(1).values.filter((header: any) => header);
logger.info(`Filtered Headers in the first row : ${headers}`);

// Unlock cells in the target columns
if (Array.isArray(columnsNotToBeFreezed) && columnsNotToBeFreezed.length > 0) {
columnsNotToBeFreezed.forEach((header) => {
const targetColumnNumber = headers.indexOf(header) + 1; // Excel columns are 1-based
logger.info(`Header: ${header}, Target Column Index: ${targetColumnNumber}`);
if (targetColumnNumber > -1) {
newSheet.eachRow((row: any, rowNumber: number) => {
changeFirstRowColumnColour(newSheet, 'B6D7A8', targetColumnNumber);
Expand Down Expand Up @@ -209,4 +227,4 @@ function lockTargetFields(newSheet: any, columnsNotToBeFreezed: any, boundaryCod



export { getNewExcelWorkbook, getExcelWorkbookFromFileURL, formatWorksheet, addDataToSheet, lockTargetFields };
export { getNewExcelWorkbook, getExcelWorkbookFromFileURL, formatWorksheet, addDataToSheet, lockTargetFields, updateFontNameToRoboto };
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { generatedResourceStatuses, headingMapping, resourceDataStatuses } from
import { getLocaleFromRequest, getLocalisationModuleName } from "./localisationUtils";
import { getBoundaryColumnName, getBoundaryTabName } from "./boundaryUtils";
import { getBoundaryDataService } from "../service/dataManageService";
import { addDataToSheet, formatWorksheet, getNewExcelWorkbook } from "./excelUtils";
import { addDataToSheet, formatWorksheet, getNewExcelWorkbook, updateFontNameToRoboto } from "./excelUtils";
import createAndSearch from "../config/createAndSearch";
const NodeCache = require("node-cache");

Expand Down Expand Up @@ -486,6 +486,8 @@ async function createReadMeSheet(request: any, workbook: any, mainHeader: any, l

formatWorksheet(worksheet, datas, headerSet);

updateFontNameToRoboto(worksheet);

return worksheet;
}

Expand Down Expand Up @@ -556,6 +558,7 @@ async function getReadMeConfig(request: any) {
}
}


function changeFirstRowColumnColour(facilitySheet: any, color: any, columnNumber = 1) {
// Color the first column header of the facility sheet orange
const headerRow = facilitySheet.getRow(1); // Assuming the first row is the header
Expand Down
Loading