Sorting order toggle
Этот коммит содержится в:
		
							родитель
							
								
									5a94654284
								
							
						
					
					
						Коммит
						7ed175a801
					
				| @ -1,6 +1,7 @@ | |||||||
| <script> | <script> | ||||||
|     export let displayDataAs |     export let displayDataAs | ||||||
|     export let selectedSorting |     export let selectedSorting | ||||||
|  |     export let sortingOrder | ||||||
| 
 | 
 | ||||||
|     const sortOptions = [ |     const sortOptions = [ | ||||||
| 		{ id: 'attribution_date', label: 'Attribution Date', type: 'date' }, | 		{ id: 'attribution_date', label: 'Attribution Date', type: 'date' }, | ||||||
| @ -46,6 +47,26 @@ | |||||||
|             </select> |             </select> | ||||||
|         </div> |         </div> | ||||||
|     </div> |     </div> | ||||||
|  |     <div class="cases-control"> | ||||||
|  |         <div class="buttons has-addons"> | ||||||
|  |             <button | ||||||
|  |                 class={sortingOrder == 'Ascending' | ||||||
|  |                     ? 'button is-dark is-selected is-small' | ||||||
|  |                     : 'button is-small'} | ||||||
|  |                 on:click={() => { | ||||||
|  |                     sortingOrder = 'Ascending'; | ||||||
|  |                 }}>Ascending</button | ||||||
|  |             > | ||||||
|  |             <button | ||||||
|  |                 class={sortingOrder == 'Descending' | ||||||
|  |                     ? 'button is-dark is-selected is-small' | ||||||
|  |                     : 'button is-small'} | ||||||
|  |                 on:click={() => { | ||||||
|  |                     sortingOrder = 'Descending'; | ||||||
|  |                 }}>Descending</button | ||||||
|  |             > | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|     <div class="cases-control"> |     <div class="cases-control"> | ||||||
|         <a |         <a | ||||||
|             href="https://d2u5cqyg0ksa9n.cloudfront.net/dfrlab-fiat-2024-dataset.csv" |             href="https://d2u5cqyg0ksa9n.cloudfront.net/dfrlab-fiat-2024-dataset.csv" | ||||||
|  | |||||||
| @ -153,25 +153,39 @@ | |||||||
| 		} | 		} | ||||||
| 	}); | 	}); | ||||||
| 
 | 
 | ||||||
