Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DP_projet
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
Model registry
Operate
Environments
Terraform modules
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VILLAUME Lucas
DP_projet
Commits
da7689cc
Commit
da7689cc
authored
1 year ago
by
VILLAUME Lucas
Browse files
Options
Downloads
Patches
Plain Diff
Interface web administrer la DB
parent
d29e91b8
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
app.js
+19
-5
19 additions, 5 deletions
app.js
server.js
+1
-4
1 addition, 4 deletions
server.js
views/db/admin.ejs
+15
-0
15 additions, 0 deletions
views/db/admin.ejs
views/db/collection.ejs
+26
-0
26 additions, 0 deletions
views/db/collection.ejs
with
61 additions
and
9 deletions
app.js
+
19
−
5
View file @
da7689cc
const
path
=
require
(
'
path
'
);
const
express
=
require
(
'
express
'
);
const
app
=
express
();
module
.
exports
=
app
;
const
db
=
require
(
'
./db/Database.js
'
);
//Configuration
const
viewsPath
=
path
.
join
(
__dirname
,
'
views
'
);
app
.
set
(
"
views
"
,
viewsPath
)
app
.
set
(
"
views
"
,
viewsPath
)
;
app
.
set
(
"
view engine
"
,
"
ejs
"
);
//chemin d'accès
app
.
get
(
"
/
"
,
defaut
).
get
(
"
/accueil
"
,
defaut
);
app
.
all
(
"
*
"
,
(
req
,
res
)
=>
res
.
status
(
404
).
send
(
"
<h1>Il semblerait que cette page n'existe pas.</h1>
"
))
app
.
get
(
"
/db/:collection
"
,
collection
).
get
(
"
/db
"
,
dbAdmin
);
app
.
all
(
"
*
"
,
(
req
,
res
)
=>
res
.
status
(
404
).
send
(
"
<h1>Il semblerait que cette page n'existe pas.</h1>
"
));
function
defaut
(
req
,
res
){
const
ind
=
{
method
:
req
.
method
,
url
:
req
.
url
}
res
.
render
(
"
index
"
,
ind
);
}
\ No newline at end of file
}
async
function
collection
(
req
,
res
){
const
nomCollection
=
req
.
params
.
collection
;
const
data
=
await
db
.
find
(
nomCollection
,
{});
res
.
render
(
"
db/collection
"
,
{
nomCollection
,
data
});
}
async
function
dbAdmin
(
req
,
res
){
const
collections
=
await
db
.
listCollections
();
res
.
render
(
"
db/admin
"
,
{
collections
});
}
module
.
exports
=
app
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
server.js
+
1
−
4
View file @
da7689cc
const
http
=
require
(
'
http
'
);
const
app
=
require
(
'
./app.js
'
);
const
Database
=
require
(
'
./db/Database.js
'
);
db
=
new
Database
(
"
mongodb://127.0.0.1:27017/test?retryWrites=true&w=majority
"
);
db
.
connect
();
const
db
=
require
(
'
./db/Database.js
'
);
const
serv
=
http
.
createServer
(
app
);
serv
.
listen
(
3500
,
()
=>
console
.
log
(
"
Serveur lancé !
"
));
\ No newline at end of file
This diff is collapsed.
Click to expand it.
views/db/admin.ejs
0 → 100644
+
15
−
0
View file @
da7689cc
<!DOCTYPE html>
<html
lang=
"fr"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
Admin DB
</title>
</head>
<body>
<h1>
Admin DB
</h1>
<h2>
Les collections
</h2>
<ul>
<
%
for
(
let
i=
0;
i
<
collections.length
;
i
++){
%
>
<li><a
href=
"/db/<%= collections[i].collectionName %>"
><
%=
collections
[
i
].
collectionName
%
></a></li>
<
%
}
%
>
</ul>
</html>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
views/db/collection.ejs
0 → 100644
+
26
−
0
View file @
da7689cc
<!DOCTYPE html>
<html
lang=
"fr"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
Collection
<
%=
nomCollection
%
></title>
</head>
<body>
<h1>
Collection
<
%=
nomCollection
%
></h1>
<table>
<tr>
<
%
if
(
data.length
>
0) { %>
<
%
Object.keys(data[0]).forEach(key =
>
{
%
>
<th><
%=
key
%
></th>
<
%
})
%
>
<
%
}
%
>
</tr>
<
%
data.forEach(item =
>
{
%
>
<tr>
<
%
for
(
let
val
of
Object.values
(
item
)){
%
>
<td><
%=
val
%
></td>
<
%}%
>
</tr>
<
%
})
%
>
</table>
</body>
</html>
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