Files
huly-platform/plugins/login-resources/src/components/SelectWorkspace.svelte
T
2022-01-11 10:23:17 +01:00

139 lines
3.8 KiB
Svelte

<!--
// Copyright © 2020, 2021 Anticrm Platform Contributors.
// Copyright © 2021, 2022 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
-->
<script lang="ts">
import { Status, Severity, OK } from '@anticrm/platform'
import { getWorkspaces, selectWorkspace } from '../utils'
import { Button, getCurrentLocation, Label, navigate, setMetadataLocalStorage } from '@anticrm/ui'
import workbench from '@anticrm/workbench'
import login from '../plugin'
import StatusControl from './StatusControl.svelte'
let status = OK
async function select (workspace: string) {
status = new Status(Severity.INFO, login.status.ConnectingToServer, {})
const [loginStatus, result] = await selectWorkspace(workspace)
status = loginStatus
if (result !== undefined) {
setMetadataLocalStorage(login.metadata.LoginToken, result.token)
setMetadataLocalStorage(login.metadata.LoginEndpoint, result.endpoint)
setMetadataLocalStorage(login.metadata.LoginEmail, result.email)
navigate({ path: [workbench.component.WorkbenchApp] })
}
}
function createWorkspace (): void {
const loc = getCurrentLocation()
loc.path[1] = 'createWorkspace'
loc.path.length = 2
navigate(loc)
}
</script>
<form class="container">
<div class="grow-separator" />
<div class="title"><Label label={login.string.SelectWorkspace} /></div>
<div class="status">
<StatusControl {status} />
</div>
{#await getWorkspaces() then workspaces}
<div class="form">
{#each workspaces as workspace (workspace._id)}
<div
class="workspace flex-center fs-title cursor-pointer focused-button form-row"
on:click={() => select(workspace.workspace)}
>
{workspace.workspace}
</div>
{/each}
{#if !workspaces.length}
<div class="form-row send">
<Button label={login.string.CreateWorkspace} primary width="100%" on:click={createWorkspace} />
</div>
{/if}
</div>
<div class="grow-separator" />
{#if workspaces.length}
<div class="footer">
<span><Label label={login.string.CreateWorkspace} /></span>
<a href="." on:click|preventDefault={createWorkspace}><Label label={login.string.CreateWorkspace} /></a>
</div>
{/if}
{/await}
</form>
<style lang="scss">
.container {
display: flex;
flex-direction: column;
justify-content: space-between;
overflow: hidden;
height: 100%;
padding: 5rem;
.title {
font-weight: 600;
font-size: 1.5rem;
color: var(--theme-caption-color);
}
.status {
min-height: 7.5rem;
max-height: 7.5rem;
padding-top: 1.25rem;
}
.form {
display: grid;
grid-template-columns: 1fr 1fr;
column-gap: 0.75rem;
row-gap: 1.5rem;
.form-row {
grid-column-start: 1;
grid-column-end: 3;
}
.workspace {
padding: 1rem;
border-radius: 1rem;
}
}
.grow-separator {
flex-grow: 1;
}
.footer {
margin-top: 3.5rem;
font-size: 0.8rem;
color: var(--theme-caption-color);
span {
opacity: 0.3;
}
a {
text-decoration: none;
color: var(--theme-caption-color);
opacity: 0.8;
&:hover {
opacity: 1;
}
}
}
}
</style>