Skip to content

Commit

Permalink
Merge pull request #415 from tdt/development
Browse files Browse the repository at this point in the history
Add original csv file when an ES datasource is configured with a know…
  • Loading branch information
coreation authored Oct 9, 2016
2 parents 2ec5908 + 35e7045 commit ef111d8
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/Tdt/Core/Formatters/HTMLFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function getBody($dataObj)
if (!empty($dataObj->source_definition)) {
$type = $dataObj->source_definition['type'];

// Check if other views need to be served
// Check if other views need to be served
switch ($type) {
case 'XLS':
case 'CSV':
Expand Down
53 changes: 53 additions & 0 deletions app/Tdt/Core/Repositories/ElasticsearchDefinitionRepository.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Tdt\Core\Repositories;

use Tdt\Core\Repositories\Interfaces\ElasticsearchDefinitionRepositoryInterface;
use Load\Elasticsearch;

class ElasticsearchDefinitionRepository extends BaseDefinitionRepository implements ElasticsearchDefinitionRepositoryInterface
{
Expand All @@ -26,6 +27,58 @@ public function getAllParameters()
return array_merge($this->getCreateParameters());
}

public function update($model_id, array $input)
{
// Process input (e.g. set default values to empty properties)
$input = $this->processInput($input);

$model_object = $this->model->find($model_id);

// Validation has been done, lets create the models
$input = array_only($input, array_keys($this->getCreateParameters()));

$input = $this->addOriginalFile($input);

$model_object->update($input);

return $model_object->toArray();
}

/**
* Check if we can get the original file by looking for the passed index and document type
* in the jobs (CSV is only supported for now to be a computed original file field)
*
* @param array $input
* @return array
*/
private function addOriginalFile($input)
{
$es_job = Elasticsearch::where('es_index', $input['es_index'])
->where('es_type', $input['es_type'])
->where('host', $input['host'])
->first();

if (! empty($es_job)) {
$extractor = $es_job->job->extractor()->first();

if (strtolower($extractor->type) == 'csv') {
$input['original_file'] = $extractor->uri;
}
}

return $input;
}

public function store(array $input)
{
// Process input (e.g. set default values to empty properties)
$input = $this->processInput($input);

$input = $this->addOriginalFile($input);

return $this->model->create(array_only($input, array_keys($this->getCreateParameters())));
}

/**
* Return the properties (= column fields) for this model.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddOriginalCsvFileToEsDatasource extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('elasticsearchdefinitions', function ($table) {
$table->string('original_file', 255);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('elasticsearchdefinitions', function ($table) {
$table->dropColumn('original_file');
});
}
}
1 change: 1 addition & 0 deletions app/lang/en/htmlview.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
"publisher" => "Publisher",
"keywords" => "Keywords",
"spatial" => "Geographic context",
"original_file" => "Original file",
];
1 change: 1 addition & 0 deletions app/lang/fr/htmlview.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
"contact" => "Contact",
"publisher" => "Editeur",
"keywords" => "mot-clés",
"original_file" => "Fichier d'origine",
];
1 change: 1 addition & 0 deletions app/lang/nl/htmlview.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
"publisher" => "Uitgever",
"keywords" => "Trefwoorden",
"spatial" => "Geografische context",
"original_file" => "Origineel bestand",
];
2 changes: 1 addition & 1 deletion app/models/sourcetypes/ElasticsearchDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ class ElasticsearchDefinition extends SourceType
{
protected $table = 'elasticsearchdefinitions';

protected $fillable = array('host', 'es_type', 'es_index', 'port', 'username', 'password', 'description', 'title');
protected $fillable = array('host', 'es_type', 'es_index', 'port', 'username', 'password', 'description', 'title', 'original_file');
}
10 changes: 9 additions & 1 deletion app/views/dataset/partials/details.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@
</p>
</li>
@endif
@if(!empty($source_definition['original_file']) && substr($source_definition['original_file'], 0, 4) == 'http')
<li class="list-group-item">
<h5 class="list-group-item-heading">{{ trans('htmlview.original_file') }}</h5>
<p class="list-group-item-text">
<a href="{{ $source_definition['original_file'] }}"><b>Download</b></a>
</p>
</li>
@endif
@if(!empty($definition['spatial']))
<li class="list-group-item">
<h5 class="list-group-item-heading">{{ trans('htmlview.spatial') }}</h5>
Expand All @@ -94,7 +102,7 @@
<script type="text/javascript" src='{{ asset("js/leaflet.min.js", Config::get('ssl_enabled')) }}'></script>
<script type="text/javascript" src='{{ asset("js/n3-browser.min.js", Config::get('ssl_enabled')) }}'></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('DOMContentLoaded', function() {
var geo = {{json_encode($definition['spatial']['geometry'], JSON_PRETTY_PRINT)}};
showGeoJsonMap(JSON.parse(geo.geometry));
});
Expand Down

0 comments on commit ef111d8

Please sign in to comment.