Merge pull request #12703 from Godmartinz/webhook_clean_up

adds clear and save button, save button updates accordingly
This commit is contained in:
snipe 2023-03-21 17:02:33 -07:00 committed by GitHub
commit 35bef6625a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 100 additions and 65 deletions

View file

@ -11,7 +11,7 @@ class SlackSettingsForm extends Component
public $webhook_endpoint; public $webhook_endpoint;
public $webhook_channel; public $webhook_channel;
public $webhook_botname; public $webhook_botname;
public $isDisabled ='disabled' ; public $isDisabled ='' ;
public $webhook_name; public $webhook_name;
public $webhook_link; public $webhook_link;
public $webhook_placeholder; public $webhook_placeholder;
@ -27,7 +27,6 @@ class SlackSettingsForm extends Component
'webhook_botname' => 'string|nullable', 'webhook_botname' => 'string|nullable',
]; ];
public function mount(){ public function mount(){
$this->webhook_text= [ $this->webhook_text= [
"slack" => array( "slack" => array(
@ -45,6 +44,7 @@ class SlackSettingsForm extends Component
]; ];
$this->setting = Setting::getSettings(); $this->setting = Setting::getSettings();
$this->save_button = trans('general.save');
$this->webhook_selected = $this->setting->webhook_selected; $this->webhook_selected = $this->setting->webhook_selected;
$this->webhook_placeholder = $this->webhook_text[$this->setting->webhook_selected]["placeholder"]; $this->webhook_placeholder = $this->webhook_text[$this->setting->webhook_selected]["placeholder"];
$this->webhook_name = $this->webhook_text[$this->setting->webhook_selected]["name"]; $this->webhook_name = $this->webhook_text[$this->setting->webhook_selected]["name"];
@ -54,6 +54,12 @@ class SlackSettingsForm extends Component
$this->webhook_botname = $this->setting->webhook_botname; $this->webhook_botname = $this->setting->webhook_botname;
$this->webhook_options = $this->setting->webhook_selected; $this->webhook_options = $this->setting->webhook_selected;
if($this->setting->webhook_selected == 'general'){
$this->isDisabled='';
}
if($this->setting->webhook_endpoint != null && $this->setting->webhook_channel != null){
$this->isDisabled= '';
}
} }
public function updated($field){ public function updated($field){
@ -66,17 +72,28 @@ class SlackSettingsForm extends Component
$this->webhook_icon = $this->webhook_text[$this->webhook_selected]["icon"]; ; $this->webhook_icon = $this->webhook_text[$this->webhook_selected]["icon"]; ;
$this->webhook_placeholder = $this->webhook_text[$this->webhook_selected]["placeholder"]; $this->webhook_placeholder = $this->webhook_text[$this->webhook_selected]["placeholder"];
$this->webhook_link = $this->webhook_text[$this->webhook_selected]["link"]; $this->webhook_link = $this->webhook_text[$this->webhook_selected]["link"];
if($this->webhook_selected != 'slack'){
$this->isDisabled= '';
$this->save_button = trans('general.save');
}
} }
private function isButtonDisabled(){
if($this->webhook_selected == 'slack') {
if (empty($this->webhook_endpoint)) {
$this->isDisabled = 'disabled';
$this->save_button = trans('admin/settings/general.webhook_presave');
}
if (empty($this->webhook_channel)) {
$this->isDisabled = 'disabled';
$this->save_button = trans('admin/settings/general.webhook_presave');
}
}
}
public function render() public function render()
{ {
if(empty($this->webhook_channel || $this->webhook_endpoint)){ $this->isButtonDisabled();
$this->isDisabled= 'disabled';
}
if(empty($this->webhook_endpoint && $this->webhook_channel)){
$this->isDisabled= '';
}
return view('livewire.slack-settings-form'); return view('livewire.slack-settings-form');
} }
@ -100,6 +117,7 @@ class SlackSettingsForm extends Component
try { try {
$webhook->post($this->webhook_endpoint, ['body' => $payload]); $webhook->post($this->webhook_endpoint, ['body' => $payload]);
$this->isDisabled=''; $this->isDisabled='';
$this->save_button = trans('general.save');
return session()->flash('success' , 'Your '.$this->webhook_name.' Integration works!'); return session()->flash('success' , 'Your '.$this->webhook_name.' Integration works!');
} catch (\Exception $e) { } catch (\Exception $e) {
@ -110,9 +128,21 @@ class SlackSettingsForm extends Component
//} //}
return session()->flash('message' , trans('admin/settings/message.webhook.error_misc')); return session()->flash('message' , trans('admin/settings/message.webhook.error_misc'));
} }
public function clearSettings(){
$this->webhook_endpoint = '';
$this->webhook_channel = '';
$this->webhook_botname = '';
$this->setting->webhook_endpoint = '';
$this->setting->webhook_channel = '';
$this->setting->webhook_botname = '';
$this->setting->save();
session()->flash('save',trans('admin/settings/message.update.success'));
}
public function submit() public function submit()
{ {
if($this->webhook_selected != 'general') { if($this->webhook_selected != 'general') {
@ -124,11 +154,9 @@ class SlackSettingsForm extends Component
$this->setting->webhook_channel = $this->webhook_channel; $this->setting->webhook_channel = $this->webhook_channel;
$this->setting->webhook_botname = $this->webhook_botname; $this->setting->webhook_botname = $this->webhook_botname;
$this->setting->save(); $this->setting->save();
session()->flash('save',trans('admin/settings/message.update.success')); session()->flash('save',trans('admin/settings/message.update.success'));
} }
} }

View file

@ -202,6 +202,7 @@ return [
'slack' => 'Slack', 'slack' => 'Slack',
'general_webhook' => 'General Webhook', 'general_webhook' => 'General Webhook',
'webhook' => ':app', 'webhook' => ':app',
'webhook_presave' => 'Test to Save',
'webhook_title' => 'Update Webhook Settings', 'webhook_title' => 'Update Webhook Settings',
'webhook_help' => 'Integration settings', 'webhook_help' => 'Integration settings',
'webhook_botname' => ':app Botname', 'webhook_botname' => ':app Botname',

View file

@ -15,7 +15,6 @@
<div> <div>
<form class="form-horizontal" role="form" wire:submit.prevent="submit"> <form class="form-horizontal" role="form" wire:submit.prevent="submit">
{{csrf_field()}} {{csrf_field()}}
<div class="row"> <div class="row">
<div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2"> <div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">
<div class="panel box box-default"> <div class="panel box box-default">
@ -34,7 +33,7 @@
<br> <br>
</div> </div>
<div class="col-md-12"> <div class="col-md-12" style="border-top: 0px;">
@if (session()->has('save')) @if (session()->has('save'))
<div class="alert alert-success fade in"> <div class="alert alert-success fade in">
{{session('save')}} {{session('save')}}
@ -58,68 +57,73 @@
@endif @endif
<div class="form-group col-md-12 required"> <div class="form-group" style="margin-left:-14px;">
<div class="col-md-3"> <div class="col-md-3">
<label for="webhook_selected"> <label for="webhook_selected">
{{ trans('general.integration_option') }} {{ trans('general.integration_option') }}
</label> </label>
</div> </div>
<div class="col-md-9"> <div class="col-md-8" style="margin-left: -62px;">
<select wire:model="webhook_selected" aria-label="webhook_selected" class="form-control"> <select wire:model="webhook_selected" aria-label="webhook_selected" class="form-control">
<option value="slack">{{ trans('admin/settings/general.slack') }}</option> <option value="slack">{{ trans('admin/settings/general.slack') }}</option>
<option value="general">{{ trans('admin/settings/general.general_webhook') }}</option> <option value="general">{{ trans('admin/settings/general.general_webhook') }}</option>
</select> </select>
</div> </div>
<br><br><br>
</div> </div>
<form class="form-horizontal" role="form" wire:submit.prevent="submit">
{{csrf_field()}}
<!--Webhook endpoint--> <!--Webhook endpoint-->
<div class="form-group col-md-12 required{{ $errors->has('webhook_endpoint') ? ' error' : '' }}"> <div class="form-group{{ $errors->has('webhook_endpoint') ? ' error' : '' }}">
<div class="col-md-2">
<div class="col-md-3"> {{ Form::label('webhook_endpoint', trans('admin/settings/general.webhook_endpoint',['app' => $webhook_name ])) }}
{{ Form::label('webhook_endpoint', trans('admin/settings/general.webhook_endpoint',['app' => ucwords($webhook_selected) ])) }}
</div> </div>
<div class="col-md-8 required">
<div class="col-md-9">
@if (config('app.lock_passwords')===true) @if (config('app.lock_passwords')===true)
<p class="text-warning"> <p class="text-warning"><i
<i class="fas fa-lock" aria-hidden="true"></i> class="fas fa-lock"></i> {{ trans('general.feature_disabled') }}</p>
{{ trans('general.feature_disabled') }} <input type="text" wire:model="webhook_endpoint" class='form-control'
</p> placeholder="{{$webhook_placeholder}}"
<input type="text" wire:model="webhook_endpoint" class="form-control" placeholder="{{ $webhook_placeholder }}" value="{{ old('webhook_endpoint', $webhook_endpoint) }}"> value="{{old('webhook_endpoint', $webhook_endpoint)}}">
@else @else
<input type="text" wire:model="webhook_endpoint" class="form-control" placeholder="{{ $webhook_placeholder }}" value="{{ old('webhook_endpoint', $webhook_endpoint) }}"> <input type="text" wire:model="webhook_endpoint" class='form-control'
placeholder="{{$webhook_placeholder}}"
value="{{old('webhook_endpoint', $webhook_endpoint)}}">
@endif @endif
{!! $errors->first('webhook_endpoint', '<span class="alert-msg">:message</span>') !!} {!! $errors->first('webhook_endpoint', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div> </div>
</div> </div>
<!-- Webhook channel --> <!-- Webhook channel -->
<div class="col-md-12 form-group required{{ $errors->has('webhook_channel') ? ' error' : '' }}"> <div class="form-group{{ $errors->has('webhook_channel') ? ' error' : '' }}">
<div class="col-md-3"> <div class="col-md-2">
{{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => ucwords($webhook_selected) ])) }} {{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => $webhook_name ])) }}
</div> </div>
<div class="col-md-9"> <div class="col-md-8 required">
@if (config('app.lock_passwords')===true) @if (config('app.lock_passwords')===true)
<input type="text" wire:model="webhook_channel" class="form-control" placeholder="#IT-Ops" value="{{ old('webhook_channel', $webhook_channel) }}"> <input type="text" wire:model="webhook_channel" class='form-control'
<p class="text-warning"> placeholder="#IT-Ops"
<i class="fas fa-lock" aria-hidden="true"></i> {{ trans('general.feature_disabled') }}</p> value="{{old('webhook_channel', $webhook_channel)}}">
<p class="text-warning"><i
class="fas fa-lock"></i> {{ trans('general.feature_disabled') }}</p>
@else @else
<input type="text" wire:model="webhook_channel" class="form-control" placeholder="#IT-Ops" value="{{ old('webhook_channel', $webhook_channel) }}"> <input type="text" wire:model="webhook_channel" class='form-control'
placeholder="#IT-Ops"
value="{{old('webhook_channel', $webhook_channel)}}">
@endif @endif
{!! $errors->first('webhook_channel', '<span class="alert-msg">:message</span>') !!} {!! $errors->first('webhook_channel', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div> </div>
</div> </div>
<!-- Webhook botname --> <!-- Webhook botname -->
<div class="col-md-12 form-group required{{ $errors->has('webhook_botname') ? ' error' : '' }}"> <div class="form-group{{ $errors->has('webhook_botname') ? ' error' : '' }}">
<div class="col-md-3"> <div class="col-md-2">
{{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => ucwords($webhook_selected) ])) }} {{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }}
</div> </div>
<div class="col-md-9"> <div class="col-md-8">
@if (config('app.lock_passwords')===true) @if (config('app.lock_passwords')===true)
<input type="text" wire:model="webhook_botname" class='form-control' <input type="text" wire:model="webhook_botname" class='form-control'
placeholder="Snipe-Bot" {{old('webhook_botname', $webhook_botname)}}> placeholder="Snipe-Bot" {{old('webhook_botname', $webhook_botname)}}>
@ -127,7 +131,8 @@
{{ trans('general.feature_disabled') }} {{ trans('general.feature_disabled') }}
</p> </p>
@else @else
<input type="text" wire:model="webhook_botname" class="form-control" placeholder="Snipe-Bot" {{old('webhook_botname', $webhook_botname)}}> <input type="text" wire:model="webhook_botname" class='form-control'
placeholder="Snipe-Bot" {{old('webhook_botname', $webhook_botname)}}>
@endif @endif
{!! $errors->first('webhook_botname', '<span class="alert-msg" aria-hidden="true">:message</span>') !!} {!! $errors->first('webhook_botname', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div><!--col-md-10--> </div><!--col-md-10-->
@ -136,9 +141,8 @@
<!--Webhook Integration Test--> <!--Webhook Integration Test-->
@if($webhook_selected == 'slack') @if($webhook_selected == 'slack')
@if($webhook_endpoint != null && $webhook_channel != null) @if($webhook_endpoint != null && $webhook_channel != null)
<div class="form-group col-md-12"> <div class="form-group">
<div class="col-md-offset-3 col-md-9"> <div class="col-md-offset-2 col-md-8">
<a href="#" wire:click.prevent="testWebhook" <a href="#" wire:click.prevent="testWebhook"
class="btn btn-default btn-sm pull-left"> class="btn btn-default btn-sm pull-left">
<i class="{{$webhook_icon}}" aria-hidden="true"></i> <i class="{{$webhook_icon}}" aria-hidden="true"></i>
@ -149,7 +153,6 @@
<i class="fas fa-spinner fa-spin" aria-hidden="true"></i> <i class="fas fa-spinner fa-spin" aria-hidden="true"></i>
</span> </span>
</div> </div>
</div> </div>
</div> </div>
@endif @endif
@ -157,17 +160,20 @@
<div class="box-footer" style="margin-top: 45px;"> <div class="box-footer" style="margin-top: 45px;">
<div class="text-right col-md-12"> <div class="text-right col-md-12">
<button type="reset" wire:click.prevent="clearSettings" class="col-md-2 text-left btn btn-danger">Clear & Save</button>
<a class="btn btn-link text-left" <a class="btn btn-link text-left"
href="{{ route('settings.index') }}">{{ trans('button.cancel') }}</a> href="{{ route('settings.index') }}">{{ trans('button.cancel') }}</a>
<button type="submit" {{$isDisabled}} class="btn btn-primary"><i <button type="submit" {{$isDisabled}} class="btn btn-primary"><i
class="fas fa-check icon-white" class="fas fa-check icon-white"
aria-hidden="true"></i> {{ trans('general.save') }}</button> aria-hidden="true"></i> {{ $save_button }}</button>
</div> </div>
</div><!--box-footer--> </div><!--box-footer-->
</div> <!-- /box --> </div> <!-- /box -->
</div> <!-- /.col-md-8--> </div> <!-- /.col-md-8-->
</div> </div>
</div> </div>
</div>
</form> </form>
</div> </div>