FEATURE #1446: add html code widget
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use App\Handlers\Registrators\WidgetRegistrator;
|
use App\Handlers\Registrators\WidgetRegistrator;
|
||||||
|
use App\Widgets\HtmlCode\HtmlCode;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
@@ -50,5 +51,6 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
$registrator = $this->app->make('registerWidget');
|
$registrator = $this->app->make('registerWidget');
|
||||||
|
|
||||||
// register all available widgets
|
// register all available widgets
|
||||||
|
$registrator->register(HtmlCode::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Widgets\HtmlCode;
|
||||||
|
|
||||||
|
use App\Http\Requests\Request;
|
||||||
|
use App\Models\Widget;
|
||||||
|
use App\Widgets\Contracts\WidgetRenderer;
|
||||||
|
use App\Widgets\Exceptions\MissingParameterException;
|
||||||
|
use App\Widgets\NonInstallableWidget;
|
||||||
|
|
||||||
|
class HtmlCode extends NonInstallableWidget
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Name getter
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getName()
|
||||||
|
{
|
||||||
|
return 'widgets/htmlCode.widgetName';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for description
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getDescription()
|
||||||
|
{
|
||||||
|
return 'widgets/htmlCode.widgetDescription';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for presenter/renderer of this widget
|
||||||
|
*
|
||||||
|
* @return WidgetRenderer
|
||||||
|
*/
|
||||||
|
public static function getPresenter()
|
||||||
|
{
|
||||||
|
return Presenters\HtmlCode::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Widget $widget
|
||||||
|
* @param Request $request
|
||||||
|
*
|
||||||
|
* @return Widget
|
||||||
|
* @throws MissingParameterException
|
||||||
|
*/
|
||||||
|
public static function save(Widget $widget, Request $request)
|
||||||
|
{
|
||||||
|
if (!isset($request->code) || empty($request->code)) {
|
||||||
|
throw new MissingParameterException('code');
|
||||||
|
}
|
||||||
|
|
||||||
|
$widgetSettings = [
|
||||||
|
'code' => $request->code,
|
||||||
|
'containerClass' => isset($request->containerClass) ? $request->containerClass : ''
|
||||||
|
];
|
||||||
|
|
||||||
|
$widget->settings = json_encode($widgetSettings);
|
||||||
|
|
||||||
|
return $widget;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Widgets\HtmlCode\Presenters;
|
||||||
|
|
||||||
|
use App\Models\Widget;
|
||||||
|
use App\Models\WidgetType;
|
||||||
|
use App\Widgets\Contracts\WidgetRenderer;
|
||||||
|
|
||||||
|
class HtmlCode implements WidgetRenderer
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Method used for displaying widget.
|
||||||
|
*
|
||||||
|
* This method renders some HTML code for displaying.
|
||||||
|
*
|
||||||
|
* @param object $settings
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function render($settings)
|
||||||
|
{
|
||||||
|
$code = '
|
||||||
|
<div class="html-code-widget ' . $settings->containerClass . '">
|
||||||
|
' . $settings->code . '
|
||||||
|
</div>';
|
||||||
|
|
||||||
|
return $code;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display form for creating new instance of widget
|
||||||
|
*
|
||||||
|
* @param WidgetType $type
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function renderAddForm(WidgetType $type)
|
||||||
|
{
|
||||||
|
return view('admin.widgets.htmlCode.new', ['type' => $type]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display form for editing already existing widget
|
||||||
|
*
|
||||||
|
* @param Widget $widget
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function renderEditForm(Widget $widget)
|
||||||
|
{
|
||||||
|
return view('admin.widgets.htmlCode.edit', ['widget' => $widget]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
@extends('admin.layout')
|
||||||
|
|
||||||
|
@section('pageName', @trans('widgets/htmlCode.edit', ['name' => $widget->name]))
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<h1>@lang('widgets/htmlCode.edit', ['name' => $widget->name])</h1>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="column large-8">
|
||||||
|
@include('admin.widgets.htmlCode.editForm')
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="column large-4">
|
||||||
|
<h3>@lang('widgets/htmlCode.preview')</h3>
|
||||||
|
|
||||||
|
@widgetPreview($widget)
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@stop
|
||||||
|
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
@if (!isset($hideMessages))
|
||||||
|
@if (session('success'))
|
||||||
|
<div class="callout success">
|
||||||
|
{{ session('success') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if (session('error'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ session('error') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<form action="{{route('widgets.postEdit', ['id' => $widget->id])}}" method="POST">
|
||||||
|
{!! csrf_field() !!}
|
||||||
|
<label>
|
||||||
|
@lang('widgets/htmlCode.name')
|
||||||
|
|
||||||
|
<input type="text" name="name" value="{{$widget->name}}" placeholder="@lang('widgets/htmlCode.name')" />
|
||||||
|
|
||||||
|
@if (isset($errors) && $errors->has('name'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ $errors->first('name') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
@lang('widgets/htmlCode.description')
|
||||||
|
|
||||||
|
<input type="text" name="description" placeholder="@lang('widgets/htmlCode.description')"
|
||||||
|
value="{{$widget->description}}" />
|
||||||
|
|
||||||
|
@if (isset($errors) && $errors->has('description'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ $errors->first('description') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
@lang('widgets/htmlCode.containerClass')
|
||||||
|
|
||||||
|
<input type="text" name="containerClass" placeholder="@lang('widgets/htmlCode.containerClass')"
|
||||||
|
value="{{$widget->containerClass}}" />
|
||||||
|
|
||||||
|
@if (isset($errors) && $errors->has('containerClass'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ $errors->first('description') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
@lang('widgets/htmlCode.code')
|
||||||
|
|
||||||
|
<textarea rows="4" name="code" placeholder="@lang('widgets/htmlCode.code')">{{$widget->code}}</textarea>
|
||||||
|
|
||||||
|
@if (isset($errors) && $errors->has('code'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ $errors->first('code') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<button type="submit" class="button success">@lang('widgets/htmlCode.editExisting')</button>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
@extends('admin.layout')
|
||||||
|
|
||||||
|
@section('pageName', @trans('widgets/htmlCode.new'))
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<h1>@lang('widgets/htmlCode.new')</h1>
|
||||||
|
|
||||||
|
@include('admin.widgets.htmlCode.newForm')
|
||||||
|
@stop
|
||||||
|
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
@if (!isset($hideMessages))
|
||||||
|
@if (session('success'))
|
||||||
|
<div class="callout success">
|
||||||
|
{{ session('success') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if (session('error'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ session('error') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<form action="{{route('widgets.postNew', ['type' => $type])}}" method="POST">
|
||||||
|
{!! csrf_field() !!}
|
||||||
|
<label>
|
||||||
|
@lang('widgets/htmlCode.name')
|
||||||
|
|
||||||
|
<input type="text" name="name" value="{{old("name")}}" placeholder="@lang('widgets/htmlCode.name')" />
|
||||||
|
|
||||||
|
@if (isset($errors) && $errors->has('name'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ $errors->first('name') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
@lang('widgets/htmlCode.description')
|
||||||
|
|
||||||
|
<input type="text" name="description" placeholder="@lang('widgets/htmlCode.description')"
|
||||||
|
value="{{old("description")}}" />
|
||||||
|
|
||||||
|
@if (isset($errors) && $errors->has('description'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ $errors->first('description') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
@lang('widgets/htmlCode.containerClass')
|
||||||
|
|
||||||
|
<input type="text" name="containerClass" placeholder="@lang('widgets/htmlCode.containerClass')"
|
||||||
|
value="{{old("containerClass")}}" />
|
||||||
|
|
||||||
|
@if (isset($errors) && $errors->has('containerClass'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ $errors->first('description') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
@lang('widgets/htmlCode.code')
|
||||||
|
|
||||||
|
<textarea rows="4" name="code" placeholder="@lang('widgets/htmlCode.code')">{{old("code")}}</textarea>
|
||||||
|
|
||||||
|
@if (isset($errors) && $errors->has('code'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ $errors->first('code') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<button type="submit" class="button success">@lang('widgets/htmlCode.createNew')</button>
|
||||||
|
</form>
|
||||||
Reference in New Issue
Block a user