Setting plugin (#328)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2021-11-22 13:06:14 +01:00
committed by GitHub
parent ef0c3e8c91
commit 5e807d466a
54 changed files with 2629 additions and 1284 deletions
@@ -14,12 +14,25 @@
-->
<script lang="ts">
import { createEventDispatcher } from 'svelte'
import { Label, showPopup } from '@anticrm/ui'
import { Avatar } from '@anticrm/presentation'
import TelegramPopup from './TelegramPopup.svelte'
import { getCurrentLocation, Label, navigate } from '@anticrm/ui'
import { Avatar, getClient } from '@anticrm/presentation'
import workbench, { Application, SpecialNavModel } from '@anticrm/workbench'
import setting from '@anticrm/setting'
import { Ref } from '@anticrm/core'
let items: string[] = ['Settings', 'Integrations', 'Support', 'Privacy', 'Terms & policy', 'Sign out']
const client = getClient()
async function getItems(): Promise<SpecialNavModel[] | undefined> {
const app = await client.findOne(workbench.class.Application, { _id: setting.ids.SettingApp as Ref<Application> })
return app?.navigatorModel?.specials
}
function selectSpecial (sp: SpecialNavModel): void {
const loc = getCurrentLocation()
loc.path[1] = setting.ids.SettingApp
loc.path[2] = sp.id
loc.path.length = 3
navigate(loc)
}
</script>
<div class="account-popup">
@@ -32,12 +45,14 @@
</div>
</div>
<div class="content">
{#each items as item }
<div class="item" on:click={() => {
if (item === 'Integrations')
showPopup(TelegramPopup, {})
}}>{item}</div>
{/each}
{#await getItems() then items}
{#if items}
{#each items as item }
<div class="item" on:click={() => selectSpecial(item)}><Label label={item.label} /></div>
{/each}
{/if}
{/await}
<div class="item"><Label label={'Sign out'} /></div>
</div>
</div>
@@ -27,8 +27,8 @@
let apps: Application[] = []
const query = createQuery()
$: query.query(workbench.class.Application, {}, result => { apps = result })
const query = createQuery()
$: query.query(workbench.class.Application, { hidden: false }, result => { apps = result })
function navigateApp(app: Ref<Application>) {
const loc = getCurrentLocation()
@@ -1,5 +1,5 @@
<!--
// Copyright © 2020 Anticrm Platform Contributors.
// Copyright © 2020, 2021 Anticrm Platform Contributors.
//
// 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
@@ -14,14 +14,31 @@
-->
<script lang="ts">
import type { Ref, Space } from '@anticrm/core'
import type { NavigatorModel } from '@anticrm/workbench'
import type { NavigatorModel, SpecialNavModel } from '@anticrm/workbench'
import SpacesNav from './navigator/SpacesNav.svelte'
import TreeSeparator from './navigator/TreeSeparator.svelte'
import SpecialElement from './navigator/SpecialElement.svelte'
import { getCurrentLocation, navigate } from '@anticrm/ui'
export let model: NavigatorModel | undefined
function selectSpecial (sp: SpecialNavModel): void {
const loc = getCurrentLocation()
loc.path[2] = sp.id
loc.path.length = 3
navigate(loc)
}
</script>
{#if model}
{#if model.specials}
{#each model.specials as special}
<SpecialElement label={special.label} icon={special.icon} on:click={() => selectSpecial(special)} />
{/each}
{#if model.spaces.length}
<TreeSeparator />
{/if}
{/if}
{#each model.spaces as m}
<SpacesNav model={m}/>
{/each}
@@ -1,108 +0,0 @@
<!--
// Copyright © 2020 Anticrm Platform Contributors.
//
// 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 { onMount } from "svelte"
import { createEventDispatcher } from 'svelte'
export let length: number = 6
export let value: string = ''
const dispatch = createEventDispatcher()
let digits: string[] = []
let areas: HTMLInputElement[] = []
let selected: number = 0
let filled: number
for (let i = 0; i < length; i++) digits[i] = ''
const onInput = (ev?: Event, n?: number): void => {
selected = -1
filled = 0
for (let i = 0; i < length; i++) {
if (digits[i] && digits[i].length > 1) {
if (i < length - 1) digits[i+1] = digits[i].substring(1)
digits[i] = digits[i][0]
}
if (digits[i]) filled++
if (selected < 0 && selected < length && digits[i] === '') selected = i
}
digits = digits
if (filled === length) {
if ((ev as InputEvent).inputType === 'insertFromPaste' && n && n < length) selected = n
if ((ev as InputEvent).inputType === 'insertText' && selected < 0 && (n || n === 0)) selected = n + 1
if (selected === length) selected--
value = ''
for (let i = 0; i < length; i++) value += digits[i]
dispatch('filled', value)
}
if (selected !== -1 && selected < length) {
areas[selected].focus()
areas[selected].select()
}
}
const selectInput = (n: number): void => {
if (areas[n]) {
areas[n].focus()
areas[n].select()
}
}
const keyPressed = (ev: Event, n: number): void => {
if ((ev as KeyboardEvent).key === 'Backspace' && n > 0 && digits[n] === '') {
digits[n-1] = ''
digits = digits
onInput(undefined, n-1)
}
}
onMount(() => {
if (areas[0]) onInput()
console.log('AREAS', areas)
})
</script>
<div class="flex-between">
{#each digits as digit, i}
<input
class="fs-title digit"
type="text"
bind:this={areas[i]}
bind:value={digit}
on:input={(ev) => { onInput(ev, i) }}
on:keydown={async (ev) => keyPressed(ev, i)}
on:click={async () => selectInput(i)}
/>
{/each}
</div>
<style lang="scss">
.digit {
width: 2.5rem;
height: 3rem;
text-align: center;
background-color: var(--theme-card-bg-dark);
border: 1px solid transparent;
border-style: none;
border-radius: .5rem;
&:focus {
border: 1px solid var(--primary-button-focused-border);
box-shadow: 0 0 0 3px var(--primary-button-outline);
}
}
</style>
@@ -1,121 +0,0 @@
<!--
// Copyright © 2020 Anticrm Platform Contributors.
//
// 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 { createEventDispatcher } from 'svelte'
import { Label, IconClose, Button, EditBox } from '@anticrm/ui'
import PinPad from './PinPad.svelte'
export let checkState: boolean = false
const dispatch = createEventDispatcher()
const digitsCount: number = 6
const changeState = (): void => {
if (checkState) {
} else {
}
checkState = !checkState
}
const checkInput = (result: CustomEvent) => {
if (result) console.log('Telegram pin code filled', result.detail)
}
</script>
<div class="plugin-popup">
<div class="popup-bg" />
<div class="flex-between header">
<div class="overflow-label fs-title"><Label label={'Connect your Telegram account'} /></div>
<div class="tool" on:click={() => { dispatch('close') }}>
<IconClose size={'small'}/>
</div>
</div>
<div class="content" class:more={!checkState}>
{#if checkState}
<p>Enter the {digitsCount}-digit code you received on your Telegram account.</p>
<PinPad length={digitsCount} on:filled={checkInput} />
{:else}
<p>Enter your Telegram username or phone number to connect your account.</p>
<EditBox label={'Username or phone number'} placeholder={'@johnappleseed'} />
{/if}
</div>
<div class="footer">
<Button label={checkState ? 'Connect' : 'Next'} primary on:click={changeState} />
{#if checkState}
<a class="link" href={'#'} on:click={changeState}>Back</a>
{/if}
</div>
</div>
<style lang="scss">
.plugin-popup {
position: relative;
display: flex;
flex-direction: column;
width: 20rem;
min-width: 20rem;
max-width: 20rem;
border-radius: 1.25rem;
.header {
flex-shrink: 0;
margin: 1.75rem 1.75rem 1.25rem;
.tool {
cursor: pointer;
&:hover { color: var(--theme-caption-color); }
&:active { color: var(--theme-content-accent-color); }
}
}
.content {
flex-shrink: 0;
flex-grow: 1;
margin: 0 1.75rem .5rem;
height: fit-content;
p { margin: 0 0 1rem; }
&.more { margin-bottom: 1rem; }
}
.footer {
display: flex;
flex-direction: row-reverse;
justify-content: space-between;
align-items: center;
padding: 1rem 1.75rem 1.75rem;
.link {
color: var(--theme-content-dark-color);
&:hover { color: var(--theme-caption-color); }
&:active { color: var(--theme-content-accent-color); }
}
}
.popup-bg {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: var(--theme-card-bg);
border-radius: 1.25rem;
backdrop-filter: blur(15px);
box-shadow: var(--theme-card-shadow);
z-index: -1;
}
}
</style>
@@ -22,14 +22,14 @@
import type { Ref, Space, Client } from '@anticrm/core'
import type { Application, NavigatorModel, ViewConfiguration } from '@anticrm/workbench'
import { setClient, Avatar, MessageBox } from '@anticrm/presentation'
import { setClient, Avatar } from '@anticrm/presentation'
import workbench from '@anticrm/workbench'
import Navigator from './Navigator.svelte'
import SpaceHeader from './SpaceHeader.svelte'
import SpaceView from './SpaceView.svelte'
import { AnyComponent, location, Popup, showPopup, TooltipInstance } from '@anticrm/ui'
import { AnyComponent, Component, location, Popup, showPopup, TooltipInstance } from '@anticrm/ui'
import core from '@anticrm/core'
import AccountPopup from './AccountPopup.svelte'
@@ -39,25 +39,35 @@
let currentApp: Ref<Application> | undefined
let currentSpace: Ref<Space> | undefined
let specialComponent: AnyComponent | undefined
let currentView: ViewConfiguration | undefined
let createItemDialog: AnyComponent | undefined
let navigatorModel: NavigatorModel | undefined
onDestroy(location.subscribe(async (loc) => {
currentApp = loc.path[1] as Ref<Application>
currentSpace = loc.path[2] as Ref<Space>
const space = (await client.findAll(core.class.Space, { _id: currentSpace }))[0]
if (space) {
const spaceClass = client.getHierarchy().getClass(space._class) // (await client.findAll(core.class.Class, { _id: space._class }))[0]
const view = client.getHierarchy().as(spaceClass, workbench.mixin.SpaceView)
currentView = view.view
createItemDialog = currentView.createItemDialog
} else {
currentView = undefined
createItemDialog = undefined
}
navigatorModel = (await client.findAll(workbench.class.Application, { _id: currentApp }))[0]?.navigatorModel
let currentFolder = loc.path[2] as Ref<Space>
specialComponent = getSpecialComponent(currentFolder)
if (!specialComponent) {
currentSpace = currentFolder
const space = (await client.findAll(core.class.Space, { _id: currentSpace }))[0]
if (space) {
const spaceClass = client.getHierarchy().getClass(space._class) // (await client.findAll(core.class.Class, { _id: space._class }))[0]
const view = client.getHierarchy().as(spaceClass, workbench.mixin.SpaceView)
currentView = view.view
createItemDialog = currentView.createItemDialog
} else {
currentView = undefined
createItemDialog = undefined
}
}
}))
function getSpecialComponent (id: string): AnyComponent | undefined {
let special = navigatorModel?.specials?.find((x) => x.id === id)
return special?.component
}
</script>
{#if client}
@@ -82,13 +92,17 @@
{#if navigator}
<div class="panel-navigator">
<NavHeader label={'Chat'} action={() => {}} />
<Navigator model={navigatorModel}/>
<Navigator model={navigatorModel} />
</div>
{/if}
<div class="panel-component">
<SpaceHeader space={currentSpace} {createItemDialog} />
{#if currentView && currentSpace}
<SpaceView space={currentSpace} _class={currentView.class} options={currentView.options} />
{#if specialComponent}
<Component is={specialComponent} />
{:else}
<SpaceHeader space={currentSpace} {createItemDialog} />
{#if currentView && currentSpace}
<SpaceView space={currentSpace} _class={currentView.class} options={currentView.options} />
{/if}
{/if}
</div>
<!-- <div class="aside"><Chat thread/></div> -->
@@ -0,0 +1,98 @@
<!--
// Copyright © 2021 Anticrm Platform Contributors.
//
// 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 type { Asset, IntlString } from '@anticrm/platform'
import type { Action } from '@anticrm/ui'
import { ActionIcon, Icon, Label } from '@anticrm/ui'
import { createEventDispatcher } from 'svelte'
export let icon: Asset | undefined = undefined
export let label: IntlString | undefined = undefined
export let notifications = 0
export let actions: Action[] = []
const dispatch = createEventDispatcher()
</script>
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
<div
class="flex-row-center container"
on:click|stopPropagation={() => {
dispatch('click')
}}
>
<div class="icon">
{#if icon}
<Icon {icon} size={'small'} />
{/if}
</div>
<span>
{#if label}<Label {label} />{:else}{label}{/if}
</span>
{#each actions as action}
<div class="tool">
<ActionIcon label={action.label} icon={action.icon} size={'small'} action={action.action} />
</div>
{/each}
{#if notifications > 0}
<div class="counter">{notifications}</div>
{/if}
</div>
<style lang="scss">
.container {
margin: 0 16px;
padding-left: 10px;
padding-right: 12px;
min-height: 36px;
font-weight: 500;
color: var(--theme-caption-color);
border-radius: 8px;
user-select: none;
cursor: pointer;
.icon {
margin-right: 18px;
width: 16px;
min-width: 16px;
height: 16px;
border-radius: 4px;
opacity: 0.3;
}
span {
flex-grow: 1;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.tool {
margin-left: 12px;
visibility: hidden;
}
.counter {
margin-left: 12px;
font-weight: 600;
font-size: 12px;
line-height: 100%;
}
&:hover {
background-color: var(--theme-button-bg-enabled);
.tool {
visibility: visible;
}
}
}
</style>