Skip to content

Commit b125d58

Browse files
IgorPolyakovsea5kg
authored andcommitted
add web page for users
1 parent 2134e88 commit b125d58

File tree

4 files changed

+124
-11
lines changed

4 files changed

+124
-11
lines changed

html/assets/css/index.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ body,html{
3939
.services-card .card-img-top {
4040
width: 286px;
4141
height: 286px;
42-
}
42+
}
43+
44+
.users-card-avatar {
45+
object-fit: cover;
46+
object-position: top center;
47+
border-radius: 50%;
48+
width: 80px;
49+
height: 80px;
50+
}

html/assets/js/api.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,49 @@ window.ctf01d_tp_api.service_info = function(service_id) {
8989
method: 'GET',
9090
});
9191
}
92+
93+
window.ctf01d_tp_api.users_list = function (user_data) {
94+
return $.ajax({
95+
url: '/api/v1/users',
96+
method: 'GET',
97+
});
98+
}
99+
100+
window.ctf01d_tp_api.user_create = function (user_data) {
101+
return $.ajax({
102+
url: '/api/v1/users',
103+
method: 'POST',
104+
contentType: 'application/json',
105+
data: JSON.stringify(user_data),
106+
});
107+
}
108+
109+
window.ctf01d_tp_api.user_update = function (user_id, user_data) {
110+
return $.ajax({
111+
url: '/api/v1/users/' + user_id,
112+
method: 'PUT',
113+
contentType: 'application/json',
114+
data: JSON.stringify(user_data),
115+
});
116+
}
117+
118+
window.ctf01d_tp_api.user_delete = function (user_id) {
119+
return $.ajax({
120+
url: '/api/v1/users/' + user_id,
121+
method: 'DELETE',
122+
});
123+
}
124+
125+
window.ctf01d_tp_api.user_info = function (user_id) {
126+
return $.ajax({
127+
url: '/api/v1/users/' + user_id,
128+
method: 'GET',
129+
});
130+
}
131+
132+
window.ctf01d_tp_api.user_profile = function (user_id) {
133+
return $.ajax({
134+
url: '/api/v1/users/' + user_id + '/profile',
135+
method: 'GET',
136+
});
137+
}

html/assets/js/index.js

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ function isServicesPage(pathname) {
2828
return pathname == "/services" || pathname == "/services/";
2929
}
3030

