2024-07-25 17:10:00 +02:00
<!--
@component Main job list component
Properties:
- `filterPresets Object?`: Optional predefined filter values [Default: {} ]
- `authlevel Number`: The current users authentication level
- `roles [Number]`: Enum containing available roles
-->
< script >
2024-03-09 10:30:40 +01:00
import { onMount , getContext } from "svelte";
import { init } from "./utils.js";
import {
Row,
Col,
Button,
Icon,
Card,
Spinner,
} from "@sveltestrap/sveltestrap";
import Filters from "./filters/Filters.svelte";
import JobList from "./joblist/JobList.svelte";
import Refresher from "./joblist/Refresher.svelte";
import Sorting from "./joblist/SortSelection.svelte";
import MetricSelection from "./MetricSelection.svelte";
2024-05-22 18:22:35 +02:00
import TextFilter from "./filters/TextFilter.svelte";
2022-06-22 11:20:57 +02:00
2024-03-09 10:30:40 +01:00
const { query : initq } = init();
2022-06-22 11:20:57 +02:00
2024-03-09 10:30:40 +01:00
const ccconfig = getContext("cc-config");
2022-06-22 11:20:57 +02:00
2024-03-09 10:30:40 +01:00
export let filterPresets = {} ;
export let authlevel;
export let roles;
2022-06-22 11:20:57 +02:00
2024-03-09 10:30:40 +01:00
let filterComponent; // see why here: https://stackoverflow.com/questions/58287729/how-can-i-export-a-function-from-a-svelte-component-that-changes-a-value-in-the
let jobList,
matchedJobs = null;
2024-07-22 15:41:33 +02:00
let sorting = { field : "startTime" , type : "col" , order : "DESC" } ,
2024-03-09 10:30:40 +01:00
isSortingOpen = false,
isMetricsSelectionOpen = false;
let metrics = filterPresets.cluster
? ccconfig[`plot_list_selectedMetrics:${ filterPresets . cluster } `] ||
ccconfig.plot_list_selectedMetrics
: ccconfig.plot_list_selectedMetrics;
let showFootprint = filterPresets.cluster
? !!ccconfig[`plot_list_showFootprint:${ filterPresets . cluster } `]
: !!ccconfig.plot_list_showFootprint;
let selectedCluster = filterPresets?.cluster ? filterPresets.cluster : null;
2024-05-23 15:43:09 +02:00
let presetProject = filterPresets?.project ? filterPresets.project : ""
2024-03-09 10:30:40 +01:00
// The filterPresets are handled by the Filters component,
// so we need to wait for it to be ready before we can start a query.
// This is also why JobList component starts out with a paused query.
2024-07-25 17:10:00 +02:00
onMount(() => filterComponent.updateFilters());
2022-06-22 11:20:57 +02:00
< / script >
< Row >
2024-03-09 10:30:40 +01:00
{ #if $initq . fetching }
2022-06-22 11:20:57 +02:00
< Col xs = "auto" >
2024-03-09 10:30:40 +01:00
< Spinner / >
2022-06-22 11:20:57 +02:00
< / Col >
2024-03-09 10:30:40 +01:00
{ :else if $initq . error }
2022-06-22 11:20:57 +02:00
< Col xs = "auto" >
2024-03-09 10:30:40 +01:00
< Card body color = "danger" > { $initq . error . message } </ Card >
2022-06-22 11:20:57 +02:00
< / Col >
2024-03-09 10:30:40 +01:00
{ /if }
< / Row >
< Row >
< Col xs = "auto" >
< Button outline color = "primary" on:click = {() => ( isSortingOpen = true )} >
< Icon name = "sort-up" / > Sorting
< / Button >
< Button
outline
color="primary"
on:click={() => ( isMetricsSelectionOpen = true )}
>
< Icon name = "graph-up" / > Metrics
< / Button >
< Button disabled outline
>{ matchedJobs == null ? "Loading..." : `$ { matchedJobs } jobs ` } < /Button
>
< / Col >
< Col xs = "auto" >
< Filters
{ filterPresets }
bind:this={ filterComponent }
2024-07-25 17:10:00 +02:00
on:update-filters={({ detail }) => {
2024-03-09 10:30:40 +01:00
selectedCluster = detail.filters[0]?.cluster
? detail.filters[0].cluster.eq
: null;
2024-07-25 17:10:00 +02:00
jobList.queryJobs(detail.filters);
2024-03-09 10:30:40 +01:00
}}
/>
< / Col >
2022-06-22 11:20:57 +02:00
2024-03-09 10:30:40 +01:00
< Col xs = "3" style = "margin-left: auto;" >
2024-05-22 18:22:35 +02:00
< TextFilter
2024-05-23 15:43:09 +02:00
{ presetProject }
2024-03-09 10:30:40 +01:00
bind:authlevel
bind:roles
2024-07-25 17:10:00 +02:00
on:set-filter={({ detail }) => filterComponent . updateFilters ( detail )}
2024-03-09 10:30:40 +01:00
/>
< / Col >
< Col xs = "2" >
2024-07-25 17:10:00 +02:00
< Refresher on:refresh = {() => {
jobList.refreshJobs()
jobList.refreshAllMetrics()
}} />
2024-03-09 10:30:40 +01:00
< / Col >
2022-06-22 11:20:57 +02:00
< / Row >
2024-03-09 10:30:40 +01:00
< br / >
2022-06-22 11:20:57 +02:00
< Row >
2024-03-09 10:30:40 +01:00
< Col >
< JobList
bind:metrics
bind:sorting
bind:matchedJobs
bind:this={ jobList }
bind:showFootprint
/>
< / Col >
2022-06-22 11:20:57 +02:00
< / Row >
2024-03-09 10:30:40 +01:00
< Sorting bind:sorting bind:isOpen = { isSortingOpen } / >
2022-06-22 11:20:57 +02:00
< MetricSelection
2024-03-09 10:30:40 +01:00
bind:cluster={ selectedCluster }
configName="plot_list_selectedMetrics"
bind:metrics
bind:isOpen={ isMetricsSelectionOpen }
bind:showFootprint
2024-07-25 17:10:00 +02:00
footprintSelect={ true }
2024-03-09 10:30:40 +01:00
/>