Skip to content

Commit

Permalink
Merge pull request #306 from nabeelio/issue-297/search-options
Browse files Browse the repository at this point in the history
Add more search criteria/dev environment via docker-compose #297
  • Loading branch information
nabeelio authored May 11, 2019
2 parents 1dae81b + df814ed commit b8d4f4e
Show file tree
Hide file tree
Showing 22 changed files with 320 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .travis/deploy_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ if [ "$TRAVIS" = "true" ]; then
.sass-cache
.idea
.travis
docker
tests
_ide_helper.php
.dpl
Expand All @@ -64,6 +65,7 @@ if [ "$TRAVIS" = "true" ]; then
.styleci.yml
env.php
config.php
docker-compose.yml
Makefile
phpunit.xml
phpvms.iml
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ update: build
@echo "Done!"

.PHONY: reset
reset: cleanapp/Models/Traits/JournalTrait.php
reset: clean
@php $(COMPOSER) dump-autoload
@make reload-db

Expand Down
4 changes: 2 additions & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dnsmasq: /usr/local/sbin/dnsmasq --keep-in-foreground
#dnsmasq: /usr/local/sbin/dnsmasq --keep-in-foreground
php-fpm: /usr/local/sbin/php-fpm --nodaemonize
nginx: /usr/local/bin/nginx -g 'daemon off;'
#mysql: /usr/local/bin/mysqld
mysql: docker-compose --file ~/docker/mysql/docker-compose.yml up
#mailhog: /usr/local/bin/mailhog
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

