mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	Add Custom and Category homepages.
This commit is contained in:
		
							
								
								
									
										23
									
								
								public/src/admin/general/homepage.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								public/src/admin/general/homepage.js
									
									
									
									
									
										Normal file
									
								
							| @@ -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,6 +348,34 @@ adminController.navigation.get = function(req, res, next) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| adminController.homepage.get = function(req, res, next) { | adminController.homepage.get = function(req, res, next) { | ||||||
|  | 	async.parallel({ | ||||||
|  | 		categoryData: function(next) { | ||||||
|  | 			async.waterfall([ | ||||||
|  | 				function(next) { | ||||||
|  | 					db.getSortedSetRange('cid:0:children', 0, -1, next); | ||||||
|  | 				}, | ||||||
|  | 				function(cids, next) { | ||||||
|  | 					privileges.categories.filterCids('find', cids, 0, next); | ||||||
|  | 				}, | ||||||
|  | 				function(cids, next) { | ||||||
|  | 					categories.getMultipleCategoryFields(cids, ['name', 'slug'], next); | ||||||
|  | 				}, | ||||||
|  | 				function(categoryData, next) { | ||||||
|  | 					async.map(categoryData, function(category, next) { | ||||||
|  | 						var route = 'category/' + category.slug, | ||||||
|  | 							hook = 'action:homepage.get:' + route; | ||||||
|  |  | ||||||
|  | 						next(null, { | ||||||
|  | 							route: route, | ||||||
|  | 							name: 'Category: ' + category.name | ||||||
|  | 						}); | ||||||
|  | 					}, next); | ||||||
|  | 				} | ||||||
|  | 			], next); | ||||||
|  | 		} | ||||||
|  | 	}, function(err, results) { | ||||||
|  | 		if (err || !results || !results.categoryData) results = {categoryData:[]}; | ||||||
|  |  | ||||||
| 		plugins.fireHook('filter:homepage.get', {routes: [ | 		plugins.fireHook('filter:homepage.get', {routes: [ | ||||||
| 			{ | 			{ | ||||||
| 				route: 'categories', | 				route: 'categories', | ||||||
| @@ -361,9 +389,15 @@ adminController.homepage.get = function(req, res, next) { | |||||||
| 				route: 'popular', | 				route: 'popular', | ||||||
| 				name: 'Popular' | 				name: 'Popular' | ||||||
| 			} | 			} | ||||||
| 	]}, function(err, data) { | 		].concat(results.categoryData)}, function(err, data) { | ||||||
|  | 			data.routes.push({ | ||||||
|  | 				route: '', | ||||||
|  | 				name: 'Custom' | ||||||
|  | 			}); | ||||||
|  |  | ||||||
| 			res.render('admin/general/homepage', data); | 			res.render('admin/general/homepage', data); | ||||||
| 		}); | 		}); | ||||||
|  | 	}); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| adminController.settings.get = function(req, res, next) { | adminController.settings.get = function(req, res, next) { | ||||||
|   | |||||||
| @@ -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> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user