Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
leximpact-socio-fiscal-ui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
leximpact
Simulateur socio-fiscal
leximpact-socio-fiscal-ui
Commits
b34ca02c
Commit
b34ca02c
authored
Jun 30, 2021
by
Emmanuel Raviart
Browse files
Options
Downloads
Patches
Plain Diff
Situation Edit: Handle drag & drop of persons in roles.
parent
e6d11f2a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib/components/situations/RolePersonsEdit.svelte
+68
-0
68 additions, 0 deletions
src/lib/components/situations/RolePersonsEdit.svelte
with
68 additions
and
0 deletions
src/lib/components/situations/RolePersonsEdit.svelte
0 → 100644
+
68
−
0
View file @
b34ca02c
<script
lang=
"ts"
>
import
{
createEventDispatcher
}
from
"
svelte
"
import
{
flip
}
from
"
svelte/animate
"
import
{
dndzone
}
from
"
svelte-dnd-action
"
export
let
idPrefix
:
string
export
let
names
:
string
[]
|
undefined
|
null
export
let
type
:
string
const
dispatch
=
createEventDispatcher
()
const
existingItemByName
=
{}
let
existingItems
=
[]
let
existingNames
=
[]
const
flipDurationMs
=
300
$
:
items
=
computeItems
(
names
)
/// Create items from names, but try to reuse existing items when possible.
/// Otherwise, svelte-dnd-action fails.
function
computeItems
(
names
:
string
[]
|
undefined
|
null
)
{
if
(
names
==
null
)
{
return
[]
}
if
(
names
.
length
===
existingNames
.
length
&&
names
.
every
((
name
,
index
)
=>
name
===
existingNames
[
index
])
)
{
return
existingItems
}
const
items
=
names
.
map
((
name
)
=>
{
let
item
=
existingItemByName
[
name
]
if
(
item
===
undefined
)
{
item
=
existingItemByName
[
name
]
=
{
id
:
`
${
idPrefix
}
.
${
name
}
`
,
name
}
}
return
item
})
existingNames
=
names
existingItems
=
items
return
items
}
function
handleDndConsider
({
detail
}:
CustomEvent
<
DndEvent
>
)
{
existingItems
=
detail
.
items
existingNames
=
detail
.
items
.
map
((
item
)
=>
item
.
name
)
dispatch
(
"
change
"
,
existingNames
)
}
function
handleDndFinalize
({
detail
}:
CustomEvent
<
DndEvent
>
)
{
existingItems
=
detail
.
items
existingNames
=
detail
.
items
.
map
((
item
)
=>
item
.
name
)
dispatch
(
"
change
"
,
existingNames
)
}
</script>
<ul
on:consider=
{
handleDndConsider
}
on:finalize=
{
handleDndFinalize
}
style=
"min-height: 0.5rem;"
use:dndzone=
{
{
flipDurationMs
,
items
,
type
,
}
}
>
{
#each
items
as
{
id
,
name
}
(
id
)
}
<li
animate:flip=
{
{
duration
:
flipDurationMs
}}
class
=
"
ml-4
"
>
{
name
}
<
/li
>
{
/each}
<
/ul
>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment