moduleConfig.R 62.2 KB
Newer Older
1
2
# DQAgui - A graphical user interface (GUI) to the functions implemented in the
# R package 'DQAstats'.
3
# Copyright (C) 2019-2022 Universitätsklinikum Erlangen
Lorenz Kapsner's avatar
Lorenz Kapsner committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

18

19
#' @title module_config_server
kapsner's avatar
kapsner committed
20
21
22
23
24
#'
#' @param input Shiny server input object
#' @param output Shiny server output object
#' @param session Shiny session object
#' @param rv The global 'reactiveValues()' object, defined in server.R
25
26
#' @param input_re The Shiny server input object, wrapped into a reactive
#'   expression: input_re = reactive({input})
kapsner's avatar
kapsner committed
27
28
29
#'
#' @export
#'
30
# module_config_server
31
32
33
module_config_server <-
  function(input, output, session, rv, input_re) {
    # filepath roots dir
34
35
36
    roots <- c(
      # home = "/home/",
      home = "~",
37
38
      source = Sys.getenv("CSV_SOURCE_BASEPATH"),
      target = Sys.getenv("CSV_TARGET_BASEPATH")
39
40
    )

41

42
43
44
45
46
47
    ## Mapping between system_type and tab_name:
    system_types_mapping <-
      list("postgres" = "PostgreSQL",
           "csv" = "CSV",
           "oracle" = "Oracle")

48
49
50
51
    # If source-csv-path-button is clicked, read the path and save it:
    # root-folder of shinyFiles::shinyDirChoose
    shinyFiles::shinyDirChoose(
      input = input,
52
53
      id = "config_sourcedir_in",
      roots = roots,
54
55
      defaultRoot = ifelse(roots[["source"]] == "", "home", "source"),
      allowDirCreate = FALSE,
56
      session = session
57
    )
58
59
60

    shinyFiles::shinyDirChoose(
      input = input,
61
62
      id = "config_targetdir_in",
      roots = roots,
63
64
      defaultRoot = ifelse(roots[["target"]] == "", "home", "target"),
      allowDirCreate = FALSE,
65
      session = session
66
    )
67
68

    # observe click button event
69
    observeEvent(
70
      eventExpr = input$config_sourcedir_in,
71
72
      ignoreInit = TRUE,
      ignoreNULL = TRUE,
73
      handlerExpr = {
74
        rv$csv_dir_src_clicked <- FALSE
Lorenz Kapsner's avatar
Lorenz Kapsner committed
75
        rv$csv_dir_src <- as.character(
Jonathan Mang's avatar
Jonathan Mang committed
76
          DIZutils::clean_path_name(
Lorenz Kapsner's avatar
Lorenz Kapsner committed
77
78
79
80
            shinyFiles::parseDirPath(
              roots = roots,
              selection = input$config_sourcedir_in
            )))
81

82
        rv$source$settings$path <- rv$csv_dir_src
83

84
85
86
        if (!identical(rv$source$settings$path, character(0)) &&
            !is.null(rv$source$settings$path) &&
            rv$source$settings$path != "") {
87
88
          # workaround to tell ui, that it is there
          output$source_csv_dir <- reactive({
Jonathan Mang's avatar
Jonathan Mang committed
89
            DIZutils::feedback(
90
              paste0("Source file dir: ",
91
                     rv$source$settings$path),
92
93
94
95
              findme = "ad440c9fcb",
              logfile_dir = rv$log$logfile_dir,
              headless = rv$headless
            )
96
            paste(rv$source$settings$path)
97
98
          })
          outputOptions(output, "source_csv_dir", suspendWhenHidden = FALSE)
99
100
          rv$source$system_name <-
            input_re()[["moduleConfig-source_csv_presettings_list"]]
101
          rv$source$system_type <- "csv"
102

103
          ## Fixes #42 (GitLab):
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
          env_var_name <-
            paste0(toupper(rv$source$system_name), "_PATH")
          DIZutils::feedback(
            print_this = paste0(
              "CSV path '",
              rv$source$settings$path,
              "' was assigned in the GUI.",
              " Assigning it to the environment variable '",
              env_var_name,
              "' now."
            ),
            findme = "272f922ab2",
            logfile_dir = rv$log$logfile_dir,
            headless = rv$headless
          )
          ## Setting the path as environment variable (this must be done via
          ## `do.call` because otherwise the name `env_var_name` will
          ## become the name of the env-var and not its value.
          ## Sys.setenv(env_var_name = rv$source$settings$path) leads to
          ## `env_var_name = "path"` be created and not
          ## `example_name = "path"`):
          DIZutils::setenv2(key = env_var_name, val = rv$source$settings$path)
          rm(env_var_name)

128
129
130
131
          DIZutils::feedback(
            paste0("rv$source$system_type = ",
                   rv$source$system_type),
            findme = "91ebdd5a1d")
132
133
134
135
136
          output$source_system_feedback_txt <-
            renderText({
              feedback_txt(system = "CSV", type = "source")
            })
        }
137
        check_load_data_button(rv, session)
138
      }
139
140
141
    )
    observeEvent(
      eventExpr = input$config_targetdir_in,
142
143
      ignoreInit = TRUE,
      ignoreNULL = TRUE,
144
      handlerExpr = {
145
        rv$csv_dir_tar_clicked <- FALSE
Lorenz Kapsner's avatar
Lorenz Kapsner committed
146
        rv$csv_dir_tar <- as.character(
Jonathan Mang's avatar
Jonathan Mang committed
147
          DIZutils::clean_path_name(
Lorenz Kapsner's avatar
Lorenz Kapsner committed
148
149
150
151
            shinyFiles::parseDirPath(
              roots = roots,
              selection = input$config_targetdir_in
            )))
152
        rv$target$settings$path <- rv$csv_dir_tar
153

154
155
156
        if (!identical(rv$target$settings$path, character(0)) &&
            !is.null(rv$target$settings$path) &&
            rv$target$settings$path != "") {
157
158
          # workaround to tell ui, that it is there
          output$target_csv_dir <- reactive({
Jonathan Mang's avatar
Jonathan Mang committed
159
            DIZutils::feedback(
160
              paste0("Target file dir: ",
161
                     rv$target$settings$path),
162
163
164
165
              findme = "6f18c181e5",
              logfile_dir = rv$log$logfile_dir,
              headless = rv$headless
            )
166
            paste(rv$target$settings$path)
167
168
          })
          outputOptions(output, "target_csv_dir", suspendWhenHidden = FALSE)
169
170
          rv$target$system_name <-
            input_re()[["moduleConfig-target_csv_presettings_list"]]
171
          rv$target$system_type <- "csv"
172

173
          ## Fixes #42 (GitLab):
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
          env_var_name <-
            paste0(toupper(rv$target$system_name), "_PATH")
          DIZutils::feedback(
            print_this = paste0(
              "CSV path '",
              rv$target$settings$path,
              "' was assigned in the GUI.",
              " Assigning it to the environment variable '",
              env_var_name,
              "' now."
            ),
            findme = "fe2b85dc3c",
            logfile_dir = rv$log$logfile_dir,
            headless = rv$headless
          )
          ## Setting the path as environment variable (this must be done via
          ## `do.call` because otherwise the name `env_var_name` will
          ## become the name of the env-var and not its value.
          ## Sys.setenv(env_var_name = rv$target$settings$path) leads to
          ## `env_var_name = "path"` be created and not
          ## `example_name = "path"`):
          DIZutils::setenv2(key = env_var_name, val = rv$target$settings$path)
          rm(env_var_name)

198
199
200
201
          DIZutils::feedback(
            paste0("rv$target$system_type = ",
                   rv$target$system_type),
            findme = "4690c52739")
202
203
204
205
206
          output$target_system_feedback_txt <-
            renderText({
              feedback_txt(system = "CSV", type = "target")
            })
        }
207
        check_load_data_button(rv, session)
208
      }
209
    )
210

211
212
213
214
215
    # load mdr
    observeEvent(
      eventExpr = input_re()[["moduleConfig-config_load_mdr"]],
      handlerExpr = {
        if (is.null(rv$mdr)) {
Jonathan Mang's avatar
Jonathan Mang committed
216
          DIZutils::feedback(
217
218
219
220
221
            print_this = "Reading MDR ...",
            findme = "f877fee7d2",
            logfile_dir = rv$log$logfile_dir,
            headless = rv$headless
          )
Jonathan Mang's avatar
Jonathan Mang committed
222
          DIZutils::feedback(
223
224
            print_this = paste0("MDR-Filename:",
                                rv$mdr_filename),
225
226
227
228
            findme = "582d6a39c6",
            logfile_dir = rv$log$logfile_dir,
            headless = rv$headless
          )
Jonathan Mang's avatar
Jonathan Mang committed
229
          DIZutils::feedback(
230
231
            print_this = paste0("rv$utilspath:",
                                rv$utilspath),
232
233
234
235
            findme = "b5c71849f9",
            logfile_dir = rv$log$logfile_dir,
            headless = rv$headless
          )
236

Lorenz Kapsner's avatar
Lorenz Kapsner committed
237
238
239
240
241
242
          rv$mdr <- button_mdr(
            utils_path = rv$utilspath,
            mdr_filename = rv$mdr_filename,
            logfile_dir = rv$log$logfile_dir,
            headless = rv$headless
          )
243
244
          stopifnot(data.table::is.data.table(rv$mdr))

245
246
247
          ## Read in the settings
          # - Determine the different systems from mdr:
          vec <-
248
            c("source_system_name",
249
250
              "source_system_type")
          rv$systems <- unique(rv$mdr[, vec, with = F])
251
          rv$systems <- rv$systems[!is.na(get("source_system_name"))]
Jonathan Mang's avatar
Jonathan Mang committed
252
          DIZutils::feedback(
253
254
255
256
257
            print_this = paste0(
              "Different systems found in the MDR: ",
              paste(unique(rv$systems[["source_system_name"]]),
                    collapse = ", ")
            ),
258
259
260
261
            findme = "4451da82ad",
            logfile_dir = rv$log$logfile_dir,
            headless = rv$headless
          )
262

263
264
265
266
          # - Read the settings for all these systems:
          unique_systems <-
            rv$systems[!is.na(get("source_system_name")),
                       unique(get("source_system_name"))]
267

268
          # FIXME remove settings reading in the future
269
          rv$settings <-
270
            sapply(unique_systems, function(x) {
271
272
              DIZutils::get_config_env(
                system_name = x,
273
274
275
                logfile_dir = rv$log$logfile_dir,
                headless = rv$headless
              )
276
            }, USE.NAMES = T, simplify = F)
277

278
279
280
          ## Create mapping for display names:
          tmp <- names(rv$settings)
          names(tmp) <- names(rv$settings)
281
282
283
284
285
286
287
          rv$displaynames <- lapply(tmp, function(x) {
            ret <- get_display_name_from_settings(settings = rv$settings,
                                                  prefilter = x)
            return(ret)
          }) %>%
            data.table::as.data.table() %>%
            data.table::transpose(keep.names = "displayname")
288
289
          rm(tmp)
          data.table::setnames(x = rv$displaynames,
290
                               old = "V1",
291
                               new = "source_system_name")
292
          print(rv$displaynames)
293
294


295
296
297
298
          # - Different system-types:
          rv$system_types <-
            rv$systems[!is.na(get("source_system_type")),
                       unique(get("source_system_type"))]
299

Jonathan Mang's avatar
Jonathan Mang committed
300
          DIZutils::feedback(
301
            print_this = rv$system_types,
302
            prefix = "System types:  ",
303
304
305
306
            findme = "9aec84fcca",
            logfile_dir = rv$log$logfile_dir,
            headless = rv$headless
          )
307
308
          if (!("csv" %in% tolower(rv$system_types))) {
            # Remove CSV-Tabs:
Jonathan Mang's avatar
Jonathan Mang committed
309
            DIZutils::feedback(
310
              "Removing csv-tab from source ...",
311
312
313
314
              findme = "3c2f368001",
              logfile_dir = rv$log$logfile_dir,
              headless = rv$headless
            )
Jonathan Mang's avatar
Jonathan Mang committed
315
316
            shiny::removeTab(inputId = "source_tabs",
                             target = system_types_mapping[["csv"]])
317

Jonathan Mang's avatar
Jonathan Mang committed
318
            DIZutils::feedback(
319
              "Removing csv-tab from target ...",
320
321
322
323
              findme = "337b20a126",
              logfile_dir = rv$log$logfile_dir,
              headless = rv$headless
            )
Jonathan Mang's avatar
Jonathan Mang committed
324
325
            shiny::removeTab(inputId = "target_tabs",
                             target = system_types_mapping[["csv"]])
326
327
328
329
330
          } else {
            csv_system_names <-
              rv$systems[get("source_system_type") == "csv" &
                           !is.na(get("source_system_name")),
                         unique(get("source_system_name"))]
Jonathan Mang's avatar
Jonathan Mang committed
331
            DIZutils::feedback(
332
333
334
335
336
337
              csv_system_names,
              prefix = "csv_system_names: ",
              findme = "5a083a3d53",
              logfile_dir = rv$log$logfile_dir,
              headless = rv$headless
            )
338

339
340
341
342
            csv_system_names <-
              rv$displaynames[get("source_system_name") %in%
                                csv_system_names, get("displayname")]

343
344
345
            if (length(csv_system_names) > 0) {
              # Show buttons to prefill diff. systems presettings:
              # - Add a button/choice/etc. for each system:
346
              shiny::updateSelectInput(session = session,
347
348
                                inputId = "source_csv_presettings_list",
                                choices = csv_system_names)
349
              shiny::updateSelectInput(session = session,
350
351
                                inputId = "target_csv_presettings_list",
                                choices = csv_system_names)
352
353
354
355
            }
          }
          if (!("postgres" %in% tolower(rv$system_types))) {
            # Remove Postgres-Tabs:
Jonathan Mang's avatar
Jonathan Mang committed
356
            DIZutils::feedback(
357
358
359
360
              "Removing postgres-tab from source ...",
              logfile_dir = rv$log$logfile_dir,
              headless = rv$headless
            )
Jonathan Mang's avatar
Jonathan Mang committed
361
362
            shiny::removeTab(inputId = "source_tabs",
                             target = system_types_mapping[["postgres"]])
363

Jonathan Mang's avatar
Jonathan Mang committed
364
            DIZutils::feedback(
365
366
367
368
              "Removing postgres-tab from target ...",
              logfile_dir = rv$log$logfile_dir,
              headless = rv$headless
            )
Jonathan Mang's avatar
Jonathan Mang committed
369
370
            shiny::removeTab(inputId = "target_tabs",
                             target = system_types_mapping[["postgres"]])
371
372
373
374
375
376
377
378
379
380
381
          } else{
            # Fill the tab with presettings
            # - filter for all system_names with
            #% system_type == postgres
            #% select source_system_name from
            #% rv$systems where source_system_type == postgres
            #% GROUP BY source_system_name
            postgres_system_names <-
              rv$systems[get("source_system_type") == "postgres" &
                           !is.na(get("source_system_name")),
                         unique(get("source_system_name"))]
Jonathan Mang's avatar
Jonathan Mang committed
382
            DIZutils::feedback(
383
384
385
386
387
388
              postgres_system_names,
              prefix = "postgres_system_names: ",
              findme = "be136f5ab6",
              logfile_dir = rv$log$logfile_dir,
              headless = rv$headless
            )
389

390
391
392
393
            postgres_system_names <-
              rv$displaynames[get("source_system_name") %in%
                                postgres_system_names, get("displayname")]

394
395
396
            if (length(postgres_system_names) > 0) {
              # Show buttons to prefill diff. systems presettings:
              # - Add a button/choice/etc. for each system:
397
              shiny::updateSelectInput(session = session,
398
                                inputId = "source_postgres_presettings_list",
399
                                choices = postgres_system_names)
400
              shiny::updateSelectInput(session = session,
401
                                inputId = "target_postgres_presettings_list",
402
                                choices = postgres_system_names)
403
404
            }
          }
Jonathan Mang's avatar
Jonathan Mang committed
405
406
407
408
409
410
411
412
          if (!("oracle" %in% tolower(rv$system_types))) {
            # Remove Oracle-Tabs:
            DIZutils::feedback(
              "Removing oracle-tab from source ...",
              logfile_dir = rv$log$logfile_dir,
              headless = rv$headless,
              findme = "8e93367dec"
            )
Jonathan Mang's avatar
Jonathan Mang committed
413
414
            shiny::removeTab(inputId = "source_tabs",
                             target = system_types_mapping[["oracle"]])
Jonathan Mang's avatar
Jonathan Mang committed
415
416
417
418
419
420
421

            DIZutils::feedback(
              "Removing oracle-tab from target ...",
              logfile_dir = rv$log$logfile_dir,
              headless = rv$headless,
              findme = "1c2023da56"
            )
Jonathan Mang's avatar
Jonathan Mang committed
422
423
            shiny::removeTab(inputId = "target_tabs",
                             target = system_types_mapping[["oracle"]])
Jonathan Mang's avatar
Jonathan Mang committed
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
          } else{
            # Fill the tab with presettings
            # - filter for all system_names with
            #% system_type == oracle
            #% select source_system_name from
            #% rv$systems where source_system_type == oracle
            #% GROUP BY source_system_name
            oracle_system_names <-
              rv$systems[get("source_system_type") == "oracle" &
                           !is.na(get("source_system_name")),
                         unique(get("source_system_name"))]
            DIZutils::feedback(
              oracle_system_names,
              prefix = "oracle_system_names: ",
              findme = "bea2cd91a1",
              logfile_dir = rv$log$logfile_dir,
              headless = rv$headless
            )

443
444
445
446
            oracle_system_names <-
              rv$displaynames[get("source_system_name") %in%
                                oracle_system_names, get("displayname")]

Jonathan Mang's avatar
Jonathan Mang committed
447
448
449
450
451
452
453
454
455
456
457
            if (length(oracle_system_names) > 0) {
              # Show buttons to prefill diff. systems presettings:
              # - Add a button/choice/etc. for each system:
              updateSelectInput(session = session,
                                inputId = "source_oracle_presettings_list",
                                choices = oracle_system_names)
              updateSelectInput(session = session,
                                inputId = "target_oracle_presettings_list",
                                choices = oracle_system_names)
            }
          }
458
459
460
461
462

          first_system <- tolower(rv$system_types)[[1]]
          DIZutils::feedback(
            print_this = paste0("Setting tab '",
                                first_system,
Jonathan Mang's avatar
Jonathan Mang committed
463
464
                                "' as active tab for source",
                                " and target on config page."),
465
466
467
            findme = "46c03705a8",
            logfile_dir = rv$log$logfile_dir
          )
Jonathan Mang's avatar
Jonathan Mang committed
468
469
470
471
472
473
474
475
          shiny::updateTabsetPanel(
            session = session,
            inputId = "source_tabs",
            selected = system_types_mapping[[first_system]])
          shiny::updateTabsetPanel(
            session = session,
            inputId = "target_tabs",
            selected = system_types_mapping[[first_system]])
Jonathan Mang's avatar
Jonathan Mang committed
476

477
478
479
480
481
482
483
484
485

          # Store the system-types in output-variable to only
          # show these tabs on the config page:
          output$system_types <- reactive({
            rv$system_types
          })
          outputOptions(output,
                        "system_types",
                        suspendWhenHidden = FALSE)
486
487

          # workaround to tell ui, that mdr is there
488
489
490
          output$mdr_present <- reactive({
            return(TRUE)
          })
491
492
493
494
495
496
497
498
499
500
501
502
          outputOptions(output,
                        "mdr_present",
                        suspendWhenHidden = FALSE)

          # workaround to tell ui, that mdr is there
          output$source_system_type <- reactive({
            return(input_re()
                   [["moduleConfig-config_source_system_type"]])
          })
          outputOptions(output,
                        "source_system_type",
                        suspendWhenHidden = FALSE)
503
504
505
506
          output$source_system_feedback_txt <-
            renderText({
              "\U26A0 Please select a source system to load the data."
            })
507
        }
508
        check_load_data_button(rv, session)
509
      })
kapsner's avatar
kapsner committed
510
511


512
513
    # If the "load presets"-button was pressed, startload & show the presets:
    # observeEvent(input$source_pg_presettings_btn, {
514
    observeEvent(input$source_postgres_presettings_list, {
Jonathan Mang's avatar
Jonathan Mang committed
515
      DIZutils::feedback(
516
517
        print_this =
          paste0(
518
            "Input-preset '",
519
            input$source_postgres_presettings_list,
520
            "' was chosen as SOURCE.",
521
522
            " Loading presets ..."
          ),
523
524
525
        findme = "e9832b3092",
        logfile_dir = rv$log$logfile_dir,
        headless = rv$headless
kapsner's avatar
kapsner committed
526
      )
527
528
529
530
531
532
533
      config_stuff <-
        rv$settings[[tolower(input$source_postgres_presettings_list)]]
      config_stuff <-
        get_settings_from_displayname(
          displayname = input$source_postgres_presettings_list,
          settings = rv$settings
        )
534

Jonathan Mang's avatar
Jonathan Mang committed
535
      DIZutils::feedback(
536
537
538
539
        print_this = paste(
          "Loaded successfully.",
          "Filling presets to global rv-object and UI ..."
        ),
540
541
542
        findme = "3c9136d49f",
        logfile_dir = rv$log$logfile_dir,
        headless = rv$headless
543
      )
544
545
      if (length(config_stuff) != 0) {
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
                        inputId = "config_source_postgres_dbname",
                        value = config_stuff[["dbname"]])
        updateTextInput(session = session,
                        inputId = "config_source_postgres_host",
                        value = config_stuff[["host"]])
        updateTextInput(session = session,
                        inputId = "config_source_postgres_port",
                        value = config_stuff[["port"]])
        updateTextInput(session = session,
                        inputId = "config_source_postgres_user",
                        value = config_stuff[["user"]])
        updateTextInput(session = session,
                        inputId = "config_source_postgres_password",
                        value = config_stuff[["password"]])
      } else{
        updateTextInput(session = session,
                        inputId = "config_source_postgres_dbname",
                        value = "")
        updateTextInput(session = session,
                        inputId = "config_source_postgres_host",
                        value = "")
        updateTextInput(session = session,
                        inputId = "config_source_postgres_port",
                        value = "")
        updateTextInput(session = session,
                        inputId = "config_source_postgres_user",
                        value = "")
        updateTextInput(session = session,
                        inputId = "config_source_postgres_password",
                        value = "")
      }
      updateActionButton(
        session = session,
        inputId = "source_postgres_test_connection",
        label = "Test & Save connection",
        icon = icon("database")
      )
      shinyjs::enable("source_postgres_test_connection")
    })

    observeEvent(input$source_oracle_presettings_list, {
      DIZutils::feedback(
        print_this =
          paste0(
            "Input-preset ",
            input$source_oracle_presettings_list,
            " was chosen as SOURCE.",
            " Loading presets ..."
          ),
        findme = "44179e7b1f",
        logfile_dir = rv$log$logfile_dir,
        headless = rv$headless
      )
599
600
601
602
603
      config_stuff <-
        get_settings_from_displayname(
          displayname = input$source_oracle_presettings_list,
          settings = rv$settings
        )
Jonathan Mang's avatar
Jonathan Mang committed
604
605
606
607
608
609
610
611
612
613
614
615
616

      DIZutils::feedback(
        print_this = paste(
          "Loaded successfully.",
          "Filling presets to global rv-object and UI ..."
        ),
        findme = "ff874cb58d",
        logfile_dir = rv$log$logfile_dir,
        headless = rv$headless
      )
      if (length(config_stuff) != 0) {
        updateTextInput(session = session,
                        inputId = "config_source_oracle_dbname",
617
618
                        value = config_stuff[["dbname"]])
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
619
                        inputId = "config_source_oracle_host",
620
621
                        value = config_stuff[["host"]])
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
622
                        inputId = "config_source_oracle_port",
623
624
                        value = config_stuff[["port"]])
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
625
                        inputId = "config_source_oracle_user",
626
627
                        value = config_stuff[["user"]])
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
628
                        inputId = "config_source_oracle_password",
