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
Merge requests
!30
Resolve "Handle CandidateList"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Handle CandidateList"
29-handle-candidatelist
into
master
Overview
0
Commits
8
Pipelines
1
Changes
1
Merged
Alexis POYEN
requested to merge
29-handle-candidatelist
into
master
4 years ago
Overview
0
Commits
8
Pipelines
1
Changes
1
Expand
Closes
#29 (closed)
0
0
Merge request reports
Viewing commit
89969a7c
Prev
Next
Show latest version
1 file
+
102
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
89969a7c
Feat : Create CandidateList model
· 89969a7c
Alexis POYEN
authored
4 years ago
web/services/model/candidateList-model.js
0 → 100644
+
102
−
0
Options
import
*
as
Messages
from
"
/services/messages/messages.js
"
;
let
candidateListModel
;
export
function
getCandidateListModel
()
{
if
(
candidateListModel
==
null
)
{
candidateListModel
=
new
CandidateListModel
();
}
return
candidateListModel
;
}
class
CandidateListModel
{
constructor
()
{}
async
getCandidateList
(
id
)
{
if
(
this
.
candidateLists
==
null
)
await
this
.
refreshCandidateLists
();
let
candidateListToGet
;
this
.
candidateLists
.
forEach
((
candidateList
)
=>
{
if
(
candidateList
.
ID
==
id
)
candidateListToGet
=
candidateList
;
});
return
candidateListToGet
;
}
async
getCandidateLists
()
{
if
(
this
.
candidateLists
==
null
)
{
try
{
const
response
=
await
fetch
(
"
/api/CandidateList/
"
,
{
method
:
"
GET
"
,
headers
:
new
Headers
({
"
XSRF-Token
"
:
this
.
current_user
.
xsrftoken
,
}),
});
if
(
response
.
status
!==
200
)
{
throw
new
Error
(
`CandidateLists could not be fetched (status
${
response
.
status
}
)`
);
}
this
.
candidateLists
=
await
response
.
json
();
}
catch
(
e
)
{
Messages
.
Show
(
"
is-warning
"
,
e
.
message
);
console
.
error
(
e
);
}
}
return
this
.
candidateLists
;
}
async
saveCandidateList
(
method
,
ID
,
Name
,
PartyID
,
RoundID
,
AreaID
)
{
try
{
const
response
=
await
fetch
(
"
/api/CandidateList/
"
+
ID
,
{
method
:
method
,
headers
:
new
Headers
({
"
XSRF-Token
"
:
this
.
current_user
.
xsrftoken
,
}),
body
:
JSON
.
stringify
({
ID
:
ID
,
Name
:
Name
,
PartyID
:
PartyID
,
RoundID
:
RoundID
,
AreaID
:
AreaID
}),
}
);
if
(
response
.
status
!==
200
)
{
throw
new
Error
(
`CandidateList could not be updated or created (status
${
response
.
status
}
)`
);
}
this
.
refreshCandidateLists
();
return
await
response
.
json
();
}
catch
(
e
)
{
Messages
.
Show
(
"
is-warning
"
,
e
.
message
);
console
.
error
(
e
);
return
;
}
}
async
deleteCandidateList
(
ID
)
{
try
{
const
response
=
await
fetch
(
"
/api/CandidateList/
"
+
ID
,
{
method
:
"
delete
"
,
headers
:
new
Headers
({
"
XSRF-Token
"
:
this
.
current_user
.
xsrftoken
,
}),
});
if
(
response
.
status
!==
200
)
{
throw
new
Error
(
`CandidateList could not be deleted (status
${
response
.
status
}
)`
);
}
}
catch
(
e
)
{
Messages
.
Show
(
"
is-warning
"
,
e
.
message
);
console
.
error
(
e
);
}
}
async
refreshCandidateLists
()
{
this
.
candidateLists
=
null
;
await
this
.
getCandidateLists
();
}
}
Loading