-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2fa0d04
Showing
78 changed files
with
2,761 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This file documents the revision history for Perl extension DealsManager. | ||
|
||
0.01 2012-07-03 17:53:25 | ||
- initial revision, generated by Catalyst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env perl | ||
# IMPORTANT: if you delete this file your app will not work as | ||
# expected. You have been warned. | ||
use inc::Module::Install 1.02; | ||
use Module::Install::Catalyst; # Complain loudly if you don't have | ||
# Catalyst::Devel installed or haven't said | ||
# 'make dist' to create a standalone tarball. | ||
|
||
name 'DealsManager'; | ||
all_from 'lib/DealsManager.pm'; | ||
|
||
requires 'Catalyst::Runtime' => '5.90012'; | ||
requires 'Catalyst::Plugin::ConfigLoader'; | ||
requires 'Catalyst::Plugin::Static::Simple'; | ||
requires 'Catalyst::Action::RenderView'; | ||
requires 'Moose'; | ||
requires 'namespace::autoclean'; | ||
requires 'Config::General'; # This should reflect the config file format you've chosen | ||
# See Catalyst::Plugin::ConfigLoader for supported formats | ||
|
||
requires 'Catalyst::Plugin::Authentication'; | ||
requires 'Catalyst::Plugin::Session'; | ||
requires 'Catalyst::Plugin::Session::Store::File'; | ||
requires 'Catalyst::Plugin::Session::State::Cookie'; | ||
|
||
test_requires 'Test::More' => '0.88'; | ||
catalyst; | ||
|
||
install_script glob('script/*.pl'); | ||
auto_install; | ||
WriteAll; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Run script/dealsmanager_server.pl to test the application. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
-- create a database, connect to it and then run the following code | ||
create table users ( | ||
id serial primary key, | ||
username varchar, | ||
password varchar); | ||
|
||
CREATE TABLE roles ( | ||
id serial primary key, | ||
role varchar | ||
); | ||
|
||
CREATE TABLE users_roles ( | ||
user_id INTEGER REFERENCES users, | ||
role_id INTEGER REFERENCES roles, | ||
PRIMARY KEY (user_id, role_id) | ||
); | ||
|
||
create table contacts ( | ||
id serial primary key, | ||
name varchar, | ||
phone varchar, | ||
address varchar, | ||
email varchar, | ||
notes text, | ||
created timestamp with time zone); | ||
|
||
create table deals ( | ||
id serial primary key, | ||
name varchar, | ||
responsible_id int references users, | ||
contact_id int references contacts, | ||
status varchar, | ||
price int, | ||
probability int, | ||
created timestamp with time zone, | ||
updated timestamp with time zone); | ||
|
||
create table notes ( | ||
id serial primary key, | ||
note text, | ||
deal_id int references deals on update cascade on delete cascade, | ||
user_id int references users on update cascade on delete restrict, | ||
created timestamp with time zone); | ||
|
||
create table dashboard ( | ||
id serial primary key, | ||
content text, | ||
created timestamp with time zone, | ||
"type" varchar, -- deal created, deal updated, deal deleted, note created, note deleted, | ||
user_id int references users, | ||
deal_id int references deals); | ||
|
||
|
||
-- data | ||
|
||
insert into users (username, password) values | ||
('admin', 'admin'); | ||
|
||
insert into roles (role) values | ||
('admin'); | ||
|
||
insert into users_roles (user_id, role_id) values | ||
(1, 1); | ||
|
||
insert into contacts (name) values | ||
('Sérgio Ruoso'); | ||
|
||
insert into deals (name, responsible_id, contact_id, price) values | ||
('Deal 1', 1, 1, '700'); | ||
|
||
insert into notes (note, deal_id, user_id) values | ||
('Body of note', 1, 1), | ||
('Note note', 1, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# rename this file to dealsmanager.yml and put a ':' after 'name' if | ||
# you want to use YAML like in old versions of Catalyst | ||
name DealsManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use DealsManager; | ||
|
||
my $app = DealsManager->apply_default_middlewares(DealsManager->psgi_app); | ||
$app; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package DealsManager; | ||
use Moose; | ||
use namespace::autoclean; | ||
|
||
use Catalyst::Runtime 5.80; | ||
|
||
# Set flags and add plugins for the application. | ||
# | ||
# Note that ORDERING IS IMPORTANT here as plugins are initialized in order, | ||
# therefore you almost certainly want to keep ConfigLoader at the head of the | ||
# list if you're using it. | ||
# | ||
# -Debug: activates the debug mode for very useful log messages | ||
# ConfigLoader: will load the configuration from a Config::General file in the | ||
# application's home directory | ||
# Static::Simple: will serve static files from the application's root | ||
# directory | ||
|
||
use Catalyst qw/ | ||
-Debug | ||
ConfigLoader | ||
Static::Simple | ||
Authentication | ||
Authorization::Roles | ||
Session | ||
Session::Store::File | ||
Session::State::Cookie | ||
/; | ||
|
||
extends 'Catalyst'; | ||
|
||
our $VERSION = '0.01'; | ||
|
||
# Configure the application. | ||
# | ||
# Note that settings in dealsmanager.conf (or other external | ||
# configuration file that you set up manually) take precedence | ||
# over this when using ConfigLoader. Thus configuration | ||
# details given here can function as a default configuration, | ||
# with an external configuration file acting as an override for | ||
# local deployment. | ||
|
||
__PACKAGE__->config( | ||
name => 'DealsManager', | ||
|
||
# Disable deprecated behavior needed by old applications | ||
disable_component_resolution_regex_fallback => 1, | ||
|
||
enable_catalyst_header => 1, # Send X-Catalyst header | ||
|
||
'Plugin::Authentication' => { | ||
default => { | ||
class => 'SimpleDB', | ||
user_model => 'DB::User' | ||
} | ||
}, | ||
|
||
'Controller::HTML::FormFu' => { | ||
model_stash => { | ||
schema => 'DB' | ||
} | ||
}, | ||
|
||
); | ||
|
||
# Start the application | ||
__PACKAGE__->setup(); | ||
|
||
=head1 LICENSE | ||
This library is free software. You can redistribute it and/or modify | ||
it under the same terms as Perl itself. | ||
=cut | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package DealsManager::Controller::Auth; | ||
use Moose; | ||
use namespace::autoclean; | ||
|
||
BEGIN { extends 'Catalyst::Controller'; } | ||
|
||
sub login :Local { | ||
my ($self, $c) = @_; | ||
} | ||
|
||
sub login_do :Local { | ||
my ($self, $c) = @_; | ||
|
||
my $authentication_response = | ||
$c->authenticate({ username => $c->req->params->{username}, | ||
password => $c->req->params->{password} }); | ||
|
||
if ( $authentication_response ) { | ||
$c->res->redirect('/deals'); | ||
} | ||
else { | ||
$c->res->redirect('/auth/login'); | ||
} | ||
} | ||
|
||
sub logout :Local { | ||
my ($self, $c) = @_; | ||
|
||
$c->logout; | ||
$c->res->redirect('/deals'); | ||
} | ||
|
||
__PACKAGE__->meta->make_immutable; | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package DealsManager::Controller::Contacts; | ||
use Moose; | ||
use namespace::autoclean; | ||
|
||
BEGIN { extends 'Catalyst::Controller::HTML::FormFu'; } | ||
|
||
sub base :Chained('/') PathPart('contacts') CaptureArgs(0) { | ||
my ( $self, $c ) = @_; | ||
|
||
$c->stash->{resulset} = $c->model('DB::Contact'); | ||
} | ||
|
||
sub object :Chained('base') PathPart('') CaptureArgs(1) { | ||
my ( $self, $c, $id ) = @_; | ||
|
||
$c->stash->{object} = | ||
$c->stash->{resulset}->search_rs({ 'me.id' => $id }); | ||
} | ||
|
||
sub index :Chained('base') PathPart('') Args(0) { | ||
my ( $self, $c ) = @_; | ||
|
||
my $rs = $c->stash->{resulset}; | ||
|
||
$c->stash->{contacts} = [ $rs->all ]; | ||
} | ||
|
||
sub show :Chained('object') PathPart('') Args(0) { | ||
my ( $self, $c ) = @_; | ||
|
||
my $contact = $c->stash->{object}->first; | ||
|
||
$c->stash->{object} = $c->stash->{object} | ||
->search_rs(undef, | ||
{ prefetch => [ 'deals' ] } ) | ||
->first; | ||
} | ||
|
||
sub create :Chained('base') PathPart('create') Args(0) FormConfig('contacts/form.yml') { | ||
my ( $self, $c ) = @_; | ||
|
||
my $form = $c->stash->{form}; | ||
|
||
if ( $form->submitted_and_valid ) { | ||
my $new_contact = $c->stash->{resulset}->new_result({}); | ||
$form->model->update( $new_contact ); | ||
$c->res->redirect('/contacts'); | ||
} | ||
} | ||
|
||
sub edit :Chained('object') PathPart('edit') Args(0) FormConfig('contacts/form.yml') { | ||
my ( $self, $c ) = @_; | ||
|
||
my $form = $c->stash->{form}; | ||
|
||
if ( $form->submitted_and_valid ) { | ||
$form->model->update( $c->stash->{object}->first ); | ||
$c->res->redirect('/contacts'); | ||
} | ||
else { | ||
$form->model->default_values( $c->stash->{object}->first ); | ||
} | ||
} | ||
|
||
sub delete :Chained('object') PathPart('delete') Args(0) { | ||
my ( $self, $c ) = @_; | ||
|
||
$c->stash->{object}->first->delete; | ||
$c->res->redirect('/contacts'); | ||
} | ||
|
||
=head1 AUTHOR | ||
sgrs,,, | ||
=head1 LICENSE | ||
This library is free software. You can redistribute it and/or modify | ||
it under the same terms as Perl itself. | ||
=cut | ||
|
||
__PACKAGE__->meta->make_immutable; | ||
|
||
1; |
Oops, something went wrong.