Skip to content

Commit 4f75272

Browse files
committed
Add project list to main navbar
1 parent b5d6856 commit 4f75272

File tree

5 files changed

+62
-18
lines changed

5 files changed

+62
-18
lines changed

resources/templates/page/full.html.twig

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,33 @@
2525
</div>
2626
<div id="navbar_menu" class="navbar-menu">
2727
<div class="navbar-start">
28-
{% for item in main_nav %}
29-
{% set selected = is_current_path(item.route) %}
30-
<a class="navbar-item{% if item.class %} {{ item.class }}{% endif %}{% if selected %} is-active{% endif %}" href="{{ path_for(item.route) }}"{% if selected %} aria-current="page"{% endif %}>{{ item.name }}</a>
31-
{% endfor %}
28+
<div class="navbar-item has-dropdown is-hoverable">
29+
<a class="navbar-link">Projects</a>
30+
31+
<div class="navbar-dropdown">
32+
<div class="navbar-item"><strong>Favourites</strong></div>
33+
{% set faves = current_favourites() %}
34+
{% if 0 < faves|length %}
35+
{% for fave in faves %}
36+
<a class="navbar-item" href="{{ path_for('project.view', { key: fave.key }) }}">
37+
{{ fave.name }}
38+
</a>
39+
{% endfor %}
40+
{% else %}
41+
<div class="navbar-item"><p>Click the star icon on the project list or<br /> project view to set your favourites</p></div>
42+
{% endif %}
43+
<hr class="navbar-divider">
44+
<a class="navbar-item" href="{{ path_for('project.index') }}">
45+
All Projects
46+
</a>
47+
</div>
48+
</div>
49+
50+
<a class="navbar-item" href="{{ path_for('project.add') }}" >Add Project</a>
3251
</div>
3352

3453
<div class="navbar-end">
35-
<div class="navbar-item has-dropdown">
54+
<div class="navbar-item has-dropdown is-hoverable">
3655
<a class="navbar-link">
3756
{{ security.name }}
3857
</a>

src/Controller/ProjectController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ public function deploy(
233233
Router::pathFor('project.index')
234234
);
235235
}
236+
if (!$project->isDeployable()) {
237+
throw new RuntimeException('Project is not deployable at the moment');
238+
}
236239
$input = $request->getParsedBodyParam('project', []);
237240
$type = 'branch';
238241
$branch = (!isset($input['branch']) || empty($input['branch'])) ? $project->branch : $input['branch'];

src/Model/Finder/ProjectFinder.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ class ProjectFinder extends Finder
1919
* @return array
2020
* @author Ronan Chilvers <ronan@d3r.com>
2121
*/
22-
public function all()
22+
public function all(array $ids = null)
2323
{
24-
return $this->select()
24+
$select = $this->select()
2525
->orderBy(Project::prefix('last_deployment'), 'desc')
2626
->orderBy(Project::prefix('repository'), 'asc')
27-
->execute();
27+
;
28+
if (is_array($ids)) {
29+
$select->where(Project::primaryKey(), 'IN', $ids);
30+
}
31+
return $select->execute();
2832
}
2933

3034
/**

src/Provider.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,6 @@ public function register(Container $container)
8888
'session' => $c->get('session'),
8989
'request' => $c->get('request'),
9090
'security' => $c->get(Manager::class),
91-
'main_nav' => [
92-
[
93-
'name' => 'Project List',
94-
'route' => 'project.index',
95-
],
96-
[
97-
'name' => 'Add Project',
98-
'route' => 'project.add',
99-
],
100-
],
10191
'php' => [
10292
'version' => phpversion(),
10393
],

src/Twig/ProjectExtension.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
namespace App\Twig;
44

5+
use App\Facades\Security;
56
use App\Model\Project;
67
use App\Provider\Factory;
78
use App\Security\Manager;
89
use Carbon\Carbon;
910
use Ronanchilvers\Foundation\Traits\Optionable;
11+
use Ronanchilvers\Orm\Orm;
1012
use Ronanchilvers\Utility\Str;
1113
use Twig\Extension\AbstractExtension;
1214
use Twig\Markup;
@@ -69,6 +71,10 @@ public function getFunctions()
6971
'sha_link',
7072
[$this, 'shaLink']
7173
),
74+
new TwigFunction(
75+
'current_favourites',
76+
[$this, 'getCurrentFavourites']
77+
),
7278
];
7379
}
7480

@@ -199,4 +205,26 @@ public function humanDate(Carbon $carbon = null)
199205

200206
return $carbon->diffForHumans(['parts' => 2]);
201207
}
208+
209+
/**
210+
* Get the favourite projects for the current user
211+
*
212+
* @return []
213+
* @author Ronan Chilvers <ronan@d3r.com>
214+
*/
215+
public function getCurrentFavourites()
216+
{
217+
$user = Security::user();
218+
$userFavourites = $user->preference(
219+
'favourites',
220+
[]
221+
);
222+
if (empty($userFavourites)) {
223+
return [];
224+
}
225+
226+
return Orm::finder(Project::class)->all(
227+
$userFavourites
228+
);
229+
}
202230
}

0 commit comments

Comments
 (0)