Skip to content

Commit 3c20365

Browse files
committed
[Implement: krayin#368 Option to edit the tag.]
1 parent 4854641 commit 3c20365

File tree

6 files changed

+204
-0
lines changed

6 files changed

+204
-0
lines changed

packages/Webkul/Admin/src/DataGrids/Setting/TagDataGrid.php

+7
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ public function addColumns()
120120
*/
121121
public function prepareActions()
122122
{
123+
$this->addAction([
124+
'title' => trans('ui::app.datagrid.edit'),
125+
'method' => 'GET',
126+
'route' => 'admin.settings.tags.edit',
127+
'icon' => 'pencil-icon',
128+
]);
129+
123130
$this->addAction([
124131
'title' => trans('ui::app.datagrid.delete'),
125132
'method' => 'DELETE',

packages/Webkul/Admin/src/Http/Controllers/Setting/TagController.php

+42
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,48 @@ public function store()
8585
}
8686
}
8787

88+
/**
89+
* Show the form for editing the specified tag.
90+
*
91+
* @param int $id
92+
* @return \Illuminate\View\View
93+
*/
94+
public function edit($id)
95+
{
96+
$tag = $this->tagRepository->findOrFail($id);
97+
98+
return view('admin::settings.tags.edit', compact('tag'));
99+
}
100+
101+
/**
102+
* Update the specified tag in storage.
103+
*
104+
* @param int $id
105+
* @return \Illuminate\Http\Response
106+
*/
107+
public function update($id)
108+
{
109+
$validator = Validator::make(request()->all(), [
110+
'name' => 'required|unique:tags,name,' . $id,
111+
]);
112+
113+
if ($validator->fails()) {
114+
session()->flash('error', $validator->errors()->first('name'));
115+
116+
return redirect()->back();
117+
}
118+
119+
Event::dispatch('settings.tag.update.before', $id);
120+
121+
$tag = $this->tagRepository->update(request()->all(), $id);
122+
123+
Event::dispatch('settings.tag.update.after', $tag);
124+
125+
session()->flash('success', trans('admin::app.settings.tags.update-success'));
126+
127+
return redirect()->route('admin.settings.tags.index');
128+
}
129+
88130
/**
89131
* Remove the specified type from storage.
90132
*

packages/Webkul/Admin/src/Http/routes.php

+4
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@
384384

385385
Route::post('create', 'TagController@store')->name('admin.settings.tags.store');
386386

387+
Route::get('edit/{id?}', 'TagController@edit')->name('admin.settings.tags.edit');
388+
389+
Route::put('edit/{id}', 'TagController@update')->name('admin.settings.tags.update');
390+
387391
Route::get('search', 'TagController@search')->name('admin.settings.tags.search');
388392

389393
Route::delete('{id}', 'TagController@destroy')->name('admin.settings.tags.delete');

packages/Webkul/Admin/src/Resources/lang/en/app.php

+1
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@
627627
'tags' => [
628628
'title' => 'Tags',
629629
'create-title' => 'Create Tag',
630+
'edit-title' => 'Edit Tag',
630631
'cancel' => 'Cancel',
631632
'save-btn-title' => 'Save as Tag',
632633
'name' => 'Name',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
@extends('admin::layouts.master')
2+
3+
@section('page_title')
4+
{{ __('admin::app.settings.tags.edit-title') }}
5+
@stop
6+
7+
@section('css')
8+
<style>
9+
.color-item {
10+
position: relative;
11+
display: inline-block;
12+
margin: 10px 5px 5px 0px;
13+
}
14+
15+
.color-item input {
16+
position: absolute;
17+
top: 4px;
18+
left: 1px;
19+
opacity: 0;
20+
z-index: 100;
21+
cursor: pointer;
22+
}
23+
24+
.color-item label {
25+
width: 25px;
26+
height: 25px;
27+
margin-right: 3px;
28+
border-radius: 50%;
29+
cursor: pointer;
30+
display: inline-block;
31+
box-shadow: 0px 4px 15.36px 0.75px rgb(0 0 0 / 10%), 0px 2px 6px 0px rgb(0 0 0 / 15%);
32+
transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
33+
}
34+
35+
.color-item input:checked + label {
36+
border: solid 3px #FFFFFF;
37+
}
38+
</style>
39+
@stop
40+
41+
@section('content-wrapper')
42+
<div class="content full-page adjacent-center">
43+
{!! view_render_event('admin.settings.tags.edit.header.before') !!}
44+
45+
<div class="page-header">
46+
47+
{{ Breadcrumbs::render('settings.tags.edit', $tag) }}
48+
49+
<div class="page-title">
50+
<h1>{{ __('admin::app.settings.tags.edit-title') }}</h1>
51+
</div>
52+
</div>
53+
54+
{!! view_render_event('admin.settings.tags.edit.header.after') !!}
55+
56+
<form action="{{ route('admin.settings.tags.update', $tag->id) }}" method="POST" @submit.prevent="onSubmit">
57+
<div class="page-content">
58+
<div class="form-container">
59+
<div class="panel">
60+
<div class="panel-header">
61+
{!! view_render_event('admin.settings.tags.edit.form_buttons.before') !!}
62+
63+
<button type="submit" class="btn btn-md btn-primary">
64+
{{ __('admin::app.settings.tags.save-btn-title') }}
65+
</button>
66+
67+
<a href="{{ route('admin.settings.tags.index') }}">
68+
{{ __('admin::app.layouts.back') }}
69+
</a>
70+
71+
{!! view_render_event('admin.settings.tags.edit.form_buttons.after') !!}
72+
</div>
73+
74+
<div class="panel-body tag-container">
75+
{!! view_render_event('admin.settings.tags.edit.form_controls.before') !!}
76+
77+
@csrf()
78+
79+
<input name="_method" type="hidden" value="PUT">
80+
81+
<div class="form-group" :class="[errors.has('name') ? 'has-error' : '']">
82+
<label class="required">
83+
{{ __('admin::app.settings.tags.name') }}
84+
</label>
85+
86+
<input
87+
type="text"
88+
name="name"
89+
class="control"
90+
placeholder="{{ __('admin::app.settings.tags.name') }}"
91+
v-validate="'required'"
92+
data-vv-as="{{ __('admin::app.settings.tags.name') }}"
93+
value="{{ $tag->name }}"
94+
/>
95+
96+
<span class="control-error" v-if="errors.has('name')">
97+
@{{ errors.first('name') }}
98+
</span>
99+
</div>
100+
101+
<div class="form-group">
102+
<label>{{ __('admin::app.settings.tags.color') }}</label>
103+
104+
<div class="color-list">
105+
<span class="color-item">
106+
<input type="radio" id="337CFF" name="color" value="#337CFF" {{ $tag->color == "#337CFF" ? 'checked' : '' }}>
107+
<label for="337CFF" style="background: #337CFF;"></label>
108+
</span>
109+
110+
<span class="color-item">
111+
<input type="radio" id="FEBF00" name="color" value="#FEBF00" {{ $tag->color == "#FEBF00" ? 'checked' : '' }}>
112+
<label for="FEBF00" style="background: #FEBF00;"></label>
113+
</span>
114+
115+
<span class="color-item">
116+
<input type="radio" id="E5549F" name="color" value="#E5549F" {{ $tag->color == "#E5549F" ? 'checked' : '' }}>
117+
<label for="E5549F" style="background: #E5549F;"></label>
118+
</span>
119+
120+
<span class="color-item">
121+
<input type="radio" id="27B6BB" name="color" value="#27B6BB" {{ $tag->color == "#27B6BB" ? 'checked' : '' }}>
122+
<label for="27B6BB" style="background: #27B6BB;"></label>
123+
</span>
124+
125+
<span class="color-item">
126+
<input type="radio" id="FB8A3F" name="color" value="#FB8A3F" {{ $tag->color == "#FB8A3F" ? 'checked' : '' }}>
127+
<label for="FB8A3F" style="background: #FB8A3F;"></label>
128+
</span>
129+
130+
<span class="color-item">
131+
<input type="radio" id="43AF52" name="color" value="#43AF52" {{ $tag->color == "#337CFF" ? 'checked' : '' }}>
132+
<label for="43AF52" style="background: #43AF52;"></label>
133+
</span>
134+
</div>
135+
</div>
136+
137+
{!! view_render_event('admin.settings.tags.edit.form_controls.after') !!}
138+
</div>
139+
</div>
140+
</div>
141+
</div>
142+
</form>
143+
</div>
144+
@stop

routes/breadcrumbs.php

+6
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@
313313
$trail->push(trans('admin::app.layouts.tags'), route('admin.settings.tags.index'));
314314
});
315315

316+
// Dashboard > Tags > Edit Tag
317+
Breadcrumbs::for('settings.tags.edit', function (BreadcrumbTrail $trail, $tag) {
318+
$trail->parent('settings.tags');
319+
$trail->push(trans('admin::app.settings.tags.edit-title'), route('admin.settings.tags.edit', $tag->id));
320+
});
321+
316322

317323
// Configuration
318324
Breadcrumbs::for('configuration', function (BreadcrumbTrail $trail) {

0 commit comments

Comments
 (0)