629
                        value = config_stuff[["password"]])
Jonathan Mang's avatar
Jonathan Mang committed
630
631
632
        updateTextInput(session = session,
                        inputId = "config_source_oracle_sid",
                        value = config_stuff[["sid"]])
633
634
      } else{
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
635
636
637
638
                        inputId = "config_source_oracle_dbname",
                        value = "")
        updateTextInput(session = session,
                        inputId = "config_source_oracle_host",
639
640
                        value = "")
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
641
                        inputId = "config_source_oracle_port",
642
643
                        value = "")
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
644
                        inputId = "config_source_oracle_user",
645
646
                        value = "")
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
647
                        inputId = "config_source_oracle_password",
648
649
                        value = "")
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
650
                        inputId = "config_source_oracle_sid",
651
652
                        value = "")
      }
653
654
      updateActionButton(
        session = session,
Jonathan Mang's avatar
Jonathan Mang committed
655
        inputId = "source_oracle_test_connection",
656
657
658
        label = "Test & Save connection",
        icon = icon("database")
      )
Jonathan Mang's avatar
Jonathan Mang committed
659
      shinyjs::enable("source_oracle_test_connection")
660
661
    })

Jonathan Mang's avatar
Jonathan Mang committed
662

663
    #observeEvent(input$target_pg_presettings_btn, {