31-
function isTeamPage(pathname) {
31+
function isTeamsPage(pathname) {
3232
return pathname == "/teams" || pathname == "/teams/";
3333
}
3434

35+
function isUsersPage(pathname) {
36+
return pathname == "/users" || pathname == "/users/";
37+
}
38+
3539
function getHumanTimeHasPassed(dt_end) {
3640
var dt = dt_end.getTime();
3741
var dt_now = new Date().getTime();
@@ -128,14 +132,14 @@ function showLoginForm() {
128132
$('#signin_password').unbind();
129133
$('#signin_password').keypress(function (e) {
130134
if (e.which == 13) {
131-
doSignin();
135+
doSignIn();
132136
return false; // <---- Add this line
133137
}
134138
});
135139
$('#modal_signin').modal('show');
136140
}
137141

138-
function doSignin() {
142+
function doSignIn() {
139143
var username = $('#signin_username').val();
140144
var password = $('#signin_password').val();
141145
$('#sign_error_info').html('')
@@ -355,6 +359,43 @@ function renderServicesPage() {
355359
})
356360
}
357361

362+
function renderUsersPage() {
363+
$('.spa-web-page').css({ "display": "" })
364+
$('#users_page').css({ "display": "block" })
365+
$('#users_page_error').css({ "display": "none" });
366+
$('#users_page_error').html("");
367+
if (window.location.pathname != "/users/") {
368+
window.location.href = "/users/";
369+
}
370+
window.ctf01d_tp_api.users_list().fail(function (res) {
371+
$('#users_page_error').css({
372+
"display": "block"
373+
});
374+
$('#users_page_error').html("Error loading users");
375+
console.error("users_list", res);
376+
}).done(function (res) {
377+
var usersHtml = ""
378+
for (var i in res) {
379+
var user_info = res[i];
380+
console.log("user_info", user_info);
381+
usersHtml += '<div class="card services-card" style="width: 20rem;">';
382+
usersHtml += ' <img class="users-card-avatar" src="' + user_info.avatar_url + '" alt="Image of user">';
383+
usersHtml += ' <div class="card-body">';
384+
usersHtml += ' <h5 class="card-title">@' + user_info.user_name + ' - ' + escapeHtml(user_info.display_name) + '</h5>';
385+
usersHtml += ' <p class="card-text"> ' + escapeHtml(user_info.id) + '</p>';
386+
usersHtml += ' <p class="card-subtitle mb-2 text-muted"> role ' + escapeHtml(user_info.role) + '</p>';
387+
usersHtml += ' <p class="card-text"> state ' + escapeHtml(user_info.status) + '</p>';
388+
usersHtml += ' </div>';
389+
usersHtml += ' <div class="card-body">';
390+
usersHtml += ' <button class="btn btn-secondary" onclick="showProfileUser(\'' + user_info.id + '\');">Profile</button>';
391+
usersHtml += ' <button class="btn btn-primary" onclick="showUpdateUser(\'' + user_info.id + '\');">Update</button>';
392+
usersHtml += ' <button class="btn btn-danger" onclick="deleteUser(\'' + user_info.id + '\');">Delete</button>';
393+
usersHtml += ' </div>';
394+
usersHtml += '</div>';
395+
}
396+
$('#users_page_list').html(usersHtml);
397+
})
398+
}
358399

359400
function renderPage(pathname) {
360401
console.log("pathname", pathname)
@@ -367,7 +408,9 @@ function renderPage(pathname) {
367408
renderGamesPage();
368409
} else if (isServicesPage(pathname)) {
369410
renderServicesPage();
370-
} else if (isTeamPage(pathname)) {
411+
} else if (isUsersPage(pathname)) {
412+
renderUsersPage();
413+
} else if (isTeamsPage(pathname)) {
371414
$('#teams_page').css({"display": "block"})
372415
$('.spa-web-page').css({
373416
"display": ""
@@ -387,12 +430,12 @@ $(document).ready(function () {
387430

388431
window.ctf01d_tp_api.auth_session().fail(function(res) {
389432
console.error(res);
390-
$('#btn_signin').css({"display": "inline-block"});
391-
$('#btn_signout').css({"display": "none"});
433+
$('#btn_sign_in').css({"display": "inline-block"});
434+
$('#btn_sign_out').css({"display": "none"});
392435
$('#btn_profile').css({"display": "none"});
393436
}).done(function(res) {
394-
$('#btn_signin').css({"display": "none"});
395-
$('#btn_signout').css({"display": "inline-block"});
437+
$('#btn_sign_in').css({"display": "none"});
438+
$('#btn_sign_out').css({"display": "inline-block"});
396439
$('#btn_profile').css({"display": "inline-block"});
397440
$('#btn_profile').html(res.name + " (" + res.role + ")");
398441
})

html/index.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
</li>
4242
</ul>
4343
<div class="form-inline my-2 my-lg-0">
44-
<button id="btn_signin" class="btn-menu-top-left btn btn-outline-success my-2 my-sm-0" style="display: none" onclick="showLoginForm()">Sign-in</button>
44+
<button id="btn_sign_in" class="btn-menu-top-left btn btn-outline-success my-2 my-sm-0" style="display: none" onclick="showLoginForm()">Sign-in</button>
4545
<div class="nav-item dropdown">
4646
<a class="nav-link dropdown-toggle" href="#" id="btn_profile" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
4747
User
@@ -50,7 +50,7 @@
5050
<div class="dropdown-item" id="btn_my_teams" onclick="showMyTeams()">My Team(s)</div>
5151
<div class="dropdown-item" id="btn_my_services" onclick="showMyServices()">My Service(s)</div>
5252
<div class="dropdown-divider"></div>
53-
<div class="dropdown-item" id="btn_signout" onclick="doSignOut()">Sign-out</div>
53+
<div class="dropdown-item" id="btn_sign_out" onclick="doSignOut()">Sign-out</div>
5454
</div>
5555
</div>
5656
</div>
@@ -230,6 +230,22 @@ <h5 class="modal-title" id="title_service_create_or_update">New Service</h5>
230230
<br>
231231
</div>
232232

233+
<!-- USERS PAGE -->
234+
<div class="container spa-web-page" id="users_page">
235+
<br>
236+
<h2>Users</h2>
237+
<button type="button" class="btn btn-primary" onclick="showCreateUser()">
238+
New User
239+
</button>
240+
<br><br>
241+
<div class="alert alert-danger" role="alert" style="display: none;" id="services_page_error">
242+
Something wrong
243+
</div>
244+
<div id="users_page_list">
245+
</div>
246+
<br>
247+
</div>
248+
233249
<!-- UNKNOWN PAGE -->
234250
<div class="container spa-web-page" id="unknown_page">
235251
<br>

0 commit comments

Comments
 (0)