Skip to content

Commit

Permalink
Merge branch 'dh2-1m-rework' into dh2-beta-release
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethbruskiewicz committed Dec 18, 2024
2 parents 8aa5420 + effa943 commit dcf0ed9
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 10 deletions.
44 changes: 35 additions & 9 deletions lib/DataHarmonizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,17 +776,43 @@ class DataHarmonizer {
// Get the starting row index where the new rows will be added
const startRowIndex = this.hot.countRows();

// Insert the new rows below the last existing row
this.hot.alter('insert_row_below', startRowIndex, numRows);
// Validate and process the current selection
if (
this.context.currentSelection !== null &&
this.context.currentSelection.valueToMatch !== null
) {
// Find the nearest index after the last non-empty row in the specified column
this.populateNewRows(numRows, startRowIndex);
const is1mAndHasParent = (class_assignment) => {
console.log(this.context.currentSelection, this.context.oneToManyAppContext.appContext[class_assignment]);
const unique_keys = this.context.oneToManyAppContext.appContext[class_assignment].unique_keys;
for (let key in unique_keys) {
if ('foreign_key' in unique_keys[key]) {
return unique_keys[key].foreign_key;
}
}
return false;
};
const classIsForeignKeyForClassAndCurrentSelection = (maybe_child_class, currentSelection) => {
const unique_keys = this.context.oneToManyAppContext.appContext[maybe_child_class].unique_keys;
return !isEmptyUnitVal(unique_keys[currentSelection.shared_key_name]) && maybe_child_class !== currentSelection.source;

}
// check if the DH refers to a parent class or class with no children.
// if it has a parent, ensure a foreign key is selected in some parent
// if it doesn't have a parent, use regular add rows implementation
if (is1mAndHasParent(this.class_assignment)) {
if (
!isEmptyUnitVal(this.context.currentSelection) &&
!isEmptyUnitVal(this.context.currentSelection.valueToMatch) &&
classIsForeignKeyForClassAndCurrentSelection(this.class_assignment, this.context.currentSelection)
) {

// Insert the new rows below the last existing row
this.hot.alter('insert_row_below', startRowIndex, numRows);
// Find the nearest index after the last non-empty row in the specified column
this.populateNewRows(numRows, startRowIndex);
} else {
console.warn('No current selection to populate the new rows.');
$('#empty-parent-key-modal').modal('show');
}
} else {
console.warn('No current selection to populate the new rows.');
// Insert the new rows below the last existing row
this.hot.alter('insert_row_below', startRowIndex, numRows);
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import pkg from '../package.json';

const VERSION = pkg.version;


class Toolbar {
constructor(root, context, options = {}) {
this.context = context;
Expand Down
206 changes: 206 additions & 0 deletions lib/toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,212 @@ <h5 id="template-help-title" data-i18n="template-help-title">
</div>
</div>
</div>

<!-- Duplicate Primary Key Warning -->
<div
class="modal fade"
id="duplicate-primary-key-modal"
tabindex="-1"
role="dialog"
>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col text-danger">
This primary key value already exists. The previous value will
be retained.
</div>
</div>
<div class="row mt-3">
<div class="col d-flex justify-content-end">
<button
type="button"
class="btn btn-secondary"
data-dismiss="modal"
data-i18n="template-ok"
>
OK
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<!-- Primary Key Change Warning -->
<div
class="modal fade"
id="primary-key-change-modal"
tabindex="-1"
role="dialog"
>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col text-danger">
Changing a primary key will affect related records. Do you want
to proceed?
</div>
</div>
<div class="row mt-3">
<div class="col-2 col-sm-6"></div>
<div class="col d-flex justify-content-end">
<button
type="button"
class="btn btn-secondary"
data-dismiss="modal"
data-i18n="template-cancel"
>
Cancel
</button>
</div>
<div class="col d-flex justify-content-end">
<button
type="button"
class="btn btn-danger"
id="pk-change-confirm-btn"
data-dismiss="modal"
data-i18n="template-continue"
>
Continue
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<!-- Primary Key Delete Warning -->
<div
class="modal fade"
id="primary-key-delete-modal"
tabindex="-1"
role="dialog"
>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col text-danger">
Deleting this primary key will also remove related foreign key
entries. Continue?
</div>
</div>
<div class="row mt-3">
<div class="col-2 col-sm-6"></div>
<div class="col d-flex justify-content-end">
<button
type="button"
class="btn btn-secondary"
data-dismiss="modal"
data-i18n="template-cancel"
>
Cancel
</button>
</div>
<div class="col d-flex justify-content-end">
<button
type="button"
class="btn btn-danger"
id="pk-delete-confirm-btn"
data-dismiss="modal"
data-i18n="template-continue"
>
Delete
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<!-- Undo Changes Warning -->
<div class="modal fade" id="undo-changes-modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col text-danger">
Are you sure you want to undo all changes to primary keys?
</div>
</div>
<div class="row mt-3">
<div class="col-2 col-sm-6"></div>
<div class="col d-flex justify-content-end">
<button
type="button"
class="btn btn-secondary"
data-dismiss="modal"
data-i18n="template-cancel"
>
Cancel
</button>
</div>
<div class="col d-flex justify-content-end">
<button
type="button"
class="btn btn-danger"
id="undo-confirm-btn"
data-dismiss="modal"
data-i18n="template-continue"
>
Undo
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<!-- Empty Parent Key Warning -->
<div
class="modal fade"
id="empty-parent-key-modal"
tabindex="-1"
role="dialog"
>
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col text-danger">
Please select a parent row with a valid primary key before
adding child rows.
</div>
</div>
<div class="row mt-3">
<div class="col d-flex justify-content-end">
<button
type="button"
class="btn btn-secondary"
data-dismiss="modal"
data-i18n="template-ok"
>
OK
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<div id="missing-template-modal" role="dialog" style="display: none">
<div class="modal-dialog" role="document">
<div class="modal-content" style="z-index: 2000">
Expand Down
1 change: 1 addition & 0 deletions lib/utils/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export async function accessTemplate(
const template = template_manifest.children.find(
(el) => el.name === template_name
);
console.info(template, template_manifest);
return template ? processNode(template, fetchFileImpl) : null;
}

Expand Down
2 changes: 1 addition & 1 deletion web/templates/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"display": true
}
},
"grdi": {
"grdi_1m": {
"GRDI": {
"name": "GRDI",
"status": "published",
Expand Down

0 comments on commit dcf0ed9

Please sign in to comment.