Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

2.8 KB
Raw Blame
@php
    use App\Actions\CoolifyTask\RunRemoteProcess;

    $exitCode = data_get($activity, 'properties.exitCode');
    $activityStatus = match (true) {
        ! $activity => null,
        $isPollingActive || $exitCode === null => 'running',
        (int) $exitCode === 0 => 'finished',
        default => 'failed',
    };
@endphp
<div data-activity-status="{{ $activityStatus }}" @class([
    'h-full flex flex-col overflow-hidden' => $fullHeight,
    'overflow-hidden' => !$fullHeight,
])>
    @if ($activity)
        @if (isset($header))
            <div class="flex gap-2 pb-2 flex-shrink-0" @if ($isPollingActive) wire:poll.1000ms @endif>
                <h3>{{ $header }}</h3>
                @if ($isPollingActive)
                    <x-loading />
                @endif
            </div>
        @endif
        <div x-data="{
            autoScrollEnabled: true,
            observer: null,
            scrollToBottom() {
                if (this.autoScrollEnabled) {
                    this.$el.scrollTop = this.$el.scrollHeight;
                }
            },
            isAtBottom() {
                const threshold = 5; // 5px tolerance
                return this.$el.scrollTop + this.$el.clientHeight >= this.$el.scrollHeight - threshold;
            },
            handleScroll() {
                // Check if user scrolled to bottom
                if (this.isAtBottom()) {
                    this.autoScrollEnabled = true;
                } else {
                    this.autoScrollEnabled = false;
                }
            }
        }" x-init="// Initial scroll
        $nextTick(() => scrollToBottom());

        // Add scroll event listener
        $el.addEventListener('scroll', () => handleScroll());

        // Set up mutation observer to watch for content changes
        observer = new MutationObserver(() => {
            $nextTick(() => scrollToBottom());
        });
        observer.observe($el, {
            childList: true,
            subtree: true,
            characterData: true
        });" x-destroy="observer && observer.disconnect()"
            @class([
                'activity-monitor-log flex flex-col w-full min-w-0 max-w-full px-4 py-2 overflow-y-auto bg-white border border-solid rounded-sm dark:text-white dark:bg-coolgray-100 scrollbar border-neutral-300 dark:border-coolgray-300',
                'flex-1 min-h-0' => $fullHeight,
                'max-h-96' => !$fullHeight,
            ])>
            <pre class="font-logs min-w-0 max-w-full whitespace-pre-wrap wrap-anywhere" @if ($isPollingActive) wire:poll.1000ms="polling" @endif>{{ RunRemoteProcess::decodeOutput($activity) }}</pre>
        </div>
    @else
        @if ($showWaiting)
            <div class="flex justify-start">
                <x-loading text="Waiting for the process to start..." />
            </div>
        @endif
    @endif
</div>