Skip to content

Commit

Permalink
router works better now
Browse files Browse the repository at this point in the history
  • Loading branch information
dav-m85 committed Dec 21, 2017
1 parent e47d6d2 commit 86cd8ec
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![Logo](./silo.png)
[![Build Status](https://travis-ci.org/frankandoak/silo.svg?branch=master)](https://travis-ci.org/frankandoak/silo)
# Silo
Simple yet powerful Warehouse Managment System. Daily used by Frank + Oak.
Simple yet powerful Warehouse Managment System. Daily used by Frank And Oak.

Proudly built in Montréal with:
- React
Expand Down
8 changes: 4 additions & 4 deletions client/Editor/Cell/OperationDirectionCell.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const React = require('react');
const Link = require('../../Factory').Link;
const Link = require('react-router-dom').Link;
const {Cell} = require('fixed-data-table');

module.exports = ({rowIndex, data, ...props}) => {
const {source, target, location} = data.getObjectAt(rowIndex);
return <Cell {...props}>
{source ? <Link route="location" code={source} /> : <span className="label label-success">CREATE</span>}
{source ? <Link to={"/location/"+source}>{source}</Link> : <span className="label label-success">CREATE</span>}
&nbsp;&rarr;&nbsp;
{target ? <Link route="location" code={target} /> : <span className="label label-danger">DELETE</span>}
&nbsp;({location ? <Link route="location" code={location} /> : 'skus'})
{target ? <Link to={"/location/"+target}>{target}</Link> : <span className="label label-danger">DELETE</span>}
&nbsp;({location ? <Link to={"/location/"+location}>{location}</Link> : 'skus'})
</Cell>
};
34 changes: 18 additions & 16 deletions client/Hud/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ module.exports = React.createClass({
return <LinkContainer to={route}><MenuItem eventKey={key}>{title}</MenuItem></LinkContainer>
},

/*
<Nav>
<NavDropdown eventKey={1} title="Inventory" id="main-nav-dropdown">
{this.menu("/operations", "Operations", 1.1)}
</NavDropdown>
<NavItem eventKey={2} href="#">Work</NavItem>
</Nav>
<Nav pullRight>
<NavDropdown eventKey={3} title="An" id="user-nav-dropdown">
<MenuItem eventKey={3.1}>Administration</MenuItem>
<MenuItem eventKey={3.2}>Help</MenuItem>
<MenuItem eventKey={3.3}>About Silo</MenuItem>
<MenuItem divider />
<MenuItem eventKey={3.4}>Log out</MenuItem>
</NavDropdown>
</Nav>
*/

render: function(){
return (
<Navbar fixedTop fluid>
Expand All @@ -17,22 +35,6 @@ module.exports = React.createClass({
<Link to="/">Silo</Link>
</Navbar.Brand>
</Navbar.Header>
<Nav>
<NavDropdown eventKey={1} title="Inventory" id="main-nav-dropdown">
{this.menu("/operations", "Operations", 1.1)}
</NavDropdown>
<NavItem eventKey={2} href="#">Work</NavItem>
</Nav>
<Nav pullRight>
<NavDropdown eventKey={3} title="An" id="user-nav-dropdown">
<MenuItem eventKey={3.1}>Administration</MenuItem>
<MenuItem eventKey={3.2}>Help</MenuItem>
<MenuItem eventKey={3.3}>About Silo</MenuItem>
<MenuItem divider />
<MenuItem eventKey={3.4}>Log out</MenuItem>
</NavDropdown>
</Nav>

</Navbar>
);
}
Expand Down
14 changes: 10 additions & 4 deletions client/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ import Location from './View/Location'
import Product from './View/Product'
import OperationSet from './View/OperationSet'

const withId = (WrappedComponent) => ({match, ...props}) => (<WrappedComponent id={match.params.id} {...props}/>);

export {withId};

// match.params.id
let key = 0;
const routes = (RouteCp = Route) => [
<RouteCp key={key++} path="/operations" component={Operations} />,
<RouteCp key={key++} path="/operation/:id" component={Operation} />,
<RouteCp key={key++} path="/location/:id" component={Location} />,
<RouteCp key={key++} path="/product/:id" component={Product} />,
<RouteCp key={key++} path="/operation-set/:id" component={OperationSet} />
<RouteCp key={key++} path="/operation/:id" component={withId(Operation)} />,
<RouteCp key={key++} path="/location/:id" component={withId(Location)} />,
<RouteCp key={key++} path="/product/:id" component={withId(Product)} />,
<RouteCp key={key++} path="/operation-set/:id" component={withId(OperationSet)} />
];

export default routes


4 changes: 2 additions & 2 deletions client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const App = React.createClass({
<div className="col-sm-12 main">
<Switch>
<Route exact path="/" component={Home} />
{Routes}
{Routes()}
<Route path="*" render={(props)=>(<div>Not found</div>)} />
</Switch>
</div>
Expand All @@ -44,4 +44,4 @@ const App = React.createClass({
}
});

ReactDOM.render(<App />, document.getElementById('ReactMount'));
ReactDOM.render(<App />, document.getElementById('container'));
3 changes: 3 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
'config.cache' => new \Silo\Base\SinglePhpFileCache($configFile, \Silo\Base\Configuration::CACHE_KEY),
'defaultErrorHandler' => true
]);
$indexProvider = new \Silo\Base\Provider\IndexProvider();
$app->register($indexProvider)->mount('/', $indexProvider);

$app->run();
8 changes: 7 additions & 1 deletion server/Base/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public function has($name, $defaultValue, $validation = null)
$this->validate($defaultValue, $validation);
$this->app[$name] = $defaultValue;
}

return $this;
}

public function set($name, $value)
Expand All @@ -79,11 +81,15 @@ public function set($name, $value)
}
$this->validate($value, $configKey->getValidation());
$this->app[$name] = $value;

return $this;
}

