Skip to content

A free open source IT asset/license management system

gets select working, placeholders update dynamically

Godfrey Maae178a60652
diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php
index 996a30e236..ac94743383 100644
--- a/app/Http/Livewire/SlackSettingsForm.php
+++ b/app/Http/Livewire/SlackSettingsForm.php
@@ -13,36 +13,33 @@ class SlackSettingsForm extends Component
public $webhook_botname;
public $isDisabled ='disabled' ;
public $webhook_link;
+ public $webhook_placeholder;
+ public $webhook_icon;
public $webhook_selected;
- public $webhook_options = array(
- array(
- "name" => 'Slack',
+
+ public Setting $setting;
+
+ protected $rules = [
+ 'webhook_endpoint' => 'url|required_with:slack_channel|starts_with:https://hooks.slack.com/|nullable',
+ 'webhook_channel' => 'required_with:slack_endpoint|starts_with:#|nullable',
+ 'webhook_botname' => 'string|nullable',
+ ];
+ static $webhook_text= [
+ "Slack" => array(
"icon" => 'fab fa-slack',
"placeholder" => "https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX",
"link" => 'https://api.slack.com/messaging/webhooks'
),
- array(
- "name" => 'Discord',
+ "Discord" => array(
"icon" => 'fab fa-discord',
"placeholder" => "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXXXX",
"link" => 'https://support.discord.com/hc/en-us/articles/360045093012-Server-Integrations-Page'
),
- array(
- "name" => 'Rocket Chat',
+ "RocketChat"=> array(
"icon" => 'fab fa-rocketchat',
"placeholder" => "https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXXXX",
"link" => '',
),
- );
- public $keys;
- public $icon;
-
- public Setting $setting;
-
- protected $rules = [
- 'webhook_endpoint' => 'url|required_with:slack_channel|starts_with:https://hooks.slack.com/|nullable',
- 'webhook_channel' => 'required_with:slack_endpoint|starts_with:#|nullable',
- 'webhook_botname' => 'string|nullable',
];
public function mount(){
@@ -51,15 +48,21 @@ class SlackSettingsForm extends Component
$this->webhook_endpoint = $this->setting->webhook_endpoint;
$this->webhook_channel = $this->setting->webhook_channel;
$this->webhook_botname = $this->setting->webhook_botname;
-// $this->webhook_options = $this->setting->webhook_selected;lma
- $this->keys = array_column($this->webhook_options, 'name');
+ $this->webhook_options = $this->setting->webhook_selected;
}
public function updated($field){
- $this->webhook_selected = $this->webhook_options;
+// $this->webhook_selected = $this->webhook_options;
$this->validateOnly($field ,$this->rules);
}
+ public function updatedWebhookSelected(){
+
+ $this->webhook_icon = self::$webhook_text[$this->webhook_selected]["icon"]; ;
+ $this->webhook_placeholder = self::$webhook_text[$this->webhook_selected]["placeholder"];
+ $this->webhook_link = self::$webhook_text[$this->webhook_selected]["link"];
+
+ }
public function render()
{
@@ -109,7 +112,7 @@ class SlackSettingsForm extends Component
{
$this->validate($this->rules);
- $this->setting->webhook_options = $this->webhook_options;
+ $this->setting->webhook_selected = $this->webhwebhook_selected;
$this->setting->webhook_endpoint = $this->webhook_endpoint;
$this->setting->webhook_channel = $this->webhook_channel;
$this->setting->webhook_botname = $this->webhook_botname;
diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php
index b863a0aaed..c435ae0c4a 100644
--- a/resources/views/livewire/slack-settings-form.blade.php
+++ b/resources/views/livewire/slack-settings-form.blade.php
@@ -1,32 +1,4 @@
-{{-- Page title --}}
-@section('title')
- {{ trans('admin/settings/general.webhook_title', ['app' => $webhook_selected->name ]) }}
- @parent
-@stop
-
-@section('header_right')
- <a href="{{ route('settings.index') }}" class="btn btn-primary"> {{ trans('general.back') }}</a>
-@stop
-
-
-{{-- Page content --}}
-@section('content')
-
- <div class="row">
- <div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">
- <div class="panel box box-default">
- <div class="box-header with-border">
- <h2 class="box-title">
- <i class="{{$icon}}"></i> {{ trans('admin/settings/general.webhook',['app' => $webhook_selected->name ]) }}
- </h2>
- </div>
- <div class="box-body">
- <div class="col-md-12">
- <p>
- {!! trans('admin/settings/general.webhook_integration_help',array('webhook_link' => $webhook_link, 'app' => $webhook_selected )) !!}
- </p>
- <br>
- </div>
+<div>
<div class="col-md-12" style="border-top: 0px;">
@if (session()->has('save'))
@@ -50,23 +22,21 @@
{{session('message')}}
</div>
@endif
+
<div class="form-group col-md-12">
<div class="col-md-3">
<label>Integration Option</label>
</div>
<div class="col-md-6">
-{{-- <select wire:model="webhook_options"--}}
-{{-- aria-label="webhook_options"--}}
-{{-- class="form-control "--}}
-{{-- >--}}
-{{-- <option>{{ trans('admin/settings/general.no_default_group') }}</option>--}}
-{{-- @foreach ($webhook_options[$keys] as $webhook_options)--}}
-{{-- <option value="{{$key}}" {{ $key ? 'selected' : '' }}>--}}
-{{-- {{ $key }}--}}
-{{-- </option>--}}
-{{-- @endforeach--}}
-
-{{-- </select>--}}
+ <select wire:model="webhook_selected"
+ aria-label="webhook_selected"
+ class="form-control "
+ >
+ <option>{{ trans('admin/settings/general.no_default_group') }}</option>
+ <option value="Slack">Slack</option>
+ <option value="Discord">Discord</option>
+ <option value="RocketChat">RocketChat</option>
+ </select>
</div>
<br><br><br>
@@ -84,10 +54,10 @@
<p class="text-warning"><i
class="fas fa-lock"></i> {{ trans('general.feature_disabled') }}</p>
<input type="text" wire:model="webhook_endpoint" class='form-control'
- placeholder="https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX" {{old('webhook_endpoint', $webhook_endpoint)}}>
+ placeholder={{$webhook_placeholder}} {{old('webhook_endpoint', $webhook_endpoint)}}>
@else
<input type="text" wire:model="webhook_endpoint" class='form-control'
- placeholder="https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXX" {{old('webhook_endpoint', $webhook_endpoint)}}>
+ placeholder={{$webhook_placeholder}} {{old('webhook_endpoint', $webhook_endpoint)}}>
@endif
{!! $errors->first('webhook_endpoint', '<span class="alert-msg" aria-hidden="true">:message</span>') !!}
</div>
@@ -160,9 +130,7 @@
</div> <!-- /box -->
</div> <!-- /.col-md-8-->
- </div> <!-- /.row-->
- @stop
@push('scripts')
<script>
diff --git a/resources/views/settings/slack.blade.php b/resources/views/settings/slack.blade.php
index fac07c7ccd..a5cbd8d0b3 100644
--- a/resources/views/settings/slack.blade.php
+++ b/resources/views/settings/slack.blade.php
@@ -1,18 +1,44 @@
@extends('layouts/default')
-
-
-
-
-
-
+{{-- Page title --}}
+@section('title')
+ {{ trans('admin/settings/general.slack_title') }}
+ @parent
+@stop
+
+@section('header_right')
+ <a href="{{ route('settings.index') }}" class="btn btn-primary"> {{ trans('general.back') }}</a>
+@stop
+
+
+{{-- Page content --}}
+@section('content')
+
+
+ <div class="row">
+ <div class="col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2">
+
+ <div class="panel box box-default">
+ <div class="box-header with-border">
+ <h2 class="box-title">
+ <i class="fab fa-slack"></i> {{ trans('admin/settings/general.slack') }}
+ </h2>
+ </div>
+ <div class="box-body">
+ <div class="col-md-12">
+ <p>
+ {!! trans('admin/settings/general.slack_integration_help',array('slack_link' => 'https://my.slack.com/services/new/incoming-webhook')) !!}
+ </p>
+ <br>
+ </div>
@livewire('slack-settings-form')
+ </div> <!-- /.col-md-8-->
+ </div> <!-- /.row-->
-
-
+@stop