Skip to content

Commit

Permalink
- Added Manual search with position and/or location
Browse files Browse the repository at this point in the history
  • Loading branch information
hayk-manasyan committed Aug 23, 2017
1 parent 261f078 commit c4d715e
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 62 deletions.
26 changes: 0 additions & 26 deletions module/Application/src/Controller/FormsController.php

This file was deleted.

41 changes: 39 additions & 2 deletions module/Application/src/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@

namespace Application\Controller;

use Application\Form\SearchForm;
use Application\View\Helper\Sidebar;
use Github\Service\SearchService;
use Zend\Form\Element\Search;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\View\View;

class IndexController extends AbstractActionController
{
private $searchService;
private $searchForm;

public function __construct(SearchService $searchService)
public function __construct(SearchService $searchService, SearchForm $searchForm)
{
$this->searchService = $searchService;
$this->searchForm = $searchForm;
}

public function dashboardAction()
Expand Down Expand Up @@ -56,8 +60,41 @@ public function detailAction()

$viewModel = new ViewModel();
$jobDetail = $this->searchService->searchById($jobId);
// var_dump($jobDetail);

$viewModel->job = $jobDetail;
return $viewModel;
}

public function manualSearchAction()
{
$viewModel = new ViewModel();
$viewModel->form = $this->searchForm;

$request = $this->getRequest();
if(!$request->isPost()) {
return $viewModel;
}


$postData = $request->getPost();

$this->searchForm->setData($postData);
if(!$this->searchForm->isValid()) {
return $viewModel;
}

$formData = $this->searchForm->getData();
$position = $formData['position'];
$location = $formData['location'];

try {

$viewModel->result = $this->searchService->searchByCombinedParams($position, $location);
} catch (\Exception $ex) {
$viewModel->error = true;
return $viewModel;
}

return $viewModel;
}
}
5 changes: 4 additions & 1 deletion module/Application/src/Factory/IndexControllerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


use Application\Controller\IndexController;
use Application\Form\SearchForm;
use Github\Service\SearchService;
use Interop\Container\ContainerInterface;
use Interop\Container\Exception\ContainerException;
Expand All @@ -28,6 +29,8 @@ class IndexControllerFactory implements FactoryInterface
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return new IndexController($container->get(SearchService::class));
$searchForm = $container->get('FormElementManager')->get(SearchForm::class);

return new IndexController($container->get(SearchService::class), $searchForm);
}
}
32 changes: 32 additions & 0 deletions module/Application/src/Form/SearchForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Application\Form;


use Zend\Form\Element\Text;
use Zend\Form\Form;

class SearchForm extends Form
{

public function init()
{
$position = new Text('position');
$position->setAttributes([
'class' => 'form-control has-feedback-left',
'maxlength' => 10,
'placeholder' => "PHP, JAVA, ...",
]);

$this->add($position);

$location = new Text('location');
$location->setAttributes([
'class' => 'form-control has-feedback-left',
'maxlength' => 20,
'placeholder' => "London, Berlin, ...",
]);

$this->add($location);
}
}
34 changes: 18 additions & 16 deletions module/Application/view/application/index/dashboard.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,25 @@


