Skip to content

Commit

Permalink
Various tasks for NEFBA2 (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
mihailistov committed Mar 26, 2024
1 parent 01132d5 commit 24837f3
Show file tree
Hide file tree
Showing 10 changed files with 590 additions and 44 deletions.
2 changes: 1 addition & 1 deletion assets/application/js/application.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function () {
const src =
'https://cdn.jsdelivr.net/gh/bcgov/nr-af-pods@dev/powerpod/releases/powerpod-0.9.8.min.js';
'https://cdn.jsdelivr.net/gh/bcgov/nr-af-pods@dev/powerpod/releases/powerpod-0.9.9.min.js';
const script = document.createElement('script');
script.setAttribute('async', '');
script.src = src;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"tags": ["Application", "StaffPortal", "NEFBA2", "NEFBA Phase 2"],
"version": "1.1.5",
"version": "1.1.9",
"name": "New Entrant Farm Business Accelerator Phase 2",
"abbreviation": "NEFBA2",
"hiddenSteps": "tab_Project",
Expand Down Expand Up @@ -135,15 +135,11 @@
"name": "quartech_totalprojectcost",
"label": "Total Project Cost ($CAD):",
"bold": true,
"allowNegatives": true,
"required": true,
"readOnly": true,
"format": "currency",
"maxDigits": 13,
"validation": {
"type": "numeric",
"value": "0",
"comparison": "greaterThanOrEqualTo"
}
"maxDigits": 13
},
{
"name": "quartech_totaladdedincome",
Expand Down Expand Up @@ -173,15 +169,11 @@
"name": "quartech_totaladdedincomeandreducedcosts",
"label": "Total added income and reduced costs ($CAD):",
"bold": true,
"allowNegatives": true,
"required": true,
"readOnly": true,
"format": "currency",
"maxDigits": 13,
"validation": {
"type": "numeric",
"value": "0",
"comparison": "greaterThanOrEqualTo"
}
"maxDigits": 13
},
{
"name": "quartech_totaladdedcost",
Expand Down Expand Up @@ -211,29 +203,21 @@
"name": "quartech_totaladdedcostsandreducedincome",
"label": "Total added costs and reduced income ($CAD):",
"bold": true,
"allowNegatives": true,
"required": true,
"readOnly": true,
"format": "currency",
"maxDigits": 13,
"validation": {
"type": "numeric",
"value": "0",
"comparison": "greaterThanOrEqualTo"
}
"maxDigits": 13
},
{
"name": "quartech_netchangeinprofit",
"label": "Net change in profit ($CAD):",
"bold": true,
"allowNegatives": true,
"required": true,
"readOnly": true,
"format": "currency",
"maxDigits": 13,
"validation": {
"type": "numeric",
"value": "0",
"comparison": "greaterThanOrEqualTo"
}
"maxDigits": 13
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion assets/claim/js/claim.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function () {
const src =
'https://cdn.jsdelivr.net/gh/bcgov/nr-af-pods@dev/powerpod/releases/powerpod-0.9.8.min.js';
'https://cdn.jsdelivr.net/gh/bcgov/nr-af-pods@dev/powerpod/releases/powerpod-0.9.9.min.js';
const script = document.createElement('script');
script.setAttribute('async', '');
script.src = src;
Expand Down
2 changes: 1 addition & 1 deletion powerpod/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "powerpod",
"type": "module",
"version": "0.9.8",
"version": "0.9.9",
"description": "Powerpod is a jQuery plugin that enhances functionality of Power Pages components.",
"main": "dist/powerpod",
"scripts": {
Expand Down
479 changes: 479 additions & 0 deletions powerpod/releases/powerpod-0.9.9.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion powerpod/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import typescript from '@rollup/plugin-typescript';
import css from 'rollup-plugin-import-css';

const licenseContent = `/*!
* powerpod 0.9.8
* powerpod 0.9.9
* https://github.com/bcgov/nr-af-pods/powerpod
*
* @license GPLv3 for open source use only
Expand Down
8 changes: 7 additions & 1 deletion powerpod/src/js/common/fieldConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import {
getFieldsBySectionClaim,
getFieldsBySectionApplication,
} from './fields.js';
import { hideFieldByFieldName, observeChanges, showFieldRow } from './html.js';
import {
combineElementsIntoOneRowNew,
hideFieldByFieldName,
observeChanges,
showFieldRow,
} from './html.js';
import { Logger } from './logger.js';
import { FieldMaskType, maskInput } from './masking.js';
import { getOptions } from './options.js';
Expand Down Expand Up @@ -74,6 +79,7 @@ export function configureFields() {
doNotBlank = false,
fileTypes, // not currently used anywhere
visibleIf,
oneLine,
} = fields[i];
logger.info({
fn: configureFields,
Expand Down
7 changes: 6 additions & 1 deletion powerpod/src/js/common/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import {
getClaimConfigData,
getGlobalConfigData,
} from './config.js';
import { showFieldRow, showFieldsetElement } from './html.js';
import {
combineElementsIntoOneRowNew,
showFieldRow,
showFieldsetElement,
} from './html.js';
import { Logger } from './logger.js';
import { getProgramAbbreviation } from './program.ts';
import { POWERPOD } from './constants.js';
Expand Down Expand Up @@ -110,6 +114,7 @@ export function getFieldsBySectionApplication(stepName, forceRefresh = false) {
}

fields.forEach((s) => {
combineElementsIntoOneRowNew(s.name);
if (s.visibleIf) {
logger.warn({
fn: getFieldsBySectionClaim,
Expand Down
96 changes: 84 additions & 12 deletions powerpod/src/js/common/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export function getControlType(tr) {
export function isEmptyRow(tr) {
const firstTd = tr.querySelector('td');
if (
!firstTd ||
firstTd?.getAttribute('quartechHtml') === 'true' ||
firstTd?.getAttribute('class').includes('zero-cell') ||
firstTd.children?.length === 0
) {
Expand Down Expand Up @@ -160,35 +162,70 @@ export function addHtmlToSection(
htmlContentToAdd,
topOrBottom = 'top'
) {
const sectionTable = doc.querySelector(`table[data-name='${tableDataName}'`);
const sectionTable = doc.querySelector(
`table[data-name='${tableDataName}'] > tbody`
);
if (!sectionTable) {
logger.error({
fn: addHtmlToSection,
message: `Unable to add to section of tableDataName: ${tableDataName}, could not find section`,
});
return;
}
const divElement = doc.createElement('div');
divElement.innerHTML = htmlContentToAdd;
const trElement = doc.createElement('tr');

const tdElement = document.createElement('td');
tdElement.setAttribute('colspan', '2');
tdElement.setAttribute('quartechHtml', 'true');
tdElement.innerHTML = htmlContentToAdd;

trElement.appendChild(tdElement);

if (topOrBottom === 'top') {
sectionTable.prepend(divElement);
sectionTable.prepend(trElement);
} else if (topOrBottom === 'bottom') {
sectionTable.append(divElement);
sectionTable.append(trElement);
}
}

export function addTextAboveField(fieldName, htmlContentToAdd) {
const fieldLabelDivContainer = $(`#${fieldName}_label`).parent();
if (!fieldLabelDivContainer) return;

fieldLabelDivContainer.prepend(htmlContentToAdd);
addHtmlToField(fieldName, htmlContentToAdd, 'top');
}

export function addTextBelowField(fieldName, htmlContentToAdd) {
const fieldLabelDivContainer = $(`#${fieldName}_label`).parent().parent();
if (!fieldLabelDivContainer) return;
addHtmlToField(fieldName, htmlContentToAdd, 'bottom');
}

export function addHtmlToField(
fieldName,
htmlContentToAdd,
topOrBottom = 'top'
) {
const tr = $(`#${fieldName}`).closest('tr');
if (!tr) return;

const uuid = crypto.randomUUID();

fieldLabelDivContainer.append(htmlContentToAdd);
if (topOrBottom === 'top') {
$(`<tr data-uuid='${uuid}'></tr>`).insertBefore(tr);
} else if (topOrBottom === 'bottom') {
$(`<tr data-uuid='${uuid}'></tr>`).insertAfter(tr);
}
const newTrElement = $(`tr[data-uuid="${uuid}"]`);

if (!newTrElement || !newTrElement?.length) {
logger.error({
fn: addHtmlToField,
message: 'Failed to create new row',
});
}

const tdElement = document.createElement('td');
tdElement.setAttribute('colspan', '2');
tdElement.setAttribute('quartechHtml', 'true');
tdElement.innerHTML = htmlContentToAdd;

newTrElement.append(tdElement);
}

export function observeChanges(element, customFunc) {
Expand Down Expand Up @@ -359,6 +396,41 @@ export function setFieldValue(name, value) {
element.dispatchEvent(e);
}

export function combineElementsIntoOneRowNew(name) {
const inputElement = $(`#${name}`);
const labelElement = $(`#${name}_label`);

const inputTd = inputElement.closest('td');
const labelTd = labelElement.closest('td');

if (!inputTd.is(labelTd)) {
logger.warn({
fn: combineElementsIntoOneRowNew,
message: `Skipping... elements must've already been combined, since label and input are in different cells`,
data: { name, inputElement, labelElement, inputTd, labelTd },
});
return;
}

const tableElement = inputElement.closest('table.section');

// find and delete colgroup config, if it exists
tableElement.find('colgroup')?.remove();

const controlDiv = inputElement.closest('div.control');

const tr = inputElement.closest('tr');

const clonedTd = inputTd.clone();
clonedTd.attr('colspan', '1');
tr.append(clonedTd);

controlDiv.remove();

const newInfoDiv = clonedTd.find('div.info');
newInfoDiv.remove();
}

export function combineElementsIntoOneRow(
valueElementId,
descriptionInputElementId
Expand Down
2 changes: 1 addition & 1 deletion powerpod/src/js/powerpod.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function setAPI() {
};
};
// @ts-ignore
POWERPOD.version = '0.9.8';
POWERPOD.version = '0.9.9';
// @ts-ignore
win.powerpod = POWERPOD;
}

0 comments on commit 24837f3

Please sign in to comment.