-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from COS301-SE-2024/feature/work-integration
Feature/work integration
- Loading branch information
Showing
47 changed files
with
13,428 additions
and
12,314 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/client/src/lib/components/admin/modals/add/+AddToWorkSpace.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<script lang="ts"> | ||
import { Button, Modal, Label } from 'flowbite-svelte'; | ||
import { set_workspaces } from '$lib/services/workspaces'; | ||
import axios from 'axios'; | ||
import { wrkspcs } from '$lib/store'; | ||
import { Checkbox } from 'flowbite-svelte'; | ||
import IconLibraryPlus from '@tabler/icons-svelte/IconLibraryPlus.svelte'; | ||
export let id; | ||
let formModal = false; | ||
// Function to handle form submission | ||
async function handleSubmit(event) { | ||
console.log('add to workspace is being handled'); | ||
// Prevent the default form submission behavior | ||
event.preventDefault(); | ||
const formData = new FormData(event.currentTarget); | ||
formData.append('userId', id); | ||
// Collect all checked workspaces and append them to the form data | ||
let checkedWorkspaces = []; | ||
const checkboxes = event.currentTarget.querySelectorAll('input[name="workspace"]:checked'); | ||
checkboxes.forEach((checkbox) => { | ||
checkedWorkspaces.push(checkbox.value); | ||
}); | ||
formData.append('Workspaces', JSON.stringify(checkedWorkspaces)); | ||
const response = await fetch('/admin/workspaces?/adduser', { | ||
method: 'POST', | ||
body: formData | ||
}); | ||
console.log(response); | ||
formModal = false; | ||
} | ||
let workspaces = []; | ||
async function openModal() { | ||
await set_workspaces(); | ||
const url = 'http://localhost:3000/users/' + id; | ||
const response = await axios.get(url); | ||
// Handle the response data | ||
const res_data = response.data; | ||
const wk_ids = []; | ||
for (let j = 0; j < res_data.workspaces.length; j++) { | ||
const wk_id = res_data.workspaces[j]; | ||
wk_ids.push(wk_id); | ||
} | ||
for (let j = 0; j < $wrkspcs.length; j++) { | ||
const wk_id = $wrkspcs[j].id; | ||
if (wk_ids.includes(wk_id)) { | ||
workspaces.push({ | ||
name: $wrkspcs[j].name, | ||
id: $wrkspcs[j].id, | ||
checked: true | ||
}); | ||
} else { | ||
workspaces.push({ | ||
name: $wrkspcs[j].name, | ||
id: $wrkspcs[j].id, | ||
checked: false | ||
}); | ||
} | ||
} | ||
formModal = true; | ||
} | ||
</script> | ||
|
||
<button | ||
on:click={openModal} | ||
class="transition-colors duration-200 hover:text-green-500 focus:outline-none dark:text-gray-300 dark:hover:text-green-500" | ||
> | ||
<IconLibraryPlus stroke={2} /> | ||
</button> | ||
|
||
<Modal bind:open={formModal} size="xs" autoclose={false} class="w-full"> | ||
<form class="flex flex-col space-y-6" on:submit={handleSubmit}> | ||
<h3 class="mb-4 text-xl font-medium text-gray-900 dark:text-white">Add to Workspace</h3> | ||
|
||
<Label for="workspaces" class="mb-2 mt-2 space-y-2">Workspaces</Label> | ||
{#each workspaces as workspace} | ||
<Checkbox name="workspace" value={workspace.id} bind:checked={workspace.checked} | ||
>{workspace.name}</Checkbox | ||
> | ||
{/each} | ||
<Button type="submit" class="w-full1">Add to Workspace</Button> | ||
</form> | ||
</Modal> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.