-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'add-column-options' into alpha
re #551
- Loading branch information
Showing
15 changed files
with
26,186 additions
and
989 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
database/migrations/2021_04_10_082758_add_visible_columns_setting.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
database/migrations/2021_04_10_102320_add_hidden_columns_setting.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.