Skip to content

Commit 96f13ab

Browse files
committed
Merge branch '2.0' of https://github.com/codestudiohq/laravel-totem into 2.0
2 parents f699c72 + c02dd6c commit 96f13ab

17 files changed

+210
-30
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ php artisan migrate
5050
php artisan totem:assets
5151
```
5252

53+
##### Table Prefix
54+
55+
Totems' tables use generic names which may conflict with existing tables in a project. To alleviate this the `.env` param `TOTEM_TABLE_PREFIX` can be set which will apply a prefix to all of Totems tables and their models.
56+
5357
#### Updating
5458

5559
Please republish totem assets after updating totem to a new version
@@ -83,6 +87,22 @@ Totem::auth(function($request) {
8387

8488
By default Totem's dashboard only works in local environment. To view the dashboard point your browser to /totem of your app. For e.g. laravel.dev/totem.
8589

90+
##### Filter Commands Dropdown
91+
92+
By default `Totem` outputs all Artisan commands on the Create/Edit tasks. To make this dropdown more concise there is a filter config feature that can be set in the `totem.php` config file.
93+
94+
Example filters
95+
```php
96+
'artisan' => [
97+
'command_filter' => [
98+
'stats:*',
99+
'email:daily-reports'
100+
],
101+
],
102+
```
103+
104+
This feature uses [fnmatch](http://php.net/manual/en/function.fnmatch.php) syntax to filter displayed commands. `stats:*` will match all Artisan commands that start with `stats:` while `email:daily-reports` will only match the command named `email:daily-reports`.
105+
86106
#### Middleware
87107

88108
`Laravel Totem` uses the default web and api middleware but if customization is required the middleware can be changed by setting the appropriate `.env` value. These values can be found in `config/totem.php`.

config/totem.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,8 @@
222222
'api' => [
223223
'middleware' => env('TOTEM_API_MIDDLEWARE', 'api'),
224224
],
225+
'table_prefix' => env('TOTEM_TABLE_PREFIX', ''),
226+
'artisan' => [
227+
'command_filter' => [],
228+
],
225229
];

database/factories/ModelFactory.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,14 @@
3232
'expression' => '* * * * *',
3333
];
3434
});
35+
36+
$factory->define(Studio\Totem\Result::class, function (Faker\Generator $faker) {
37+
return [
38+
'task_id' => $faker->randomDigit,
39+
'ran_at' => $faker->dateTimeBetween('-1 hour'),
40+
'duration' => (string) $faker->randomFloat(11, 0, 8000000),
41+
'result' => $faker->sentence,
42+
'created_at' => $faker->dateTimeBetween('-1 year', '-6 months'),
43+
'updated_at' => $faker->dateTimeBetween('-6 months'),
44+
];
45+
});

database/migrations/2017_08_05_194349_create_tasks_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateTasksTable extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::create('tasks', function (Blueprint $table) {
16+
Schema::create(config('totem.table_prefix').'tasks', function (Blueprint $table) {
1717
$table->increments('id');
1818
$table->string('description');
1919
$table->string('command');
@@ -35,6 +35,6 @@ public function up()
3535
*/
3636
public function down()
3737
{
38-
Schema::dropIfExists('tasks');
38+
Schema::dropIfExists(config('totem.table_prefix').'tasks');
3939
}
4040
}

database/migrations/2017_08_05_195539_create_task_frequencies_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateTaskFrequenciesTable extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::create('task_frequencies', function (Blueprint $table) {
16+
Schema::create(config('totem.table_prefix').'task_frequencies', function (Blueprint $table) {
1717
$table->increments('id');
1818
$table->unsignedInteger('task_id');
1919
$table->string('label');
@@ -29,6 +29,6 @@ public function up()
2929
*/
3030
public function down()
3131
{
32-
Schema::dropIfExists('task_frequencies');
32+
Schema::dropIfExists(config('totem.table_prefix').'task_frequencies');
3333
}
3434
}

database/migrations/2017_08_05_201914_create_task_results_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateTaskResultsTable extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::create('task_results', function (Blueprint $table) {
16+
Schema::create(config('totem.table_prefix').'task_results', function (Blueprint $table) {
1717
$table->increments('id');
1818
$table->unsignedInteger('task_id');
1919
$table->timestamp('ran_at')->useCurrent();
@@ -30,6 +30,6 @@ public function up()
3030
*/
3131
public function down()
3232
{
33-
Schema::dropIfExists('task_results');
33+
Schema::dropIfExists(config('totem.table_prefix').'task_results');
3434
}
3535
}

database/migrations/2017_08_24_085132_create_frequency_parameters_table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CreateFrequencyParametersTable extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::create('frequency_parameters', function (Blueprint $table) {
16+
Schema::create(config('totem.table_prefix').'frequency_parameters', function (Blueprint $table) {
1717
$table->increments('id');
1818
$table->unsignedInteger('frequency_id');
1919
$table->string('name');
@@ -29,6 +29,6 @@ public function up()
2929
*/
3030
public function down()
3131
{
32-
Schema::dropIfExists('frequency_parameters');
32+
Schema::dropIfExists(config('totem.table_prefix').'frequency_parameters');
3333
}
3434
}

database/migrations/2017_08_26_083622_alter_tasks_table_add_notifications_fields.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AlterTasksTableAddNotificationsFields extends Migration
1313
*/
1414
public function up()
1515
{
16-
Schema::table('tasks', function (Blueprint $table) {
16+
Schema::table(config('totem.table_prefix').'tasks', function (Blueprint $table) {
1717
$table->string('notification_phone_number')->nullable()->after('notification_email_address');
1818
$table->string('notification_slack_webhook')->nullable()->after('notification_phone_number');
1919
});
@@ -26,11 +26,11 @@ public function up()
2626
*/
2727
public function down()
2828
{
29-
Schema::table('tasks', function (Blueprint $table) {
29+
Schema::table(config('totem.table_prefix').'tasks', function (Blueprint $table) {
3030
$table->dropColumn('notification_phone_number');
3131
});
3232

33-
Schema::table('tasks', function (Blueprint $table) {
33+
Schema::table(config('totem.table_prefix').'tasks', function (Blueprint $table) {
3434
$table->dropColumn('notification_slack_webhook');
3535
});
3636
}

resources/views/tasks/index.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
<span class="uk-float-right uk-hidden@s uk-text-muted">Command</span>
3737
</td>
3838
<td>
39-
{{ $task->results->count() > 0 ? number_format( $task->results->sum('duration') / (1000 * $task->results->count()) , 2) : '0' }} seconds
39+
{{ number_format( $task->averageRuntime / 1000 , 2 ) }} seconds
4040
<span class="uk-float-right uk-hidden@s uk-text-muted">Avg. Runtime</span>
4141
</td>
42-
@if($last = $task->results->last())
42+
@if($last = $task->lastResult)
4343
<td>
4444
{{$last->ran_at->toDateTimeString()}}
4545
<span class="uk-float-right uk-hidden@s uk-text-muted">Last Run</span>

src/Frequency.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
namespace Studio\Totem;
44

55
use Studio\Totem\Traits\HasParameters;
6-
use Illuminate\Database\Eloquent\Model;
76

8-
class Frequency extends Model
7+
class Frequency extends TotemModel
98
{
109
use HasParameters;
1110

0 commit comments

Comments
 (0)