664
    observeEvent(input$target_postgres_presettings_list, {
Jonathan Mang's avatar
Jonathan Mang committed
665
      DIZutils::feedback(
666
667
        paste0(
          "Input-preset ",
668
          input$target_postgres_presettings_list,
Jonathan Mang's avatar
Jonathan Mang committed
669
          " was chosen as TARGET.",
670
          " Loading presets ..."
671
672
673
674
        ),
        findme = "d603f8127a",
        logfile_dir = rv$log$logfile_dir,
        headless = rv$headless
675
      )
676
677
678
679
680
681
      # config_stuff <-
      config_stuff <-
        get_settings_from_displayname(
          displayname = input$target_postgres_presettings_list,
          settings = rv$settings
        )
682

Jonathan Mang's avatar
Jonathan Mang committed
683
      DIZutils::feedback(
684
685
686
687
688
689
690
691
        paste(
          "Loaded successfully.",
          "Filling presets to global rv-object and UI ..."
        ),
        findme = "fa908f0035",
        logfile_dir = rv$log$logfile_dir,
        headless = rv$headless
      )
692
693
      if (length(config_stuff) != 0) {
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
694
                        inputId = "config_target_postgres_dbname",
695
696
                        value = config_stuff[["dbname"]])
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
697
                        inputId = "config_target_postgres_host",
698
699
                        value = config_stuff[["host"]])
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
700
                        inputId = "config_target_postgres_port",
701
702
                        value = config_stuff[["port"]])
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
703
                        inputId = "config_target_postgres_user",
