Преглед изворни кода

updated Storage route - working add Zasoby TABELA, KOMORKA

Piotr Labudda пре 9 година
родитељ
комит
db37955186
1 измењених фајлова са 153 додато и 45 уклоњено
  1. 153 45
      SE/se-lib/Route/Storage.php

+ 153 - 45
SE/se-lib/Route/Storage.php

@@ -9,9 +9,9 @@ Lib::loadClass('OBJ');
 
 /*
 # Storage:
-- [ ] view available storage (from Zasoby - type 'BAZA_DANYCH', 'DATABASE_MYSQL', ...)
-- [ ] check config for connection
-- [ ] add cells to Zasoby
+- [x] view available storage (from Zasoby - type 'BAZA_DANYCH', 'DATABASE_MYSQL', ...)
+- [x] check config for connection
+- [x] add cells to Zasoby
 - [ ] create cells in Storage
 - [x] use PDO
 
@@ -151,18 +151,70 @@ class Route_Storage extends RouteBase {
 			<?php endforeach; ?>
 		</tbody>
 	</table>
-	<div class="btn-group">
-		<button class="btn btn-default" title="Wybierz rekordy wg instancji"><i class="glyphicon glyphicon-question-sign"></i></button>
-		<button class="btn btn-default">Przypisani</button>
-		<button class="btn btn-default">Nieprzypisani</button>
-	</div>
+	<a href="index.php?_route=Storage&_task=coreObjectConnect&object=<?php echo $objectName; ?>" class="btn btn-primary">Przypisz rekordy do klasy</a>
 	<?php
 		$mainTable = OBJ::getMainTableName($json);
 		$sqlFields = OBJ::getTableFields($json);
 		$this->showTableWidget($mainTable, $sqlFields);
+	?>
+</div>
+<script>
+jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:click', function(e, n, payload) {
+	console.log('event p5UIBtnAjax:Storage:checkObjectInstallAjax:click', n, payload);
+});
+jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', function(e, n, payload) {
+	console.log('event p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', n, payload);
+	if ('success' == payload.type) {
+		// jQuery(n).parents('td').text(payload.body.id);
+	}
+	jQuery.notify(payload.msg, payload.type);
+});
+</script>
+<?php
+			DBG::_(true, true, "json", $json, __CLASS__, __FUNCTION__, __LINE__);
+		} catch (Exception $e) {
+			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
+		}
+		UI::dol();
+	}
+
+	public function coreObjectConnectAction() {
+		UI::gora();
+		UI::menu();
+		$this->navView();
+		try {
+
+			$objectName = V::get('object', '', $_REQUEST, 'word');
+			if (empty($objectName)) throw new Exception("Missing Object name");
+			$json = OBJ::getCoreObjectFromFile($objectName);
+
+			$label = OBJ::getLabel($json);
+			$parentList = OBJ::getParentList($json);
+			$linksParentList = array(); foreach ($parentList as $parentName) {
+				$parentLink = '<a href="index.php?_route=Storage&_task=coreObjectStruct&object=' . str_replace('/', '-', $parentName) . '">' . $parentName . '</a>';
+				array_unshift($linksParentList, $parentLink);
+			}
+
+			$ajaxCheckInstall = Request::getPathUri() . "index.php?_route=Storage&_task=checkObjectInstallAjax&object={$objectName}";
+			$onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:checkObjectInstallAjax', { href: '{$ajaxCheckInstall}' })";
+			$btnCheckInstall = '<a onclick="'.$onClick.'" href="#" title="check install db tables"><i class="glyphicon glyphicon-cog"></i></a>';
 
+?>
+<div class="container">
+	<h1>Obiekt <code><?php echo $label; ?></code> <small><?php echo $btnCheckInstall; ?></small></h1>
+	<?php if (!empty($parentList)) : ?>
+		<ol class="breadcrumb">
+		  <li>Dziedziczy z:</li>
+			<?php foreach ($linksParentList as $parentLink) : ?>
+			  <li><?php echo $parentLink; ?></li>
+			<?php endforeach; ?>
+		  <!-- <li class="active">Data</li> -->
+		</ol>
+		<!-- <p> <?php echo implode(", ", $parentList); ?></p> -->
+	<?php endif; ?>
+	<?php
 		$tableOne = array();
-		$tableOne['caption'] = 'Instancje';
+		$tableOne['caption'] = 'Klasy';
 		$tableOne['rows'] = array();
 		$parentList = OBJ::getParentList($json);
 		$tableOne['rows'][] = array('__primary_key' => $objectName, 'name' => $objectName);
@@ -182,7 +234,11 @@ class Route_Storage extends RouteBase {
 			$tableTwo['rows'][$idx]['__primary_key'] = $row['ID'];
 		}
 		echo '<hr>';
-		$this->showConnectTableWidget($tableOne, $tableTwo, $connectFunction);
+		// TODO: filter connected rows
+		// TODO: filter not connected rows
+		// TODO: action connect rows - args(schema, rows_primary_key_list)
+		// TODO: action un connect rows - args(schema, rows_primary_key_list)
+		$this->showConnectSchemaToTableWidget(compact('tableOne', 'tableTwo'));
 	?>
 </div>
 <script>
@@ -205,11 +261,17 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 		UI::dol();
 	}
 
-	public function showConnectTableWidget($tableOne, $tableTwo, $conectionType) {
+	public function showConnectSchemaToTableWidget($params) {
+		if (empty($params['tableOne'])) throw new Exception("Missing tableOne in Connect widget");
+		if (empty($params['tableTwo'])) throw new Exception("Missing tableTwo in Connect widget");
+		$tableOne = $params['tableOne'];
+		$tableTwo = $params['tableTwo'];
 		// TODO: add __js_on_click to $tableOne and $tableTwo
 		// TODO: add p5BtnAjax to table filters button
 		// TODO: add p5BtnAjax to conn button
 		$jsEventNamespace = 'ConnectTableWidget' . time();
+		$htmlIdWrap = "{$jsEventNamespace}-wrap";
+
 		$stateLogId = "{$jsEventNamespace}-state-log";
 		$stateSelectedTotalId = "{$jsEventNamespace}-state-selected";
 		$stateClearSelectedBtnId = "{$jsEventNamespace}-state-clear-selected-btn";
@@ -222,46 +284,78 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 		$tableOne['hidden_cols'] = $tableTwo['hidden_cols'] = array('__primary_key', '__js_on_click', '__html_id');
 		$tableTwo['__html_id'] = "{$jsEventNamespace}-table-two";
 ?>
-		<?php UI::table($tableOne); ?>
-		<div class="btn-group">
-			<button class="btn btn-default" title="Wybierz rekordy wg instancji"><i class="glyphicon glyphicon-question-sign"></i></button>
-			<button class="btn btn-default">Przypisani</button>
-			<button class="btn btn-default">Nieprzypisani</button>
-		</div>
-		<div class="btn-group">
-			<span style="padding-left:30px;">Zaznaczono
-				<span id="<?php echo $stateSelectedTotalId; ?>">0</span>
-				<button id="<?php echo $stateClearSelectedBtnId; ?>"
-								onClick="return p5UI__Clickable(this, '<?php echo $jsEventNamespace; ?>:clearSelection', {});"
-								class="btn btn-link"
-								style="display:none"><i class="glyphicon glyphicon-remove" style="color:red"></i></button>
-			</span>
-		</div>
-		<?php UI::table($tableTwo); ?>
-		<pre id="<?php echo "{$stateLogId}"; ?>"></pre>
+<div id="<?php echo $htmlIdWrap; ?>">
+	<?php UI::table($tableOne); ?>
+	<div class="btn-group">
+		<button class="btn btn-default" title="Wybierz rekordy wg instancji"><i class="glyphicon glyphicon-question-sign"></i></button>
+		<button class="btn btn-default conn-btn-filter-yes">Przypisani</button>
+		<button class="btn btn-default conn-btn-filter-no active">Nieprzypisani</button>
+		<button class="btn btn-default conn-btn-filter-clear" title="Wszystkie"><i class="glyphicon glyphicon-remove"></i></button>
+	</div>
+	<div class="btn-group">
+		<span style="padding-left:30px;">Zaznaczono
+			<span class="conn-selected-total">0</span>
+			<button class="conn-btn-clear-selected btn btn-link"
+							onClick="return p5UI__Clickable(this, '<?php echo $jsEventNamespace; ?>:clearSelection', {});"
+							style="display:none"><i class="glyphicon glyphicon-remove" style="color:red"></i></button>
+		</span>
+	</div>
+	<?php UI::jsAjaxTable($tableTwo); ?>
+	<pre class="conn-log"></pre>
+</div>
 <script>
 (function(){
 
 	var state = {
 		selectedTableOne: null,
-		selectedTableTwo: []
-	};
+		selectedTableTwo: [],
+		filterSelected: 'no'
+	}
 	var props = {
 		jsEventNamespace: '<?php echo $jsEventNamespace; ?>',
+		htmlIdWrap: '<?php echo $htmlIdWrap; ?>',
 		tableTwoId: '#<?php echo $tableTwo['__html_id']; ?>',
 		stateSelectedTotalId: '#<?php echo $stateSelectedTotalId; ?>',
 		stateClearSelectedBtnId: '#<?php echo $stateClearSelectedBtnId; ?>',
 		stateLogId: '#<?php echo $stateLogId; ?>'
 	}
+	var wrap = jQuery('#' + props.htmlIdWrap);
+	var jqNodes = {
+		wrap: wrap,
+		filter_yes: wrap.find('.conn-btn-filter-yes'),
+		filter_no: wrap.find('.conn-btn-filter-no'),
+		filter_clear: wrap.find('.conn-btn-filter-clear'),
+		total_selected: wrap.find('.conn-selected-total'),
+		btn_clear_selected: wrap.find('.conn-btn-clear-selected'),
+		state_log: wrap.find('.conn-log')
+	}
 
 	function render() {
-		jQuery(props.stateSelectedTotalId).text(state.selectedTableTwo.length);
+		jqNodes['total_selected'].text(state.selectedTableTwo.length);
 		if (state.selectedTableTwo.length > 0) {
 			jQuery(props.stateClearSelectedBtnId).show();
 		} else {
 			jQuery(props.stateClearSelectedBtnId).hide();
 		}
-		jQuery(props.stateLogId).text(JSON.stringify(state));
+		jqNodes['state_log'].text(JSON.stringify(state));
+
+		switch (state.filterSelected) {
+			case 'yes':
+				jqNodes['filter_yes'].addClass('active');
+				jqNodes['filter_no'].removeClass('active');
+				jqNodes['filter_clear'].removeClass('active');
+				break;
+			case 'no':
+				jqNodes['filter_yes'].removeClass('active');
+				jqNodes['filter_no'].addClass('active');
+				jqNodes['filter_clear'].removeClass('active');
+				break;
+			case 'clear':
+				jqNodes['filter_yes'].removeClass('active');
+				jqNodes['filter_no'].removeClass('active');
+				jqNodes['filter_clear'].addClass('active');
+				break;
+		}
 	}
 	function action__selectTableOneRow(pk) {
 		state.selectedTableOne = pk;
@@ -288,6 +382,11 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 		jQuery(props.tableTwoId).find('tbody').children('.info').removeClass('info');
 		render();
 	}
+	function action__filterSet(fltr) {
+		state.filterSelected = fltr;
+		render();
+		// TODO: ajax load tableTwo based on filter
+	}
 
 	jQuery(document).on(props.jsEventNamespace + ':tableOne:click', function(e, n, payload) {
 		var n$ = jQuery(n);
@@ -317,6 +416,15 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 	jQuery(document).on(props.jsEventNamespace + ':clearSelection:click', function(e, n, payload) {
 		action__clearSelection();
 	});
+	jqNodes['filter_yes'].on('click', function(e) {
+		action__filterSet('yes');
+	});
+	jqNodes['filter_no'].on('click', function(e) {
+		action__filterSet('no');
+	});
+	jqNodes['filter_clear'].on('click', function(e) {
+		action__filterSet('clear');
+	});
 
 })();
 </script>
@@ -444,7 +552,7 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 				} else {
 					$tblItem['uwagi'] .= 'TODO: ADD ZASOB';
 					$ajaxAddZasobLink = Request::getPathUri() . "index.php?_route=Storage&_task=addTableToZasoby&idStorage={$idStorage}&tblName={$tblName}";
-					$onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addToZasoby', { href: '{$ajaxAddZasobLink}' })";
+					$onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addTableToZasoby', { href: '{$ajaxAddZasobLink}' })";
 					$tblItem['id_zasob'] = '<a onclick="'.$onClick.'" class="btn btn-xs btn-primary" href="#">TODO: ADD ZASOB</a>';
 				}
 				$tableList[] = $tblItem;
@@ -488,11 +596,11 @@ jQuery(document).on('p5UIBtnAjax:Storage:checkObjectInstallAjax:ajaxLoaded', fun
 			DBG::table("tableList", $tableList, __CLASS__, __FUNCTION__, __LINE__);
 			?>
 <script>
-jQuery(document).on('p5UIBtnAjax:Storage:addToZasoby:click', function(e, n, payload) {
-	console.log('event p5UIBtnAjax:Storage:addToZasoby:click', n, payload);
+jQuery(document).on('p5UIBtnAjax:Storage:addTableToZasoby:click', function(e, n, payload) {
+	console.log('event p5UIBtnAjax:Storage:addTableToZasoby:click', n, payload);
 });
-jQuery(document).on('p5UIBtnAjax:Storage:addToZasoby:ajaxLoaded', function(e, n, payload) {
-	console.log('event p5UIBtnAjax:Storage:addToZasoby:ajaxLoaded', n, payload);
+jQuery(document).on('p5UIBtnAjax:Storage:addTableToZasoby:ajaxLoaded', function(e, n, payload) {
+	console.log('event p5UIBtnAjax:Storage:addTableToZasoby:ajaxLoaded', n, payload);
 	if ('success' == payload.type && payload.body && payload.body.id > 0) {
 		jQuery(n).parents('td').text(payload.body.id);
 	}
@@ -592,7 +700,7 @@ jQuery(document).on('p5UIBtnAjax:Storage:addToZasoby:ajaxLoaded', function(e, n,
 				} else {
 					$tblItem['uwagi'] .= '!Zasob';//'TODO: ADD ZASOB';
 					$ajaxAddZasobLink = Request::getPathUri() . "index.php?_route=Storage&_task=addCellToZasoby&idStorage={$idStorage}&tblName={$tblName}&cellName={$cellName}";
-					$onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addToZasoby', { href: '{$ajaxAddZasobLink}' })";
+					$onClick = "return p5UI__ButtonAjax(this, 'p5UIBtnAjax:Storage:addCellToZasoby', { href: '{$ajaxAddZasobLink}' })";
 					$tblItem['id_zasob'] = '<a onclick="'.$onClick.'" class="btn btn-xs btn-primary" href="#">TODO: ADD ZASOB</a>';
 				}
 				$tableList[] = $tblItem;
@@ -620,13 +728,15 @@ jQuery(document).on('p5UIBtnAjax:Storage:addToZasoby:ajaxLoaded', function(e, n,
 			DBG::table("tableList", $tableList, __CLASS__, __FUNCTION__, __LINE__);
 			?>
 <script>
-jQuery(document).on('p5UIBtnAjax:Storage:addToZasoby:click', function(e, n, payload) {
-	console.log('event p5UIBtnAjax:Storage:addToZasoby:click', n, payload);
+jQuery(document).on('p5UIBtnAjax:Storage:addCellToZasoby:click', function(e, n, payload) {
+	console.log('event p5UIBtnAjax:Storage:addCellToZasoby:click', n, payload);
 });
-jQuery(document).on('p5UIBtnAjax:Storage:addToZasoby:ajaxLoaded', function(e, n, payload) {
-	console.log('event p5UIBtnAjax:Storage:addToZasoby:ajaxLoaded', n, payload);
+jQuery(document).on('p5UIBtnAjax:Storage:addCellToZasoby:ajaxLoaded', function(e, n, payload) {
+	console.log('event p5UIBtnAjax:Storage:addCellToZasoby:ajaxLoaded', n, payload);
 	if ('success' == payload.type && payload.body && payload.body.id > 0) {
-		jQuery(n).parents('td').next('td').text(payload.body.id);
+		var cellUwagi$Node = jQuery(n).parents('td').next('td');
+		cellUwagi$Node.text(cellUwagi$Node.text().replace('!Zasob', ''))
+		jQuery(n).parents('td').text(payload.body.id);
 		jQuery(n).remove();
 	}
 	jQuery.notify(payload.msg, payload.type);
@@ -961,7 +1071,6 @@ jQuery(document).on('p5UIBtnAjax:Storage:addToZasoby:ajaxLoaded', function(e, n,
 	public function addTableToZasobyAction() {// sends JSON
 		$response = new stdClass();
 		try {
-			$response->id = 123; throw new AlertSuccessException("TEST: Utworzono pomyślnie rekord nr 123");
 			$idStorage = V::get('storageId', '', $_GET);
 			$tblName = V::get('tblName', '', $_GET, 'word');
 			if (empty($tblName)) throw new HttpException("Wrong table name");
@@ -1034,7 +1143,6 @@ jQuery(document).on('p5UIBtnAjax:Storage:addToZasoby:ajaxLoaded', function(e, n,
 	public function addCellToZasobyAction() {// sends JSON
 		$response = new stdClass();
 		try {
-			$response->id = 123; throw new AlertSuccessException("TEST: Utworzono pomyślnie rekord nr 123");
 			$idStorage = V::get('storageId', '', $_GET);
 			$tblName = V::get('tblName', '', $_GET, 'word');
 			$cellName = V::get('cellName', '', $_GET, 'word');