Skip to content

Commit 6220f9b

Browse files
Delete Process Category Modal vue
1 parent ee4780e commit 6220f9b

10 files changed

Lines changed: 221 additions & 160 deletions

File tree

‎ProcessMaker/Http/Controllers/Process/ProcessCategoryController.php‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,30 @@
22

33
namespace ProcessMaker\Http\Controllers\Process;
44

5-
use Illuminate\Http\Request;
65
use ProcessMaker\Http\Controllers\Controller;
6+
use ProcessMaker\Models\ProcessCategory;
77

88
class ProcessCategoryController extends Controller
99
{
10-
public function index() {
11-
return view ('processes.categories.index');
10+
/**
11+
* Get list of Process Categories
12+
*
13+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
14+
*/
15+
public function index()
16+
{
17+
return view('processes.categories.index');
18+
}
19+
20+
/**
21+
* Get a specific process category
22+
*
23+
* @param ProcessCategory $processCategory
24+
*
25+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
26+
*/
27+
public function edit(ProcessCategory $processCategory)
28+
{
29+
return view('processes.categories.edit', compact('processCategory'));
1230
}
1331
}

‎ProcessMaker/Http/Resources/ProcessCategory.php‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,16 @@
33

44
class ProcessCategory extends ApiResource
55
{
6-
6+
/**
7+
* Transform the resource into an array.
8+
*
9+
* @param \Illuminate\Http\Request
10+
* @return array
11+
*/
12+
public function toArray($request)
13+
{
14+
$array = parent::toArray($request);
15+
16+
return $array;
17+
}
718
}

‎ProcessMaker/Models/ProcessCategory.php‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,25 @@
2929
* )
3030
*/
3131
class ProcessCategory extends Model
32-
{
32+
{
3333

3434
protected $fillable = [
3535
'name',
3636
'status'
3737
];
3838

39-
public static function rules()
39+
public static function rules($existing=null)
4040
{
4141
$rules = [
4242
'name' => 'required|string|max:100|unique:process_categories,name',
4343
'status' => 'required|string|in:ACTIVE,INACTIVE'
4444
];
45+
if ($existing) {
46+
$rules['name'] = [
47+
'required','max:100','string',
48+
Rule::unique('process_categories')->ignore($existing->id, 'id')
49+
];
50+
}
4551

4652
return $rules;
4753
}

‎resources/js/processes/categories/components/CategoriesListing.vue‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
<template>
22
<div class="data-table">
3-
<vuetable :dataManager="dataManager" :sortOrder="sortOrder" :css="css" :api-mode="false" @vuetable:pagination-data="onPaginationData" :fields="fields" :data="data" data-path="data" pagination-path="meta">
3+
<vuetable :dataManager="dataManager" :sortOrder="sortOrder" :css="css" :api-mode="false"
4+
@vuetable:pagination-data="onPaginationData" :fields="fields" :data="data" data-path="data"
5+
pagination-path="meta">
46
<template slot="actions" slot-scope="props">
5-
<div class="actions">
6-
<i class="fas fa-ellipsis-h"></i>
7-
<div class="popout">
8-
<b-btn variant="action" @click="onAction('edit-item', props.rowData, props.rowIndex)" v-b-tooltip.hover title="Edit"><i class="fas fa-edit"></i></b-btn>
9-
<b-btn variant="action" @click="onAction('remove-item', props.rowData, props.rowIndex)" v-b-tooltip.hover title="Remove"><i class="fas fa-trash-alt"></i></b-btn>
7+
<div class="actions">
8+
<div class="popout">
9+
<b-btn variant="action" @click="onAction('edit-item', props.rowData, props.rowIndex)"
10+
v-b-tooltip.hover title="Edit"><i class="fas fa-edit"></i></b-btn>
11+
<b-btn variant="action" @click="onAction('remove-item', props.rowData, props.rowIndex)"
12+
v-b-tooltip.hover title="Remove"><i class="fas fa-trash-alt"></i></b-btn>
13+
</div>
1014
</div>
11-
</div>
1215
</template>
1316
</vuetable>
14-
<pagination single="Category" plural="Categdories" :perPageSelectEnabled="true" @changePerPage="changePerPage" @vuetable-pagination:change-page="onPageChange" ref="pagination"></pagination>
17+
<pagination single="Category" plural="Categories" :perPageSelectEnabled="true" @changePerPage="changePerPage"
18+
@vuetable-pagination:change-page="onPageChange" ref="pagination"></pagination>
1519
</div>
1620
</template>
1721

@@ -80,23 +84,24 @@
8084
},
8185
transform(data) {
8286
// format in a way vuetable is expecting
83-
data = Object.assign({}, data, data.meta, { meta: null })
87+
data = Object.assign({}, data, data.meta, {meta: null})
8488
return data;
8589
},
86-
onPaginationData() { },
90+
onPaginationData() {
91+
},
8792
onAction(action, data, index) {
8893
switch (action) {
8994
case "edit-item":
90-
this.$emit('edit', data)
91-
break
95+
window.location = "/processes/categories/" + data.id + "/edit";
96+
break;
9297
case "remove-item":
9398
ProcessMaker.confirmModal(
9499
'Caution!',
95-
'<b>Are you sure to delete the process </b>' + data.name + '?', '', () => {
100+
'<b>Are you sure to delete the process category </b>' + data.name + '?', '', () => {
96101
this.$emit('delete', data)
97102
}
98-
)
99-
break
103+
);
104+
break;
100105
}
101106
},
102107
formatStatus(value) {

‎resources/js/processes/categories/components/modal/modal-category-add-edit.vue‎

Lines changed: 0 additions & 121 deletions
This file was deleted.

‎resources/js/processes/categories/index.js‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,19 @@ new Vue({
2121
this.$refs.addEdit.$refs.modal.show()
2222
},
2323
deleteCategory(data) {
24-
//@todo implement
25-
ProcessMaker.apiClient.delete('category/' + data.id)
24+
ProcessMaker.apiClient.delete('process_categories/' + data.id)
2625
.then(response => {
2726
ProcessMaker.alert('Category Successfully Deleted', 'success');
2827
this.reload();
29-
})
30-
.catch(error => {
31-
if (error.response.status === 422) {
32-
let errors = error.response.data.errors;
33-
ProcessMaker.alert(errors.processCategory.join(', '), 'danger');
34-
}
3528
});
3629
},
3730
reload() {
38-
this.$refs.list.fetch();
31+
this.$refs.list.dataManager([
32+
{
33+
field: 'updated_at',
34+
direction: 'desc'
35+
}
36+
]);
3937
}
4038
}
4139
});

