Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Package registry
Container registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
videoag
frontend
Commits
9c1ab43d
Verified
Commit
9c1ab43d
authored
11 months ago
by
Dorian Koch
Browse files
Options
Downloads
Patches
Plain Diff
Lock buttons when something is happening in lecture import, Closes
#8
parent
a547fd5e
No related branches found
No related tags found
No related merge requests found
Pipeline
#6357
passed
11 months ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/misc/Calendar.tsx
+3
-1
3 additions, 1 deletion
src/misc/Calendar.tsx
src/pages/internal/import.tsx
+80
-18
80 additions, 18 deletions
src/pages/internal/import.tsx
with
83 additions
and
19 deletions
src/misc/Calendar.tsx
+
3
−
1
View file @
9c1ab43d
...
...
@@ -7,7 +7,9 @@ export interface ICalEvent {
duration
?:
number
;
location
?:
string
;
description
?:
string
;
foreign_id
?:
number
;
id_in_videoag_system
?:
number
;
id_in_foreign_system
?:
number
;
locally_unique_id
:
string
;
}
export
function
parseICal
(
fileContent
:
string
):
ICalEvent
[]
{
...
...
This diff is collapsed.
Click to expand it.
src/pages/internal/import.tsx
+
80
−
18
View file @
9c1ab43d
...
...
@@ -19,18 +19,20 @@ function TerminBody({
})
{
const
api
=
useBackendContext
();
const
reloadFunc
=
useReloadBoundary
();
const
[
lockedIds
,
setLockedIds
]
=
useState
<
string
[]
|
undefined
>
([]);
// undefined has the special meaning that everything is locked
const
existingEvents
:
ICalEvent
[]
=
(
course
.
lectures
??
[]).
map
((
l
)
=>
{
const
obj
:
ICalEvent
=
{
location
:
l
.
location
,
duration
:
l
.
duration
,
startDate
:
DateTime
.
fromISO
(
l
.
time
),
foreign_id
:
l
.
id
,
id_in_videoag_system
:
l
.
id
,
locally_unique_id
:
"
videoag_
"
+
l
.
id
,
};
return
obj
;
});
const
event
Equals
=
(
a
:
ICalEvent
,
b
:
ICalEvent
)
=>
{
const
event
sSimilar
=
(
a
:
ICalEvent
,
b
:
ICalEvent
)
=>
{
return
(
a
.
location
===
b
.
location
&&
a
.
duration
===
b
.
duration
&&
...
...
@@ -39,12 +41,12 @@ function TerminBody({
};
const
removeDuplicates
=
(
event
:
ICalEvent
,
index
:
number
,
self
:
ICalEvent
[])
=>
{
return
index
===
self
.
findIndex
((
e
)
=>
event
Equals
(
e
,
event
));
return
index
===
self
.
findIndex
((
e
)
=>
event
sSimilar
(
e
,
event
));
};
const
notContainedIn
=
(
other
:
ICalEvent
[])
=>
{
return
(
event
:
ICalEvent
)
=>
{
return
!
other
.
some
((
oth
)
=>
{
return
event
Equals
(
event
,
oth
);
return
event
sSimilar
(
event
,
oth
);
});
};
};
...
...
@@ -67,6 +69,13 @@ function TerminBody({
.
filter
(
removeDuplicates
).
length
;
const
importEvent
=
(
event
:
ICalEvent
)
=>
{
setLockedIds
((
old
)
=>
{
if
(
old
===
undefined
)
{
return
old
;
}
else
{
return
old
.
concat
(
event
.
locally_unique_id
);
}
});
api
.
getNewOMConfiguration
(
"
lecture
"
)
.
then
((
res
:
GetNewConfigurationResponse
)
=>
{
const
defaultValues
:
any
=
{};
...
...
@@ -97,10 +106,20 @@ function TerminBody({
.
catch
((
e
)
=>
{
showError
(
e
,
"
Unable to create lecture
"
);
})
.
then
(
reloadFunc
);
.
then
(
reloadFunc
)
.
finally
(()
=>
{
setLockedIds
((
old
)
=>
{
if
(
old
===
undefined
)
{
return
old
;
}
else
{
return
old
.
filter
((
id
)
=>
id
!==
event
.
locally_unique_id
);
}
});
});
};
const
importAllEvents
=
()
=>
{
setLockedIds
(
undefined
);
api
.
getNewOMConfiguration
(
"
lecture
"
)
.
then
((
res
:
GetNewConfigurationResponse
)
=>
{
const
defaultValues
:
any
=
{};
...
...
@@ -135,37 +154,59 @@ function TerminBody({
.
catch
((
e
)
=>
{
showError
(
e
,
"
Unable to create lectures
"
);
})
.
then
(
reloadFunc
);
.
then
(
reloadFunc
)
.
finally
(()
=>
{
setLockedIds
([]);
});
};
const
removeEvent
=
(
event
:
ICalEvent
)
=>
{
if
(
!
confirm
(
"
Really delete?
"
))
return
;
if
(
event
.
foreig
n_id
===
undefined
)
{
if
(
event
.
id_i
n_
v
id
eoag_system
===
undefined
)
{
showErrorToast
(
"
Event not found
"
);
return
;
}
api
.
deleteOMObject
(
"
lecture
"
,
event
.
foreign_id
)
setLockedIds
((
old
)
=>
{
if
(
old
===
undefined
)
{
return
old
;
}
else
{
return
old
.
concat
(
event
.
locally_unique_id
);
}
});
api
.
deleteOMObject
(
"
lecture
"
,
event
.
id_in_videoag_system
)
.
catch
((
e
)
=>
{
showError
(
e
,
"
Unable to delete lecture
"
);
})
.
then
(
reloadFunc
);
.
then
(
reloadFunc
)
.
finally
(()
=>
{
setLockedIds
((
old
)
=>
{
if
(
old
===
undefined
)
{
return
old
;
}
else
{
return
old
.
filter
((
id
)
=>
id
!==
event
.
locally_unique_id
);
}
});
});
};
const
removeAllEvents
=
()
=>
{
if
(
!
confirm
(
"
Really delete all?
"
))
return
;
setLockedIds
(
undefined
);
const
promises
=
existingEvents
.
flatMap
((
event
)
=>
{
if
(
event
.
foreig
n_id
===
undefined
)
{
if
(
event
.
id_i
n_
v
id
eoag_system
===
undefined
)
{
return
[];
}
return
[
api
.
deleteOMObject
(
"
lecture
"
,
event
.
foreig
n_id
)];
return
[
api
.
deleteOMObject
(
"
lecture
"
,
event
.
id_i
n_
v
id
eoag_system
)];
});
Promise
.
allSettled
(
promises
)
.
catch
((
e
)
=>
{
showError
(
e
,
"
Unable to delete lectures
"
);
})
.
then
(
reloadFunc
);
.
then
(
reloadFunc
)
.
finally
(()
=>
{
setLockedIds
([]);
});
};
return
(
...
...
@@ -187,11 +228,19 @@ function TerminBody({
</
tbody
>
</
table
>
{
lockedIds
===
undefined
||
lockedIds
.
length
>
0
?
(
<
div
className
=
"spinner-border mb-2"
role
=
"status"
/>
)
:
null
}
<
div
className
=
"card mb-2"
>
<
div
className
=
"card-header d-flex align-items-center"
>
<
span
className
=
"flex-grow-1"
>
Im Import, nicht bei uns
</
span
>
<
button
className
=
"btn btn-primary"
onClick
=
{
importAllEvents
}
>
<
button
className
=
"btn btn-primary"
onClick
=
{
importAllEvents
}
disabled
=
{
lockedIds
===
undefined
||
lockedIds
.
length
>
0
}
>
Alle anlegen
</
button
>
</
div
>
...
...
@@ -219,6 +268,10 @@ function TerminBody({
<
button
className
=
"btn btn-primary"
onClick
=
{
()
=>
importEvent
(
event
)
}
disabled
=
{
lockedIds
===
undefined
||
lockedIds
.
includes
(
event
.
locally_unique_id
)
}
>
Anlegen
</
button
>
...
...
@@ -233,7 +286,11 @@ function TerminBody({
<
div
className
=
"card-header d-flex align-items-center"
>
<
span
className
=
"flex-grow-1"
>
Bei uns, nicht im Import
</
span
>
<
button
className
=
"btn btn-primary"
onClick
=
{
removeAllEvents
}
>
<
button
className
=
"btn btn-primary"
onClick
=
{
removeAllEvents
}
disabled
=
{
lockedIds
===
undefined
||
lockedIds
.
length
>
0
}
>
Alle entfernen
</
button
>
</
div
>
...
...
@@ -261,6 +318,10 @@ function TerminBody({
<
button
className
=
"btn btn-primary"
onClick
=
{
()
=>
removeEvent
(
event
)
}
disabled
=
{
lockedIds
===
undefined
||
lockedIds
.
includes
(
event
.
locally_unique_id
)
}
>
Entfernen
</
button
>
...
...
@@ -350,8 +411,9 @@ function RWTHOnlineImportImpl() {
imported_courses
.
current
.
push
(
courseIdNr
!
);
const
parsed
=
parseICal
(
ical
);
// add id to events
parsed
.
forEach
((
event
)
=>
{
event
.
foreign_id
=
courseIdNr
;
parsed
.
forEach
((
event
,
idx
)
=>
{
event
.
id_in_foreign_system
=
courseIdNr
;
event
.
locally_unique_id
=
"
rwthonline_
"
+
courseIdNr
+
"
_
"
+
idx
;
});
// append
imported_events
.
current
=
imported_events
.
current
.
concat
(
parsed
);
...
...
@@ -369,7 +431,7 @@ function RWTHOnlineImportImpl() {
imported_courses
.
current
=
imported_courses
.
current
.
filter
((
id
)
=>
id
!==
courseId
);
imported_events
.
current
=
imported_events
.
current
.
filter
(
(
event
)
=>
event
.
foreign_
id
!==
courseId
,
(
event
)
=>
event
.
id_in_
foreign_
system
!==
courseId
,
);
doReRender
((
r
)
=>
r
+
1
);
};
...
...
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