177 lines
6.7 KiB
Svelte
177 lines
6.7 KiB
Svelte
<script>
|
|
import { t, _ } from "svelte-i18n";
|
|
import Toastify from "toastify-js";
|
|
import { RunnerTeamService } from "@odit/lfk-client-js";
|
|
const teams_promise = RunnerTeamService.runnerTeamControllerGetAll();
|
|
import { users as usersstore } from "../store.js";
|
|
import store from "../store";
|
|
import TeamsEmptyState from "./TeamsEmptyState.svelte";
|
|
import ConfirmTeamDeletion from "./ConfirmTeamDeletion.svelte";
|
|
$: searchvalue = "";
|
|
$: active_deletes = [];
|
|
export let current_teams = [];
|
|
let modal_open = false;
|
|
let delete_team = {};
|
|
usersstore.subscribe((val) => {
|
|
current_teams = val;
|
|
});
|
|
teams_promise.then((data) => {
|
|
usersstore.set(data);
|
|
});
|
|
</script>
|
|
|
|
<ConfirmTeamDeletion
|
|
on:cancelDelete={(event) => {
|
|
modal_open = false;
|
|
active_deletes[event.detail.id] = false;
|
|
}}
|
|
bind:modal_open
|
|
bind:delete_team />
|
|
{#if store.state.jwtinfo.userdetails.permissions.includes('TEAM:GET')}
|
|
{#await teams_promise}
|
|
<div
|
|
class="bg-teal-lightest border-t-4 border-teal rounded-b text-teal-darkest px-4 py-3 shadow-md my-2"
|
|
role="alert">
|
|
<p class="font-bold">teams are being loaded...</p>
|
|
<p class="text-sm">{$_('this-might-take-a-moment')}</p>
|
|
</div>
|
|
{:then}
|
|
{#if current_teams.length === 0}
|
|
<TeamsEmptyState />
|
|
{:else}
|
|
<input
|
|
type="search"
|
|
bind:value={searchvalue}
|
|
placeholder={$_('datatable.search')}
|
|
aria-label={$_('datatable.search')}
|
|
class="gridjs-input gridjs-search-input mb-4" />
|
|
<div
|
|
class="shadow border-b border-gray-200 sm:rounded-lg overflow-x-scroll">
|
|
<table class="divide-y divide-gray-200 w-full">
|
|
<thead class="bg-gray-50">
|
|
<tr>
|
|
<th
|
|
scope="col"
|
|
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
Name
|
|
</th>
|
|
<th
|
|
scope="col"
|
|
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
{$_('organization')}
|
|
</th>
|
|
<th
|
|
scope="col"
|
|
class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
Contact
|
|
</th>
|
|
<th scope="col" class="relative px-6 py-3">
|
|
<span class="sr-only">Action</span>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-gray-200">
|
|
{#each current_teams as t}
|
|
{#if Object.values(t)
|
|
.toString()
|
|
.toLowerCase()
|
|
.includes(searchvalue)}
|
|
<tr data-rowid="team_{t.id}">
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<div class="flex items-center">
|
|
<div class="ml-4">
|
|
<div
|
|
class="text-sm font-medium text-gray-900">
|
|
{t.name}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<div class="flex items-center">
|
|
<div class="ml-4">
|
|
<div
|
|
class="text-sm font-medium text-gray-900">
|
|
{#if t.parentGroup}
|
|
{t.parentGroup.name}
|
|
{:else}no organization specified{/if}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<div class="flex items-center">
|
|
<div class="ml-4">
|
|
<div
|
|
class="text-sm font-medium text-gray-900">
|
|
{#if t.contact}
|
|
{JSON.stringify(t.contact)}
|
|
{:else}no contact specified{/if}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
{#if active_deletes[t.id] === true}
|
|
<td
|
|
class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
|
<button
|
|
on:click={() => {
|
|
active_deletes[t.id] = false;
|
|
}}
|
|
tabindex="0"
|
|
class="ml-4 text-indigo-600 hover:text-indigo-900 cursor-pointer">Cancel
|
|
Delete</button>
|
|
<button
|
|
on:click={() => {
|
|
RunnerTeamService.runnerTeamControllerRemove(t.id, false)
|
|
.then((resp) => {
|
|
current_teams = current_teams.filter((obj) => obj.id !== t.id);
|
|
Toastify({
|
|
text: 'Organization deleted',
|
|
duration: 500,
|
|
backgroundColor:
|
|
'linear-gradient(to right, #00b09b, #96c93d)',
|
|
}).showToast();
|
|
})
|
|
.catch((err) => {
|
|
modal_open = true;
|
|
delete_team = t;
|
|
});
|
|
}}
|
|
tabindex="0"
|
|
class="ml-4 text-red-600 hover:text-red-900 cursor-pointer">Confirm
|
|
Delete</button>
|
|
</td>
|
|
{:else}
|
|
<td
|
|
class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
|
<a
|
|
href="./{t.id}"
|
|
class="text-indigo-600 hover:text-indigo-900">Edit</a>
|
|
{#if store.state.jwtinfo.userdetails.permissions.includes('TEAM:DELETE')}
|
|
<button
|
|
on:click={() => {
|
|
active_deletes[t.id] = true;
|
|
}}
|
|
tabindex="0"
|
|
class="ml-4 text-red-600 hover:text-red-900 cursor-pointer">Delete</button>
|
|
{/if}
|
|
</td>
|
|
{/if}
|
|
</tr>
|
|
{/if}
|
|
{/each}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
{/if}
|
|
{:catch error}
|
|
<div class="text-white px-6 py-4 border-0 rounded relative mb-4 bg-red-500">
|
|
<span class="inline-block align-middle mr-8">
|
|
<b class="capitalize">{$_('general_promise_error')}</b>
|
|
{error}
|
|
</span>
|
|
</div>
|
|
{/await}
|
|
{/if}
|