-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added GitHub API support (show release info)
new dialog (show release info) fixed caching timings (main ajax update trigger calls) fixed footer "current year" number
- Loading branch information
Showing
29 changed files
with
459 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
|
||
}); | ||
|
||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
<ul class="timeline"></ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.