diff --git a/mocha-php/src/mocha-php/include/mochacommon.inc.php b/mocha-php/src/mocha-php/include/mochacommon.inc.php index 19019f9..0798d8d 100644 --- a/mocha-php/src/mocha-php/include/mochacommon.inc.php +++ b/mocha-php/src/mocha-php/include/mochacommon.inc.php @@ -101,12 +101,15 @@ function mocha_get_current_user() : ?InstanceReference if ($currentTenant !== null) { - if (isset($_SESSION["user_token_" . $currentTenant->ID])) + if (isset($_SESSION["user_token_" . System::GetTenantName()])) { // SELECT FROM `Users` WHERE `Token` = $_SESSION["user_token"] + + //! FIXME: this still results in loads of (tiny) HTTP calls to the OMS + // replace with: /tenants/super/instances?4$223=...&4$215=... $insts = $oms->getInstancesOfByAttributes(KnownClassGuids::UserLogin, array ( - KnownAttributeGuids::Token => $_SESSION["user_token_" . $currentTenant->ID] + KnownAttributeGuids::Token => $_SESSION["user_token_" . System::GetTenantName()] )); $currentUser = null; diff --git a/mocha-php/src/mocha-php/lib/mocha/core/InstanceKey.inc.php b/mocha-php/src/mocha-php/lib/mocha/core/InstanceKey.inc.php index f589d98..c5e0360 100644 --- a/mocha-php/src/mocha-php/lib/mocha/core/InstanceKey.inc.php +++ b/mocha-php/src/mocha-php/lib/mocha/core/InstanceKey.inc.php @@ -5,23 +5,39 @@ { public $ClassIndex; public $InstanceIndex; + public $IsDerived; - public function __construct(int $class_id, int $inst_id) + public function __construct(int $class_id, int $inst_id, bool $isDerived = false) { $this->ClassIndex = $class_id; $this->InstanceIndex = $inst_id; + $this->IsDerived = $isDerived; } public static function Parse(?string $instanceKeyStr) : ?InstanceKey { if ($instanceKeyStr !== null) { - $split = explode("$", $instanceKeyStr); - if (count($split) == 2) + $sep = null; + $isDerived = false; + if (str_contains($instanceKeyStr, '$')) { - if (is_numeric($split[0]) && is_numeric($split[1])) + $sep = '$'; + } + else if (str_contains($instanceKeyStr, '!')) + { + $sep = '!'; + $isDerived = true; + } + if ($sep != null) + { + $split = explode($sep, $instanceKeyStr); + if (count($split) == 2) { - return new InstanceKey(intval($split[0]), intval($split[1])); + if (is_numeric($split[0]) && is_numeric($split[1])) + { + return new InstanceKey(intval($split[0]), intval($split[1]), $isDerived); + } } } } diff --git a/mocha-php/src/mocha-php/lib/mocha/core/InstanceReference.inc.php b/mocha-php/src/mocha-php/lib/mocha/core/InstanceReference.inc.php index faaffbc..6a9a98e 100644 --- a/mocha-php/src/mocha-php/lib/mocha/core/InstanceReference.inc.php +++ b/mocha-php/src/mocha-php/lib/mocha/core/InstanceReference.inc.php @@ -14,6 +14,18 @@ public ?int $DatabaseId; public InstanceKey|null $InstanceKey; public UUID|null $GlobalIdentifier; + public string|null $Text; + public InstanceReference|null $DefaultTask; + public string|null $DefaultTaskUrl; + public InstanceReference|null $ParentClass; + + public static function parse(array|null $obj) : InstanceReference|null + { + if ($obj == null) + return null; + + return new InstanceReference(null, InstanceKey::parse($obj["iid"]), UUID::parse($obj["globalIdentifier"]), $obj["text"], InstanceReference::parse($obj["parentClass"]["defaultTask"]), InstanceReference::parse($obj["parentClass"])); + } public static function toInstanceKeys(array $instanceReferences) : array { @@ -25,7 +37,7 @@ return $keys; } - public function __construct(?int $databaseId, InstanceKey|null $instanceKey, UUID|string|null $globalIdentifier) + public function __construct(?int $databaseId, InstanceKey|null $instanceKey, UUID|string|null $globalIdentifier, string|null $text = null, InstanceReference|string|null $defaultTaskOrUrl = null, InstanceReference|null $parentClass = null) { //$this->OMS = $oms; $this->DatabaseId = $databaseId; @@ -36,6 +48,19 @@ $globalIdentifier = UUID::parse($globalIdentifier); } $this->GlobalIdentifier = $globalIdentifier; + $this->Text = $text; + + if (is_string($defaultTaskOrUrl)) + { + $this->DefaultTaskUrl = $defaultTaskOrUrl; + $this->DefaultTask = null; + } + else + { + $this->DefaultTask = $defaultTaskOrUrl; + $this->DefaultTaskUrl = null; + } + $this->ParentClass = $parentClass; } /* diff --git a/mocha-php/src/mocha-php/lib/mocha/core/KnownRelationshipGuids.inc.php b/mocha-php/src/mocha-php/lib/mocha/core/KnownRelationshipGuids.inc.php index 4dc1136..a441803 100644 --- a/mocha-php/src/mocha-php/lib/mocha/core/KnownRelationshipGuids.inc.php +++ b/mocha-php/src/mocha-php/lib/mocha/core/KnownRelationshipGuids.inc.php @@ -255,6 +255,7 @@ class KnownRelationshipGuids const Instance__for__Element_Content = "c3959f84248d4edea3f2f262917c7b56"; const Element_Content__has__Layout = "1ab7412005ea4acab6d3c7e0133e0c4f"; + const Element_Content__has__EC_Dynamic_Display_Option = "{4a41391a-c325-4182-920a-a94ad28c15fa}"; const EC_Dynamic_Display_Option__modifies__Element_Content = "{4d091643-2bfc-4b83-b3e4-8a3b22c665a9}"; 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 358bff1..b5ed6c0 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 @@ -192,7 +192,6 @@ */ public function getParentClass(InstanceReference $inst) : ?InstanceReference { - $gid = $inst->GlobalIdentifier->__toString(); $forClass = $this->getRelatedInstance($inst, $this->getInstanceByGlobalIdentifier(KnownRelationshipGuids::Instance__for__Class)); return $forClass; } @@ -964,9 +963,14 @@ return new OmsContext(); } - public function isConnected() + public function isConnected() : bool { return true; } + + public function processElement(InstanceReference $element, array $values) : array | bool + { + return false; + } } ?> \ No newline at end of file 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 d031458..c8fb9f5 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 @@ -56,9 +56,10 @@ { //trigger_error("curl_request for url " . $relativeUrl); $curl = $this->curl_new($relativeUrl); + \curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-Forwarded-For:" . $_SERVER["REMOTE_ADDR"])); if ($method == HttpRequestMethod::POST) { - trigger_error("POST " . $relativeUrl); + //trigger_error("POST " . $relativeUrl); \curl_setopt($curl, CURLOPT_POST, true); if ($data !== null) { @@ -70,7 +71,7 @@ { if ($dataFormat == HttpPostDataFormat::URLENCODED) { - trigger_error("POST(" . count($data) . ") " . http_build_query2($data)); + //trigger_error("POST(" . count($data) . ") " . http_build_query2($data)); \curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query2($data)); } else @@ -196,9 +197,54 @@ return $insts2; } + public function search(string $query, array | InstanceReference | null $parentClasses = null, string | null $m = null) : array | bool + { + $uri = "/tenants/super/instances?"; + + if ($m != null) + { + $uri .= "m=" . urlencode($m) . "&"; + } + $uri .= "q=" . urlencode($query); + if (is_array($parentClasses)) + { + for ($i = 0; $i < count($parentClasses); $i++) + { + $uri .= "&parentClassIid=" . $parentClasses[$i]->InstanceKey->__toString(); + } + } + else if ($parentClasses instanceof InstanceReference) + { + $uri .= "&parentClassIid=" . $parentClasses->InstanceKey->__toString(); + } + + $json = $this->curl_request_json($uri, HttpRequestMethod::GET); + return $json; + } public function getInstancesOfByAttributes(array|InstanceKey|InstanceReference|string|null $parentClass, array $parms) { $parentClass = $this->normalizeInstanceReference($parentClass); + $data = array(); + foreach ($parms as $k => $v) + { + $data[$this->normalizeInstanceReference($k)->GlobalIdentifier->__toString()] = $v; + } + + $insts2 = array(); + $url = "/tenants/" . $this->getTenantName() . "/instances"; + if ($parentClass !== null) + { + $url .= "?parentClassIid=" . $parentClass->GlobalIdentifier; + } + $json = $this->curl_request_json($url, HttpRequestMethod::POST, $data); + foreach ($json["instances"] as $inst) + { + $insts2[] = new InstanceReference(null, InstanceKey::parse($inst["iid"]), UUID::parse($inst["globalIdentifier"])); + } + return $insts2; + + /* + // FIXME: NOT IMPLEMENTED //usage: // getInstanceByAttributes (array ( getInstanceByGlobalIdentifier(NAME_ATTRIBUTE) => "zq-developer" )) @@ -227,6 +273,7 @@ } return $insts2; + */ } public function getInstanceData(array|InstanceKey|InstanceReference|string|null $inst) @@ -312,7 +359,7 @@ public function getInstanceByKey(InstanceKey|string $key) : ?InstanceReference { $result = $this->curl_request_json("/tenants/" . $this->getTenantName() . "/instances/" . $key); - return new InstanceReference(null, InstanceKey::parse($result["instanceKey"]), UUID::parse($result["globalIdentifier"])); + return new InstanceReference(null, InstanceKey::parse($result["iid"]), UUID::parse($result["globalIdentifier"])); } /** @@ -321,7 +368,7 @@ public function getInstanceByGlobalIdentifier(UUID|string $inst) : ?InstanceReference { $result = $this->curl_request_json("/tenants/" . $this->getTenantName() . "/instances/" . $inst); - return new InstanceReference(null, InstanceKey::parse($result["instanceKey"]), UUID::parse($result["globalIdentifier"])); + return new InstanceReference(null, InstanceKey::parse($result["iid"]), UUID::parse($result["globalIdentifier"])); } public function createInstanceOf(InstanceReference $classInstance) : ?InstanceReference @@ -337,6 +384,26 @@ return null; } + public function processElement(InstanceReference $element, array $values) : array | bool + { + $result = $this->curl_request_json("/tenants/" . $this->getTenantName() . "/instances/" . $element->GlobalIdentifier . "/element", HttpRequestMethod::POST, $values); + if ($result["result"] == "success") + { + return $result; + } + return false; + } + + public function getRelatedTasks(InstanceReference $inst) + { + $result = $this->curl_request_json("/tenants/" . $this->getTenantName() . "/instances/" . $inst->GlobalIdentifier . "/relatedTasks", HttpRequestMethod::GET); + if ($result["result"] == "success") + { + return $result; + } + return [ ]; + } + } ?> \ No newline at end of file diff --git a/mocha-php/src/mocha-php/lib/mocha/search/SearchHelper.inc.php b/mocha-php/src/mocha-php/lib/mocha/search/SearchHelper.inc.php index a82a153..b1a5c1a 100644 --- a/mocha-php/src/mocha-php/lib/mocha/search/SearchHelper.inc.php +++ b/mocha-php/src/mocha-php/lib/mocha/search/SearchHelper.inc.php @@ -1,11 +1,14 @@ searchSlow($q); return $this->searchIndexed($q); + */ + + $json = $this->_OMS->search($q, $this->ValidClasses, $m); + $results = array(); + + foreach ($json["instances"] as $obj) + { + $results[] = InstanceReference::parse($obj); + } + return $results; } public function searchIndexed(string $q) diff --git a/mocha-php/src/mocha-php/lib/mocha/ui/controls/InstanceBrowser.inc.php b/mocha-php/src/mocha-php/lib/mocha/ui/controls/InstanceBrowser.inc.php index b2bf81f..a352922 100644 --- a/mocha-php/src/mocha-php/lib/mocha/ui/controls/InstanceBrowser.inc.php +++ b/mocha-php/src/mocha-php/lib/mocha/ui/controls/InstanceBrowser.inc.php @@ -194,12 +194,12 @@ $li = new WebControl(); $li->TagName = "li"; - $instParent = $oms->getParentClass($inst); - $parentClassName = $oms->getInstanceText($instParent); + //$instParent = $oms->getParentClass($inst); + //$parentClassName = $oms->getInstanceText($instParent); $adw = new AdditionalDetailWidget(""); $adw->RelatedActionButtonUrl = "~/d/inst/" . $inst->InstanceKey . "/rel-tasks.htmld"; - + if (mocha_asset_exists("uic-assets", "1.1.5", "zq/icons/1$" . $inst->InstanceKey->ClassIndex . ".png") || mocha_asset_exists("uic-assets", "1.1.5", "zq/icons/1$" . $inst->InstanceKey->ClassIndex . ".svg")) { @@ -207,9 +207,9 @@ } $adw->Attributes[] = new WebControlAttribute("data-instance-id", $inst->InstanceKey); $adw->ClassList[] = "mcx-moniker"; - $adw->ClassTitle = $parentClassName; + //$adw->ClassTitle = $parentClassName; - $defaultTaskUrl = $oms->getDefaultTaskUrl($inst); + $defaultTaskUrl = $inst->DefaultTaskUrl; // $oms->getDefaultTaskUrl($inst); if ($defaultTaskUrl !== null) { $adw->TargetURL = $defaultTaskUrl; @@ -226,8 +226,13 @@ } else { - $adw->Text = $oms->getInstanceText($inst); + if ($inst->Text !== null) + { + $adw->Text = $inst->Text; + } + //$adw->Text = $oms->getInstanceText($inst); } + /* $this->MenuItems = array( 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 19fce0c..8392043 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 @@ -2,8 +2,13 @@ namespace Mocha\UI\Renderers\HTML; + use Mocha\Core\InstanceKey; + use Mocha\Core\InstanceReference; use Mocha\Core\OmsContext; + use Mocha\UI\Controls\InstanceBrowser; use Phast\System; + use Phast\WebControlAttribute; + use Phast\WebControls\AdditionalDetailWidget; class HTMLRenderer2 extends HTMLRenderer { @@ -12,6 +17,60 @@ parent::__construct($context, $withoutOms); } + public function processPostback(InstanceReference $element) : array | bool + { + /** + * @var \Mocha\Core\Oms + */ + $oms = mocha_get_oms(); + + $values = array(); + foreach ($_POST as $key => $value) + { + if (str_starts_with($key, "ec_")) + { + $fqecid = substr($key, 3); + $values[$fqecid] = $value; + } + } + + $array = $this->OMS->processElement($element, $values); + if ($array === false) + { + return false; + } + + if (is_callable($this->ProcessPostbackFunction)) + { + // call user-defined ProcessPostbackFunction + return call_user_func($this->ProcessPostbackFunction, $this, $element, $array); + } + else + { + $dummy = [ ]; + if (!$this->processRelatedPostback($dummy, $element)) + { + return false; + } + } + + if (count($this->FailedValidations) > 0) + return false; + + if ($this->DebugMode) + { + echo ("debug mode done"); + die(); + } + + if (isset($_POST["ReturnToURL"])) + { + System::Redirect($_POST["ReturnToURL"]); + return true; + } + return $array; + } + public function renderInitialElement($element) { $json = $this->OMS->getResponse($element); @@ -32,7 +91,11 @@ public function renderFragment(array $json, $fqecidPrefix = "") { + // echo ("renderFragment:
"); print_r($json); + //print_r($json); die(); $fqecid = $fqecidPrefix . $json["ecid"]; + // we do not yet know how to deal with fully-qualified ECIDs + $fqecid = $json["ecid"]; if ($json["visible"] === false) { return; @@ -42,6 +105,45 @@ { $this->renderFragment($json["body"]); } + else if ($json["widget"] == "grid") + { + echo (""); + echo (""); + echo (""); + foreach ($json["columns"] as $col) + { + if (isset($col["visible"]) && !$col["visible"]) + { + continue; + } + + echo (""); + } + echo (""); + echo (""); + echo (""); + foreach ($json["rows"] as $row) + { + echo (""); + foreach ($row["cellsMap"] as $key => $col) + { + if (isset($col["visible"]) && !$col["visible"]) + { + continue; + } + + echo (""); + } + echo (""); + } + echo (""); + echo ("
"); + echo (""); + echo ("
"); + //print_r($col); + $this->renderFragment($col); + echo ("
"); + } else if ($json["widget"] == "vbox") { echo ("
"); @@ -73,7 +175,9 @@ echo ("
"); foreach ($json["children"] as $child) { - $fqecidChild = $fqecidPrefix . $child["ecid"]; + // $fqecidChild = $fqecidPrefix . $child["ecid"]; + $fqecidChild = $child["ecid"]; + echo ("
"); echo ("
"); @@ -129,6 +237,62 @@ { echo (""); } + else if ($json["widget"] == "monikerList") + { + $adw = new InstanceBrowser(); + $adw->Attributes[] = new WebControlAttribute("data-ecid", $json["ecid"]); + if (isset($json["enabled"]) && $json["enabled"] == false) + { + $adw->Editable = false; + } + else + { + $adw->Editable = true; + } + if (isset($json["instances"]) && count($json["instances"]) > 0) + { + foreach ($json["instances"] as $json_inst) + { + if ($json_inst["widget"] == "moniker") + { + // $adw->SelectedInstances[] = $this->OMS->getInstanceByKey(InstanceKey::Parse($json_inst["instanceId"])); + $uri = $json_inst["target"]; + if ($uri == "") + { + $uri = $this->makeSelfUri($json["selfUriTemplate"]); + } + $adw->SelectedInstances[] = new InstanceReference(null, InstanceKey::Parse($json_inst["instanceId"]), null, $json_inst["text"], $uri); + } + } + } + else + { + $adw->Text = $json["text"]; + } + echo (""); + $adw->Render(); + } + } + + public function makeSelfUri(string $uriTemplate) + { + $uri_parts = explode("/", $uriTemplate); + $uri_parts2 = array(); + $i = 0; + foreach ($uri_parts as $part) + { + $uri_parts2[] = $part; + if ($i == 1) + { + $uri_parts2[] = "d"; + } + $i++; + } + $uri_parts2[count($uri_parts2) - 1] .= ".htmld"; + + return implode("/", $uri_parts2); } } diff --git a/mocha-php/src/mocha-php/scripts/mcx-instancebrowser.js b/mocha-php/src/mocha-php/scripts/mcx-instancebrowser.js index d2e2a33..aa44917 100644 --- a/mocha-php/src/mocha-php/scripts/mcx-instancebrowser.js +++ b/mocha-php/src/mocha-php/scripts/mcx-instancebrowser.js @@ -182,32 +182,34 @@ function McxInstanceBrowser(parentElement) this.NativeObject.clearSearchResults(); System.ClassList.Remove(this.NativeObject.SearchResultsElement, "mcx-placeholder-visible"); - for (var i = 0; i < json.items.length; i++) + if (typeof(json.items) !== 'undefined') { - var li = document.createElement("li"); - li.className = "uwt-menu-item uwt-menu-item-command uwt-visible"; - li.searchResult = json.items[i]; - li.NativeObject = this.NativeObject; - li.addEventListener("click", function() + for (var i = 0; i < json.items.length; i++) { - if (this.NativeObject.activateSearchResult(this.searchResult)) + var li = document.createElement("li"); + li.className = "uwt-menu-item uwt-menu-item-command uwt-visible"; + li.searchResult = json.items[i]; + li.NativeObject = this.NativeObject; + li.addEventListener("click", function() { - this.NativeObject.setEditing(false); - } - }); + if (this.NativeObject.activateSearchResult(this.searchResult)) + { + this.NativeObject.setEditing(false); + } + }); - var moniker = McxMoniker.create(json.items[i].instanceId, json.items[i].text); - /* - var span = document.createElement("span"); - span.className = "uwt-title uwt-description-empty"; - span.innerText = json.items[i].title; - li.appendChild(span); - */ - li.appendChild(moniker); + var moniker = McxMoniker.create(json.items[i].instanceId, json.items[i].text); + /* + var span = document.createElement("span"); + span.className = "uwt-title uwt-description-empty"; + span.innerText = json.items[i].title; + li.appendChild(span); + */ + li.appendChild(moniker); - this.NativeObject.SearchResultsMenuElement.appendChild(li); + this.NativeObject.SearchResultsMenuElement.appendChild(li); + } } - System.ClassList.Remove(this.NativeObject.SearchResultsElement, "uwt-loading"); } else diff --git a/mocha-php/src/mocha-php/scripts/mcx-moniker.js b/mocha-php/src/mocha-php/scripts/mcx-moniker.js index 5949f50..a64ce37 100644 --- a/mocha-php/src/mocha-php/scripts/mcx-moniker.js +++ b/mocha-php/src/mocha-php/scripts/mcx-moniker.js @@ -180,12 +180,11 @@ function McxMoniker(parentElement) xhr.thiss = this; xhr.onreadystatechange = function(e) { - var xhr = e.target; - if (xhr.readyState == 4) + if (this.readyState == 4) { - if (xhr.status == 200) + if (this.status == 200) { - var json = JSON.parse(xhr.responseText); + var json = JSON.parse(this.responseText); console.log(json); if (json.result == "failure" && json.responseCode == 403) @@ -198,20 +197,20 @@ function McxMoniker(parentElement) { if (json.instance.label) { - // xhr.thiss.setClassTitle("Return Attribute Method Binding"); - xhr.thiss.setClassTitle(json.instance.label); + // this.thiss.setClassTitle("Return Attribute Method Binding"); + this.thiss.setClassTitle(json.instance.label); } if (json.instance.title) { - // xhr.thiss.setInstanceTitle("Common Text@get Concatenated Date and Time Format (BA)*P*S(public)[ramb]"); - xhr.thiss.setInstanceTitle(json.instance.title); + // this.thiss.setInstanceTitle("Common Text@get Concatenated Date and Time Format (BA)*P*S(public)[ramb]"); + this.thiss.setInstanceTitle(json.instance.title); } } if (json.taskGroups) { - System.ClassList.Remove(xhr.thiss.ActionsMenuElement.parentElement, "uwt-empty"); + System.ClassList.Remove(this.thiss.ActionsMenuElement.parentElement, "uwt-empty"); - xhr.thiss.ActionsMenuElement.innerHTML = ""; + this.thiss.ActionsMenuElement.innerHTML = ""; for (var i = 0; i < json.taskGroups.length; i++) { var tgprimary = json.taskGroups[i].taskGroups[0]; @@ -256,7 +255,7 @@ function McxMoniker(parentElement) li.appendChild(ulMenuChild); - xhr.thiss.ActionsMenuElement.appendChild(li); + this.thiss.ActionsMenuElement.appendChild(li); } } @@ -270,17 +269,17 @@ function McxMoniker(parentElement) if (json.preview) { - xhr.thiss.PreviewContentElement.innerHTML = json.preview; + this.thiss.PreviewContentElement.innerHTML = json.preview; } - System.ClassList.Remove(xhr.thiss.PopupElement, "uwt-loading"); - xhr.thiss.ParentElement.NativeObject.UpdatePopupLocation(); + System.ClassList.Remove(this.thiss.PopupElement, "uwt-loading"); + this.thiss.ParentElement.NativeObject.UpdatePopupLocation(); } - else if (xhr.status == 403) + else if (this.status == 403) { } - else if (xhr.status == 0) + else if (this.status == 0) { Alert.show("Please check your connection and try again", "Connection lost", "uwt-color-danger", 5000); } diff --git a/mocha-php/src/mocha-php/scripts/mcx-typeaheadsearch.js b/mocha-php/src/mocha-php/scripts/mcx-typeaheadsearch.js index 37b4e8f..fea6232 100644 --- a/mocha-php/src/mocha-php/scripts/mcx-typeaheadsearch.js +++ b/mocha-php/src/mocha-php/scripts/mcx-typeaheadsearch.js @@ -20,11 +20,14 @@ function McxTypeaheadSearch(parentElement) this.search = function(query) { + if (query.length < 3) + return; + System.ClassList.Add(this.PopupElement, "uwt-visible"); System.ClassList.Add(this.PopupElement, "uwt-loading"); var xhr = new XMLHttpRequest(); - var searchUrl = System.ExpandRelativePath("~/" + System.TenantName + "/search.htmld?q=" + encodeURIComponent(query)); + var searchUrl = System.ExpandRelativePath("~/" + System.TenantName + "/search.htmld?m=typeahead&q=" + encodeURIComponent(query)); // var searchUrl = System.ExpandRelativePath("~/madi/pex/fs/" + System.TenantName + "typeahead?q=" + encodeURIComponent(query) + "&contextualsearch=true&autocomplete=true&clientRequestId="); /* @@ -67,7 +70,7 @@ function McxTypeaheadSearch(parentElement) span = document.createElement("span"); span.className = "uwt-description"; - span.innerText = json.items[i].summaryDescription; + span.innerText = json.items[i].subtitle1; // json.items[i].summaryDescription; li.appendChild(span); this.NativeObject.MenuElement.appendChild(li); diff --git a/mocha-php/src/mocha-php/themes/common/styles/uwt-actionpreviewbutton.less b/mocha-php/src/mocha-php/themes/common/styles/uwt-actionpreviewbutton.less index 9d6a8c9..286dba6 100644 --- a/mocha-php/src/mocha-php/themes/common/styles/uwt-actionpreviewbutton.less +++ b/mocha-php/src/mocha-php/themes/common/styles/uwt-actionpreviewbutton.less @@ -148,7 +148,7 @@ div.uwt-actionpreviewbutton position: relative; &> ul.uwt-menu { - display: none; + // display: none; // this should already be handled by uwt-popup position: absolute; //margin-left: 20px; left: @ActionPreviewButton_ActionMenu_Width; @@ -156,9 +156,10 @@ div.uwt-actionpreviewbutton width: max-content; z-index: 1; } - &:hover > ul.uwt-menu + &:hover > ul.uwt-menu, &:focus-within > ul.uwt-menu { - display: block; + opacity: 1; + visibility: visible; } } } diff --git a/mocha-php/src/mocha-php/themes/mocha/mcx-elementcontent.less b/mocha-php/src/mocha-php/themes/mocha/mcx-elementcontent.less index 9c9b2a1..7d35450 100644 --- a/mocha-php/src/mocha-php/themes/mocha/mcx-elementcontent.less +++ b/mocha-php/src/mocha-php/themes/mocha/mcx-elementcontent.less @@ -131,3 +131,12 @@ div.mcx-elementcontent } } } + +div.uwt-formview-item.mcx-element +{ + display: block !important; + &> div.uwt-formview-item-label, &> div.uwt-formview-item-content + { + display: block !important; + } +} \ No newline at end of file diff --git a/mocha-php/src/mocha-php/ui/pages/InstancePage.phpx.php b/mocha-php/src/mocha-php/ui/pages/InstancePage.phpx.php index 2e80454..38d1f82 100644 --- a/mocha-php/src/mocha-php/ui/pages/InstancePage.phpx.php +++ b/mocha-php/src/mocha-php/ui/pages/InstancePage.phpx.php @@ -11,6 +11,7 @@ use Mocha\UI\Controls\InstanceBrowser; use Mocha\UI\Renderers\HTML\HTMLRenderer; + use Mocha\UI\Renderers\HTML\HTMLRenderer2; use Phast\RenderingEventArgs; use Phast\WebPage; @@ -21,10 +22,24 @@ { parent::OnRendering($re); - /** - * @var MySQLDatabaseOms - */ + $useLegacyRendering = false; + if (isset($_GET["useLegacyRendering"]) && $_GET["useLegacyRendering"] == true) + { + $useLegacyRendering = true; + } + $oms = mocha_get_oms(); + $useRendererV2 = true; + + $ctx = new OmsContext(); + if ($useRendererV2) + { + $htmlRenderer = new HTMLRenderer2($ctx); + } + else + { + $htmlRenderer = new HTMLRenderer($ctx); + } $instkey = InstanceKey::parse($this->Page->GetPathVariableValue("instid")); @@ -33,9 +48,6 @@ $inst = $oms->getInstanceByKey($instkey); if ($inst === null) { - $ctx = new OmsContext(); - $htmlRenderer = new HTMLRenderer($ctx); - $htmlRenderer->renderBeginPage("Error"); ?>
@@ -72,15 +84,18 @@ } else { - $ctx = new OmsContext(); - $htmlRenderer = new HTMLRenderer($ctx); - $parentClass = $oms->getParentClass($inst); if ($castkey !== null) { $parentClass = $oms->getInstanceByKey($castkey); } + if (!$useLegacyRendering) + { + $htmlRenderer->renderInitialElement($inst); + exit(); + } + $rel_Class__has_default__Task = $oms->getInstanceByGlobalIdentifier(KnownRelationshipGuids::Class__has_default__Task); if ($rel_Class__has_default__Task !== null) { @@ -94,15 +109,13 @@ $context->setWorkData($parentClass, $inst); // echo ("instance for " . $parentClass->InstanceKey . " = " . $inst->InstanceKey); - - $taskRenderer = new HTMLRenderer($context); - $taskRenderer->TargetInstance = $inst; - $taskRenderer->IsPostback = $this->Page->IsPostback; + $htmlRenderer->TargetInstance = $inst; + $htmlRenderer->IsPostback = $this->Page->IsPostback; if ($this->Page->IsPostback) { - $taskRenderer->processPostback(element: $initiatingElement); + $htmlRenderer->processPostback(element: $initiatingElement); } - $taskRenderer->renderTask($defaultTask, $inst); + $htmlRenderer->renderTask($defaultTask, $inst); exit(); } else diff --git a/mocha-php/src/mocha-php/ui/pages/LoginPage.phpx.php b/mocha-php/src/mocha-php/ui/pages/LoginPage.phpx.php index 0c81479..a0fcb34 100644 --- a/mocha-php/src/mocha-php/ui/pages/LoginPage.phpx.php +++ b/mocha-php/src/mocha-php/ui/pages/LoginPage.phpx.php @@ -34,7 +34,7 @@ $oms->setTenant($tenant); $oms->initializeInstanceCache(); - // echo (" login token: " . $_SESSION["user_token_" . $oms->getTenant()->ID]); + // echo (" login token: " . $_SESSION["user_token_" . System::GetTenantName()]); /* if (mocha_get_current_user() !== null) { @@ -103,6 +103,25 @@ $json = $oms->getResponse($pageElement); $json = $json["value"]; + $renderer->ProcessPostbackFunction = function($sender, $element, $array) + { + $oms = mocha_get_oms(); + + if ($array["result"] == "success") + { + if (array_key_exists("sessionSecureToken", $array)) + { + $token = $array["sessionSecureToken"]; + $_SESSION["user_token_" . System::GetTenantName()] = $token; + if ($array["type"] == "redirect") + { + System::Redirect($array["destinationUrl"]); + return false; + } + } + } + }; + $renderer->ProcessUpdatesFunction = function($sender, $element) { /** @@ -160,7 +179,7 @@ die(); } - $_SESSION["user_token_" . $oms->getTenant()->ID] = $token; + $_SESSION["user_token_" . System::GetTenantName()] = $token; $oms->setCurrentUser($instUser); System::RedirectFromLoginPage(); @@ -287,7 +306,7 @@ die(); } - $_SESSION["user_token_" . $oms->getTenant()->ID] = $token; + $_SESSION["user_token_" . System::GetTenantName()] = $token; $oms->setCurrentUser($instUser); System::RedirectFromLoginPage(); exit(); diff --git a/mocha-php/src/mocha-php/ui/pages/LogoutPage.phpx.php b/mocha-php/src/mocha-php/ui/pages/LogoutPage.phpx.php index 08936f5..31b159c 100644 --- a/mocha-php/src/mocha-php/ui/pages/LogoutPage.phpx.php +++ b/mocha-php/src/mocha-php/ui/pages/LogoutPage.phpx.php @@ -20,7 +20,7 @@ */ $oms = mocha_get_oms(); - unset($_SESSION["user_token_" . $oms->getTenant()->ID]); + unset($_SESSION["user_token_" . System::GetTenantName()]); System::Redirect("~/" . $_SESSION["CurrentTenantName"], true); exit(); diff --git a/mocha-php/src/mocha-php/ui/pages/PromptPage.phpx.php b/mocha-php/src/mocha-php/ui/pages/PromptPage.phpx.php index 1e0ed2a..ae015cb 100644 --- a/mocha-php/src/mocha-php/ui/pages/PromptPage.phpx.php +++ b/mocha-php/src/mocha-php/ui/pages/PromptPage.phpx.php @@ -3,6 +3,7 @@ namespace Mocha\UI\Pages; use Mocha\Core\InstanceKey; + use Mocha\Core\InstanceReference; use Mocha\Core\KnownClassGuids; use Mocha\Core\KnownInstanceGuids; use Mocha\Core\KnownRelationshipGuids; @@ -43,22 +44,34 @@ $search = new SearchHelper($oms); - $ec = $oms->getInstanceByKey(InstanceKey::parse($id)); - if ($ec !== null) + $ik = new InstanceKey(0, 0); + if (InstanceKey::TryParse($id, $ik)) { - $ecinst = $oms->getRelatedInstance($ec, KnownRelationshipGuids::Element_Content__has__Instance); - if ($ecinst !== null) + $search->ValidClasses[] = new InstanceReference(null, $ik, null); + /* + $ec = $oms->getInstanceByKey($ik); + if ($ec !== null) { - if ($oms->is_a($ecinst, KnownClassGuids::Clasz)) + $ecinst = $oms->getRelatedInstance($ec, KnownRelationshipGuids::Element_Content__has__Instance); + if ($ecinst !== null) { - $search->ValidClasses[] = $ecinst; - } - else if ($oms->is_a($ecinst, KnownClassGuids::Relationship)) - { - $relDestination = $oms->getRelatedInstance($ecinst, KnownRelationshipGuids::Relationship__has_destination__Class); - $search->ValidClasses[] = $relDestination; + if ($oms->is_a($ecinst, KnownClassGuids::Clasz)) + { + $search->ValidClasses[] = $ecinst; + } + else if ($oms->is_a($ecinst, KnownClassGuids::Relationship)) + { + $relDestination = $oms->getRelatedInstance($ecinst, KnownRelationshipGuids::Relationship__has_destination__Class); + $search->ValidClasses[] = $relDestination; + } } } + */ + } + else + { + echo (json_encode(array("result" => "failure", "message" => "could not parse instance key: " . $id))); + exit(); } $postdata = file_get_contents("php://input"); @@ -77,15 +90,21 @@ foreach ($results as $result) { $viewTaskIid = null; - $viewTask =$oms->getRelatedInstance($oms->getParentClass($result->Instance), KnownRelationshipGuids::Class__has_default__Task); + if ($result->DefaultTask != null) + { + $viewTaskIid = $result->DefaultTask->InstanceKey->__toString(); + } + + /* + $viewTask =$oms->getRelatedInstance($oms->getParentClass($result), KnownRelationshipGuids::Class__has_default__Task); if ($viewTask !== null) { $viewTaskIid = $viewTask->InstanceKey->__toString(); } - + */ $json["items"][] = [ - "instanceId" => $result->Instance->InstanceKey->__toString(), - "text" => $result->Title, + "instanceId" => $result->InstanceKey->__toString(), + "text" => $result->Text, "action" => "view", "viewTask" => $viewTaskIid ]; diff --git a/mocha-php/src/mocha-php/ui/pages/SearchPage.phpx.php b/mocha-php/src/mocha-php/ui/pages/SearchPage.phpx.php index 3dc9aea..8a8a1cf 100644 --- a/mocha-php/src/mocha-php/ui/pages/SearchPage.phpx.php +++ b/mocha-php/src/mocha-php/ui/pages/SearchPage.phpx.php @@ -154,51 +154,54 @@ } $query = $_GET["q"]; - $results = $searchHelper->search($query); + if (strlen($query) < 3) + { + $json = array + ( + "result" => "failure", + "responseCode" => 400, + "responseText" => "Bad Request", + + "mochaResponseCode" => "MCX0019", + "mochaResponseText" => "Search Query Required", + "title" => "Search Query Required", + "message" => "Please enter a search query longer than 3 characters" + ); + echo (json_encode($json)); + $re->Handled = true; + return true; + } + + $results = $searchHelper->search($query, isset($_GET["m"]) ? $_GET["m"] : null); + $count = count($results); if ($count > 50) { - if (strlen($query) < 3) - { - $json = array - ( - "result" => "failure", - "responseCode" => 400, - "responseText" => "Bad Request", - - "mochaResponseCode" => "MCX0019", - "mochaResponseText" => "Search Query Required", - "title" => "Search Query Required", - "message" => "Please enter a search query longer than 3 characters" - ); - echo (json_encode($json)); - $re->Handled = true; - return true; - } } echo ("{ \"result\": \"success\", \"items\": [ "); for ($i = 0; $i < $count; $i++) { - $inst = $results[$i]->Instance; - $instClass = $oms->getParentClass($inst); - $viewTask = $oms->getRelatedInstance($instClass, KnownRelationshipGuids::Class__has_default__Task); + $inst = $results[$i]; + $viewTask = $results[$i]->DefaultTask; // $oms->getRelatedInstance($instClass, KnownRelationshipGuids::Class__has_default__Task); $uri = "/" . $oms->getTenantName() . "/d/inst/" . $inst->InstanceKey->__toString() . ".htmld"; + /* if ($oms->is_a($inst, KnownClassGuids::Task)) { $uri = "/" . $oms->getTenantName() . "/d/task/" . $inst->InstanceKey->__toString() . ".htmld"; } + */ $instJson = array ( "iconId" => null, "iid" => $inst->InstanceKey->__toString(), "imageUrl" => null, - "label" => $results[$i]->Title, - "title" => $results[$i]->Title, - "subtitle1" => null, + "label" => $results[$i]->Text, + "title" => $results[$i]->Text, + "subtitle1" => $results[$i]->ParentClass->Text, "subtitle2" => null, "subtitle3" => null, - "summaryDescription" => $oms->getInstanceText($instClass), + // "summaryDescription" => $oms->getInstanceText($instClass), "returnedByQueryIntent" => false, "viewTask" => $viewTask === null ? null : $viewTask->InstanceKey->__toString(), "uri" => $uri diff --git a/mocha-php/src/mocha-php/ui/pages/TaskPage.phpx.php b/mocha-php/src/mocha-php/ui/pages/TaskPage.phpx.php index 93f784e..74556bc 100644 --- a/mocha-php/src/mocha-php/ui/pages/TaskPage.phpx.php +++ b/mocha-php/src/mocha-php/ui/pages/TaskPage.phpx.php @@ -6,6 +6,7 @@ use Mocha\Core\KnownRelationshipGuids; use Mocha\Core\OmsContext; use Mocha\UI\Renderers\HTML\HTMLRenderer; + use Mocha\UI\Renderers\HTML\HTMLRenderer2; use Phast\RenderingEventArgs; use Phast\WebPage; @@ -26,7 +27,14 @@ $initiatingElement = $oms->getRelatedInstance($taskInstance, KnownRelationshipGuids::Task__has_initiating__Element); $context = new OmsContext(); - $taskRenderer = new HTMLRenderer($context); + if ($_GET["legacy"] == "1") + { + $taskRenderer = new HTMLRenderer($context); + } + else + { + $taskRenderer = new HTMLRenderer2($context); + } //$taskRenderer->TargetInstance = $instance; $taskRenderer->IsPostback = $this->Page->IsPostback; if ($this->Page->IsPostback)