mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-27 17:16:14 +01:00 
			
		
		
		
	refactor: flags lib to have a separate getFlagIdsWithFilters method
added quick filter for unresolved flags
This commit is contained in:
		
							
								
								
									
										27
									
								
								src/flags.js
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								src/flags.js
									
									
									
									
									
								
							| @@ -36,9 +36,13 @@ Flags.init = async function () { | |||||||
| 		if (!Array.isArray(value)) { | 		if (!Array.isArray(value)) { | ||||||
| 			sets.push(prefix + value); | 			sets.push(prefix + value); | ||||||
| 		} else if (value.length) { | 		} else if (value.length) { | ||||||
|  | 			if (value.length === 1) { | ||||||
|  | 				sets.push(prefix + value.pop()); | ||||||
|  | 			} else { | ||||||
| 				value.forEach(x => orSets.push(prefix + x)); | 				value.forEach(x => orSets.push(prefix + x)); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	const hookData = { | 	const hookData = { | ||||||
| 		filters: { | 		filters: { | ||||||
| @@ -67,6 +71,10 @@ Flags.init = async function () { | |||||||
| 					case 'mine': | 					case 'mine': | ||||||
| 						sets.push('flags:byAssignee:' + uid); | 						sets.push('flags:byAssignee:' + uid); | ||||||
| 						break; | 						break; | ||||||
|  |  | ||||||
|  | 					case 'unresolved': | ||||||
|  | 						prepareSets(sets, orSets, 'flags:byState:', ['open', 'wip']); | ||||||
|  | 						break; | ||||||
| 				} | 				} | ||||||
| 			}, | 			}, | ||||||
| 		}, | 		}, | ||||||
| @@ -113,9 +121,13 @@ Flags.get = async function (flagId) { | |||||||
| 	return data.flag; | 	return data.flag; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| Flags.list = async function (data) { | Flags.getCount = async function ({ uid, filters }) { | ||||||
| 	const filters = data.filters || {}; | 	filters = filters || {}; | ||||||
|  | 	const flagIds = await Flags.getFlagIdsWithFilters({ filters, uid }); | ||||||
|  | 	return flagIds.length; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | Flags.getFlagIdsWithFilters = async function ({ filters, uid }) { | ||||||
| 	let sets = []; | 	let sets = []; | ||||||
| 	const orSets = []; | 	const orSets = []; | ||||||
|  |  | ||||||
| @@ -126,7 +138,7 @@ Flags.list = async function (data) { | |||||||
| 	for (var type in filters) { | 	for (var type in filters) { | ||||||
| 		if (filters.hasOwnProperty(type)) { | 		if (filters.hasOwnProperty(type)) { | ||||||
| 			if (Flags._filters.hasOwnProperty(type)) { | 			if (Flags._filters.hasOwnProperty(type)) { | ||||||
| 				Flags._filters[type](sets, orSets, filters[type], data.uid); | 				Flags._filters[type](sets, orSets, filters[type], uid); | ||||||
| 			} else { | 			} else { | ||||||
| 				winston.warn('[flags/list] No flag filter type found: ' + type); | 				winston.warn('[flags/list] No flag filter type found: ' + type); | ||||||
| 			} | 			} | ||||||
| @@ -152,6 +164,15 @@ Flags.list = async function (data) { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	return flagIds; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | Flags.list = async function (data) { | ||||||
|  | 	const filters = data.filters || {}; | ||||||
|  | 	let flagIds = Flags.getFlagIdsWithFilters({ | ||||||
|  | 		filters, | ||||||
|  | 		uid: data.uid, | ||||||
|  | 	}); | ||||||
| 	flagIds = await Flags.sort(flagIds, data.sort); | 	flagIds = await Flags.sort(flagIds, data.sort); | ||||||
|  |  | ||||||
| 	// Create subset for parsing based on page number (n=20) | 	// Create subset for parsing based on page number (n=20) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user