Merge pull request #3594 from yariplus/homepages

Add Custom and Category homepages.
v1.18.x
Barış Soner Uşaklı 9 years ago
commit bcb3b55ab0

@ -0,0 +1,23 @@
"use strict";
/*global define*/
define('admin/general/homepage', ['admin/settings'], function(Settings) {
function toggleCustomRoute() {
if ($('[data-field="homePageRoute"]').val()) {
$('#homePageCustom').hide();
}else{
$('#homePageCustom').show();
}
}
var Homepage = {};
Homepage.init = function() {
$('[data-field="homePageRoute"]').on('change', toggleCustomRoute);
toggleCustomRoute();
};
return Homepage;
});

@ -348,21 +348,49 @@ adminController.navigation.get = function(req, res, next) {
}; };
adminController.homepage.get = function(req, res, next) { adminController.homepage.get = function(req, res, next) {
plugins.fireHook('filter:homepage.get', {routes: [ async.waterfall([
{ function(next) {
route: 'categories', db.getSortedSetRange('cid:0:children', 0, -1, next);
name: 'Categories' },
function(cids, next) {
privileges.categories.filterCids('find', cids, 0, next);
}, },
{ function(cids, next) {
route: 'recent', categories.getMultipleCategoryFields(cids, ['name', 'slug'], next);
name: 'Recent'
}, },
{ function(categoryData, next) {
route: 'popular', categoryData = categoryData.map(function(category) {
name: 'Popular' return {
route: 'category/' + category.slug,
name: 'Category: ' + category.name
};
});
next(null, categoryData);
} }
]}, function(err, data) { ], function(err, categoryData) {
res.render('admin/general/homepage', data); if (err || !categoryData) categoryData = [];
plugins.fireHook('filter:homepage.get', {routes: [
{
route: 'categories',
name: 'Categories'
},
{
route: 'recent',
name: 'Recent'
},
{
route: 'popular',
name: 'Popular'
}
].concat(categoryData)}, function(err, data) {
data.routes.push({
route: '',
name: 'Custom'
});
res.render('admin/general/homepage', data);
});
}); });
}; };

@ -33,20 +33,20 @@ var Controllers = {
Controllers.home = function(req, res, next) { Controllers.home = function(req, res, next) {
var route = meta.config.homePageRoute || 'categories', var route = meta.config.homePageRoute || meta.config.homePageCustom || 'categories',
hook = 'action:homepage.get:' + route; hook = 'action:homepage.get:' + route;
if (plugins.hasListeners(hook)) { if (plugins.hasListeners(hook)) {
plugins.fireHook(hook, {req: req, res: res, next: next}); plugins.fireHook(hook, {req: req, res: res, next: next});
} else { } else {
if (route === 'categories') { if (route === 'categories' || route === '/') {
Controllers.categories.list(req, res, next); Controllers.categories.list(req, res, next);
} else if (route === 'recent') { } else if (route === 'recent') {
Controllers.recent.get(req, res, next); Controllers.recent.get(req, res, next);
} else if (route === 'popular') { } else if (route === 'popular') {
Controllers.popular.get(req, res, next); Controllers.popular.get(req, res, next);
} else { } else {
next(); res.redirect(route);
} }
} }
}; };

@ -12,6 +12,11 @@
<option value="{routes.route}">{routes.name}</option> <option value="{routes.route}">{routes.name}</option>
<!-- END routes --> <!-- END routes -->
</select> </select>
<br>
<div id="homePageCustom" style="display: none;">
<label>Custom Route</label>
<input type="text" class="form-control" data-field="homePageCustom"/>
</div>
</div> </div>
</form> </form>
</div> </div>

Loading…
Cancel
Save