Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/OpenSkill/Datatable/Views/DatatableView.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class DatatableView
/** @var Repository The repository responsible for the config value resolution */
private $configRepository;

/** @var string the URL for the endpoint */
private $endpointURL = '/';

/**
* DatatableView constructor, will take a view as a string if a custom one should be used. will also take the
* column configurations to provide out of the box headers for the view.
Expand Down Expand Up @@ -120,6 +123,17 @@ public function headers()
return $this;
}

/**
* Sets the endpoint URL that will be passed to templates when rendering html & scripts.
* @param $endpoint_url
* @return $this
*/
public function endpoint($endpoint_url)
{
$this->endpointURL = $endpoint_url;
return $this;
}

/**
* Will set the columns for the view
* @param string $columnName The name of the column
Expand Down Expand Up @@ -158,7 +172,8 @@ public function table()
->make($this->tableView, [
'columns' => $this->columns,
'showHeaders' => $this->printHeaders,
'id' => $this->tableId
'id' => $this->tableId,
'endpoint' => $this->endpointURL,
])
->render();
}
Expand All @@ -179,6 +194,7 @@ public function script()
'columns' => $this->columns,
'options' => $this->scriptOptions,
'callbacks' => $this->scriptCallbacks,
'endpoint' => $this->endpointURL,
])
->render();
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/datatable110.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
oTable = jQuery('#{{ $id }}').DataTable({
"processing": true,
"serverSide": true,
"ajax": "{{ isset($options['route']) ? $options['route'] : '/' }}",
"ajax": "{{ $endpoint }}",
"columns": [
@foreach($columns as $name => $label)
{ 'data': '{{ $name }}' },
Expand Down
2 changes: 1 addition & 1 deletion src/views/datatable19.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
oTable = jQuery('#{{ $id }}').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "{{ isset($options['route']) ? $options['route'] : '/' }}",
"sAjaxSource": "{{ $endpoint }}",
"aoColumns": [
@foreach($columns as $name => $label)
{ 'mData': '{{ $name }}' },
Expand Down
44 changes: 42 additions & 2 deletions tests/OpenSkill/Datatable/Views/DatatableViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function testId()
'columns' => ['id' => 'id'],
'showHeaders' => false,
'id' => 123,
'endpoint' => '/'
]
])
->times(1)
Expand All @@ -119,6 +120,7 @@ public function testOption()
'fooBar1' => ['fooBar']
],
'callbacks' => [],
'endpoint' => '/'
]
])
->times(1)
Expand All @@ -143,6 +145,7 @@ public function testCallback()
'fooBar' => 'fooBar',
'fooBar1' => ['fooBar']
],
'endpoint' => '/'
]
])
->times(1)
Expand All @@ -163,7 +166,8 @@ public function testHeaders()
'columns' => ['id' => 'id'],
'showHeaders' => true,
'id' => 'fooBar',
]
'endpoint' => '/'
],
])
->times(1)
->andReturn($this->view);
Expand All @@ -185,7 +189,8 @@ public function testColumns()
],
'showHeaders' => false,
'id' => 'fooBar',
]
'endpoint' => '/'
],
])
->times(1)
->andReturn($this->view);
Expand All @@ -201,6 +206,7 @@ public function testColumns()
],
'options' => [],
'callbacks' => [],
'endpoint' => '/'
]
])
->times(1)
Expand All @@ -212,6 +218,40 @@ public function testColumns()
$this->dtv2->html();
}

public function testEndpoint()
{
$this->viewFactory->shouldReceive('make')
->withArgs([
'fooTable',
[
'columns' => ['id' => 'id'],
'showHeaders' => false,
'id' => 'fooBar',
'endpoint' => '/test/endpoint/gets/set'
],
])
->times(1)
->andReturn($this->view);

$this->viewFactory->shouldReceive('make')
->withArgs([
'fooScript',
[
'id' => 'fooBar',
'columns' => ['id' => 'id'],
'options' => [],
'callbacks' => [],
'endpoint' => '/test/endpoint/gets/set'
]
])
->times(1)
->andReturn($this->view);


$this->dtv2->endpoint('/test/endpoint/gets/set');
$this->dtv2->html();
}

/**
* @expectedException \InvalidArgumentException
*/
Expand Down