Skip to content

Commit

Permalink
added GitHub API support (show release info)
Browse files Browse the repository at this point in the history
new dialog (show release info)
fixed caching timings (main ajax update trigger calls)
fixed footer "current year" number
  • Loading branch information
exodus4d committed Jan 16, 2016
1 parent 6bf0a1a commit 3f4d33a
Show file tree
Hide file tree
Showing 29 changed files with 459 additions and 84 deletions.
82 changes: 82 additions & 0 deletions app/main/controller/api/github.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* Created by PhpStorm.
* User: exodus4d
* Date: 16.01.16
* Time: 03:34
*/

namespace Controller\Api;
use Model;
use Controller;


/**
* Github controller
* Class Route
* @package Controller\Api
*/
class GitHub extends Controller\Controller {

/**
* get HTTP request options for API (curl) request
* @return array
*/
protected function getRequestOptions(){
$requestOptions = [
'timeout' => 8,
'method' => 'GET',
'user_agent' => $this->getUserAgent(),
'follow_location' => false // otherwise CURLOPT_FOLLOWLOCATION will fail
];

return $requestOptions;
}

/**
* get release information from GitHub
* @param $f3
*/
public function releases($f3){
$cacheKey = 'CACHE_GITHUB_RELEASES';
$ttl = 60 * 30; // 30min
$releaseCount = 5;

if( !$f3->exists($cacheKey) ){
$apiPath = $this->getF3()->get('PATHFINDER.API.GIT_HUB') . '/repos/exodus4d/pathfinder/releases';

// build request URL
$options = $this->getRequestOptions();
$apiResponse = \Web::instance()->request($apiPath, $options );

if($apiResponse['body']){
// request succeeded -> format "Markdown" to "HTML"
// result is JSON formed
$releasesData = (array)json_decode($apiResponse['body']);

// check max release count
if(count($releasesData) > $releaseCount){
$releasesData = array_slice($releasesData, 0, $releaseCount);
}

$md = \Markdown::instance();
foreach($releasesData as &$releaseData){
if(isset($releaseData->body)){
$releaseData->body = $md->convert( $releaseData->body );
}
}
$f3->set($cacheKey, $releasesData, $ttl);
}else{
// request failed -> cache failed result (respect API request limit)
$f3->set($cacheKey, false, 60 * 5);
}
}

// set 503 if service unavailable or temp cached data = false
if( !$f3->get($cacheKey) ){
$f3->status(503);
}

echo json_encode($f3->get($cacheKey));
}
}
4 changes: 2 additions & 2 deletions app/main/controller/api/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public function updateData($f3){
$responseTTL = $f3->get('PATHFINDER.TIMER.UPDATE_SERVER_MAP.DELAY') / 1000;
$mapData = (array)$f3->get('POST.mapData');

$user = $this->_getUser(0);
$user = $this->_getUser();
$return = (object) [];
$return->error = [];

Expand Down Expand Up @@ -628,7 +628,7 @@ public function updateUserData($f3){
$return = (object) [];
$return->error = [];

$user = $this->_getUser(0);
$user = $this->_getUser();

if($user){

Expand Down
16 changes: 0 additions & 16 deletions app/main/controller/ccpapicontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@
*/
class CcpApiController extends Controller{

/**
* get a custom userAgent string for API calls
* (recommended by CCP)
* @return string
*/
protected function getUserAgent(){
$userAgent = '';

$userAgent .= $this->getF3()->get('PATHFINDER.NAME');
$userAgent .= ' - ' . $this->getF3()->get('PATHFINDER.VERSION');
$userAgent .= ' | ' . $this->getF3()->get('PATHFINDER.CONTACT');
$userAgent .= ' (' . $_SERVER['SERVER_NAME'] . ')';

return $userAgent;
}

/**
* get HTTP request options for API (curl) request
* @return array
Expand Down
16 changes: 16 additions & 0 deletions app/main/controller/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,21 @@ protected function getRouteUrl($alias = null){
return $url;
}

/**
* get a custom userAgent string for API calls
* @return string
*/
protected function getUserAgent(){
$userAgent = '';

$userAgent .= $this->getF3()->get('PATHFINDER.NAME');
$userAgent .= ' - ' . $this->getF3()->get('PATHFINDER.VERSION');
$userAgent .= ' | ' . $this->getF3()->get('PATHFINDER.CONTACT');
$userAgent .= ' (' . $_SERVER['SERVER_NAME'] . ')';

return $userAgent;
}

/**
* onError() callback function
* -> on AJAX request -> return JSON with error information
Expand Down Expand Up @@ -475,6 +490,7 @@ public function showError($f3){
if($f3->get('AJAX')){
header('Content-type: application/json');
echo json_encode($return);
die();
}else{
// set error data for template rendering
$error->redirectUrl = $this->getRouteUrl();
Expand Down
1 change: 1 addition & 0 deletions app/pathfinder.ini
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ DELETE_ACCOUNT = delete_account
[PATHFINDER.API]
; Path for CCPs XML APIv2
CCP_XML = https://api.eveonline.com
GIT_HUB = https://api.github.com
4 changes: 3 additions & 1 deletion js/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ define(['jquery'], function($) {
saveSignatureData: 'api/signature/save', // ajax URL - save signature data for system
deleteSignatureData: 'api/signature/delete', // ajax URL - delete signature data for system
// route API
searchRoute: 'api/route/search' // ajax URL - search system routes
searchRoute: 'api/route/search', // ajax URL - search system routes
// GitHub API
gitHubReleases: 'api/github/releases' // ajax URL - get release info from GitHub
},
url: {
ccpImageServer: 'https://image.eveonline.com/', // CCP image Server
Expand Down
9 changes: 8 additions & 1 deletion js/app/landingpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ define([
'dialog/account_settings',
'dialog/notification',
'dialog/manual',
'dialog/releases',
'dialog/credit'
], function($, Init, Util, Render, CCP, Gallery, bootbox) {

Expand All @@ -39,7 +40,8 @@ define([
// navigation
navigationElementId: 'pf-navbar', // id for navbar element
navigationLinkManualClass: 'pf-navbar-manual', // class for "manual" trigger link
navigationLinkLicenseClass : 'pf-navbar-license', // class for "license" trigger link
navigationLinkLicenseClass: 'pf-navbar-license', // class for "license" trigger link
navigationVersionLinkClass: 'pf-navbar-version-info', // class for "version information"

// login form
loginFormId: 'pf-login-form', // id for login form
Expand Down Expand Up @@ -130,6 +132,11 @@ define([
}
});

// releases -----------------------------------------------------
$('.' + config.navigationVersionLinkClass).on('click', function(e){
$.fn.releasesDialog();
});

// manual -------------------------------------------------------
$('.' + config.navigationLinkManualClass).on('click', function(e){
e.preventDefault();
Expand Down
3 changes: 2 additions & 1 deletion js/app/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,8 @@ define([

var moduleData = {
id: config.pageFooterId,
footerLicenceLinkClass: config.footerLicenceLinkClass
footerLicenceLinkClass: config.footerLicenceLinkClass,
currentYear: new Date().getFullYear()
};

var headRendered = Mustache.render(TplFooter, moduleData);
Expand Down
80 changes: 80 additions & 0 deletions js/app/ui/dialog/releases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* releases dialog (GitHub API repository information)
*/

define([
'jquery',
'app/init',
'app/util',
'app/render',
'bootbox'
], function($, Init, Util, Render, bootbox) {
'use strict';

var config = {
releasesDialogClass: 'pf-releases-dialog' // class for "Releases" dialog
};

/**
* load release information in dialog
* @param releasesDialog
*/
var loadDialogData = function(releasesDialog){
$.ajax({
type: 'POST',
url: Init.path.gitHubReleases,
// data: updatedMapData,
dataType: 'json'
}).done(function(releasesData){
requirejs(['text!templates/ui/timeline_element.html', 'mustache'], function(template, Mustache) {
for(var i = 0; i < releasesData.length; i++){
var releaseData = releasesData[i];

// template vars
var data = {
isFirst: (i === 0),
isOdd: (i % 2 !== 0),
releaseDate: releaseData.published_at.substr(0, 10),
releaseData: releaseData
};

var content = Mustache.render(template, data);
releasesDialog.find('ul.timeline').append(content);
}
});
}).fail(function( jqXHR, status, error) {
var reason = status + ' ' + jqXHR.status + ': ' + error;
Util.showNotify({title: jqXHR.status + ': login', text: reason, type: 'error'});
});
};

/**
* show releases dialog
*/
$.fn.releasesDialog = function(){

requirejs(['text!templates/dialog/releases.html', 'mustache'], function(template, Mustache) {

var data = {
test: 'blaBla'
};

var content = Mustache.render(template, data);

var releasesDialog = bootbox.dialog({
className: config.releasesDialogClass,
title: 'Releases',
size: 'large',
message: content
});

// after modal is shown =======================================================================
releasesDialog.on('shown.bs.modal', function(e) {

loadDialogData(releasesDialog);
});

});

};
});
2 changes: 1 addition & 1 deletion js/app/ui/dialog/trust.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ define([
}
},
trust: {
label: '<i class="fa fa-fw fa-lock"></i> trust set',
label: '<i class="fa fa-fw fa-lock"></i> set "Trust"',
className: 'btn-primary',
callback: function(){
var dialog = $(this);
Expand Down
4 changes: 2 additions & 2 deletions public/css/pathfinder.css

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions public/js/v1.0.0RC1/app/landingpage.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/v1.0.0RC1/app/landingpage.js.map

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions public/js/v1.0.0RC1/app/mappage.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/v1.0.0RC1/app/mappage.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/v1.0.0RC1/app/notification.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/v1.0.0RC1/app/notification.js.map

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions public/js/v1.0.0RC1/app/setup.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/v1.0.0RC1/app/setup.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/js/v1.0.0RC1/build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ app/ui/demo_map.js
app/ui/dialog/account_settings.js
app/ui/dialog/notification.js
app/ui/dialog/manual.js
app/ui/dialog/releases.js
app/ui/dialog/credit.js
app/landingpage.js
lib/requirejs/text.js
Expand Down
2 changes: 2 additions & 0 deletions public/templates/dialog/releases.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

<ul class="timeline"></ul>
2 changes: 1 addition & 1 deletion public/templates/modules/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="navbar-header pull-left">

<p class="navbar-text txt-color txt-color-gray"><i class="fa fa-copyright"></i>
2015 <a class="{{footerLicenceLinkClass}}" href="javascript:void(0)" target="_blank">Licence</a>
{{ currentYear }} <a class="{{footerLicenceLinkClass}}" href="javascript:void(0)" target="_blank">Licence</a>
</p>
</div>
<div class="navbar-header pull-right">
Expand Down
19 changes: 19 additions & 0 deletions public/templates/ui/timeline_element.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<li class="{{#isOdd}}timeline-inverted{{/isOdd}} {{#isFirst}}timeline-first{{/isFirst}}">
<div class="timeline-badge"><i class="fa fa-lg fa-github fa-fw"></i></div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">
<a href="{{releaseData.html_url}}" target="_blank">{{ releaseData.name }}</a>

<span class="text-muted pull-right">
{{ #releaseData.prerelease }}
<span class="label label-danger">Pre-release</span>
{{ /releaseData.prerelease }}
<i class="fa fa-calendar fa-fw"></i> {{ releaseDate }}
</span>
</h4>
<p><small class="text-muted"></small></p>
</div>
<div class="timeline-body">{{{ releaseData.body }}}</div>
</div>
</li>
6 changes: 5 additions & 1 deletion public/templates/view/landingpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</button>

<p class="navbar-text">
<span class="badge txt-color txt-color-grayLight">{{ @PATHFINDER.VERSION }}</span>
<span class="badge txt-color txt-color-green pf-navbar-version-info">{{ @PATHFINDER.VERSION }}</span>
</p>

<ul class="nav navbar-nav navbar-right" role="tablist">
Expand Down Expand Up @@ -130,6 +130,7 @@ <h2><span class="text-primary">Please</span> log in</h2>
</div>
</check>

{* signUp/logIn buttons *}
<div class="row text-center">
<div class="col-sm-6 col-sm-offset-3">
<div class="col-xs-6 col-sm-4 col-sm-offset-2" data-placement="left" title="{{@registrationStatusTitle}}">
Expand All @@ -145,6 +146,8 @@ <h2><span class="text-primary">Please</span> log in</h2>
</section>




{* features/ gallery *}
<section id="pf-landing-gallery">

Expand Down Expand Up @@ -823,6 +826,7 @@ <h3>Can you give me an introduction into <em>Pathfinder</em> ?</h3>
<p>
Unfortunately not. I will probably not have the time to answer any question personally.
Make sure you have read the <span class="pf-navbar-manual"><a href="javascript:void(0);">manual</a></span>.
<br>
If there are still some open questions, please ask in the <a target="_blank" href="https://forums.eveonline.com/">official forums</a> thread for help.
</p>
<h3>Which browsers are compatible with <em>Pathfinder</em>?</h3>
Expand Down
8 changes: 4 additions & 4 deletions sass/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -728,14 +728,14 @@ $close-text-shadow: 0 1px 0 #fff;
//
//##

$code-color: #c7254e;
$code-bg: #f9f2f4;
$code-color: $gray-darkest;
$code-bg: $gray-light;

$kbd-color: $gray-lighter;
$kbd-bg: $gray-darker;

$pre-bg: #f5f5f5;
$pre-color: $gray-dark;
$pre-bg: $gray-light;
$pre-color: $gray-darkest;
$pre-border-color: #ccc;
$pre-scrollable-max-height: 340px;

Expand Down
Loading

0 comments on commit 3f4d33a

Please sign in to comment.