diff --git a/app/Casts/CommaSeparatedArrayCast.php b/app/Casts/CommaSeparatedArrayCast.php new file mode 100644 index 00000000..c8331835 --- /dev/null +++ b/app/Casts/CommaSeparatedArrayCast.php @@ -0,0 +1,51 @@ +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); + } +} diff --git a/app/Helpers/SettingsHelper.php b/app/Helpers/SettingsHelper.php index 1ff03877..a314f4d9 100644 --- a/app/Helpers/SettingsHelper.php +++ b/app/Helpers/SettingsHelper.php @@ -168,6 +168,9 @@ class SettingsHelper 'telegram_bot_token' => SettingsHelper::settingIsEditable('telegram_bot_token'), 'telegram_chat_id' => SettingsHelper::settingIsEditable('telegram_chat_id'), ], + 'tables' => [ + 'visible_columns' => SettingsHelper::get('visible_columns')->value, + ], 'auth' => (bool)SettingsHelper::get('auth')->value ]; } diff --git a/app/Setting.php b/app/Setting.php index 78c78765..075fa304 100644 --- a/app/Setting.php +++ b/app/Setting.php @@ -2,6 +2,7 @@ namespace App; +use App\Casts\CommaSeparatedArrayCast; use App\Helpers\SettingsHelper; use Illuminate\Database\Eloquent\Model; @@ -17,4 +18,8 @@ class Setting extends Model ]; protected $table = 'settings'; + + protected $casts = [ + 'value' => CommaSeparatedArrayCast::class, + ]; } diff --git a/database/migrations/2021_04_10_082758_add_visible_columns_setting.php b/database/migrations/2021_04_10_082758_add_visible_columns_setting.php new file mode 100644 index 00000000..4d17b3dc --- /dev/null +++ b/database/migrations/2021_04_10_082758_add_visible_columns_setting.php @@ -0,0 +1,38 @@ + 'visible_columns', + 'value' => 'id,created_at,download,upload,ping', + 'description' => 'Columns visible in the "All Tests" table.' + ]); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Setting::whereIn('name', [ + 'visible_columns', + ])->delete(); + } +} diff --git a/resources/js/components/Graphics/TableRow.js b/resources/js/components/Graphics/TableRow.js index 30180892..4e1f9d44 100644 --- a/resources/js/components/Graphics/TableRow.js +++ b/resources/js/components/Graphics/TableRow.js @@ -47,18 +47,62 @@ export default class TableRow extends Component { this.toggleShow(); } + getDataFields = () => { + let allFields = this.props.allFields; + let data = this.state.data; + let processedFields = []; + + for(var key in allFields) { + let field = allFields[key]; + + let value = data[key]; + + if(field.type === 'date') { + value = new Date(value).toLocaleString(); + } else if(field.type === 'bool') { + value = Boolean(value) ? field.if_true : field.if_false + } + + let final = { + name: key, + key: field.alias, + value: value, + type: field.type + }; + + processedFields.push(final); + } + + let visible = []; + let inModal = []; + + window.config.tables.visible_columns.forEach(column => { + visible.push(processedFields.find(x => x.name == column)); + }); + + inModal = processedFields.filter(el => { + return !visible.includes(el); + }); + + return { + visible: visible, + modal: inModal + }; + } + render() { var e = this.state.data; var show = this.state.show; + var fields = this.getDataFields(); if(e.failed != true) { return (
Server ID: {e.server_id}
-Name: {e.server_name}
-Host: {e.server_host}
-URL: Speedtest.net
- {e.scheduled != undefined && -Type: {e.scheduled == true ? 'scheduled' : 'manual'}
- } + {fields.modal.map((e, i) => { + if(e.type === 'url') { + return ( +{e.key}: Speedtest.net
+ ); + } else { + return ( +{e.key}: {e.value}
+ ); + } + })}| ID | -Time | -Download (Mbit/s) | -Upload (Mbit/s) | -Ping (ms) | + {window.config.tables.visible_columns.map((e, i) => { + return ( +{allFields[e].alias} | + ); + })}More |
|---|