Select weather fields for country view
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ console.log("api host:", import.meta.env.VITE_API_HOST);
|
|||||||
type Section = "cities" | "country" | "database";
|
type Section = "cities" | "country" | "database";
|
||||||
|
|
||||||
const App: Component = () => {
|
const App: Component = () => {
|
||||||
const [getSection, setSection] = createSignal<Section>("country");
|
const [getSection, setSection] = createSignal<Section>("cities");
|
||||||
|
|
||||||
const section = () => {
|
const section = () => {
|
||||||
switch(getSection()) {
|
switch(getSection()) {
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ export const SelectCity: Component<{
|
|||||||
onClick={selectAll}
|
onClick={selectAll}
|
||||||
/>
|
/>
|
||||||
<ul>{cityList.map(city =>
|
<ul>{cityList.map(city =>
|
||||||
<label>
|
|
||||||
<li>
|
<li>
|
||||||
|
<label>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
name="city"
|
name="city"
|
||||||
@@ -43,8 +43,8 @@ export const SelectCity: Component<{
|
|||||||
onClick={handleSelect}
|
onClick={handleSelect}
|
||||||
/>
|
/>
|
||||||
{city}
|
{city}
|
||||||
|
</label>
|
||||||
</li>
|
</li>
|
||||||
</label>
|
|
||||||
)}
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ export const cityList = ["Ainaži", "Alūksne", "Bauska", "Dagda", "Daugavgrīva
|
|||||||
|
|
||||||
export const weatherField = ["tempMax", "tempMin", "tempAvg", "precipitation", "windAvg", "windMax", "visibilityMin", "visibilityAvg", "snowAvg", "atmPressire", "dewPoint", "humidity", "sunDuration", "phenomena"];
|
export const weatherField = ["tempMax", "tempMin", "tempAvg", "precipitation", "windAvg", "windMax", "visibilityMin", "visibilityAvg", "snowAvg", "atmPressire", "dewPoint", "humidity", "sunDuration", "phenomena"];
|
||||||
|
|
||||||
|
export const weatherFieldNumeric = weatherField.filter(f => f !== "phenomena");
|
||||||
|
|
||||||
export const aggregateKey = ["min", "max", "avg", "sum", "list", "distinct"];
|
export const aggregateKey = ["min", "max", "avg", "sum", "list", "distinct"];
|
||||||
|
|
||||||
export const aggregateGranularity = ["hour", "day", "month", "year"];
|
export const aggregateGranularity = ["hour", "day", "month", "year"];
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
|
import moment from "moment";
|
||||||
import { createSignal } from "solid-js";
|
import { createSignal } from "solid-js";
|
||||||
|
|
||||||
import { QueryResult } from "./result/QueryResult";
|
import { QueryResult } from "./result/QueryResult";
|
||||||
import { SelectTimeRange } from "../components/SelectTimeRange";
|
import { SelectTimeRange } from "../components/SelectTimeRange";
|
||||||
import moment from "moment";
|
import { weatherFieldNumeric } from "../consts";
|
||||||
import { weatherField } from "../consts";
|
import { MultiSelectField } from "./MultiSelectField";
|
||||||
|
|
||||||
const nowRounded = new Date(new Date().setMinutes(30));
|
const nowRounded = new Date(new Date().setMinutes(30));
|
||||||
const dayAgo = moment(nowRounded).subtract(1, "days").subtract(30, "minutes").toDate();
|
const dayAgo = moment(nowRounded).subtract(1, "days").subtract(30, "minutes").toDate();
|
||||||
|
|
||||||
export function Country() {
|
export function Country() {
|
||||||
const weatherFieldNumeric = weatherField.filter(f => f !== "phenomena");
|
|
||||||
const [getStart, setStart] = createSignal(dayAgo);
|
const [getStart, setStart] = createSignal(dayAgo);
|
||||||
const [getEnd, setEnd] = createSignal(nowRounded);
|
const [getEnd, setEnd] = createSignal(nowRounded);
|
||||||
const [getFields, setFields] = createSignal(weatherFieldNumeric);
|
const [getFields, setFields] = createSignal(weatherFieldNumeric);
|
||||||
@@ -19,7 +19,10 @@ export function Country() {
|
|||||||
<h2>Latvia</h2>
|
<h2>Latvia</h2>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
column1
|
<MultiSelectField
|
||||||
|
getFields={getFields}
|
||||||
|
setFields={setFields}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<SelectTimeRange
|
<SelectTimeRange
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import { Accessor, Component, Setter } from "solid-js";
|
||||||
|
import { weatherFieldNumeric } from "../consts";
|
||||||
|
|
||||||
|
export const MultiSelectField: Component<{
|
||||||
|
getFields: Accessor<string[]>,
|
||||||
|
setFields: Setter<string[]>,
|
||||||
|
}> = ({ getFields, setFields }) => {
|
||||||
|
|
||||||
|
function handleSelect(fieldName: string) {
|
||||||
|
const fields = [...getFields()];
|
||||||
|
if (fields.includes(fieldName)) {
|
||||||
|
const removeIndex = fields.indexOf(fieldName);
|
||||||
|
fields.splice(removeIndex, 1);
|
||||||
|
}
|
||||||
|
else fields.push(fieldName);
|
||||||
|
|
||||||
|
setFields(fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectAll(e: MouseEvent) {
|
||||||
|
if (!e.target) return;
|
||||||
|
const target = e.target as HTMLInputElement;
|
||||||
|
const selectedFields = target.checked
|
||||||
|
? [...weatherFieldNumeric]
|
||||||
|
: [];
|
||||||
|
|
||||||
|
setFields(selectedFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
Select all <input
|
||||||
|
type="checkbox"
|
||||||
|
checked={true}
|
||||||
|
onClick={selectAll}
|
||||||
|
/>
|
||||||
|
<ul>
|
||||||
|
{weatherFieldNumeric.map(fieldName =>
|
||||||
|
<li>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name={fieldName}
|
||||||
|
checked={getFields().includes(fieldName)}
|
||||||
|
onClick={() => handleSelect(fieldName)}
|
||||||
|
/>
|
||||||
|
{fieldName}
|
||||||
|
</label>
|
||||||
|
</li>
|
||||||
|
)}
|
||||||
|
</ul>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -14,6 +14,15 @@ code {
|
|||||||
monospace;
|
monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
list-style-type: none;
|
||||||
|
padding-inline-start: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
thead {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: 'Rubik';
|
font-family: 'Rubik';
|
||||||
src: url('../assets/Rubik-Medium.ttf') format('truetype');
|
src: url('../assets/Rubik-Medium.ttf') format('truetype');
|
||||||
|
|||||||
Reference in New Issue
Block a user