704
705
                        value = config_stuff[["user"]])
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
706
                        inputId = "config_target_postgres_password",
707
708
709
                        value = config_stuff[["password"]])
      } else{
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
710
                        inputId = "config_target_postgres_dbname",
711
712
                        value = "")
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
713
                        inputId = "config_target_postgres_host",
714
715
                        value = "")
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
716
                        inputId = "config_target_postgres_port",
717
718
                        value = "")
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
719
                        inputId = "config_target_postgres_user",
720
721
                        value = "")
        updateTextInput(session = session,
Jonathan Mang's avatar
Jonathan Mang committed
722
                        inputId = "config_target_postgres_password",
723
724
                        value = "")
      }
725
726
      updateActionButton(
        session = session,
Jonathan Mang's avatar
Jonathan Mang committed
727
        inputId = "target_postgres_test_connection",
728
729
730
        label = "Test & Save connection",
        icon = icon("database")
      )
Jonathan Mang's avatar
Jonathan Mang committed
731
      shinyjs::enable("target_postgres_test_connection")
732
    })
kapsner's avatar
kapsner committed
733

Jonathan Mang's avatar
Jonathan Mang committed
734
735
736
737
738
739
740
741
742
743
744
745
    observeEvent(input$target_oracle_presettings_list, {
      DIZutils::feedback(
        paste0(
          "Input-preset ",
          input$target_oracle_presettings_list,
          " was chosen as TARGET.",
          " Loading presets ..."
        ),
        findme = "1156504e13",
        logfile_dir = rv$log$logfile_dir,
        headless = rv$headless
      )
746
747
748
749
750
751
       # config_stuff <-
      config_stuff <-
        get_settings_from_displayname(
          displayname = input$target_oracle_presettings_list,
          settings = rv$settings
        )
kapsner's avatar
kapsner committed
752

Jonathan Mang's avatar
Jonathan Mang committed
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
      DIZutils::feedback(
        paste(
          "Loaded successfully.",
          "Filling presets to global rv-object and UI ..."
        ),
        findme = "3d39553c3c",
        logfile_dir = rv$log$logfile_dir,
        headless = rv$headless
      )
      if (length(config_stuff) != 0) {
        updateTextInput(session = session,
                        inputId = "config_target_oracle_dbname",
                        value = config_stuff[["dbname"]])
        updateTextInput(session = session,
                        inputId = "config_target_oracle_host",
                        value = config_stuff[["host"]])
        updateTextInput(session = session,
                        inputId = "config_target_oracle_port",
                        value = config_stuff[["port"]])
        updateTextInput(session = session,
                        inputId = "config_target_oracle_user",
                        value = config_stuff[["user"]])
        updateTextInput(session = session,
                        inputId = "config_target_oracle_password",
                        value = config_stuff[["password"]])
        updateTextInput(session = session,
                        inputId = "config_target_oracle_sid",
                        value = config_stuff[["sid"]])
      } else{
        updateTextInput(session = session,
                        inputId = "config_target_oracle_dbname",
                        value = "")
        updateTextInput(session = session,
                        inputId = "config_target_oracle_host",
                        value = "")
        updateTextInput(session = session,
                        inputId = "config_target_oracle_port",
                        value = "")
        updateTextInput(session = session,
                        inputId = "config_target_oracle_user",
                        value = "")
        updateTextInput(session = session,
                        inputId = "config_target_oracle_password",
                        value = "")
        updateTextInput(session = session,
                        inputId = "config_target_oracle_sid",
                        value = "")
800
      }
Jonathan Mang's avatar
Jonathan Mang committed
801
802
803
804
805
806
807
      updateActionButton(
        session = session,
        inputId = "target_oracle_test_connection",
        label = "Test & Save connection",
        icon = icon("database")
      )
      shinyjs::enable("target_oracle_test_connection")
808
    })
kapsner's avatar
kapsner committed
809

810

Jonathan Mang's avatar
Jonathan Mang committed
811
812
813
814
815
816
817
818
819
820
    observeEvent(input$source_postgres_test_connection, {
      test_connection_button_clicked(
        rv = rv,
        source_target = "source",
        db_type = "postgres",
        input = input,
        output = output,
        session = session
      )
    })
821

Jonathan Mang's avatar
Jonathan Mang committed
822
823
824
825
826
827
828
829
830
    observeEvent(input$source_oracle_test_connection, {
      test_connection_button_clicked(
        rv = rv,
        source_target = "source",
        db_type = "oracle",
        input = input,
        output = output,
        session = session
      )
831
832
    })

