Skip to content

Commit

Permalink
Add Task Selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Jun 21, 2024
1 parent b071c18 commit 809ed68
Show file tree
Hide file tree
Showing 6 changed files with 486 additions and 167 deletions.
60 changes: 56 additions & 4 deletions api/routes/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default async function router(schema: Schema, config: Config) {
})
}, async (req, res) => {
try {
await Auth.as_user(config, req, { admin: true });
await Auth.as_user(config, req);

const list = await config.models.Task.list({
limit: req.query.limit,
Expand All @@ -75,6 +75,29 @@ export default async function router(schema: Schema, config: Config) {
}
});

await schema.post('/task', {
name: 'Create Task',
group: 'Task',
description: 'Create Registered Task',
body: Type.Object({
name: Type.String(),
prefix: Type.String(),
repo: Type.Optional(Type.String()),
readme: Type.Optional(Type.String()),
}),
res: TaskResponse
}, async (req, res) => {
try {
await Auth.as_user(config, req);

const task = await config.models.Task.generate(req.body);

return res.json(task);
} catch (err) {
return Err.respond(err, res);
}
});

await schema.get('/task/raw', {
name: 'List Tasks',
group: 'RawTask',
Expand All @@ -85,7 +108,7 @@ export default async function router(schema: Schema, config: Config) {
})
}, async (req, res) => {
try {
await Auth.as_user(config, req, { admin: true });
await Auth.as_user(config, req);

const { total, tasks } = await listTasks();

Expand All @@ -111,7 +134,7 @@ export default async function router(schema: Schema, config: Config) {
})
}, async (req, res) => {
try {
await Auth.as_user(config, req, { admin: true });
await Auth.as_user(config, req);

// Stuck with this approach for now - https://github.com/aws/containers-roadmap/issues/418
const { tasks } = await listTasks();
Expand All @@ -136,7 +159,7 @@ export default async function router(schema: Schema, config: Config) {
res: StandardResponse
}, async (req, res) => {
try {
await Auth.as_user(config, req, { admin: true });
await Auth.as_user(config, req);

const { tasks } = await listTasks();

Expand Down Expand Up @@ -164,4 +187,33 @@ export default async function router(schema: Schema, config: Config) {
return Err.respond(err, res);
}
});

await schema.get('/task/prefix/:prefix/readme', {
name: 'Task README',
group: 'Task',
description: 'Return README Contents',
params: Type.Object({
prefix: Type.String()
}),
res: Type.Object({
body: Type.String()
})
}, async (req, res) => {
try {
await Auth.as_user(config, req);

const task = await config.models.Task.from(req.params.prefix);

if (task.readme) {
const readmeres = await fetch(task.readme);
return res.json({
body: await readmeres.text()
})
} else {
return res.json({ body: '' });
}
} catch (err) {
return Err.respond(err, res);
}
});
}
10 changes: 9 additions & 1 deletion api/web/src/components/Admin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,22 @@
}'
@click='$router.push(`/admin/config`)'
><IconSettings size='32' /><span class='mx-3'>Settings</span></span>
<span
class='list-group-item list-group-item-action d-flex align-items-center'
:class='{
"active": $route.name === "admin-task-raw",
"cursor-pointer": $route.name !== "admin-task-raw"
}'
@click='$router.push(`/admin/task-raw`)'
><IconBrandDocker size='32' /><span class='mx-3'>ETL Containers</span></span>
<span
class='list-group-item list-group-item-action d-flex align-items-center'
:class='{
"active": $route.name === "admin-task",
"cursor-pointer": $route.name !== "admin-task"
}'
@click='$router.push(`/admin/task`)'
><IconBrandDocker size='32' /><span class='mx-3'>ETL Tasks</span></span>
><IconBrandDocker size='32' /><span class='mx-3'>Registered Tasks</span></span>
<span
class='list-group-item list-group-item-action d-flex align-items-center'
:class='{
Expand Down
154 changes: 154 additions & 0 deletions api/web/src/components/Admin/AdminRawTasks.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<template>
<div>
<div class='card-header'>
<template v-if='task'>
<IconCircleArrowLeft
size='32'
class='cursor-pointer'
@click='task = null'
/>
<h3
class='mx-2 card-title'
v-text='task'
/>
</template>
<template v-else>
<h3 class='card-title'>
ETL Task Containers
</h3>
</template>
<div class='ms-auto'>
<div class='btn-list' />
</div>
</div>

<div style='min-height: 20vh; margin-bottom: 61px'>
<TablerLoading v-if='loading' />
<TablerNone
v-else-if='!Object.keys(tasks.items)'
label='Tasks'
:create='false'
/>
<template v-else-if='task'>
<TablerNone
v-if='!tasks.items[task].length'
label='Versions'
:create='false'
/>
<div
v-else
class='table-responsive'
>
<table class='table card-table table-hover table-vcenter datatable cursor-pointer'>
<tbody>
<tr
v-for='version in tasks.items[task]'
:key='version'
>
<td>
<div class='d-flex align-items-center'>
<span v-text='version' />
<div class='ms-auto'>
<TablerDelete
displaytype='icon'
@delete='deleteVersion(task, version)'
/>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div
class='position-absolute bottom-0 w-100'
style='height: 61px;'
>
<TableFooter
:limit='tasks.items[task].length'
:total='tasks.items[task].length'
@page='0'
/>
</div>
</template>
<template v-else>
<div class='table-responsive'>
<table class='table card-table table-hover table-vcenter datatable cursor-pointer'>
<tbody>
<tr
v-for='t in Object.keys(tasks.items)'
:key='t'
@click='task = t'
>
<td v-text='t' />
<td v-text='`${tasks.items[t].length} Versions`' />
</tr>
</tbody>
</table>
</div>
<div
class='position-absolute bottom-0 w-100'
style='height: 61px;'
>
<TableFooter
:limit='Object.keys(tasks.items).length'
:total='Object.keys(tasks.items).length'
@page='0'
/>
</div>
</template>
</div>
</div>
</template>

<script>
import { std } from '/src/std.ts';
import {
TablerLoading,
TablerDelete,
TablerNone,
} from '@tak-ps/vue-tabler';
import TableFooter from '../util/TableFooter.vue'
import {
IconCircleArrowLeft
} from '@tabler/icons-vue';
export default {
name: 'AdminTask',
components: {
TablerLoading,
TablerDelete,
TablerNone,
TableFooter,
IconCircleArrowLeft,
},
data: function() {
return {
loading: true,
task: null,
tasks: {
total: 0,
items: {}
}
}
},
mounted: async function() {
await this.fetch();
},
methods: {
fetch: async function() {
this.loading = true;
this.tasks = await std(`/api/task/raw`);
this.loading = false;
},
deleteVersion: async function(task, version) {
this.loading = true;
this.tasks = await std(`/api/task/raw/${task}/version/${version}`, {
method: 'DELETE'
});
await this.fetch();
}
}
}
</script>
Loading

0 comments on commit 809ed68

Please sign in to comment.