Skip to content

Commit

Permalink
Merge pull request #126 from Pear-Trading/Release-v0.10.10
Browse files Browse the repository at this point in the history
Release v0.10.10
  • Loading branch information
TBSliver authored Sep 16, 2019
2 parents 647e68a + 558e7e1 commit 95ff10f
Show file tree
Hide file tree
Showing 130 changed files with 33,841 additions and 175 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
myapp.conf
hypnotoad.pid
*.db
*.db-wal
*.db-shm
*.db-journal
*~
/images
*.swp
/upload

cover_db/
schema.png
Expand Down
7 changes: 7 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/Foodloop-Server.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/sqldialects.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ language: perl
# postgresql: "9.6"

perl:
- "5.20"
- "5.26"
env:
- HARNESS_PERL_SWITCHES="-MDevel::Cover"
install:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

# Next Release

# v0.10.10

* Added proper minion job support
* **Admin Feature** Added importing of CSVs from Lancaster City Council
* Added pagination support to searching of organisations during transaction submission in API

# v0.10.9

* Removed sector list from dashboard stats and swapped it for category list
Expand Down
126 changes: 126 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,129 @@ cpanm --installdeps . --with-feature postgres
PEAR_TEST_PG=1 prove -lr
```

# Minion

to set up minion support, you will need to create a database and user for
minion to connect to. In production his should be a PostgreSQL database,
however an SQLite db can be used in testing.

To use the SQLite version, run the following commands:

```
cpanm --installdeps --with-feature sqlite .
```

And then add the following to your configuration file:

```
minion => {
SQLite => 'sqlite:minion.db',
},
```

This will then use an SQLite db for the minion backend, using `minion.db` as
the database file. To start the minion itself, run:

```
./script/pear-local_loop minion worker
```

# Importing Ward Data

To import ward data, get the ward data csv and then run the following command:

```shell script
./script/pear-local_loop minion job \
--enqueue 'csv_postcode_import' \
--args '[ "/path/to/ward/csv" ]'
```

# Setting up Entity Postcodes

Assuming you have imported codepoint open, then to properly assign all
postcodes:

```shell script
./script/pear-local_loop minion job \
--enqueue entity_postcode_lookup
```

## Example PostgreSQL setup

```
# Example commands - probably not the best ones
# TODO come back and improve these with proper ownership and DDL rights
sudo -u postgres createuser minion
sudo -u postgres createdb localloop_minion
sudo -u postgres psql
psql=# alter user minion with encrypted password 'abc123';
psql=# grant all privileges on database localloop_minion to minion;
```

# Development

There are a couple of setup steps to getting a development environment ready.
Use the corresponding instructions depending on what state your current setup
is in.

## First Time Setup

First, decide if you're using SQLite or PostgreSQL locally. Development supports
both, however production uses PostgreSQL. For this example we will use SQLite.
As the default config is set up for this, no configuration changes are
needed initially. So, first off, install dependencies:

```shell script
cpanm --installdeps . --with-feature=sqlite
```

Then install the database:

```shell script
./script/deploy_db install -c 'dbi:SQLite:dbname=foodloop.db'
```

Then set up the development users:

```shell script
./script/pear-local_loop dev_data --force
```

***Note: do NOT run that script on production.***

Then you can start the application:

```shell script
morbo script/pear-local_loop -l http://*:3000
```

You can modify the host and port for listening as needed.

# Old Docs

## Local test database

To install a local DB:

```
./script/deploy_db install -c 'dbi:SQLite:dbname=foodloop.db'
```

To do an upgrade of it after making DB changes to commit:

```
./script/deploy_db write_ddl -c 'dbi:SQLite:dbname=foodloop.db'
./script/deploy_db upgrade -c 'dbi:SQLite:dbname=foodloop.db'
```

To redo leaderboards:

```
./script/pear-local_loop recalc_leaderboards
```

To serve a test version locally of the server:

```
morbo script/pear-local_loop
```
10 changes: 9 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ requires 'DBIx::Class::Schema::Loader';
requires 'SQL::Translator';
requires 'DateTime';
requires 'DateTime::Format::Strptime', "1.73";
requires 'DateTime::Format::SQLite';
requires 'Try::Tiny';
requires 'MooX::Options::Actions';
requires 'Module::Runtime';
Expand All @@ -23,6 +22,8 @@ requires 'DBIx::Class::Fixtures';
requires 'GIS::Distance';
requires 'Text::CSV';
requires 'Try::Tiny';
requires 'Throwable::Error';
requires 'Minion';

on 'test' => sub {
requires 'Test::More';
Expand All @@ -37,6 +38,13 @@ feature 'schema-graph', 'Draw diagrams of Schema' => sub {
feature 'postgres', 'PostgreSQL Support' => sub {
requires 'DBD::Pg';
requires 'Test::PostgreSQL';
requires 'Mojo::Pg';
requires 'DateTime::Format::Pg';
};

feature 'sqlite', 'SQLite Support' => sub {
requires 'Minion::Backend::SQLite';
requires 'DateTime::Format::SQLite';
};

feature 'codepoint-open', 'Code Point Open manipulation' => sub {
Expand Down
25 changes: 25 additions & 0 deletions lib/Pear/LocalLoop.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sub startup {
$self->plugin('Config', {
default => {
storage_path => tempdir,
upload_path => $self->home->child('upload'),
sessionTimeSeconds => 60 * 60 * 24 * 7,
sessionTokenJsonName => 'session_key',
sessionExpiresJsonName => 'sessionExpires',
Expand All @@ -49,6 +50,7 @@ sub startup {
$self->plugin('Pear::LocalLoop::Plugin::Currency');
$self->plugin('Pear::LocalLoop::Plugin::Postcodes');
$self->plugin('Pear::LocalLoop::Plugin::TemplateHelpers');
$self->plugin('Pear::LocalLoop::Plugin::Minion');

$self->plugin('Authentication' => {
'load_user' => sub {
Expand Down Expand Up @@ -158,6 +160,7 @@ sub startup {
$api->post('/stats')->to('api-stats#post_index');
$api->post('/stats/category')->to('api-categories#post_category_list');
$api->post('/stats/customer')->to('api-stats#post_customer');
$api->post('/stats/organisation')->to('api-stats#post_organisation');
$api->post('/stats/leaderboard')->to('api-stats#post_leaderboards');
$api->post('/stats/leaderboard/paged')->to('api-stats#post_leaderboards_paged');
$api->post('/outgoing-transactions')->to('api-transactions#post_transaction_list_purchases');
Expand Down Expand Up @@ -188,6 +191,15 @@ sub startup {
$api_v1_org->post('/employee')->to('api-organisation#post_employee_read');
$api_v1_org->post('/employee/add')->to('api-organisation#post_employee_add');

$api_v1_org->post('/external/transactions')->to('api-external#post_lcc_transactions');
$api_v1_org->post('/external/suppliers')->to('api-external#post_lcc_suppliers');
$api_v1_org->post('/external/year_spend')->to('api-external#post_year_spend');
$api_v1_org->post('/external/supplier_count')->to('api-external#post_supplier_count');
$api_v1_org->post('/external/supplier_history')->to('api-external#post_supplier_history');
$api_v1_org->post('/external/lcc_tables')->to('api-external#post_lcc_table_summary');

$api_v1_org->post('/pies')->to('api-v1-organisation-pies#index');

my $api_v1_cust = $api_v1->under('/customer')->to('api-v1-customer#auth');

$api_v1_cust->post('/graphs')->to('api-v1-customer-graphs#index');
Expand All @@ -196,6 +208,12 @@ sub startup {

my $admin_routes = $r->under('/admin')->to('admin#under');

if ( defined $config->{minion} ) {
$self->plugin( 'Minion::Admin' => {
return_to => '/admin/home',
route => $admin_routes->any('/minion'),
} );
}
$admin_routes->get('/home')->to('admin#home');

$admin_routes->get('/tokens')->to('admin-tokens#index');
Expand Down Expand Up @@ -244,6 +262,13 @@ sub startup {

$admin_routes->get('/import/:set_id/ignore/:value_id')->to('admin-import#ignore_value');
$admin_routes->get('/import/:set_id/import')->to('admin-import#run_import');

$admin_routes->get('/import_from')->to('admin-import_from#index');
$admin_routes->post('/import_from/suppliers')->to('admin-import_from#post_suppliers');
$admin_routes->post('/import_from/transactions')->to('admin-import_from#post_transactions');
$admin_routes->post('/import_from/postcodes')->to('admin-import_from#post_postcodes');
$admin_routes->get('/import_from/org_search')->to('admin-import_from#org_search');

# my $user_routes = $r->under('/')->to('root#under');

# $user_routes->get('/home')->to('root#home');
Expand Down
7 changes: 6 additions & 1 deletion lib/Pear/LocalLoop/Command/codepoint_open.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ sub run {

unless ( -d $output_dir ) {
print "Unzipping code-point-open data\n" unless $quiet_mode;
system( 'unzip', '-q', $zip_file, '-d', $output_dir );
eval { system( 'unzip', '-q', $zip_file, '-d', $output_dir ) };
if ( my $err = $@ ) {
print "Error extracting zip: " . $err . "\n";
print "Manually create etc/code-point-open/codepo_gb directory and extract zip into it";
die;
}
}

my $cpo = Geo::UK::Postcode::CodePointOpen->new( path => $output_dir );
Expand Down
2 changes: 2 additions & 0 deletions lib/Pear/LocalLoop/Controller/Admin/Categories.pm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ sub update {
my $validation = $c->validation;
$validation->required('id');
$validation->required('category', 'trim')->like(qr/^[\w]*$/);
$validation->optional('line_icon');

my $id = $c->param('id');

Expand All @@ -70,6 +71,7 @@ sub update {
$category->update({
id => $validation->param('id'),
name => $validation->param('category'),
line_icon => (defined $validation->param('line_icon') ? $validation->param('line_icon') : undef ),
});
$c->flash( success => 'Category Updated' );
$c->redirect_to( '/admin/categories/' . $validation->param('id') );
Expand Down
Loading

0 comments on commit 95ff10f

Please sign in to comment.