major updates to mocha-php with HttpOmsClient
This commit is contained in:
parent
bd367d7ba8
commit
0a3e0090e7
@ -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;
|
||||
|
||||
@ -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);
|
||||
$sep = null;
|
||||
$isDerived = false;
|
||||
if (str_contains($instanceKeyStr, '$'))
|
||||
{
|
||||
$sep = '$';
|
||||
}
|
||||
else if (str_contains($instanceKeyStr, '!'))
|
||||
{
|
||||
$sep = '!';
|
||||
$isDerived = true;
|
||||
}
|
||||
if ($sep != null)
|
||||
{
|
||||
$split = explode($sep, $instanceKeyStr);
|
||||
if (count($split) == 2)
|
||||
{
|
||||
if (is_numeric($split[0]) && is_numeric($split[1]))
|
||||
{
|
||||
return new InstanceKey(intval($split[0]), intval($split[1]));
|
||||
return new InstanceKey(intval($split[0]), intval($split[1]), $isDerived);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -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}";
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -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 [ ];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@ -1,11 +1,14 @@
|
||||
<?php
|
||||
namespace Mocha\Search;
|
||||
use Mocha\Core\InstanceKey;
|
||||
use Mocha\Core\InstanceReference;
|
||||
use Mocha\Core\KnownClassGuids;
|
||||
use Phast\UUID;
|
||||
|
||||
class SearchHelper
|
||||
{
|
||||
/**
|
||||
* @var \Mocha\Oms\MySQLDatabaseOms
|
||||
* @var \Mocha\Core\Oms
|
||||
*/
|
||||
private $_OMS;
|
||||
public function __construct($oms)
|
||||
@ -19,12 +22,24 @@
|
||||
public $LastQuery;
|
||||
|
||||
|
||||
public function search(string $q)
|
||||
public function search(string $q, string | null $m = null)
|
||||
{
|
||||
// this is ALL MySQL-specific
|
||||
/*
|
||||
if ($q == "")
|
||||
return $this->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)
|
||||
|
||||
@ -194,8 +194,8 @@
|
||||
$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";
|
||||
@ -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(
|
||||
|
||||
|
||||
@ -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:<br/>"); 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 ("<table class=\"uwt-listview mcx-element\" data-ecid=\"" . $json["ecid"] . "\" data-instance-id=\"" . $json["iid"] . "\">");
|
||||
echo ("<thead>");
|
||||
echo ("<tr>");
|
||||
foreach ($json["columns"] as $col)
|
||||
{
|
||||
if (isset($col["visible"]) && !$col["visible"])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
echo ("<th data-ecid=\"" . $col["ecid"] . "\" data-instance-id=\"" . $col["iid"] . "\">");
|
||||
echo ("<label>" . $col["label"] . "</label>");
|
||||
echo ("</th>");
|
||||
}
|
||||
echo ("</tr>");
|
||||
echo ("</thead>");
|
||||
echo ("<tbody>");
|
||||
foreach ($json["rows"] as $row)
|
||||
{
|
||||
echo ("<tr>");
|
||||
foreach ($row["cellsMap"] as $key => $col)
|
||||
{
|
||||
if (isset($col["visible"]) && !$col["visible"])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
echo ("<td data-ecid=\"" . $col["ecid"] . "\" data-instance-id=\"" . $col["iid"] . "\">");
|
||||
//print_r($col);
|
||||
$this->renderFragment($col);
|
||||
echo ("</td>");
|
||||
}
|
||||
echo ("</tr>");
|
||||
}
|
||||
echo ("</tbody>");
|
||||
echo ("</table>");
|
||||
}
|
||||
else if ($json["widget"] == "vbox")
|
||||
{
|
||||
echo ("<div class=\"uwt-layout-box uwt-orientation-vertical\">");
|
||||
@ -73,7 +175,9 @@
|
||||
echo ("<div class=\"uwt-formview mcx-element\" data-instance-id=\"" . $json["iid"] . "\" data-ecid=\"" . $fqecid . "\">");
|
||||
foreach ($json["children"] as $child)
|
||||
{
|
||||
$fqecidChild = $fqecidPrefix . $child["ecid"];
|
||||
// $fqecidChild = $fqecidPrefix . $child["ecid"];
|
||||
$fqecidChild = $child["ecid"];
|
||||
|
||||
echo ("<div class=\"uwt-formview-item mcx-elementcontent");
|
||||
if (!isset($child["label"]))
|
||||
{
|
||||
@ -87,6 +191,10 @@
|
||||
{
|
||||
echo(" mcx-required");
|
||||
}
|
||||
if ($child["widget"] == "grid")
|
||||
{
|
||||
echo (" mcx-element");
|
||||
}
|
||||
echo ("\" data-instance-id=\"" . $child["iid"] . "\" data-ecid=\"" . $child["ecid"] . "\">");
|
||||
|
||||
echo ("<div class=\"uwt-formview-item-label\">");
|
||||
@ -129,6 +237,62 @@
|
||||
{
|
||||
echo ("<input id=\"ec_" . $fqecid . "\" name=\"ec_" . $fqecid . "\" type=\"password\" value=\"" . $json["value"] . "\" />");
|
||||
}
|
||||
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 ("<!-- ");
|
||||
print_r($json);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -182,6 +182,8 @@ function McxInstanceBrowser(parentElement)
|
||||
this.NativeObject.clearSearchResults();
|
||||
System.ClassList.Remove(this.NativeObject.SearchResultsElement, "mcx-placeholder-visible");
|
||||
|
||||
if (typeof(json.items) !== 'undefined')
|
||||
{
|
||||
for (var i = 0; i < json.items.length; i++)
|
||||
{
|
||||
var li = document.createElement("li");
|
||||
@ -207,7 +209,7 @@ function McxInstanceBrowser(parentElement)
|
||||
|
||||
this.NativeObject.SearchResultsMenuElement.appendChild(li);
|
||||
}
|
||||
|
||||
}
|
||||
System.ClassList.Remove(this.NativeObject.SearchResultsElement, "uwt-loading");
|
||||
}
|
||||
else
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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");
|
||||
?>
|
||||
<div class="uwt-panel" style="width: 600px; margin-left: auto; margin-right: auto; margin-top: 128px;">
|
||||
@ -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
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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,7 +44,12 @@
|
||||
|
||||
$search = new SearchHelper($oms);
|
||||
|
||||
$ec = $oms->getInstanceByKey(InstanceKey::parse($id));
|
||||
$ik = new InstanceKey(0, 0);
|
||||
if (InstanceKey::TryParse($id, $ik))
|
||||
{
|
||||
$search->ValidClasses[] = new InstanceReference(null, $ik, null);
|
||||
/*
|
||||
$ec = $oms->getInstanceByKey($ik);
|
||||
if ($ec !== null)
|
||||
{
|
||||
$ecinst = $oms->getRelatedInstance($ec, KnownRelationshipGuids::Element_Content__has__Instance);
|
||||
@ -60,6 +66,13 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
echo (json_encode(array("result" => "failure", "message" => "could not parse instance key: " . $id)));
|
||||
exit();
|
||||
}
|
||||
|
||||
$postdata = file_get_contents("php://input");
|
||||
$postjson = json_decode($postdata, true);
|
||||
@ -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
|
||||
];
|
||||
|
||||
@ -154,10 +154,6 @@
|
||||
}
|
||||
|
||||
$query = $_GET["q"];
|
||||
$results = $searchHelper->search($query);
|
||||
$count = count($results);
|
||||
if ($count > 50)
|
||||
{
|
||||
if (strlen($query) < 3)
|
||||
{
|
||||
$json = array
|
||||
@ -175,30 +171,37 @@
|
||||
$re->Handled = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
$results = $searchHelper->search($query, isset($_GET["m"]) ? $_GET["m"] : null);
|
||||
|
||||
$count = count($results);
|
||||
if ($count > 50)
|
||||
{
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@ -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();
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user