Skip to content

Commit

Permalink
[#21] Litteraturkritikk: Add korrekturstatus
Browse files Browse the repository at this point in the history
  • Loading branch information
danmichaelo committed Oct 13, 2019
1 parent 1ffcbe8 commit c24b61a
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 24 deletions.
64 changes: 54 additions & 10 deletions app/Litteraturkritikk/LitteraturkritikkSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ class LitteraturkritikkSchema extends Schema
'operators' => ['eq', 'neq'],
]
],

// Sist endret
[
'key' => 'updated_at',
'type' => 'simple',
'editable' => false,
'searchable' => 'disabled',

'columnClassName' => 'dt-body-nowrap',
],
],

'groups' => [
Expand Down Expand Up @@ -332,6 +322,60 @@ class LitteraturkritikkSchema extends Schema
],
],
],

// Posten
[
'label' => 'Databaseposten',

'fields' => [

// Opprettet
[
'key' => 'created_at',
'type' => 'simple',
'editable' => false,
'searchable' => 'disabled',

'columnClassName' => 'dt-body-nowrap',
],

// Sist endret
[
'key' => 'updated_at',
'type' => 'simple',
'editable' => false,
'searchable' => 'disabled',

'columnClassName' => 'dt-body-nowrap',
],

// Korrekturstatus
[
'key' => 'korrekturstatus',
'type' => 'enum',
'values' => [
['id' => 1, 'label' => 'Ikke korrekturlest'],
['id' => 2, 'label' => 'Må korrekturleses mot fysisk materiale'],
['id' => 3, 'label' => 'Korrekturlest mot fysisk materiale'],
['id' => 4, 'label' => 'Korrekturlest og lenket til digitalt materiale'],
],
'searchOptions' => [
'operators' => ['ex']
],
'columnClassName' => 'dt-body-nowrap',
],

// Slettet
[
'key' => 'deleted_at',
'type' => 'simple',
'editable' => false,
'searchable' => 'disabled',

'columnClassName' => 'dt-body-nowrap',
],
]
],
],
];

Expand Down
142 changes: 142 additions & 0 deletions database/migrations/2019_10_13_171731_add_korrekturstatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php

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

class AddKorrekturstatus extends Migration
{
protected function dropView()
{
DB::unprepared('DROP MATERIALIZED VIEW litteraturkritikk_records_search');

}

protected function recreateView()
{
DB::unprepared("
CREATE MATERIALIZED VIEW litteraturkritikk_records_search AS
SELECT
r.*,
SUBSTR(TRIM(dato),1,4) AS dato_numeric,
-- Flat representasjon for tabellvisning
STRING_AGG(DISTINCT forfatter.etternavn_fornavn, '; ') AS verk_forfatter,
STRING_AGG(DISTINCT kritiker.etternavn_fornavn, '; ') AS kritiker,
STRING_AGG(DISTINCT forfatter.kjonn, '; ') AS forfatter_kjonn,
STRING_AGG(DISTINCT kritiker.kjonn, '; ') AS kritiker_kjonn,
-- Søkeindeks 'any_field_ts'
TO_TSVECTOR('simple', r.id::text)
|| TO_TSVECTOR('simple', COALESCE(r.tittel, ''))
|| TO_TSVECTOR('simple', COALESCE(r.publikasjon, ''))
|| TO_TSVECTOR('simple', COALESCE(r.dato, ''))
|| TO_TSVECTOR('simple', COALESCE(r.bind, ''))
|| TO_TSVECTOR('simple', COALESCE(r.hefte, ''))
|| TO_TSVECTOR('simple', COALESCE(r.sidetall, ''))
|| TO_TSVECTOR('simple', COALESCE(r.kommentar, ''))
|| TO_TSVECTOR('simple', COALESCE(r.utgivelseskommentar, ''))
|| TO_TSVECTOR('simple', COALESCE(r.verk_tittel, ''))
|| TO_TSVECTOR('simple', COALESCE(r.verk_dato, ''))
|| TO_TSVECTOR('simple', COALESCE(r.verk_kommentar, ''))
|| TO_TSVECTOR('simple', COALESCE(STRING_AGG(person_pivot.kommentar, ' '), ''))
|| TO_TSVECTOR('simple', COALESCE(STRING_AGG(person_pivot.pseudonym, ' '), ''))
|| TO_TSVECTOR('simple', COALESCE(STRING_AGG(person.etternavn, ' '), ''))
|| TO_TSVECTOR('simple', COALESCE(STRING_AGG(person.fornavn, ' '), ''))
AS any_field_ts,
-- Søkeindeks 'verk_tittel_ts'
TO_TSVECTOR('simple', COALESCE(r.verk_tittel, ''))
AS verk_tittel_ts,
-- Søkeindeks 'forfatter_ts'.
TO_TSVECTOR('simple', COALESCE(STRING_AGG(DISTINCT forfatter.etternavn_fornavn, ' '), ''))
|| TO_TSVECTOR('simple', COALESCE(STRING_AGG(DISTINCT forfatter.fornavn_etternavn, ' '), ''))
|| TO_TSVECTOR('simple', COALESCE(STRING_AGG(DISTINCT forfatter_pivot.pseudonym, ' '), ''))
AS forfatter_ts,
-- Søkeindeks 'kritiker_ts'
TO_TSVECTOR('simple', COALESCE(STRING_AGG(DISTINCT kritiker.etternavn_fornavn, ' '), ''))
|| TO_TSVECTOR('simple', COALESCE(STRING_AGG(DISTINCT kritiker.fornavn_etternavn, ' '), ''))
|| TO_TSVECTOR('simple', COALESCE(STRING_AGG(DISTINCT kritiker_pivot.pseudonym, ' '), ''))
AS kritiker_ts,
-- Søkeindeks 'person_ts'
TO_TSVECTOR('simple', COALESCE(STRING_AGG(DISTINCT person.etternavn_fornavn, ' '), ''))
|| TO_TSVECTOR('simple', COALESCE(STRING_AGG(DISTINCT person.fornavn_etternavn, ' '), ''))
|| TO_TSVECTOR('simple', COALESCE(STRING_AGG(DISTINCT person_pivot.pseudonym, ' '), ''))
AS person_ts
FROM litteraturkritikk_records AS r
-- person
LEFT JOIN litteraturkritikk_record_person AS person_pivot
ON r.id = person_pivot.record_id
LEFT JOIN litteraturkritikk_personer_view AS person
ON person.id = person_pivot.person_id
-- kritiker
LEFT JOIN litteraturkritikk_record_person AS kritiker_pivot
ON r.id = kritiker_pivot.record_id
AND kritiker_pivot.person_role = 'kritiker'
LEFT JOIN litteraturkritikk_personer_view AS kritiker
ON kritiker.id = kritiker_pivot.person_id
-- forfatter
LEFT JOIN litteraturkritikk_record_person AS forfatter_pivot
ON forfatter_pivot.record_id = r.id
AND forfatter_pivot.person_role != 'kritiker'
LEFT JOIN litteraturkritikk_personer_view AS forfatter
ON forfatter.id = forfatter_pivot.person_id
GROUP BY r.id
");

DB::unprepared('CREATE UNIQUE INDEX litteraturkritikk_records_search_id ON litteraturkritikk_records_search (id)');
DB::unprepared('CREATE INDEX litteraturkritikk_any_field_ts_idx ON litteraturkritikk_records_search USING gin(any_field_ts)');
DB::unprepared('CREATE INDEX litteraturkritikk_forfatter_ts_idx ON litteraturkritikk_records_search USING gin(forfatter_ts)');
DB::unprepared('CREATE INDEX litteraturkritikk_kritiker_ts_idx ON litteraturkritikk_records_search USING gin(kritiker_ts)');
DB::unprepared('CREATE INDEX litteraturkritikk_person_ts_idx ON litteraturkritikk_records_search USING gin(person_ts)');

Schema::table('litteraturkritikk_records_search', function ($view) {
$view->index('publikasjon');
$view->index('verk_sjanger');
$view->index('kritikktype');
$view->index('spraak');
});
}

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$this->dropView();
Schema::table('litteraturkritikk_records', function (Blueprint $table) {
$table->tinyInteger('korrekturstatus')->default(1);
});
$this->recreateView();
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$this->dropView();
Schema::table('litteraturkritikk_records', function (Blueprint $table) {
$table->dropColumn('korrekturstatus');
});
$this->recreateView();
}
}
2 changes: 2 additions & 0 deletions resources/lang/nb/litteraturkritikk.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
'id' => 'ID',
'created_at' => 'Opprettet',
'updated_at' => 'Sist endret',
'deleted_at' => 'Slettet',
'korrekturstatus' => 'Korrekturstatus',
'q' => 'Alle felt',
'person' => 'Person (forfatter, kritiker e.a.)',

