Procházet zdrojové kódy

added admin for ref source in Storage object source

Piotr Labudda před 8 roky
rodič
revize
e68705c98f
1 změnil soubory, kde provedl 117 přidání a 8 odebrání
  1. 117 8
      SE/se-lib/Route/Storage.php

+ 117 - 8
SE/se-lib/Route/Storage.php

@@ -694,6 +694,67 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 		try {
 			$namespace = V::get('namespace', '', $_GET);
 			if (empty($namespace)) throw new Exception("Missing param namespace");
+
+			if ('setFieldRefConfig' === V::get('_postTask', '', $_POST)) {
+				$field = V::get('field', '', $_POST);
+				$source = V::get('source', '', $_POST);
+				switch ($source) {
+					case 'view':
+						$refSelect = ACL::generateRefSelectSqlByFlatRelationCache($namespace, $field);
+						ACL::setRefSource($namespace, $field, 'view', $refSelect);
+						break;
+					case 'table': ACL::setRefSource($namespace, $field, 'table'); break;
+				}
+			}
+			if ('preview' === V::get('_postTask', '', $_POST)) {
+				try {
+					$item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
+					$localFields = array_filter($item['field'], function ($field) {
+						return $field['isLocal'];
+					});
+					$refFields = array_filter($item['field'], function ($field) {
+						return 'ref:' === substr($field['xsdType'], 0, 4);
+					});
+					$activeRefFields = array_filter($refFields, function ($field) {
+						$refNamespace = str_replace(['__x3A__', ':'], '/', substr($field['xsdType'], strlen('ref:')));
+						return (1 == DB::getPDO()->fetchValue("
+							select t.isObjectActive
+							from `CRM_#CACHE_ACL_OBJECT` t
+							where t.`namespace` = '{$refNamespace}'
+						"));
+					});
+					$query = [ 'cols' => array_merge(
+						array_map(
+							function ($field) {
+								return $field['fieldNamespace'];
+							}, $localFields
+						),
+						array_map(
+							function ($field) {
+								return "{$field['fieldNamespace']}/*";
+							}, $activeRefFields
+						)
+					) ];
+					DBG::nicePrint($item, '$item');
+					DBG::nicePrint($refFields, '$refFields');
+					DBG::nicePrint($query, '$query');
+
+					// $refTableCom = ACL::getRefTable('default_db/BI_audit_KRS/BI_audit_KRS', 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company');
+					// $refTablePer = ACL::getRefTable('default_db/BI_audit_KRS/BI_audit_KRS', 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person');
+					// echo UI::h('pre', [], "
+					// 	Tabela `{$refTableCom}`: 'default_db/BI_audit_KRS/BI_audit_KRS' ref do 'default_db__x3A__BI_audit_KRS_company:BI_audit_KRS_company'
+					// 	Tablea `{$refTablePer}`: 'default_db/BI_audit_KRS/BI_audit_KRS' ref do 'default_db__x3A__BI_audit_KRS_person:BI_audit_KRS_person'
+					// ");
+					$krsItems = ACL::getAclByNamespace($namespace)->buildQuery($query)->getItems([
+						'limit' => 3
+					]);
+					DBG::nicePrint($krsItems, '$krsItems - limit 10');
+				} catch (Exception $e) {
+					DBG::log($e);
+					UI::alert('danger', $e->getMessage());
+				}
+			}
+
 			$item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
 			usort($item['field'], function ($a, $b) {
 				if ($a['fieldNamespace'] > $b['fieldNamespace']) return 1;
@@ -702,28 +763,68 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 			});
 			$thisGetLink = array($this, 'getLink');
 			{ // not installed ref
-				$notInstalled = array_filter($item['field'], function ($field) {
+				$refFields = array_filter($item['field'], function ($field) {
 					return 'ref:' === substr($field['xsdType'], 0, 4);
 				});
 				UI::table([
 					'caption' => UI::h('span', [], "Obiekty powiązane (TODO backRef)"),
 					'rows' => array_map(function ($field) use ($thisGetLink) {
-						$ns = str_replace(['__x3A__', ':'], '/', substr($field['xsdType'], strlen('ref:')));
+						$refNamespace = str_replace(['__x3A__', ':'], '/', substr($field['xsdType'], strlen('ref:')));
 						$isInstalled = (1 == DB::getPDO()->fetchValue("
 							select t.isObjectActive
 							from `CRM_#CACHE_ACL_OBJECT` t
-							where t.`namespace` = '{$ns}'
+							where t.`namespace` = '{$refNamespace}'
 						"));
+						$refSource = null;
+						if ($isInstalled) {
+							try {
+								$refTable = ACL::getRefTable($field['objectNamespace'], $field['fieldNamespace']);
+								DBG::log($refTable, 'array', "getRefTable('{$field['objectNamespace']}', '{$field['fieldNamespace']}')");
+								$refSource = ACL::getRefSource($field['objectNamespace'], $field['fieldNamespace']);
+								DBG::log($refSource, 'array', "ACL::getRefSource('{$field['objectNamespace']}', '{$field['fieldNamespace']}')");
+							} catch (Exception $e) {
+								DBG::log($e);
+							}
+						}
 						return [
 							'fieldName' => $field['fieldNamespace'],
-							'xsdType' => $field['xsdType'],
-							'reinstall' => UI::h('a', [
+							// 'xsdType' => $field['xsdType'], // always === "ref:{$field['fieldNamespace']}"
+							'ref object' => UI::h('a', [
 								'class' => "btn btn-xs btn-link",
-								'href' => $thisGetLink('objectStruct', [ 'namespace' => $ns ])
-							], "objectStruct ({$ns})"),
+								'href' => $thisGetLink('objectStruct', [ 'namespace' => $refNamespace ])
+							], "objectStruct ({$refNamespace})"),
+							'ref source' => UI::h('div', [],
+								(null === $refSource)
+								? [ "ref object not installed" ] // TODO: link to install? is table struct
+								: [
+										// UI::hButtonAjax("Tabela ref", "setFieldRefConfig", [
+										// 	'class' => "btn btn-xs btn-default" . ( 'table' === $refSource ? ' disabled' : '' ),
+										// 	'href' => $thisGetLink('setFieldRefConfig'),
+										// 	'data' => [ 'namespace' => $refNamespace, 'field' => $field['fieldNamespace'], 'do' => 'table' ]
+										// ]),
+										// UI::hButtonAjax("Widok (cache)", "setFieldRefConfig", [
+										// 	'title' => "Według flat_relation_cache",
+										// 	'class' => "btn btn-xs btn-default" . ( 'view' === $refSource ? ' disabled' : '' ),
+										// 	'href' => $thisGetLink('setFieldRefConfig'),
+										// 	'data' => [ 'namespace' => $refNamespace, 'field' => $field['fieldNamespace'], 'do' => 'view' ]
+										// ]),
+										UI::hButtonPost("Tabela ref", [
+											'title' => "Według wygenerowanej tabeli REF",
+											'class' => "btn btn-xs btn-default" . ( 'table' === $refSource ? ' disabled' : '' ),
+											// 'href' => $thisGetLink('setFieldRefConfig'),
+											'data' => [ 'namespace' => $refNamespace, 'field' => $field['fieldNamespace'], '_postTask' => 'setFieldRefConfig', 'source' => 'table' ]
+										]),
+										UI::hButtonPost("Widok (cache)", [
+											'title' => "Według flat_relation_cache",
+											'class' => "btn btn-xs btn-default" . ( 'view' === $refSource ? ' disabled' : '' ),
+											// 'href' => $thisGetLink('setFieldRefConfig'),
+											'data' => [ 'namespace' => $refNamespace, 'field' => $field['fieldNamespace'], '_postTask' => 'setFieldRefConfig', 'source' => 'view' ]
+										]),
+									]
+							),
 							'@class' => ($isInstalled) ? "success" : "danger",
 						]; // TODO: link to install object
-					}, $notInstalled)
+					}, $refFields)
 				]);
 			}
 			UI::table([
@@ -787,6 +888,14 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 						'class' => 'btn btn-link', 'style' => "color:#f00",
 						'title' => "Zainstaluje ponownie obiekt"
 					], "reinstall object"),
+					'   ',
+					UI::hButtonPost("(podgląd)", [
+						'data' => [
+							'_postTask' => 'preview'
+						],
+						'class' => 'btn btn-link', 'style' => "color:#bbb",
+						'title' => "Podgląd kilku ostatnich obiektów"
+					]),
 				]),
 				'rows' => array_map(function ($field) use ($item, $thisGetLink) {
 					$tblItem = []; foreach ($field as $k => $v) $tblItem[$k] = $v;