Added 404 page

This commit is contained in:
Marcin Kurczewski 2014-10-18 12:37:01 +02:00
parent dd8050f250
commit 177a7d79f3
8 changed files with 81 additions and 8 deletions

1
TODO
View file

@ -20,7 +20,6 @@ first major release.
- misc: add README - apache2 has good README: - misc: add README - apache2 has good README:
http://svn.apache.org/repos/asf/httpd/httpd/trunk/README http://svn.apache.org/repos/asf/httpd/httpd/trunk/README
- misc: add spinner to forms such as registration, login, settings... - misc: add spinner to forms such as registration, login, settings...
- misc: add 404 pages
- misc: improve throbber appearance - misc: improve throbber appearance
- misc: try not to fade in images that are already in browser cache - misc: try not to fade in images that are already in browser cache

View file

@ -1,8 +1,12 @@
DirectoryIndex app.min.html DirectoryIndex app.min.html
DirectoryIndex index.html DirectoryIndex index.html
ErrorDocument 404 /404.html
RewriteEngine On RewriteEngine On
RewriteRule ^/?404.html$ /#/404 [NE,R,L]
#RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?data/posts/([^/]+)/? /api/posts/$1/content [L] RewriteRule ^/?data/posts/([^/]+)/? /api/posts/$1/content [L]

View file

@ -0,0 +1,6 @@
.http-error {
text-align: center;
}
.http-error img {
margin: 0 auto;
}

BIN
public_html/img/404.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View file

@ -46,6 +46,7 @@
<link rel="stylesheet" type="text/css" href="/css/tags.css"/> <link rel="stylesheet" type="text/css" href="/css/tags.css"/>
<link rel="stylesheet" type="text/css" href="/css/tag-list.css"/> <link rel="stylesheet" type="text/css" href="/css/tag-list.css"/>
<link rel="stylesheet" type="text/css" href="/css/help.css"/> <link rel="stylesheet" type="text/css" href="/css/help.css"/>
<link rel="stylesheet" type="text/css" href="/css/http-error.css"/>
<!-- /build --> <!-- /build -->
<!-- build:remove --> <!-- build:remove -->
@ -105,6 +106,7 @@
<script type="text/javascript" src="/js/Presenters/TopNavigationPresenter.js"></script> <script type="text/javascript" src="/js/Presenters/TopNavigationPresenter.js"></script>
<script type="text/javascript" src="/js/Presenters/PagerPresenter.js"></script> <script type="text/javascript" src="/js/Presenters/PagerPresenter.js"></script>
<script type="text/javascript" src="/js/Presenters/MessagePresenter.js"></script> <script type="text/javascript" src="/js/Presenters/MessagePresenter.js"></script>
<script type="text/javascript" src="/js/Presenters/HttpErrorPresenter.js"></script>
<script type="text/javascript" src="/js/Presenters/LoginPresenter.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/LogoutPresenter.js"></script>

View file

@ -0,0 +1,48 @@
var App = App || {};
App.Presenters = App.Presenters || {};
App.Presenters.HttpErrorPresenter = function(
jQuery,
promise,
util,
topNavigationPresenter) {
var $el = jQuery('#content');
var templates = {};
function init(params, loaded) {
topNavigationPresenter.changeTitle('Error ' + params.error);
if (params.error === 404) {
promise.wait(util.promiseTemplate('404'))
.then(function(template) {
templates.errorPage = template;
reinit(params, loaded);
}).fail(function() {
console.log(arguments);
loaded();
});
} else {
console.log('Not supported.');
loaded();
}
}
function reinit(params, loaded) {
render();
loaded();
}
function render() {
$el.html(templates.errorPage());
}
return {
init: init,
reinit: reinit,
render: render,
};
};
App.DI.register('httpErrorPresenter', ['jQuery', 'promise', 'util', 'topNavigationPresenter'], App.Presenters.HttpErrorPresenter);

View file

@ -11,6 +11,7 @@ App.Router = function(_, jQuery, promise, util, appState, presenterManager) {
function injectRoutes() { function injectRoutes() {
inject('', 'homePresenter'); inject('', 'homePresenter');
inject('#/', 'homePresenter'); inject('#/', 'homePresenter');
inject('#/404', 'httpErrorPresenter', {error: 404});
inject('#/home', 'homePresenter'); inject('#/home', 'homePresenter');
inject('#/login', 'loginPresenter'); inject('#/login', 'loginPresenter');
inject('#/logout', 'logoutPresenter'); inject('#/logout', 'logoutPresenter');
@ -28,20 +29,29 @@ App.Router = function(_, jQuery, promise, util, appState, presenterManager) {
inject('#/help(/:tab)', 'helpPresenter'); inject('#/help(/:tab)', 'helpPresenter');
} }
function navigate(url) { function navigate(url, useBrowserDispatcher) {
if (('pushState' in history) && !useBrowserDispatcher) {
history.pushState('', '', url);
dispatch();
} else {
window.location.href = url; window.location.href = url;
} }
}
function navigateToMainPage() { function navigateToMainPage() {
navigate(root); navigate(root);
} }
function navigateInplace(url) { function navigateInplace(url, useBrowserDispatcher) {
if ('replaceState' in history) { if ('replaceState' in history) {
history.replaceState('', '', url); history.replaceState('', '', url);
if (!useBrowserDispatcher) {
dispatch(); dispatch();
} else { } else {
navigate(url); location.reload();
}
} else {
navigate(url, useBrowserDispatcher);
} }
} }
@ -90,8 +100,7 @@ App.Router = function(_, jQuery, promise, util, appState, presenterManager) {
return true; return true;
} }
} }
//todo: 404 navigateInplace('#/404', true);
console.log(new Error('Unhandled route: ' + url));
return false; return false;
} }

View file

@ -0,0 +1,5 @@
<div class="http-error">
<img src="/img/404.png" alt="404 Not found"/>
<br/>
<a href="#/">Back to main page</a>
</div>