Skip to content

Commit 9621e9a

Browse files
committed
Added categories full tree support
1 parent 936c096 commit 9621e9a

File tree

6 files changed

+73
-22
lines changed

6 files changed

+73
-22
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"cookie-parser": "^1.4.3",
5858
"css-loader": "^0.28.0",
5959
"express": "^4.15.1",
60-
"express-jwt": "^5.1.0",
60+
"express-jwt": "^5.3.0",
6161
"extract-text-webpack-plugin": "^2.1.0",
6262
"formidable": "^1.1.1",
6363
"fs-extra": "^2.1.2",
@@ -69,7 +69,7 @@
6969
"lru-cache": "^4.0.2",
7070
"material-ui": "^0.17.4",
7171
"moment": "^2.18.1",
72-
"mongodb": "^2.2.25",
72+
"mongodb": "^2.2.26",
7373
"nodemailer": "^4.0.1",
7474
"nodemailer-smtp-transport": "^2.7.4",
7575
"react": "^15.5.4",

themes/current/assets/css/theme.css

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,29 +183,23 @@ hr.separator {
183183
.categories-tree ul ul {
184184
display: none;
185185
}
186-
.categories-tree a.active + ul {
187-
display: block;
188-
}
189186
.categories-tree li {
190187
margin: 0;
191-
padding: 0;
188+
padding: 0 0 0 .75em;
192189
list-style: none;
190+
position: relative;
193191
}
194192
.categories-tree li a {
195193
color: #7a7a7a;
196194
margin: 0;
197-
padding: 0 0 0 .75em;
198-
line-height: 1.9;
195+
padding: 0;
196+
line-height: 2.2;
199197
display: block;
198+
position: relative;
199+
text-indent: 20px;
200200
}
201-
.categories-tree li li a {
202-
padding: 0 0 0 1.5em;
203-
}
204-
.categories-tree li li li a {
205-
padding: 0 0 0 2.25em;
206-
}
207-
.categories-tree li li li li a {
208-
padding: 0 0 0 3em;
201+
.categories-tree li a:hover {
202+
color: #000;
209203
}
210204
.categories-tree li a.active {
211205
color: #000;
@@ -215,6 +209,23 @@ hr.separator {
215209
display: block;
216210
}
217211

212+
.categories-tree li.has-child > a:after {
213+
content: "";
214+
display: block;
215+
position: absolute;
216+
top: calc(50% - 10px);
217+
left: 0;
218+
width: 16px;
219+
height: 19px;
220+
background-position: -7px -2px;
221+
background-image: url(/assets/images/arrow_right.svg);
222+
}
223+
224+
.categories-tree li.active.has-child > a:after {
225+
background-position: -4px -2px;
226+
background-image: url(/assets/images/arrow_down.svg);
227+
}
228+
218229
.sidebar {
219230
z-index: 1000;
220231
background: #fff;
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading

themes/current/src/components/categoryTree.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,25 @@ import config from '../lib/config'
55
import * as helper from '../lib/helper'
66

77
const TreeItem = ({ categories, categoryDetails, activeCategory, onClick }) => {
8-
const childs = categories.filter(category => category.parent_id === categoryDetails.id).map((category, index) => <TreeItem key={index} categories={categories} categoryDetails={category} activeCategory={activeCategory} />)
9-
const currentCategoryIsActive = activeCategory && activeCategory.id === categoryDetails.id;
10-
const parentCategoryIsActive = activeCategory && activeCategory.parent_id === categoryDetails.id;
8+
const childs = categories
9+
.filter(category => category.parent_id === categoryDetails.id)
10+
.map((category, index) =>
11+
<TreeItem key={index} categories={categories} categoryDetails={category} activeCategory={activeCategory} />
12+
);
13+
14+
const parentIds = helper.getParentIds(categories, activeCategory.id);
15+
const isActive = parentIds.includes(categoryDetails.id) || activeCategory.id === categoryDetails.id;
16+
const hasChild = childs && childs.length > 0;
17+
18+
let classNames = isActive ? 'active' : '';
19+
if(hasChild){
20+
classNames += classNames === '' ? 'has-child' : ' has-child';
21+
}
1122

1223
return (
13-
<li className={currentCategoryIsActive || parentCategoryIsActive ? 'active' : ''}>
24+
<li className={classNames}>
1425
<Link to={categoryDetails.path} activeClassName="active" onClick={onClick}>{categoryDetails.name}</Link>
15-
{childs && childs.length > 0 &&
26+
{hasChild &&
1627
<ul>
1728
{childs}
1829
</ul>
@@ -23,7 +34,12 @@ const TreeItem = ({ categories, categoryDetails, activeCategory, onClick }) => {
2334

2435
const CategoryTree = ({ categories, activeCategory, onClick }) => {
2536
if(categories) {
26-
const elements = categories.filter(category => category.parent_id === null).map((category, index) => <TreeItem key={index} categories={categories} categoryDetails={category} activeCategory={activeCategory} onClick={onClick} />)
37+
const elements = categories
38+
.filter(category => category.parent_id === null)
39+
.map((category, index) =>
40+
<TreeItem key={index} categories={categories} categoryDetails={category} activeCategory={activeCategory} onClick={onClick} />
41+
);
42+
2743
return (
2844
<div className="categories-tree">
2945
<ul>

themes/current/src/lib/helper.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,19 @@ export const getThumbnailUrl = (originalUrl, width) => {
2626
return '';
2727
}
2828
}
29+
30+
export const getParentIds = (categories, categoryId) => {
31+
let parentIds = [];
32+
let parentExists = false;
33+
34+
do {
35+
const category = categories.find(item => item.id === categoryId);
36+
parentExists = category && category.parent_id;
37+
if(parentExists){
38+
parentIds.push(category.parent_id)
39+
categoryId = category.parent_id;
40+
}
41+
} while(parentExists)
42+
43+
return parentIds;
44+
}

0 commit comments

Comments
 (0)