public function save()
{
$this->cache->save($this->key, $this->getAll());

return $this;
}

private function getConfigurationKeyByName($name)
Expand Down Expand Up @@ -111,6 +117,7 @@ public function getAll()
$name = $config->getName();
$result[$name] = $app[$name];
});

return $result;
}

Expand All @@ -125,6 +132,5 @@ public function injectFromCache()
}
}
}

}
}
13 changes: 5 additions & 8 deletions server/Base/Provider/IndexProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@ class IndexProvider implements \Pimple\ServiceProviderInterface, ControllerProvi
{
public function register(Container $app)
{
$app['index.css'] = [
'/master.css',
'/static/default/default/css/chosen.css',
'/static/default/default/css/jquery.switchButton.css'
];
$app['index.css'] = [];

$app['index.js'] = [
'/legacy.js',
'/vendors.js',
'/app.js'
];

$app['title'] = 'silo';

$app['index.response'] = $app->factory(function()use($app){

$metas = "";
Expand All @@ -44,7 +41,7 @@ public function register(Container $app)
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>silo</title>
<title>{$app['title']}</title>
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
Expand All @@ -67,7 +64,7 @@ public function connect(Application $app)
{
$c = $app['controllers_factory'];

$c->get('/', $app['index.response']);
$c->get('/', function()use($app){return $app['index.response'];});

return $c;
}
Expand Down
24 changes: 15 additions & 9 deletions server/Silo.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Validator\Validation;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* Main Silo entry point, exposed as a Container.
*/
Expand All @@ -38,8 +39,14 @@ public function __construct(array $values = [])
parent::__construct($values);

$this->register(new ConfigurationProvider);
$this['config']->has('configured', true); // @todo should be false in a not so distant future
$this['config']
->has('configured', false) // @todo should be false in a not so distant future
->has('route.base', '/silo/inventory')
->has('em.dsn', null);

//$this['config']->save();

$this['debug'] = true;
if ($this['configured']) {
$this->register(new MetricProvider);
$this->register(new DoctrineProvider, [
Expand Down Expand Up @@ -105,12 +112,12 @@ public function __construct(array $values = [])
return $s;
};

$app->mount('/silo/inventory/location', new \Silo\Inventory\LocationController);
$app->mount('/silo/inventory/operation', new \Silo\Inventory\OperationController);
$app->mount('/silo/inventory/product', new \Silo\Inventory\ProductController);
$app->mount('/silo/inventory/batch', new \Silo\Inventory\BatchController);
$app->mount('/silo/inventory/user', new \Silo\Inventory\UserController);
$app->mount('/silo/inventory/export', new \Silo\Inventory\ExportController);
$app->mount($app['route.base'].'/location', new \Silo\Inventory\LocationController);
$app->mount($app['route.base'].'/operation', new \Silo\Inventory\OperationController);
$app->mount($app['route.base'].'/product', new \Silo\Inventory\ProductController);
$app->mount($app['route.base'].'/batch', new \Silo\Inventory\BatchController);
$app->mount($app['route.base'].'/user', new \Silo\Inventory\UserController);
$app->mount($app['route.base'].'/export', new \Silo\Inventory\ExportController);

$app['version'] = function(){
$filename = __DIR__.'/../../VERSION';
Expand All @@ -129,7 +136,6 @@ public function __construct(array $values = [])

// Deal with exceptions
ErrorHandler::register();

if (isset($app['defaultErrorHandler']) && $app['defaultErrorHandler']) {
$app->error(function (\Exception $e, $request) use ($app) {
if ($e instanceof NotFoundHttpException) {
Expand Down

0 comments on commit 86cd8ec

Please sign in to comment.