Jonathan Mang's avatar
Jonathan Mang committed
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
    observeEvent(input$target_postgres_test_connection, {
      test_connection_button_clicked(
        rv = rv,
        source_target = "target",
        db_type = "postgres",
        input = input,
        output = output,
        session = session
      )
    })

    observeEvent(input$target_oracle_test_connection, {
      test_connection_button_clicked(
        rv = rv,
        source_target = "target",
        db_type = "oracle",
        input = input,
        output = output,
        session = session
      )
    })


856
    observeEvent(input$target_system_to_source_system_btn, {
Jonathan Mang's avatar
Jonathan Mang committed
857
858
      if (isTRUE(input$target_system_to_source_system_btn)) {
        ## Target was != source and should become equal:
859
860
861
        # Hide target-setting-tabs:
        hideTab(inputId = "target_tabs", target = "CSV")
        hideTab(inputId = "target_tabs", target = "PostgreSQL")
Jonathan Mang's avatar
Jonathan Mang committed
862
        hideTab(inputId = "target_tabs", target = "Oracle")
863
864
865
866
867
868
869
870
871
872
        # Assign source-values to target:
        rv <- set_target_equal_to_source(rv)
        # Set internal flag that target == source:
        rv$target_is_source <- T
        # Show feedback-box in the UI:
        output$target_system_feedback_txt <-
          renderText({
            feedback_txt(system = "The source system", type = "target")
          })
        # Feedback to the console:
Jonathan Mang's avatar
Jonathan Mang committed
873
        DIZutils::feedback(
874
875
876
877
878
          "Target == source now.",
          findme = "94d3a2090c",
          logfile_dir = rv$log$logfile_dir,
          headless = rv$headless
        )
Jonathan Mang's avatar
Jonathan Mang committed
879
880
881
882
883
884
885
886
      } else if (isFALSE(input$target_system_to_source_system_btn)) {
        ## Target was == source but should become different now:
        rv$target_is_source <- F
        rv$target <- NULL
        output$target_system_feedback_txt <- NULL
        # Show target-settings-tabs again:
        showTab(inputId = "target_tabs", target = "CSV")
        showTab(inputId = "target_tabs", target = "PostgreSQL")
Jonathan Mang's avatar
Jonathan Mang committed
887
        showTab(inputId = "target_tabs", target = "Oracle")
Jonathan Mang's avatar
Jonathan Mang committed
888
889
890
891
892
893
894
        # Feedback to the console:
        DIZutils::feedback(
          "Target != source now.",
          findme = "ec51b122ee",
          logfile_dir = rv$log$logfile_dir,
          headless = rv$headless
        )
895
      }
896
      check_load_data_button(rv, session)
897
    })
898
899
900
901
902
903

    observe({
      if (is.null(rv$sitenames)) {
        # check, if user has provided custom site names
        rv$sitenames <- tryCatch({
          outlist <- jsonlite::fromJSON(
904
            paste0(rv$utilspath, "/MISC/sitenames.JSON")
905
906
907
          )
          outlist
        }, error = function(e) {
908
          outlist <- list("undefined" = "undefined")
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
          outlist
          # TODO instead of dropdown menu, render text input field in the
          # case, users have not provided sitenames. This allows them
          # to specify a name of the DQA session (which will be included
          # into the report's title)
        }, finally = function(f) {
          return(outlist)
        })

        updateSelectInput(
          session,
          "config_sitename",
          choices = rv$sitenames,
          selected = ifelse(!is.null(rv$sitename),
                            rv$sitename,
                            character(0))
        )
      }
    })
928

929
930
931
932
    observeEvent(input_re()[["moduleConfig-dash_load_btn"]], {
      tryCatch({
        ## For runtime calculation:
        start_time <- Sys.time()
933

Lorenz Kapsner's avatar
Lorenz Kapsner committed
934
935
936
937
938
939
940
941
942
943
944
945
        DIZutils::feedback(
          paste0(
            "Restricting date slider state: ",
            input$date_restriction_slider
          ),
          type = "Info",
          findme = "1dcsdfg37b8",
          logfile_dir = rv$log$logfile_dir,
          headless = rv$headless
        )
        rv$restricting_date$use_it <- input$date_restriction_slider

946
947
948
949
950
        # The button is on "moduleConfig".
        # This tab here will be set active below if all inputs are valid.

        # Error flag: If an error occurs, the flag will be set to true
        # and the main calculation won't start:
Lorenz Kapsner's avatar
Lorenz Kapsner committed
951
        error_tmp <- FALSE
952
953
954
955

        # check, if mdr is present. without mdr, we cannot perform any
        # further operations
        if (is.null(rv$mdr)) {
Jonathan Mang's avatar
Jonathan Mang committed
956
          DIZutils::feedback(
957
958
            "No MDR found. Please provide a metadata repository (MDR).",
            type = "Warning",
959
960
961
            findme = "1dc68937b8",
            logfile_dir = rv$log$logfile_dir,
            headless = rv$headless
962
          )
Lorenz Kapsner's avatar
Lorenz Kapsner committed
963
          error_tmp <- TRUE
964
965
966
967
968
969
          # mdr is present:
        } else {
          # check if sitename is present
          if (nchar(input_re()[["moduleConfig-config_sitename"]]) < 2 ||
              any(grepl("\\s", input_re()[["moduleConfig-config_sitename"]]))) {
            # site name is missing:
970
971
972
973
974
975
976
977
            shiny::showModal(shiny::modalDialog(
              title = "The sitename is missing",
              paste0(
                "There are no empty strings or spaces allowed in",
                " the site name configuration.",
                " Please select your site name."
              )
            ))
Lorenz Kapsner's avatar
Lorenz Kapsner committed
978
            error_tmp <- TRUE
979
980
          } else {
            # site name is present:
981
982
            rv$sitename <-
              input_re()[["moduleConfig-config_sitename"]]
983
984
          }

985
986
987
988
989
990
991
992
993
994
          # Check if at least one data element was selected for analyzation:
          if (length(input_re()[[paste0("moduleConfig-select_dqa_assessment",
                                        "_variables")]]) <= 0) {
            DIZutils::feedback(
              print_this = paste0(
                "You didn't specify a data element to",
                " analyze. Please select at least one data element",
                " and try again."
              ),
              type = "UI",
Lorenz Kapsner's avatar
Lorenz Kapsner committed
995
              ui = TRUE,
Jonathan Mang's avatar
Jonathan Mang committed
996
997
              findme = "57562a3092",
              logfile_dir = rv$log$logfile_dir
998
            )
Lorenz Kapsner's avatar
Lorenz Kapsner committed
999
            error_tmp <- TRUE
1000
1001
          }

1002
1003
1004
          # If target should be identical to source, set it here again:
          if (isTRUE(rv$target_is_source)) {
            rv <- set_target_equal_to_source(rv)
Jonathan Mang's avatar
Jonathan Mang committed
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
            DIZutils::feedback(print_this = "Source == Target",
                               findme = "c14c17bf15",
                               logfile_dir = rv$log$logfile_dir,
                               headless = rv$headless
            )
          } else {
            DIZutils::feedback(print_this = "Source != Target",
                               findme = "54fe9a5717",
                               logfile_dir = rv$log$logfile_dir,
                               headless = rv$headless
            )
1016
1017
          }

Jonathan Mang's avatar
Jonathan Mang committed
1018
          DIZutils::feedback(
1019
1020
1021
1022
1023
            paste0("Source system is ", rv$source$system_name),
            findme = "1d61685355",
            logfile_dir = rv$log$logfile_dir,
            headless = rv$headless
          )
Jonathan Mang's avatar
Jonathan Mang committed
1024
          DIZutils::feedback(
1025
1026
1027
1028
1029
            paste0("Target system is ", rv$target$system_name),
            findme = "eaf72ed747",
            logfile_dir = rv$log$logfile_dir,
            headless = rv$headless
          )
1030
1031
        }

1032
1033
1034
1035
1036
        if (validate_inputs(rv,
                            input = input,
                            output = output,
                            session = session) &&
            !error_tmp) {
1037
1038
1039
1040
          # set flags to inactivate config-widgets and start loading of
          # data
          rv$getdata_target <- TRUE
          rv$getdata_source <- TRUE
1041
          rv$start <- TRUE
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054

          if (!dir.exists(paste0(tempdir(), "/_settings/"))) {
            dir.create(paste0(tempdir(), "/_settings/"))
          }

          # save user settings
          writeLines(
            jsonlite::toJSON(
              list(
                "source_system" = rv$source$settings,
                "target_system" = rv$target$settings,
                "site_name" = rv$sitename
              ),
Lorenz Kapsner's avatar
Lorenz Kapsner committed
1055
1056
              pretty = TRUE,
              auto_unbox = FALSE
1057
1058
1059
1060
            ),
            paste0(tempdir(), "/_settings/global_settings.JSON")
          )
        }
1061
1062
1063
1064
1065
      }, error = function(cond) {
        DIZutils::feedback(
          print_this = paste0(cond),
          findme = "05c96798f8",
          type = "Error",
1066
1067
          logfile_dir = rv$log$logfile_dir
        )
1068
        ## Trigger the modal for the user/UI:
Lorenz Kapsner's avatar
Lorenz Kapsner committed
1069
        rv$error <- TRUE
1070
1071
1072
1073
1074
1075
        show_failure_alert(
          paste0(
            "Executing the script to pre-check the",
            " input parameters before data-loading failed"
          )
        )
1076
      })
1077
1078
1079
1080
1081
1082
      print_runtime(
        start_time = start_time,
        name = "moduleConfig-dash_load_btn",
        logfile_dir = rv$log$logfile_dir
      )
    })
