Enabled default routing
This commit is contained in:
parent
7ec01d778a
commit
c7388c2db6
@ -95,6 +95,25 @@ class ZoneController extends Controller
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set address as default for zone
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Address $o
|
||||
*/
|
||||
public function api_default(Request $request,Zone $o)
|
||||
{
|
||||
$this->authorize('admin',$o);
|
||||
|
||||
$default = $o->systems->where('pivot.default',TRUE);
|
||||
if ($default->count() && ($default->first()->id != $request->sid))
|
||||
abort(404);
|
||||
|
||||
$o->systems()->updateExistingPivot($request->sid,[
|
||||
'default' => (bool)$request->set,
|
||||
]);
|
||||
}
|
||||
|
||||
public function home()
|
||||
{
|
||||
return view('zone.home');
|
||||
|
@ -38,42 +38,48 @@ class Address extends Model
|
||||
if (! $this->session('sespass'))
|
||||
return $this->hasMany(self::class,'id','void');
|
||||
|
||||
switch ($this->role) {
|
||||
case DomainController::NODE_ZC:
|
||||
$children = self::select('addresses.*')
|
||||
->where('zone_id',$this->zone_id);
|
||||
if (! $this->session('default')) {
|
||||
switch ($this->role) {
|
||||
case DomainController::NODE_ZC:
|
||||
$children = self::select('addresses.*')
|
||||
->where('zone_id',$this->zone_id);
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case DomainController::NODE_RC:
|
||||
$children = self::select('addresses.*')
|
||||
->where('zone_id',$this->zone_id)
|
||||
->where('region_id',$this->region_id);
|
||||
case DomainController::NODE_RC:
|
||||
$children = self::select('addresses.*')
|
||||
->where('zone_id',$this->zone_id)
|
||||
->where('region_id',$this->region_id);
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case DomainController::NODE_NC:
|
||||
$children = self::select('addresses.*')
|
||||
->where('zone_id',$this->zone_id)
|
||||
->where('region_id',$this->region_id)
|
||||
->where('host_id',$this->host_id);
|
||||
case DomainController::NODE_NC:
|
||||
$children = self::select('addresses.*')
|
||||
->where('zone_id',$this->zone_id)
|
||||
->where('region_id',$this->region_id)
|
||||
->where('host_id',$this->host_id);
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case DomainController::NODE_HC:
|
||||
// Identify our children.
|
||||
$children = self::select('addresses.*')
|
||||
->where('hub_id',$this->id);
|
||||
case DomainController::NODE_HC:
|
||||
// Identify our children.
|
||||
$children = self::select('addresses.*')
|
||||
->where('hub_id',$this->id);
|
||||
|
||||
break;
|
||||
break;
|
||||
|
||||
case DomainController::NODE_ACTIVE:
|
||||
case DomainController::NODE_POINT:
|
||||
// Nodes dont have children, but must return a relationship instance
|
||||
return $this->hasOne(self::class,NULL,'void');
|
||||
case DomainController::NODE_ACTIVE:
|
||||
case DomainController::NODE_POINT:
|
||||
// Nodes dont have children, but must return a relationship instance
|
||||
return $this->hasOne(self::class,NULL,'void');
|
||||
|
||||
default:
|
||||
throw new Exception('Unknown role: '.serialize($this->role));
|
||||
default:
|
||||
throw new Exception('Unknown role: '.serialize($this->role));
|
||||
}
|
||||
|
||||
} else {
|
||||
$children = self::select('addresses.*')
|
||||
->where('zone_id',$this->zone_id);
|
||||
}
|
||||
|
||||
// Remove any children that we have session details for (SAME AS HC)
|
||||
@ -116,9 +122,12 @@ class Address extends Model
|
||||
return $this;
|
||||
|
||||
switch ($this->role) {
|
||||
// ZCs dont have parents.
|
||||
// ZCs dont have parents, but we may have a default
|
||||
case DomainController::NODE_ZC:
|
||||
return NULL;
|
||||
if (($x=$this->zone->systems->where('pivot.default',TRUE))->count())
|
||||
return $x->first()->match($this->zone)->first();
|
||||
else
|
||||
return NULL;
|
||||
|
||||
// RC
|
||||
case DomainController::NODE_RC:
|
||||
|
@ -34,7 +34,7 @@ class System extends Model
|
||||
public function sessions()
|
||||
{
|
||||
return $this->belongsToMany(Zone::class)
|
||||
->withPivot(['sespass','pktpass','ticpass','fixpass','zt_ipv4','zt_ipv6']);
|
||||
->withPivot(['sespass','pktpass','ticpass','fixpass','zt_ipv4','zt_ipv6','default']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,4 +40,13 @@ class Zone extends Model
|
||||
{
|
||||
return $this->belongsTo(System::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default route for this zone
|
||||
*/
|
||||
public function systems()
|
||||
{
|
||||
return $this->belongsToMany(System::class)
|
||||
->withPivot(['default']);
|
||||
}
|
||||
}
|
36
database/migrations/2021_08_08_125817_default_route.php
Normal file
36
database/migrations/2021_08_08_125817_default_route.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class DefaultRoute extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('system_zone', function (Blueprint $table) {
|
||||
$table->boolean('default')->nullable();
|
||||
});
|
||||
|
||||
DB::statement('CREATE UNIQUE INDEX default_zone ON system_zone (zone_id) WHERE "default" = true');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
DB::statement("DROP UNIQUE INDEX default_zone");
|
||||
|
||||
Schema::table('system_zone', function (Blueprint $table) {
|
||||
$table->dropColumn('default');
|
||||
});
|
||||
}
|
||||
}
|
@ -70,7 +70,7 @@
|
||||
@foreach ($o->zones->sortBy('zone_id') as $oz)
|
||||
@foreach ($oz->addresses as $ao)
|
||||
<tr>
|
||||
<td><a href="{{ url('ftn/system/addedit',[$ao->system_id]) }}">{{ $ao->system->full_name($ao) }}</a> @auth<span class="float-end"><small>@if($ao->session('sespass'))<sup>*</sup>@elseif($ao->system->setup)<sup class="success">+</sup>@endif[{{ $ao->system_id }}]</small></span>@endauth</td>
|
||||
<td><a href="{{ url('ftn/system/addedit',[$ao->system_id]) }}">{{ $ao->system->full_name($ao) }}</a> @auth<span class="float-end"><small>@if($ao->session('sespass'))<sup>{{ $ao->session('default') ? '**' : '*' }}</sup>@elseif($ao->system->setup)<sup class="success">+</sup>@endif[{{ $ao->system_id }}]</small></span>@endauth</td>
|
||||
<td>{{ $ao->system->sysop }}</td>
|
||||
<td>{{ $ao->system->location }}</td>
|
||||
<td>{{ $ao->ftn_3d }}</td>
|
||||
@ -82,7 +82,7 @@
|
||||
@auth
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="5"><sup>*</sup>System defined here <sup class="success">+</sup>This system</td>
|
||||
<td colspan="5"><sup>**</sup>Default route <sup>*</sup>System defined here <sup class="success">+</sup>This system</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
@endauth
|
||||
|
@ -38,12 +38,13 @@ use App\Http\Controllers\DomainController as DC;
|
||||
<table class="table monotable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th colspan="2"> </th>
|
||||
<th colspan="4" class="text-center">Passwords</th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Zone</th>
|
||||
<th style="min-width: 1%;">Default</th>
|
||||
<th>Session</th>
|
||||
<th>Packet</th>
|
||||
<th>TIC</th>
|
||||
@ -56,6 +57,13 @@ use App\Http\Controllers\DomainController as DC;
|
||||
@foreach ($o->sessions->sortBy('zone_id') as $oo)
|
||||
<tr>
|
||||
<td>{{ $oo->zone_id }}<span>@</span>{{ $oo->domain->name }}</td>
|
||||
<td style="text-align: center;">
|
||||
@if(($x=$oo->systems->where('pivot.default',TRUE))->count() && ($x->first()->id !== $o->id))
|
||||
<i class="bi bi-dash-square"></i>
|
||||
@else
|
||||
<span id="default" itemid="{{$oo->id}}"><i class="bi bi-{{ $x->count() ? 'check-square' : 'square' }}"></i></span>
|
||||
@endif
|
||||
</td>
|
||||
<td>{{ $oo->pivot->sespass }}</td>
|
||||
<td>{{ $oo->pivot->pktpass }}</td>
|
||||
<td>{{ $oo->pivot->ticpass }}</td>
|
||||
@ -272,3 +280,39 @@ use App\Http\Controllers\DomainController as DC;
|
||||
|
||||
@include('widgets.modal_delete')
|
||||
@endsection
|
||||
|
||||
@section('page-scripts')
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$('#default').click(function() {
|
||||
var item = this;
|
||||
icon = $(item).find('i');
|
||||
|
||||
$.ajax({
|
||||
type:'POST',
|
||||
data: {sid: {{$o->id}},_token: '{{csrf_token()}}',set:(icon.hasClass('bi-square') ? 1 : 0)},
|
||||
beforeSend: function() {
|
||||
$(item).find('i').addClass('spinner-grow spinner-grow-sm');
|
||||
},
|
||||
success: function() {
|
||||
if (icon.hasClass('bi-square')) {
|
||||
icon.removeClass('bi-square');
|
||||
icon.addClass('bi-check-square');
|
||||
} else {
|
||||
icon.removeClass('bi-check-square');
|
||||
icon.addClass('bi-square');
|
||||
}
|
||||
|
||||
$(item).find('i').removeClass('spinner-grow spinner-grow-sm');
|
||||
},
|
||||
error: function() {
|
||||
$(item).find('i').removeClass('spinner-grow spinner-grow-sm');
|
||||
alert('That didnt work? Please try again....');
|
||||
},
|
||||
url: '{{ url('api/default') }}/'+item.attributes.itemid.nodeValue,
|
||||
cache: false
|
||||
})
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@append
|
@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Controllers\{DomainController};
|
||||
|
||||
use App\Http\Controllers\{DomainController,ZoneController};
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@ -18,4 +19,5 @@ Route::middleware(['auth:api'])->group(function () {
|
||||
Route::get('regions/{o}',[DomainController::class,'api_regions']);
|
||||
Route::get('hosts/{o}/{region}',[DomainController::class,'api_hosts']);
|
||||
Route::get('hubs/{o}/{host}',[DomainController::class,'api_hubs']);
|
||||
Route::post('default/{o}',[ZoneController::class,'api_default']);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user