PHRAS-3406_classification-field-centric_MASTER

fix : new ux "field" centric
fix : black dlgbox
This commit is contained in:
jygaulier
2021-03-25 18:29:48 +01:00
parent 45cc756e40
commit f819833d4f
20 changed files with 578 additions and 469 deletions

View File

@@ -46,12 +46,10 @@ class ThesaurusController extends Controller
// twig parameters
$twp = [
'error' => null,
// 'dlg_level' => $request->get('dlg_level'),
// 'lst' => $records->serializedList(),
// 'records' => $recRefs,
'dlg_level' => $request->get('dlg_level'),
'received_cnt' => $records->received()->count(),
'rejected_cnt' => $records->rejected()->count(),
'up_paths' => [],
'by_fields' => [],
];
// find which field(s) can be updated, that is what tbranches are linked to a parent of the term
@@ -67,13 +65,16 @@ class ThesaurusController extends Controller
throw new Exception("error fetching th");
}
$upPaths = [];
$xpath = new DOMXPath($domth);
$fields = [];
foreach ($dbox->get_meta_structure() as $field) {
if($field->is_readonly() || !$field->get_gui_editable()) {
continue;
}
if (!($q = $field->get_tbranch())) {
continue;
}
$roots = $xpath->query($q); // linked nodes for this field
$q = '(' . $q . ')//sy[@id=\'' . $tx_term_id . '\']'; // can we find the term under the tbranch(es) ?
// normally we should find only one linked parent, since we search from a unique term
@@ -85,73 +86,96 @@ class ThesaurusController extends Controller
// going up, we decide to stop at the first link (B) (easier)
if (($droppedSy = $xpath->query($q))->length > 0) {
// yes (and since the query targets a unique id, there is only one result)
// yes this field is linked to a branch that contains the term
// since the query targets a unique id, there is only one result
$droppedSy = $droppedSy->item(0);
/** @var DOMElement $droppedSy */
$droppedlng = $droppedSy->getAttribute('lng'); // the lng of the dropped term is prefered
$values = [];
// go from the sy upto a linked branch (possibly multiples if the field is linked to many branches)
$ok = true; // == the term (level up-to top) can populate the current field
for ($te = $droppedSy->parentNode; $te->nodeType === XML_ELEMENT_NODE; $te = $te->parentNode) {
$depth = 0; // 0 for dropped-on level, will decrease while going up
$selectedValue = null;
for ($te = $droppedSy->parentNode; $te->nodeType === XML_ELEMENT_NODE; $te = $te->parentNode, $depth--) {
/** @var DOMElement $te */
$teid = $te->getAttribute('id');
for ($i = 0; $i < $roots->length; $i++) {
if ($te->isSameNode($roots->item($i))) {
$ok = false; // we met the link point, upmost terms are not "values" anymore
// we hit the link point, upmost terms are not "values" anymore
break 2; // no need to go higher
}
}
if ($ok) { // acceptable value for the current field
if (!array_key_exists($teid, $upPaths)) {
$upPaths[$teid] = [
'synonyms' => [],
'fields' => []
];
// get all the sy so the user can choose which is prefered
$preferedId = null;
foreach ($te->childNodes as $sy) {
if ($sy->nodeName != 'sy') {
continue; // skip 'te' children
}
$lng = $sy->getAttribute('lng');
$id = $sy->getAttribute('id');
$s = [
// here acceptable value for the current field
if($depth === 0) {
//
// dropped-on level : we accept the exact term (not searching synonyms)
//
$selectedValue = [
'value' => $droppedSy->getAttribute('v'),
'lng' => $droppedlng,
'selected' => true
];
$values[$droppedSy->getAttribute('id')] = $selectedValue;
}
else {
//
// upper level : get all the sy so the user can choose which is prefered
//
// first, see if at least one sy is matching the lng
$lngFound = false;
foreach ($te->childNodes as $sy) {
if ($sy->nodeName == 'sy' && $sy->getAttribute('lng') == $droppedlng) {
$lngFound = true;
break;
}
}
// then rescan sy to add to the values
foreach ($te->childNodes as $sy) {
if ($sy->nodeName != 'sy') {
continue; // skip 'te' children
}
$lng = $sy->getAttribute('lng');
if (!$lngFound || $lng == $droppedlng) {
$values[$sy->getAttribute('id')] = [
'value' => $sy->getAttribute('v'),
'lng' => $lng,
'selected' => false
'selected' => $sy->isSameNode($droppedSy)
];
// this sy is prefered if...
if ($sy->getAttribute('lng') === $droppedlng) {
$preferedId = $id; // ... it has the same lng as the dropped
}
if ($sy->isSameNode($droppedSy)) {
$preferedId = $id; // ... better : it was the dropped target
}
$upPaths[$teid]['synonyms'][$id] = $s;
}
if ($preferedId) {
$upPaths[$teid]['synonyms'][$preferedId]['selected'] = true;
}
}
$upPaths[$teid]['fields'][$field->get_id()] = $field;
}
}
$twp['up_paths'] = array_reverse($upPaths);
$twp['fields'][] = $field;
// $field->
if(!empty($values)) {
$fields[$field->get_name()] = [
'field' => $field,
'values' => array_reverse($values),
'selected_value' => $selectedValue,
];
}
}
}
if (empty($upPaths)) {
if(empty($fields)) {
// no fields (could happen if one drops on a top-level branch, or if the th is not linked, or...)
throw new Exception("this branch is not linked");
}
$twp['by_fields'] = $fields;
}
catch (Exception $e) {
$twp['error'] = $e->getMessage();
}
$zzz = $this->render('prod/Thesaurus/droppedrecords.html.twig', $twp);
return $this->app->json([
'dlg_title' => sprintf("editing %s record(s)", $records->received()->count()),
'dlg_content' => $this->render('prod/Thesaurus/droppedrecords.html.twig', $twp),