Skip to content

Commit

Permalink
Update the modals to use the more global base for the comparators/par…
Browse files Browse the repository at this point in the history
…ameters
  • Loading branch information
Austin Kregel committed Jun 26, 2020
1 parent 70b27f3 commit 625815d
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 623 deletions.
67 changes: 61 additions & 6 deletions app/Console/Commands/GenerateChannelsAndAlertsFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Console\Commands;

use App\AccountKpi;
use App\Condition;
use App\Events\TransactionCreated;
use App\Events\TransactionGroupedEvent;
use App\Events\TransactionUpdated;
Expand Down Expand Up @@ -50,7 +51,7 @@ public function __construct()
*/
public function handle()
{
$channels = [
$this->writeToDisk('js/channels.js', [
[
'type' => SlackWebhookChannel::class,
'name' => 'Slack',
Expand Down Expand Up @@ -79,12 +80,55 @@ public function handle()
'type' => DatabaseChannel::class,
'name' => 'In-site notification',
],
];
]);

file_put_contents(resource_path('js/channels.js'), sprintf('module.exports = %s', json_encode($channels)));
$this->writeToDisk('js/alert-events.js', [
[
'type' => TransactionUpdated::class,
'name' => 'When a transaction is updated (moving from pending to not pending, updating amounts, etc...)'
],
[
'type' => TransactionCreated::class,
'name' => 'When a transaction is initially created (only fired once per transaction)',
],
[
'type' => TransactionGroupedEvent::class,
'name' => 'When a transaction is added to a group (this gives you access to the `tag` variable in your title, body and payload.)'
],
]);

$this->writeToDisk('js/condition-parameters.js', [
[
'value' => 'name',
'name' => 'transaction.name'
],
[
'value' => 'amount',
'name' => 'transaction.amount'
],
[
'value' => 'account.name',
'name' => 'transaction.account.name'
],
[
'value' => 'date',
'name' => 'transaction.date'
],
[
'value' => 'pending',
'name' => 'transaction.pending'
],
[
'value' => 'category.name',
'name' => 'transaction.category.name'
],
[
'value' => 'tag.name',
'name' => 'transaction.tag.name'
],
]);

$channels = [
$this->writeToDisk('js/alert-events.js', [
[
'type' => TransactionUpdated::class,
'name' => 'When a transaction is updated (moving from pending to not pending, updating amounts, etc...)'
Expand All @@ -97,8 +141,19 @@ public function handle()
'type' => TransactionGroupedEvent::class,
'name' => 'When a transaction is added to a group (this gives you access to the `tag` variable in your title, body and payload.)'
],
];
]);

$this->writeToDisk('js/condition-comparator.js', array_map(function ($comparator) {
return [
'value' => $comparator,
'name' => $comparator,
];
}, Condition::ALL_COMPARATORS));

file_put_contents(resource_path('js/alert-events.js'), sprintf('module.exports = %s', json_encode($channels)));
}

