wip
This commit is contained in:
parent
0072343e0f
commit
ce265e1f91
@ -2,11 +2,15 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
|
|
||||||
class GithubApp extends BaseModel
|
class GithubApp extends BaseModel
|
||||||
{
|
{
|
||||||
protected $fillable = ['name', 'uuid', 'organization', 'api_url', 'html_url', 'custom_user', 'custom_port', 'team_id'];
|
protected $fillable = ['name', 'uuid', 'organization', 'api_url', 'html_url', 'custom_user', 'custom_port', 'team_id'];
|
||||||
|
protected $appends = ['type'];
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'is_public' => 'boolean',
|
'is_public' => 'boolean',
|
||||||
|
'type' => 'string'
|
||||||
];
|
];
|
||||||
protected static function booted(): void
|
protected static function booted(): void
|
||||||
{
|
{
|
||||||
@ -25,6 +29,16 @@ class GithubApp extends BaseModel
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(PrivateKey::class);
|
return $this->belongsTo(PrivateKey::class);
|
||||||
}
|
}
|
||||||
|
public function type(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
get: function () {
|
||||||
|
if ($this->getMorphClass() === 'App\Models\GithubApp') {
|
||||||
|
return 'github';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
static public function public()
|
static public function public()
|
||||||
{
|
{
|
||||||
return GithubApp::where('team_id', session('currentTeam')->id)->where('is_public', true)->get();
|
return GithubApp::where('team_id', session('currentTeam')->id)->where('is_public', true)->get();
|
||||||
|
@ -190,6 +190,30 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
{{-- Sources --}}
|
||||||
|
<template x-cloak x-if="sourcesMenu">
|
||||||
|
<div x-on:click.outside="closeMenus">
|
||||||
|
<input x-ref="search" x-model="search" class="magic-input" placeholder="Select a source..."
|
||||||
|
x-on:keyup.escape="closeMenus" x-on:keydown.down="focusNext(sources.length)"
|
||||||
|
x-on:keydown.up="focusPrev(sources.length)"
|
||||||
|
x-on:keyup.enter="focusedIndex !== '' && await set('jumpToSource',filteredSources()[focusedIndex])" />
|
||||||
|
<div class="magic-items">
|
||||||
|
<template x-if="sources.length === 0">
|
||||||
|
<div class="magic-item" x-on:click="set('newSource')">
|
||||||
|
<span>No Source found. Click here to add a new one!</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template x-for="(source,index) in filteredSources" :key="source.name ?? source">
|
||||||
|
<div x-on:click="await set('jumpToSource',source)"
|
||||||
|
:class="focusedIndex === index && 'magic-item-focused'"
|
||||||
|
class="py-2 pl-4 cursor-pointer hover:bg-neutral-700">
|
||||||
|
<span class="px-2 mr-1 text-xs bg-purple-700 rounded">Jump</span>
|
||||||
|
<span x-text="source.name"></span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -202,7 +226,8 @@
|
|||||||
!this.environmentMenu &&
|
!this.environmentMenu &&
|
||||||
!this.projectsMenu &&
|
!this.projectsMenu &&
|
||||||
!this.destinationsMenu &&
|
!this.destinationsMenu &&
|
||||||
!this.privateKeysMenu
|
!this.privateKeysMenu &&
|
||||||
|
!this.sourcesMenu
|
||||||
},
|
},
|
||||||
focus() {
|
focus() {
|
||||||
if (this.$refs.search) this.$refs.search.focus()
|
if (this.$refs.search) this.$refs.search.focus()
|
||||||
@ -229,6 +254,9 @@
|
|||||||
this.$watch('privateKeysMenu', () => {
|
this.$watch('privateKeysMenu', () => {
|
||||||
this.focus()
|
this.focus()
|
||||||
})
|
})
|
||||||
|
this.$watch('sourcesMenu', () => {
|
||||||
|
this.focus()
|
||||||
|
})
|
||||||
},
|
},
|
||||||
mainMenu: false,
|
mainMenu: false,
|
||||||
serverMenu: false,
|
serverMenu: false,
|
||||||
@ -238,6 +266,7 @@
|
|||||||
projectsMenu: false,
|
projectsMenu: false,
|
||||||
environmentMenu: false,
|
environmentMenu: false,
|
||||||
privateKeysMenu: false,
|
privateKeysMenu: false,
|
||||||
|
sourcesMenu: false,
|
||||||
search: '',
|
search: '',
|
||||||
|
|
||||||
selectedAction: '',
|
selectedAction: '',
|
||||||
@ -251,6 +280,7 @@
|
|||||||
projects: ['Loading...'],
|
projects: ['Loading...'],
|
||||||
environments: ['Loading...'],
|
environments: ['Loading...'],
|
||||||
privateKeys: ['Loading...'],
|
privateKeys: ['Loading...'],
|
||||||
|
sources: ['Loading...'],
|
||||||
|
|
||||||
focusedIndex: "",
|
focusedIndex: "",
|
||||||
items: [{
|
items: [{
|
||||||
@ -322,6 +352,12 @@
|
|||||||
type: 'Jump',
|
type: 'Jump',
|
||||||
tags: 'private keys,ssh, keys, key',
|
tags: 'private keys,ssh, keys, key',
|
||||||
next: 'privateKeys'
|
next: 'privateKeys'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Sources',
|
||||||
|
type: 'Jump',
|
||||||
|
tags: 'github,apps,source',
|
||||||
|
next: 'sources'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
focusPrev(maxLength) {
|
focusPrev(maxLength) {
|
||||||
@ -362,6 +398,10 @@
|
|||||||
this.destinationMenu = false
|
this.destinationMenu = false
|
||||||
this.projectMenu = false
|
this.projectMenu = false
|
||||||
this.environmentMenu = false
|
this.environmentMenu = false
|
||||||
|
this.projectsMenu = false
|
||||||
|
this.destinationsMenu = false
|
||||||
|
this.privateKeysMenu = false
|
||||||
|
this.sourcesMenu = false
|
||||||
},
|
},
|
||||||
checkMainMenu() {
|
checkMainMenu() {
|
||||||
if (this.serverMenu) return
|
if (this.serverMenu) return
|
||||||
@ -410,6 +450,13 @@
|
|||||||
.toLowerCase())
|
.toLowerCase())
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
filteredSources() {
|
||||||
|
if (this.search === '') return this.sources
|
||||||
|
return this.sources.filter(source => {
|
||||||
|
return source.name.toLowerCase().includes(this.search
|
||||||
|
.toLowerCase())
|
||||||
|
})
|
||||||
|
},
|
||||||
async newProject() {
|
async newProject() {
|
||||||
const response = await fetch('/magic?server=' + this.selectedServer +
|
const response = await fetch('/magic?server=' + this.selectedServer +
|
||||||
'&destination=' + this.selectedDestination +
|
'&destination=' + this.selectedDestination +
|
||||||
@ -519,6 +566,17 @@
|
|||||||
this.closeMenus()
|
this.closeMenus()
|
||||||
this.privateKeysMenu = true
|
this.privateKeysMenu = true
|
||||||
break
|
break
|
||||||
|
case 'sources':
|
||||||
|
response = await fetch('/magic?sources=true');
|
||||||
|
if (response.ok) {
|
||||||
|
const {
|
||||||
|
sources
|
||||||
|
} = await response.json();
|
||||||
|
this.sources = sources;
|
||||||
|
}
|
||||||
|
this.closeMenus()
|
||||||
|
this.sourcesMenu = true
|
||||||
|
break
|
||||||
case 'environment':
|
case 'environment':
|
||||||
if (this.focusedIndex === 0) {
|
if (this.focusedIndex === 0) {
|
||||||
this.focusedIndex = ''
|
this.focusedIndex = ''
|
||||||
@ -573,6 +631,10 @@
|
|||||||
window.location = `/private-key/${id}`
|
window.location = `/private-key/${id}`
|
||||||
this.closeMenus()
|
this.closeMenus()
|
||||||
break
|
break
|
||||||
|
case 'jumpToSource':
|
||||||
|
window.location = `/source/${id.type}/${id.uuid}`
|
||||||
|
this.closeMenus()
|
||||||
|
break
|
||||||
case 'newServer':
|
case 'newServer':
|
||||||
window.location = `/server/new`
|
window.location = `/server/new`
|
||||||
this.closeMenus()
|
this.closeMenus()
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<p>No servers found.</p>
|
<p>No servers found.</p>
|
||||||
@endforelse
|
@endforelse
|
||||||
</div>
|
</div>
|
||||||
<h1>Destinations </h1>
|
{{-- <h1>Destinations </h1>
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
@forelse ($destinations as $destination)
|
@forelse ($destinations as $destination)
|
||||||
<a href="{{ route('destination.show', [$destination->uuid]) }}"
|
<a href="{{ route('destination.show', [$destination->uuid]) }}"
|
||||||
@ -31,8 +31,8 @@
|
|||||||
@empty
|
@empty
|
||||||
<p>No destinations found.</p>
|
<p>No destinations found.</p>
|
||||||
@endforelse
|
@endforelse
|
||||||
</div>
|
</div> --}}
|
||||||
<h1>Private Keys </h1>
|
{{-- <h1>Private Keys </h1>
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
@forelse ($private_keys as $private_key)
|
@forelse ($private_keys as $private_key)
|
||||||
<a href="{{ route('private-key.show', [$private_key->uuid]) }}"
|
<a href="{{ route('private-key.show', [$private_key->uuid]) }}"
|
||||||
@ -40,8 +40,8 @@
|
|||||||
@empty
|
@empty
|
||||||
<p>No servers found.</p>
|
<p>No servers found.</p>
|
||||||
@endforelse
|
@endforelse
|
||||||
</div>
|
</div> --}}
|
||||||
<h1>GitHub Apps </h1>
|
{{-- <h1>GitHub Apps </h1>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
@forelse ($github_apps as $github_app)
|
@forelse ($github_apps as $github_app)
|
||||||
<a href="{{ route('source.github.show', [$github_app->uuid]) }}"
|
<a href="{{ route('source.github.show', [$github_app->uuid]) }}"
|
||||||
@ -49,7 +49,7 @@
|
|||||||
@empty
|
@empty
|
||||||
<p>No servers found.</p>
|
<p>No servers found.</p>
|
||||||
@endforelse
|
@endforelse
|
||||||
</div>
|
</div> --}}
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
</x-layout>
|
</x-layout>
|
||||||
|
@ -30,11 +30,12 @@ use Illuminate\Support\Str;
|
|||||||
Route::middleware(['auth'])->group(function () {
|
Route::middleware(['auth'])->group(function () {
|
||||||
Route::get('/magic', function () {
|
Route::get('/magic', function () {
|
||||||
try {
|
try {
|
||||||
|
$id = session('currentTeam')->id;
|
||||||
$is_new_project = request()->query('project') === 'new';
|
$is_new_project = request()->query('project') === 'new';
|
||||||
$is_new_environment = request()->query('environment') === 'new';
|
$is_new_environment = request()->query('environment') === 'new';
|
||||||
// Get servers
|
// Get servers
|
||||||
if (request()->query('servers') === 'true') {
|
if (request()->query('servers') === 'true') {
|
||||||
$servers = Server::where('team_id', session('currentTeam')->id)->get();
|
$servers = Server::where('team_id', $id)->get();
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'servers' => $servers,
|
'servers' => $servers,
|
||||||
]);
|
]);
|
||||||
@ -49,14 +50,22 @@ Route::middleware(['auth'])->group(function () {
|
|||||||
}
|
}
|
||||||
// Get private Keys
|
// Get private Keys
|
||||||
if (request()->query('privateKeys') === 'true') {
|
if (request()->query('privateKeys') === 'true') {
|
||||||
$privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
|
$privateKeys = PrivateKey::where('team_id', $id)->get();
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'privateKeys' => $privateKeys->toArray(),
|
'privateKeys' => $privateKeys->toArray(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
// Get sources
|
||||||
|
if (request()->query('sources') === 'true') {
|
||||||
|
$github_apps = GithubApp::private();
|
||||||
|
$sources = $github_apps;
|
||||||
|
return response()->json([
|
||||||
|
'sources' => $sources->toArray(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
// Get projects
|
// Get projects
|
||||||
if ((request()->query('server') && request()->query('destination') && request()->query('projects') === 'true') || request()->query('projects') === 'true') {
|
if ((request()->query('server') && request()->query('destination') && request()->query('projects') === 'true') || request()->query('projects') === 'true') {
|
||||||
$projects = Project::where('team_id', session('currentTeam')->id)->get();
|
$projects = Project::where('team_id', $id)->get()->sortBy('name');
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'projects' => $projects->toArray(),
|
'projects' => $projects->toArray(),
|
||||||
]);
|
]);
|
||||||
@ -64,7 +73,7 @@ Route::middleware(['auth'])->group(function () {
|
|||||||
|
|
||||||
// Get environments
|
// Get environments
|
||||||
if (request()->query('server') && request()->query('destination') && request()->query('project') && request()->query('environments') === 'true') {
|
if (request()->query('server') && request()->query('destination') && request()->query('project') && request()->query('environments') === 'true') {
|
||||||
$environments = Project::where('team_id', session('currentTeam')->id)->where('uuid', request()->query('project'))->first()->environments;
|
$environments = Project::where('team_id', $id)->where('uuid', request()->query('project'))->first()->environments;
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'environments' => $environments->toArray(),
|
'environments' => $environments->toArray(),
|
||||||
]);
|
]);
|
||||||
@ -73,7 +82,7 @@ Route::middleware(['auth'])->group(function () {
|
|||||||
if ($is_new_project) {
|
if ($is_new_project) {
|
||||||
$project = Project::create([
|
$project = Project::create([
|
||||||
'name' => request()->query('name') ?? generateRandomName(),
|
'name' => request()->query('name') ?? generateRandomName(),
|
||||||
'team_id' => session('currentTeam')->id,
|
'team_id' => $id,
|
||||||
]);
|
]);
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'project_uuid' => $project->uuid
|
'project_uuid' => $project->uuid
|
||||||
|
Loading…
x
Reference in New Issue
Block a user