Enable echomail subscription by any of a systems address
This commit is contained in:
parent
424d6ef39d
commit
847869911f
@ -3,7 +3,7 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
@ -275,6 +275,17 @@ class SystemController extends Controller
|
|||||||
: redirect()->to('user/system/register');
|
: redirect()->to('user/system/register');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function api_address(Request $request,System $o): Collection
|
||||||
|
{
|
||||||
|
return Address::select(['addresses.id','addresses.zone_id','region_id','host_id','node_id'])
|
||||||
|
->leftjoin('zones',['zones.id'=>'addresses.zone_id'])
|
||||||
|
->where('addresses.system_id',$o->id)
|
||||||
|
->where('zones.domain_id',$request->domain_id)
|
||||||
|
->FTNorder()
|
||||||
|
->get()
|
||||||
|
->map(function($item) { return ['id'=>$item->id,'value'=>$item->ftn3d]; });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Systems with no owners
|
* Systems with no owners
|
||||||
*/
|
*/
|
||||||
@ -335,7 +346,7 @@ class SystemController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function echoareas(Request $request,System $o)
|
public function echoareas(Request $request,System $o)
|
||||||
{
|
{
|
||||||
$ao = $o->addresses->filter(function($item) use ($request) { return $item->zone->domain_id == $request->domain_id; })->first();
|
$ao = $o->addresses->firstWhere('id',$request->address_id);
|
||||||
|
|
||||||
if (($request->method() == 'POST') && $request->post()) {
|
if (($request->method() == 'POST') && $request->post()) {
|
||||||
session()->flash('accordion','echoarea');
|
session()->flash('accordion','echoarea');
|
||||||
@ -344,13 +355,13 @@ class SystemController extends Controller
|
|||||||
if (! $ao->session('sespass'))
|
if (! $ao->session('sespass'))
|
||||||
return redirect()->back()->withErrors('System doesnt belong to this network');
|
return redirect()->back()->withErrors('System doesnt belong to this network');
|
||||||
|
|
||||||
$ao->echoareas()->syncWithPivotValues($request->id,['subscribed'=>Carbon::now()]);
|
$ao->echoareas()->syncWithPivotValues($request->get('id',[]),['subscribed'=>Carbon::now()]);
|
||||||
|
|
||||||
return redirect()->back()->with('success','Echoareas updated');;
|
return redirect()->back()->with('success','Echoareas updated');;
|
||||||
}
|
}
|
||||||
|
|
||||||
$eo = Echoarea::active()
|
$eo = Echoarea::active()
|
||||||
->where('domain_id',$request->domain_id)
|
->where('domain_id',$ao->zone->domain_id)
|
||||||
->orderBy('name')
|
->orderBy('name')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
@ -30,7 +30,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="offset-2 col-3" id="echoarea-summary">
|
<!-- Select Address -->
|
||||||
|
<div class="col-3">
|
||||||
|
<div class="d-none" id="address-select">
|
||||||
|
<label for="address_id" class="form-label">Address</label>
|
||||||
|
<div class="input-group">
|
||||||
|
<span class="input-group-text"><i class="bi bi-hash"></i></span>
|
||||||
|
<select class="form-select" id="address_id" name="address_id" required>
|
||||||
|
<option></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Summary of Addresses -->
|
||||||
|
<div class="offset-3 col-3" id="echoarea-summary">
|
||||||
<table class="table monotable">
|
<table class="table monotable">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -65,8 +79,45 @@
|
|||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
$('#domain_id').on('change',function() {
|
$('#domain_id').on('change',function() {
|
||||||
|
if (! $(this).val()) {
|
||||||
|
$('#echoarea-summary').removeClass('d-none');
|
||||||
|
$('#address-select').addClass('d-none');
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
$('#address-select').removeClass('d-none');
|
||||||
|
}
|
||||||
|
|
||||||
|
var item = this;
|
||||||
|
icon = $(item).parent().find('i');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
data: {domain_id: $(item).val()},
|
||||||
|
beforeSend: function() {
|
||||||
|
icon.addClass('spinner-grow spinner-grow-sm');
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
icon.removeClass('spinner-grow spinner-grow-sm');
|
||||||
|
$('#address_id')
|
||||||
|
.empty()
|
||||||
|
.append($('<option>'))
|
||||||
|
.append(data.map(function(item) {
|
||||||
|
return $('<option>').val(item.id).text(item.value);
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
error: function(e) {
|
||||||
|
icon.removeClass('spinner-grow spinner-grow-sm');
|
||||||
|
|
||||||
|
if (e.status != 412)
|
||||||
|
alert('That didnt work? Please try again....');
|
||||||
|
},
|
||||||
|
url: '{{ url('api/system/address',[$o->id]) }}',
|
||||||
|
cache: false
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#address_id').on('change',function() {
|
||||||
if (! $(this).val()) {
|
if (! $(this).val()) {
|
||||||
$('#echoarea-summary').removeClass('d-none');
|
$('#echoarea-summary').removeClass('d-none');
|
||||||
$('#echoarea-select').addClass('d-none');
|
$('#echoarea-select').addClass('d-none');
|
||||||
@ -83,7 +134,7 @@
|
|||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
data: {domain_id: $(item).val()},
|
data: {address_id: $(item).val()},
|
||||||
beforeSend: function() {
|
beforeSend: function() {
|
||||||
icon.addClass('spinner-grow spinner-grow-sm');
|
icon.addClass('spinner-grow spinner-grow-sm');
|
||||||
},
|
},
|
||||||
@ -91,7 +142,6 @@
|
|||||||
icon.removeClass('spinner-grow spinner-grow-sm');
|
icon.removeClass('spinner-grow spinner-grow-sm');
|
||||||
$('#echoarea-select').empty().append(data);
|
$('#echoarea-select').empty().append(data);
|
||||||
$('#echoareas').checkboxes('range',true);
|
$('#echoareas').checkboxes('range',true);
|
||||||
//eval(document.getElementById('echoarea-javascript').innerHTML);
|
|
||||||
},
|
},
|
||||||
error: function(e) {
|
error: function(e) {
|
||||||
icon.removeClass('spinner-grow spinner-grow-sm');
|
icon.removeClass('spinner-grow spinner-grow-sm');
|
||||||
@ -103,6 +153,6 @@
|
|||||||
cache: false
|
cache: false
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
</script>
|
</script>
|
||||||
@append
|
@append
|
@ -16,9 +16,15 @@ use App\Http\Controllers\{DomainController,SystemController,ZoneController};
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Route::middleware(['auth:api'])->group(function () {
|
Route::middleware(['auth:api'])->group(function () {
|
||||||
Route::get('regions/{o}',[DomainController::class,'api_regions']);
|
Route::get('regions/{o}',[DomainController::class,'api_regions'])
|
||||||
Route::get('hosts/{o}/{region}',[DomainController::class,'api_hosts']);
|
->where('o','[0-9]+');
|
||||||
|
Route::get('hosts/{o}/{region}',[DomainController::class,'api_hosts'])
|
||||||
|
->where('o','[0-9]+');
|
||||||
Route::get('systems/orphan',[SystemController::class,'api_orphan']);
|
Route::get('systems/orphan',[SystemController::class,'api_orphan']);
|
||||||
Route::get('hubs/{o}/{host}',[DomainController::class,'api_hubs']);
|
Route::get('hubs/{o}/{host}',[DomainController::class,'api_hubs'])
|
||||||
Route::post('default/{o}',[ZoneController::class,'api_default']);
|
->where('o','[0-9]+');
|
||||||
|
Route::post('default/{o}',[ZoneController::class,'api_default'])
|
||||||
|
->where('o','[0-9]+');
|
||||||
|
Route::post('system/address/{o}',[SystemController::class,'api_address'])
|
||||||
|
->where('o','[0-9]+');
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user