Fix validFrom, validTo in result table

This commit is contained in:
2024-07-13 16:38:43 +02:00
parent 4b89c9578c
commit 3f177efca4
2 changed files with 64 additions and 11 deletions

View File

@@ -5,7 +5,7 @@ namespace App\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use JsonMachine\Items; use JsonMachine\Items;
use JsonMachine\JsonDecoder\PassThruDecoder; use Illuminate\Support\Facades\DB;
class Import extends Command class Import extends Command
{ {
@@ -16,6 +16,7 @@ class Import extends Command
*/ */
protected $signature = 'import {dir}'; protected $signature = 'import {dir}';
protected $RpoTree;
/** /**
* The console command description. * The console command description.
* *
@@ -23,13 +24,19 @@ class Import extends Command
*/ */
protected $description = 'Import data from gzipped backup init files'; protected $description = 'Import data from gzipped backup init files';
public function transformItem($item)
{
return $item;
}
public function ImportToDB($dir, $files) public function ImportToDB($dir, $files)
{ {
foreach ($files as $file) { foreach ($files as $file) {
$stream = gzopen($dir.'/'.$file,'rb'); $stream = gzopen($dir.'/'.$file,'rb');
$items = Items::fromStream($stream, ['pointer' => '/results']); $items = Items::fromStream($stream, ['pointer' => '/results']);
foreach ($items as $item) { foreach ($items as $item) {
dd($item); $item = $this->transformItem($item);
DB::table('data')->insert($item);
} }
} }
} }
@@ -55,6 +62,8 @@ class Import extends Command
$files = explode(PHP_EOL, File::get($file)); $files = explode(PHP_EOL, File::get($file));
$this->RpoTree = json_decode(File::get(resource_path('js/Data/RpoTree.json')));
$this->ImportToDB($dir, $files); $this->ImportToDB($dir, $files);
} }
} }

View File

