Skip to content

Commit e15f1a2

Browse files
committed
New menu
1 parent 3f5eeef commit e15f1a2

File tree

7 files changed

+385
-44
lines changed

7 files changed

+385
-44
lines changed

coreui/src/containers/TheSidebar.vue

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
:minimize="minimize"
55
:show="show"
66
>
7-
<CSidebarBrand
8-
fullSrc="img/brand/coreui-base-white.svg"
9-
minimizedSrc="img/brand/coreui-signet-white.svg"
7+
<CSidebarBrand
8+
:imgFull="{ width: 118, height: 46, alt: 'Logo', src: 'img/brand/coreui-base-white.svg'}"
9+
:imgMinimized="{ width: 118, height: 46, alt: 'Logo', src: 'img/brand/coreui-signet-white.svg'}"
1010
:wrappedInLink="{ href: 'https://coreui.io/', target: '_blank'}"
1111
/>
1212
<!-- <CSidebarHeader/> -->
@@ -21,18 +21,104 @@
2121
</template>
2222

2323
<script>
24-
import nav from './_nav'
24+
import axios from 'axios'
2525
export default {
2626
name: 'TheSidebar',
2727
data () {
2828
return {
2929
minimize: false,
30-
nav,
30+
nav: [],
3131
show: true
3232
}
3333
},
34+
methods: {
35+
rebuildData(data){
36+
let result = ['CSidebarNav',[]]
37+
for(let k=0; k<data.length; k++){
38+
switch(data[k]['slug']){
39+
case 'link':
40+
if(data[k]['href'].indexOf('http') !== -1){
41+
result[1].push(
42+
[
43+
'CSidebarNavLink',
44+
{
45+
props: {
46+
name: data[k]['name'],
47+
href: data[k]['href'],
48+
icon: data[k]['icon'],
49+
target: '_blank'
50+
}
51+
}
52+
]
53+
);
54+
}else{
55+
result[1].push(
56+
[
57+
'CSidebarNavLink',
58+
{
59+
props: {
60+
name: data[k]['name'],
61+
to: data[k]['href'],
62+
icon: data[k]['icon'],
63+
}
64+
}
65+
]
66+
);
67+
}
68+
break;
69+
case 'title':
70+
result[1].push(
71+
[
72+
'CSidebarNavTitle',
73+
[data[k]['name']]
74+
]
75+
);
76+
break;
77+
case 'dropdown':
78+
result[1].push(
79+
[
80+
'CSidebarNavDropdown',
81+
{
82+
props: {
83+
name: data[k]['name'],
84+
route: data[k]['href'],
85+
icon: data[k]['icon']
86+
}
87+
},
88+
[]
89+
]
90+
);
91+
for(let i=0; i<data[k]['elements'].length; i++){
92+
result[1][k][2].push(
93+
[
94+
'CSidebarNavLink',
95+
{
96+
props: {
97+
name: data[k]['elements'][i]['name'],
98+
to: data[k]['elements'][i]['href'],
99+
icon: data[k]['elements'][i]['icon']
100+
}
101+
}
102+
]
103+
);
104+
}
105+
break;
106+
}
107+
}
108+
return result;
109+
}
110+
},
34111
mounted () {
35112
this.$root.$on('toggle-sidebar', () => this.show = !this.show)
113+
let self = this;
114+
axios.get('/api/menu?token=' + localStorage.getItem("api_token") )
115+
.then(function (response) {
116+
self.nav = self.rebuildData(response.data);
117+
}).catch(function (error) {
118+
console.log(error);
119+
self.$router.push({ path: '/login' });
120+
});
121+
36122
}
37123
}
38124
</script>

