From 4312da2f0023df7047173111c85281a563d4c13d Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sat, 21 Dec 2024 00:25:27 -0500 Subject: [PATCH] support instance previews delivered from .NET OMS --- .../src/mocha-php/lib/mocha/core/Oms.inc.php | 10 +++++++++ .../lib/mocha/oms/HttpOmsClient.inc.php | 8 ++++++- .../ui/renderers/html/HTMLRenderer2.inc.php | 11 +++++++++- .../src/mocha-php/scripts/mcx-moniker.js | 21 ++++++++++++++++++- .../ui/pages/RelatedTaskListPage.phpx.php | 9 ++++++-- 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/mocha-php/src/mocha-php/lib/mocha/core/Oms.inc.php b/mocha-php/src/mocha-php/lib/mocha/core/Oms.inc.php index b5ed6c0..6717580 100644 --- a/mocha-php/src/mocha-php/lib/mocha/core/Oms.inc.php +++ b/mocha-php/src/mocha-php/lib/mocha/core/Oms.inc.php @@ -109,6 +109,11 @@ */ public abstract function getInstanceByGlobalIdentifier(UUID|string $inst) : ?InstanceReference; + /** + * Gets the instance with the specified instance key. + */ + public abstract function getInstanceByKey(InstanceKey $inst) : ?InstanceReference; + /** * Indices are 1-based */ @@ -487,6 +492,11 @@ } + public function getInstancePreview(InstanceReference $inst) : array + { + return [ ]; + } + public function getRelatedTasks(InstanceReference $inst) { $instParent = $this->getParentClass($inst); diff --git a/mocha-php/src/mocha-php/lib/mocha/oms/HttpOmsClient.inc.php b/mocha-php/src/mocha-php/lib/mocha/oms/HttpOmsClient.inc.php index 9d031b5..612e76b 100644 --- a/mocha-php/src/mocha-php/lib/mocha/oms/HttpOmsClient.inc.php +++ b/mocha-php/src/mocha-php/lib/mocha/oms/HttpOmsClient.inc.php @@ -347,6 +347,12 @@ return null; } + public function getInstancePreview(InstanceReference $inst) : array + { + $json = $this->curl_request_json("/tenants/" . $this->getTenantName() . "/instances/" . $inst->GlobalIdentifier->__toString() . "/preview"); + return $json; + } + public function getResponse($element) { $json = $this->curl_request_json("/tenants/" . $this->getTenantName() . "/instances/" . $element->InstanceKey . "/element"); @@ -356,7 +362,7 @@ /** * Gets the instance with the specified instance key. */ - public function getInstanceByKey(InstanceKey|string $key) : ?InstanceReference + public function getInstanceByKey(InstanceKey $key) : ?InstanceReference { $result = $this->curl_request_json("/tenants/" . $this->getTenantName() . "/instances/" . $key); return new InstanceReference(null, InstanceKey::parse($result["iid"]), UUID::parse($result["globalIdentifier"])); diff --git a/mocha-php/src/mocha-php/lib/mocha/ui/renderers/html/HTMLRenderer2.inc.php b/mocha-php/src/mocha-php/lib/mocha/ui/renderers/html/HTMLRenderer2.inc.php index ca714d9..f87186e 100644 --- a/mocha-php/src/mocha-php/lib/mocha/ui/renderers/html/HTMLRenderer2.inc.php +++ b/mocha-php/src/mocha-php/lib/mocha/ui/renderers/html/HTMLRenderer2.inc.php @@ -79,7 +79,16 @@ public function renderResponse(array $json) { - $this->renderBeginPage("Test App"); + $title = ""; + if (array_key_exists("title", $json)) + { + if (array_key_exists("label", $json["title"])) + { + $title = $json["title"]["label"]; + } + } + + $this->renderBeginPage($title); $this->renderBeginContent(); $this->renderFragment($json); diff --git a/mocha-php/src/mocha-php/scripts/mcx-moniker.js b/mocha-php/src/mocha-php/scripts/mcx-moniker.js index a64ce37..9f00e56 100644 --- a/mocha-php/src/mocha-php/scripts/mcx-moniker.js +++ b/mocha-php/src/mocha-php/scripts/mcx-moniker.js @@ -1,3 +1,21 @@ +function flattenUri(uri) +{ + var strUri = uri; + var strUriParts = strUri.split('/'); + var strUriParts2 = [ ]; + for (var i = 0; i < strUriParts.length; i++) + { + strUriParts2.push(strUriParts[i]); + if (i == 1) + { + strUriParts2.push('d'); + } + } + strUri = strUriParts2.join("/"); + strUri = strUri + ".htmld"; + return strUri; +} + function McxMoniker(parentElement) { this.ParentElement = parentElement; @@ -242,7 +260,8 @@ function McxMoniker(parentElement) li2.className = "uwt-menu-item-command uwt-visible"; var a2 = document.createElement("a"); - a2.href = tgsecondary.uri; + + a2.href = flattenUri(tgsecondary.uri); var span2 = document.createElement("span"); span2.className = "uwt-title"; diff --git a/mocha-php/src/mocha-php/ui/pages/RelatedTaskListPage.phpx.php b/mocha-php/src/mocha-php/ui/pages/RelatedTaskListPage.phpx.php index 69d3bc4..251bbb1 100644 --- a/mocha-php/src/mocha-php/ui/pages/RelatedTaskListPage.phpx.php +++ b/mocha-php/src/mocha-php/ui/pages/RelatedTaskListPage.phpx.php @@ -135,7 +135,6 @@ protected function OnRendering(RenderingEventArgs $re) { - /** @var \Mocha\Oms\MySQLDatabaseOMS */ $oms = mocha_get_oms(); if ($oms->getCurrentUser() === null) @@ -159,6 +158,9 @@ $inst = $oms->getInstanceByKey(InstanceKey::parse($iid)); $instParent = $oms->getParentClass($inst); + $jsonPreview = $oms->getInstancePreview($inst); + + /* $tasks = $oms->getRelatedTasks($inst); $taskGroupsDefs = [ ]; @@ -197,6 +199,9 @@ "title" => $oms->getInstanceText($inst) ) ); + */ + $json = $jsonPreview["relatedTasks"]; + /* $previewElement = $oms->getRelatedInstance($instParent, KnownRelationshipGuids::Class__uses_preview__Executable_returning_Element); if ($previewElement !== null) @@ -208,7 +213,7 @@ $previewContent = $r->renderElementAsString($parentECs, $previewElement, [ $oms->getInstanceByGlobalIdentifier(KnownInstanceGuids::DisplayOption__Singular), $oms->getInstanceByGlobalIdentifier(KnownInstanceGuids::DisplayOption__ShowSubelementsVertically) ], true); $json["preview"] = $previewContent; } - + */ $json["result"] = "success";