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 {
Row,
Col,
Button,
2024-10-07 17:36:40 +02:00
ButtonGroup,
2024-03-09 10:30:40 +01:00
Icon,
Card,
Spinner,
} from "@sveltestrap/sveltestrap";
2024-07-26 12:34:18 +02:00
import { init } from "./generic/utils.js";
import Filters from "./generic/Filters.svelte";
import JobList from "./generic/JobList.svelte";
import TextFilter from "./generic/helper/TextFilter.svelte";
import Refresher from "./generic/helper/Refresher.svelte";
import Sorting from "./generic/select/SortSelection.svelte";
import MetricSelection from "./generic/select/MetricSelection.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 >
2024-10-07 17:36:40 +02:00
<!-- ROW1: Status -->
{ #if $initq . fetching }
< Row class = "mb-3" >
< Col >
2024-03-09 10:30:40 +01:00
< Spinner / >
2022-06-22 11:20:57 +02:00
< / Col >
2024-10-07 17:36:40 +02:00
< / Row >
{ :else if $initq . error }
< Row class = "mb-3" >
< Col >
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-10-07 17:36:40 +02:00
< / Row >
{ /if }
<!-- ROW2: Tools -->
< Row cols = {{ xs : 1 , md : 2 , lg : 4 }} class="mb-3" >
< Col lg = "2" class = "mb-2 mb-lg-0" >
< ButtonGroup class = "w-100" >
< 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 >
< / ButtonGroup >
2024-03-09 10:30:40 +01:00
< / Col >
2024-10-07 17:36:40 +02:00
< Col lg = "4" xl = " {( presetProject !== '' ) ? 5 : 6 } " class = "mb-1 mb-lg-0" >
2024-03-09 10:30:40 +01:00
< Filters
{ filterPresets }
2024-10-07 17:36:40 +02:00
{ matchedJobs }
2024-03-09 10:30:40 +01:00
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 >
2024-10-07 17:36:40 +02:00
< Col lg = "3" xl = " {( presetProject !== '' ) ? 3 : 2 } " class = "mb-2 mb-lg-0" >
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 >
2024-10-07 17:36:40 +02:00
< Col lg = "3" xl = "2" class = "mb-1 mb-lg-0" >
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-10-07 17:36:40 +02:00
<!-- ROW3: Job List -->
2022-06-22 11:20:57 +02:00
< Row >
2024-03-09 10:30:40 +01:00
< Col >
< JobList
2024-10-07 17:36:40 +02:00
bind:this={ jobList }
2024-03-09 10:30:40 +01:00
bind:metrics
bind:sorting
bind:matchedJobs
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
/>