coreui/src/router/index.js

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,14 @@ function configRoutes () {
8787
component: Dashboard
8888
},
8989
{
90-
path: 'theme',
91-
redirect: '/theme/colors',
92-
name: 'Theme',
93-
component: {
94-
render (c) { return c('router-view') }
95-
},
96-
children: [
97-
{
98-
path: 'colors',
99-
name: 'Colors',
100-
component: Colors
101-
},
102-
{
103-
path: 'typography',
104-
name: 'Typography',
105-
component: Typography
106-
}
107-
]
90+
path: 'colors',
91+
name: 'Colors',
92+
component: Colors
93+
},
94+
{
95+
path: 'typography',
96+
name: 'Typography',
97+
component: Typography
10898
},
10999
{
110100
path: 'charts',
@@ -206,28 +196,28 @@ function configRoutes () {
206196
component: Tabs
207197
},
208198
{
209-
path: 'breadcrumbs',
210-
name: 'Breadcrumbs',
199+
path: 'breadcrumb',
200+
name: 'Breadcrumb',
211201
component: Breadcrumbs
212202
},
213203
{
214-
path: 'carousels',
215-
name: 'Carousels',
204+
path: 'carousel',
205+
name: 'Carousel',
216206
component: Carousels
217207
},
218208
{
219-
path: 'collapses',
220-
name: 'Collapses',
209+
path: 'collapse',
210+
name: 'Collapse',
221211
component: Collapses
222212
},
223213
{
224-
path: 'jumbotrons',
225-
name: 'Jumbotrons',
214+
path: 'jumbotron',
215+
name: 'Jumbotron',
226216
component: Jumbotrons
227217
},
228218
{
229-
path: 'list-groups',
230-
name: 'List Groups',
219+
path: 'list-group',
220+
name: 'List Group',
231221
component: ListGroups
232222
},
233223
{
@@ -241,8 +231,8 @@ function configRoutes () {
241231
component: Navbars
242232
},
243233
{
244-
path: 'paginations',
245-
name: 'Paginations',
234+
path: 'pagination',
235+
name: 'Pagination',
246236
component: Paginations
247237
},
248238
{
@@ -251,8 +241,8 @@ function configRoutes () {
251241
component: Popovers
252242
},
253243
{
254-
path: 'progress-bars',
255-
name: 'Progress Bars',
244+
path: 'progress',
245+
name: 'Progress',
256246
component: ProgressBars
257247
},
258248
{
@@ -271,13 +261,13 @@ function configRoutes () {
271261
},
272262
children: [
273263
{
274-
path: 'standard-buttons',
275-
name: 'Standard Buttons',
264+
path: 'buttons',
265+
name: 'Buttons',
276266
component: StandardButtons
277267
},
278268
{
279-
path: 'button-groups',
280-
name: 'Button Groups',
269+
path: 'button-group',
270+
name: 'Button Group',
281271
component: ButtonGroups
282272
},
283273
{
@@ -293,7 +283,7 @@ function configRoutes () {
293283
]
294284
},
295285
{
296-
path: 'icons',
286+
path: 'icon',
297287
redirect: '/icons/coreui-icons',
298288
name: 'CoreUI Icons',
299289
component: {
@@ -331,8 +321,8 @@ function configRoutes () {
331321
component: Alerts
332322
},
333323
{
334-
path: 'badges',
335-
name: 'Badges',
324+
path: 'badge',
325+
name: 'Badge',
336326
component: Badges
337327
},
338328
{
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use App\Http\Menus\Menus;
7+
8+
class MenuController extends Controller
9+
{
10+
/**
11+
* Display a listing of the resource.
12+
*
13+
* @return \Illuminate\Http\Response
14+
*/
15+
public function index()
16+
{
17+
try {
18+
$user = auth()->user();
19+
if($user && !empty($user)){
20+
$roles = $user->roles;
21+
}else{
22+
$roles = '';
23+
}
24+
} catch (Exception $e) {
25+
$roles = '';
26+
}
27+
$menus = new Menus();
28+
return response()->json( $menus->get( $roles ) );
29+
}
30+
31+
}
32+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/*
3+
* 07.11.2019
4+
* GuestMenu.php
5+
*/
6+
namespace App\Http\Menus;
7+
8+
use App\MenuBuilder;
9+
10+
interface MenuInterface
11+
{
12+
public function get(string $roles);
13+
}

laravel/app/Http/Menus/Menus.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/*
3+
* 07.11.2019
4+
* MenusMenu.php
5+
*/
6+
namespace App\Http\Menus;
7+
8+
use App\MenuBuilder\MenuBuilder;
9+
10+
class Menus implements MenuInterface{
11+
12+
private $mb; //menu builder
13+
14+
public function __construct(){
15+
$this->mb = new MenuBuilder();
16+
}
17+
18+
private function getGuestMenu(){
19+
$this->mb->addLink('Dashboard', '/', 'cui-speedometer');
20+
$this->mb->addLink('Login', '/login', 'cui-account-logout');
21+
$this->mb->addLink('Register', '/register', 'cui-account-logout');
22+
$this->mb->addLink('Download CoreUI', 'https://coreui.io', 'cui-cloud-download');
23+
$this->mb->addLink('Try CoreUI PRO', 'https://coreui.io/pro/', 'cui-layers');
24+
}
25+
26+
private function getAdminMenu(){
27+
$this->mb->addLink('Dashboard', '/', 'cui-speedometer');
28+
$this->mb->addTitle('Theme');
29+
$this->mb->addLink('Colors', '/colors', 'cui-drop1');
30+
$this->mb->addLink('Typography', '/typography', 'cui-pencil');
31+
$this->mb->addTitle('Components');
32+
$this->mb->beginDropdown('Base', '/base', 'cui-puzzle');
33+
$this->mb->addLink('Breadcrumb', '/base/breadcrumb');
34+
$this->mb->addLink('Cards', '/base/cards');
35+
$this->mb->addLink('Carousel', '/base/carousel');
36+
$this->mb->addLink('Collapse', '/base/collapse');
37+
$this->mb->addLink('Forms', '/base/forms');
38+
$this->mb->addLink('Jumbotron', '/base/jumbotron');
39+
$this->mb->addLink('List group', '/base/list-group');
40+
$this->mb->addLink('Navs', '/base/navs');
41+
$this->mb->addLink('Pagination', '/base/pagination');
42+
$this->mb->addLink('Popovers', '/base/popovers');
43+
$this->mb->addLink('Progress', '/base/progress');
44+
// $this->mb->addLink('Scrollspy', '/base/scrollspy');
45+
$this->mb->addLink('Switches', '/base/switches');
46+
$this->mb->addLink('Tables', '/base/tables');
47+
$this->mb->addLink('Tabs', '/base/tabs');
48+
$this->mb->addLink('Tooltips', '/base/tooltips');
49+
$this->mb->endDropdown();
50+
$this->mb->beginDropdown('Buttons', '/buttons', 'cui-cursor');
51+
$this->mb->addLink('Buttons', '/buttons/buttons');
52+
$this->mb->addLink('Buttons Group', '/buttons/button-group');
53+
$this->mb->addLink('Dropdowns', '/buttons/dropdowns');
54+
$this->mb->addLink('Brand Buttons', '/buttons/brand-buttons');
55+
$this->mb->endDropdown();
56+
$this->mb->addLink('Charts', '/charts', 'cui-chart-pie');
57+
$this->mb->beginDropdown('Icons', '/icon', 'cui-star');
58+
$this->mb->addLink('CoreUI Icons', '/icon/coreui-icons');
59+
$this->mb->addLink('Flags', '/icon/flags');
60+
$this->mb->addLink('Brands', '/icon/brands');
61+
$this->mb->endDropdown();
62+
$this->mb->beginDropdown('Notifications', '/notifications', 'cui-bell');
63+
$this->mb->addLink('Alerts', '/notifications/alerts');
64+
$this->mb->addLink('Badge', '/notifications/badge');
65+
$this->mb->addLink('Modals', '/notifications/modals');
66+
$this->mb->endDropdown();
67+
$this->mb->addLink('Widgets', '/widgets', 'cui-calculator');
68+
$this->mb->addTitle('Extras');
69+
$this->mb->beginDropdown('Pages', '/pages', 'cui-star');
70+
$this->mb->addLink('Login', '/login');
71+
$this->mb->addLink('Register', '/register');
72+
$this->mb->addLink('Error 404', '/404');
73+
$this->mb->addLink('Error 500', '/500');
74+
$this->mb->endDropdown();
75+
$this->mb->addLink('Download CoreUI', 'https://coreui.io', 'cui-cloud-download');
76+
$this->mb->addLink('Try CoreUI PRO', 'https://coreui.io/pro/', 'cui-layers');
77+
}
78+
79+
public function get($roles){
80+
$roles = explode(',', $roles);
81+
if(empty($roles)){
82+
$this->getGuestMenu();
83+
}elseif(in_array('user', $roles)){
84+
$this->getAdminMenu();
85+
}else{
86+
$this->getGuestMenu();
87+
}
88+
return $this->mb->getResult();
89+
}
90+
91+
}

0 commit comments

Comments
 (0)