Added post view placeholder
This commit is contained in:
parent
9699aeaf64
commit
7806333b24
6 changed files with 120 additions and 3 deletions
|
@ -73,24 +73,32 @@
|
|||
<script type="text/javascript" src="/js/Controls/FileDropper.js"></script>
|
||||
<script type="text/javascript" src="/js/Controls/TagInput.js"></script>
|
||||
<script type="text/javascript" src="/js/PresenterManager.js"></script>
|
||||
|
||||
<script type="text/javascript" src="/js/Presenters/TopNavigationPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/PagedCollectionPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/MessagePresenter.js"></script>
|
||||
|
||||
<script type="text/javascript" src="/js/Presenters/LoginPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/LogoutPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/MessagePresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/RegistrationPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/UserActivationPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/UserListPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/UserBrowsingSettingsPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/UserAccountSettingsPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/UserAccountRemovalPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/UserPresenter.js"></script>
|
||||
|
||||
<script type="text/javascript" src="/js/Presenters/PostListPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/PostUploadPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/PostPresenter.js"></script>
|
||||
|
||||
<script type="text/javascript" src="/js/Presenters/CommentListPresenter.js"></script>
|
||||
|
||||
<script type="text/javascript" src="/js/Presenters/TagListPresenter.js"></script>
|
||||
|
||||
<script type="text/javascript" src="/js/Presenters/HelpPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/HomePresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/UserActivationPresenter.js"></script>
|
||||
|
||||
<script type="text/javascript" src="/js/Router.js"></script>
|
||||
<script type="text/javascript" src="/js/Bootstrap.js"></script>
|
||||
<!-- /build -->
|
||||
|
|
57
public_html/js/Presenters/PostPresenter.js
Normal file
57
public_html/js/Presenters/PostPresenter.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
var App = App || {};
|
||||
App.Presenters = App.Presenters || {};
|
||||
|
||||
App.Presenters.PostPresenter = function(
|
||||
_,
|
||||
jQuery,
|
||||
util,
|
||||
promise,
|
||||
api,
|
||||
topNavigationPresenter,
|
||||
messagePresenter) {
|
||||
|
||||
var $el = jQuery('#content');
|
||||
var $messages = $el;
|
||||
var template;
|
||||
var post;
|
||||
var postNameOrId;
|
||||
|
||||
function init(args, loaded) {
|
||||
postNameOrId = args.postNameOrId;
|
||||
topNavigationPresenter.select('posts');
|
||||
|
||||
promise.waitAll(
|
||||
util.promiseTemplate('post'),
|
||||
api.get('/posts/' + postNameOrId))
|
||||
.then(function(
|
||||
templatehtml,
|
||||
response) {
|
||||
$messages = $el.find('.messages');
|
||||
template = _.template(templatehtml);
|
||||
|
||||
post = response.json;
|
||||
topNavigationPresenter.changeTitle('@' + post.id);
|
||||
render();
|
||||
loaded();
|
||||
|
||||
}).fail(function(response) {
|
||||
$el.empty();
|
||||
messagePresenter.showError($messages, response.json && response.json.error || response);
|
||||
});
|
||||
}
|
||||
|
||||
function render() {
|
||||
$el.html(template({
|
||||
post: post,
|
||||
formatRelativeTime: util.formatRelativeTime,
|
||||
}));
|
||||
}
|
||||
|
||||
return {
|
||||
init: init,
|
||||
render: render
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
App.DI.register('postPresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'topNavigationPresenter', 'messagePresenter'], App.Presenters.PostPresenter);
|
|
@ -39,6 +39,7 @@ App.Router = function(pathJs, _, jQuery, util, appState, presenterManager) {
|
|||
inject('#/users(/:searchArgs)', 'userListPresenter');
|
||||
inject('#/user/:userName(/:tab)', 'userPresenter');
|
||||
inject('#/posts(/:searchArgs)', 'postListPresenter');
|
||||
inject('#/post(/:postNameOrId)', 'postPresenter');
|
||||
inject('#/comments(/:searchArgs)', 'commentListPresenter');
|
||||
inject('#/tags(/:searchArgs)', 'tagListPresenter');
|
||||
inject('#/help', 'helpPresenter');
|
||||
|
|
30
public_html/templates/post.tpl
Normal file
30
public_html/templates/post.tpl
Normal file
|
@ -0,0 +1,30 @@
|
|||
<% var postContentUrl = '/data/posts/' + post.name %>
|
||||
|
||||
<% if (post.contentType == 'image') { %>
|
||||
|
||||
<img alt="<%= post.name %>" src="<%= postContentUrl %>"/>
|
||||
|
||||
<% } else if (post.contentType == 'youtube') { %>
|
||||
|
||||
<iframe src="//www.youtube.com/embed/<%= post.contentChecksum %>?wmode=opaque" allowfullscreen></iframe>
|
||||
|
||||
<% } else if (post.contentType == 'flash') { %>
|
||||
|
||||
<object
|
||||
type="application/x-shockwave-flash"
|
||||
width="<%= post.imageWidth %>"
|
||||
height="<%= post.imageHeight %>"
|
||||
data="<%= postContentUrl %>">
|
||||
<param name="wmode" value="opaque"/>
|
||||
<param name="movie" value="<%= postContentUrl %>"/>
|
||||
</object>
|
||||
|
||||
<% } else if (post.contentType == 'video') { %>
|
||||
|
||||
<video controls>
|
||||
<source src="<%= postContentUrl %>"/>
|
||||
|
||||
Your browser doesn't support HTML5 videos.
|
||||
</video>
|
||||
|
||||
<% } else { console.log(new Error('Unknown post type')) } %>
|
|
@ -22,8 +22,15 @@ final class PostController extends AbstractController
|
|||
|
||||
public function registerRoutes(\Szurubooru\Router $router)
|
||||
{
|
||||
$router->get('/api/posts', [$this, 'getFiltered']);
|
||||
$router->post('/api/posts', [$this, 'createPost']);
|
||||
$router->get('/api/posts', [$this, 'getFiltered']);
|
||||
$router->get('/api/posts/:postNameOrId', [$this, 'getByNameOrId']);
|
||||
}
|
||||
|
||||
public function getByNameOrId($postNameOrId)
|
||||
{
|
||||
$post = $this->postService->getByNameOrId($postNameOrId);
|
||||
return $this->postViewProxy->fromEntity($post);
|
||||
}
|
||||
|
||||
public function getFiltered()
|
||||
|
|
|
@ -32,6 +32,20 @@ class PostService
|
|||
$this->authService = $authService;
|
||||
}
|
||||
|
||||
public function getByNameOrId($postNameOrId)
|
||||
{
|
||||
$transactionFunc = function() use ($postNameOrId)
|
||||
{
|
||||
$post = $this->postDao->findByName($postNameOrId);
|
||||
if (!$post)
|
||||
$post = $this->postDao->findById($postNameOrId);
|
||||
if (!$post)
|
||||
throw new \InvalidArgumentException('Post with name "' . $postName . '" was not found.');
|
||||
return $post;
|
||||
};
|
||||
return $this->transactionManager->rollback($transactionFunc);
|
||||
}
|
||||
|
||||
public function getByName($postName)
|
||||
{
|
||||
$transactionFunc = function() use ($postName)
|
||||
|
|
Loading…
Reference in a new issue