<?php
$this->inlineScript()->captureStart();
//echo $this->inlineScript()->captureStart();
echo $this->headScript()
// ->appendFile($this->basePath('vendors/Chart.js/dist/Chart.min.js'))
// ->appendFile($this->basePath('vendors/gauge.js/dista/gauge.min.js'))
// ->appendFile($this->basePath('vendors/bootstrap-progressbar/bootstrap-progressbar.min.js'))
// ->appendFile($this->basePath('vendors/iCheck/icheck.min.js'))
// ->appendFile($this->basePath('vendors/skycons/skycons.js'))
// ->appendFile($this->basePath('vendors/Flot/jquery.flot.js'))
// ->appendFile($this->basePath('vendors/Flot/jquery.flot.pie.js'))
// ->appendFile($this->basePath('vendors/Flot/jquery.flot.time.js'))
// ->appendFile($this->basePath('vendors/Flot/jquery.flot.stack.js'))
// ->appendFile($this->basePath('vendors/Flot/jquery.flot.resize.js'))
// ->appendFile($this->basePath('vendors/flot.orderbars/js/jquery.flot.orderBars.js'))
// ->appendFile($this->basePath('ve ndors/flot-spline/js/jquery.flot.spline.min.js'))
// ->appendFile($this->basePath('vendors/flot.curvedlines/curvedLines.js'))
// ->appendFile($this->basePath('vendors/DateJS/build/date.js'))
//// ->appendFile($this->basePath('vendors/Chart.js/dist/Chart.min.js'))
//// ->appendFile($this->basePath('vendors/gauge.js/dista/gauge.min.js'))
//// ->appendFile($this->basePath('vendors/bootstrap-progressbar/bootstrap-progressbar.min.js'))
//// ->appendFile($this->basePath('vendors/iCheck/icheck.min.js'))
//// ->appendFile($this->basePath('vendors/skycons/skycons.js'))
//// ->appendFile($this->basePath('vendors/Flot/jquery.flot.js'))
//// ->appendFile($this->basePath('vendors/Flot/jquery.flot.pie.js'))
//// ->appendFile($this->basePath('vendors/Flot/jquery.flot.time.js'))
//// ->appendFile($this->basePath('vendors/Flot/jquery.flot.stack.js'))
//// ->appendFile($this->basePath('vendors/Flot/jquery.flot.resize.js'))
//// ->appendFile($this->basePath('vendors/flot.orderbars/js/jquery.flot.orderBars.js'))
//// ->appendFile($this->basePath('ve ndors/flot-spline/js/jquery.flot.spline.min.js'))
//// ->appendFile($this->basePath('vendors/flot.curvedlines/curvedLines.js'))
//// ->appendFile($this->basePath('vendors/DateJS/build/date.js'))
->appendFile($this->basePath('build/js/custom.min.js'));


$this->inlineScript()->captureEnd();
//echo $this->headScript()->offsetSetScript(10, $this->basePath('build/js/custom.min.js'), 'text/javascript');

//echo $this->inlineScript()->captureEnd();
99 changes: 99 additions & 0 deletions module/Application/view/application/index/manual-search.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<!-- bootstrap-wysiwyg -->
<link href="<?php echo $this->basePath() . '/vendors/google-code-prettify/bin/prettify.min.css' ?>" rel="stylesheet">
<!-- Select2 -->
<link href="<?php echo $this->basePath() . '/vendors/select2/dist/css/select2.min.css'; ?>" rel="stylesheet">
<!-- Switchery -->
<link href="<?php echo $this->basePath() . '/vendors/switchery/dist/switchery.min.css'; ?>" rel="stylesheet">
<!-- starrr -->
<link href="<?php echo $this->basePath() . '/vendors/starrr/dist/starrr.css'; ?>" rel="stylesheet">
<!-- bootstrap-daterangepicker -->
<link href="<?php echo $this->basePath() . '/vendors/bootstrap-daterangepicker/daterangepicker.css'; ?>"
rel="stylesheet">

<?php
$form = $this->form;
$form->setAttribute('action', $this->url() . '/manual-search');
$form->setAttribute('method', 'POST');
$form->setAttribute('class', 'form-horizontal form-label-left input_mask col-md-offset-1');
$form->prepare();
?>

<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_content">

<div class="row">
<?php
echo $this->form()->openTag($form);
?>
<div class="col-md-4 col-sm-4 col-xs-12 form-group ">
<?php echo $this->formElement($form->get('position')); ?>
<span class="fa fa-tasks form-control-feedback left" aria-hidden="true"></span>
</div>
<div class="col-md-4 col-sm-4 col-xs-12 form-group ">
<?php echo $this->formElement($form->get('location')); ?>
<span class="fa fa-location-arrow form-control-feedback left" aria-hidden="true"></span>
</div>

<div class="col-md-4 col-sm-4 col-xs-12 form-group ">
<button type="submit" class="btn btn-success">Submit</button>
</div>
<?php
echo $this->form()->closeTag();
?>
</div>
</div>
<?php if ($this->result) : ?>
<table id="datatable" class="table table-hover">
<thead>
<tr>
<th>Company</th>
<th>Title</th>
<th>Location</th>
<th>Type</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($this->result as $k => $res) :

?>
<tr>
<th scope="row"><?php echo $res['company']; ?></th>
<td><?php echo $res['title']; ?></td>
<td><?php echo $res['location']; ?></td>
<td><?php echo $res['type']; ?></td>
<td>
<a class="btn btn-info"
href="<?php echo $this->basePath() . '/application/detail/' . $res['id']; ?>">
More </a>
</td>
</tr>