‎resources/views/admin/groups/edit.blade.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<div class="form-group">
1919
{!! Form::label('name', 'Name') !!}
2020
{!! Form::text('name', null, ['id' => 'name','class'=> 'form-control', 'v-model' => 'formData.name', 'v-bind:class' => '{\'form-control\':true, \'is-invalid\':errors.name}']) !!}
21-
<small id="emailHelp" class="form-text text-muted">Group name must be distinct</small>
21+
<small class="form-text text-muted">Group name must be distinct</small>
2222
<div class="invalid-feedback" v-if="errors.name">@{{errors.name[0]}}</div>
2323
</div>
2424
<div class="form-group">
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
@extends('layouts.layout')
2+
3+
@section('title')
4+
{{__('Edit Process Category')}}
5+
@endsection
6+
7+
@section('sidebar')
8+
@include('layouts.sidebar', ['sidebar'=> Menu::get('sidebar_processes')])
9+
@endsection
10+
11+
@section('content')
12+
<div class="container" id="editProcessCategory">
13+
<h1>{{__('Edit Process Category')}}</h1>
14+
<div class="row">
15+
<div class="col-8">
16+
<div class="card card-body">
17+
{!! Form::open() !!}
18+
<div class="form-group">
19+
{!! Form::label('name', 'Category Name') !!}
20+
{!! Form::text('name', null, ['id' => 'name','class'=> 'form-control', 'v-model' => 'formData.name',
21+
'v-bind:class' => '{"form-control":true, "is-invalid":errors.name}']) !!}
22+
<small class="form-text text-muted">{{ __('Category Name must be distinct') }}</small>
23+
<div class="invalid-feedback" v-if="errors.name">@{{errors.name[0]}}</div>
24+
</div>
25+
<div class="form-group">
26+
{!! Form::label('status', 'Status') !!}
27+
{!! Form::select('status', ['ACTIVE' => 'Active', 'INACTIVE' => 'Inactive'], null, ['id' => 'status',
28+
'class' => 'form-control', 'v-model' => 'formData.status', 'v-bind:class' => '{"form-control":true, "is-invalid":errors.status}']) !!}
29+
<div class="invalid-feedback" v-if="errors.status">@{{errors.status[0]}}</div>
30+
</div>
31+
<br>
32+
<div class="text-right">
33+
{!! Form::button('Cancel', ['class'=>'btn btn-outline-success', '@click' => 'onClose']) !!}
34+
{!! Form::button('Update', ['class'=>'btn btn-success ml-2', '@click' => 'onUpdate']) !!}
35+
</div>
36+
{!! Form::close() !!}
37+
</div>
38+
</div>
39+
</div>
40+
</div>
41+
@endsection
42+
43+
@section('js')
44+
<script>
45+
new Vue({
46+
el: '#editProcessCategory',
47+
data() {
48+
return {
49+
formData: @json($processCategory),
50+
errors: {
51+
'name': null,
52+
'status': null
53+
}
54+
}
55+
},
56+
methods: {
57+
resetErrors() {
58+
this.errors = Object.assign({}, {
59+
name: null,
60+
description: null,
61+
status: null
62+
});
63+
},
64+
onClose() {
65+
window.location.href = '/processes/categories';
66+
},
67+
onUpdate() {
68+
this.resetErrors();
69+
ProcessMaker.apiClient.put('process_categories/' + this.formData.id, this.formData)
70+
.then(response => {
71+
ProcessMaker.alert('Update Process Category Successfully', 'success');
72+
this.onClose();
73+
})
74+
.catch(error => {
75+
if (error.response.status && error.response.status === 422) {
76+
this.errors = error.response.data.errors;
77+
}
78+
});
79+
}
80+
}
81+
});
82+
</script>
83+
@endsection

0 commit comments

Comments
 (0)