diff --git a/app/Controller/Api/Setup.php b/app/Controller/Api/Setup.php index b436ff06..31f85c78 100644 --- a/app/Controller/Api/Setup.php +++ b/app/Controller/Api/Setup.php @@ -9,8 +9,9 @@ namespace Exodus4D\Pathfinder\Controller\Api; use Exodus4D\Pathfinder\Lib\Config; -use Exodus4D\Pathfinder\Controller; use Exodus4D\Pathfinder\Lib\Cron; +use Exodus4D\Pathfinder\Lib\Format\Number; +use Exodus4D\Pathfinder\Controller; use Exodus4D\Pathfinder\Model; class Setup extends Controller\Controller { @@ -91,7 +92,7 @@ class Setup extends Controller\Controller { ], 'tplCounter' => $this->counter(), 'tplConvertBytes' => function(){ - return call_user_func_array([\lib\format\Number::instance(), 'bytesToString'], func_get_args()); + return call_user_func_array([Number::instance(), 'bytesToString'], func_get_args()); } ]; return \Template::instance()->render('templates/ui/cron_table_row.html', null, $tplData, 0); diff --git a/app/Controller/Setup.php b/app/Controller/Setup.php index faa273af..81d0c650 100644 --- a/app/Controller/Setup.php +++ b/app/Controller/Setup.php @@ -15,6 +15,7 @@ use Exodus4D\Pathfinder\Lib\Db\Sql; use Exodus4D\Pathfinder\Lib\Config; use Exodus4D\Pathfinder\Lib\Cron; use Exodus4D\Pathfinder\Lib\Util; +use Exodus4D\Pathfinder\Lib\Format\Number; use Exodus4D\Pathfinder\Model\Pathfinder; use Exodus4D\Pathfinder\Model\Universe; use Exodus4D\Pathfinder\Controller\Ccp\Universe as UniverseController; @@ -174,7 +175,7 @@ class Setup extends Controller { $f3->set('tplCounter', $this->counter()); $f3->set('tplConvertBytes', function(){ - return call_user_func_array([\lib\format\Number::instance(), 'bytesToString'], func_get_args()); + return call_user_func_array([Number::instance(), 'bytesToString'], func_get_args()); }); // render view @@ -754,20 +755,20 @@ class Setup extends Controller { ], 'maxMemory' => [ 'label' => 'maxmemory', - 'required' => \lib\format\Number::instance()->bytesToString($f3->get('REQUIREMENTS.REDIS.MAX_MEMORY')), - 'version' => \lib\format\Number::instance()->bytesToString($redisMemoryInfo['maxmemory']), + 'required' => Number::instance()->bytesToString($f3->get('REQUIREMENTS.REDIS.MAX_MEMORY')), + 'version' => Number::instance()->bytesToString($redisMemoryInfo['maxmemory']), 'check' => $redisMemoryInfo['maxmemory'] >= $f3->get('REQUIREMENTS.REDIS.MAX_MEMORY'), 'tooltip' => 'Max memory limit for Redis' ], 'usedMemory' => [ 'label' => 'used_memory', - 'version' => \lib\format\Number::instance()->bytesToString($redisMemoryInfo['used_memory']), + 'version' => Number::instance()->bytesToString($redisMemoryInfo['used_memory']), 'check' => $redisMemoryInfo['used_memory'] < $redisMemoryInfo['maxmemory'], 'tooltip' => 'Current memory used by Redis' ], 'usedMemoryPeak' => [ 'label' => 'used_memory_peak', - 'version' => \lib\format\Number::instance()->bytesToString($redisMemoryInfo['used_memory_peak']), + 'version' => Number::instance()->bytesToString($redisMemoryInfo['used_memory_peak']), 'check' => $redisMemoryInfo['used_memory_peak'] <= $redisMemoryInfo['maxmemory'], 'tooltip' => 'Peak memory used by Redis' ], @@ -1125,7 +1126,7 @@ class Setup extends Controller { // get table data from model foreach($dbData['models'] as $model){ - $tableConfig = call_user_func($model . '::resolveConfiguration'); + $tableConfig = call_user_func(Config::withNamespace($model) . '::resolveConfiguration'); $requiredTables[$tableConfig['table']] = [ 'model' => $model, 'name' => $tableConfig['table'], @@ -1221,7 +1222,7 @@ class Setup extends Controller { $currentColType = $currentColumns[$columnName]['type']; $currentNullable = $currentColumns[$columnName]['nullable']; $hasNullable = $currentNullable ? '1' : '0'; - $currentColIndexData = call_user_func($data['model'] . '::indexExists', [$columnName]); + $currentColIndexData = call_user_func(Config::withNamespace($data['model']) . '::indexExists', [$columnName]); $currentColIndex = is_array($currentColIndexData); $hasIndex = ($currentColIndex) ? '1' : '0'; $hasUnique = ($currentColIndexData['unique']) ? '1' : '0'; @@ -1938,7 +1939,7 @@ class Setup extends Controller { } $bytesAll += $bytes; - $dirAll[$key]['size'] = ($maxHit ? '>' : '') . \lib\format\Number::instance()->bytesToString($bytes); + $dirAll[$key]['size'] = ($maxHit ? '>' : '') . Number::instance()->bytesToString($bytes); $dirAll[$key]['task'] = [ [ 'action' => http_build_query([ @@ -1953,7 +1954,7 @@ class Setup extends Controller { } return [ - 'sizeAll' => ($maxHitAll ? '>' : '') . \lib\format\Number::instance()->bytesToString($bytesAll), + 'sizeAll' => ($maxHitAll ? '>' : '') . Number::instance()->bytesToString($bytesAll), 'dirAll' => $dirAll ]; } diff --git a/app/Cron/AbstractCron.php b/app/Cron/AbstractCron.php index c14bcad6..2413a866 100644 --- a/app/Cron/AbstractCron.php +++ b/app/Cron/AbstractCron.php @@ -8,6 +8,7 @@ namespace Exodus4D\Pathfinder\Cron; +use Exodus4D\Pathfinder\Lib\Format\Number; use Exodus4D\Pathfinder\Model\Pathfinder; abstract class AbstractCron { @@ -201,7 +202,7 @@ abstract class AbstractCron { $text = sprintf(self::LOG_TEXT_BASE, $state['count'], $state['importCount'], $percent, $state['total'], - \lib\format\Number::instance()->bytesToString($memPeak), $duration + Number::instance()->bytesToString($memPeak), $duration ); $text .= $logText ? $logText: ''; diff --git a/app/Lib/Config.php b/app/Lib/Config.php index 249723cb..a422a6cf 100644 --- a/app/Lib/Config.php +++ b/app/Lib/Config.php @@ -569,7 +569,7 @@ class Config extends \Prefab { if($matches = (bool)preg_match('/^(\w+)\h*=\h*(.+)/', strtolower(trim($dsn)), $parts)){ $conf['type'] = $parts[1]; if($conf['type'] == 'redis'){ - list($conf['host'], $conf['port'], $conf['db']) = explode(':', $parts[2]) + [1 => 6379, 2 => null]; + [$conf['host'], $conf['port'], $conf['db']] = explode(':', $parts[2]) + [1 => 6379, 2 => null]; }elseif($conf['type'] == 'folder'){ $conf['folder'] = $parts[2]; } @@ -641,6 +641,11 @@ class Config extends \Prefab { return $format; } + /** + * @param $fromExists + * @param int $ttlMax + * @return int + */ static function ttlLeft($fromExists, int $ttlMax) : int { $ttlMax = max($ttlMax, 0); if($fromExists){ @@ -655,4 +660,16 @@ class Config extends \Prefab { return $ttlMax; } } + + /** + * @param string|null $class + * @return string + */ + static function withNamespace(?string $class) : string { + $path = [\Base::instance()->get('NAMESPACE')]; + if($class){ + $path[] = $class; + } + return implode('\\', $path); + } } \ No newline at end of file diff --git a/app/Lib/Format/Number.php b/app/Lib/Format/Number.php index d75ea610..edb66400 100644 --- a/app/Lib/Format/Number.php +++ b/app/Lib/Format/Number.php @@ -1,7 +1,7 @@ showError -UNLOAD = Exodus4D\Pathfinder\Controller\Controller->unload +ONERROR = {{ @NAMESPACE }}\Controller\Controller->showError +UNLOAD = {{ @NAMESPACE }}\Controller\Controller->unload ; Path configurations ============================================================================= ; All path configurations are relative to BASE dir and should NOT be changed diff --git a/app/cron.ini b/app/cron.ini index de4f53d7..f7c841e1 100644 --- a/app/cron.ini +++ b/app/cron.ini @@ -25,48 +25,48 @@ downtime = 0 11 * * * [CRON.jobs] ; delete EOL connections -deleteEolConnections = Cron\MapUpdate->deleteEolConnections, @fiveMinutes +deleteEolConnections = {{ @NAMESPACE }}\Cron\MapUpdate->deleteEolConnections, @fiveMinutes ; delete expired wh connections -deleteExpiredConnections = Cron\MapUpdate->deleteExpiredConnections, @hourly +deleteExpiredConnections = {{ @NAMESPACE }}\Cron\MapUpdate->deleteExpiredConnections, @hourly ; delete character log data -deleteLogData = Cron\CharacterUpdate->deleteLogData, @instant +deleteLogData = {{ @NAMESPACE }}\Cron\CharacterUpdate->deleteLogData, @instant ; delete expired signatures -deleteSignatures = Cron\MapUpdate->deleteSignatures, @halfHour +deleteSignatures = {{ @NAMESPACE }}\Cron\MapUpdate->deleteSignatures, @halfHour ; import system data (jump, kill,..) from CCP API -importSystemData = Cron\CcpSystemsUpdate->importSystemData, @halfPastHour +importSystemData = {{ @NAMESPACE }}\Cron\CcpSystemsUpdate->importSystemData, @halfPastHour ; disable outdated maps -deactivateMapData = Cron\MapUpdate->deactivateMapData, @hourly +deactivateMapData = {{ @NAMESPACE }}\Cron\MapUpdate->deactivateMapData, @hourly ; clean up character data (kick, ban,..) -cleanUpCharacterData = Cron\CharacterUpdate->cleanUpCharacterData, @hourly +cleanUpCharacterData = {{ @NAMESPACE }}\Cron\CharacterUpdate->cleanUpCharacterData, @hourly ; delete disabled maps -deleteMapData = Cron\MapUpdate->deleteMapData, @downtime +deleteMapData = {{ @NAMESPACE }}\Cron\MapUpdate->deleteMapData, @downtime ; delete expired character cookie authentication data -deleteAuthenticationData = Cron\CharacterUpdate->deleteAuthenticationData, @downtime +deleteAuthenticationData = {{ @NAMESPACE }}\Cron\CharacterUpdate->deleteAuthenticationData, @downtime ; delete expired cache files -deleteExpiredCacheData = Cron\Cache->deleteExpiredCacheData, @downtime +deleteExpiredCacheData = {{ @NAMESPACE }}\Cron\Cache->deleteExpiredCacheData, @downtime ; delete old statistics (activity log) data -deleteStatisticsData = Cron\StatisticsUpdate->deleteStatisticsData, @weekly +deleteStatisticsData = {{ @NAMESPACE }}\Cron\StatisticsUpdate->deleteStatisticsData, @weekly ; truncate map history log files -truncateMapHistoryLogFiles = Cron\MapHistory->truncateMapHistoryLogFiles, @halfHour +truncateMapHistoryLogFiles = {{ @NAMESPACE }}\Cron\MapHistory->truncateMapHistoryLogFiles, @halfHour ; sync "sovereignty" and "faction warfare" data from CCP´s ESI API -updateSovereigntyData = Cron\Universe->updateSovereigntyData, @halfPastHour +updateSovereigntyData = {{ @NAMESPACE }}\Cron\Universe->updateSovereigntyData, @halfPastHour ; sync static system data from CCP´s ESI API ; -> Job is WIP! -;updateUniverseSystems = Cron\Universe->updateUniverseSystems, @instant +;updateUniverseSystems = {{ @NAMESPACE }}\Cron\Universe->updateUniverseSystems, @instant ; bootstrap job for "eve_universe" DB from CCP´s ESI API ; -> Only for development! This job is used to build the initial export/sql/eve_universe.sql -;setup = Cron\Universe->setup, @instant \ No newline at end of file +;setup = {{ @NAMESPACE }}\Cron\Universe->setup, @instant \ No newline at end of file diff --git a/app/routes.ini b/app/routes.ini index 5b4ce3cf..07dafbd5 100644 --- a/app/routes.ini +++ b/app/routes.ini @@ -3,25 +3,25 @@ [routes] ; DB setup setup ; IMPORTANT: remove/comment this line after setup/update is finished! -GET @setup: /setup [sync] = Exodus4D\Pathfinder\Controller\Setup->init +GET @setup: /setup [sync] = {{ @NAMESPACE }}\Controller\Setup->init ; login (index) page -GET @login: / [sync] = Exodus4D\Pathfinder\Controller\AppController->init +GET @login: / [sync] = {{ @NAMESPACE }}\Controller\AppController->init ; CCP SSO redirect -GET @sso: /sso/@action [sync] = Exodus4D\Pathfinder\Controller\Ccp\Sso->@action +GET @sso: /sso/@action [sync] = {{ @NAMESPACE }}\Controller\Ccp\Sso->@action ; map page -GET @map: /map* [sync] = Exodus4D\Pathfinder\Controller\MapController->init +GET @map: /map* [sync] = {{ @NAMESPACE }}\Controller\MapController->init ; admin panel -GET @admin: /admin* [sync] = Exodus4D\Pathfinder\Controller\Admin->dispatch +GET @admin: /admin* [sync] = {{ @NAMESPACE }}\Controller\Admin->dispatch ; AJAX API wildcard endpoints (not cached, throttled) -GET|POST /api/@controller/@action [ajax] = Exodus4D\Pathfinder\Controller\Api\@controller->@action, 0, 512 -GET|POST /api/@controller/@action/@arg1 [ajax] = Exodus4D\Pathfinder\Controller\Api\@controller->@action, 0, 512 -GET|POST /api/@controller/@action/@arg1/@arg2 [ajax] = Exodus4D\Pathfinder\Controller\Api\@controller->@action, 0, 512 +GET|POST /api/@controller/@action [ajax] = {{ @NAMESPACE }}\Controller\Api\@controller->@action, 0, 512 +GET|POST /api/@controller/@action/@arg1 [ajax] = {{ @NAMESPACE }}\Controller\Api\@controller->@action, 0, 512 +GET|POST /api/@controller/@action/@arg1/@arg2 [ajax] = {{ @NAMESPACE }}\Controller\Api\@controller->@action, 0, 512 ; onUnload route or final map sync (@see https://developer.mozilla.org/docs/Web/API/Navigator/sendBeacon) -POST /api/map/updateUnloadData = Exodus4D\Pathfinder\Controller\Api\map->updateUnloadData, 0, 512 +POST /api/map/updateUnloadData = {{ @NAMESPACE }}\Controller\Api\map->updateUnloadData, 0, 512 [maps] ; REST API wildcard endpoints (not cached, throttled) -/api/rest/@controller* [ajax] = Exodus4D\Pathfinder\Controller\Api\Rest\@controller, 0, 512 -/api/rest/@controller/@id [ajax] = Exodus4D\Pathfinder\Controller\Api\Rest\@controller, 0, 512 \ No newline at end of file +/api/rest/@controller* [ajax] = {{ @NAMESPACE }}\Controller\Api\Rest\@controller, 0, 512 +/api/rest/@controller/@id [ajax] = {{ @NAMESPACE }}\Controller\Api\Rest\@controller, 0, 512 \ No newline at end of file diff --git a/index.php b/index.php index 1bfbc12a..b79b4c84 100644 --- a/index.php +++ b/index.php @@ -11,6 +11,7 @@ if(file_exists($composerAutoloader)){ } $f3 = \Base::instance(); +$f3->set('NAMESPACE', __NAMESPACE__); // load main config $f3->config('app/config.ini', true); diff --git a/js/app/ui/dialog/map_info.js b/js/app/ui/dialog/map_info.js index 6ac3bb80..357d384d 100644 --- a/js/app/ui/dialog/map_info.js +++ b/js/app/ui/dialog/map_info.js @@ -202,315 +202,322 @@ define([ * @param mapData */ $.fn.initSystemInfoTable = function(mapData){ - let systemsElement = $(this).empty(); + let tableApi = Util.getDataTableInstance(config.tableId, mapData.config.id, '', 'systems'); - let systemTable = $('', { - id: Util.getTableId(config.tableId, 'systems', mapData.config.id, ''), - class: ['compact', 'stripe', 'order-column', 'row-border'].join(' ') - }); - systemsElement.append(systemTable); + if(tableApi){ + tableApi.clear(); + tableApi.rows.add(mapData.data.systems); + tableApi.draw(); + }else{ + let systemsElement = $(this); - systemsElement.showLoadingAnimation(config.loadingOptions); + let systemTable = $('
', { + id: Util.getTableId(config.tableId, 'systems', mapData.config.id, ''), + class: ['compact', 'stripe', 'order-column', 'row-border'].join(' ') + }); + systemsElement.append(systemTable); - systemTable.on('init.dt', function(){ - systemsElement.hideLoadingAnimation(); + systemsElement.showLoadingAnimation(config.loadingOptions); - // init table tooltips - let tooltipElements = systemsElement.find('[data-toggle="tooltip"]'); - tooltipElements.tooltip(); - }); + systemTable.on('init.dt', function(){ + systemsElement.hideLoadingAnimation(); - let systemsDataTable = systemTable.DataTable({ - pageLength: 20, - paging: true, - lengthMenu: [[5, 10, 20, 50, -1], [5, 10, 20, 50, 'All']], - ordering: true, - order: [15, 'desc'], - hover: false, - data: mapData.data.systems, - columnDefs: [], - language: { - emptyTable: 'Map is empty', - zeroRecords: 'No systems found', - lengthMenu: 'Show _MENU_ systems', - info: 'Showing _START_ to _END_ of _TOTAL_ systems' - }, - columns: [ - { - name: 'type', - title: 'type', - width: 25, - className: ['min-screen-l'].join(' '), - data: 'type', - render: { - _: (cellData, type, rowData, meta) => { - return MapUtil.getSystemTypeInfo(cellData.id, 'name'); - } - } - },{ - name: 'security', - title: '', - width: 1, - data: 'security', - render: { - display: (cellData, type, rowData, meta) => { - let securityClass = Util.getSecurityClassForSystem(cellData); - return '' + cellData + ''; - } - } - },{ - name: 'trueSec', - title: 'sec', - width: 18, - className: ['text-center', 'min-screen-l'].join(' '), - searchable: false, - data: 'trueSec', - render: { - display: (cellData, type, rowData, meta) => { - let systemTrueSecClass = Util.getTrueSecClassForSystem(cellData); - return '' + cellData.toFixed(1) + ''; - } - } - },{ - name: 'shattered', - title: '', - width: 10, - className: ['text-center', 'min-screen-l'].join(' '), - searchable: false, - data: 'shattered', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - if(cellData){ - value = ''; + // init table tooltips + let tooltipElements = systemsElement.find('[data-toggle="tooltip"]'); + tooltipElements.tooltip(); + }); + + let systemsDataTable = systemTable.DataTable({ + pageLength: 20, + paging: true, + lengthMenu: [[5, 10, 20, 50, -1], [5, 10, 20, 50, 'All']], + ordering: true, + order: [15, 'desc'], + hover: false, + data: mapData.data.systems, + columnDefs: [], + language: { + emptyTable: 'Map is empty', + zeroRecords: 'No systems found', + lengthMenu: 'Show _MENU_ systems', + info: 'Showing _START_ to _END_ of _TOTAL_ systems' + }, + columns: [ + { + name: 'type', + title: 'type', + width: 25, + className: ['min-screen-l'].join(' '), + data: 'type', + render: { + _: (cellData, type, rowData, meta) => { + return MapUtil.getSystemTypeInfo(cellData.id, 'name'); } - return value; } - } - },{ - name: 'name', - title: 'system', - data: 'name', - className: [config.tableCellLinkClass].join(' '), - createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ - // select system - $(cell).on('click', function(e){ - Util.triggerMenuAction(Util.getMapModule().getActiveMap(), 'SelectSystem', {systemId: rowData.id}); - }); - } - },{ - name: 'alias', - title: 'alias', - data: 'alias', - render: { - _: (cellData, type, rowData, meta) => { - return (cellData === rowData.name) ? '' : cellData; - } - } - },{ - name: 'region', - title: 'region', - data: 'region.name', - className: 'min-screen-l', - },{ - name: 'sovereignty', - title: 'sov.', - width: 30, - className: 'text-center', - data: 'sovereignty.alliance.ticker', - defaultContent: '', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - if(cellData){ - value = '<' + cellData + '>'; + },{ + name: 'security', + title: '', + width: 1, + data: 'security', + render: { + display: (cellData, type, rowData, meta) => { + let securityClass = Util.getSecurityClassForSystem(cellData); + return '' + cellData + ''; } - return value; } - } - },{ - name: 'planets', - title: '', - width: 10, - className: ['text-right', config.systemInfoPlanetsClass, Util.config.helpDefaultClass, Util.config.popoverTriggerClass].join(' '), - searchable: false, - orderSequence: ['desc', 'asc'], - data: 'planets', - render: { - _: (cellData, type, rowData, meta) => { - return cellData.length; - } - } - },{ - name: 'status', - title: '', - width: 10, - className: 'text-center', - searchable: false, - data: 'status.id', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - let systemStatusClass = Util.getStatusInfoForSystem(cellData, 'class'); - if(systemStatusClass !== ''){ - value = ''; + },{ + name: 'trueSec', + title: 'sec', + width: 18, + className: ['text-center', 'min-screen-l'].join(' '), + searchable: false, + data: 'trueSec', + render: { + display: (cellData, type, rowData, meta) => { + let systemTrueSecClass = Util.getTrueSecClassForSystem(cellData); + return '' + cellData.toFixed(1) + ''; } - return value; } - } - },{ - name: 'effect', - title: '', - width: 10, - className: 'text-center', - searchable: false, - data: 'effect', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - let systemEffectClass = MapUtil.getEffectInfoForSystem(cellData, 'class'); - if(systemEffectClass !== ''){ - value = ''; - } - return value; - } - } - },{ - name: 'statics', - title: 'statics', - width: 30, - searchable: false, - data: 'statics', - render: { - _: (cellData, type, rowData, meta) => { - let statics = []; - for(let wormholeName of cellData){ - let wormholeData = Object.assign({}, Init.wormholes[wormholeName]); - statics.push('' + wormholeData.security + ''); - } - return statics.join('  '); - } - } - },{ - name: 'position', - title: '', - width: 8, - className: 'text-center', - searchable: false, - data: 'currentUser', - defaultContent: false, - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - if(cellData === true){ - value = ''; - } - return value; - } - } - },{ - name: 'userCount', - title: '', - width: 12, - className: 'text-center', - searchable: false, - data: 'userCount', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - if(cellData > 0){ - value = cellData; - } - return value; - } - } - },{ - name: 'locked', - title: '', - width: 10, - className: 'text-center', - searchable: false, - data: 'locked', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - if(cellData === 1){ - value = ''; - } - return value; - } - } - },{ - name: 'updated', - title: 'updated', - width: 80, - searchable: false, - className: ['text-right', config.tableCellCounterClass].join(' '), - data: 'updated.updated', - defaultContent: '', - },{ - name: 'action', - title: '', - orderable: false, - searchable: false, - width: 10, - className: ['text-center', config.tableCellActionClass].join(' '), - data: null, - defaultContent: '', - createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ - let tempTableElement = this; - - let confirmationSettings = { - placement: 'left', - title: 'Delete system', - template: Util.getConfirmationTemplate(null, { - size: 'small', - noTitle: true - }), - onConfirm: function(e, target){ - let deleteRowElement = $(target).parents('tr'); - - let activeMap = Util.getMapModule().getActiveMap(); - let systemElement = $('#' + MapUtil.getSystemId(mapData.config.id, rowData.id) ); - - if(systemElement.length){ - // trigger system delete event - activeMap.trigger('pf:deleteSystems', [{ - systems: [systemElement[0]], - callback: function(deletedSystems){ - // callback function after ajax "delete" success - // check if system was deleted - if(deletedSystems.length === 1){ - // remove table row - tempTableElement.DataTable().rows(deleteRowElement).remove().draw(); - - Util.showNotify({title: 'System deleted', text: rowData.name, type: 'success'}); - - // refresh connection table (connections might have changed) -------------- - let connectionsElement = $('#' + config.mapInfoConnectionsId); - let mapDataNew = activeMap.getMapDataFromClient(['hasId']); - - connectionsElement.initConnectionInfoTable(mapDataNew); - }else{ - // error - Util.showNotify({title: 'Failed to delete system', text: rowData.name, type: 'error'}); - } - } - }]); + },{ + name: 'shattered', + title: '', + width: 10, + className: ['text-center', 'min-screen-l'].join(' '), + searchable: false, + data: 'shattered', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + if(cellData){ + value = ''; } + return value; } - }; + } + },{ + name: 'name', + title: 'system', + data: 'name', + className: [config.tableCellLinkClass].join(' '), + createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ + // select system + $(cell).on('click', function(e){ + Util.triggerMenuAction(Util.getMapModule().getActiveMap(), 'SelectSystem', {systemId: rowData.id}); + }); + } + },{ + name: 'alias', + title: 'alias', + data: 'alias', + render: { + _: (cellData, type, rowData, meta) => { + return (cellData === rowData.name) ? '' : cellData; + } + } + },{ + name: 'region', + title: 'region', + data: 'region.name', + className: 'min-screen-l', + },{ + name: 'sovereignty', + title: 'sov.', + width: 30, + className: 'text-center', + data: 'sovereignty.alliance.ticker', + defaultContent: '', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + if(cellData){ + value = '<' + cellData + '>'; + } + return value; + } + } + },{ + name: 'planets', + title: '', + width: 10, + className: ['text-right', config.systemInfoPlanetsClass, Util.config.helpDefaultClass, Util.config.popoverTriggerClass].join(' '), + searchable: false, + orderSequence: ['desc', 'asc'], + data: 'planets', + render: { + _: (cellData, type, rowData, meta) => { + return cellData.length; + } + } + },{ + name: 'status', + title: '', + width: 10, + className: 'text-center', + searchable: false, + data: 'status.id', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + let systemStatusClass = Util.getStatusInfoForSystem(cellData, 'class'); + if(systemStatusClass !== ''){ + value = ''; + } + return value; + } + } + },{ + name: 'effect', + title: '', + width: 10, + className: 'text-center', + searchable: false, + data: 'effect', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + let systemEffectClass = MapUtil.getEffectInfoForSystem(cellData, 'class'); + if(systemEffectClass !== ''){ + value = ''; + } + return value; + } + } + },{ + name: 'statics', + title: 'statics', + width: 30, + searchable: false, + data: 'statics', + render: { + _: (cellData, type, rowData, meta) => { + let statics = []; + for(let wormholeName of cellData){ + let wormholeData = Object.assign({}, Init.wormholes[wormholeName]); + statics.push('' + wormholeData.security + ''); + } + return statics.join('  '); + } + } + },{ + name: 'position', + title: '', + width: 8, + className: 'text-center', + searchable: false, + data: 'currentUser', + defaultContent: false, + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + if(cellData === true){ + value = ''; + } + return value; + } + } + },{ + name: 'userCount', + title: '', + width: 12, + className: 'text-center', + searchable: false, + data: 'userCount', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + if(cellData > 0){ + value = cellData; + } + return value; + } + } + },{ + name: 'locked', + title: '', + width: 10, + className: 'text-center', + searchable: false, + data: 'locked', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + if(cellData === 1){ + value = ''; + } + return value; + } + } + },{ + name: 'updated', + title: 'updated', + width: 80, + searchable: false, + className: ['text-right', config.tableCellCounterClass].join(' '), + data: 'updated.updated', + defaultContent: '', + },{ + name: 'action', + title: '', + orderable: false, + searchable: false, + width: 10, + className: ['text-center', config.tableCellActionClass].join(' '), + data: null, + defaultContent: '', + createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ + let tempTableElement = this; - // init confirmation dialog - $(cell).confirmation(confirmationSettings); + let confirmationSettings = { + placement: 'left', + title: 'Delete system', + template: Util.getConfirmationTemplate(null, { + size: 'small', + noTitle: true + }), + onConfirm: function(e, target){ + let deleteRowElement = $(target).parents('tr'); + + let activeMap = Util.getMapModule().getActiveMap(); + let systemElement = $('#' + MapUtil.getSystemId(mapData.config.id, rowData.id) ); + + if(systemElement.length){ + // trigger system delete event + activeMap.trigger('pf:deleteSystems', [{ + systems: [systemElement[0]], + callback: function(deletedSystems){ + // callback function after ajax "delete" success + // check if system was deleted + if(deletedSystems.length === 1){ + // remove table row + tempTableElement.DataTable().rows(deleteRowElement).remove().draw(); + + Util.showNotify({title: 'System deleted', text: rowData.name, type: 'success'}); + + // refresh connection table (connections might have changed) -------------- + let connectionsElement = $('#' + config.mapInfoConnectionsId); + let mapDataNew = activeMap.getMapDataFromClient(['hasId']); + + connectionsElement.initConnectionInfoTable(mapDataNew); + }else{ + // error + Util.showNotify({title: 'Failed to delete system', text: rowData.name, type: 'error'}); + } + } + }]); + } + } + }; + + // init confirmation dialog + $(cell).confirmation(confirmationSettings); + } } + ], + initComplete: function(settings){ + Counter.initTableCounter(this, ['updated:name']); } - ], - initComplete: function(settings){ - Counter.initTableCounter(this, ['updated:name']); - } - }); - + }); + } }; /** @@ -518,179 +525,188 @@ define([ * @param mapData */ $.fn.initConnectionInfoTable = function(mapData){ - let connectionsElement = $(this).empty(); + let tableApi = Util.getDataTableInstance(config.tableId, mapData.config.id, '', 'connections'); - let connectionTable = $('
', { - class: ['compact', 'stripe', 'order-column', 'row-border'].join(' ') - }); - connectionsElement.append(connectionTable); + if(tableApi){ + tableApi.clear(); + tableApi.rows.add(mapData.data.connections); + tableApi.draw(); + }else{ + let connectionsElement = $(this); - connectionsElement.showLoadingAnimation(config.loadingOptions); + let connectionTable = $('
', { + id: Util.getTableId(config.tableId, 'connections', mapData.config.id, ''), + class: ['compact', 'stripe', 'order-column', 'row-border'].join(' ') + }); + connectionsElement.append(connectionTable); - // table init complete - connectionTable.on('init.dt', function(){ - connectionsElement.hideLoadingAnimation(); + connectionsElement.showLoadingAnimation(config.loadingOptions); - // init table tooltips - let tooltipElements = connectionsElement.find('[data-toggle="tooltip"]'); - tooltipElements.tooltip(); - }); + // table init complete + connectionTable.on('init.dt', function(){ + connectionsElement.hideLoadingAnimation(); - // connections table ------------------------------------------------------------------------------------------ - let connectionDataTable = connectionTable.dataTable({ - pageLength: 20, - paging: true, - lengthMenu: [[5, 10, 20, 50, -1], [5, 10, 20, 50, 'All']], - ordering: true, - order: [ 6, 'desc' ], - autoWidth: false, - hover: false, - data: mapData.data.connections, - columnDefs: [], - language: { - emptyTable: 'No connections', - zeroRecords: 'No connections found', - lengthMenu: 'Show _MENU_ connections', - info: 'Showing _START_ to _END_ of _TOTAL_ connections' - }, - columns: [ - { - name: 'scope', - title: 'scope', - width: 50, - orderable: true, - data: 'scope', - render: { - display: (cellData, type, rowData, meta) => { - return MapUtil.getScopeInfoForConnection(cellData, 'label'); - } - } - },{ - name: 'sourceName', - title: 'source system', - data: 'sourceName', - className: [config.tableCellLinkClass].join(' '), - createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ - // select system - $(cell).on('click', function(e){ - Util.triggerMenuAction(Util.getMapModule().getActiveMap(), 'SelectSystem', {systemId: rowData.source}); - }); - } - },{ - name: 'sourceBubble', - title: '', - width: 10, - data: 'endpoints.source', - className: 'text-right', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - if(cellData.types.includes('bubble')){ - value = ''; - } - return value; - } - } - },{ - name: 'connection', - title: 'connection', - width: 80, - className: 'text-center', - orderable: false, - searchable: false, - data: 'type', - render: { - display: (cellData, type, rowData, meta) => { - let connectionClasses = MapUtil.getConnectionFakeClassesByTypes(cellData); - connectionClasses = connectionClasses.join(' '); - return '
'; - } - } - },{ - name: 'targetBubble', - title: '', - width: 10, - data: 'endpoints.target', - className: 'text-left', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - if(cellData.types.includes('bubble')){ - value = ''; - } - return value; - } - } - },{ - name: 'targetName', - title: 'target system', - data: 'targetName', - className: [config.tableCellLinkClass].join(' '), - createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ - // select system - $(cell).on('click', function(e){ - Util.triggerMenuAction(Util.getMapModule().getActiveMap(), 'SelectSystem', {systemId: rowData.target}); - }); - } - },{ - name: 'updated', - title: 'updated', - width: 80, - searchable: false, - className: ['text-right', config.tableCellCounterClass].join(' '), - data: 'updated', - createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ - if(rowData.scope.scope_sort === 'wh'){ - // highlight cell - let diff = new Date().getTime() - cellData * 1000; - let dateDiff = new Date(diff); - if(dateDiff.getUTCDate() > 1){ - $(cell).addClass('txt-color txt-color-warning'); + // init table tooltips + let tooltipElements = connectionsElement.find('[data-toggle="tooltip"]'); + tooltipElements.tooltip(); + }); + + // connections table ------------------------------------------------------------------------------------------ + let connectionDataTable = connectionTable.dataTable({ + pageLength: 20, + paging: true, + lengthMenu: [[5, 10, 20, 50, -1], [5, 10, 20, 50, 'All']], + ordering: true, + order: [ 6, 'desc' ], + autoWidth: false, + hover: false, + data: mapData.data.connections, + columnDefs: [], + language: { + emptyTable: 'No connections', + zeroRecords: 'No connections found', + lengthMenu: 'Show _MENU_ connections', + info: 'Showing _START_ to _END_ of _TOTAL_ connections' + }, + columns: [ + { + name: 'scope', + title: 'scope', + width: 50, + orderable: true, + data: 'scope', + render: { + display: (cellData, type, rowData, meta) => { + return MapUtil.getScopeInfoForConnection(cellData, 'label'); } } - } - },{ - name: 'action', - title: '', - orderable: false, - searchable: false, - width: 10, - className: ['text-center', config.tableCellActionClass].join(' '), - data: null, - defaultContent: '', - createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ - let tempTableElement = this; - - let confirmationSettings = { - placement: 'left', - title: 'Delete connection', - template: Util.getConfirmationTemplate(null, { - size: 'small', - noTitle: true - }), - onConfirm: function(e, target){ - let deleteRowElement = $(target).parents('tr'); - - // deleteSignatures(row); - let connection = $().getConnectionById(mapData.config.id, rowData.id); - - MapUtil.deleteConnections([connection], () => { - // callback function after ajax "delete" success - // remove table row - tempTableElement.DataTable().rows(deleteRowElement).remove().draw(); - }); + },{ + name: 'sourceName', + title: 'source system', + data: 'sourceName', + className: [config.tableCellLinkClass].join(' '), + createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ + // select system + $(cell).on('click', function(e){ + Util.triggerMenuAction(Util.getMapModule().getActiveMap(), 'SelectSystem', {systemId: rowData.source}); + }); + } + },{ + name: 'sourceBubble', + title: '', + width: 10, + data: 'endpoints.source', + className: 'text-right', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + if(cellData.types.includes('bubble')){ + value = ''; + } + return value; } - }; + } + },{ + name: 'connection', + title: 'connection', + width: 80, + className: 'text-center', + orderable: false, + searchable: false, + data: 'type', + render: { + display: (cellData, type, rowData, meta) => { + let connectionClasses = MapUtil.getConnectionFakeClassesByTypes(cellData); + connectionClasses = connectionClasses.join(' '); + return '
'; + } + } + },{ + name: 'targetBubble', + title: '', + width: 10, + data: 'endpoints.target', + className: 'text-left', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + if(cellData.types.includes('bubble')){ + value = ''; + } + return value; + } + } + },{ + name: 'targetName', + title: 'target system', + data: 'targetName', + className: [config.tableCellLinkClass].join(' '), + createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ + // select system + $(cell).on('click', function(e){ + Util.triggerMenuAction(Util.getMapModule().getActiveMap(), 'SelectSystem', {systemId: rowData.target}); + }); + } + },{ + name: 'updated', + title: 'updated', + width: 80, + searchable: false, + className: ['text-right', config.tableCellCounterClass].join(' '), + data: 'updated', + createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ + if(rowData.scope.scope_sort === 'wh'){ + // highlight cell + let diff = new Date().getTime() - cellData * 1000; + let dateDiff = new Date(diff); + if(dateDiff.getUTCDate() > 1){ + $(cell).addClass('txt-color txt-color-warning'); + } + } + } + },{ + name: 'action', + title: '', + orderable: false, + searchable: false, + width: 10, + className: ['text-center', config.tableCellActionClass].join(' '), + data: null, + defaultContent: '', + createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ + let tempTableElement = this; - // init confirmation dialog - $(cell).confirmation(confirmationSettings); + let confirmationSettings = { + placement: 'left', + title: 'Delete connection', + template: Util.getConfirmationTemplate(null, { + size: 'small', + noTitle: true + }), + onConfirm: function(e, target){ + let deleteRowElement = $(target).parents('tr'); + + // deleteSignatures(row); + let connection = $().getConnectionById(mapData.config.id, rowData.id); + + MapUtil.deleteConnections([connection], () => { + // callback function after ajax "delete" success + // remove table row + tempTableElement.DataTable().rows(deleteRowElement).remove().draw(); + }); + } + }; + + // init confirmation dialog + $(cell).confirmation(confirmationSettings); + } } + ], + initComplete: function(settings){ + Counter.initTableCounter(this, ['updated:name']); } - ], - initComplete: function(settings){ - Counter.initTableCounter(this, ['updated:name']); - } - }); + }); + } }; /** diff --git a/js/app/ui/dialog/map_settings.js b/js/app/ui/dialog/map_settings.js index 56389ea0..9130edee 100644 --- a/js/app/ui/dialog/map_settings.js +++ b/js/app/ui/dialog/map_settings.js @@ -22,11 +22,13 @@ define([ dialogMapDownloadContainerId: 'pf-map-dialog-download', // id for the "download" container // new map form + newNameInputId: 'pf-map-dialog-new-name-input', // id for "name" input newIconSelectId: 'pf-map-dialog-new-icon-select', // id for "icon" select newScopeSelectId: 'pf-map-dialog-new-scope-select', // id for "scope" select newTypeSelectId: 'pf-map-dialog-new-type-select', // id for "type" select // edit map form + editNameInputId: 'pf-map-dialog-edit-name-input', // id for "name" input editIconSelectId: 'pf-map-dialog-edit-icon-select', // id for "icon" select editScopeSelectId: 'pf-map-dialog-edit-scope-select', // id for "scope" select editTypeSelectId: 'pf-map-dialog-edit-type-select', // id for "type" select @@ -136,6 +138,7 @@ define([ // render "new map" tab content ----------------------------------------------------------------------- let mapFormDataNew = $.extend({}, mapFormData, { hasRightMapForm: hasRightMapCreate, + nameInputId: config.newNameInputId, iconSelectId: config.newIconSelectId, scopeSelectId: config.newScopeSelectId, typeSelectId: config.newTypeSelectId @@ -145,6 +148,7 @@ define([ // render "edit map" tab content ---------------------------------------------------------------------- let mapFormDataEdit = $.extend({}, mapFormData, { hasRightMapForm: hasRightMapUpdate, + nameInputId: config.editNameInputId, iconSelectId: config.editIconSelectId, scopeSelectId: config.editScopeSelectId, typeSelectId: config.editTypeSelectId diff --git a/public/js/v1.5.6/app/ui/dialog/map_info.js b/public/js/v1.5.6/app/ui/dialog/map_info.js index 6ac3bb80..357d384d 100644 --- a/public/js/v1.5.6/app/ui/dialog/map_info.js +++ b/public/js/v1.5.6/app/ui/dialog/map_info.js @@ -202,315 +202,322 @@ define([ * @param mapData */ $.fn.initSystemInfoTable = function(mapData){ - let systemsElement = $(this).empty(); + let tableApi = Util.getDataTableInstance(config.tableId, mapData.config.id, '', 'systems'); - let systemTable = $('
', { - id: Util.getTableId(config.tableId, 'systems', mapData.config.id, ''), - class: ['compact', 'stripe', 'order-column', 'row-border'].join(' ') - }); - systemsElement.append(systemTable); + if(tableApi){ + tableApi.clear(); + tableApi.rows.add(mapData.data.systems); + tableApi.draw(); + }else{ + let systemsElement = $(this); - systemsElement.showLoadingAnimation(config.loadingOptions); + let systemTable = $('
', { + id: Util.getTableId(config.tableId, 'systems', mapData.config.id, ''), + class: ['compact', 'stripe', 'order-column', 'row-border'].join(' ') + }); + systemsElement.append(systemTable); - systemTable.on('init.dt', function(){ - systemsElement.hideLoadingAnimation(); + systemsElement.showLoadingAnimation(config.loadingOptions); - // init table tooltips - let tooltipElements = systemsElement.find('[data-toggle="tooltip"]'); - tooltipElements.tooltip(); - }); + systemTable.on('init.dt', function(){ + systemsElement.hideLoadingAnimation(); - let systemsDataTable = systemTable.DataTable({ - pageLength: 20, - paging: true, - lengthMenu: [[5, 10, 20, 50, -1], [5, 10, 20, 50, 'All']], - ordering: true, - order: [15, 'desc'], - hover: false, - data: mapData.data.systems, - columnDefs: [], - language: { - emptyTable: 'Map is empty', - zeroRecords: 'No systems found', - lengthMenu: 'Show _MENU_ systems', - info: 'Showing _START_ to _END_ of _TOTAL_ systems' - }, - columns: [ - { - name: 'type', - title: 'type', - width: 25, - className: ['min-screen-l'].join(' '), - data: 'type', - render: { - _: (cellData, type, rowData, meta) => { - return MapUtil.getSystemTypeInfo(cellData.id, 'name'); - } - } - },{ - name: 'security', - title: '', - width: 1, - data: 'security', - render: { - display: (cellData, type, rowData, meta) => { - let securityClass = Util.getSecurityClassForSystem(cellData); - return '' + cellData + ''; - } - } - },{ - name: 'trueSec', - title: 'sec', - width: 18, - className: ['text-center', 'min-screen-l'].join(' '), - searchable: false, - data: 'trueSec', - render: { - display: (cellData, type, rowData, meta) => { - let systemTrueSecClass = Util.getTrueSecClassForSystem(cellData); - return '' + cellData.toFixed(1) + ''; - } - } - },{ - name: 'shattered', - title: '', - width: 10, - className: ['text-center', 'min-screen-l'].join(' '), - searchable: false, - data: 'shattered', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - if(cellData){ - value = ''; + // init table tooltips + let tooltipElements = systemsElement.find('[data-toggle="tooltip"]'); + tooltipElements.tooltip(); + }); + + let systemsDataTable = systemTable.DataTable({ + pageLength: 20, + paging: true, + lengthMenu: [[5, 10, 20, 50, -1], [5, 10, 20, 50, 'All']], + ordering: true, + order: [15, 'desc'], + hover: false, + data: mapData.data.systems, + columnDefs: [], + language: { + emptyTable: 'Map is empty', + zeroRecords: 'No systems found', + lengthMenu: 'Show _MENU_ systems', + info: 'Showing _START_ to _END_ of _TOTAL_ systems' + }, + columns: [ + { + name: 'type', + title: 'type', + width: 25, + className: ['min-screen-l'].join(' '), + data: 'type', + render: { + _: (cellData, type, rowData, meta) => { + return MapUtil.getSystemTypeInfo(cellData.id, 'name'); } - return value; } - } - },{ - name: 'name', - title: 'system', - data: 'name', - className: [config.tableCellLinkClass].join(' '), - createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ - // select system - $(cell).on('click', function(e){ - Util.triggerMenuAction(Util.getMapModule().getActiveMap(), 'SelectSystem', {systemId: rowData.id}); - }); - } - },{ - name: 'alias', - title: 'alias', - data: 'alias', - render: { - _: (cellData, type, rowData, meta) => { - return (cellData === rowData.name) ? '' : cellData; - } - } - },{ - name: 'region', - title: 'region', - data: 'region.name', - className: 'min-screen-l', - },{ - name: 'sovereignty', - title: 'sov.', - width: 30, - className: 'text-center', - data: 'sovereignty.alliance.ticker', - defaultContent: '', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - if(cellData){ - value = '<' + cellData + '>'; + },{ + name: 'security', + title: '', + width: 1, + data: 'security', + render: { + display: (cellData, type, rowData, meta) => { + let securityClass = Util.getSecurityClassForSystem(cellData); + return '' + cellData + ''; } - return value; } - } - },{ - name: 'planets', - title: '', - width: 10, - className: ['text-right', config.systemInfoPlanetsClass, Util.config.helpDefaultClass, Util.config.popoverTriggerClass].join(' '), - searchable: false, - orderSequence: ['desc', 'asc'], - data: 'planets', - render: { - _: (cellData, type, rowData, meta) => { - return cellData.length; - } - } - },{ - name: 'status', - title: '', - width: 10, - className: 'text-center', - searchable: false, - data: 'status.id', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - let systemStatusClass = Util.getStatusInfoForSystem(cellData, 'class'); - if(systemStatusClass !== ''){ - value = ''; + },{ + name: 'trueSec', + title: 'sec', + width: 18, + className: ['text-center', 'min-screen-l'].join(' '), + searchable: false, + data: 'trueSec', + render: { + display: (cellData, type, rowData, meta) => { + let systemTrueSecClass = Util.getTrueSecClassForSystem(cellData); + return '' + cellData.toFixed(1) + ''; } - return value; } - } - },{ - name: 'effect', - title: '', - width: 10, - className: 'text-center', - searchable: false, - data: 'effect', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - let systemEffectClass = MapUtil.getEffectInfoForSystem(cellData, 'class'); - if(systemEffectClass !== ''){ - value = ''; - } - return value; - } - } - },{ - name: 'statics', - title: 'statics', - width: 30, - searchable: false, - data: 'statics', - render: { - _: (cellData, type, rowData, meta) => { - let statics = []; - for(let wormholeName of cellData){ - let wormholeData = Object.assign({}, Init.wormholes[wormholeName]); - statics.push('' + wormholeData.security + ''); - } - return statics.join('  '); - } - } - },{ - name: 'position', - title: '', - width: 8, - className: 'text-center', - searchable: false, - data: 'currentUser', - defaultContent: false, - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - if(cellData === true){ - value = ''; - } - return value; - } - } - },{ - name: 'userCount', - title: '', - width: 12, - className: 'text-center', - searchable: false, - data: 'userCount', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - if(cellData > 0){ - value = cellData; - } - return value; - } - } - },{ - name: 'locked', - title: '', - width: 10, - className: 'text-center', - searchable: false, - data: 'locked', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - if(cellData === 1){ - value = ''; - } - return value; - } - } - },{ - name: 'updated', - title: 'updated', - width: 80, - searchable: false, - className: ['text-right', config.tableCellCounterClass].join(' '), - data: 'updated.updated', - defaultContent: '', - },{ - name: 'action', - title: '', - orderable: false, - searchable: false, - width: 10, - className: ['text-center', config.tableCellActionClass].join(' '), - data: null, - defaultContent: '', - createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ - let tempTableElement = this; - - let confirmationSettings = { - placement: 'left', - title: 'Delete system', - template: Util.getConfirmationTemplate(null, { - size: 'small', - noTitle: true - }), - onConfirm: function(e, target){ - let deleteRowElement = $(target).parents('tr'); - - let activeMap = Util.getMapModule().getActiveMap(); - let systemElement = $('#' + MapUtil.getSystemId(mapData.config.id, rowData.id) ); - - if(systemElement.length){ - // trigger system delete event - activeMap.trigger('pf:deleteSystems', [{ - systems: [systemElement[0]], - callback: function(deletedSystems){ - // callback function after ajax "delete" success - // check if system was deleted - if(deletedSystems.length === 1){ - // remove table row - tempTableElement.DataTable().rows(deleteRowElement).remove().draw(); - - Util.showNotify({title: 'System deleted', text: rowData.name, type: 'success'}); - - // refresh connection table (connections might have changed) -------------- - let connectionsElement = $('#' + config.mapInfoConnectionsId); - let mapDataNew = activeMap.getMapDataFromClient(['hasId']); - - connectionsElement.initConnectionInfoTable(mapDataNew); - }else{ - // error - Util.showNotify({title: 'Failed to delete system', text: rowData.name, type: 'error'}); - } - } - }]); + },{ + name: 'shattered', + title: '', + width: 10, + className: ['text-center', 'min-screen-l'].join(' '), + searchable: false, + data: 'shattered', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + if(cellData){ + value = ''; } + return value; } - }; + } + },{ + name: 'name', + title: 'system', + data: 'name', + className: [config.tableCellLinkClass].join(' '), + createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ + // select system + $(cell).on('click', function(e){ + Util.triggerMenuAction(Util.getMapModule().getActiveMap(), 'SelectSystem', {systemId: rowData.id}); + }); + } + },{ + name: 'alias', + title: 'alias', + data: 'alias', + render: { + _: (cellData, type, rowData, meta) => { + return (cellData === rowData.name) ? '' : cellData; + } + } + },{ + name: 'region', + title: 'region', + data: 'region.name', + className: 'min-screen-l', + },{ + name: 'sovereignty', + title: 'sov.', + width: 30, + className: 'text-center', + data: 'sovereignty.alliance.ticker', + defaultContent: '', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + if(cellData){ + value = '<' + cellData + '>'; + } + return value; + } + } + },{ + name: 'planets', + title: '', + width: 10, + className: ['text-right', config.systemInfoPlanetsClass, Util.config.helpDefaultClass, Util.config.popoverTriggerClass].join(' '), + searchable: false, + orderSequence: ['desc', 'asc'], + data: 'planets', + render: { + _: (cellData, type, rowData, meta) => { + return cellData.length; + } + } + },{ + name: 'status', + title: '', + width: 10, + className: 'text-center', + searchable: false, + data: 'status.id', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + let systemStatusClass = Util.getStatusInfoForSystem(cellData, 'class'); + if(systemStatusClass !== ''){ + value = ''; + } + return value; + } + } + },{ + name: 'effect', + title: '', + width: 10, + className: 'text-center', + searchable: false, + data: 'effect', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + let systemEffectClass = MapUtil.getEffectInfoForSystem(cellData, 'class'); + if(systemEffectClass !== ''){ + value = ''; + } + return value; + } + } + },{ + name: 'statics', + title: 'statics', + width: 30, + searchable: false, + data: 'statics', + render: { + _: (cellData, type, rowData, meta) => { + let statics = []; + for(let wormholeName of cellData){ + let wormholeData = Object.assign({}, Init.wormholes[wormholeName]); + statics.push('' + wormholeData.security + ''); + } + return statics.join('  '); + } + } + },{ + name: 'position', + title: '', + width: 8, + className: 'text-center', + searchable: false, + data: 'currentUser', + defaultContent: false, + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + if(cellData === true){ + value = ''; + } + return value; + } + } + },{ + name: 'userCount', + title: '', + width: 12, + className: 'text-center', + searchable: false, + data: 'userCount', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + if(cellData > 0){ + value = cellData; + } + return value; + } + } + },{ + name: 'locked', + title: '', + width: 10, + className: 'text-center', + searchable: false, + data: 'locked', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + if(cellData === 1){ + value = ''; + } + return value; + } + } + },{ + name: 'updated', + title: 'updated', + width: 80, + searchable: false, + className: ['text-right', config.tableCellCounterClass].join(' '), + data: 'updated.updated', + defaultContent: '', + },{ + name: 'action', + title: '', + orderable: false, + searchable: false, + width: 10, + className: ['text-center', config.tableCellActionClass].join(' '), + data: null, + defaultContent: '', + createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ + let tempTableElement = this; - // init confirmation dialog - $(cell).confirmation(confirmationSettings); + let confirmationSettings = { + placement: 'left', + title: 'Delete system', + template: Util.getConfirmationTemplate(null, { + size: 'small', + noTitle: true + }), + onConfirm: function(e, target){ + let deleteRowElement = $(target).parents('tr'); + + let activeMap = Util.getMapModule().getActiveMap(); + let systemElement = $('#' + MapUtil.getSystemId(mapData.config.id, rowData.id) ); + + if(systemElement.length){ + // trigger system delete event + activeMap.trigger('pf:deleteSystems', [{ + systems: [systemElement[0]], + callback: function(deletedSystems){ + // callback function after ajax "delete" success + // check if system was deleted + if(deletedSystems.length === 1){ + // remove table row + tempTableElement.DataTable().rows(deleteRowElement).remove().draw(); + + Util.showNotify({title: 'System deleted', text: rowData.name, type: 'success'}); + + // refresh connection table (connections might have changed) -------------- + let connectionsElement = $('#' + config.mapInfoConnectionsId); + let mapDataNew = activeMap.getMapDataFromClient(['hasId']); + + connectionsElement.initConnectionInfoTable(mapDataNew); + }else{ + // error + Util.showNotify({title: 'Failed to delete system', text: rowData.name, type: 'error'}); + } + } + }]); + } + } + }; + + // init confirmation dialog + $(cell).confirmation(confirmationSettings); + } } + ], + initComplete: function(settings){ + Counter.initTableCounter(this, ['updated:name']); } - ], - initComplete: function(settings){ - Counter.initTableCounter(this, ['updated:name']); - } - }); - + }); + } }; /** @@ -518,179 +525,188 @@ define([ * @param mapData */ $.fn.initConnectionInfoTable = function(mapData){ - let connectionsElement = $(this).empty(); + let tableApi = Util.getDataTableInstance(config.tableId, mapData.config.id, '', 'connections'); - let connectionTable = $('
', { - class: ['compact', 'stripe', 'order-column', 'row-border'].join(' ') - }); - connectionsElement.append(connectionTable); + if(tableApi){ + tableApi.clear(); + tableApi.rows.add(mapData.data.connections); + tableApi.draw(); + }else{ + let connectionsElement = $(this); - connectionsElement.showLoadingAnimation(config.loadingOptions); + let connectionTable = $('
', { + id: Util.getTableId(config.tableId, 'connections', mapData.config.id, ''), + class: ['compact', 'stripe', 'order-column', 'row-border'].join(' ') + }); + connectionsElement.append(connectionTable); - // table init complete - connectionTable.on('init.dt', function(){ - connectionsElement.hideLoadingAnimation(); + connectionsElement.showLoadingAnimation(config.loadingOptions); - // init table tooltips - let tooltipElements = connectionsElement.find('[data-toggle="tooltip"]'); - tooltipElements.tooltip(); - }); + // table init complete + connectionTable.on('init.dt', function(){ + connectionsElement.hideLoadingAnimation(); - // connections table ------------------------------------------------------------------------------------------ - let connectionDataTable = connectionTable.dataTable({ - pageLength: 20, - paging: true, - lengthMenu: [[5, 10, 20, 50, -1], [5, 10, 20, 50, 'All']], - ordering: true, - order: [ 6, 'desc' ], - autoWidth: false, - hover: false, - data: mapData.data.connections, - columnDefs: [], - language: { - emptyTable: 'No connections', - zeroRecords: 'No connections found', - lengthMenu: 'Show _MENU_ connections', - info: 'Showing _START_ to _END_ of _TOTAL_ connections' - }, - columns: [ - { - name: 'scope', - title: 'scope', - width: 50, - orderable: true, - data: 'scope', - render: { - display: (cellData, type, rowData, meta) => { - return MapUtil.getScopeInfoForConnection(cellData, 'label'); - } - } - },{ - name: 'sourceName', - title: 'source system', - data: 'sourceName', - className: [config.tableCellLinkClass].join(' '), - createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ - // select system - $(cell).on('click', function(e){ - Util.triggerMenuAction(Util.getMapModule().getActiveMap(), 'SelectSystem', {systemId: rowData.source}); - }); - } - },{ - name: 'sourceBubble', - title: '', - width: 10, - data: 'endpoints.source', - className: 'text-right', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - if(cellData.types.includes('bubble')){ - value = ''; - } - return value; - } - } - },{ - name: 'connection', - title: 'connection', - width: 80, - className: 'text-center', - orderable: false, - searchable: false, - data: 'type', - render: { - display: (cellData, type, rowData, meta) => { - let connectionClasses = MapUtil.getConnectionFakeClassesByTypes(cellData); - connectionClasses = connectionClasses.join(' '); - return '
'; - } - } - },{ - name: 'targetBubble', - title: '', - width: 10, - data: 'endpoints.target', - className: 'text-left', - render: { - display: (cellData, type, rowData, meta) => { - let value = ''; - if(cellData.types.includes('bubble')){ - value = ''; - } - return value; - } - } - },{ - name: 'targetName', - title: 'target system', - data: 'targetName', - className: [config.tableCellLinkClass].join(' '), - createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ - // select system - $(cell).on('click', function(e){ - Util.triggerMenuAction(Util.getMapModule().getActiveMap(), 'SelectSystem', {systemId: rowData.target}); - }); - } - },{ - name: 'updated', - title: 'updated', - width: 80, - searchable: false, - className: ['text-right', config.tableCellCounterClass].join(' '), - data: 'updated', - createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ - if(rowData.scope.scope_sort === 'wh'){ - // highlight cell - let diff = new Date().getTime() - cellData * 1000; - let dateDiff = new Date(diff); - if(dateDiff.getUTCDate() > 1){ - $(cell).addClass('txt-color txt-color-warning'); + // init table tooltips + let tooltipElements = connectionsElement.find('[data-toggle="tooltip"]'); + tooltipElements.tooltip(); + }); + + // connections table ------------------------------------------------------------------------------------------ + let connectionDataTable = connectionTable.dataTable({ + pageLength: 20, + paging: true, + lengthMenu: [[5, 10, 20, 50, -1], [5, 10, 20, 50, 'All']], + ordering: true, + order: [ 6, 'desc' ], + autoWidth: false, + hover: false, + data: mapData.data.connections, + columnDefs: [], + language: { + emptyTable: 'No connections', + zeroRecords: 'No connections found', + lengthMenu: 'Show _MENU_ connections', + info: 'Showing _START_ to _END_ of _TOTAL_ connections' + }, + columns: [ + { + name: 'scope', + title: 'scope', + width: 50, + orderable: true, + data: 'scope', + render: { + display: (cellData, type, rowData, meta) => { + return MapUtil.getScopeInfoForConnection(cellData, 'label'); } } - } - },{ - name: 'action', - title: '', - orderable: false, - searchable: false, - width: 10, - className: ['text-center', config.tableCellActionClass].join(' '), - data: null, - defaultContent: '', - createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ - let tempTableElement = this; - - let confirmationSettings = { - placement: 'left', - title: 'Delete connection', - template: Util.getConfirmationTemplate(null, { - size: 'small', - noTitle: true - }), - onConfirm: function(e, target){ - let deleteRowElement = $(target).parents('tr'); - - // deleteSignatures(row); - let connection = $().getConnectionById(mapData.config.id, rowData.id); - - MapUtil.deleteConnections([connection], () => { - // callback function after ajax "delete" success - // remove table row - tempTableElement.DataTable().rows(deleteRowElement).remove().draw(); - }); + },{ + name: 'sourceName', + title: 'source system', + data: 'sourceName', + className: [config.tableCellLinkClass].join(' '), + createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ + // select system + $(cell).on('click', function(e){ + Util.triggerMenuAction(Util.getMapModule().getActiveMap(), 'SelectSystem', {systemId: rowData.source}); + }); + } + },{ + name: 'sourceBubble', + title: '', + width: 10, + data: 'endpoints.source', + className: 'text-right', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + if(cellData.types.includes('bubble')){ + value = ''; + } + return value; } - }; + } + },{ + name: 'connection', + title: 'connection', + width: 80, + className: 'text-center', + orderable: false, + searchable: false, + data: 'type', + render: { + display: (cellData, type, rowData, meta) => { + let connectionClasses = MapUtil.getConnectionFakeClassesByTypes(cellData); + connectionClasses = connectionClasses.join(' '); + return '
'; + } + } + },{ + name: 'targetBubble', + title: '', + width: 10, + data: 'endpoints.target', + className: 'text-left', + render: { + display: (cellData, type, rowData, meta) => { + let value = ''; + if(cellData.types.includes('bubble')){ + value = ''; + } + return value; + } + } + },{ + name: 'targetName', + title: 'target system', + data: 'targetName', + className: [config.tableCellLinkClass].join(' '), + createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ + // select system + $(cell).on('click', function(e){ + Util.triggerMenuAction(Util.getMapModule().getActiveMap(), 'SelectSystem', {systemId: rowData.target}); + }); + } + },{ + name: 'updated', + title: 'updated', + width: 80, + searchable: false, + className: ['text-right', config.tableCellCounterClass].join(' '), + data: 'updated', + createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ + if(rowData.scope.scope_sort === 'wh'){ + // highlight cell + let diff = new Date().getTime() - cellData * 1000; + let dateDiff = new Date(diff); + if(dateDiff.getUTCDate() > 1){ + $(cell).addClass('txt-color txt-color-warning'); + } + } + } + },{ + name: 'action', + title: '', + orderable: false, + searchable: false, + width: 10, + className: ['text-center', config.tableCellActionClass].join(' '), + data: null, + defaultContent: '', + createdCell: function(cell, cellData, rowData, rowIndex, colIndex){ + let tempTableElement = this; - // init confirmation dialog - $(cell).confirmation(confirmationSettings); + let confirmationSettings = { + placement: 'left', + title: 'Delete connection', + template: Util.getConfirmationTemplate(null, { + size: 'small', + noTitle: true + }), + onConfirm: function(e, target){ + let deleteRowElement = $(target).parents('tr'); + + // deleteSignatures(row); + let connection = $().getConnectionById(mapData.config.id, rowData.id); + + MapUtil.deleteConnections([connection], () => { + // callback function after ajax "delete" success + // remove table row + tempTableElement.DataTable().rows(deleteRowElement).remove().draw(); + }); + } + }; + + // init confirmation dialog + $(cell).confirmation(confirmationSettings); + } } + ], + initComplete: function(settings){ + Counter.initTableCounter(this, ['updated:name']); } - ], - initComplete: function(settings){ - Counter.initTableCounter(this, ['updated:name']); - } - }); + }); + } }; /** diff --git a/public/js/v1.5.6/app/ui/dialog/map_settings.js b/public/js/v1.5.6/app/ui/dialog/map_settings.js index 56389ea0..9130edee 100644 --- a/public/js/v1.5.6/app/ui/dialog/map_settings.js +++ b/public/js/v1.5.6/app/ui/dialog/map_settings.js @@ -22,11 +22,13 @@ define([ dialogMapDownloadContainerId: 'pf-map-dialog-download', // id for the "download" container // new map form + newNameInputId: 'pf-map-dialog-new-name-input', // id for "name" input newIconSelectId: 'pf-map-dialog-new-icon-select', // id for "icon" select newScopeSelectId: 'pf-map-dialog-new-scope-select', // id for "scope" select newTypeSelectId: 'pf-map-dialog-new-type-select', // id for "type" select // edit map form + editNameInputId: 'pf-map-dialog-edit-name-input', // id for "name" input editIconSelectId: 'pf-map-dialog-edit-icon-select', // id for "icon" select editScopeSelectId: 'pf-map-dialog-edit-scope-select', // id for "scope" select editTypeSelectId: 'pf-map-dialog-edit-type-select', // id for "type" select @@ -136,6 +138,7 @@ define([ // render "new map" tab content ----------------------------------------------------------------------- let mapFormDataNew = $.extend({}, mapFormData, { hasRightMapForm: hasRightMapCreate, + nameInputId: config.newNameInputId, iconSelectId: config.newIconSelectId, scopeSelectId: config.newScopeSelectId, typeSelectId: config.newTypeSelectId @@ -145,6 +148,7 @@ define([ // render "edit map" tab content ---------------------------------------------------------------------- let mapFormDataEdit = $.extend({}, mapFormData, { hasRightMapForm: hasRightMapUpdate, + nameInputId: config.editNameInputId, iconSelectId: config.editIconSelectId, scopeSelectId: config.editScopeSelectId, typeSelectId: config.editTypeSelectId diff --git a/public/templates/form/map.html b/public/templates/form/map.html index 7f059be0..fa814adf 100644 --- a/public/templates/form/map.html +++ b/public/templates/form/map.html @@ -16,9 +16,9 @@
- +
- + Choose a meaningful name