@@ -24,13 +24,34 @@ const columns = [
field: 'translated', field: 'translated',
sortable: false, sortable: false,
}, },
{ name: 'val', align: 'left', label: 'Hodnota', field: 'val', sortable: false }, {
name: 'val',
align: 'left',
label: 'Hodnota',
field: 'val',
sortable: false
},
{
name: 'validFrom',
aling: 'left',
label: 'Platne od',
field: 'vlaidFrom',
sortable: true,
},
{
name: 'validTo',
aling: 'left',
label: 'Platne do',
field: 'vlaidTo',
sortable: true,
}
] ]
const arrData = computed(() => Object.keys(props.data)); const arrData = computed(() => Object.keys(props.data));
const title = ref(props.data["fullNames"][0]["value"]); const numTitles = props.data["fullNames"].length;
const title = ref(props.data["fullNames"][numTitles-1]["value"]);
console.log('TITLE', title); console.log('TITLE', title);
function keyTitle(key) { function keyTitle(key) {
@@ -69,20 +90,37 @@ function createRPOflatList(resultTree, flatList, RpoTree, lastKey = undefined, l
console.log('RESTREE=', resultTree); console.log('RESTREE=', resultTree);
let fullPath = [...fullPathRpo]; let fullPath = [...fullPathRpo];
if (lastKey != undefined) fullPath.push(lastKey); if (lastKey != undefined) fullPath.push(lastKey);
var validFrom = undefined;
var validTo = undefined;
if (checkValueType(resultTree) == "object") {
Object.keys(resultTree).forEach(k => {
if (k == "validFrom") validFrom = resultTree[k];
if (k == "validTo") validTo = resultTree[k];
});
}
if (level == 0 || checkValueType(resultTree) == "object") { if (level == 0 || checkValueType(resultTree) == "object") {
let i = 0; let i = 0;
Object.keys(resultTree).forEach(k => { Object.keys(resultTree).forEach(k => {
if (typeof resultTree[k] != 'string') { if (typeof resultTree[k] != 'string') {
if (RpoTree[k] !== undefined) { if (RpoTree[k] !== undefined) {
flatList.push({ "level": level, "key": k, "val": undefined, "translated": RpoTree[k].desc, "full": fullPath.join(' => '), "index": i++ }); if (k != "validFrom" && k != "validTo") {
console.log("VF VT ",validFrom,validTo);
flatList.push({ "level": level, "key": k, "val": undefined, "translated": RpoTree[k].desc, "full": fullPath.join(' => '), "index": i++, "validFrom": validFrom , "validTo": validTo });
createRPOflatList(resultTree[k], flatList, RpoTree[k], k, level + 1, fullPath); createRPOflatList(resultTree[k], flatList, RpoTree[k], k, level + 1, fullPath);
} }
}
} else { } else {
console.log('RT=', RpoTree); console.log('RT=', RpoTree);
console.log('K=', k); console.log('K=', k);
if (RpoTree[k] !== undefined) if (RpoTree[k] !== undefined) {
flatList.push({ "level": level, "key": k, "val": resultTree[k], "translated": RpoTree[k].desc, "full": fullPath.join(' => '), "index": i++ }); if (k != "validFrom" && k != "validTo")
flatList.push({ "level": level, "key": k, "val": resultTree[k], "translated": RpoTree[k].desc, "full": fullPath.join(' => '), "index": i++, "validFrom": validFrom , "validTo": validTo });
}
} }
}); });
} else if (checkValueType(resultTree) == "array") { } else if (checkValueType(resultTree) == "array") {
@@ -93,7 +131,7 @@ function createRPOflatList(resultTree, flatList, RpoTree, lastKey = undefined, l
createRPOflatList(e, flatList, RpoTree, lastKey, level + 1, fullPath); createRPOflatList(e, flatList, RpoTree, lastKey, level + 1, fullPath);
} else { } else {
console.log('RT=', RpoTree); console.log('RT=', RpoTree);
flatList.push({ "level": level, "key": lastKey, "val": e, "translated": RpoTree.desc !== undefined ? RpoTree.desc : '', "full": fullPath.join(' => '), "index": i++ }); flatList.push({ "level": level, "key": lastKey, "val": e, "translated": RpoTree.desc !== undefined ? RpoTree.desc : '', "full": fullPath.join(' => '), "index": i++, "vaildFrom": validFrom , "validTo": validTo != undefined ? validTo : null });
} }
} }
} }
@@ -113,8 +151,8 @@ console.log('FLAT=', flatListRpo);
<template> <template>
<!-- https://github.com/quasarframework/quasar/blob/dev/docs/src/examples/QTable/VirtscrollExpandedRow.vue --> <!-- https://github.com/quasarframework/quasar/blob/dev/docs/src/examples/QTable/VirtscrollExpandedRow.vue -->
<div class="col q-pa-md" style="overflow: auto;"> <div class="col q-pa-md" style="overflow: auto;">
<q-table style="height: 700px;" separator="cell" flat bordered dense :rows-per-page-options="[0]" <q-table style="height: 700px;" separator="cell" flat bordered dense :rows-per-page-options="[0]" :title="title"
:title="title" :rows="flatListRpo" :columns="columns" wrap-cells card-class="bg-deep-purple-7 text-white" :rows="flatListRpo" :columns="columns" wrap-cells card-class="bg-deep-purple-7 text-white"
table-header-class="bg-deep-purple-1 text-black" row-key="name"> table-header-class="bg-deep-purple-1 text-black" row-key="name">
<template v-slot:body="props"> <template v-slot:body="props">
@@ -125,6 +163,12 @@ console.log('FLAT=', flatListRpo);
<q-td class="bg-grey-6"> <q-td class="bg-grey-6">
<div class="text-left">{{ props.row.val }}</div> <div class="text-left">{{ props.row.val }}</div>
</q-td> </q-td>
<q-td class="bg-grey-5">
<div class="text-left">{{ props.row.validFrom }}</div>
</q-td>
<q-td class="bg-grey-5">
<div class="text-left">{{ props.row.validTo }}</div>
</q-td>
</q-tr> </q-tr>
</template> </template>
</q-table> </q-table>