Commit b1a6c02e authored by Yassine Doghri's avatar Yassine Doghri
Browse files

feat(admin): add instance wide dashboard with storage and bandwidth usage

* add DashboardCard component
* add instance wide podcasts and episodes numbers
* add app.storageLimit environment variable
* divide bytes by 1000 instead of 1024 in stats sql queries

closes #216
parent 3d363f2e
Loading
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -451,4 +451,9 @@ class App extends BaseConfig
    ];

    public string $theme = 'pine';

    /**
     * Storage limit in Gigabytes
     */
    public ?int $storageLimit = null;
}
+55 −11
Original line number Diff line number Diff line
@@ -179,9 +179,9 @@ if (! function_exists('publication_button')) {
                break;
        }

        return <<<CODE_SAMPLE
        return <<<HTML
            <Button variant="{$variant}" uri="{$route}" iconLeft="{$iconLeft}" >{$label}</Button>
        CODE_SAMPLE;
        HTML;
    }
}

@@ -205,7 +205,7 @@ if (! function_exists('publication_status_banner')) {
            case 'scheduled':
                $bannerDisclaimer = lang('Podcast.publication_status_banner.draft_mode');
                $bannerText = lang('Podcast.publication_status_banner.scheduled', [
                    'publication_date' => local_time($publicationDate),
                    'publication_date' => local_datetime($publicationDate),
                ], null, false);
                $linkRoute = route_to('podcast-publish_edit', $podcastId);
                $linkLabel = lang('Podcast.publish_edit');
@@ -218,7 +218,7 @@ if (! function_exists('publication_status_banner')) {
                break;
        }

        return <<<CODE_SAMPLE
        return <<<HTML
        <div class="flex items-center px-12 py-1 border-b bg-stripes-gray border-subtle" role="alert">
            <p class="text-gray-900">
                <span class="text-xs font-semibold tracking-wide uppercase">{$bannerDisclaimer}</span>
@@ -226,7 +226,7 @@ if (! function_exists('publication_status_banner')) {
            </p>
            <a href="{$linkRoute}" class="ml-1 text-sm font-semibold underline shadow-xs text-accent-base hover:text-accent-hover hover:no-underline">{$linkLabel}</a>
        </div>
        CODE_SAMPLE;
        HTML;
    }
}

@@ -321,7 +321,7 @@ if (! function_exists('audio_player')) {
        $language = service('request')
            ->getLocale();

        return <<<CODE_SAMPLE
        return <<<HTML
            <vm-player
                id="castopod-vm-player"
                theme="light"
@@ -346,7 +346,7 @@ if (! function_exists('audio_player')) {
                    </vm-controls>
                </vm-ui>
            </vm-player>
        CODE_SAMPLE;
        HTML;
    }
}

@@ -361,16 +361,60 @@ if (! function_exists('relative_time')) {
        $translatedDate = $time->toLocalizedString($formatter->getPattern());
        $datetime = $time->format(DateTime::ISO8601);

        return <<<CODE_SAMPLE
        return <<<HTML
            <time-ago class="{$class}" datetime="{$datetime}">
                <time
                    datetime="{$datetime}"
                    title="{$time}">{$translatedDate}</time>
            </time-ago>
        CODE_SAMPLE;
        HTML;
    }
}

// ------------------------------------------------------------------------

if (! function_exists('local_datetime')) {
    function local_datetime(Time $time): string
    {
        $formatter = new IntlDateFormatter(service(
            'request'
        )->getLocale(), IntlDateFormatter::MEDIUM, IntlDateFormatter::LONG);
        $translatedDate = $time->toLocalizedString($formatter->getPattern());
        $datetime = $time->format(DateTime::ISO8601);

        return <<<HTML
            <local-time datetime="{$datetime}" 
                weekday="long" 
                month="long"
                day="numeric"
                year="numeric"
                hour="numeric"
                minute="numeric">
                <time
                    datetime="{$datetime}"
                    title="{$time}">{$translatedDate}</time>
            </local-time>
        HTML;
    }
}

