mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2026-04-05 15:37:29 +02:00
Migrate jobView components
This commit is contained in:
@@ -9,7 +9,8 @@
|
||||
|
||||
<script>
|
||||
import {
|
||||
getContext
|
||||
getContext,
|
||||
onMount
|
||||
} from "svelte";
|
||||
import {
|
||||
Card,
|
||||
@@ -21,17 +22,26 @@
|
||||
} from "@sveltestrap/sveltestrap";
|
||||
import { round } from "mathjs";
|
||||
|
||||
export let jobId;
|
||||
export let jobEnergy = null;
|
||||
export let jobEnergyFootprint = null;
|
||||
/* Svelte 5 Props */
|
||||
let {
|
||||
jobId,
|
||||
jobEnergy = null,
|
||||
jobEnergyFootprint = null
|
||||
} = $props();
|
||||
|
||||
/* Const Init */
|
||||
const carbonPerkWh = getContext("emission");
|
||||
let carbonMass;
|
||||
|
||||
/* State Init */
|
||||
let carbonMass = $state(0);
|
||||
|
||||
$: if (carbonPerkWh) {
|
||||
// ( kWh * g/kWh) / 1000 = kg || Rounded to 2 Digits via [ round(x * 100) / 100 ]
|
||||
carbonMass = round( ((jobEnergy ? jobEnergy : 0.0) * carbonPerkWh) / 10 ) / 100;
|
||||
}
|
||||
/* On Mount */
|
||||
onMount(() => {
|
||||
if (carbonPerkWh) {
|
||||
// ( kWh * g/kWh) / 1000 = kg || Rounded to 2 Digits via [ round(x * 100) / 100 ]
|
||||
carbonMass = round( ((jobEnergy ? jobEnergy : 0.0) * carbonPerkWh) / 10 ) / 100;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<Card>
|
||||
|
||||
Reference in New Issue
Block a user