Added tag presenter

This commit is contained in:
Marcin Kurczewski 2014-10-07 21:15:26 +02:00
parent e85293f338
commit ad8e3bdcd5
11 changed files with 151 additions and 24 deletions

View file

@ -19,6 +19,11 @@ h2 {
font-weight: normal; font-weight: normal;
} }
h3 {
font-weight: normal;
font-size: 20px;
}
#middle { #middle {
padding: 0 2em; padding: 0 2em;
position: relative; position: relative;

View file

@ -170,3 +170,27 @@ input[type=checkbox]:checked + label:before {
margin-left: 0.5em; margin-left: 0.5em;
cursor: pointer; cursor: pointer;
} }
.autocomplete {
position: absolute;
display: none;
z-index: 10;
}
.autocomplete ul {
list-style-type: none;
padding: 0 0 !important;
margin: 0 !important;
border: 2px solid #5da;
background: white;
display: block !important;
text-align: left;
}
.autocomplete li {
margin: 0;
padding: 0.1em 0.5em !important;
}
.autocomplete li.active {
background: #5da;
}

View file

@ -1,20 +1,20 @@
#post-list { .post-list {
text-align: center; text-align: center;
} }
#post-list .wrapper { .post-list .wrapper {
display: inline-block; display: inline-block;
margin: 0 auto; margin: 0 auto;
} }
#post-list .search { .post-list .search {
margin-bottom: 1em; margin-bottom: 1em;
} }
#post-list .search input { .post-list .search input {
max-width: 20em; max-width: 20em;
} }
#post-list ul { .post-list ul {
list-style-type: none; list-style-type: none;
padding: 0; padding: 0;
margin: 0; margin: 0;

View file

@ -1,23 +1,19 @@
.autocomplete { #tag-view {
position: absolute; margin: 0 auto;
display: none; max-width: 45em;
z-index: 10; text-align: center;
} }
.autocomplete ul {
list-style-type: none; #tav-view .header {
padding: 0 0 !important;
margin: 0 !important;
border: 2px solid #5da;
background: white;
display: block !important;
text-align: left; text-align: left;
display: inline-block;
margin: 0 auto;
} }
.autocomplete li { #tag-view .header h1 {
margin: 0; margin-top: 0;
padding: 0.1em 0.5em !important;
} }
.autocomplete li.active { #tag-view h3 {
background: #5da; margin-bottom: 0.5em;
} }

View file

@ -118,6 +118,7 @@
<script type="text/javascript" src="/js/Presenters/PostCommentListPresenter.js"></script> <script type="text/javascript" src="/js/Presenters/PostCommentListPresenter.js"></script>
<script type="text/javascript" src="/js/Presenters/TagListPresenter.js"></script> <script type="text/javascript" src="/js/Presenters/TagListPresenter.js"></script>
<script type="text/javascript" src="/js/Presenters/TagPresenter.js"></script>
<script type="text/javascript" src="/js/Presenters/HelpPresenter.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/HomePresenter.js"></script>

View file

@ -6,6 +6,7 @@ App.Presenters.TagListPresenter = function(
jQuery, jQuery,
util, util,
promise, promise,
keyboard,
pagerPresenter, pagerPresenter,
topNavigationPresenter) { topNavigationPresenter) {
@ -52,6 +53,11 @@ App.Presenters.TagListPresenter = function(
page: searchArgs.page, page: searchArgs.page,
searchParams: { searchParams: {
order: searchArgs.order}}); order: searchArgs.order}});
keyboard.keyup('p', function() {
$el.find('table a').eq(0).focus();
});
} }
function deinit() { function deinit() {
@ -92,4 +98,4 @@ App.Presenters.TagListPresenter = function(
}; };
App.DI.register('tagListPresenter', ['_', 'jQuery', 'util', 'promise', 'pagerPresenter', 'topNavigationPresenter'], App.Presenters.TagListPresenter); App.DI.register('tagListPresenter', ['_', 'jQuery', 'util', 'promise', 'keyboard', 'pagerPresenter', 'topNavigationPresenter'], App.Presenters.TagListPresenter);

View file

@ -0,0 +1,77 @@
var App = App || {};
App.Presenters = App.Presenters || {};
App.Presenters.TagPresenter = function(
_,
jQuery,
util,
promise,
api,
keyboard,
topNavigationPresenter) {
var $el = jQuery('#content');
var templates = {};
var tagName;
function init(args, loaded) {
topNavigationPresenter.select('tags');
topNavigationPresenter.changeTitle('Tags');
promise.wait(
util.promiseTemplate('tag'),
util.promiseTemplate('post-list-item'))
.then(function(tagTemplate, postListItemTemplate) {
templates.tag = tagTemplate;
templates.postListItem = postListItemTemplate;
reinit(args, loaded);
});
}
function reinit(args, loaded) {
tagName = args.tagName;
render();
loaded();
promise.wait(api.get('posts', {query: tagName}))
.then(function(response) {
var posts = response.json.data;
posts = posts.slice(0, 8);
renderPosts(posts);
}).fail(function(response) {
console.log(new Error(response));
});
}
function render() {
$el.html(templates.tag({tagName: tagName}));
$el.find('.post-list').hide();
}
function renderPosts(posts) {
var $target = $el.find('.post-list ul');
_.each(posts, function(post) {
var $post = jQuery('<li>' + templates.postListItem({
post: post,
searchArgs: {query: tagName},
}) + '</li>');
$target.append($post);
});
if (posts.length > 0) {
$el.find('.post-list').fadeIn();
keyboard.keyup('p', function() {
$el.find('.post-list a').eq(0).focus();
});
}
}
return {
init: init,
reinit: reinit,
};
};
App.DI.register('tagPresenter', ['_', 'jQuery', 'util', 'promise', 'api', 'keyboard', 'topNavigationPresenter'], App.Presenters.TagPresenter);

View file

@ -42,6 +42,7 @@ App.Router = function(pathJs, _, jQuery, promise, util, appState, presenterManag
inject('#/post(/:postNameOrId)(/:searchArgs)', 'postPresenter'); inject('#/post(/:postNameOrId)(/:searchArgs)', 'postPresenter');
inject('#/comments(/:searchArgs)', 'globalCommentListPresenter'); inject('#/comments(/:searchArgs)', 'globalCommentListPresenter');
inject('#/tags(/:searchArgs)', 'tagListPresenter'); inject('#/tags(/:searchArgs)', 'tagListPresenter');
inject('#/tag(/:tagName)', 'tagPresenter');
inject('#/help', 'helpPresenter'); inject('#/help', 'helpPresenter');
setRoot('#/home'); setRoot('#/home');
} }

View file

@ -1,4 +1,4 @@
<div id="post-list"> <div class="post-list">
<form class="search"> <form class="search">
<input type="text" name="query" placeholder="Search query..."/> <input type="text" name="query" placeholder="Search query..."/>
<button type="submit">Search</button> <button type="submit">Search</button>

View file

@ -1,5 +1,8 @@
<tr class="tag"> <tr class="tag">
<td> <td>
<%= tag.name %> (<%= tag.usages %>) <a href="#/tag/<%= tag.name %>"><%= tag.name %></a>
</td>
<td>
<%= tag.usages %>
</td> </td>
</tr> </tr>

View file

@ -0,0 +1,14 @@
<div id="tag-view">
<div class="header">
<h1><%= tagName %></h1>
</div>
<div class="post-list">
<h3>Example usages</h3>
<ul>
</ul>
<a href="#/posts/query=<%= tagName %>">Search for more</a>
</div>
</div>