Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ELC_elections
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gestion-des-assemblees
ELC_elections
Commits
dd90604f
Commit
dd90604f
authored
4 years ago
by
Alexis POYEN
Browse files
Options
Downloads
Patches
Plain Diff
Resolve "Party : Delete in cascade CandidateList"
parent
a49cfa61
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
internal/models/party.go
+4
-0
4 additions, 0 deletions
internal/models/party.go
internal/rootmux/rootmux_test.go
+5
-2
5 additions, 2 deletions
internal/rootmux/rootmux_test.go
web/components/management/party.js
+84
-7
84 additions, 7 deletions
web/components/management/party.js
with
93 additions
and
9 deletions
internal/models/party.go
+
4
−
0
View file @
dd90604f
...
...
@@ -108,6 +108,10 @@ func (d *DataHandler) deleteParty(w http.ResponseWriter, r *http.Request, id int
return
}
for
_
,
candidateList
:=
range
o
.
CandidateLists
{
d
.
deleteCandidateList
(
w
,
r
,
int
(
candidateList
.
ID
))
}
d
.
db
.
Delete
(
&
o
)
}
else
{
http
.
Error
(
w
,
ErrorIDIsMissing
,
http
.
StatusNotFound
)
...
...
This diff is collapsed.
Click to expand it.
internal/rootmux/rootmux_test.go
+
5
−
2
View file @
dd90604f
...
...
@@ -157,9 +157,12 @@ func deletionInCascadePartyTest(t *testing.T) {
response
:=
do
(
"GET"
,
"/api/common/WhoAmI"
,
noH
,
""
,
200
,
""
)
token
:=
auth
.
TokenData
{}
json
.
Unmarshal
([]
byte
(
response
),
&
token
)
//
xsrfHeader := tester.Header{Key: "XSRF-TOKEN", Value: token.XSRFToken}
xsrfHeader
:=
tester
.
Header
{
Key
:
"XSRF-TOKEN"
,
Value
:
token
.
XSRFToken
}
// TODO check that Candidate and candidateLists are deleted in cascade on Party deletion.
// Check that Candidate and candidateLists are deleted in cascade on Party deletion.
do
(
"DELETE"
,
"/api/Party/1"
,
xsrfHeader
,
``
,
200
,
``
)
do
(
"GET"
,
"/api/CandidateList/1"
,
xsrfHeader
,
``
,
404
,
`id is missing`
)
do
(
"GET"
,
"/api/Candidate/1"
,
xsrfHeader
,
``
,
404
,
`id is missing`
)
}
// Do an OAuth2 login with an known admin
...
...
This diff is collapsed.
Click to expand it.
web/components/management/party.js
+
84
−
7
View file @
dd90604f
...
...
@@ -2,7 +2,10 @@
import
*
as
Auth
from
"
/services/auth/auth.js
"
;
import
*
as
Common
from
"
/services/common/common.js
"
;
import
*
as
PartyModel
from
"
/services/model/party-model.js
"
;
import
{
Delete
}
from
"
/services/common/delete.js
"
;
import
*
as
CandidateListModel
from
"
/services/model/candidateList-model.js
"
;
import
*
as
ElectionModel
from
"
/services/model/election-model.js
"
;
import
*
as
RoundModel
from
"
/services/model/round-model.js
"
;
import
{
AnimateCSS
}
from
"
/services/common/common.js
"
;
// DOM elements
export
async
function
mount
(
where
)
{
...
...
@@ -13,10 +16,16 @@ export async function mount(where) {
class
Party
{
constructor
()
{
this
.
PartyModel
=
PartyModel
.
getPartyModel
();
this
.
CandidateListModel
=
CandidateListModel
.
getCandidateListModel
();
this
.
ElectionModel
=
ElectionModel
.
getElectionModel
();
this
.
RoundModel
=
RoundModel
.
getRoundModel
();
}
async
mount
(
where
)
{
this
.
PartyModel
.
current_user
=
await
Auth
.
GetUser
();
this
.
CandidateListModel
.
current_user
=
await
Auth
.
GetUser
();
this
.
ElectionModel
.
current_user
=
await
Auth
.
GetUser
();
this
.
RoundModel
.
current_user
=
await
Auth
.
GetUser
();
const
mountpoint
=
where
;
document
.
getElementById
(
mountpoint
).
innerHTML
=
/* HTML */
` <div
class="container"
...
...
@@ -115,7 +124,8 @@ class Party {
<div class="content">
<nav class="level">
<div class="level-left" style="color:
${
party
.
Color
}
">
${
party
.
Name
}
  <p style="background-color:
${
party
.
Color
}
">Couleur</p>
${
party
.
Name
}
  
<p style="background-color:
${
party
.
Color
}
">Couleur</p>
</div>
<div class="level-right">
<a
...
...
@@ -157,9 +167,77 @@ class Party {
});
document
.
getElementById
(
`parties-party-delete-
${
party
.
ID
}
`
)
.
addEventListener
(
"
click
"
,
function
()
{
new
Delete
(()
=>
{
partyHandler
.
deleteParty
(
party
);
.
addEventListener
(
"
click
"
,
async
function
()
{
let
deleteModal
=
document
.
createElement
(
"
div
"
);
deleteModal
.
classList
.
add
(
"
modal
"
,
"
animated
"
,
"
fadeIn
"
,
"
faster
"
,
"
is-active
"
);
deleteModal
.
innerHTML
=
/* HTML */
`
<div class="modal-background"></div>
<div class="modal-content">
<div class="box" style="margin: 2rem;">
<div class="content">
<label class="label"
>Les listes suivantes seront supprimées :</label
>
<ul id="candidate-lists-list"></ul>
</div>
<div class="field is-grouped">
<div class="control">
<button id="delete-ok" class="button is-danger">
<span class="icon"><i class="fas fa-check"></i></span
><span>Supprimer</span>
</button>
</div>
<div class="control">
<button id="delete-cancel" class="button">
<span class="icon"
><i class="fas fa-times-circle"></i></span
><span>Annuler</span>
</button>
</div>
</div>
</div>
</div>
`
;
deleteModal
.
querySelector
(
"
#
"
+
"
delete-ok
"
)
.
addEventListener
(
"
click
"
,
async
()
=>
{
await
partyHandler
.
deleteParty
(
party
);
AnimateCSS
(
deleteModal
,
"
fadeOut
"
,
function
()
{
deleteModal
.
parentNode
.
removeChild
(
deleteModal
);
});
});
deleteModal
.
querySelector
(
"
#
"
+
"
delete-cancel
"
)
.
addEventListener
(
"
click
"
,
()
=>
{
AnimateCSS
(
deleteModal
,
"
fadeOut
"
,
function
()
{
deleteModal
.
parentNode
.
removeChild
(
deleteModal
);
});
});
document
.
body
.
appendChild
(
deleteModal
);
partyHandler
.
party
=
party
;
let
candidateLists
=
await
partyHandler
.
CandidateListModel
.
getCandidateLists
();
candidateLists
.
filter
(
function
(
candidateList
)
{
return
candidateList
.
PartyID
==
partyHandler
.
party
.
ID
;
});
candidateLists
.
forEach
(
async
(
candidateList
)
=>
{
let
round
=
await
partyHandler
.
RoundModel
.
getRound
(
candidateList
.
RoundID
);
let
election
=
await
partyHandler
.
ElectionModel
.
getElection
(
round
.
ElectionID
);
let
el
=
document
.
createElement
(
"
li
"
);
el
.
innerHTML
=
candidateList
.
Name
+
"
(
"
+
election
.
Name
+
"
"
+
new
Date
(
round
.
Date
).
toLocaleDateString
()
+
"
)
"
;
document
.
getElementById
(
"
candidate-lists-list
"
).
appendChild
(
el
);
});
});
});
...
...
@@ -177,8 +255,7 @@ class Party {
this
.
method
=
"
PUT
"
;
document
.
getElementById
(
"
party-modal-id
"
).
value
=
party
.
ID
;
document
.
getElementById
(
"
party-modal-name
"
).
value
=
party
.
Name
;
document
.
getElementById
(
"
party-modal-color
"
).
value
=
party
.
Color
;
document
.
getElementById
(
"
party-modal-color
"
).
value
=
party
.
Color
;
Common
.
toggleModal
(
"
party-modal
"
,
"
party-modal-card
"
);
}
...
...
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