// ------------------------------------------------------------------------

if (! function_exists('local_date')) {
    function local_date(Time $time): string
    {
        $formatter = new IntlDateFormatter(service(
            'request'
        )->getLocale(), IntlDateFormatter::MEDIUM, IntlDateFormatter::NONE);
        $translatedDate = $time->toLocalizedString($formatter->getPattern());

        return <<<HTML
            <time title="{$time}">{$translatedDate}</time>
        HTML;
    }
}


// ------------------------------------------------------------------------

if (! function_exists('explicit_badge')) {
@@ -381,9 +425,9 @@ if (! function_exists('explicit_badge')) {
        }

        $explicitLabel = lang('Common.explicit');
        return <<<CODE_SAMPLE
        return <<<HTML
            <span class="px-1 text-xs font-semibold leading-tight tracking-wider uppercase border md:border-white/50 {$class}">{$explicitLabel}</span>
        CODE_SAMPLE;
        HTML;
    }
}

+4 −30
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ declare(strict_types=1);
 * @link       https://castopod.org/
 */

use CodeIgniter\I18n\Time;

if (! function_exists('get_browser_language')) {
    /**
@@ -281,41 +280,16 @@ if (! function_exists('format_bytes')) {
    /**
     * Adapted from https://stackoverflow.com/a/2510459
     */
    function formatBytes(float $bytes, int $precision = 2): string
    function formatBytes(float $bytes, bool $is_binary = false, int $precision = 2): string
    {
        $units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
        $units = $is_binary ? ['B', 'KiB', 'MiB', 'GiB', 'TiB'] : ['B', 'KB', 'MB', 'GB', 'TB'];

        $bytes = max($bytes, 0);
        $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
        $pow = floor(($bytes ? log($bytes) : 0) / log($is_binary ? 1024 : 1000));
        $pow = min($pow, count($units) - 1);

        $bytes /= pow(1024, $pow);
        $bytes /= pow($is_binary ? 1024 : 1000, $pow);

        return round($bytes, $precision) . $units[$pow];
    }
}

if (! function_exists('local_time')) {
    function local_time(Time $time): string
    {
        $formatter = new IntlDateFormatter(service(
            'request'
        )->getLocale(), IntlDateFormatter::MEDIUM, IntlDateFormatter::LONG);
        $translatedDate = $time->toLocalizedString($formatter->getPattern());
        $datetime = $time->format(DateTime::ISO8601);

        return <<<CODE_SAMPLE
            <local-time datetime="{$datetime}" 
                weekday="long" 
                month="long"
                day="numeric"
                year="numeric"
                hour="numeric"
                minute="numeric">
                <time
                    datetime="{$datetime}"
                    title="{$time}">{$translatedDate}</time>
            </local-time>
        CODE_SAMPLE;
    }
}
+6 −0
Original line number Diff line number Diff line
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
    <g>
        <path fill="none" d="M0 0h24v24H0z"/>
        <path d="M21 9.5v3c0 2.485-4.03 4.5-9 4.5s-9-2.015-9-4.5v-3c0 2.485 4.03 4.5 9 4.5s9-2.015 9-4.5zm-18 5c0 2.485 4.03 4.5 9 4.5s9-2.015 9-4.5v3c0 2.485-4.03 4.5-9 4.5s-9-2.015-9-4.5v-3zm9-2.5c-4.97 0-9-2.015-9-4.5S7.03 3 12 3s9 2.015 9 4.5-4.03 4.5-9 4.5z"/>
    </g>
</svg>
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
    <g>
        <path fill="none" d="M0 0h24v24H0z"/>
        <path d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm0-2a8 8 0 1 0 0-16 8 8 0 0 0 0 16zM10.622 8.415l4.879 3.252a.4.4 0 0 1 0 .666l-4.88 3.252a.4.4 0 0 1-.621-.332V8.747a.4.4 0 0 1 .622-.332z"/>
    </g>
</svg>
 No newline at end of file
Loading