FEATURE #1419: add admin for creating new widget area
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests;
|
||||
use App\Http\Requests\NewWidgetAreaRequest;
|
||||
use App\Models\WidgetArea;
|
||||
|
||||
class CreateNewWidgetArea extends Controller
|
||||
{
|
||||
/**
|
||||
* Form for new widget area
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function getNew()
|
||||
{
|
||||
return view('admin.widgets.area.new');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param NewWidgetAreaRequest $request
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postNew(NewWidgetAreaRequest $request)
|
||||
{
|
||||
$parameters = [
|
||||
'code' => $request->code,
|
||||
'name' => $request->name,
|
||||
'description' => $request->description
|
||||
];
|
||||
|
||||
WidgetArea::create($parameters);
|
||||
|
||||
|
||||
// redirect with success notification
|
||||
return redirect()
|
||||
->route('widgetareas.overview')
|
||||
->with('success', trans('admin/widgetAreas.successfullyCreated'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
class NewWidgetAreaRequest extends Request
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'code' => 'required|unique:widget_areas,code',
|
||||
'name' => 'required'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class FixAutoIncrementForWidgetAreas extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
|
||||
try {
|
||||
Schema::table('widget_in_widget_area', function (Blueprint $table) {
|
||||
$table->dropForeign('fk_widget_has_widget_area_widget_area1');
|
||||
});
|
||||
} catch (\Illuminate\Database\QueryException $e) {
|
||||
// probably foreign does not exist, try to remove one from migration
|
||||
|
||||
try {
|
||||
Schema::table('widget_in_widget_area', function (Blueprint $table) {
|
||||
$table->dropForeign('widget_in_widget_area_widget_area_id_foreign');
|
||||
});
|
||||
} catch (\Illuminate\Database\QueryException $ex) {
|
||||
// ignore this error
|
||||
}
|
||||
}
|
||||
|
||||
Schema::table('widget_areas', function (Blueprint $table) {
|
||||
$table->integer('id', true)->change();
|
||||
});
|
||||
|
||||
Schema::table('widget_in_widget_area', function(Blueprint $table) {
|
||||
$table->foreign('widget_area_id')
|
||||
->references('id')
|
||||
->on('widget_areas')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('widget_in_widget_area', function (Blueprint $table) {
|
||||
$table->dropForeign('widget_in_widget_area_widget_area_id_foreign');
|
||||
});
|
||||
|
||||
Schema::table('widget_areas', function (Blueprint $table) {
|
||||
$table->integer('id', false)->change();
|
||||
});
|
||||
|
||||
Schema::table('widget_in_widget_area', function(Blueprint $table) {
|
||||
$table->foreign('widget_area_id')
|
||||
->references('id')
|
||||
->on('widget_areas')
|
||||
->onDelete('cascade');
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,5 +14,7 @@ return [
|
||||
'uploadFile' => 'New file',
|
||||
'uploadImage' => 'New image',
|
||||
'uploadedFiles' => 'Overview',
|
||||
'actionLog' => 'Log'
|
||||
'actionLog' => 'Log',
|
||||
'widgets' => 'Widgets',
|
||||
'newWidgetArea' => 'New area',
|
||||
];
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
return [
|
||||
'new' => 'New widget area',
|
||||
'name' => 'Widget area name',
|
||||
'code' => 'Unique code',
|
||||
'description' => 'Description',
|
||||
'createNew' => 'Create new widget area',
|
||||
'successfullyCreated' => 'Widget area successfully created',
|
||||
'overview' => 'List of all widget areas',
|
||||
'successfullyDeleted' => 'Successfully deleted',
|
||||
'invalidArea' => 'Specified widget area is not valid. Try to choose a valid one.',
|
||||
'actions' => 'Actions',
|
||||
'noEntries' => 'No widget areas defined yet. Try to create some first.',
|
||||
'editButton' => 'Edit',
|
||||
'edit' => 'Editing widget area :name',
|
||||
'editSuccessfull' => 'Successfully edited'
|
||||
];
|
||||
@@ -0,0 +1,10 @@
|
||||
@extends('admin.layout')
|
||||
|
||||
@section('pageName', @trans('admin/widgetAreas.new'))
|
||||
|
||||
@section('content')
|
||||
<h1>@lang('admin/widgetAreas.new')</h1>
|
||||
|
||||
@include('admin.widgets.area.newForm')
|
||||
@stop
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
@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('widgetareas.postNew')}}" method="POST">
|
||||
{!! csrf_field() !!}
|
||||
<label>
|
||||
@lang('admin/widgetAreas.name')
|
||||
|
||||
<input type="text" name="name" value="{{old("name")}}" placeholder="@lang('admin/widgetAreas.name')" />
|
||||
|
||||
@if (isset($errors) && $errors->has('name'))
|
||||
<div class="callout alert">
|
||||
{{ $errors->first('name') }}
|
||||
</div>
|
||||
@endif
|
||||
</label>
|
||||
|
||||
<label>
|
||||
@lang('admin/widgetAreas.code')
|
||||
|
||||
<input type="text" name="code" value="{{old("code")}}" placeholder="@lang('admin/widgetAreas.code')" />
|
||||
|
||||
@if (isset($errors) && $errors->has('code'))
|
||||
<div class="callout alert">
|
||||
{{ $errors->first('code') }}
|
||||
</div>
|
||||
@endif
|
||||
</label>
|
||||
|
||||
<label>
|
||||
@lang('admin/widgetAreas.description')
|
||||
|
||||
<textarea rows="3" name="description"
|
||||
placeholder="@lang('admin/widgetAreas.description')">{{old("description")}}</textarea>
|
||||
|
||||
@if (isset($errors) && $errors->has('description'))
|
||||
<div class="callout alert">
|
||||
{{ $errors->first('description') }}
|
||||
</div>
|
||||
@endif
|
||||
</label>
|
||||
|
||||
<button type="submit" class="button success">@lang('admin/widgetAreas.createNew')</button>
|
||||
</form>
|
||||
Reference in New Issue
Block a user