1- // SPDX-FileCopyrightText: 2025 Christian Winger <https://github.com/wingechr> © Öko-Institut e.V.
2- // SPDX-FileCopyrightText: 2025 Eike Broda <https://github.com/ebroda>
3- // SPDX-FileCopyrightText: 2025 Jonas Huber <https://github.com/jh-RLI> © Reiner Lemoine Institut
4- // SPDX-FileCopyrightText: 2025 Jonas Huber <https://github.com/jh-RLI> © Reiner Lemoine Institut
5- // SPDX-FileCopyrightText: 2025 Christian Winger <https://github.com/wingechr> © Öko-Institut e.V.
6- // SPDX-FileCopyrightText: 2025 user <https://github.com/Darynarli> © Reiner Lemoine Institut
7- //
8- // SPDX-License-Identifier: AGPL-3.0-or-later
1+ /* eslint-disable max-len */
2+ /*
3+ SPDX-FileCopyrightText: 2025 Christian Winger <https://github.com/wingechr> © Öko-Institut e.V.
4+ SPDX-FileCopyrightText: 2025 Eike Broda <https://github.com/ebroda>
5+ SPDX-FileCopyrightText: 2025 Jonas Huber <https://github.com/jh-RLI> © Reiner Lemoine Institut
6+ SPDX-FileCopyrightText: 2025 Jonas Huber <https://github.com/jh-RLI> © Reiner Lemoine Institut
7+ SPDX-FileCopyrightText: 2025 Christian Winger <https://github.com/wingechr> © Öko-Institut e.V.
8+ SPDX-FileCopyrightText: 2025 user <https://github.com/Darynarli> © Reiner Lemoine Institut
9+ SPDX-License-Identifier: AGPL-3.0-or-later
10+ */
11+ /* eslint-enable max-len */
912
1013window . Wizard = function ( config ) {
1114 var state = {
@@ -122,7 +125,7 @@ window.Wizard = function (config) {
122125 * add a new column in the create table section
123126 */
124127 function addColumn ( columnDef ) {
125- columnDef = columnDef || { } ;
128+ columnDef = columnDef || { is_nullable : true } ;
126129 var columns = $ ( "#wizard-columns" ) ;
127130 var n = columns . find ( ".wizard-column" ) . length ;
128131 var column = $ ( "#wizard-column-template" )
@@ -172,7 +175,6 @@ window.Wizard = function (config) {
172175 * add a new column in the csv upload section
173176 */
174177 function addColumnCsv ( columnDef ) {
175- // console.log("add column csv", columnDef)
176178 columnDef = columnDef || { } ;
177179 var columns = $ ( "#wizard-csv-columns" ) ;
178180 var n = columns . find ( ".wizard-csv-column" ) . length ;
@@ -375,7 +377,6 @@ window.Wizard = function (config) {
375377 * Update the upload preview table
376378 */
377379 function updatePreview ( ) {
378- // console.log('updatePreview', state)
379380 var tbody = $ ( "#wizard-csv-preview" ) . find ( "tbody" ) ;
380381 tbody . empty ( ) ;
381382 var rows = state . previewRows . length
@@ -397,6 +398,11 @@ window.Wizard = function (config) {
397398 * The selected file has changed
398399 */
399400 function updateFile ( ) {
401+ /* reset */
402+ state . previewRows = [ ] ;
403+ updateExample ( ) ;
404+ updatePreview ( ) ;
405+
400406 // console.log('updateFile')
401407 state . file = $ ( "#wizard-file" ) ;
402408 state . encoding = $ ( "#wizard-encoding" ) . find ( ":selected" ) . val ( ) ;
@@ -434,7 +440,6 @@ window.Wizard = function (config) {
434440 * Update the example data
435441 */
436442 function updateExample ( ) {
437- // console.log('updateExample')
438443 var exampleText = "" ;
439444 if ( state . columns ) {
440445 var delim = state . delimiter || "," ;
@@ -462,14 +467,17 @@ window.Wizard = function (config) {
462467 * a file settings option (e.g. delimiter, encoding, ...) has been changed
463468 */
464469 function changeFileSettings ( ) {
465- // console.log('changeFileSettings')
470+ $ ( "#wizard-table-upload" ) . hide ( ) ;
471+
466472 updateFile ( ) ;
473+
467474 state . csvColumns = [ ] ;
468475 state . previewRows = [ ] ;
469476 updateExample ( ) ;
470477 $ ( "#wizard-csv-columns" ) . empty ( ) ;
471478 $ ( "#wizard-csv-text" ) . text ( "" ) ;
472479 if ( state . file ) {
480+ setStatusUpload ( "info" , false , "checking file" , true ) ;
473481 state . file . parse ( {
474482 config : {
475483 encoding : state . encoding ,
@@ -516,9 +524,23 @@ window.Wizard = function (config) {
516524 }
517525 }
518526 updateColumnMapping ( ) ;
527+ $ ( "#wizard-table-upload" ) . show ( ) ;
528+ setStatusUpload (
529+ "info" ,
530+ false ,
531+ "" ,
532+ false
533+ ) ; /* remove status message*/
519534 } ,
520535 error : function ( error ) {
521- setStatusUpload ( "danger" , false , error , false ) ;
536+ var msg = error . message ;
537+ if ( msg == "File could not be read" ) {
538+ msg =
539+ "File could not be read " +
540+ "(Probably too large - should be smaller than 1 GB)" ;
541+ }
542+ console . error ( msg ) ;
543+ setStatusUpload ( "danger" , false , msg , false ) ;
522544 } ,
523545 } ,
524546 } ) ;
@@ -587,8 +609,9 @@ window.Wizard = function (config) {
587609 }
588610
589611 /** *
590- * NOTE: the api returns Bigints as connection/cursor ids, and the normal JSON.parse truncates those
591- * so we need to parse those manually to extract the id and keep it as string
612+ * NOTE: the api returns Bigints as connection/cursor ids, and the normal JSON.parse
613+ * truncates those so we need to parse those manually to extract the id
614+ * and keep it as string
592615 */
593616 function getJSONBigintKey ( key , str ) {
594617 var pat = new RegExp ( '"' + key + '":[ ]*([0-9]+)' ) ;
@@ -602,11 +625,6 @@ window.Wizard = function (config) {
602625 * First we open a new advanced connection and cursor
603626 * We read the csv in chunks (set size in state variable)
604627 * on each chunk we pause and and post the data. on success we resume the csv parser
605- *
606- ,
607-
608-
609- *
610628 */
611629 function csvUpload ( ) {
612630 Promise . all ( [
@@ -669,7 +687,10 @@ window.Wizard = function (config) {
669687 data . data = data . data . slice ( 1 ) ;
670688 }
671689 if ( data . data . length > 0 ) {
672- // if chunk size is too small, you can get a chunk with 0 complete rows, but the database does not allow empty insert
690+ /*
691+ if chunk size is too small, you can get a chunk with 0 complete
692+ rows, but the database does not allow empty insert
693+ */
673694 state . csvParser = parser ;
674695 // pause the csv parser
675696 state . csvParser . pause ( ) ;
@@ -714,7 +735,6 @@ window.Wizard = function (config) {
714735 return sendJson ( "POST" , urlConClose , createContext ( ) ) ;
715736 } )
716737 . then ( function ( ) {
717- // setStatusUpload("success", false, "Upload ok: " + state.uploadedRows + " rows", false);
718738 resetUpload ( ) ; // reset or reload page
719739 setStatusUpload (
720740 "success" ,
@@ -768,15 +788,16 @@ window.Wizard = function (config) {
768788 var data = {
769789 query : {
770790 columns : colDefs ,
771- embargo : embargoValue === "none" ? null : { duration : embargoValue } , // Conditional check
791+ // Conditional check
792+ embargo : embargoValue === "none" ? null : { duration : embargoValue } ,
772793 // "embargo": embargoData
773794 } ,
774795 } ;
775796
776797 Promise . all ( [
777798 window . reverseUrl ( "api:api_table" , { table : tablename } ) ,
778799 window . reverseUrl ( "dataedit:wizard_upload" , {
779- table : tablename ,
800+ table : tablename ,
780801 } ) ,
781802 ] ) . then ( ( [ urlTable , urlSuccess ] ) => {
782803 sendJson ( "PUT" , urlTable , JSON . stringify ( data ) )
@@ -816,32 +837,9 @@ window.Wizard = function (config) {
816837 } ;
817838 }
818839
819- /**
820- * delete table
821- */
822- function deleteTable ( ) {
823- $ ( "#wizard-confirm-delete" ) . modal ( "hide" ) ;
824- setStatusCreate ( "primary" , true , "deleting table..." ) ;
825- var tablename = $ ( "#wizard-tablename" ) . val ( ) ;
826-
827- Promise . all ( [
828- window . reverseUrl ( "api:api_table" , { table : tablename } ) ,
829- window . reverseUrl ( "dataedit:wizard_create" ) ,
830- ] ) . then ( ( [ urlTable , urlSuccess ] ) => {
831- sendJson ( "DELETE" , urlTable )
832- . then ( function ( ) {
833- setStatusCreate ( "success" , true , "ok, reloading page..." ) ;
834- window . location = urlSuccess ;
835- } )
836- . catch ( function ( err ) {
837- setStatusCreate ( "danger" , false , getErrorMsg ( err ) ) ;
838- } ) ;
839- } ) ;
840- }
841-
842840 function resetUpload ( ) {
843841 state . cancel = null ;
844- $ ( "#wizard-table-upload" ) . show ( ) ;
842+ $ ( "#wizard-table-upload" ) . hide ( ) ;
845843 $ ( "#wizard-table-upload-cancel" ) . hide ( ) ;
846844 $ ( "#wizard-file" ) . val ( "" ) ;
847845 changeFileSettings ( ) ;
@@ -854,25 +852,22 @@ window.Wizard = function (config) {
854852 data_type : "bigserial" ,
855853 is_nullable : false ,
856854 } ) ;
855+
857856 new bootstrap . Collapse ( "#wizard-container-create" , {
858857 toggle : false ,
859858 } ) . show ( ) ;
860859 new bootstrap . Collapse ( "#wizard-container-upload" , {
861860 toggle : false ,
862861 } ) . hide ( ) ;
863- $ ( "#wizard-table-delete" ) . hide ( ) ;
862+
864863 $ ( "#wizard-container-upload" ) . find ( ".btn" ) . hide ( ) ;
865864 $ ( "#wizard-container-upload" ) . find ( "input" ) . prop ( "readonly" , true ) ;
866865 }
867866
868867 function showUpload ( ) {
869- new bootstrap . Collapse ( "#wizard-container-create" , {
870- toggle : false ,
871- } ) . hide ( ) ;
872868 new bootstrap . Collapse ( "#wizard-container-upload" , {
873869 toggle : false ,
874870 } ) . show ( ) ;
875- $ ( "#wizard-table-delete" ) . show ( ) ;
876871
877872 $ ( "#wizard-container-create" ) . find ( ".btn" ) . hide ( ) ;
878873 $ ( "#wizard-container-create" ) . find ( "input" ) . prop ( "readonly" , true ) ;
@@ -931,7 +926,6 @@ window.Wizard = function (config) {
931926 }
932927
933928 ( function init ( ) {
934- // console.log('init')
935929 var cParseDiv = $ ( "#wizard-csv-column-template .wizard-csv-column-parse" ) ;
936930 Object . keys ( columnParsers ) . map ( function ( k ) {
937931 cParseDiv . append (
@@ -956,12 +950,6 @@ window.Wizard = function (config) {
956950 tgt . addClass ( "is-invalid" ) ;
957951 }
958952 } ) ;
959- // Add this block to remove the "Create Table" card if canAdd is true
960- if ( state . canAdd ) {
961- // Remove the "Create Table" card
962- $ ( "#wizard-container-create" ) . closest ( ".card" ) . remove ( ) ;
963- }
964-
965953 resetUpload ( ) ;
966954 if ( state . table ) {
967955 $ ( "#wizard-tablename" ) . val ( state . table ) ;
@@ -977,15 +965,6 @@ window.Wizard = function (config) {
977965 cN . append ( "<option>" + c . name + "</option>" ) ;
978966 } ) ;
979967
980- /* delete table */
981- $ ( "#wizard-table-delete" ) . bind ( "click" , function ( ) {
982- $ ( "#wizard-confirm-delete" ) . modal ( "show" ) ;
983- } ) ;
984- $ ( "#wizard-confirm-delete-cancel" ) . bind ( "click" , function ( ) {
985- $ ( "#wizard-confirm-delete" ) . modal ( "hide" ) ;
986- } ) ;
987- $ ( "#wizard-confirm-delete-delete" ) . bind ( "click" , deleteTable ) ;
988-
989968 showUpload ( ) ;
990969 } else {
991970 showCreate ( ) ;
0 commit comments