Skip to content

Commit

Permalink
Merge pull request #15 from antistatique/bugfixes
Browse files Browse the repository at this point in the history
Bugfixes
  • Loading branch information
gido authored Nov 11, 2022
2 parents b329a58 + fd1ac4a commit f8ab23b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{
"matches": [
"*://*.harvestapp.com/estimates/*/edit",
"*://*.harvestapp.com/estimates/*/duplicate",
"*://*.harvestapp.com/estimates/new",
"*://*.harvestapp.com/estimates/*"
],
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ ready(() => {
} else if (d.querySelector('#edit_estimate')) {
targetQueryElement = '#edit_estimate > .pds-mt-md';
appView = 'edit';
} else if (d.querySelector('#new_estimate')) {
targetQueryElement = '#new_estimate > .pds-mt-md';
appView = 'new';
} else {
// page not compatible with this plugin
return false;
Expand All @@ -49,7 +52,7 @@ ready(() => {
// Init summary generation
app.generateSummary();

if ('edit' === appView) {
if ('edit' === appView || 'new' === appView) {
// Generate PM tools
const show_pm_factor_field = browser.storage.local.get('show_pm_factor_field');
show_pm_factor_field.then(res => app.initPM(app, res));
Expand Down
3 changes: 2 additions & 1 deletion src/lib/airtable.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const airtableSelector = (templates, types) => {
.value;

// Restart select generator if type changes
// @TODO: don't add multiple time the same addEventListener. Remove this from the forEach.
itemTypeSelect.addEventListener('change', () => {
airtableSelector(templates, types);
});
Expand Down Expand Up @@ -114,7 +115,7 @@ const airtableSelector = (templates, types) => {

// Create select with options
const airtableSelectTemplate = d.createElement('select');
airtableSelectTemplate.className = 'select-template';
airtableSelectTemplate.className = 'select-template pds-input pds-input-xs';
airtableSelectTemplate.name = 'airtable-template';
airtableSelectTemplate.style.marginBottom = '1em';
airtableSelectTemplate.style.fontSize = '14px;';
Expand Down
25 changes: 11 additions & 14 deletions src/lib/summary.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
const extractFloatAmountFromText = function (amountAsText) {
// this works for number format: 1'234.56 (but not for 1 234,56)
// check https://*.harvestapp.com/company/preferences/edit
return parseFloat(amountAsText.replaceAll(/[^0-9.]/g, ''));
};

/**
* Render a summray table at the bottom of the estimate during edition
*/
Expand All @@ -18,12 +24,8 @@ const generateSummaryEdit = () => {
const select = element.querySelector('select');
const type = select.options[select.selectedIndex].value;
const qty = parseFloat(element.querySelector('.js-change-total').value);
const amount = parseFloat(
element
.querySelector('.amount')
.innerText.substring(4) // Remove 'CHF '
.replace(/'/, ''), // Remove currency formatting 10'500 -> 10500
);
const amountAsText = element.querySelector('.amount').innerText;
const amount = extractFloatAmountFromText(amountAsText);

totalQty += qty;
totalAmount += amount;
Expand Down Expand Up @@ -60,7 +62,7 @@ const generateSummaryView = () => {
let totalQty = 0;
let totalAmount = 0;

if (!d.querySelector('.client-doc-rows') || d.querySelector('.edit_estimate')) {
if (!d.querySelector('.client-doc-rows') || d.querySelector('.edit_estimate') || d.querySelector('.new_estimate')) {
return ;
}

Expand All @@ -71,13 +73,8 @@ const generateSummaryView = () => {
const select = element.querySelector('select');
const type = element.querySelector('.item-type').innerText.trim();
const qty = parseFloat(element.querySelector('.item-qty').innerText.trim());
const amount = parseFloat(
element
.querySelector('.item-amount')
.innerText.trim()
.substring(4) // Remove 'CHF '
.replace(/'/, ''), // Remove currency formatting 10'500 -> 10500
);
const amountAsText = element.querySelector('.item-amount').innerText.trim();
const amount = extractFloatAmountFromText(amountAsText);

totalQty += qty;
totalAmount += amount;
Expand Down

0 comments on commit f8ab23b

Please sign in to comment.