| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- <?php
- Lib::loadClass('OBJ');
- Lib::loadClass('Response');
- Lib::loadClass('Router');
- class Route_Storage_TestObj extends RouteBase {
- public function defaultAction() {
- }
- public function objectListAction() {
- UI::gora();
- UI::menu();
- try {
- throw new Exception("TODO...");
- } catch (Exception $e) {
- UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
- }
- UI::dol();
- }
- public function coreObjectListAction() {
- UI::gora();
- UI::menu();
- Router::getRoute('Storage')->navView();
- try {
- $coreObjlist = OBJ::getCoreObjectList();
- $objectList = array();
- foreach ($coreObjlist as $objName) {
- $objItem = array();
- $objItem['name'] = $objName;
- $objItem['struktura'] = UI::h('a', [ 'href' => $this->getLink('coreObjectStruct', [ 'object' => $objName ]) ], "struct");
- // $objItem['label'] = "";// TODO: read from json
- $objectList[] = $objItem;
- }
- usort($objectList, function($rowA, $rowB) {
- $a = $rowA['nazwa']; $b = $rowB['nazwa'];
- if ($a == $b) return 0;
- return ($a < $b) ? -1 : 1;
- });
- DBG::table("objectList", $objectList, __CLASS__, __FUNCTION__, __LINE__);
- } catch (Exception $e) {
- UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
- }
- UI::dol();
- }
- public function checkObjectInstallAjaxAction() {
- $response = array();
- try {
- $objectName = V::get('object', '', $_REQUEST, 'word');
- if (empty($objectName)) throw new Exception("Missing Object name");
- $response['object'] = $objectName;
- $json = OBJ::getCoreObjectFromFile($objectName);
- OBJ::checkInstall($json);
- $response['type'] = 'success';
- $response['msg'] = "OK - object installed";
- } catch (Exception $e) {
- $response['type'] = 'error';
- $response['msg'] = $e->getMessage();
- $response['code'] = $e->getCode();
- $response['line'] = $e->getLine();
- }
- Response::sendJsonExit($response);
- }
- public function coreObjectConnectAction() {
- UI::gora();
- UI::menu();
- Router::getRoute('Storage')->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 = UI::h('a', [ 'href' => $this->getLink('coreObjectStruct', [ 'object' => str_replace('/', '-', $parentName) ]) ], $parentName);
- array_unshift($linksParentList, $parentLink);
- }
- $ajaxCheckInstall = Router::getRoute('Storage_TestObj')->getLink('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>';
- UI::startContainer();
- echo UI::h('h1', [], "Obiekt <code>{$label}</code> <small>{$btnCheckInstall}</small>");
- if (!empty($parentList)) {
- echo UI::h('ol', [ 'class' => "breadcrumb" ], array_merge([
- '<li>Dziedziczy z:</li>',
- ], array_map(function ($parentLink) {
- return "<li>{$parentLink}</li>";
- }, $linksParentList)));
- // <li class="active">Data</li>
- // echo '<p>' . implode(", ", $parentList) . '</p>';
- }
- $tableOne = array();
- $tableOne['caption'] = 'Klasy';
- $tableOne['rows'] = array();
- $parentList = OBJ::getParentList($json);
- $tableOne['rows'][] = array('__primary_key' => $objectName, 'name' => $objectName);
- $linksParentList = array();
- foreach ($parentList as $parentName) {
- // $parentLink = UI::h('a', [ 'href' => $this->getLink('coreObjectStruct', [ 'object' => str_replace('/', '-', $parentName) ]) ], $parentName);
- // array_unshift($linksParentList, $parentLink);
- $tableOne['rows'][] = array('__primary_key' => $parentName, 'name' => $parentName);
- }
- $tableTwo = array();
- $tableTwo['caption'] = 'Rekordy w tabeli głównej';
- $mainTable = OBJ::getMainTableName($json);
- $sqlFields = OBJ::getTableFields($json);
- $tableTwo['rows'] = $this->getTableRows($mainTable, $sqlFields);
- foreach ($tableTwo['rows'] as $idx => $row) {
- // $tableTwo['rows'][] = array('__primary_key' => $objectName, 'name' => $objectName);
- $tableTwo['rows'][$idx]['__primary_key'] = $row['ID'];
- }
- echo '<hr>';
- // 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'));
- UI::endContainer();
- echo UI::h('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);
- });
- ");
- 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 coreObjectStructAction() {
- UI::gora();
- UI::menu();
- Router::getRoute('Storage')->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 = UI::h('a', [ 'href' => $this->getLink('coreObjectStruct', [ 'object' => str_replace('/', '-', $parentName) ]) ], $parentName);
- array_unshift($linksParentList, $parentLink);
- }
- $ajaxCheckInstall = $this->getLink('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>';
- UI::startContainer();
- UI::tag('h1', [], "Obiekt <code>{$label}</code> <small>{$btnCheckInstall}</small>");
- if (!empty($parentList)) {
- UI::startTag('ol', ['class'=>"breadcrumb"]);
- UI::tag('li', [], "Dziedziczy z:");
- foreach ($linksParentList as $parentLink) {
- UI::tag('li', [], $parentLink);
- }
- // <!-- <li class="active">Data</li> -->
- UI::endTag('ol');
- // <!-- <p> implode(", ", $parentList);</p> -->
- }
- // TODO: UI::table(['rows'=>array_map()]);
- $jsonFields = OBJ::getFields($json);
- UI::table([
- 'caption' => "Struktura:",
- 'rows' => array_map(function ($field, $fieldName) {
- return [
- 'nazwa' => $fieldName,
- 'typ' => $field['type'],
- 'label' => $field['label'],
- 'json' => json_encode($field),
- ];
- }, $jsonFields, array_keys($jsonFields))
- ]);
- echo UI::h('a', [ 'class' => "btn btn-primary", 'href' => $this->getLink('coreObjectConnect', [ 'object' => $objectName ]) ], "Przypisz rekordy do klasy");
- $mainTable = OBJ::getMainTableName($json);
- $sqlFields = OBJ::getTableFields($json);
- $this->showTableWidget($mainTable, $sqlFields);
- UI::endContainer();
- echo UI::h('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);
- });
- ");
- 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 coreObjectParseAllAction() {
- UI::gora();
- UI::menu();
- Router::getRoute('Storage')->navView();
- try {
- OBJ::parseAll();
- } catch (Exception $e) {
- UI::alert('danger', "Error #" . $e->getCode() . "|" . $e->getLine() . ": " . $e->getMessage());
- }
- UI::dol();
- }
- 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 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";
- foreach ($tableOne['rows'] as $idx => $r) {
- $tableOne['rows'][$idx]['@onClick'] = "return p5UI__Clickable(this, '{$jsEventNamespace}:tableOne', { primary_key: '{$r['__primary_key']}' });";
- }
- foreach ($tableTwo['rows'] as $idx => $r) {
- $tableTwo['rows'][$idx]['@onClick'] = "return p5UI__Clickable(this, '{$jsEventNamespace}:tableTwo', { primary_key: '{$r['__primary_key']}' });";
- }
- $tableOne['hidden_cols'] = $tableTwo['hidden_cols'] = array('__primary_key', '@onClick', '__html_id');
- $tableTwo['__html_id'] = "{$jsEventNamespace}-table-two";
- ?>
- <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: [],
- 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() {
- jqNodes['total_selected'].text(state.selectedTableTwo.length);
- if (state.selectedTableTwo.length > 0) {
- jQuery(props.stateClearSelectedBtnId).show();
- } else {
- jQuery(props.stateClearSelectedBtnId).hide();
- }
- 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;
- render();
- }
- function action__unselectTableOneRow() {
- state.selectedTableOne = null;
- render();
- }
- function action__selectTableTwoRow(pk) {
- var idx = state.selectedTableTwo.indexOf(pk);
- if (-1 === idx) state.selectedTableTwo.push(pk);
- else console.log("Error selectedTableTwo - should be not set");
- render();
- }
- function action__unselectTableTwoRow(pk) {
- var idx = state.selectedTableTwo.indexOf(pk);
- if (-1 === idx) state.selectedTableTwo.push(pk);
- else state.selectedTableTwo.splice(idx, 1);
- render();
- }
- function action__clearSelection() {
- state.selectedTableTwo = [];
- 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);
- console.log('event '+props.jsEventNamespace+':tableOne:click', n, payload);
- jQuery.notify('tableOne row clicked [' + payload.props.primary_key + ']', 'info');
- if (n$.hasClass('info')) {
- n$.removeClass('info');
- action__unselectTableOneRow();
- } else {
- n$.parent().children('.info').removeClass('info');
- n$.addClass('info');
- action__selectTableOneRow(payload.props.primary_key);
- }
- });
- jQuery(document).on(props.jsEventNamespace + ':tableTwo:click', function(e, n, payload) {
- var n$ = jQuery(n);
- console.log('event '+props.jsEventNamespace+':tableTwo:click', n, payload);
- jQuery.notify('tableTwo row clicked [' + payload.props.primary_key + ']', 'info');
- if (n$.hasClass('info')) {
- n$.removeClass('info');
- action__unselectTableTwoRow(payload.props.primary_key);
- } else {
- n$.addClass('info');
- action__selectTableTwoRow(payload.props.primary_key);
- }
- });
- 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>
- <?php
- }
- }
|