1083

Jonathan Mang's avatar
Jonathan Mang committed
1084
    observeEvent(input$select_all_assessment_variables, {
1085
1086
      updateCheckboxGroupInput(
        session = session,
Jonathan Mang's avatar
Jonathan Mang committed
1087
        inputId = "select_dqa_assessment_variables",
1088
        choices = sort(rv$dqa_assessment[["designation"]]),
1089
1090
1091
1092
        selected = rv$dqa_assessment[["designation"]]
      )
    })

Jonathan Mang's avatar
Jonathan Mang committed
1093
    observeEvent(input$select_no_assessment_variables, {
1094
1095
      updateCheckboxGroupInput(
        session = session,
Jonathan Mang's avatar
Jonathan Mang committed
1096
        inputId = "select_dqa_assessment_variables",
1097
        choices = sort(rv$dqa_assessment[["designation"]]),
1098
1099
1100
        selected = NULL
      )
    })
1101

1102
1103
    shiny::observeEvent(eventExpr = input$date_restriction_slider,
                        handlerExpr = {
Lorenz Kapsner's avatar
Lorenz Kapsner committed
1104
                          if (isTRUE(input$date_restriction_slider)) {
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
                            DIZutils::feedback(
                              print_this = "Date restriction will be applied",
                              findme = "4736de090c",
                              logfile_dir = rv$log$logfile_dir
                            )
                            shinyjs::show(id = "datetime_picker")
                            shinyjs::enable(id = "datetime_picker")
                            rv$restricting_date$use_it <- TRUE
                            rv$restricting_date$start <-
                              as.Date(input$datetime_picker[[1]])
                            rv$restricting_date$end <-
                              as.Date(input$datetime_picker[[2]])
                          } else {
                            DIZutils::feedback(
Jonathan Mang's avatar
Jonathan Mang committed
1119
1120
                              print_this = paste0("Date restriction will",
                                                  " NOT be applied"),
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
                              findme = "508c7f34f9",
                              logfile_dir = rv$log$logfile_dir
                            )
                            shinyjs::disable(id = "datetime_picker")
                            shinyjs::hide(id = "datetime_picker")
                            rv$restricting_date$use_it <- FALSE
                            rv$restricting_date$start <- NULL
                            rv$restricting_date$end <- NULL
                          }
                        }
1131
                        , ignoreInit = TRUE
1132
1133
                        )

1134
1135
1136
    ## Date-time picker for date restriction:
    shiny::observeEvent(eventExpr = input$datetime_picker,
                        handlerExpr = {
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
                          rv$restricting_date$use_it <- TRUE
                          rv$restricting_date$start <-
                            as.Date(input$datetime_picker[[1]])
                          rv$restricting_date$end <-
                            as.Date(input$datetime_picker[[2]])

                          output$datetime_picker_info_start <-
                            shiny::renderText({
                              paste0(
                                "Start timestamp: ",
                                input$datetime_picker[[1]]
                              )
                            })
                          output$datetime_picker_info_end <-
1151
1152
                            shiny::renderText({
                              paste0(
1153
                                "End timestamp: ",
1154
1155
1156
                                input$datetime_picker[[2]]
                              )
                            })
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
                          DIZutils::feedback(
                            print_this = paste0(
                              "Using ",
                              rv$restricting_date$start,
                              " as start and ",
                              rv$restricting_date$end,
                              " as end timestamp for filtering the data."
                            ),
                            findme = "04bf478581",
                            logfile_dir = rv$log$logfile_dir,
                            headless = rv$headless
                          )
1169
                        })
1170

Jonathan Mang's avatar
Jonathan Mang committed
1171

1172
  }
kapsner's avatar
kapsner committed
1173