<?php endforeach;;
?>
</tbody>
</table>
<?php endif; ?>
</div>
</div>
</div>

<?php
echo $this->headScript()
->appendFile($this->basePath('vendors/datatables.net/js/jquery.dataTables.min.js'))
->appendFile($this->basePath('vendors/datatables.net-bs/js/dataTables.bootstrap.min.js'))
->appendFile($this->basePath('vendors/datatables.net-buttons/js/dataTables.buttons.min.js'))
->appendFile($this->basePath('vendors/datatables.net-buttons-bs/js/buttons.bootstrap.min.js'))
->appendFile($this->basePath('vendors/datatables.net-buttons/js/buttons.flash.min.js'))
->appendFile($this->basePath('vendors/datatables.net-buttons/js/buttons.html5.min.js'))
->appendFile($this->basePath('vendors/datatables.net-buttons/js/buttons.print.min.js'))
->appendFile($this->basePath('vendors/datatables.net-buttons/js/buttons.print.min.js'))
->appendFile($this->basePath('vendors/datatables.net-fixedheader/js/dataTables.fixedHeader.min.js'))
->appendFile($this->basePath('vendors/datatables.net-keytable/js/dataTables.keyTable.min.js'))
->appendFile($this->basePath('vendors/datatables.net-responsive/js/dataTables.responsive.min.js'))
->appendFile($this->basePath('vendors/datatables.net-responsive-bs/js/responsive.bootstrap.js'))
->appendFile($this->basePath('vendors/datatables.net-scroller/js/dataTables.scroller.min.js'))
->appendFile($this->basePath('build/js/custom.min.js'));
?>
23 changes: 9 additions & 14 deletions module/Application/view/layout/layout.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
->prependStylesheet($this->basePath('vendors/bootstrap/dist/css/bootstrap.min.css'))
?>

<!-- Scripts -->
<?php echo $this->headScript()
->prependFile($this->basePath('vendors/nprogress/nprogress.js'))
->prependFile($this->basePath('vendors/fastclick/lib/fastclick.js'))
->prependFile($this->basePath('vendors/bootstrap/dist/js/bootstrap.min.js'))
->prependFile($this->basePath('vendors/jquery/dist/jquery.min.js'))

?>

</head>
<body class="nav-md">

Expand All @@ -44,20 +53,6 @@
<!-- /footer content -->
</div>
</div>


<!-- Scripts -->
<?php echo $this->headScript()
->prependFile($this->basePath('vendors/nprogress/nprogress.js'))
->prependFile($this->basePath('vendors/fastclick/lib/fastclick.js'))
->prependFile($this->basePath('vendors/bootstrap/dist/js/bootstrap.min.js'))
->prependFile($this->basePath('vendors/jquery/dist/jquery.min.js'))

?>




<?php echo $this->inlineScript() ?>
</body>
</html>
3 changes: 3 additions & 0 deletions module/Application/view/partials/left-sidebar.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<li>
<a href="/">Home</a>
</li>
<li>
<a href="<?php echo $this->basePath() . '/application/manual-search' ?>">Manual Search</a>
</li>

</ul>
</div>
Expand Down
15 changes: 14 additions & 1 deletion module/Github/src/Service/SearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,20 @@ public function searchByCombinedParams(
$fullTime = false
)
{
// TODO: Implement searchByCombinedParams() method.
$url = self::GITHUB_JOBS_URL . 'positions.json';

$params = [
'description' => $description,
'location' => $location,
];

$response = HostService::makeApiCall($url, $params);

try {
return Json::decode($response, true);
} catch (\Exception $ex) {
return null;
}
}

/**
Expand Down
11 changes: 9 additions & 2 deletions module/Utils/src/Service/HostService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,21 @@ public static function makeApiCall($url, $params = null, $isPost = false, $cont


if(false == $isPost) {
if(is_array($params)) {

$requestStr = '?';
foreach ($params as $key => $param) {
if(empty($params)) {
continue;
}

$requestStr .= $key . '=' . $param . '&';
}

$url .= $requestStr;

}

} else {
$request->setMethod(Request::METHOD_POST);
}
Expand All @@ -47,8 +56,6 @@ public static function makeApiCall($url, $params = null, $isPost = false, $cont

} elseif($contentType == 'application/json') {
$request->setContent(json_encode($params));
} else {
$request->setContent($params);
}

$response = $client->dispatch($request);
Expand Down

0 comments on commit c4d715e

Please sign in to comment.