| 	const sortFunction = (option) => | 	const sortFunction = (option, sortOrder) => | ||||||
| 		function (a, b) { | 		function (a, b) { | ||||||
| 			if (option.type == 'string' || option.type == 'date' || option.type == 'number') { | 			if (option.type == 'string' || option.type == 'date' || option.type == 'number') { | ||||||
| 				if (a[option.id] < b[option.id]) { | 				if (a[option.id] > b[option.id] && sortOrder == 'Descending') { | ||||||
| 					return -1; | 					return -1; | ||||||
| 				} | 				} | ||||||
| 				if (b[option.id] < a[option.id]) { | 				if (b[option.id] > a[option.id] && sortOrder == 'Descending') { | ||||||
| 					return 1; | 					return 1; | ||||||
| 				} else { | 				}  | ||||||
|  | 				if (a[option.id] > b[option.id] && sortOrder == 'Ascending') { | ||||||
|  | 					return 1; | ||||||
|  | 				} | ||||||
|  | 				if (b[option.id] > a[option.id] && sortOrder == 'Ascending') { | ||||||
|  | 					return -1; | ||||||
|  | 				} | ||||||
|  | 				else { | ||||||
| 					return 0; | 					return 0; | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 			if (option.type == 'array') { | 			if (option.type == 'array') { | ||||||
| 				if (a[option.id][0] < b[option.id][0]) { | 				if (a[option.id][0] > b[option.id][0] && sortOrder == 'Descending') { | ||||||
| 					return -1; | 					return -1; | ||||||
| 				} | 				} | ||||||
| 				if (b[option.id][0] < a[option.id][0]) { | 				if (b[option.id][0] > a[option.id][0] && sortOrder == 'Descending') { | ||||||
| 					return 1; | 					return 1; | ||||||
| 				} else { | 				} | ||||||
|  | 				if (a[option.id][0] > b[option.id][0] && sortOrder == 'Ascending') { | ||||||
|  | 					return 1; | ||||||
|  | 				} | ||||||
|  | 				if (b[option.id][0] > a[option.id][0] && sortOrder == 'Ascending') { | ||||||
|  | 					return -1; | ||||||
|  | 				} | ||||||
|  | 				else { | ||||||
| 					return 0; | 					return 0; | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| @ -192,18 +206,7 @@ | |||||||
| 				includesTextSearch($textSearchFilter, d.search) | 				includesTextSearch($textSearchFilter, d.search) | ||||||
| 		})); | 		})); | ||||||
| 	} | 	} | ||||||
| 	$: sortedCases = [...cases].sort(sortFunction(selectedSorting)); | 	$: sortedCases = [...cases].sort(sortFunction(selectedSorting, sortingOrder)); | ||||||
| 
 |  | ||||||
| 	let width = 1200; |  | ||||||
| 	let margin = { |  | ||||||
| 		top: 30, |  | ||||||
| 		right: 30, |  | ||||||
| 		bottom: 30, |  | ||||||
| 		left: 30 |  | ||||||
| 	}; |  | ||||||
| 
 |  | ||||||
| 	// set the scales |  | ||||||
| 	//$: setScales(cases, width, margin); |  | ||||||
| 
 | 
 | ||||||
| 	let sidebarOpen = false; | 	let sidebarOpen = false; | ||||||
| 
 | 
 | ||||||
| @ -211,16 +214,8 @@ | |||||||
| 		sidebarOpen = !sidebarOpen; | 		sidebarOpen = !sidebarOpen; | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
| 	const sortOptions = [ |  | ||||||
| 		{ id: 'attribution_date', label: 'Attribution Date', type: 'date' }, |  | ||||||
| 		{ id: 'attribution_score', label: 'Attribution Score', type: 'number' }, |  | ||||||
| 		{ id: 'actor_nation', label: 'Actor Nation', type: 'array' }, |  | ||||||
| 		{ id: 'platform', label: 'Platform', type: 'array' }, |  | ||||||
| 		{ id: 'source', label: 'Source', type: 'array' }, |  | ||||||
| 		{ id: 'source_category', label: 'Source Category', type: 'string' } |  | ||||||
| 	]; |  | ||||||
| 
 |  | ||||||
| 	let selectedSorting = { id: 'attribution_date', label: 'Attribution Date', type: 'date' }; | 	let selectedSorting = { id: 'attribution_date', label: 'Attribution Date', type: 'date' }; | ||||||
|  | 	let sortingOrder = 'Descending' | ||||||
| 
 | 
 | ||||||
| 	let modalOpen = false; | 	let modalOpen = false; | ||||||
| 	let activeCaseData; | 	let activeCaseData; | ||||||
| @ -296,7 +291,7 @@ | |||||||
| {#if displayDataAs == 'Cards'} | {#if displayDataAs == 'Cards'} | ||||||
| 	<section class="section"> | 	<section class="section"> | ||||||
| 		<div class="container"> | 		<div class="container"> | ||||||
| 			<CasesControls bind:displayDataAs bind:selectedSorting></CasesControls> | 			<CasesControls bind:displayDataAs bind:selectedSorting bind:sortingOrder></CasesControls> | ||||||
| 			<div class="grid is-col-min-12"> | 			<div class="grid is-col-min-12"> | ||||||
| 				{#each sortedCases as attrCase} | 				{#each sortedCases as attrCase} | ||||||
| 					{#if attrCase.show} | 					{#if attrCase.show} | ||||||
| @ -314,7 +309,7 @@ | |||||||
| {#if displayDataAs == 'Table' && sortedCases.length > 0} | {#if displayDataAs == 'Table' && sortedCases.length > 0} | ||||||
| 	<section class="section"> | 	<section class="section"> | ||||||
| 		<div class="container"> | 		<div class="container"> | ||||||
| 			<CasesControls bind:displayDataAs bind:selectedSorting></CasesControls> | 			<CasesControls bind:displayDataAs bind:selectedSorting bind:sortingOrder></CasesControls> | ||||||
| 			<CaseTable cases={sortedCases}></CaseTable> | 			<CaseTable cases={sortedCases}></CaseTable> | ||||||
| 		</div> | 		</div> | ||||||
| 	</section> | 	</section> | ||||||
|  | |||||||
		Загрузка…
	
	
			
			x
			
			
		
	
		Ссылка в новой задаче
	
	Block a user
	 Maarten
						Maarten