Przeglądaj źródła

updated create base proces for object

Piotr Labudda 8 lat temu
rodzic
commit
d55e150bfb
2 zmienionych plików z 48 dodań i 36 usunięć
  1. 25 35
      SE/se-lib/Route/Storage.php
  2. 23 1
      SE/se-lib/Route/Storage/AclUsage.php

+ 25 - 35
SE/se-lib/Route/Storage.php

@@ -831,45 +831,35 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 		$item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
 		$item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
 		DBG::log($item, 'array', "TODO: addObjectBaseProcesAjax for \$item");
 		DBG::log($item, 'array', "TODO: addObjectBaseProcesAjax for \$item");
 
 
-		throw new HttpException("TODO: addObjectBaseProcesAjax('{$namespace}')", 400); // TODO: ...
-
-		// $return['$tableStruct'] = $tableStruct;
-		//
-		// $idTable = $this->fetchTableId($idStorage, $tblName);
-		// if ($idTable <= 0) {
-		// 	UI::alert('warning', "Zasob tabela '{$tblName}' nie istnieje");// TODO: add p5UI btn
-		// 	DBG::table("tblStruct", $tblStruct, __CLASS__, __FUNCTION__, __LINE__);
-		// 	throw new Exception("Zasob tabela '{$tblName}' nie istnieje");
-		// }
-		// $cellZasobList = array();
-		// foreach (DB::getPDO()->fetchAllByKey("
-		// 		select z.ID, z.`DESC`, z.A_STATUS
-		// 		from CRM_LISTA_ZASOBOW z
-		// 		where z.PARENT_ID = '{$idTable}'
-		// 	", $key = 'DESC') as $ind => $row) {
-		// 	$cellZasobList[strtolower($ind)] = $row;
-		// }
-		//
-		// $return['$cellZasobList'] = $cellZasobList;
-
-		// TODO: ACL::modify('default_db/CRM_PROCES/CRM_PROCES_INIT', [ 'ref:...' => $namespace ]);
+		if (!$item['idZasob']) throw new Exception("Missing id zasob for object '{$namespace}'");
+		if (!$item['idDatabase']) throw new Exception("Missing id database for object '{$namespace}'");
+		if (!$item['_rootTableName']) throw new Exception("Missing root table name for object '{$namespace}'");
+		if ('AntAcl' != $item['_type']) throw new Exception("Not implemented type '{$item['_type']}' for namespace '{$namespace}' - only AntAcl supported");
+		if (!$item['hasStruct']) throw new Exception("Missing structure for object '{$namespace}'");
+		if (!$item['isStructInstalled']) throw new Exception("Structure not installed for object '{$namespace}'");
+		if (!$item['isObjectActive']) throw new Exception("Object is not active '{$namespace}'");
+		$fieldsWithIdZasob = array_filter($item['field'], function ($field) {
+			if (!$field['idZasob']) return false;
+			return true;
+		});
+		if (empty($fieldsWithIdZasob)) throw new Exception("Missing fields with id zasob in object '{$namespace}'");
+
 		$idProces = DB::getDB()->ADD_NEW_OBJ('CRM_PROCES', (object)[
 		$idProces = DB::getDB()->ADD_NEW_OBJ('CRM_PROCES', (object)[
 			'TYPE' => 'PROCES_INIT',
 			'TYPE' => 'PROCES_INIT',
-			'DESC' => "Proces dla obiektu '{$namespace}'",
+			'DESC' => "TODO: Proces dla obiektu '{$namespace}'",
 		]);
 		]);
 		if (!$idProces) throw new Exception("DB ERROR - nie udało się dodać procesu");
 		if (!$idProces) throw new Exception("DB ERROR - nie udało się dodać procesu");