1174
#' @title module_config_ui
kapsner's avatar
kapsner committed
1175
1176
1177
1178
1179
#'
#' @param id A character. The identifier of the shiny object
#'
#' @export
#'
1180
1181
# module_config_ui
module_config_ui <- function(id) {
kapsner's avatar
kapsner committed
1182
1183
  ns <- NS(id)

1184
1185
  tagList(
    fluidRow(
1186
1187
1188
1189
1190
1191
      column(
        9,
        ## This will be displayed after the MDR is loaded successfully:
        conditionalPanel(
          condition =
            "typeof output['moduleConfig-system_types'] !== 'undefined'",
1192
          box(
1193
1194
            title =  "SOURCE settings",
            width = 6,
1195
            #solidHeader = TRUE,
Jonathan Mang's avatar
Jonathan Mang committed
1196
            tabsetPanel(
1197
1198
1199
              # The id lets us use input$source_tabs
              # on the server to find the current tab
              id = ns("source_tabs"),
1200
              # selected = "PostgreSQL",
1201
              tabPanel(
1202
1203
1204
1205
1206
                # ATTENTION: If you change the title, you also have to change
                # the
                # corresponding part above for the "source == source" button
                # reaction. Otherwise the tabs won't hide/show up anymore.
                # >> ATTENTION <<
1207
                title = "CSV",
1208
1209
                # >> ATTENTION << for title. See above.
                id = ns("source_tab_csv"),
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
                h4("Source CSV Upload"),
                box(
                  title = "Available CSV-Systems",
                  # background = "blue",
                  # solidHeader = TRUE,
                  width = 12,
                  selectInput(
                    # This will be filled in the server part.
                    inputId = ns("source_csv_presettings_list"),
                    label = NULL,
                    choices = NULL,
                    selected = NULL
                  ),
                  style = "text-align:center;"
1224
                ),
1225
1226
1227
                div(
                  paste(
                    "Please choose the directory of your",
1228
                    " source data in csv format (default: '/home/input')."
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
                  )
                ),
                br(),
                # If the path is already set, display it
                conditionalPanel(
                  condition = paste0(
                    "typeof ",
                    "output['moduleConfig-source_csv_dir']",
                    " !== 'undefined'"
                  ),
                  verbatimTextOutput(ns("source_csv_dir")),
1240
                  style = "text-align:center;"
1241
                ),
1242
1243
1244
                br(),

                # If there is no path set yet: Display the button to choose it
1245
1246
1247
1248
1249
1250
1251
                shinyFiles::shinyDirButton(
                  id = ns("config_sourcedir_in"),
                  label = "Source Dir",
                  title = "Please select the source directory",
                  buttonType = "default",
                  icon = icon("folder"),
                  class = NULL,
1252
1253
                  style = "text-align:center;"
                )
1254
              ),
1255
              tabPanel(
1256
1257
1258
1259
1260
                # ATTENTION: If you change the title, you also have to change
                # the
                # corresponding part above for the "source == source" button
                # reaction. Otherwise the tabs won't hide/show up anymore.
                # >> ATTENTION <<
1261
                title = "PostgreSQL",
1262
1263
                # >> ATTENTION << for title. See above.
                id = ns("source_tab_pg"),
1264
1265
1266
1267
1268
1269
1270
1271
                h4("Source Database Connection"),
                box(
                  title = "Preloadings",
                  # background = "blue",
                  #solidHeader = TRUE,
                  width = 12,
                  selectInput(
                    # This will be filled in the server part.
1272
                    inputId = ns("source_postgres_presettings_list"),
1273
1274
1275
1276
                    label = NULL,
                    choices = NULL,
                    selected = NULL
                  ),
1277
1278
                  style = "text-align:center;"
                ),
1279
                textInput(
Jonathan Mang's avatar
Jonathan Mang committed
1280
                  inputId = ns("config_source_postgres_dbname"),
1281
1282
                  label = "DB Name",
                  placeholder = "Enter the name of the database ..."
1283
                ),
1284
                textInput(
Jonathan Mang's avatar
Jonathan Mang committed
1285
                  inputId = ns("config_source_postgres_host"),
1286
1287
1288
1289
                  label = "IP",
                  placeholder = "Enter the IP here in format '192.168.1.1' ..."
                ),
                textInput(
Jonathan Mang's avatar
Jonathan Mang committed
1290
                  inputId = ns("config_source_postgres_port"),
1291
1292
1293
1294
                  label = "Port",
                  placeholder = "Enter the Port of the database connection ..."
                ),
                textInput(
Jonathan Mang's avatar
Jonathan Mang committed
1295
                  inputId = ns("config_source_postgres_user"),
1296
1297
1298
1299
1300
                  label = "Username",
                  placeholder =
                    "Enter the Username for the database connection ..."
                ),
                passwordInput(
Jonathan Mang's avatar
Jonathan Mang committed
1301
                  inputId = ns("config_source_postgres_password"),
1302
1303
1304
1305
1306
                  label = "Password",
                  placeholder = "Enter the database password ..."
                ),
                br(),
                actionButton(
Jonathan Mang's avatar
Jonathan Mang committed
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
                  inputId = ns("source_postgres_test_connection"),
                  label = "Test & Save connection",
                  icon = icon("database"),
                  style = "text-align:center;"
                )
              ),
              tabPanel(
                # ATTENTION: If you change the title, you also have to change
                # the
                # corresponding part above for the "target == source" button
                # reaction. Otherwise the tabs won't hide/show up anymore.
                # >> ATTENTION <<
                title = "Oracle",
                # >> ATTENTION << for title. See above.
                id = ns("source_tab_oracle"),
                h4("Source Database Connection"),
                box(
                  title = "Preloadings",
                  # background = "blue",
                  #solidHeader = TRUE,
                  width = 12,
                  selectInput(
                    # This will be filled in the server part.
                    inputId = ns("source_oracle_presettings_list"),
                    label = NULL,
                    choices = NULL,
                    selected = NULL
                  ),
                  style = "text-align:center;"
                ),
                textInput(
                  inputId = ns("config_source_oracle_dbname"),
                  label = "DB Name",
                  placeholder = "Enter the name of the database ..."
                ),
                textInput(
                  inputId = ns("config_source_oracle_host"),
                  label = "IP",
                  placeholder = "Enter the IP here in format '192.168.1.1' ..."
                ),
                textInput(
                  inputId = ns("config_source_oracle_port"),
                  label = "Port",
                  placeholder = "Enter the Port of the database connection ..."
                ),
                textInput(
                  inputId = ns("config_source_oracle_user"),
                  label = "Username",
                  placeholder =
                    "Enter the Username for the database connection ..."
                ),
                passwordInput(
                  inputId = ns("config_source_oracle_password"),
                  label = "Password",
                  placeholder = "Enter the database password ..."
                ),
                textInput(
                  inputId = ns("config_source_oracle_sid"),
                  label = "SID",
                  placeholder =
                    "Enter the SID for the database connection ..."
                ),
                br(),
                actionButton(
                  inputId = ns("source_oracle_test_connection"),
1372
1373
1374
1375
                  label = "Test & Save connection",
                  icon = icon("database"),
                  style = "text-align:center;"
                )
1376
              )
1377
1378
            )
          ),
1379
1380
1381
          box(
            title =  "TARGET settings",
            width = 6,
1382
            #solidHeader = TRUE,
Jonathan Mang's avatar
Jonathan Mang committed
1383
            tabsetPanel(
1384
1385
1386
1387
1388
              # The id lets us use input$target_tabs
              # on the server to find the current tab
              id = ns("target_tabs"),
              # selected = "PostgreSQL",
              tabPanel(
Lorenz Kapsner's avatar
Lorenz Kapsner committed
1389
1390
                # ATTENTION: If you change the title, you also have to change
                # the
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
                # corresponding part above for the "target == source" button
                # reaction. Otherwise the tabs won't hide/show up anymore.
                # >> ATTENTION <<
                title = "CSV",
                # >> ATTENTION << for title. See above.
                id = ns("target_tab_csv"),
                h4("Target CSV Upload"),
                box(
                  title = "Available CSV-Systems",
                  # background = "blue",
                  # solidHeader = TRUE,
                  width = 12,
                  selectInput(
                    # This will be filled in the server part.
                    inputId = ns("target_csv_presettings_list"),
                    label = NULL,
                    choices = NULL,
                    selected = NULL
                  ),
                  style = "text-align:center;"
1411
                ),
1412
1413
1414
                div(
                  paste(
                    "Please choose the directory of your",
1415
                    " target data in csv format (default: '/home/input')."
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
                  )
                ),
                br(),
                # If the path is already set, display it
                conditionalPanel(
                  condition = paste0(
                    "typeof ",
                    "output['moduleConfig-target_csv_dir']",
                    " !== 'undefined'"
                  ),
                  verbatimTextOutput(ns("target_csv_dir")),
1427
                  style = "text-align:center;"
1428
                ),
1429
1430
1431
                br(),

                # If there is no path set yet: Display the button to choose it
1432
1433
1434
1435
1436
1437
1438
                shinyFiles::shinyDirButton(
                  id = ns("config_targetdir_in"),
                  label = "Target Dir",
                  title = "Please select the target directory",
                  buttonType = "default",
                  icon = icon("folder"),
                  class = NULL,
1439
1440
                  style = "text-align:center;"
                )
1441
              ),
1442
              tabPanel(
Lorenz Kapsner's avatar
Lorenz Kapsner committed
1443
1444
                # ATTENTION: If you change the title, you also have to change
                # the
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
                # corresponding part above for the "target == source" button
                # reaction. Otherwise the tabs won't hide/show up anymore.
                # >> ATTENTION <<
                title = "PostgreSQL",
                # >> ATTENTION << for title. See above.
                id = ns("target_tab_pg"),
                h4("Target Database Connection"),
                box(
                  title = "Preloadings",
                  # background = "blue",
                  #solidHeader = TRUE,
                  width = 12,
                  selectInput(
                    # This will be filled in the server part.
1459
                    inputId = ns("target_postgres_presettings_list"),
1460
1461
1462
1463
                    label = NULL,
                    choices = NULL,
                    selected = NULL
                  ),
1464
1465
                  style = "text-align:center;"
                ),
1466
                textInput(
Jonathan Mang's avatar
Jonathan Mang committed
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
                  inputId = ns("config_target_postgres_dbname"),
                  label = "DB Name",
                  placeholder = "Enter the name of the database ..."
                ),
                textInput(
                  inputId = ns("config_target_postgres_host"),
                  label = "IP",
                  placeholder = "Enter the IP here in format '192.168.1.1' ..."
                ),
                textInput(
                  inputId = ns("config_target_postgres_port"),
                  label = "Port",
                  placeholder = "Enter the Port of the database connection ..."
                ),
                textInput(
                  inputId = ns("config_target_postgres_user"),
                  label = "Username",
                  placeholder =
                    "Enter the Username for the database connection ..."
                ),
                passwordInput(
                  inputId = ns("config_target_postgres_password"),
                  label = "Password",
                  placeholder = "Enter the database password ..."
                ),
                br(),
                actionButton(
                  inputId = ns("target_postgres_test_connection"),
                  label = "Test & Save connection",
                  icon = icon("database"),
                  style = "text-align:center;"
                )
              ),
              tabPanel(
                # ATTENTION: If you change the title, you also have to change
                # the
                # corresponding part above for the "target == source" button
                # reaction. Otherwise the tabs won't hide/show up anymore.
                # >> ATTENTION <<
                title = "Oracle",
                # >> ATTENTION << for title. See above.
                id = ns("target_tab_oracle"),
                h4("Target Database Connection"),
                box(
                  title = "Preloadings",
                  # background = "blue",
                  #solidHeader = TRUE,
                  width = 12,
                  selectInput(
                    # This will be filled in the server part.
                    inputId = ns("target_oracle_presettings_list"),
                    label = NULL,
                    choices = NULL,
                    selected = NULL
                  ),
                  style = "text-align:center;"
                ),
                textInput(
                  inputId = ns("config_target_oracle_dbname"),
1526
1527
                  label = "DB Name",
                  placeholder = "Enter the name of the database ..."
1528
                ),
1529
                textInput(
Jonathan Mang's avatar
Jonathan Mang committed
1530
                  inputId = ns("config_target_oracle_host"),
1531
1532
1533
1534
                  label = "IP",
                  placeholder = "Enter the IP here in format '192.168.1.1' ..."
                ),
                textInput(
Jonathan Mang's avatar
Jonathan Mang committed
1535
                  inputId = ns("config_target_oracle_port"),
1536
1537
1538
1539
                  label = "Port",
                  placeholder = "Enter the Port of the database connection ..."
                ),
                textInput(
Jonathan Mang's avatar
Jonathan Mang committed
1540
                  inputId = ns("config_target_oracle_user"),
1541
1542
1543
1544
1545
                  label = "Username",
                  placeholder =
                    "Enter the Username for the database connection ..."
                ),
                passwordInput(
Jonathan Mang's avatar
Jonathan Mang committed
1546
                  inputId = ns("config_target_oracle_password"),
1547
1548
1549
                  label = "Password",
                  placeholder = "Enter the database password ..."
                ),
Jonathan Mang's avatar
Jonathan Mang committed
1550
1551
1552
1553
1554
1555
                textInput(
                  inputId = ns("config_target_oracle_sid"),
                  label = "SID",
                  placeholder =
                    "Enter the SID for the database connection ..."
                ),
1556
1557
                br(),
                actionButton(
Jonathan Mang's avatar
Jonathan Mang committed
1558
                  inputId = ns("target_oracle_test_connection"),
1559
1560
1561
1562
                  label = "Test & Save connection",
                  icon = icon("database"),
                  style = "text-align:center;"
                )
1563
              )
Jonathan Mang's avatar
Jonathan Mang committed
1564
            ),
Jonathan Mang's avatar
Jonathan Mang committed
1565
            tags$hr(),
Jonathan Mang's avatar
Jonathan Mang committed
1566
1567
            checkboxInput(
              inputId = ns("target_system_to_source_system_btn"),
Jonathan Mang's avatar
Jonathan Mang committed
1568
              # inputId = ns("randomstringhere"),
Jonathan Mang's avatar
Jonathan Mang committed
1569
1570
1571
1572
              label = paste0(" Use SOURCE also as TARGET",
                             " (Compare source with itself)"),
              value = FALSE
            ),
Jonathan Mang's avatar
Jonathan Mang committed
1573
            tags$hr()
1574
          )
1575
        )
1576
1577
1578
1579
      ),
      column(
        3,
        conditionalPanel(
Lorenz Kapsner's avatar
Lorenz Kapsner committed
1580
1581
          condition =
            "typeof output['moduleConfig-mdr_present'] == 'undefined'",
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
          box(
            title = "Load Metadata Repository",
            actionButton(
              inputId = ns("config_load_mdr"),
              label = "Load MDR",
              icon = icon("table")
            ),
            width = 12
          )
        ),
        conditionalPanel(
Lorenz Kapsner's avatar
Lorenz Kapsner committed
1593
          condition =
1594
            "typeof output['moduleConfig-mdr_present'] !== 'undefined'",
1595
          box(
Lorenz Kapsner's avatar
Lorenz Kapsner committed
1596
            title = "Load the data",
1597
            h4(htmlOutput(ns("source_system_feedback_txt"))),
Lorenz Kapsner's avatar
Lorenz Kapsner committed
1598
            br(),
1599
            h4(htmlOutput(ns("target_system_feedback_txt"))),
1600
1601
1602
1603
1604
1605
1606
1607
1608
            hr(),
            selectInput(
              ns("config_sitename"),
              "Please enter the name of your site",
              selected = F,
              choices = NULL,
              multiple = F
            ),
            hr(),
1609
1610
            actionButton(ns("dash_load_btn"),
                         "Load data",
1611
1612
1613
1614
1615
                         icon = icon("file-upload"),
                         style = paste0("color: #fff;",
                                        "background-color: #337ab7;",
                                        "border-color: #2e6da4;",
                                        "display:center-align;")),
1616
            width = 12
1617
          ),
1618
1619
          box(
            id = ns("config_select_datetime_picker_box"),
1620
            title = "Do you want to time-filter the input data?",
1621
1622
            shinyWidgets::switchInput(inputId = ns("date_restriction_slider"),
                                      label = "Apply time-filtering",
1623
                                      labelWidth = 150,
Lorenz Kapsner's avatar
Lorenz Kapsner committed
1624
                                      value = NULL,
1625
                                      disabled = TRUE
1626
1627
                                      # , labelWidth = "80px"
                                      ),
1628
1629
            daterangepicker::daterangepicker(
              inputId = ns("datetime_picker"),
1630
1631
1632
1633
              label = "Click to change the date range:",
              start = as.Date("1970-01-01"),
              end = Sys.Date(),
              # style = "width:100%; border-radius:4px",
1634
1635
1636
              ranges = datepicker_get_list_of_ranges(),
              options = list(
                showDropdowns = TRUE,
1637
1638
1639
                # timePicker = TRUE,
                # timePicker24Hour = TRUE,
                autoApply = TRUE,
Jonathan Mang's avatar
Jonathan Mang committed
1640
1641
1642
                locale = list(separator = " <-> ",
                              format = "DD.MM.Y",
                              firstDay = 1)
1643
              )
1644
              # ,icon = shiny::icon("datetime")
1645
1646
1647
            ),
            width = 12
          ),
Lorenz Kapsner's avatar
Lorenz Kapsner committed
1648
          box(
1649
1650
1651
            id = ns("config_select_dqa_assessment_box"),
            title = "Analyse the following data elements",
            hr(),
Lorenz Kapsner's avatar
Lorenz Kapsner committed
1652
            actionButton(
Jonathan Mang's avatar
Jonathan Mang committed
1653
              inputId = ns("select_all_assessment_variables"),
1654
              label = "Select all"
Lorenz Kapsner's avatar
Lorenz Kapsner committed
1655
            ),
1656
            actionButton(
Jonathan Mang's avatar
Jonathan Mang committed
1657
              inputId = ns("select_no_assessment_variables"),
1658
1659
1660
1661
              label = "Unselect all"
            ),
            hr(),
            checkboxGroupInput(
Jonathan Mang's avatar
Jonathan Mang committed
1662
              inputId = ns("select_dqa_assessment_variables"),
1663
1664
              label = NULL,
              choices = NULL),
1665
            width = 12
Lorenz Kapsner's avatar
Lorenz Kapsner committed
1666
          )
1667
        )
1668
1669
1670
      )
    )
  )
kapsner's avatar
kapsner committed
1671
}