Skip to content

Commit 0d3065a

Browse files
committed
#1 support buttons coloring
1 parent d84ecb0 commit 0d3065a

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ you can define inside `workflows` element workflow name and it's config as follo
3737
| from | Yes | array: From states |
3838
| to | Yes | To state |
3939
| event | No | Event class that will be fired after the transition is completed |
40+
| style_classes | No | apply your css classes |
4041
| with_reasons | No | string: column inside your model will be filled with the transition |
4142
| with_reasons | No | array: will generate a dropdown list from with_reasons.model with `id` as option's value and `label` as option's text |
4243

config/workflow.php

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
'from' => ['pending', 'escalated'],
2020
'to' => 'approved',
2121
'event' => \App\Events\RequestApproved::class, // fire event
22+
'style_classes' => 'bg-success text-20'
2223
],
2324
'Escalate' => [
2425
'from' => ['pending'],
@@ -34,6 +35,7 @@
3435
'label' => 'title', // option label
3536
],
3637
],
38+
'style_classes' => 'bg-danger text-20'
3739
],
3840

3941
'Back to My Employee' => [

details.png

7.48 KB
Loading

dist/js/tool.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/components/Tool.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="flex" v-if="Object.keys(transactions).length > 0">
33
<div class="flex-1 m-1" v-for="(showModal, transaction) in transactions">
4-
<button class="bg-50 w-full btn m-1 p-2 rounded" @click.prevent="openModal(transaction)">{{transaction}}</button>
4+
<button class="bg-50 w-full btn m-1 p-2 rounded" :class="classes(transaction)" @click.prevent="openModal(transaction)">{{transaction}}</button>
55
<modal v-if="showModal" @modal-close="close(transaction)">
66
<form
77
class="bg-white rounded-lg shadow-lg overflow-hidden"
@@ -70,6 +70,10 @@
7070
this.$emit('close')
7171
},
7272
73+
classes(transaction) {
74+
return this.field.styles[transaction];
75+
},
76+
7377
reasons(transaction) {
7478
try {
7579
return this.field.reasons[transaction] || [];

src/Workflow.php

+22-7
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,10 @@ public function __construct(string $workflow_name)
3232

3333
$this->fetch_reasons($workflow, $array);
3434

35-
$transactions = [];
36-
foreach ($array as $trans) {
37-
$transactions[$trans] = false;
38-
}
39-
4035
$this->withMeta([
4136
'workflow' => $workflow_name,
42-
'transactions' => $transactions,
37+
'transactions' => $this->get_transitions($array),
38+
'styles' => $this->get_styles($workflow),
4339
]);
4440

4541

@@ -71,7 +67,7 @@ public function component()
7167
* @param array $workflow
7268
* @param array $array
7369
*/
74-
protected function fetch_reasons($workflow, array $array)
70+
protected function fetchReasons($workflow, array $array)
7571
{
7672
collect($workflow['transitions'])->filter(function ($trans, $trans_label) use ($array) {
7773
return in_array($trans_label, $array) && array_key_exists('with_reasons', $trans);
@@ -105,4 +101,23 @@ public function setReasons($reasons)
105101
"reasons" => collect(data_get($this, 'element.meta.reasons', []))->merge($reasons),
106102
]);
107103
}
104+
105+
private function get_transitions(array $array)
106+
{
107+
$transactions = [];
108+
foreach ($array as $trans) {
109+
$transactions[$trans] = false;
110+
}
111+
112+
return $transactions;
113+
}
114+
115+
private function get_styles(Collection $workflow)
116+
{
117+
return collect($workflow->get('transitions'))->reject(function ($trans) {
118+
return !isset($trans['style_classes']);
119+
})->map(function ($trans) {
120+
return $trans['style_classes'];
121+
})->toArray();
122+
}
108123
}

0 commit comments

Comments
 (0)