Expand Down
33 changes: 19 additions & 14 deletions resources/views/litteraturkritikk/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
Vis fulltekst ({{ $n + 1 }})
</a>
@endforeach
@else
@elseif ($group->label != 'Databaseposten')
<a href="https://www.nb.no/search?{{ $record->nationalLibrarySearchLink($group->label) }}" class="btn btn-outline-success btn-sm">
<em class="fa fa-search"></em>
Søk etter fulltekst i NB
Expand Down Expand Up @@ -121,10 +121,28 @@
<a href="{{ $url }}">{{ $url }}</a><br>
@endforeach

@elseif ($field->type == 'enum')

{{ $field->formatValue($record->{$field->key}) }}

@elseif (is_array($record->{$field->key}))

{{ implode(', ', $record->{$field->key}) }}

@elseif ($field->key == 'created_at')

{{ $record->{$field->key} }}
av {{ $record->createdBy ? $record->createdBy->name : ' (import)' }}

@elseif ($field->key == 'updated_at')

{{ $record->{$field->key} }}
av {{ $record->updatedBy ? $record->updatedBy->name : ' (import)' }}

@elseif ($field->key == 'deleted_at')

{{ $record->{$field->key} ?: 'Nei' }}

@else

{{ $record->{$field->key} }}
Expand All @@ -138,19 +156,6 @@

@endforeach

@if (Auth::check())
<h4 class="mt-4">Metadata</h4>
<dl class="row">
<dt class="col-sm-3 text-sm-right">Opprettet:</dt>
<dd class="col-sm-9">{{ $record->created_at }} av {{ $record->createdBy ? $record->createdBy->name : ' (import)' }}</dd>
<dt class="col-sm-3 text-sm-right">Sist endret:</dt>
<dd class="col-sm-9">{{ $record->updated_at }} av {{ $record->updatedBy ? $record->updatedBy->name : ' (import)' }}</dd>
@if ($record->deleted_at)
<dt class="col-sm-3 text-sm-right">Slettet:</dt>
<dd class="col-sm-9">{{ $record->deleted_at }}</dd>
@endif
</dl>
@endif
</div>

</div>
Expand Down

0 comments on commit c24b61a

Please sign in to comment.