Skip to content

Commit 4f5aa41

Browse files
committed
[spalenque] - #13322 * add filters to marketplace driver page and refactor to react
1 parent b408ad2 commit 4f5aa41

15 files changed

Lines changed: 670 additions & 115 deletions

File tree

marketplace/_config/injector.yml

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,25 @@ Injector:
2020
1: '%$PoweredOpenStackImplementationManager'
2121
2: 90
2222
SapphireRegionalServiceRepository:
23-
class: SapphireRegionalServiceRepository
23+
class: SapphireRegionalServiceRepository
2424
CompanyServiceResfullApi:
25-
constructor:
26-
0: '%$SapphireRegionalServiceRepository'
25+
constructor:
26+
0: '%$SapphireRegionalServiceRepository'
2727
BookManager:
28-
constructor:
29-
0: '%$SapphireMarketPlaceTypeRepository'
30-
1: '%$BookFactory'
31-
2: '%$MarketplaceFactory'
32-
3: '%$ValidatorFactory'
33-
4: '%$TransactionManager'
28+
constructor:
29+
0: '%$SapphireMarketPlaceTypeRepository'
30+
1: '%$BookFactory'
31+
2: '%$MarketplaceFactory'
32+
3: '%$ValidatorFactory'
33+
4: '%$TransactionManager'
3434
BooksCrudApi:
35-
constructor:
36-
0: '%$BookManager'
37-
1: '%$BookFactory'
38-
2: '%$SapphireMarketPlaceTypeRepository'
35+
constructor:
36+
0: '%$BookManager'
37+
1: '%$BookFactory'
38+
2: '%$SapphireMarketPlaceTypeRepository'
39+
SapphireMarketPlaceDriverRepository:
40+
class: SapphireMarketPlaceDriverRepository
41+
DriverRestfullApi:
42+
constructor:
43+
0: '%$SapphireMarketPlaceDriverRepository'
44+

