From 1b4b8af3dc3d48e8b7a4f1deb34e6eab5892e86c Mon Sep 17 00:00:00 2001 From: Exodus4D Date: Sun, 22 May 2016 01:23:06 +0200 Subject: [PATCH] closed #163 added CREST endpoint support for "waypoints" --- app/main/controller/api/system.php | 47 ++- app/main/controller/ccp/sso.php | 61 +++ app/main/controller/controller.php | 447 +++++++++++---------- app/main/lib/web.php | 1 - js/app/init.js | 3 +- js/app/map/map.js | 87 +++- public/js/v1.0.0RC3/app/init.js | 60 ++- public/js/v1.0.0RC3/app/map/map.js | 87 +++- public/js/v1.0.0RC3/app/ui/system_graph.js | 2 +- 9 files changed, 537 insertions(+), 258 deletions(-) diff --git a/app/main/controller/api/system.php b/app/main/controller/api/system.php index 503ca850..0f14b896 100644 --- a/app/main/controller/api/system.php +++ b/app/main/controller/api/system.php @@ -7,6 +7,7 @@ */ namespace Controller\Api; +use Controller\Ccp\Sso; use Data\Mapper as Mapper; use Model; @@ -318,10 +319,9 @@ class System extends \Controller\AccessController { $return->error = []; $return->systemData = []; - $constellationId = 0; - $activeCharacter = $this->getCharacter(); + if( $activeCharacter = $this->getCharacter() ){ + $constellationId = 0; - if($activeCharacter){ // check for search parameter if( isset($params['arg1']) ){ $constellationId = (int)$params['arg1']; @@ -346,12 +346,51 @@ class System extends \Controller\AccessController { echo json_encode($return); } + /** + * set destination for specific systemIds + * @param \Base $f3 + */ + public function setDestination(\Base $f3){ + $postData = (array)$f3->get('POST'); + + $return = (object) []; + $return->error = []; + $return->systemData = []; + + if( + ($activeCharacter = $this->getCharacter()) && + !empty($postData['systemData']) + ){ + $return->clearOtherWaypoints = (bool)$postData['clearOtherWaypoints']; + $return->first = (bool)$postData['first']; + + /** + * @var Sso $ssoController + */ + $ssoController = self::getController('Sso'); + foreach($postData['systemData'] as $systemData){ + $waypointData = $ssoController->setWaypoint($activeCharacter, $systemData['systemId'], [ + 'clearOtherWaypoints' => $return->clearOtherWaypoints, + 'first' => $return->first, + ]); + if($waypointData['systemId']){ + $return->systemData[] = $systemData; + }elseif( isset($waypointData['error']) ){ + $return->error[] = $waypointData['error']; + } + } + } + + echo json_encode($return); + } + + /** * delete systems and all its connections * @param \Base $f3 */ public function delete(\Base $f3){ - $systemIds = $f3->get('POST.systemIds'); + $systemIds = (array)$f3->get('POST.systemIds'); if($activeCharacter = $this->getCharacter()){ /** diff --git a/app/main/controller/ccp/sso.php b/app/main/controller/ccp/sso.php index 87a6598e..7a05acaf 100644 --- a/app/main/controller/ccp/sso.php +++ b/app/main/controller/ccp/sso.php @@ -653,6 +653,67 @@ class Sso extends Api\User{ return $locationData; } + /** + * set new ingame waypoint + * @param Model\CharacterModel $character + * @param int $systemId + * @param array $options + * @return array + */ + public function setWaypoint( Model\CharacterModel $character, $systemId, $options = []){ + $crestUrlParts = parse_url( self::getCrestEndpoint() ); + $waypointData = []; + + if( $crestUrlParts ){ + $endpointUrl = self::getCrestEndpoint() . '/characters/' . $character->_id . '/navigation/waypoints/'; + $systemEndpoint = self::getCrestEndpoint() . '/solarsystems/' . $systemId . '/'; + + // request body + $content = [ + 'clearOtherWaypoints' => (bool)$options['clearOtherWaypoints'], + 'first' => (bool)$options['first'], + 'solarSystem' => [ + 'href' => $systemEndpoint, + 'id' => (int)$systemId + ] + ]; + + $requestOptions = [ + 'timeout' => self::CREST_TIMEOUT, + 'method' => 'POST', + 'user_agent' => $this->getUserAgent(), + 'header' => [ + 'Scope: characterNavigationWrite', + 'Authorization: Bearer ' . $character->getAccessToken(), + 'Host: ' . $crestUrlParts['host'], + 'Content-Type: application/vnd.ccp.eve.PostWaypoint-v1+json;charset=utf-8', + ], + 'content' => json_encode($content, JSON_UNESCAPED_SLASHES) + ]; + + $apiResponse = Lib\Web::instance()->request($endpointUrl, $requestOptions); + + if( isset($apiResponse['body']) ){ + $responseData = json_decode($apiResponse['body']); + + if( empty($responseData) ){ + $waypointData['systemId'] = (int)$systemId; + }elseif( + isset($responseData->message) && + isset($responseData->key) + ){ + // waypoint could not be set... + $error = (object) []; + $error->type = 'error'; + $error->message = $responseData->key; + $waypointData['error'] = $error; + } + } + } + + return $waypointData; + } + /** * update character * @param $characterData diff --git a/app/main/controller/controller.php b/app/main/controller/controller.php index 1d370af1..2796e0d9 100644 --- a/app/main/controller/controller.php +++ b/app/main/controller/controller.php @@ -8,7 +8,7 @@ namespace Controller; use Controller\Api as Api; -use Controller\Ccp\Sso; +use Controller\Ccp\Sso as Sso; use Model; use DB; @@ -445,134 +445,7 @@ class Controller { echo json_encode($return); } - /** - * check weather the page is IGB trusted or not - * @return boolean - */ - static function isIGBTrusted(){ - $igbHeaderData = self::getIGBHeaderData(); - return $igbHeaderData->trusted; - } - /** - * get all eve IGB specific header data - * @return \stdClass - */ - static function getIGBHeaderData(){ - $data = (object) []; - $data->trusted = false; - $data->values = []; - $headerData = self::getRequestHeaders(); - - foreach($headerData as $key => $value){ - $key = strtolower($key); - $key = str_replace('eve_', 'eve-', $key); - - - if (strpos($key, 'eve-') === 0) { - $key = str_replace('eve-', '', $key); - - if ( - $key === 'trusted' && - $value === 'Yes' - ) { - $data->trusted = true; - } - - $data->values[$key] = $value; - } - } - - return $data; - } - - /** - * Helper function to return all headers because - * getallheaders() is not available under nginx - * @return array (string $key -> string $value) - */ - static function getRequestHeaders(){ - $headers = []; - - $serverData = self::getServerData(); - - if( - function_exists('apache_request_headers') && - $serverData->type === 'apache' - ){ - // Apache Webserver - $headers = apache_request_headers(); - }else{ - // Other webserver, e.g. Nginx - // Unfortunately this "fallback" does not work for me (Apache) - // Therefore we can´t use this for all servers - // https://github.com/exodus4d/pathfinder/issues/58 - foreach($_SERVER as $name => $value){ - if(substr($name, 0, 5) == 'HTTP_'){ - $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; - } - } - } - - return $headers; - } - - /** - * get some server information - * @param int $ttl cache time (default: 1h) - * @return \stdClass - */ - static function getServerData($ttl = 3600){ - $f3 = \Base::instance(); - $cacheKey = 'PF_SERVER_INFO'; - - if( !$f3->exists($cacheKey) ){ - $serverData = (object) []; - $serverData->type = 'unknown'; - $serverData->version = 'unknown'; - $serverData->requiredVersion = 'unknown'; - $serverData->phpInterfaceType = php_sapi_name(); - - if(strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'nginx' ) !== false){ - // Nginx server - $serverSoftwareArgs = explode('/', strtolower( $_SERVER['SERVER_SOFTWARE']) ); - $serverData->type = reset($serverSoftwareArgs); - $serverData->version = end($serverSoftwareArgs); - $serverData->requiredVersion = $f3->get('REQUIREMENTS.SERVER.NGINX.VERSION'); - }elseif(strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'apache' ) !== false){ - // Apache server - $serverData->type = 'apache'; - $serverData->requiredVersion = $f3->get('REQUIREMENTS.SERVER.APACHE.VERSION'); - - // try to get the apache version... - if(function_exists('apache_get_version')){ - // function does not exists if PHP is running as CGI/FPM module! - $matches = preg_split('/[\s,\/ ]+/', strtolower( apache_get_version() ) ); - if(count($matches) > 1){ - $serverData->version = $matches[1]; - } - } - } - - // cache data for one day - $f3->set($cacheKey, $serverData, $ttl); - } - - return $f3->get($cacheKey); - } - - /** - * check if the current request was send from inGame - * @return bool - */ - static function isIGB(){ - $isIGB = false; - $igbHeaderData = self::getIGBHeaderData(); - if(count($igbHeaderData->values) > 0){ - $isIGB = true; - } - return $isIGB; - } /** * get error object is a user is not found/logged of @@ -585,85 +458,6 @@ class Controller { return $userError; } - /** - * get the current registration status - * 0=registration stop |1=new registration allowed - * @return int - */ - static function getRegistrationStatus(){ - return (int)\Base::instance()->get('PATHFINDER.REGISTRATION.STATUS'); - } - - /** - * get a log controller e.g. "debug" - * @param string $loggerType - * @return \Log - */ - static function getLogger($loggerType){ - return LogController::getLogger($loggerType); - } - - /** - * removes illegal characters from a Hive-key that are not allowed - * @param $key - * @return string - */ - static function formatHiveKey($key){ - $illegalCharacters = ['-', ' ']; - return strtolower( str_replace($illegalCharacters, '', $key) ); - } - - /** - * get environment specific configuration data - * @param string $key - * @return string|null - */ - static function getEnvironmentData($key){ - $f3 = \Base::instance(); - $environment = self::getEnvironment(); - $environmentKey = 'ENVIRONMENT[' . $environment . '][' . $key . ']'; - $data = null; - - if( $f3->exists($environmentKey) ){ - $data = $f3->get($environmentKey); - } - return $data; - } - - /** - * get current server environment status - * -> "DEVELOP" or "PRODUCTION" - * @return string - */ - static function getEnvironment(){ - $f3 = \Base::instance(); - return $f3->get('ENVIRONMENT.SERVER'); - } - - /** - * check if current server is "PRODUCTION" - * @return bool - */ - static function isProduction(){ - return self::getEnvironment() == 'PRODUCTION'; - } - - /** - * get required MySQL variable value - * @param $key - * @return string|null - */ - static function getRequiredMySqlVariables($key){ - $f3 = \Base::instance(); - $requiredMySqlVarKey = 'REQUIREMENTS[MYSQL][VARS][' . $key . ']'; - $data = null; - - if( $f3->exists($requiredMySqlVarKey) ){ - $data = $f3->get($requiredMySqlVarKey); - } - return $data; - } - /** * get a program URL by alias * -> if no $alias given -> get "default" route (index.php) @@ -772,4 +566,243 @@ class Controller { return true; } + /** + * get controller by class name + * -> controller class is searched within all controller directories + * @param $className + * @return null|\Controller\ + * @throws \Exception + */ + static function getController($className){ + $controller = null; + // add subNamespaces for controller classes + $subNamespaces = ['Api', 'Ccp']; + + for($i = 0; $i <= count($subNamespaces); $i++){ + $path = [__NAMESPACE__]; + $path[] = ( isset($subNamespaces[$i - 1]) ) ? $subNamespaces[$i - 1] : ''; + $path[] = $className; + $classPath = implode('\\', array_filter($path)); + + if(class_exists($classPath)){ + $controller = new $classPath(); + break; + } + } + + if( is_null($controller) ){ + throw new \Exception( sprintf('Controller class "%s" not found!', $className) ); + } + + return $controller; + } + + /** + * check weather the page is IGB trusted or not + * @return boolean + */ + static function isIGBTrusted(){ + $igbHeaderData = self::getIGBHeaderData(); + return $igbHeaderData->trusted; + } + + /** + * get all eve IGB specific header data + * @return \stdClass + */ + static function getIGBHeaderData(){ + $data = (object) []; + $data->trusted = false; + $data->values = []; + $headerData = self::getRequestHeaders(); + + foreach($headerData as $key => $value){ + $key = strtolower($key); + $key = str_replace('eve_', 'eve-', $key); + + + if (strpos($key, 'eve-') === 0) { + $key = str_replace('eve-', '', $key); + + if ( + $key === 'trusted' && + $value === 'Yes' + ) { + $data->trusted = true; + } + + $data->values[$key] = $value; + } + } + + return $data; + } + + /** + * Helper function to return all headers because + * getallheaders() is not available under nginx + * @return array (string $key -> string $value) + */ + static function getRequestHeaders(){ + $headers = []; + + $serverData = self::getServerData(); + + if( + function_exists('apache_request_headers') && + $serverData->type === 'apache' + ){ + // Apache Webserver + $headers = apache_request_headers(); + }else{ + // Other webserver, e.g. Nginx + // Unfortunately this "fallback" does not work for me (Apache) + // Therefore we can´t use this for all servers + // https://github.com/exodus4d/pathfinder/issues/58 + foreach($_SERVER as $name => $value){ + if(substr($name, 0, 5) == 'HTTP_'){ + $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; + } + } + } + + return $headers; + } + + /** + * get some server information + * @param int $ttl cache time (default: 1h) + * @return \stdClass + */ + static function getServerData($ttl = 3600){ + $f3 = \Base::instance(); + $cacheKey = 'PF_SERVER_INFO'; + + if( !$f3->exists($cacheKey) ){ + $serverData = (object) []; + $serverData->type = 'unknown'; + $serverData->version = 'unknown'; + $serverData->requiredVersion = 'unknown'; + $serverData->phpInterfaceType = php_sapi_name(); + + if(strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'nginx' ) !== false){ + // Nginx server + $serverSoftwareArgs = explode('/', strtolower( $_SERVER['SERVER_SOFTWARE']) ); + $serverData->type = reset($serverSoftwareArgs); + $serverData->version = end($serverSoftwareArgs); + $serverData->requiredVersion = $f3->get('REQUIREMENTS.SERVER.NGINX.VERSION'); + }elseif(strpos(strtolower($_SERVER['SERVER_SOFTWARE']), 'apache' ) !== false){ + // Apache server + $serverData->type = 'apache'; + $serverData->requiredVersion = $f3->get('REQUIREMENTS.SERVER.APACHE.VERSION'); + + // try to get the apache version... + if(function_exists('apache_get_version')){ + // function does not exists if PHP is running as CGI/FPM module! + $matches = preg_split('/[\s,\/ ]+/', strtolower( apache_get_version() ) ); + if(count($matches) > 1){ + $serverData->version = $matches[1]; + } + } + } + + // cache data for one day + $f3->set($cacheKey, $serverData, $ttl); + } + + return $f3->get($cacheKey); + } + + /** + * check if the current request was send from inGame + * @return bool + */ + static function isIGB(){ + $isIGB = false; + $igbHeaderData = self::getIGBHeaderData(); + if(count($igbHeaderData->values) > 0){ + $isIGB = true; + } + return $isIGB; + } + + /** + * get the current registration status + * 0=registration stop |1=new registration allowed + * @return int + */ + static function getRegistrationStatus(){ + return (int)\Base::instance()->get('PATHFINDER.REGISTRATION.STATUS'); + } + + /** + * get a log controller e.g. "debug" + * @param string $loggerType + * @return \Log + */ + static function getLogger($loggerType){ + return LogController::getLogger($loggerType); + } + + /** + * removes illegal characters from a Hive-key that are not allowed + * @param $key + * @return string + */ + static function formatHiveKey($key){ + $illegalCharacters = ['-', ' ']; + return strtolower( str_replace($illegalCharacters, '', $key) ); + } + + /** + * get environment specific configuration data + * @param string $key + * @return string|null + */ + static function getEnvironmentData($key){ + $f3 = \Base::instance(); + $environment = self::getEnvironment(); + $environmentKey = 'ENVIRONMENT[' . $environment . '][' . $key . ']'; + $data = null; + + if( $f3->exists($environmentKey) ){ + $data = $f3->get($environmentKey); + } + return $data; + } + + /** + * get current server environment status + * -> "DEVELOP" or "PRODUCTION" + * @return string + */ + static function getEnvironment(){ + $f3 = \Base::instance(); + return $f3->get('ENVIRONMENT.SERVER'); + } + + /** + * check if current server is "PRODUCTION" + * @return bool + */ + static function isProduction(){ + return self::getEnvironment() == 'PRODUCTION'; + } + + /** + * get required MySQL variable value + * @param $key + * @return string|null + */ + static function getRequiredMySqlVariables($key){ + $f3 = \Base::instance(); + $requiredMySqlVarKey = 'REQUIREMENTS[MYSQL][VARS][' . $key . ']'; + $data = null; + + if( $f3->exists($requiredMySqlVarKey) ){ + $data = $f3->get($requiredMySqlVarKey); + } + return $data; + } + } \ No newline at end of file diff --git a/app/main/lib/web.php b/app/main/lib/web.php index 0985c2cd..86a0b4b0 100644 --- a/app/main/lib/web.php +++ b/app/main/lib/web.php @@ -105,7 +105,6 @@ class Web extends \Web { $f3 = \Base::instance(); if( !$f3->exists( $hash = $this->getCacheKey($url, $options) ) ){ - // retry same request until request limit is reached $retry = false; diff --git a/js/app/init.js b/js/app/init.js index 059d331a..9679ab39 100644 --- a/js/app/init.js +++ b/js/app/init.js @@ -1,4 +1,4 @@ -/** +6/** * Init */ @@ -35,6 +35,7 @@ define(['jquery'], function($) { deleteSystem: 'api/system/delete', // ajax URL - delete system from map getSystemGraphData: 'api/system/graphData', // ajax URL - get all system graph data getConstellationData: 'api/system/constellationData', // ajax URL - get system constellation data + setDestination: 'api/system/setDestination', // ajax URL - set destination // connection API saveConnection: 'api/connection/save', // ajax URL - save new connection to map diff --git a/js/app/map/map.js b/js/app/map/map.js index e28b9abb..abf8234c 100644 --- a/js/app/map/map.js +++ b/js/app/map/map.js @@ -1683,12 +1683,15 @@ define([ {icon: 'fa-lock', action: 'lock_system', text: 'lock system'}, {icon: 'fa-users', action: 'set_rally', text: 'set rally point'}, {icon: 'fa-tags', text: 'set status', subitems: systemStatus}, + {icon: 'fa-reply fa-rotate-180', text: 'waypoints', subitems: [ + {subIcon: 'fa-flag-checkered', subAction: 'set_destination', subText: 'set destination'}, + {subDivider: true, action: ''}, + {subIcon: 'fa-step-backward', subAction: 'add_first_waypoint', subText: 'add new [start]'}, + {subIcon: 'fa-step-forward', subAction: 'add_last_waypoint', subText: 'add new [end]'} + ]}, {divider: true, action: 'ingame'}, - {icon: 'fa-reply fa-rotate-180', action: 'ingame', text: 'ingame actions', subitems: [ - {subIcon: 'fa-info', subAction: 'ingame_show_info', subText: 'show info'}, - {subDivider: true, action: 'ingame'}, - {subIcon: 'fa-flag', subAction: 'ingame_add_waypoint', subText: 'add waypoint'}, - {subIcon: 'fa-flag-checkered', subAction: 'ingame_set_destination', subText: 'set destination'} + {icon: 'fa-reply fa-rotate-180', action: 'ingame', text: 'ingame', subitems: [ + {subIcon: 'fa-info', subAction: 'ingame_show_info', subText: 'show info'} ]}, {divider: true, action: 'delete_system'}, {icon: 'fa-eraser', action: 'delete_system', text: 'delete system'} @@ -2009,15 +2012,11 @@ define([ CCPEVE.showInfo(5, systemData.systemId ); break; - case 'ingame_set_destination': + case 'set_destination': + case 'add_first_waypoint': + case 'add_last_waypoint': systemData = system.getSystemData(); - - CCPEVE.setDestination( systemData.systemId ); - break; - case 'ingame_add_waypoint': - systemData = system.getSystemData(); - - CCPEVE.addWaypoint( systemData.systemId ); + setDestination(systemData, action); break; } } @@ -2069,6 +2068,68 @@ define([ system.singleDoubleClick(single, double); }; + + /** + * set new destination for a system + * -> CREST request + * @param systemData + * @param type + */ + var setDestination = function(systemData, type){ + + var description = ''; + switch(type){ + case 'set_destination': + description = 'Set destination'; + break; + case 'add_first_waypoint': + description = 'Set first waypoint'; + break; + case 'add_last_waypoint': + description = 'Set new waypoint'; + break; + } + + $.ajax({ + type: 'POST', + url: Init.path.setDestination, + data: { + clearOtherWaypoints: (type === 'set_destination') ? 1 : 0, + first: (type === 'add_last_waypoint') ? 0 : 1, + systemData: [{ + systemId: systemData.systemId, + name: systemData.name + }] + }, + context: { + description: description + }, + dataType: 'json' + }).done(function(responseData){ + if( + responseData.systemData && + responseData.systemData.length > 0 + ){ + for (var j = 0; j < responseData.systemData.length; j++) { + Util.showNotify({title: this.description, text: 'System: ' + responseData.systemData[j].name, type: 'success'}); + } + } + + if( + responseData.error && + responseData.error.length > 0 + ){ + for(var i = 0; i < responseData.error.length; i++){ + Util.showNotify({title: this.description + ' error', text: 'System: ' + responseData.error[i].message, type: 'error'}); + } + } + + }).fail(function( jqXHR, status, error) { + var reason = status + ' ' + error; + Util.showNotify({title: jqXHR.status + ': ' + this.description, text: reason, type: 'warning'}); + }); + }; + /** * mark a dom element (map, system, connection) as changed */ diff --git a/public/js/v1.0.0RC3/app/init.js b/public/js/v1.0.0RC3/app/init.js index 3bae74c8..9679ab39 100644 --- a/public/js/v1.0.0RC3/app/init.js +++ b/public/js/v1.0.0RC3/app/init.js @@ -1,4 +1,4 @@ -/** +6/** * Init */ @@ -35,6 +35,7 @@ define(['jquery'], function($) { deleteSystem: 'api/system/delete', // ajax URL - delete system from map getSystemGraphData: 'api/system/graphData', // ajax URL - get all system graph data getConstellationData: 'api/system/constellationData', // ajax URL - get system constellation data + setDestination: 'api/system/setDestination', // ajax URL - set destination // connection API saveConnection: 'api/connection/save', // ajax URL - save new connection to map @@ -126,7 +127,7 @@ define(['jquery'], function($) { }, redGiant: { class: 'pf-system-effect-redgiant', - name: 'red gaint' + name: 'red giant' }, pulsar: { class: 'pf-system-effect-pulsar', @@ -330,34 +331,58 @@ define(['jquery'], function($) { // frigate wormholes frigateWormholes: { 1: { // C1 - + 1: 'E004 - C1', + 2: 'L005 - C2', + 3: 'Z006 - C3', + 4: 'M001 - C4', + 5: 'C008 - C5', + 6: 'G008 - C6', + 7: 'Q003 - 0.0' }, 2: { // C2 - 1: 'L005 - C2', - 2: 'C008 - C5', - 3: 'Q003 - 0.0' + 1: 'E004 - C1', + 2: 'L005 - C2', + 3: 'Z006 - C3', + 4: 'M001 - C4', + 5: 'C008 - C5', + 6: 'G008 - C6', + 7: 'Q003 - 0.0' }, 3: { // C3 1: 'E004 - C1', 2: 'L005 - C2', - 3: 'M001 - C4' + 3: 'Z006 - C3', + 4: 'M001 - C4', + 5: 'C008 - C5', + 6: 'G008 - C6', + 7: 'Q003 - 0.0' }, 4: { // C4 - 1: 'L005 - C2', - 2: 'G008 - C6', - 3: 'Q003 - 0.0' - }, + 1: 'E004 - C1', + 2: 'L005 - C2', + 3: 'Z006 - C3', + 4: 'M001 - C4', + 5: 'C008 - C5', + 6: 'G008 - C6', + 7: 'Q003 - 0.0' + }, 5: { // C5 1: 'E004 - C1', 2: 'L005 - C2', 3: 'Z006 - C3', - 4: 'C008 - C5', - 5: 'Q003 - 0.0' + 4: 'M001 - C4', + 5: 'C008 - C5', + 6: 'G008 - C6', + 7: 'Q003 - 0.0' }, 6: { // C6 1: 'E004 - C1', - 2: 'Z006 - C3', - 5: 'Q003 - 0.0' + 2: 'L005 - C2', + 3: 'Z006 - C3', + 4: 'M001 - C4', + 5: 'C008 - C5', + 6: 'G008 - C6', + 7: 'Q003 - 0.0' }, 13: { // Shattered Wormholes (some of them are static) 1: 'E004 - C1', @@ -366,8 +391,7 @@ define(['jquery'], function($) { 4: 'M001 - C4', 5: 'C008 - C5', 6: 'G008 - C6', - 7: 'Q003 - C7' - + 7: 'Q003 - 0.0' } }, // incoming wormholes @@ -383,4 +407,4 @@ define(['jquery'], function($) { }; return Config; -}); \ No newline at end of file +}); diff --git a/public/js/v1.0.0RC3/app/map/map.js b/public/js/v1.0.0RC3/app/map/map.js index e28b9abb..abf8234c 100644 --- a/public/js/v1.0.0RC3/app/map/map.js +++ b/public/js/v1.0.0RC3/app/map/map.js @@ -1683,12 +1683,15 @@ define([ {icon: 'fa-lock', action: 'lock_system', text: 'lock system'}, {icon: 'fa-users', action: 'set_rally', text: 'set rally point'}, {icon: 'fa-tags', text: 'set status', subitems: systemStatus}, + {icon: 'fa-reply fa-rotate-180', text: 'waypoints', subitems: [ + {subIcon: 'fa-flag-checkered', subAction: 'set_destination', subText: 'set destination'}, + {subDivider: true, action: ''}, + {subIcon: 'fa-step-backward', subAction: 'add_first_waypoint', subText: 'add new [start]'}, + {subIcon: 'fa-step-forward', subAction: 'add_last_waypoint', subText: 'add new [end]'} + ]}, {divider: true, action: 'ingame'}, - {icon: 'fa-reply fa-rotate-180', action: 'ingame', text: 'ingame actions', subitems: [ - {subIcon: 'fa-info', subAction: 'ingame_show_info', subText: 'show info'}, - {subDivider: true, action: 'ingame'}, - {subIcon: 'fa-flag', subAction: 'ingame_add_waypoint', subText: 'add waypoint'}, - {subIcon: 'fa-flag-checkered', subAction: 'ingame_set_destination', subText: 'set destination'} + {icon: 'fa-reply fa-rotate-180', action: 'ingame', text: 'ingame', subitems: [ + {subIcon: 'fa-info', subAction: 'ingame_show_info', subText: 'show info'} ]}, {divider: true, action: 'delete_system'}, {icon: 'fa-eraser', action: 'delete_system', text: 'delete system'} @@ -2009,15 +2012,11 @@ define([ CCPEVE.showInfo(5, systemData.systemId ); break; - case 'ingame_set_destination': + case 'set_destination': + case 'add_first_waypoint': + case 'add_last_waypoint': systemData = system.getSystemData(); - - CCPEVE.setDestination( systemData.systemId ); - break; - case 'ingame_add_waypoint': - systemData = system.getSystemData(); - - CCPEVE.addWaypoint( systemData.systemId ); + setDestination(systemData, action); break; } } @@ -2069,6 +2068,68 @@ define([ system.singleDoubleClick(single, double); }; + + /** + * set new destination for a system + * -> CREST request + * @param systemData + * @param type + */ + var setDestination = function(systemData, type){ + + var description = ''; + switch(type){ + case 'set_destination': + description = 'Set destination'; + break; + case 'add_first_waypoint': + description = 'Set first waypoint'; + break; + case 'add_last_waypoint': + description = 'Set new waypoint'; + break; + } + + $.ajax({ + type: 'POST', + url: Init.path.setDestination, + data: { + clearOtherWaypoints: (type === 'set_destination') ? 1 : 0, + first: (type === 'add_last_waypoint') ? 0 : 1, + systemData: [{ + systemId: systemData.systemId, + name: systemData.name + }] + }, + context: { + description: description + }, + dataType: 'json' + }).done(function(responseData){ + if( + responseData.systemData && + responseData.systemData.length > 0 + ){ + for (var j = 0; j < responseData.systemData.length; j++) { + Util.showNotify({title: this.description, text: 'System: ' + responseData.systemData[j].name, type: 'success'}); + } + } + + if( + responseData.error && + responseData.error.length > 0 + ){ + for(var i = 0; i < responseData.error.length; i++){ + Util.showNotify({title: this.description + ' error', text: 'System: ' + responseData.error[i].message, type: 'error'}); + } + } + + }).fail(function( jqXHR, status, error) { + var reason = status + ' ' + error; + Util.showNotify({title: jqXHR.status + ': ' + this.description, text: reason, type: 'warning'}); + }); + }; + /** * mark a dom element (map, system, connection) as changed */ diff --git a/public/js/v1.0.0RC3/app/ui/system_graph.js b/public/js/v1.0.0RC3/app/ui/system_graph.js index 1a845c4e..134c266b 100644 --- a/public/js/v1.0.0RC3/app/ui/system_graph.js +++ b/public/js/v1.0.0RC3/app/ui/system_graph.js @@ -150,7 +150,7 @@ define([ dataType: 'json' }).done(function(systemGraphsData){ - if(systemGraphsData.length > 0){ + if( !$.isEmptyObject(systemGraphsData) ){ // create new (hidden) module container var moduleElement = $('
', { class: [config.moduleClass, config.systemGraphModuleClass].join(' '),