Skip to content

Power User dashboard: implement real Fremdbewertung overview + add missing comparison PDF handler#1

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-fremdbewertung-tab
Draft

Power User dashboard: implement real Fremdbewertung overview + add missing comparison PDF handler#1
Copilot wants to merge 4 commits into
mainfrom
copilot/fix-fremdbewertung-tab

Conversation

Copy link
Copy Markdown

Copilot AI commented May 7, 2026

Power User TAB 7 (Fremdbewertung) was still wired to demo-only UI and did not expose project-scoped Fremdbewertung data. This PR aligns the Power User experience with the existing admin Fremdbewertung overview and adds the missing server-side handler for the already-rendered poweruser_download_comparison button.

  • TAB 7 UI replacement (demo → data-backed overview)

    • Replaced warning/placeholder content with a full overview layout:
      • poweruser_fremd_project project selector
      • poweruser_fremdbewertung_summary summary cards
      • reviewer/section filters (poweruser_fremd_filter_user, poweruser_fremd_filter_section) + refresh button
      • poweruser_fremdbewertung_table DT output
      • poweruser_download_fremdbewertung_csv export button
  • Power User project dropdown wiring

    • Extended the existing get_all_projects()-driven updateSelectInput(...) block inside the Power User role observer to also populate poweruser_fremd_project.
  • Power User Fremdbewertung server logic

    • Added poweruser_fremdbewertung_summary (renderUI) with project-scoped counts:
      • distinct reviewers
      • total responses
    • Added poweruser_fremdbewertung_data reactive using the required DB query shape and optional filters:
      • reviewer exact match
      • section prefix match (question_id LIKE 'X%')
    • Added poweruser_fremdbewertung_table (renderDataTable) over the reactive dataset.
    • Added project-scoped reviewer-choice refresh for poweruser_fremd_filter_user.
    • Added poweruser_download_fremdbewertung_csv (downloadHandler) exporting the same filtered dataset.
  • Missing comparison download handler

    • Implemented output$poweruser_download_comparison <- downloadHandler(...) in the Power User server section, next to other Power User report downloads.
    • Handler resolves project title from input$poweruser_report_project, generates Vergleichstabelle_<Projekt>_<date>.pdf, and calls generate_comparison_pdf(file, project_id, user_role()).
output$poweruser_download_comparison <- downloadHandler(
  filename = function() {
    project_id <- input$poweruser_report_project
    project_title <- tryCatch({
      get_all_projects() %>%
        dplyr::filter(id == as.integer(project_id)) %>%
        dplyr::pull(title)
    }, error = function(e) "Projekt")
    paste0("Vergleichstabelle_", gsub(" ", "_", project_title), "_", Sys.Date(), ".pdf")
  },
  content = function(file) {
    req(input$poweruser_report_project)
    project_id <- input$poweruser_report_project
    if (is.null(project_id) || project_id == "") return(NULL)
    generate_comparison_pdf(file, project_id, user_role())
  }
)
Original prompt

Problem

Two fixes are needed in the Power User dashboard inside app.R:


Fix 1 — Fremdbewertung tab (TAB 7 in poweruser_tabs)

Currently TAB 7 ("Fremdbewertung") in the power user dashboard only shows a demo warning banner and a uiOutput("poweruser_fremdbewertung_ui") placeholder. It does not show real project data.

Required change:

Replace the demo content with a fully functional Fremdbewertung overview that mirrors the existing admin fremdbewertungen tabItem. Specifically:

  1. Add a project dropdown selector (selectInput("poweruser_fremd_project", ...)) at the top of the tab — populated from get_all_projects() inside the power user observeEvent(user_role(), ...) block.
  2. Show a summary cards row: uiOutput("poweruser_fremdbewertung_summary").
  3. Show filter dropdowns for reviewer (selectInput("poweruser_fremd_filter_user", ...)) and section (selectInput("poweruser_fremd_filter_section", ...)) plus a refresh button.
  4. Show a DT table DT::dataTableOutput("poweruser_fremdbewertung_table") with actual data from the DB.
  5. Add a CSV export button: downloadButton("poweruser_download_fremdbewertung_csv", ...).

In the server logic (inside observeEvent(user_role(), { if (user_role() == "power_user") { ... } })) add:

  • Populate poweruser_fremd_project dropdown from get_all_projects() (add to the existing observe({ ... updateSelectInput ... }) block).
  • output$poweruser_fremdbewertung_summary — render summary cards (count of reviewers, count of responses) for the selected project, similar in style to fremdbewertung_summary but scoped to input$poweruser_fremd_project.
  • output$poweruser_fremdbewertung_tablerenderDT that queries:
    SELECT 
      u.username as reviewer,
      r.question_id,
      r.response_value,
      r.assessment_type,
      TO_CHAR(r.submitted_at AT TIME ZONE 'Europe/Berlin', 'DD.MM.YYYY HH24:MI') as submitted_at
    FROM responses r
    JOIN users u ON u.id = r.user_id
    WHERE r.project_id = $1
      AND r.assessment_type = 'fremdbewertung'
    ORDER BY u.username, r.question_id
    filtered by input$poweruser_fremd_project, and optionally by input$poweruser_fremd_filter_user and input$poweruser_fremd_filter_section (question_id LIKE section%).
  • After loading data, update poweruser_fremd_filter_user choices from unique reviewers.
  • output$poweruser_download_fremdbewertung_csvdownloadHandler that exports the same data as a CSV.

Fix 2 — Missing poweruser_download_comparison download handler

In the UI there is already a download button:

downloadButton(
  "poweruser_download_comparison",
  "Vergleichstabelle herunterladen (Selbst- Vs. Fremdbewertung)",
  class = "btn-info",
  icon = icon("table")
)

But there is no corresponding downloadHandler in the server logic for the power user role. The existing output$download_comparison_pdf handler exists only for admin/leading_peer role.

Required change:

Inside observeEvent(user_role(), { if (user_role() == "power_user") { ... } }), add:

output$poweruser_download_comparison <- downloadHandler(
  filename = function() {
    project_id <- input$poweruser_report_project
    project_title <- tryCatch({
      get_all_projects() %>%
        dplyr::filter(id == as.integer(project_id)) %>%
        dplyr::pull(title)
    }, error = function(e) "Projekt")
    paste0("Vergleichstabelle_", gsub(" ", "_", project_title), "_", Sys.Date(), ".pdf")
  },
  content = function(file) {
    req(input$poweruser_report_project)
    project_id <- input$poweruser_report_project
    if (is.null(project_id) || project_id == "") {
      showNotification("Kein Projekt ausgewählt!", type = "error", duration = 5)
      return(NULL)
    }
    generate_comparison_pdf(file, project_id, user_role())
  }
)

Place this handler alongside the other poweruser_download_* handlers (near poweruser_download_zusammenfassung, poweruser_download_labinfo, etc.).


Important notes

  • All changes are inside app.R.
  • Do NOT break any existing functionality.
  • Follow the same coding style and patterns already used in the file.
  • The get_all_projects() reactive and con DB connection are already available inside the power user observeEvent block.

The following is the prior conversation context from the user's chat exploration (may be truncated):

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Fix Fremdbewertung tab to display real project data Power User dashboard: implement real Fremdbewertung overview + add missing comparison PDF handler May 7, 2026
Copilot AI requested a review from kola8513 May 7, 2026 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants