Skip to content

Commit dcf0ed9

Browse files
Merge branch 'dh2-1m-rework' into dh2-beta-release
2 parents 8aa5420 + effa943 commit dcf0ed9

File tree

5 files changed

+244
-10
lines changed

5 files changed

+244
-10
lines changed

lib/DataHarmonizer.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -776,17 +776,43 @@ class DataHarmonizer {
776776
// Get the starting row index where the new rows will be added
777777
const startRowIndex = this.hot.countRows();
778778

779-
// Insert the new rows below the last existing row
780-
this.hot.alter('insert_row_below', startRowIndex, numRows);
781779
// Validate and process the current selection
782-
if (
783-
this.context.currentSelection !== null &&
784-
this.context.currentSelection.valueToMatch !== null
785-
) {
786-
// Find the nearest index after the last non-empty row in the specified column
787-
this.populateNewRows(numRows, startRowIndex);
780+
const is1mAndHasParent = (class_assignment) => {
781+
console.log(this.context.currentSelection, this.context.oneToManyAppContext.appContext[class_assignment]);
782+
const unique_keys = this.context.oneToManyAppContext.appContext[class_assignment].unique_keys;
783+
for (let key in unique_keys) {
784+
if ('foreign_key' in unique_keys[key]) {
785+
return unique_keys[key].foreign_key;
786+
}
787+
}
788+
return false;
789+
};
790+
const classIsForeignKeyForClassAndCurrentSelection = (maybe_child_class, currentSelection) => {
791+
const unique_keys = this.context.oneToManyAppContext.appContext[maybe_child_class].unique_keys;
792+
return !isEmptyUnitVal(unique_keys[currentSelection.shared_key_name]) && maybe_child_class !== currentSelection.source;
793+
794+
}
795+
// check if the DH refers to a parent class or class with no children.
796+
// if it has a parent, ensure a foreign key is selected in some parent
797+
// if it doesn't have a parent, use regular add rows implementation
798+
if (is1mAndHasParent(this.class_assignment)) {
799+
if (
800+
!isEmptyUnitVal(this.context.currentSelection) &&
801+
!isEmptyUnitVal(this.context.currentSelection.valueToMatch) &&
802+
classIsForeignKeyForClassAndCurrentSelection(this.class_assignment, this.context.currentSelection)
803+
) {
804+
805+
// Insert the new rows below the last existing row
806+
this.hot.alter('insert_row_below', startRowIndex, numRows);
807+
// Find the nearest index after the last non-empty row in the specified column
808+
this.populateNewRows(numRows, startRowIndex);
809+
} else {
810+
console.warn('No current selection to populate the new rows.');
811+
$('#empty-parent-key-modal').modal('show');
812+
}
788813
} else {
789-
console.warn('No current selection to populate the new rows.');
814+
// Insert the new rows below the last existing row
815+
this.hot.alter('insert_row_below', startRowIndex, numRows);
790816
}
791817
}
792818

lib/Toolbar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import pkg from '../package.json';
3535

3636
const VERSION = pkg.version;
3737

38+
3839
class Toolbar {
3940
constructor(root, context, options = {}) {
4041
this.context = context;

lib/toolbar.html

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,212 @@ <h5 id="template-help-title" data-i18n="template-help-title">
854854
</div>
855855
</div>
856856
</div>
857+
858+
<!-- Duplicate Primary Key Warning -->
859+
<div
860+
class="modal fade"
861+
id="duplicate-primary-key-modal"
862+
tabindex="-1"
863+
role="dialog"
864+
>
865+
<div class="modal-dialog" role="document">
866+
<div class="modal-content">
867+
<div class="modal-body">
868+
<div class="container-fluid">
869+
<div class="row">
870+
<div class="col text-danger">
871+
This primary key value already exists. The previous value will
872+
be retained.
873+
</div>
874+
</div>
875+
<div class="row mt-3">
876+
<div class="col d-flex justify-content-end">
877+
<button
878+
type="button"
879+
class="btn btn-secondary"
880+
data-dismiss="modal"
881+
data-i18n="template-ok"
882+
>
883+
OK
884+
</button>
885+
</div>
886+
</div>
887+
</div>
888+
</div>
889+
</div>
890+
</div>
891+
</div>
892+
893+
<!-- Primary Key Change Warning -->
894+
<div
895+
class="modal fade"
896+
id="primary-key-change-modal"
897+
tabindex="-1"
898+
role="dialog"
899+
>
900+
<div class="modal-dialog" role="document">
901+
<div class="modal-content">
902+
<div class="modal-body">
903+
<div class="container-fluid">
904+
<div class="row">
905+
<div class="col text-danger">
906+
Changing a primary key will affect related records. Do you want
907+
to proceed?
908+
</div>
909+
</div>
910+
<div class="row mt-3">
911+
<div class="col-2 col-sm-6"></div>
912+
<div class="col d-flex justify-content-end">
913+
<button
914+
type="button"
915+
class="btn btn-secondary"
916+
data-dismiss="modal"
917+
data-i18n="template-cancel"
918+
>
919+
Cancel
920+
</button>
921+
</div>
922+
<div class="col d-flex justify-content-end">
923+
<button
924+
type="button"
925+
class="btn btn-danger"
926+
id="pk-change-confirm-btn"
927+
data-dismiss="modal"
928+
data-i18n="template-continue"
929+
>
930+
Continue
931+
</button>
932+
</div>
933+
</div>
934+
</div>
935+
</div>
936+
</div>
937+
</div>
938+
</div>
939+
940+
<!-- Primary Key Delete Warning -->
941+
<div
942+
class="modal fade"
943+
id="primary-key-delete-modal"
944+
tabindex="-1"
945+
role="dialog"
946+
>
947+
<div class="modal-dialog" role="document">
948+
<div class="modal-content">
949+
<div class="modal-body">
950+
<div class="container-fluid">
951+
<div class="row">
952+
<div class="col text-danger">
953+
Deleting this primary key will also remove related foreign key
954+
entries. Continue?
955+
</div>
956+
</div>
957+
<div class="row mt-3">
958+
<div class="col-2 col-sm-6"></div>
959+
<div class="col d-flex justify-content-end">
960+
<button
961+
type="button"
962+
class="btn btn-secondary"
963+
data-dismiss="modal"
964+
data-i18n="template-cancel"
965+
>
966+
Cancel
967+
</button>
968+
</div>
969+
<div class="col d-flex justify-content-end">
970+
<button
971+
type="button"
972+
class="btn btn-danger"
973+
id="pk-delete-confirm-btn"
974+
data-dismiss="modal"
975+
data-i18n="template-continue"
976+
>
977+
Delete
978+
</button>
979+
</div>
980+
</div>
981+
</div>
982+
</div>
983+
</div>
984+
</div>
985+
</div>
986+
987+
<!-- Undo Changes Warning -->
988+
<div class="modal fade" id="undo-changes-modal" tabindex="-1" role="dialog">
989+
<div class="modal-dialog" role="document">
990+
<div class="modal-content">
991+
<div class="modal-body">
992+
<div class="container-fluid">
993+
<div class="row">
994+
<div class="col text-danger">
995+
Are you sure you want to undo all changes to primary keys?
996+
</div>
997+
</div>
998+
<div class="row mt-3">
999+
<div class="col-2 col-sm-6"></div>
1000+
<div class="col d-flex justify-content-end">
1001+
<button
1002+
type="button"
1003+
class="btn btn-secondary"
1004+
data-dismiss="modal"
1005+
data-i18n="template-cancel"
1006+
>
1007+
Cancel
1008+
</button>
1009+
</div>
1010+
<div class="col d-flex justify-content-end">
1011+
<button
1012+
type="button"
1013+
class="btn btn-danger"
1014+
id="undo-confirm-btn"
1015+
data-dismiss="modal"
1016+
data-i18n="template-continue"
1017+
>
1018+
Undo
1019+
</button>
1020+
</div>
1021+
</div>
1022+
</div>
1023+
</div>
1024+
</div>
1025+
</div>
1026+
</div>
1027+
1028+
<!-- Empty Parent Key Warning -->
1029+
<div
1030+
class="modal fade"
1031+
id="empty-parent-key-modal"
1032+
tabindex="-1"
1033+
role="dialog"
1034+
>
1035+
<div class="modal-dialog" role="document">
1036+
<div class="modal-content">
1037+
<div class="modal-body">
1038+
<div class="container-fluid">
1039+
<div class="row">
1040+
<div class="col text-danger">
1041+
Please select a parent row with a valid primary key before
1042+
adding child rows.
1043+
</div>
1044+
</div>
1045+
<div class="row mt-3">
1046+
<div class="col d-flex justify-content-end">
1047+
<button
1048+
type="button"
1049+
class="btn btn-secondary"
1050+
data-dismiss="modal"
1051+
data-i18n="template-ok"
1052+
>
1053+
OK
1054+
</button>
1055+
</div>
1056+
</div>
1057+
</div>
1058+
</div>
1059+
</div>
1060+
</div>
1061+
</div>
1062+
8571063
<div id="missing-template-modal" role="dialog" style="display: none">
8581064
<div class="modal-dialog" role="document">
8591065
<div class="modal-content" style="z-index: 2000">

lib/utils/templates.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export async function accessTemplate(
6969
const template = template_manifest.children.find(
7070
(el) => el.name === template_name
7171
);
72+
console.info(template, template_manifest);
7273
return template ? processNode(template, fetchFileImpl) : null;
7374
}
7475

web/templates/menu.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"display": true
2121
}
2222
},
23-
"grdi": {
23+
"grdi_1m": {
2424
"GRDI": {
2525
"name": "GRDI",
2626
"status": "published",

0 commit comments

Comments
 (0)