rustploy-gui 0.1.77

Rustploy — desktop client (glacier-ui) for the Rustploy PaaS daemon
// Settings → Sincronização: o estado de infra (projetos, serviços, jobs,
// secrets cifrados) versionado num repositório git. Fases 6 e 7 de
// docs/plano-backup-estado-em-git.md. O STATUS vem no snapshot
// (format/state_git.luau → ctx.state_git_*); a webui faz o mesmo em
// `webui/index.html` (aba "Sync"): mude os dois juntos.
component {
  resources {
    component(name = SemRemovidosNoGit) {
      text("{t('settings_gitsync.nothing_removed')}", class = u-muted)
    }
    component(name = SemValoresEmClaro) {
      text("{t('settings_gitsync.no_plaintext_value')}", class = u-muted)
    }
  }

  scrollable(direction = vertical, class = u-fill-all) {
    // O scrollable aceita um filho só: os painéis (situação, divergência, ...)
    // vão dentro desta coluna.
    column(class = form-stack) {
    column(class = "form-panel form-panel--grouped") {
      column(class = form-panel__head) {
        text("{t('settings_gitsync.git_sync')}", class = u-label-cap)
        text("{t('settings_gitsync.versions_the_state')}", class = u-muted)
      }

      text(
        "{t('settings_gitsync.git_not_installed')}",
        if = @state_git_git_missing,
        equals = true,
        class = u-error,
      )

      text(
        "{t('settings_gitsync.no_recovery_recipient')}",
        if = @state_git_recovery_missing,
        equals = true,
        class = u-muted,
      )

      row(class = env__add, if = @state_git_recovery_missing, equals = true) {
        button(
          "{t('settings_recovery_key.generate_key')}",
          class = btn-secondary,
          on_click = recovery_key_open
        )
      }

      field(
        label = "{t('settings_gitsync.mode')}",
        label_class = u-label-cap
      ) {
        scroll(class = tabs__scroll, direction = horizontal) {
          tabbar(
            :value = state_git_form_mode,
            active = @state_git_form_mode,
            :items = state_git_form_modes,
            tab_class = tabs__tab,
            tab_active_class = "tabs__tab tabs__tab--active",
            padding = "7 14",
            size = 13,
            active_bold = false,
          )
        }

        text(
          "{t('settings_gitsync.commit_hint')}",
          if = @state_git_form_mode, equals = commit,
          class = u-muted
        )

        text(
          "{t('settings_gitsync.sync_hint')}",
          if = @state_git_form_mode, equals = sync,
          class = u-muted
        )
      }

      if @state_git_form_mode == "sync" {
        field(
          label = "{t('settings_gitsync.repository')}",
          label_class = u-label-cap
        ) {
          form(
            error_prefix = error_,
            name = state_git,
            on_submit = state_git_save,
            class = "form form--gap-8"
          ) {
            input(
              placeholder = "{t('settings_gitsync.repository_placeholder')}",
              class = "field__input u-mono",
              form_control = state_git_form_remote,
            )
          }
        }

        field(
          label = "{t('settings_gitsync.git_account')}",
          label_class = u-label-cap,
          description = "{t('settings_gitsync.connect_accounts_hint')}",
        ) {
          select(
            class = form-select,
            :options = gitea_providers,
            :value = state_git_form_provider_id,
            on_change = state_git_provider_pick,
            placeholder = "{t('common.select_the_account')}",
            label_field = display,
            value_field = id,
          )
        }
      }

      if @state_git_is_enabled == "true" {
        field(label = "{t('common.branch')}", label_class = u-label-cap) {
          form(
            error_prefix = error_,
            name = state_git_branch,
            on_submit = state_git_save,
            class = "form form--gap-8"
          ) {
            input(
              placeholder = "main",
              class = "field__input u-mono",
              form_control = state_git_form_branch,
            )
          }
        }
      }

      row(class = form-panel__actions) {
        button(
          "{t('settings_gitsync.save_and_apply')}",
          class = "btn btn--primary",
          on_click = state_git_save,
          disabled = @busy_state_git_save
        )

        if @state_git_is_sync == "true" {
          button(
            "{t('settings_gitsync.sync_now')}",
            class = "btn btn--ghost",
            on_click = state_git_sync_now,
            disabled = @busy_state_git_sync_now
          )
        }

        if @state_git_is_configured == "true" {
          button(
            "{t('settings_gitsync.clear_config')}",
            class = "btn btn--danger",
            on_click = state_git_clear,
            disabled = @busy_state_git_clear
          )
        }

        text("@state_git_message", class = u-muted)
      }
    }

    // ── Situação ────────────────────────────────────────────────────────────
    if @state_git_is_enabled == "true" {
      column(class = "form-panel form-panel--grouped") {
        text("{t('settings_gitsync.status')}", class = u-label-cap)

        column(class = info-list) {
          row(class = info-row) {
            text("{t('settings_gitsync.last_commit')}", class = info-row__key)
            text("@state_git_last_commit_label", class = info-row__value)
          }

          if @state_git_is_sync == "true" {
            row(class = info-row) {
              text("{t('settings_gitsync.last_push')}", class = info-row__key)
              text("@state_git_last_push_label", class = info-row__value)
            }

            row(class = info-row) {
              text(
                "{t('settings_gitsync.last_check')}",
                class = info-row__key
              )
              text("@state_git_last_fetch_label", class = info-row__value)
            }

            row(class = info-row) {
              text(
                "{t('settings_gitsync.ahead_behind')}",
                class = info-row__key
              )
              text("@state_git_ahead_behind_label", class = info-row__value)
            }
          }
        }

        text(
          "@state_git_last_error",
          if = @state_git_last_error,
          not_equals = "",
          class = u-error
        )
      }
    }

    // ── Divergência: o servidor não decide qual lado vence ──────────────────
    if @state_git_is_paused == "true" {
      column(class = "form-panel form-panel--grouped") {
        text("{t('settings_gitsync.diverged_title')}", class = u-label-cap)
        text("@state_git_paused_reason", class = u-error)
        text("{t('settings_gitsync.diverged_explain')}", class = u-muted)

        row(class = env__add) {
          button(
            "{t('settings_gitsync.use_repository')}",
            class = "btn btn--danger",
            on_click = state_git_resolve_remote,
            disabled = @busy_state_git_resolve_remote
          )
          button(
            "{t('settings_gitsync.use_server')}",
            class = "btn btn--danger",
            on_click = state_git_resolve_local,
            disabled = @busy_state_git_resolve_local
          )
        }

        text("{t('settings_gitsync.diverged_manual_hint')}", class = u-muted)

        row(class = env__add) {
          button(
            "{t('settings_gitsync.resume')}",
            class = "btn btn--ghost",
            on_click = state_git_resume,
            disabled = @busy_state_git_resume
          )
        }
      }
    }

    // ── Commit do repositório recusado ──────────────────────────────────────
    if @state_git_has_rejected == "true" {
      column(class = "form-panel form-panel--grouped") {
        text("{t('settings_gitsync.rejected_title')}", class = u-label-cap)
        text("@state_git_rejected_label", class = u-muted)
        text("@state_git_rejected_reason", class = u-error)
        text("{t('settings_gitsync.rejected_hint')}", class = u-muted)
      }
    }

    // ── Removidos no git: o container, os volumes e os dados NÃO foram
    // tocados ───────────
    if @state_git_removed_count != "0" {
      column(class = "form-panel form-panel--grouped") {
        column(class = form-panel__head) {
          text("{t('settings_gitsync.removed_title')}", class = u-label-cap)
          text("{t('settings_gitsync.removed_explain')}", class = u-muted)
        }

        column(class = kv-list) {
          each @state_git_removed as removal (fallback = SemRemovidosNoGit) {
            row(class = kv-list__row) {
              column(class = u-fill) {
                text("@removal.name", class = env__key)
                text("@removal.detail", class = u-muted)
              }

              button(
                "{t('settings_gitsync.dismiss')}",
                class = "btn btn--ghost btn--xs",
                on_click = state_git_dismiss_removal:@removal.id,
                disabled = @busy_state_git_dismiss_removal
              )
            }
          }
        }
      }
    }

    // ── Auditoria: a trava para ligar (e para commitar) ─────────────────────
    column(class = "form-panel form-panel--grouped") {
      column(class = form-panel__head) {
        text(
          "{t('settings_gitsync.plaintext_title',
            count=state_git_audit_count)}",
          class = u-label-cap
        )
        text(
          "{t('settings_gitsync.plaintext_explain')}",
          class = u-muted
        )
      }

      column(class = kv-list) {
        each @state_git_audit as finding (fallback = SemValoresEmClaro) {
          row(class = kv-list__row) {
            column(class = u-fill) {
              text("@finding.what", class = env__key)
              text("@finding.detail", class = u-muted)
            }

            button(
              "{t('settings_gitsync.not_a_secret')}",
              if = @finding.can_allow,
              equals = 1,
              class = "btn btn--ghost btn--xs",
              on_click = state_git_allow_finding:@finding.index,
              disabled = @busy_state_git_allow_finding
            )

            button(
              "{t('settings_gitsync.block_again')}",
              if = @finding.can_block_again,
              equals = 1,
              class = "btn btn--ghost btn--xs",
              on_click = state_git_block_again:@finding.index,
              disabled = @busy_state_git_block_again
            )
          }
        }
      }
    }

    // Baixar a infra: os mesmos arquivos que vão para o repositório (secrets
    // cifrados). A webui tem o mesmo painel em `webui/index.html` (aba
    // "Sync"): mude os dois juntos.
    column(class = "form-panel form-panel--grouped") {
      column(class = form-panel__head) {
        text(
          "{t('settings_gitsync.download_infra_title')}",
          class = u-label-cap
        )
        text("{t('settings_gitsync.download_infra_help')}", class = u-muted)
      }

      row(class = form-panel__actions) {
        button(
          "{t('settings_gitsync.download_infra')}",
          class = "btn btn--primary",
          on_click = infra_download,
          disabled = @busy_infra_download
        )

        text("@infra_download_message", class = u-muted)
      }
    }
    }
  }
}