marketplace/_config/routes.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ Director:
2121
'api/v1/marketplace/reviews': 'ReviewCrudApi'
2222
'api/v1/marketplace/openstack-powered-implementations': 'OpenStackPoweredImplementionResfullApi'
2323
'api/v1/marketplace/company-service': 'CompanyServiceResfullApi'
24-
'api/v1/marketplace/books': 'BooksCrudApi'
24+
'api/v1/marketplace/books': 'BooksCrudApi'
25+
'api/v1/marketplace/drivers': 'DriverRestfullApi'
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2016 OpenStack Foundation
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
**/
15+
final class SapphireMarketPlaceDriverRepository
16+
extends SapphireRepository
17+
implements IMarketPlaceDriverRepository
18+
{
19+
20+
public function __construct()
21+
{
22+
parent::__construct(null);
23+
}
24+
25+
/**
26+
* @param string $order
27+
* @param bool $filters
28+
* @return array
29+
*/
30+
function getAllByFilter ($order = 'Project ASC', $filters = array())
31+
{
32+
$filter_clause = '';
33+
34+
if ($filters['project'] != 'all') {
35+
$filter_clause .= " AND LCASE(D.Project) = '".$filters['project']."'";
36+
}
37+
38+
if ($filters['release'] != 'all') {
39+
$filter_clause .= " AND LCASE(R.Name) = '".$filters['release']."'";
40+
}
41+
42+
if ($filters['vendor'] != 'all') {
43+
$filter_clause .= " AND LCASE(D.Vendor) = '".$filters['vendor']."'";
44+
}
45+
46+
$query = <<<SQL
47+
SELECT D.* FROM Driver D
48+
LEFT JOIN Driver_Releases DR ON DR.DriverID = D.ID
49+
LEFT JOIN DriverRelease R ON R.ID = DR.DriverReleaseID
50+
WHERE D.Active = 1
51+
{$filter_clause}
52+
GROUP BY D.ID
53+
ORDER BY D.{$order}
54+
SQL;
55+
56+
$list = new ArrayList();
57+
foreach(DB::query($query) as $row)
58+
{
59+
$list->push(new ArrayData($row));
60+
}
61+
62+
return $list;
63+
}
64+
65+
66+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* Copyright 2017 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
use Openstack\Annotations as CustomAnnotation;
16+
17+
final class DriverRestfullApi extends AbstractRestfulJsonApi
18+
{
19+
/**
20+
* @var IMarketPlaceDriverRepository
21+
*/
22+
private $repository;
23+
24+
/**
25+
* DriverResfullApi constructor.
26+
* @param IMarketPlaceDriverRepository $repository
27+
*/
28+
public function __construct
29+
(
30+
IMarketPlaceDriverRepository $repository
31+
)
32+
{
33+
parent::__construct();
34+
$this->repository = $repository;
35+
}
36+
37+
const ApiPrefix = 'api/v1/marketplace';
38+
39+
protected function isApiCall(){
40+
$request = $this->getRequest();
41+
if(is_null($request)) return false;
42+
return strpos(strtolower($request->getURL()),self::ApiPrefix) !== false;
43+
}
44+
45+
/**
46+
* @return bool
47+
*/
48+
protected function authorize(){
49+
return true;
50+
}
51+
52+
/**
53+
* @return bool
54+
*/
55+
protected function authenticate(){
56+
return true;
57+
}
58+
59+
static $url_handlers = array(
60+
'GET ' => 'getDrivers',
61+
);
62+
63+
static $allowed_actions = [
64+
'getDrivers',
65+
];
66+
67+
68+
public function getDrivers(SS_HTTPRequest $request){
69+
try
70+
{
71+
$query_string = $request->getVars();
72+
$sort_field = (isset($query_string['sort_field']) ? Convert::raw2sql($query_string['sort_field']) : 'Project');
73+
$sort_dir = (isset($query_string['sort_dir']) ? Convert::raw2sql($query_string['sort_dir']) : 'ASC');
74+
$order = $sort_field.' '.$sort_dir;
75+
$filters['project'] = (boolval(isset($query_string['project'])) ? Convert::raw2sql($query_string['project']) : 'all');
76+
$filters['release'] = (boolval(isset($query_string['release'])) ? Convert::raw2sql($query_string['release']) : 'all');
77+
$filters['vendor'] = (boolval(isset($query_string['vendor'])) ? Convert::raw2sql($query_string['vendor']) : 'all');
78+
79+
$list = $this->repository->getAllByFilter($order, $filters);
80+
81+
$items = [];
82+
83+
foreach ($list as $item){
84+
$driver = Driver::get()->byID($item->ID);
85+
$releases = [];
86+
if ($driver) {
87+
foreach ($driver->Releases() as $release) {
88+
$releases[] = [
89+
'id' => $release->ID,
90+
'url' => $release->Url,
91+
'name' => $release->Name,
92+
];
93+
}
94+
}
95+
96+
$items[] =
97+
[
98+
'id' => intval($item->ID),
99+
'name' => $item->Name,
100+
'url' => $item->Url,
101+
'description' => trim($item->Description),
102+
'project' => trim($item->Project),
103+
'vendor' => trim($item->Vendor),
104+
'driver' => trim($item->Driver),
105+
'releases' => $releases
106+
];
107+
}
108+
109+
return $this->ok($items);
110+
}
111+
catch(NotFoundEntityException $ex2)
112+
{
113+
SS_Log::log($ex2->getMessage(), SS_Log::WARN);
114+
return $this->notFound($ex2->getMessage());
115+
}
116+
catch(Exception $ex)
117+
{
118+
SS_Log::log($ex->getMessage(), SS_Log::ERR);
119+
return $this->serverError();
120+
}
121+
}
122+
123+
124+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2017 OpenStack Foundation
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
**/
15+
interface IMarketPlaceDriverRepository
16+
{
17+
/**
18+
* @param string $order
19+
* @param bool $filters
20+
* @return array
21+
*/
22+
function getAllByFilter
23+
(
24+
$order = '',
25+
$filters = []
26+
);
27+
28+
}

marketplace/code/ui/frontend/MarketPlaceDriverPage.php

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,54 @@ final class MarketPlaceDriverPage_Controller extends MarketPlaceDirectoryPage_Co
2727
function init() {
2828
parent::init();
2929
Requirements::javascript("marketplace/code/ui/frontend/js/driver.page.js");
30+
Requirements::javascript('themes/openstack/javascript/urlfragment.jquery.js');
3031
}
3132

32-
public static function DriverTable($project = null){
33-
if ($project) {
34-
return Driver::get()->filter(array('Project' => $project, 'Active' => 1));
35-
}
36-
33+
private function getActiveDrivers() {
3734
return Driver::get()->filter('Active', 1);
3835
}
3936

4037
public function getProjects() {
41-
return GroupedList::create(Driver::get()->filter('Active', 1)->sort('Project'))->GroupedBy('Project');
38+
$drivers = $this->getActiveDrivers()->sort('Project')->column('Project');
39+
$projects = [];
40+
41+
foreach ($drivers as $project) {
42+
$projects[] = new ArrayData(['Name' => $project]);
43+
}
44+
45+
return new ArrayList($projects);
46+
}
47+
48+
public function getReleases() {
49+
$drivers = $this->getActiveDrivers();
50+
$releases = [];
51+
$release_list = [];
52+
53+
foreach ($drivers as $driver) {
54+
foreach ($driver->Releases()->column('Name') as $release) {
55+
$releases[] = $release;
56+
}
57+
}
58+
59+
$releases = array_unique($releases);
60+
sort($releases);
61+
62+
foreach ($releases as $release) {
63+
$release_list[] = new ArrayData(['Name' => $release]);
64+
}
65+
66+
return new ArrayList($release_list);
67+
}
68+
69+
public function getVendors() {
70+
$drivers = $this->getActiveDrivers()->sort('Vendor')->column('Vendor');
71+
$vendors = [];
72+
73+
foreach ($drivers as $vendor) {
74+
$vendors[] = new ArrayData(['Name' => $vendor]);
75+
}
76+
77+
return new ArrayList($vendors);
4278
}
4379

4480
}

marketplace/code/ui/frontend/js/driver.page.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,5 @@
1313
jQuery(document).ready(function($){
1414
$('#drivers','.marketplace-nav').addClass('current');
1515

16-
$('#project_filter').change(function(){
17-
var project = $(this).val();
18-
$('.driver_table').hide();
19-
$('.project_'+project).show();
20-
21-
});
22-
2316

2417
});

0 commit comments

Comments
 (0)