qa: Refactor gitlab use
This commit is contained in:
parent
c31f76e9c3
commit
d4cad767eb
7 changed files with 145 additions and 54 deletions
|
|
@ -22,7 +22,7 @@
|
|||
Row,
|
||||
} from 'sveltestrap';
|
||||
|
||||
import { auth, version } from '$lib/stores/auth';
|
||||
import { auth, gitlab, version } from '$lib/stores/auth';
|
||||
|
||||
export let activemenu = "";
|
||||
$: {
|
||||
|
|
@ -33,17 +33,6 @@
|
|||
activemenu = "";
|
||||
}
|
||||
}
|
||||
|
||||
async function rungitlab() {
|
||||
const res = await fetch('api/gitlab/token');
|
||||
if (res.status === 200) {
|
||||
return res.json();
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
const gitlab = rungitlab();
|
||||
</script>
|
||||
|
||||
<Navbar color="dark" dark expand="xs">
|
||||
|
|
@ -101,17 +90,17 @@
|
|||
{/if}
|
||||
</Nav>
|
||||
<Nav class="ms-auto text-light" navbar>
|
||||
{#await gitlab then gl}
|
||||
{#if $gitlab}
|
||||
<Icon name="gitlab" />
|
||||
{:catch err}
|
||||
{:else}
|
||||
<Button
|
||||
color="warning"
|
||||
size="sm"
|
||||
href="auth/gitlab?next=/"
|
||||
href={"auth/gitlab?next=" + encodeURIComponent($page.url.pathname) }
|
||||
>
|
||||
<Icon name="gitlab" /> Connexion GitLab
|
||||
</Button>
|
||||
{/await}
|
||||
{/if}
|
||||
<NavItem class="ms-2 text-truncate">
|
||||
v{$version.version}
|
||||
{#if $auth}– Logged as {$auth.name} (team #{$auth.id_team}){/if}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
import {
|
||||
Alert,
|
||||
Button,
|
||||
ButtonGroup,
|
||||
Card,
|
||||
CardBody,
|
||||
CardHeader,
|
||||
|
|
@ -16,7 +17,7 @@
|
|||
import BadgeState from '$lib/components/BadgeState.svelte';
|
||||
import DateFormat from '$lib/components/DateFormat.svelte';
|
||||
import { getQAComments, QAComment } from '$lib/qa';
|
||||
import { auth } from '$lib/stores/auth';
|
||||
import { auth, gitlab } from '$lib/stores/auth';
|
||||
import { ToastsStore } from '$lib/stores/toasts';
|
||||
import { viewIdx } from '$lib/stores/todo';
|
||||
|
||||
|
|
@ -150,16 +151,25 @@
|
|||
})
|
||||
}
|
||||
|
||||
async function rungitlab() {
|
||||
const res = await fetch('api/gitlab/token');
|
||||
if (res.status === 200) {
|
||||
return res.json();
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
let exportingToGitlab = false;
|
||||
async function exportgitlab() {
|
||||
exportingToGitlab = true;
|
||||
try {
|
||||
const data = await query.export2Gitlab();
|
||||
query.forge_link = data.web_url;
|
||||
query.exported = data.iid;
|
||||
ToastsStore.addToast({
|
||||
color: "success",
|
||||
title: "Retour exporté vers Gitlab !",
|
||||
msg: "Ce retour a bien été exporté vers Gitlab sous la référence #" + query.exported,
|
||||
});
|
||||
} catch (err) {
|
||||
ToastsStore.addErrorToast({
|
||||
msg: err,
|
||||
});
|
||||
}
|
||||
exportingToGitlab = false;
|
||||
}
|
||||
|
||||
const gitlab = rungitlab();
|
||||
</script>
|
||||
|
||||
{#if query}
|
||||
|
|
@ -169,14 +179,35 @@
|
|||
<h4 class="card-title fw-bold mb-0">{query.subject}</h4>
|
||||
<div>
|
||||
{#if $auth && !query.solved}
|
||||
{#await gitlab then gl}
|
||||
<Button
|
||||
on:click={() => query.export2Gitlab()}
|
||||
>
|
||||
<Icon name="gitlab" />
|
||||
Exporter vers GitLab
|
||||
</Button>
|
||||
{/await}
|
||||
<ButtonGroup>
|
||||
{#if query.forge_link}
|
||||
<Button
|
||||
color="warning"
|
||||
outline
|
||||
size="sm"
|
||||
href="{query.forge_link}"
|
||||
target="_blank"
|
||||
>
|
||||
<Icon name="gitlab" />
|
||||
</Button>
|
||||
{/if}
|
||||
{#if $gitlab}
|
||||
<Button
|
||||
color="warning"
|
||||
outline
|
||||
size="sm"
|
||||
disabled={exportingToGitlab || query.exported}
|
||||
on:click={exportgitlab}
|
||||
>
|
||||
{#if exportingToGitlab}
|
||||
<Spinner size="sm" />
|
||||
{:else if !query.exported}
|
||||
<Icon name="gitlab" />
|
||||
{/if}
|
||||
Exporter vers GitLab
|
||||
</Button>
|
||||
{/if}
|
||||
</ButtonGroup>
|
||||
{/if}
|
||||
{#if $auth && !query.solved && $viewIdx[query.id_exercice]}
|
||||
<Button on:click={solveQA} color="success">
|
||||
|
|
|
|||
Reference in a new issue