protected function writeToDisk(string $file, array $data)
{
file_put_contents(resource_path($file), sprintf('module.exports = %s', json_encode($data, JSON_PRETTY_PRINT)));
}
}
15 changes: 14 additions & 1 deletion resources/js/alert-events.js
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
module.exports = [{"type":"App\\Events\\TransactionUpdated","name":"When a transaction is updated (moving from pending to not pending, updating amounts, etc...)"},{"type":"App\\Events\\TransactionCreated","name":"When a transaction is initially created (only fired once per transaction)"},{"type":"App\\Events\\TransactionGroupedEvent","name":"When a transaction is added to a group (this gives you access to the `tag` variable in your title, body and payload.)"}]
module.exports = [
{
"type": "App\\Events\\TransactionUpdated",
"name": "When a transaction is updated (moving from pending to not pending, updating amounts, etc...)"
},
{
"type": "App\\Events\\TransactionCreated",
"name": "When a transaction is initially created (only fired once per transaction)"
},
{
"type": "App\\Events\\TransactionGroupedEvent",
"name": "When a transaction is added to a group (this gives you access to the `tag` variable in your title, body and payload.)"
}
]
31 changes: 30 additions & 1 deletion resources/js/channels.js
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
module.exports = [{"type":"Illuminate\\Notifications\\Channels\\SlackWebhookChannel","name":"Slack"},{"type":"NotificationChannels\\Discord\\DiscordChannel","name":"Discord"},{"type":"NotificationChannels\\Webhook\\WebhookChannel","name":"Webhook"},{"type":"Illuminate\\Notifications\\Channels\\BroadcastChannel","name":"Broadcasts"},{"type":"Illuminate\\Notifications\\Channels\\MailChannel","name":"Email"},{"type":"Illuminate\\Notifications\\Channels\\NexmoSmsChannel","name":"Nexmo"},{"type":"Illuminate\\Notifications\\Channels\\DatabaseChannel","name":"In-site notification"}]
module.exports = [
{
"type": "Illuminate\\Notifications\\Channels\\SlackWebhookChannel",
"name": "Slack"
},
{
"type": "NotificationChannels\\Discord\\DiscordChannel",
"name": "Discord"
},
{
"type": "NotificationChannels\\Webhook\\WebhookChannel",
"name": "Webhook"
},
{
"type": "Illuminate\\Notifications\\Channels\\BroadcastChannel",
"name": "Broadcasts"
},
{
"type": "Illuminate\\Notifications\\Channels\\MailChannel",
"name": "Email"
},
{
"type": "Illuminate\\Notifications\\Channels\\NexmoSmsChannel",
"name": "Nexmo"
},
{
"type": "Illuminate\\Notifications\\Channels\\DatabaseChannel",
"name": "In-site notification"
}
]
26 changes: 5 additions & 21 deletions resources/js/components/AlertModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,7 @@
</div>
</div>
<select v-model="condition.parameter" class="appearance-none block w-full rounded py-1 px-2 leading-tight focus:outline-none" v-dark-mode-input>
<option value="name">name</option>
<option value="amount">amount</option>
<option value="account.name">account.name</option>
<option value="date">date</option>
<option value="pending">pending</option>
<option value="category.name">category.name</option>
<option v-for="parameter in parameters" :value="parameter.value">{{ parameter.name }}</option>
</select>
</div>
<div class="flex-1 ml-4">
Expand All @@ -139,20 +134,7 @@
</div>

<select v-model="condition.comparator" class="appearance-none block w-full rounded py-1 px-2 leading-tight focus:outline-none" v-dark-mode-input>
<option value="EQUAL">EQUAL</option>
<option value="NOT_EQUAL">NOT_EQUAL</option>
<option value="LIKE">LIKE</option>
<option value="NOT_LIKE">NOT_LIKE</option>
<option value="IN">IN</option>
<option value="NOT_IN">NOT_IN</option>
<option value="IN_LIKE">IN_LIKE</option>
<option value="NOT_IN_LIKE">NOT_IN_LIKE</option>
<option value="STARTS_WITH">STARTS_WITH</option>
<option value="ENDS_WITH">ENDS_WITH</option>
<option value="LESS_THAN">LESS_THAN</option>
<option value="LESS_THAN_EQUAL">LESS_THAN_EQUAL</option>
<option value="GREATER_THAN">GREATER_THAN</option>
<option value="GREATER_THAN_EQUAL">GREATER_THAN_EQUAL</option>
<option v-for="comparator in comparators" :value="comparator.value">{{ comparator.name }}</option>
</select>
</div>
<div class="flex-1 ml-4">
Expand Down Expand Up @@ -222,7 +204,9 @@
"title": "New Charge from {{ transaction.name }}",
"body": "{{ transaction.name }} charged your account {{ transaction.account.name }} \${{ transaction.amount }}",
"transaction": "{{ transaction | json }}"
}, null, 4)
}, null, 4),
comparators: require('../condition-comparator'),
parameters: require('../condition-parameters'),
}
},
methods: {
Expand Down
Loading

0 comments on commit 625815d

Please sign in to comment.