Skip to content

Commit

Permalink
editable field, update with primary key other than id (MedicOneSystem…
Browse files Browse the repository at this point in the history
…s#282)

* wip

* Apply fixes from StyleCI (MedicOneSystems#281)

Co-authored-by: Mark Salmon <[email protected]>

Co-authored-by: Mark Salmon <[email protected]>
  • Loading branch information
marksalmon and marksalmon authored Sep 9, 2021
1 parent 5196394 commit ecd2d29
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":[],"times":{"Mediconesystems\\LivewireDatatables\\Tests\\ColumnSetTest::it_can_generate_an_array_of_columns_from_a_model":0.269,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnSetTest::it_can_correctly_populate_the_columns_from_the_model with data set #0":0.015,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnSetTest::it_can_correctly_populate_the_columns_from_the_model with data set #1":0.014,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnSetTest::it_can_correctly_populate_the_columns_from_the_model with data set #2":0.012,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnSetTest::it_can_correctly_populate_the_columns_from_the_model with data set #3":0.011,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnSetTest::it_can_correctly_populate_the_columns_from_the_model with data set #4":0.012,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnSetTest::it_can_correctly_populate_the_columns_from_the_model with data set #5":0.012,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnSetTest::it_can_correctly_populate_the_columns_from_the_model with data set #6":0.011,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnSetTest::it_can_correctly_populate_the_columns_from_the_model with data set #7":0.014,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnSetTest::it_can_exclude_columns":0.016,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnSetTest::it_can_include_columns":0.012,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnSetTest::it_can_rename_columns":0.012,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnTest::it_can_generate_a_column_from_a_table_column":0.011,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnTest::it_can_generate_a_column_from_a_scope":0.012,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnTest::it_can_generate_a_delete_column":0.011,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnTest::it_sets_properties_and_parameters with data set #0":0.011,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnTest::it_sets_properties_and_parameters with data set #1":0.012,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnTest::it_sets_properties_and_parameters with data set #2":0.011,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnTest::it_sets_properties_and_parameters with data set #3":0.011,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnTest::it_sets_properties_and_parameters with data set #4":0.012,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnTest::it_returns_an_array_from_column":0.014,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnTest::it_returns_an_array_from_raw":0.013,"Mediconesystems\\LivewireDatatables\\Tests\\ColumnTest::it_returns_width_property_from_column":0.013,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableClassTest::it_can_mount_using_the_class":0.089,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableClassTest::it_can_set_a_default_sort":0.02,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableClassTest::it_can_show_and_hide_a_column":0.043,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableClassTest::it_can_order_results":0.015,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableClassTest::it_can_filter_results_based_on_text":0.028,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableClassTest::it_can_filter_results_based_on_boolean":0.025,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableClassTest::it_can_filter_strings_as_a_boolean":0.028,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableClassTest::it_can_filter_results_based_on_selects":0.026,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableClassTest::it_can_filter_results_based_on_numbers":0.062,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableQueryBuilderTest::it_creates_a_query_builder_for_base_columns":0.014,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableQueryBuilderTest::it_creates_a_query_builder_for_has_one_relation_columns":0.014,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableQueryBuilderTest::it_creates_a_where_query_for_a_has_one_column":0.013,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableQueryBuilderTest::it_creates_a_query_builder_for_has_many_relation_columns":0.015,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableQueryBuilderTest::it_creates_a_query_builder_for_has_many_relation_column_with_specific_aggregate":0.014,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableQueryBuilderTest::it_creates_a_where_query_for_has_many_relation_columns":0.014,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableQueryBuilderTest::it_creates_a_query_builder_for_belongs_to_relation_columns":0.019,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableQueryBuilderTest::it_creates_a_where_query_for_belongs_to_relation_columns":0.015,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableQueryBuilderTest::it_creates_a_query_builder_for_belongs_to_many_relation_columns":0.017,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableQueryBuilderTest::it_creates_a__where_query_for_belongs_to_many_relation_columns":0.013,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableTemplateTest::it_can_mount_from_the_default_template_with_a_model":0.018,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableTemplateTest::the_header_can_be_hidden_with_a_property":0.016,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableTemplateTest::the_pagination_bar_can_be_hidden_with_a_property":0.017,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableTemplateTest::it_can_set_per_page_with_a_property":0.023,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableTemplateTest::it_can_include_columns_from_a_property":0.016,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableTemplateTest::it_can_exclude_columns_from_a_property":0.017,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableTemplateTest::it_can_hide_columns_from_a_property":0.02,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableTemplateTest::it_can_mark_columns_for_date_format_from_a_property":0.018,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableTemplateTest::it_can_mark_columns_for_time_format_from_a_property":0.019,"Mediconesystems\\LivewireDatatables\\Tests\\LivewireDatatableTemplateTest::it_can_set_sort_from_a_property":0.019,"Mediconesystems\\LivewireDatatables\\Tests\\MakeDatatableCommandTest::component_is_created_by_make_command":0.02,"Mediconesystems\\LivewireDatatables\\Tests\\MakeDatatableCommandTest::dot_nested_component_is_created_by_make_command":0.014,"Mediconesystems\\LivewireDatatables\\Tests\\MakeDatatableCommandTest::forward_slash_nested_component_is_created_by_make_command":0.016,"Mediconesystems\\LivewireDatatables\\Tests\\MakeDatatableCommandTest::multiword_component_is_created_by_make_command":0.017,"Mediconesystems\\LivewireDatatables\\Tests\\MakeDatatableCommandTest::pascal_case_component_is_automatically_converted_by_make_command":0.014,"Mediconesystems\\LivewireDatatables\\Tests\\MakeDatatableCommandTest::snake_case_component_is_automatically_converted_by_make_command":0.014,"Mediconesystems\\LivewireDatatables\\Tests\\MakeDatatableCommandTest::snake_case_component_is_automatically_converted_by_make_command_on_nested_component":0.018,"Mediconesystems\\LivewireDatatables\\Tests\\MakeDatatableCommandTest::new_component_model_name_matches_option":0.015,"Mediconesystems\\LivewireDatatables\\Tests\\MakeDatatableCommandTest::a_component_is_not_created_with_a_reserved_class_name":0.012}}
2 changes: 1 addition & 1 deletion resources/views/livewire/datatables/editable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
x-on:click="edit = true; $nextTick(() => { $refs.input.focus() })">{!! htmlspecialchars($value) !!}</button>
<span x-cloak x-show="edit">
<input class="border-blue-400 px-2 py-1 -mx-2 -my-1 rounded focus:outline-none focus:border" x-ref="input" value="{!! htmlspecialchars($value) !!}"
wire:change="edited($event.target.value, '{{ $table }}', '{{ $column }}', '{{ $rowId }}')"
wire:change="edited($event.target.value, '{{ $key }}', '{{ $column }}', '{{ $rowId }}')"
x-on:click.away="edit = false" x-on:blur="edit = false" x-on:keydown.enter="edit = false" />
</span>
</div>
2 changes: 1 addition & 1 deletion src/Http/Livewire/LivewireDatatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ public function mapCallbacks($paginatedCollection, $export = false)
} elseif (isset($this->editables[$name])) {
$row->$name = view('datatables::editable', [
'value' => $value,
'table' => $this->builder()->getModel()->getTable(),
'key' => $this->builder()->getModel()->getQualifiedKeyName(),
'column' => Str::after($name, '.'),
'rowId' => $row->{$this->builder()->getModel()->getTable() . '.' . $this->builder()->getModel()->getKeyName()} ?? $row->{$this->builder()->getModel()->getKeyName()},
]);
Expand Down
7 changes: 4 additions & 3 deletions src/Traits/WithCallbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace Mediconesystems\LivewireDatatables\Traits;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

trait WithCallbacks
{
public function edited($value, $table, $column, $rowId)
public function edited($value, $key, $column, $rowId)
{
DB::table($table)
->where('id', $rowId)
DB::table(Str::before($key, '.'))
->where(Str::after($key, '.'), $rowId)
->update([$column => $value]);

$this->emit('fieldEdited', $rowId);
Expand Down

0 comments on commit ecd2d29

Please sign in to comment.