feat: added the linked application system

This commit is contained in:
Andre Henriques 2024-10-04 14:17:21 +01:00
parent 69c60986ff
commit 7217f6afe1
5 changed files with 138 additions and 26 deletions

View File

@ -32,6 +32,7 @@ data class Application(
var company: String, var company: String,
var recruiter: String, var recruiter: String,
var message: String, var message: String,
var linked_application: String,
var flairs: List<Flair>, var flairs: List<Flair>,
var views: List<View>, var views: List<View>,
) { ) {
@ -50,6 +51,7 @@ data class Application(
rs.getString("company"), rs.getString("company"),
rs.getString("recruiter"), rs.getString("recruiter"),
rs.getString("message"), rs.getString("message"),
rs.getString("linked_application"),
emptyList(), emptyList(),
emptyList(), emptyList(),
) )
@ -179,6 +181,7 @@ class ApplicationsController(
"", "",
"", "",
"", "",
"",
emptyList(), emptyList(),
emptyList(), emptyList(),
) )
@ -463,7 +466,7 @@ class ApplicationService(
} }
db.update( db.update(
"insert into applications (id, url, original_url, unique_url, title, user_id, extra_data, payrange, status, company, recruiter, message) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);", "insert into applications (id, url, original_url, unique_url, title, user_id, extra_data, payrange, status, company, recruiter, message, linked_application) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
application.id, application.id,
application.url, application.url,
application.original_url, application.original_url,
@ -476,6 +479,7 @@ class ApplicationService(
application.company, application.company,
application.recruiter, application.recruiter,
application.message, application.message,
application.linked_application,
) )
return true return true
@ -491,6 +495,17 @@ class ApplicationService(
.toList() .toList()
} }
// If it's to apply also remove the linked_application to only show the main
if (info.status == 0) {
return db.query(
"select * from applications where user_id=? and linked_application='' and status=0 order by title asc;",
arrayOf(user.id),
Application
)
.toList()
}
return db.query( return db.query(
"select * from applications where user_id=? and status=? order by title asc;", "select * from applications where user_id=? and status=? order by title asc;",
arrayOf(user.id, info.status), arrayOf(user.id, info.status),
@ -501,7 +516,7 @@ class ApplicationService(
public fun update(application: Application): Application { public fun update(application: Application): Application {
db.update( db.update(
"update applications set url=?, original_url=?, unique_url=?, title=?, user_id=?, extra_data=?, payrange=?, status=?, company=?, recruiter=?, message=? where id=?", "update applications set url=?, original_url=?, unique_url=?, title=?, user_id=?, extra_data=?, payrange=?, status=?, company=?, recruiter=?, message=?, linked_application=? where id=?",
application.url, application.url,
application.original_url, application.original_url,
application.unique_url, application.unique_url,
@ -513,6 +528,7 @@ class ApplicationService(
application.company, application.company,
application.recruiter, application.recruiter,
application.message, application.message,
application.linked_application,
application.id, application.id,
) )
return application return application

View File

@ -22,7 +22,8 @@ create table if not exists applications (
mesasge text default '', mesasge text default '',
user_id text, user_id text,
extra_data text, extra_data text,
status integer status integer,
linked_application text default ''
); );
create table if not exists views ( create table if not exists views (

View File

@ -40,8 +40,9 @@ export type Application = {
status: number; status: number;
recruiter: string; recruiter: string;
company: string; company: string;
flairs: Flair[];
message: string; message: string;
linked_application: string;
flairs: Flair[];
views: View[]; views: View[];
}; };

View File

@ -0,0 +1,79 @@
<script lang="ts">
import type { Application } from '$lib/ApplicationsStore.svelte';
import { post, put } from '$lib/utils';
let {
application,
dialog = $bindable(),
onreload
}: {
application: Application;
dialog: HTMLDialogElement;
onreload: (item: Application) => void;
} = $props();
let filter = $state('');
let applications: Application[] = $state([]);
async function getApplicationList() {
const app: Application[] = await post('application/list', {});
applications = app.filter((a) => a.id != application.id);
}
$effect(() => {
getApplicationList();
});
async function submit(item: Application) {
try {
application.linked_application = item.id;
await put('application/update', application);
dialog.close();
onreload(item);
} catch (e) {
// Show message to the user
console.log(e);
}
}
</script>
<dialog class="card max-w-[50vw]" bind:this={dialog}>
<div class="flex">
<input placeholder="Filter" class="p-2 flex-grow" bind:value={filter} />
<div>
{applications.length}
</div>
</div>
<div class="overflow-y-auto overflow-x-hidden flex-grow p-2">
{#each applications.filter((i) => {
if (!filter) {
return true;
}
const f = new RegExp(filter, 'ig');
let x = i.title;
if (i.company) {
x = `${x} @ ${i.company}`;
}
return x.match(f);
}) as item}
<div class="card p-2 my-2 bg-slate-100 max-w-full" role="none">
<button class="text-left max-w-full" type="button" onclick={() => submit(item)}>
<h2 class="text-lg text-blue-500">
{item.title}
{#if item.company}
<div class="text-violet-800">
@ {item.company}
</div>
{/if}
</h2>
<span class="text-violet-600 overflow-hidden whitespace-nowrap block max-w-full">
{item.url}
</span>
</button>
</div>
{/each}
</div>
</dialog>

View File

@ -13,11 +13,13 @@
import NewUrlDialog from './NewUrlDialog.svelte'; import NewUrlDialog from './NewUrlDialog.svelte';
import DropZone from './DropZone.svelte'; import DropZone from './DropZone.svelte';
import { userStore } from '$lib/UserStore.svelte'; import { userStore } from '$lib/UserStore.svelte';
import LinkApplication from './LinkApplication.svelte';
let activeItem: Application | undefined = $state(); let activeItem: Application | undefined = $state();
let extractTokens: HTMLDialogElement; let extractTokens: HTMLDialogElement;
let changeUrl: HTMLDialogElement; let changeUrl: HTMLDialogElement;
let linkApplication: HTMLDialogElement;
let lastExtData: any = $state(undefined); let lastExtData: any = $state(undefined);
let autoExtData = false; let autoExtData = false;
@ -268,29 +270,28 @@
onchange={save} onchange={save}
/> />
</fieldset> </fieldset>
<fieldset <fieldset draggable="false" class="max-w-full min-w-0 overflow-hidden">
draggable="false"
onmouseenter={() => (drag = false)}
onmouseleave={() => (drag = true)}
class="max-w-full min-w-0 overflow-hidden"
>
<div class="flabel">Url</div> <div class="flabel">Url</div>
<div class="finput bg-white w-full break-keep"> <div class="finput bg-white w-full break-keep">
{activeItem.url} {activeItem.url}
</div> </div>
</fieldset> </fieldset>
{#if activeItem.unique_url} {#if activeItem.unique_url && activeItem.unique_url !== activeItem.url}
<fieldset <fieldset draggable="false">
draggable="false"
onmouseenter={() => (drag = false)}
onmouseleave={() => (drag = true)}
>
<div class="flabel">Unique Url</div> <div class="flabel">Unique Url</div>
<div class="finput bg-white"> <div class="finput bg-white">
{activeItem.unique_url} {activeItem.unique_url}
</div> </div>
</fieldset> </fieldset>
{/if} {/if}
{#if activeItem.linked_application}
<fieldset draggable="false">
<div class="flabel">Linked Application</div>
<div class="finput bg-white">
{activeItem.linked_application}
</div>
</fieldset>
{/if}
<div> <div>
<div class="flabel">Tags</div> <div class="flabel">Tags</div>
<div class="flex gap-2 flex-wrap"> <div class="flex gap-2 flex-wrap">
@ -342,6 +343,7 @@
Open Open
</button> </button>
<button class="btn-primary" onclick={() => openCV()}> Open CV </button> <button class="btn-primary" onclick={() => openCV()}> Open CV </button>
<div class="px-10"></div>
<button class="btn-primary" onclick={() => extractTokens.showModal()}> <button class="btn-primary" onclick={() => extractTokens.showModal()}>
Extract Flair Extract Flair
</button> </button>
@ -363,9 +365,14 @@
Update Url Update Url
</button> </button>
{/if} {/if}
<div class="px-10"></div>
<button class="btn-primary" onclick={() => linkApplication.showModal()}>
Link Application
</button>
{#if activeItem.original_url != null} {#if activeItem.original_url != null}
<button class="btn-danger" onclick={resetUrl}> Reset Url </button> <button class="btn-danger" onclick={resetUrl}> Reset Url </button>
{/if} {/if}
<button class:btn-primary={drag} class:btn-danger={!drag} onclick={() => (drag = !drag)}> 👋 </button>
</div> </div>
</div> </div>
{#if applicationStore.dragging} {#if applicationStore.dragging}
@ -462,3 +469,11 @@
onreload={(item) => (activeItem = item)} onreload={(item) => (activeItem = item)}
/> />
{/if} {/if}
{#if activeItem}
<LinkApplication
application={activeItem}
bind:dialog={linkApplication}
onreload={(item) => (activeItem = item)}
/>
{/if}