<commit_before><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Inertia\Inertia;
use Redirect;
use App\Models\Platform;
use App\Models\Release;
use App\Models\Timeline;
use Illuminate\Database\Eloquent\Builder;

class PackageController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return Inertia::render('Packages/Index', [
            'packages' => Release::where('package', '=', 1)->orderBy('platform_id', 'asc')->get()->map(function ($release) {
                return [
                    'name' => $release->name,
                    'version' => $release->version,
                    'url' => $release->url,
                    'platform' => [
                        'icon' => $release->platform->icon,
                        'name' => $release->platform->name,
                        'color' => $release->platform->color,
                        'tool' => $release->platform->tool
                    ],
                    'channels' => $release->releaseChannels->where('supported')->map(function ($channel) {
                        return [
                            'id' => $channel->id,
                            'short_name' => $channel->short_name,
                            'supported' => $channel->supported,
                            'color' => $channel->channel->color,
                            'order' => $channel->channel->order
                        ];
                    })->values()->all()
                ];
            })->values()->all(),
        ]);
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function show(Release $release)
    {
        $timeline = Timeline::orderBy('date', 'desc')
            ->whereHas('flight', function (Builder $query) use ($release) {
                $query->join('release_channels as frs', function ($join) {
                    $join->on('frs.id', '=', 'flights.release_channel_id')
                
                    ->join('channels as fc', function ($join) {
                        $join->on('fc.id', '=', 'frs.channel_id');
                    });
                })
                ->where('frs.release_id', '=', $release->id);
            })
            ->orWhereHas('promotion', function (Builder $query) use ($release) {
                $query->join('release_channels as prs', function ($join) {
                    $join->on('prs.id', '=', 'promotions.release_channel_id')
                
                    ->join('channels as pc', function ($join) {
                        $join->on('pc.id', '=', 'prs.channel_id');
                    });
                })
                ->where('prs.release_id', '=', $release->id);
            })
            ->orWhereHas('launch', function (Builder $query) use ($release) {
                $query->join('releases as lr', function ($join) {
                    $join->on('lr.id', '=', 'launches.release_id');
                })
                ->where('lr.id', '=', $release->id);
            })
            ->paginate(75);

        return Inertia::render('Packages/Show', [
            'platforms' => Platform::where('tool', 0)->orderBy('position')->get()->map(function ($_platform) {
                return [
                    'id' => $_platform->id,
                    'name' => $_platform->name,
                    'color' => $_platform->color,
                    'icon' => $_platform->icon,
                    'legacy' => $_platform->legacy,
                    'url' => route('front.platforms.show', $_platform, false)
                ];
            }),
            'release' => $release,
            'platform' => $release->platform,
            'channels' => $release->releaseChannels->map(function ($release_channel) {
                return [
                    'name' => $release_channel->short_name,
                    'order' => $release_channel->channel->order,
                    'color' => $release_channel->channel->color,
                    'disabled' => $release_channel->supported ? false : true,
                    'flight' => $release_channel->latest ? [
                        'version' => $release_channel->latest->flight,
                        'date' => $release_channel->latest->timeline->date
                    ] : []
                ];
            })->sortBy('order')->values()->all(),
            'timeline' => $timeline->sortByDesc('date')->groupBy('date')->map(function ($items, $date) {
                return [
                    'date' => $items[0]->date,
                    'flights' => $items->groupBy(function($item, $key) {
                        if ($item->item_type === \App\Models\Flight::class) {
                            return $item->item->flight.'-'.$item->item->platform->position;
                        } else if ($item->item_type === \App\Models\Promotion::class) {
                            return $item->item->platform->position.'.'.$item->item->releaseChannel->release->version.'.'.$item->item->releaseChannel->channel->order;
                        } else if ($item->item_type === \App\Models\Launch::class) {<commit_msg>#9 Show full package versions on package page<commit_after><?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Inertia\Inertia;
use Redirect;
use App\Models\Platform;
use App\Models\Release;
use App\Models\Timeline;
use Illuminate\Database\Eloquent\Builder;

class PackageController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return Inertia::render('Packages/Index', [
            'packages' => Release::where('package', '=', 1)->orderBy('platform_id', 'asc')->get()->map(function ($release) {
                return [
                    'name' => $release->name,
                    'version' => $release->version,
                    'url' => $release->url,
                    'platform' => [
                        'icon' => $release->platform->icon,
                        'name' => $release->platform->name,
                        'color' => $release->platform->color,
                        'tool' => $release->platform->tool
                    ],
                    'channels' => $release->releaseChannels->where('supported')->map(function ($channel) {
                        return [
                            'id' => $channel->id,
                            'short_name' => $channel->short_name,
                            'supported' => $channel->supported,
                            'color' => $channel->channel->color,
                            'order' => $channel->channel->order
                        ];
                    })->values()->all()
                ];
            })->values()->all(),
        ]);
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function show(Release $release)
    {
        $timeline = Timeline::orderBy('date', 'desc')
            ->whereHas('flight', function (Builder $query) use ($release) {
                $query->join('release_channels as frs', function ($join) {
                    $join->on('frs.id', '=', 'flights.release_channel_id')
                
                    ->join('channels as fc', function ($join) {
                        $join->on('fc.id', '=', 'frs.channel_id');
                    });
                })
                ->where('frs.release_id', '=', $release->id);
            })
            ->orWhereHas('promotion', function (Builder $query) use ($release) {
                $query->join('release_channels as prs', function ($join) {
                    $join->on('prs.id', '=', 'promotions.release_channel_id')
                
                    ->join('channels as pc', function ($join) {
                        $join->on('pc.id', '=', 'prs.channel_id');
                    });
                })
                ->where('prs.release_id', '=', $release->id);
            })
            ->orWhereHas('launch', function (Builder $query) use ($release) {
                $query->join('releases as lr', function ($join) {
                    $join->on('lr.id', '=', 'launches.release_id');
                })
                ->where('lr.id', '=', $release->id);
            })
            ->paginate(75);

        return Inertia::render('Packages/Show', [
            'platforms' => Platform::where('tool', 0)->orderBy('position')->get()->map(function ($_platform) {
                return [
                    'id' => $_platform->id,
                    'name' => $_platform->name,
                    'color' => $_platform->color,
                    'icon' => $_platform->icon,
                    'legacy' => $_platform->legacy,
                    'url' => route('front.platforms.show', $_platform, false)
                ];
            }),
            'release' => $release,
            'platform' => $release->platform,
            'channels' => $release->releaseChannels->map(function ($release_channel) {
                return [
                    'name' => $release_channel->short_name,
                    'order' => $release_channel->channel->order,
                    'color' => $release_channel->channel->color,
                    'disabled' => $release_channel->supported ? false : true,
                    'flight' => $release_channel->latest ? [
                        'version' => $release_channel->latest->version,
                        'date' => $release_channel->latest->timeline->date
                    ] : []
                ];
            })->sortBy('order')->values()->all(),
            'timeline' => $timeline->sortByDesc('date')->groupBy('date')->map(function ($items, $date) {
                return [
                    'date' => $items[0]->date,
                    'flights' => $items->groupBy(function($item, $key) {
                        if ($item->item_type === \App\Models\Flight::class) {
                            return $item->item->flight.'-'.$item->item->platform->position;
                        } else if ($item->item_type === \App\Models\Promotion::class) {
                            return $item->item->platform->position.'.'.$item->item->releaseChannel->release->version.'.'.$item->item->releaseChannel->channel->order;
                        } else if ($item->item_type === \App\Models\Launch::class) {
{'fraction_non_alphanumeric': 0.16860961046346318, 'fraction_numerical': 0.001042555208037153, 'mean_word_length': 1.4596736596736597, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 269, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3005421', 'n_tokens_mistral': 2782, 'n_tokens_neox': 2676, 'n_words': 441}