Commit 69e556c1 by Alex Bush

news

1 parent 8133e5fa
...@@ -43,16 +43,21 @@ sub wikitree { ...@@ -43,16 +43,21 @@ sub wikitree {
get '/' => sub { get '/' => sub {
my $self = shift; my $self = shift;
my @wikitree = wikitree(); my $news_row = $dbi->select(
['*'],
table => 'news',
);
my $news = $news_row->all;
$self->render( $self->render(
template => 'index', template => 'index',
title => 'Welcome', title => 'Welcome',
layout => 'default', layout => 'default',
wikitree => \@wikitree, news => $news,
); );
}; };
get '/download' => sub { get '/download' => sub {
my $self = shift; my $self = shift;
...@@ -119,6 +124,7 @@ get '/wiki' => sub { ...@@ -119,6 +124,7 @@ get '/wiki' => sub {
); );
}; };
post '/login' => sub { post '/login' => sub {
my $self = shift; my $self = shift;
my $login = $self->param('username') || ''; my $login = $self->param('username') || '';
...@@ -162,6 +168,80 @@ under sub { ...@@ -162,6 +168,80 @@ under sub {
return; return;
}; };
any '/news/new' => sub {
my $self = shift;
my $name = $self->param('name');
my $article = $self->param('article');
if ( !$name ) {
$self->render(
template => 'news/new',
title => 'News',
layout => 'default',
);
} else {
$dbi->insert(
{
article => $article,
name => $name,
},
table => 'news',
);
$self->redirect_to('/');
}
};
get '/news/:id' => sub {
my $self = shift;
my $action = $self->param('a');
my $id = $self->param('id');
if ( $action eq 'edit' ) {
my $article_row = $dbi->select(
['*'],
table => 'news',
);
my $article = $article_row->one;
$self->render(
template => 'news/edit',
title => 'News',
layout => 'default',
article => $article,
);
} elsif ( $action eq 'delete' ) {
my $status = $dbi->delete(
table => 'news',
where => { id => $id }
);
$self->redirect_to('/');
}
};
post '/news/:id' => sub {
my $self = shift;
my $action = $self->param('a');
my $name = $self->param('name');
my $article = $self->param('article');
my $id = $self->param('id');
if ( $action eq 'edit' ) {
$dbi->update(
{
article => $article,
name => $name,
},
table => 'news',
where => { id => $id }
);
$self->redirect_to('/');
} else {
}
};
get '/wiki/:url/edit' => sub { get '/wiki/:url/edit' => sub {
my $self = shift; my $self = shift;
my $url = $self->param('url'); my $url = $self->param('url');
......
...@@ -20,4 +20,7 @@ ...@@ -20,4 +20,7 @@
# Auth # Auth
username => 'admin', username => 'admin',
userpass => 'test', userpass => 'test',
hypnotoad => {
listen => ['http://*:3000']
}
}; };
\ No newline at end of file
No preview for this file type
% if ( my $login = session 'login' ) {
<div class="row">
<div class="span1 offset10">
<a href="/news/new" class="btn btn-primary">
<i class="icon-pencil icon-white"></i>
<span><strong>New</strong></span>
</a>
</div>
</div>
<br>
% }
<div class="row"> <div class="row">
<div class="well"> <div class="well">
<div class="row"> <div class="row">
<div class="span5"> <div class="span9">
<div class="box"> <div class="box">
<div class="box-header">Welcome</div> <div class="box-header">Welcome</div>
<div class="box-body"> <div class="box-body">
<h1>Добро пожаловать</h1> <h1>Добро пожаловать</h1>
%# dumper $news
</div> </div>
</div> </div>
<hr>
% foreach my $article (@$news ) {
<div class="box">
<div class="box-header"><%= $article->{'name'} %></div>
<div class="box-body">
<%= $article->{'article'} %>
</div>
</div>
% if ( my $login = session 'login' ) {
<div class="btn-group">
<a href="/news/<%= $article->{'id'} %>?a=edit"><button class="btn">Edit</button></a>
<a href="/news/<%= $article->{'id'} %>?a=delete"><button class="btn">Delete</button></a>
</div>
% }
<hr>
% }
</div> </div>
</div> </div>
</div> </div>
......
<div class="row">
<div class="well">
<div class="box">
<div class="box-header">Установка игры:</div>
<div class="box-body">
<form action="/news/<%= $article->{'id'} %>?a=edit" method="post">
<input type="hidden" name="page_id" value="">
<label for="name">Заголовок:</label>
<input type="text" name="name" class="span10" value="<%= $article->{'name'} %>"><br>
<textarea id="some-textarea" rows="10" class="span10" name="article"><%= $article->{'article'} %></textarea><br>
<script type="text/javascript">
$('#some-textarea').wysihtml5();
</script>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Сохранить</button>
<a href="javascript:history.back();"><button type="button" class="btn">Отменить</button></a>
</div>
</form>
</div>
</div>
</div>
</div>
\ No newline at end of file
<div class="row">
<div class="well">
<div class="box">
<div class="box-header">Установка игры:</div>
<div class="box-body">
<form action="/news/new" method="post">
<input type="hidden" name="page_id" value="">
<label for="name">Заголовок:</label>
<input type="text" name="name" class="span10" value=""><br>
<textarea id="some-textarea" rows="10" class="span10" name="article"></textarea><br>
<script type="text/javascript">
$('#some-textarea').wysihtml5();
</script>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Сохранить</button>
<a href="javascript:history.back();"><button type="button" class="btn">Отменить</button></a>
</div>
</form>
</div>
</div>
</div>
</div>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!