[![Build Status](https://travis-ci.org/nabeelio/phpvms.svg)](https://travis-ci.org/nabeelio/phpvms) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d668bebb0a3c46bda381af16ce3d9450)](https://www.codacy.com/app/nabeelio/phpvms?utm_source=github.com&utm_medium=referral&utm_content=nabeelio/phpvms&utm_campaign=Badge_Grade) [![Latest Stable Version](https://poser.pugx.org/nabeel/phpvms/v/stable)](https://packagist.org/packages/nabeel/phpvms) ![StyleCI](https://github.styleci.io/repos/93688482/shield?branch=dev) [![License](https://poser.pugx.org/nabeel/phpvms/license)](https://packagist.org/packages/nabeel/phpvms)

The next phpvms version built on the laravel framework. work in progress. If you're looking for
the old, phpVMS classic, it's [available here](https://github.com/nabeelio/phpvms_v2).
The next phpvms version built on the laravel framework. work in progress. The latest documentation, with installation instructions is available
[on the phpVMS documentation](http://docs.phpvms.net/) page.

# installation

A full distribution, with all of the composer dependencies, is available at this
[GitHub Releases](https://github.com/nabeelio/phpvms/releases) link.

The latest documentation, with installation instructions is available
[on the phpVMS documentation](http://docs.phpvms.net/) page.


## Requirements

Expand All @@ -30,6 +29,22 @@ The latest documentation, with installation instructions is available
## Installer

1. Upload to your server
2. Visit the site, and follow the link to the installer
1. Visit the site, and follow the link to the installer

[View installation details](http://docs.phpvms.net/setup/installation)

# development environment

A full development environment can be brought up using Docker:

```bash
composer install
npm install
docker-compose up
```

Then go to `http://localhost`. If you're using dnsmasq, the `app` container is listening on `phpvms.test`, or you can add to your `/etc/hosts` file:

```
127.0.0.1 phpvms.test
```
4 changes: 2 additions & 2 deletions app/Database/factories/FlightFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'alt_airport_id' => function () {
return factory(App\Models\Airport::class)->create()->id;
},
'distance' => $faker->numberBetween(0, 3000),
'distance' => $faker->numberBetween(0, 1000),
'route' => null,
'level' => 0,
'dpt_time' => $faker->time(),
Expand All @@ -35,7 +35,7 @@
'start_date' => null,
'end_date' => null,
'created_at' => $faker->dateTimeBetween('-1 week', 'now'),
'updated_at' => function (array $flight) {
'updated_at' => static function (array $flight) {
return $flight['created_at'];
},
];
Expand Down
24 changes: 15 additions & 9 deletions app/Http/Controllers/Api/FlightController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,37 @@ public function get($id)
*/
public function search(Request $request)
{
$user = Auth::user();

try {
$where = [
'active' => true,
'visible' => true,
];
$where = [
'active' => true,
'visible' => true,
];

// Allow the option to bypass some of these restrictions for the searches
if (!$request->filled('ignore_restrictions')
|| $request->get('ignore_restrictions') === '0'
) {
if (setting('pilots.restrict_to_company')) {
$where['airline_id'] = Auth::user()->airline_id;
}

if (setting('pilots.only_flights_from_current')) {
$where['dpt_airport_id'] = Auth::user()->curr_airport_id;
}
}

try {
$this->flightRepo->resetCriteria();
$this->flightRepo->searchCriteria($request);
$this->flightRepo->pushCriteria(new RequestCriteria($request));
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where));
$this->flightRepo->pushCriteria(new RequestCriteria($request));

$flights = $this->flightRepo->paginate();
} catch (RepositoryException $e) {
return response($e, 503);
}

foreach ($flights as $flight) {
$this->flightSvc->filterSubfleets($user, $flight);
$this->flightSvc->filterSubfleets(Auth::user(), $flight);
}

return FlightResource::collection($flights);
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Controllers/Frontend/FlightController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Log;
use Prettus\Repository\Criteria\RequestCriteria;
use Prettus\Repository\Exceptions\RepositoryException;

/**
Expand Down Expand Up @@ -68,6 +69,7 @@ public function index(Request $request)

try {
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where));
$this->flightRepo->pushCriteria(new RequestCriteria($request));
} catch (RepositoryException $e) {
Log::emergency($e);
}
Expand Down Expand Up @@ -137,6 +139,8 @@ public function search(Request $request)
$where['dpt_airport_id'] = Auth::user()->curr_airport_id;
}

$this->flightRepo->resetCriteria();

try {
$this->flightRepo->pushCriteria(new WhereCriteria($request, $where));
} catch (RepositoryException $e) {
Expand Down
12 changes: 12 additions & 0 deletions app/Http/Controllers/Frontend/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Interfaces\Controller;
use App\Models\User;
use Illuminate\Database\QueryException;
use Log;

/**
* Class HomeController
Expand All @@ -18,10 +19,21 @@ public function index()
{
try {
$users = User::orderBy('created_at', 'desc')->take(4)->get();
debug($users);
} catch (\PDOException $e) {
Log::emergency($e);
return view('system/errors/database_error', [
'error' => $e->getMessage(),
]);
} catch (QueryException $e) {
return view('system/errors/not_installed');
}

// No users
if (!$users) {
return view('system/errors/not_installed');
}

return view('home', [
'users' => $users,
]);
Expand Down
6 changes: 6 additions & 0 deletions app/Repositories/Criteria/WhereCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class WhereCriteria implements CriteriaInterface
protected $request;
protected $where;

/**
* Create a new Where search.
*
* @param $request
* @param $where
*/
public function __construct($request, $where)
{
$this->request = $request;
Expand Down
19 changes: 15 additions & 4 deletions app/Repositories/FlightRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ class FlightRepository extends Repository implements CacheableInterface

protected $fieldSearchable = [
'arr_airport_id',
'distance',
'dpt_airport_id',
'flight_number' => 'like',
'flight_code' => 'like',
'flight_leg' => 'like',
'route_code' => 'like',
'route_leg' => 'like',
'route' => 'like',
'notes' => 'like',
];

public function model()
public function model(): string
{
return Flight::class;
}
Expand Down Expand Up @@ -70,7 +71,7 @@ public function findFlight($airline_id, $flight_num, $route_code = null, $route_
*
* @return $this
*/
public function searchCriteria(Request $request, bool $only_active = true)
public function searchCriteria(Request $request, bool $only_active = true): self
{
$where = [];

Expand Down Expand Up @@ -103,6 +104,16 @@ public function searchCriteria(Request $request, bool $only_active = true)
$where['arr_airport_id'] = $request->arr_icao;
}

// Distance, greater than
if ($request->filled('dgt')) {
$where[] = ['distance', '>=', $request->dgt];
}

// Distance, less than
if ($request->filled('dlt')) {
$where[] = ['distance', '<=', $request->dlt];
}

$this->pushCriteria(new WhereCriteria($request, $where));

return $this;
Expand Down
7 changes: 5 additions & 2 deletions app/helpers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

use App\Exceptions\SettingNotFound;
use Illuminate\Contracts\View\Factory;

if (!function_exists('in_mask')) {
/**
* Return true/false if a value exists in a mask
Expand Down Expand Up @@ -109,7 +112,7 @@ function list_to_editable(array $list)
* @param array $vars
* @param array $merge_data
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @return Factory|\Illuminate\View\View
*/
function skin_view($template, array $vars = [], array $merge_data = [])
{
Expand All @@ -136,7 +139,7 @@ function setting($key, $default = null)

try {
$value = $settingRepo->retrieve($key);
} catch (\App\Exceptions\SettingNotFound $e) {
} catch (SettingNotFound $e) {
return $default;
}

Expand Down
51 changes: 26 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,41 @@
"ext-pdo": "*",
"composer/composer": "1.8.x",
"composer/semver": "1.4.x",
"laravel/framework": "5.7.x",
"laravelcollective/html": "5.7.x",
"prettus/l5-repository": "2.6.x",
"nwidart/laravel-modules": "3.3.x",
"santigarcor/laratrust": "5.0.x",
"akaunting/money": "1.0.x",
"anhskohbo/no-captcha": "3.0.x",
"arrilot/laravel-widgets": "3.13.x",
"sebastiaanluca/laravel-helpers": "1.0.x",
"joshbrw/laravel-module-installer": "0.1.x",
"webpatser/laravel-uuid": "3.x",
"igaster/laravel-theme": "2.0.x",
"irazasyed/laravel-gamp": "1.3.x",
"toin0u/geotools-laravel": "1.0.x",
"spatie/laravel-pjax": "1.3.x",
"myclabs/deep-copy": "1.8.x",
"league/geotools": "0.8.x",
"fzaninotto/faker": "^1.8",
"guzzlehttp/guzzle": "6.3.x",
"hashids/hashids": "2.0.x",
"igaster/laravel-theme": "2.0.x",
"intervention/image": "2.4.x",
"irazasyed/laravel-gamp": "1.3.x",
"jackiedo/timezonelist": "5.x",
"tivie/php-os-detector": "1.1.x",
"pragmarx/version": "0.2.x",
"guzzlehttp/guzzle": "6.3.x",
"jmikola/geojson": "1.0.x",
"joshbrw/laravel-module-installer": "0.1.x",
"laracasts/flash": "3.0.x",
"nabeel/vacentral": "1.x",
"laravel/framework": "5.7.x",
"laravelcollective/html": "5.7.x",
"league/csv": "9.2.x",
"league/geotools": "0.8.x",
"league/iso3166": "2.1.x",
"markrogoyski/math-php": "^0.38.0",
"myclabs/deep-copy": "1.8.x",
"nabeel/vacentral": "1.x",
"nwidart/laravel-modules": "3.3.x",
"php-units-of-measure/php-units-of-measure": "2.1.x",
"pragmarx/version": "0.2.x",
"prettus/l5-repository": "2.6.x",
"santigarcor/laratrust": "5.0.x",
"sebastiaanluca/laravel-helpers": "1.0.x",
"spatie/laravel-pjax": "1.3.x",
"symfony/polyfill-iconv": "^1.11",
"theiconic/php-ga-measurement-protocol": "2.7.x",
"tivie/php-os-detector": "1.1.x",
"toin0u/geotools-laravel": "1.0.x",
"vierbergenlars/php-semver": "3.0.x",
"php-units-of-measure/php-units-of-measure": "2.1.x",
"markrogoyski/math-php": "^0.38.0",
"akaunting/money": "1.0.x",
"anhskohbo/no-captcha": "3.0.x",
"league/csv": "9.2.x",
"intervention/image": "2.4.x",
"waavi/sanitizer": "1.0.x"
"waavi/sanitizer": "1.0.x",
"webpatser/laravel-uuid": "3.x"
},
"require-dev": {
"phpunit/phpunit": "7.5.x",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

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

Loading

0 comments on commit b8d4f4e

Please sign in to comment.