-		// TODO: add wskaznik do $item['idZasob']
-		// foreach ($cellZasobList as $loverName => $row) {
-		// 	DB::getDB()->ADD_NEW_OBJ('CRM_WSKAZNIK', (object)[
-		// 		'ID_PROCES' => $idProces,
-		// 		'ID_ZASOB' => $row['ID'],
-		// 		'TYP' => 'P',
-		// 		'ID_PRZYPADEK' => 2
-		// 	]);
-		// }
-		// $return['type'] = 'success';
-		// $return['msg'] = "Utworzono proces {{$idProces}}";
-		// return $return;
+		array_map(function ($field) use ($idProces) {
+			DB::getDB()->ADD_NEW_OBJ('CRM_WSKAZNIK', (object)[
+				'ID_PROCES' => $idProces,
+				'ID_ZASOB' => $field['idZasob'],
+				'TYP' => 'P',
+				'ID_PRZYPADEK' => 2
+			]);
+		}, $fieldsWithIdZasob);
+		$return['type'] = 'success';
+		$return['msg'] = "Utworzono proces {{$idProces}}";
+		return $return;
 	}
 	}
 
 
 	public function addGeomEtykietaCellsAction() {
 	public function addGeomEtykietaCellsAction() {

+ 23 - 1
SE/se-lib/Route/Storage/AclUsage.php

@@ -43,8 +43,30 @@ class Route_Storage_AclUsage extends RouteBase {
 						? UI::h('a', [ 'href' => Router::getRoute('Storage_AclStruct')->getLink('', [ 'idStorage' => $acl->getDatabaseID(), 'namespace' => $acl->getNamespace() ]) ], "struktura obiektu (AntAcl)")
 						? UI::h('a', [ 'href' => Router::getRoute('Storage_AclStruct')->getLink('', [ 'idStorage' => $acl->getDatabaseID(), 'namespace' => $acl->getNamespace() ]) ], "struktura obiektu (AntAcl)")
 						: UI::h('a', [ 'href' => Router::getRoute('Storage_AclStruct')->getLink('tableStruct', [ 'idStorage' => $acl->getDatabaseID(), 'table' => $acl->getRootTableName() ]) ], "struktura tabeli (TableAcl)")
 						: UI::h('a', [ 'href' => Router::getRoute('Storage_AclStruct')->getLink('tableStruct', [ 'idStorage' => $acl->getDatabaseID(), 'table' => $acl->getRootTableName() ]) ], "struktura tabeli (TableAcl)")
 					]),
 					]),
+					UI::h('p', [], [
+						"dodaj proces: ",
+						UI::hButtonAjax("Dodaj podstawowy proces - read only (TODO)", 'addObjectBaseProcesAjax', [
+							'title' => "Dodaj podstawowy proces dla obiektu '{$namespace}' - read only (TODO)",
+							'class' => "btn btn-xs btn-default",
+							'href' => Router::getRoute('Storage')->getLink('addObjectBaseProcesAjax'),
+							'data' => [ 'namespace' => $namespace ]
+						]),
+						" ",
+						UI::hButtonAjax("TODO edytor procesu", 'todoGotoProcesEditorAjax', [
+							'title' => "Otwórz edytor procesu dla obiektu '{$namespace}'",
+							'class' => "btn btn-xs btn-warning",
+							'href' => Router::getRoute('Storage')->getLink('addObjectBaseProcesAjax'),
+							'data' => [ 'namespace' => $namespace ]
+						]),
+					]),
 				])
 				])
 			]);
 			]);
+			UI::hButtonAjaxOnResponse('addObjectBaseProcesAjax', /* payload, n */ "
+				jQuery.notify(payload.msg, payload.type)
+			");
+			UI::hButtonAjaxOnResponse('todoGotoProcesEditorAjax', /* payload, n */ "
+				jQuery.notify('TODO: edytor procesu', 'error')
+			");
 
 
 			if ($idTable > 0) {
 			if ($idTable > 0) {
 				$aclTableRows = DB::getPDO()->fetchAll("select * from `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` where ID_TABLE = {$idTable}");
 				$aclTableRows = DB::getPDO()->fetchAll("select * from `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` where ID_TABLE = {$idTable}");
@@ -52,7 +74,7 @@ class Route_Storage_AclUsage extends RouteBase {
 				echo UI::h('summary', ['style'=>"cursor:pointer; margin-bottom:12px"], "Wszystkie powiązania komórek z procesami - szczegóły");
 				echo UI::h('summary', ['style'=>"cursor:pointer; margin-bottom:12px"], "Wszystkie powiązania komórek z procesami - szczegóły");
 				UI::table([
 				UI::table([
 					'rows' => array_map(function ($row) {
 					'rows' => array_map(function ($row) {
-						$splitPos = strpos($row['TABLE_DESCRIPTION'], ' ', 20);
+						$splitPos = (strlen($row['TABLE_DESCRIPTION']) > 20) ? strpos($row['TABLE_DESCRIPTION'], ' ', 20) : 20;
 						if ($splitPos > 30) $splitPos = 20;
 						if ($splitPos > 30) $splitPos = 20;
 						$row['TABLE_DESCRIPTION'] = UI::h('details', [], [
 						$row['TABLE_DESCRIPTION'] = UI::h('details', [], [
 							UI::h('summary', [ 'style' => "white-space:nowrap" ], substr($row['TABLE_DESCRIPTION'], 0, $splitPos)),
 							UI::h('summary', [ 'style' => "white-space:nowrap" ], substr($row['TABLE_DESCRIPTION'], 0, $splitPos)),