User management (#185)

This commit is contained in:
Saeed Vaziry
2024-04-29 20:58:04 +02:00
committed by GitHub
parent 35f896eab1
commit d846acaa8d
106 changed files with 1490 additions and 434 deletions

View File

@ -5,7 +5,14 @@
<div
class="flex h-10 w-max items-center rounded-md border border-gray-200 bg-gray-100 px-4 py-2 pr-7 text-sm text-gray-900 focus:ring-4 focus:ring-gray-300 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-300 dark:focus:ring-gray-600"
>
{{ auth()->user()->currentProject?->name ?? __("Select Project") }}
<x-heroicon name="o-inbox-stack" class="mr-2 h-4 w-4 lg:hidden" />
<span class="hidden lg:block">
@if (auth()->user()->currentProject &&auth()->user()->can("view", auth()->user()->currentProject))
{{ auth()->user()->currentProject->name }}
@else
{{ __("Select Project") }}
@endif
</span>
<button type="button" class="absolute inset-y-0 right-0 flex items-center pr-2">
<x-heroicon name="o-chevron-down" class="h-4 w-4 text-gray-400" />
</button>
@ -14,8 +21,8 @@ class="flex h-10 w-max items-center rounded-md border border-gray-200 bg-gray-10
</x-slot>
<x-slot:content>
@foreach (auth()->user()->projects as $project)
<x-dropdown-link class="relative" :href="route('projects.switch', ['project' => $project])">
<span class="block truncate">{{ ucfirst($project->name) }}</span>
<x-dropdown-link class="relative" :href="route('settings.projects.switch', ['project' => $project])">
<span class="block truncate">{{ $project->name }}</span>
@if ($project->id == auth()->user()->current_project_id)
<span class="absolute inset-y-0 right-0 flex items-center pr-3 text-primary-600">
<x-heroicon name="o-check" class="h-5 w-5" />
@ -24,12 +31,14 @@ class="flex h-10 w-max items-center rounded-md border border-gray-200 bg-gray-10
</x-dropdown-link>
@endforeach
<x-dropdown-link href="{{ route('projects') }}">
{{ __("Projects List") }}
</x-dropdown-link>
<x-dropdown-link href="{{ route('projects', ['create' => 'open']) }}">
{{ __("Create a Project") }}
</x-dropdown-link>
@if (auth()->user()->isAdmin())
<x-dropdown-link href="{{ route('settings.projects') }}">
{{ __("Projects List") }}
</x-dropdown-link>
<x-dropdown-link href="{{ route('settings.projects', ['create' => 'open']) }}">
{{ __("Create a Project") }}
</x-dropdown-link>
@endif
</x-slot>
</x-dropdown>
</div>

View File

@ -1,35 +1,37 @@
<div data-tooltip="Servers" class="cursor-pointer">
<x-dropdown width="full">
<x-slot:trigger>
<div>
<div
class="block w-full rounded-md border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-primary-500 focus:ring-primary-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-primary-500 dark:focus:ring-primary-500"
>
{{ isset($server) ? $server->name : "Select Server" }}
@if (auth()->user()->currentProject &&auth()->user()->can("view", auth()->user()->currentProject))
<div data-tooltip="Servers" class="cursor-pointer">
<x-dropdown width="full">
<x-slot:trigger>
<div>
<div
class="block w-full rounded-md border border-gray-300 bg-gray-50 p-2.5 text-sm text-gray-900 focus:border-primary-500 focus:ring-primary-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-primary-500 dark:focus:ring-primary-500"
>
{{ isset($server) ? $server->name : "Select Server" }}
</div>
<button type="button" class="absolute inset-y-0 right-0 flex items-center pr-2">
<x-heroicon name="o-chevron-down" class="h-4 w-4 text-gray-400" />
</button>
</div>
<button type="button" class="absolute inset-y-0 right-0 flex items-center pr-2">
<x-heroicon name="o-chevron-down" class="h-4 w-4 text-gray-400" />
</button>
</div>
</x-slot>
<x-slot:content>
@foreach (auth()->user()->currentProject->servers as $s)
<x-dropdown-link class="relative" :href="route('servers.show', ['server' => $s])">
<span class="block truncate">{{ ucfirst($s->name) }}</span>
@if (isset($server) && $server->id == $s->id)
<span class="absolute inset-y-0 right-0 flex items-center pr-3 text-primary-600">
<x-heroicon name="o-check" class="h-5 w-5" />
</span>
@endif
</x-dropdown-link>
@endforeach
</x-slot>
<x-slot:content>
@foreach (auth()->user()->currentProject->servers as $s)
<x-dropdown-link class="relative" :href="route('servers.show', ['server' => $s])">
<span class="block truncate">{{ ucfirst($s->name) }}</span>
@if (isset($server) && $server->id == $s->id)
<span class="absolute inset-y-0 right-0 flex items-center pr-3 text-primary-600">
<x-heroicon name="o-check" class="h-5 w-5" />
</span>
@endif
</x-dropdown-link>
@endforeach
<x-dropdown-link href="{{ route('servers') }}">
{{ __("Servers List") }}
</x-dropdown-link>
<x-dropdown-link href="{{ route('servers.create') }}">
{{ __("Create a Server") }}
</x-dropdown-link>
</x-slot>
</x-dropdown>
</div>
<x-dropdown-link href="{{ route('servers') }}">
{{ __("Servers List") }}
</x-dropdown-link>
<x-dropdown-link href="{{ route('servers.create') }}">
{{ __("Create a Server") }}
</x-dropdown-link>
</x-slot>
</x-dropdown>
</div>
@endif

View File

@ -1,124 +0,0 @@
<div x-data="siteCombobox()">
<div class="relative">
<div
@click="open = !open"
class="text-md flex h-10 w-full cursor-pointer items-center rounded-md bg-gray-200 px-4 py-3 pr-10 leading-5 focus:ring-1 focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-100"
x-text="selected.domain ?? 'Select Site'"
></div>
<button type="button" @click="open = !open" class="absolute inset-y-0 right-0 flex items-center pr-2">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
class="h-5 w-5 text-gray-400"
>
<path
fill-rule="evenodd"
d="M10 3a.75.75 0 01.55.24l3.25 3.5a.75.75 0 11-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 01-1.1-1.02l3.25-3.5A.75.75 0 0110 3zm-3.76 9.2a.75.75 0 011.06.04l2.7 2.908 2.7-2.908a.75.75 0 111.1 1.02l-3.25 3.5a.75.75 0 01-1.1 0l-3.25-3.5a.75.75 0 01.04-1.06z"
clip-rule="evenodd"
></path>
</svg>
</button>
<div
x-show="open"
@click.away="open = false"
class="absolute mt-1 w-full overflow-auto rounded-md bg-white pb-1 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none dark:bg-gray-700 sm:text-sm"
>
<div class="relative p-2">
<input
x-model="query"
@input="filterSitesAndOpen"
placeholder="Filter"
class="dark:focus:ring-800 w-full rounded-md bg-gray-200 py-2 pl-3 pr-10 text-sm leading-5 focus:ring-1 focus:ring-gray-400 dark:bg-gray-800 dark:text-gray-100"
/>
</div>
<div class="relative max-h-[350px] overflow-y-auto">
<template x-for="(site, index) in filteredSites" :key="index">
<div
@click="selectSite(site); open = false"
:class="site.id === selected.id ? 'cursor-default bg-primary-600 text-white' : 'cursor-pointer'"
class="relative select-none px-4 py-2 text-gray-700 hover:bg-primary-600 hover:text-white dark:text-white"
>
<span class="block truncate" x-text="site.domain"></span>
<template x-if="site.id === selected.id">
<span class="absolute inset-y-0 right-0 flex items-center pr-3 text-white">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
class="h-5 w-5"
>
<path
fill-rule="evenodd"
d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
clip-rule="evenodd"
></path>
</svg>
</span>
</template>
</div>
</template>
</div>
<div
x-show="filteredSites.length === 0"
class="relative block cursor-default select-none truncate px-4 py-2 text-gray-700 dark:text-white"
>
No sites found!
</div>
<div class="py-1">
<hr class="border-gray-300 dark:border-gray-600" />
</div>
<div>
<a
href="{{ route("servers.sites", ["server" => $server]) }}"
class="@if(request()->routeIs('sites')) cursor-default bg-primary-600 text-white @else cursor-pointer @endif relative block select-none px-4 py-2 text-gray-700 hover:bg-primary-600 hover:text-white dark:text-white"
>
<span class="block truncate">Sites List</span>
</a>
</div>
<div>
<a
href="{{ route("servers.sites.create", ["server" => $server]) }}"
class="@if(request()->routeIs('sites.create')) cursor-default bg-primary-600 text-white @else cursor-pointer @endif relative block select-none px-4 py-2 text-gray-700 hover:bg-primary-600 hover:text-white dark:text-white"
>
<span class="block truncate">Create a Site</span>
</a>
</div>
</div>
</div>
</div>
<script>
function siteCombobox() {
const sites = @json(\App\Models\Site::query()->where('server_id', $server->id)->select('id', 'domain')->get());
return {
open: false,
query: '',
sites: sites,
selected: @if(isset($site)) @json($site->only('id', 'domain')) @else {} @endif,
filteredSites: sites,
selectSite(site) {
if (this.selected.id !== site.id) {
this.selected = site;
window.location.href = '{{ url('/servers') }}/' + '{{ $server->id }}/sites/' + site.id
}
},
filterSitesAndOpen() {
if (this.query === '') {
this.filteredSites = this.sites;
this.open = false;
} else {
this.filteredSites = this.sites.filter((site) =>
site.domain
.toLowerCase()
.replace(/\s+/g, '')
.includes(this.query.toLowerCase().replace(/\s+/g, ''))
);
this.open = true;
}
},
};
}
</script>