Assigning session details to ZC makes it default route
This commit is contained in:
parent
53ab8851fa
commit
05f387aab7
@ -5,7 +5,7 @@ namespace App\Http\Controllers;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
use App\Models\{Address,System,Zone};
|
use App\Models\{Address,System,SystemZone,Zone};
|
||||||
use App\Rules\{FidoInteger,TwoByteInteger};
|
use App\Rules\{FidoInteger,TwoByteInteger};
|
||||||
|
|
||||||
class SystemController extends Controller
|
class SystemController extends Controller
|
||||||
@ -234,6 +234,12 @@ class SystemController extends Controller
|
|||||||
|
|
||||||
$zo = Zone::findOrFail($validate['zone_id']);
|
$zo = Zone::findOrFail($validate['zone_id']);
|
||||||
|
|
||||||
|
// If this session is for the ZC, it now becomes the default.
|
||||||
|
if (in_array(DomainController::NODE_ZC,$o->match($zo)->pluck('role')->toArray())) {
|
||||||
|
SystemZone::where('default',TRUE)->update(['default'=>FALSE]);
|
||||||
|
$validate['default'] = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
$o->sessions()->attach($zo,$validate);
|
$o->sessions()->attach($zo,$validate);
|
||||||
|
|
||||||
return redirect()->to(sprintf('ftn/system/addedit/%d',$o->id));
|
return redirect()->to(sprintf('ftn/system/addedit/%d',$o->id));
|
||||||
@ -319,6 +325,7 @@ class SystemController extends Controller
|
|||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param System $so
|
* @param System $so
|
||||||
* @param Address $o
|
* @param Address $o
|
||||||
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
||||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||||
*/
|
*/
|
||||||
public function mov_address(Request $request,System $so,Address $o)
|
public function mov_address(Request $request,System $so,Address $o)
|
||||||
|
@ -99,15 +99,20 @@ class ZoneController extends Controller
|
|||||||
* Set address as default for zone
|
* Set address as default for zone
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param Address $o
|
* @param Zone $o
|
||||||
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||||
*/
|
*/
|
||||||
public function api_default(Request $request,Zone $o)
|
public function api_default(Request $request,Zone $o)
|
||||||
{
|
{
|
||||||
$this->authorize('admin',$o);
|
$this->authorize('admin',$o);
|
||||||
|
|
||||||
$default = $o->systems->where('pivot.default',TRUE);
|
$default = $o->systems->where('pivot.default',TRUE);
|
||||||
|
|
||||||
|
if ($default->first()->addresses->pluck('role')->search(DomainController::NODE_ZC) !== FALSE)
|
||||||
|
abort(412);
|
||||||
|
|
||||||
if ($default->count() && ($default->first()->id != $request->sid))
|
if ($default->count() && ($default->first()->id != $request->sid))
|
||||||
abort(404);
|
abort(409);
|
||||||
|
|
||||||
$o->systems()->updateExistingPivot($request->sid,[
|
$o->systems()->updateExistingPivot($request->sid,[
|
||||||
'default' => (bool)$request->set,
|
'default' => (bool)$request->set,
|
||||||
|
@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
class SystemZone extends Model
|
class SystemZone extends Model
|
||||||
{
|
{
|
||||||
protected $table = 'system_zone';
|
protected $table = 'system_zone';
|
||||||
|
public $timestamps = FALSE;
|
||||||
|
|
||||||
public function system()
|
public function system()
|
||||||
{
|
{
|
||||||
|
@ -305,9 +305,11 @@ use App\Http\Controllers\DomainController as DC;
|
|||||||
|
|
||||||
$(item).find('i').removeClass('spinner-grow spinner-grow-sm');
|
$(item).find('i').removeClass('spinner-grow spinner-grow-sm');
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function(e) {
|
||||||
$(item).find('i').removeClass('spinner-grow spinner-grow-sm');
|
$(item).find('i').removeClass('spinner-grow spinner-grow-sm');
|
||||||
alert('That didnt work? Please try again....');
|
|
||||||
|
if (e.status != 412)
|
||||||
|
alert('That didnt work? Please try again....');
|
||||||
},
|
},
|
||||||
url: '{{ url('api/default') }}/'+item.attributes.itemid.nodeValue,
|
url: '{{ url('api/default') }}/'+item.attributes.itemid.nodeValue,
|
||||||
cache: false
|
cache: false
|
||||||
|
Loading…
Reference in New Issue
Block a user