Permalink
Browse files

day 08

  • Loading branch information...
1 parent 21311c6 commit b2f7896e00d4c09357a8268b9221ea7b72623eef @typester committed Dec 8, 2009
View
@@ -3,6 +3,7 @@
return {
active_days => 30,
max_jobs_on_homepage => 10,
+ max_jobs_on_category => 20,
database => [
'dbi:SQLite:' . $home->file('database.db'), '', '',
View
@@ -1,6 +1,8 @@
package Jobeet;
use Ark;
+use Data::Page::Navigation;
+
our $VERSION = '0.01';
use_model 'Jobeet::Models';
@@ -0,0 +1,20 @@
+package Jobeet::Controller::Category;
+use Ark 'Controller';
+
+use Jobeet::Models;
+
+sub show :Path :Args(1) {
+ my ($self, $c, $category_name) = @_;
+
+ my $category = models('Schema::Category')->find({ slug => $category_name })
+ or $c->detach('/default');
+
+ $c->stash->{category} = $category;
+ $c->stash->{jobs} = $category->get_active_jobs({
+ rows => models('conf')->{max_jobs_on_category},
+ page => $c->req->param('page') || 1,
+ });
+}
+
+1;
+
View
@@ -3,7 +3,7 @@ use strict;
use warnings;
use base 'DBIx::Class::Schema';
-our $VERSION = '2';
+our $VERSION = '3';
__PACKAGE__->load_namespaces;
@@ -3,6 +3,8 @@ use strict;
use warnings;
use base 'Jobeet::Schema::ResultBase';
+use String::CamelCase qw(decamelize);
+
__PACKAGE__->table('jobeet_category');
__PACKAGE__->add_columns(
@@ -19,10 +21,16 @@ __PACKAGE__->add_columns(
size => 255,
is_nullable => 0,
},
+ slug => {
+ data_type => 'VARCHAR',
+ size => 255,
+ is_nullable => 0,
+ },
);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->add_unique_constraint(['name']);
+__PACKAGE__->add_unique_constraint(['slug']);
__PACKAGE__->has_many( jobs => 'Jobeet::Schema::Result::Job', 'category_id' );
@@ -35,15 +43,32 @@ sub get_active_jobs {
my $self = shift;
my $attr = shift || {};
- $attr->{rows} ||= 10;
-
$self->jobs(
{ expires_at => { '>=', DateTime->now } },
{ order_by => { -desc => 'created_at' },
- rows => $attr->{rows},
+ defined $attr->{rows} ? (rows => $attr->{rows}) : (),
+ defined $attr->{page} ? (page => $attr->{page}) : (),
}
);
}
+sub insert {
+ my $self = shift;
+
+ $self->slug( decamelize $self->name );
+
+ $self->next::method(@_);
+}
+
+sub update {
+ my $self = shift;
+
+ if ($self->is_changed('name')) {
+ $self->slug( decamelize $self->name );
+ }
+
+ $self->next::method(@_);
+}
+
1;
View
@@ -0,0 +1,64 @@
+? my $category = $c->stash->{category};
+? my $jobs = $c->stash->{jobs};
+? my $pager = $jobs->pager;
+
+? extends 'common/jobs_base';
+
+? block title => sub { sprintf 'Jobs in the %s category', $category->name };
+
+? block content => sub {
+<div class="category">
+ <div class="feed">
+ <a href="">Feed</a>
+ </div>
+ <h1><?= $category->name ?></h1>
+</div>
+
+?= include('job/partial_jobs', $category->get_active_jobs);
+
+? if ($pager->last_page > 1) {
+ <div class="pagination">
+ <a href="<?= $c->req->uri_with({ page => $pager->first_page }) ?>">
+ <img src="/images/first.png" alt="First page" />
+ </a>
+
+? if ($pager->previous_page) {
+ <a href="<?= $c->req->uri_with({ page => $pager->previous_page }) ?>">
+ <img src="/images/previous.png" alt="Previous page" title="Previous page" />
+ </a>
+? } else {
+ <img src="/images/previous.png" alt="Previous page" title="Previous page" />
+? }
+
+? for my $p ($pager->pages_in_navigation) {
+? if ($p == $pager->current_page) {
+ <?= $p ?>
+? } else {
+ <a href="<?= $c->req->uri_with({ page => $p }) ?>"><?= $p ?></a>
+? }
+? }
+
+? if ($pager->next_page) {
+ <a href="<?= $c->req->uri_with({ page => $pager->next_page }) ?>">
+ <img src="/images/next.png" alt="Next page" title="Next page" />
+ </a>
+? } else {
+ <img src="/images/next.png" alt="Next page" title="Next page" />
+? }
+
+ <a href="<?= $c->req->uri_with({ page => $pager->last_page }) ?>">
+ <img src="/images/last.png" alt="Last page" title="Last page" />
+ </a>
+ </div>
+? } # endif
+
+<div class="pagination_desc">
+ <strong><?= $pager->total_entries ?></strong> jobs in this category
+
+? if ($pager->last_page > 1) {
+ - page <strong><?= $pager->current_page ?>/<?= $pager->last_page ?></strong>
+? }
+</div>
+
+? } # endblock content
+
View
@@ -2,7 +2,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
- <title>Jobeet - Your best job board</title>
+ <title><? block title => sub { 'Jobeet - Your best job board' } ?></title>
<link rel="shortcut icon" href="/favicon.ico" />
<? block javascripts => '' ?>
<? block stylesheets => '' ?>
View
@@ -0,0 +1,7 @@
+? extends 'common/base';
+
+? block stylesheets => sub {
+<link rel="stylesheet" type="text/css" href="<?= $c->uri_for('/css/main.css') ?>" />
+<link rel="stylesheet" type="text/css" href="<?= $c->uri_for('/css/jobs.css') ?>" />
+? }
+
View
@@ -1,9 +1,4 @@
-? extends 'common/base';
-
-? block stylesheets => sub {
-<link rel="stylesheet" type="text/css" href="<?= $c->uri_for('/css/main.css') ?>" />
-<link rel="stylesheet" type="text/css" href="<?= $c->uri_for('/css/jobs.css') ?>" />
-? }
+? extends 'common/jobs_base';
? block content => sub {
<div id="jobs">
@@ -13,26 +8,24 @@
<div class="feed">
<a href="">Feed</a>
</div>
- <h1><?= $category->name ?></h1>
+ <h1>
+ <a href="<?= $c->uri_for('/category', $category->slug) ?>">
+ <?= $category->name ?>
+ </a>
+ </h1>
</div>
-
- <table class="jobs">
-? my $i = 0;
+
? my $max_rows = Jobeet::Models->get('conf')->{max_jobs_on_homepage};
-? for my $job ($category->get_active_jobs({ rows => $max_rows })) {
- <tr class="<?= $i++ % 2 ? 'even' : 'odd' ?>">
- <td class="location">
- <?= $job->location ?>
- </td>
- <td class="position">
- <?= $job->position ?>
- </td>
- <td class="company">
- <?= $job->company ?>
- </td>
- </tr>
-? } #endfor $job
- </table>
+?= include('job/partial_jobs', $category->get_active_jobs({ rows => $max_rows }));
+
+? my $count = $category->get_active_jobs->count;
+? if ( (my $rest = $count - $max_rows) > 0 ) {
+ <div class="more_jobs">
+ and <a href="<?= $c->uri_for('/category', $category->slug) ?>"><?= $rest ?></a>
+ more...
+ </div>
+? } # endif
+
</div>
? } #endfor $category
</div>
View
@@ -0,0 +1,17 @@
+? my @jobs = @_;
+<table class="jobs">
+? my $i = 0;
+? for my $job (@jobs) {
+ <tr class="<?= $i++ % 2 ? 'even' : 'odd' ?>">
+ <td class="location">
+ <?= $job->location ?>
+ </td>
+ <td class="position">
+ <?= $job->position ?>
+ </td>
+ <td class="company">
+ <?= $job->company ?>
+ </td>
+ </tr>
+? } #endfor $job
+</table>
@@ -0,0 +1,82 @@
+--
+-- Created by SQL::Translator::Producer::MySQL
+-- Created on Tue Dec 8 19:28:54 2009
+--
+SET foreign_key_checks=0;
+
+DROP TABLE IF EXISTS `jobeet_affiliate`;
+
+--
+-- Table: `jobeet_affiliate`
+--
+CREATE TABLE `jobeet_affiliate` (
+ `id` INTEGER unsigned NOT NULL auto_increment,
+ `url` VARCHAR(255) NOT NULL,
+ `email` VARCHAR(255) NOT NULL,
+ `token` VARCHAR(255) NOT NULL,
+ `is_active` TINYINT NOT NULL DEFAULT '0',
+ `created_at` datetime NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE `jobeet_affiliate_email` (`email`)
+) ENGINE=InnoDB;
+
+DROP TABLE IF EXISTS `jobeet_category`;
+
+--
+-- Table: `jobeet_category`
+--
+CREATE TABLE `jobeet_category` (
+ `id` INTEGER unsigned NOT NULL auto_increment,
+ `name` VARCHAR(255) NOT NULL,
+ `slug` VARCHAR(255) NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE `jobeet_category_name` (`name`),
+ UNIQUE `jobeet_category_slug` (`slug`)
+) ENGINE=InnoDB;
+
+DROP TABLE IF EXISTS `jobeet_job`;
+
+--
+-- Table: `jobeet_job`
+--
+CREATE TABLE `jobeet_job` (
+ `id` INTEGER unsigned NOT NULL auto_increment,
+ `category_id` INTEGER unsigned NOT NULL,
+ `type` VARCHAR(255),
+ `company` VARCHAR(255),
+ `logo` VARCHAR(255),
+ `url` VARCHAR(255),
+ `position` VARCHAR(255) NOT NULL,
+ `location` VARCHAR(255) NOT NULL,
+ `description` text NOT NULL,
+ `how_to_apply` text NOT NULL,
+ `token` VARCHAR(255) NOT NULL,
+ `is_public` TINYINT NOT NULL DEFAULT '1',
+ `is_activated` TINYINT NOT NULL DEFAULT '0',
+ `email` VARCHAR(255) NOT NULL,
+ `expires_at` datetime NOT NULL,
+ `created_at` datetime NOT NULL,
+ `updated_at` datetime NOT NULL,
+ INDEX jobeet_job_idx_category_id (`category_id`),
+ PRIMARY KEY (`id`),
+ UNIQUE `jobeet_job_token` (`token`),
+ CONSTRAINT `jobeet_job_fk_category_id` FOREIGN KEY (`category_id`) REFERENCES `jobeet_category` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+DROP TABLE IF EXISTS `jobeet_category_affiliate`;
+
+--
+-- Table: `jobeet_category_affiliate`
+--
+CREATE TABLE `jobeet_category_affiliate` (
+ `category_id` INTEGER unsigned NOT NULL,
+ `affiliate_id` INTEGER unsigned NOT NULL,
+ INDEX jobeet_category_affiliate_idx_affiliate_id (`affiliate_id`),
+ INDEX jobeet_category_affiliate_idx_category_id (`category_id`),
+ PRIMARY KEY (`category_id`, `affiliate_id`),
+ CONSTRAINT `jobeet_category_affiliate_fk_affiliate_id` FOREIGN KEY (`affiliate_id`) REFERENCES `jobeet_affiliate` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `jobeet_category_affiliate_fk_category_id` FOREIGN KEY (`category_id`) REFERENCES `jobeet_category` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB;
+
+SET foreign_key_checks=1;
+
Oops, something went wrong.

0 comments on commit b2f7896

Please sign in to comment.