Skip to content

Commit

Permalink
Merge branch 'add-column-options' into alpha
Browse files Browse the repository at this point in the history
re #551
  • Loading branch information
henrywhitaker3 committed Apr 10, 2021
2 parents 0b593e6 + 9870aeb commit 39b3637
Show file tree
Hide file tree
Showing 15 changed files with 26,186 additions and 989 deletions.
52 changes: 52 additions & 0 deletions app/Casts/CommaSeparatedArrayCast.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace App\Casts;

use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

class CommaSeparatedArrayCast implements CastsAttributes
{
/**
* Array of settings that should be cast
*/
private array $shouldCast = [
'visible_columns',
'hidden_columns',
];

/**
* Cast the given value.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
* @return mixed
*/
public function get($model, $key, $value, $attributes)
{
if (!in_array($model->name, $this->shouldCast)) {
return $value;
}

return explode(',', $value);
}

/**
* Prepare the given value for storage.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
* @return mixed
*/
public function set($model, $key, $value, $attributes)
{
if (!in_array($model->name, $this->shouldCast)) {
return $value;
}

return implode(',', $value);
}
}
4 changes: 4 additions & 0 deletions app/Helpers/SettingsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ public static function getConfig()
'telegram_bot_token' => SettingsHelper::settingIsEditable('telegram_bot_token'),
'telegram_chat_id' => SettingsHelper::settingIsEditable('telegram_chat_id'),
],
'tables' => [
'visible_columns' => SettingsHelper::get('visible_columns')->value,
'hidden_columns' => SettingsHelper::get('hidden_columns')->value,
],
'auth' => (bool)SettingsHelper::get('auth')->value
];
}
Expand Down
5 changes: 5 additions & 0 deletions app/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App;

use App\Casts\CommaSeparatedArrayCast;
use App\Helpers\SettingsHelper;
use Illuminate\Database\Eloquent\Model;

Expand All @@ -17,4 +18,8 @@ class Setting extends Model
];

protected $table = 'settings';

protected $casts = [
'value' => CommaSeparatedArrayCast::class,
];
}
4 changes: 4 additions & 0 deletions changelog.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"1.11.1": [
{
"description": "Add option to show/hide columns in the all tests table.",
"link": ""
},
{
"description": "Add option to delete failed tests.",
"link": ""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use App\Helpers\SettingsHelper;
use App\Setting;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddVisibleColumnsSetting extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!SettingsHelper::get('visible_columns')) {
Setting::create([
'name' => 'visible_columns',
'value' => 'id,created_at,download,upload,ping',
'description' => 'Choose and order the columns shown in the "All Tests" table.'
]);
}
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Setting::whereIn('name', [
'visible_columns',
])->delete();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use App\Helpers\SettingsHelper;
use App\Setting;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddHiddenColumnsSetting extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!SettingsHelper::get('hidden_columns')) {
Setting::create([
'name' => 'hidden_columns',
'value' => 'server_id,server_name,server_host,url,scheduled',
'description' => 'Columns hidden from the "All Tests" table.'
]);
}
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Setting::whereIn('name', [
'hidden_columns',
])->delete();
}
}
Loading

0 comments on commit 39b3637

Please sign in to comment.