Skip to content

Commit 866c917

Browse files
committed
forms
1 parent 2c64d04 commit 866c917

File tree

14 files changed

+387
-56
lines changed

14 files changed

+387
-56
lines changed

.postgres-ci.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ entrypoint:
44
- /sbin/init
55
commands:
66
- go version
7-
- go get -u github.com/FiloSottile/gvt
8-
- gvt restore
9-
- mkdir -p /go/src/github.com/postgres-ci/app-server
10-
- cp -r . /go/src/github.com/postgres-ci/app-server/
7+
- sh test_setup.sh
118
- echo ==== Tests ====
129
tests:
1310
- go test -cover -v github.com/postgres-ci/app-server/src/app/models/webhooks/common

assets/static/js/app.js

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,25 @@ $('#confirmAction').find('.modal-content form').on('submit', function(event) {
3636
return false
3737
});
3838

39-
$('#changePassword').on('hide.bs.modal', function (event) {
39+
$('#changePassword, #userForm, #projectForm').on('hide.bs.modal', function (event) {
4040
$(this).find('.modal-dialog form').trigger("reset");
4141
});
4242

43-
$('#changePassword form').bootstrap3Validate(function(e, data) {
43+
$('#projectForm').on('show.bs.modal', function (event) {
4444

45-
e.preventDefault();
45+
var button = $(event.relatedTarget);
46+
47+
$(this).find('.modal-dialog form').attr('action', button.data('action'));
48+
$(this).find('.modal-content .modal-title').html(button.data('title'));
4649

4750
$.ajax({
48-
method : 'POST',
49-
url : '/password/change/',
50-
data : data,
51+
method : 'GET',
52+
url : button.data('source'),
53+
data : $(this).serialize(),
5154
dataType : 'json',
5255
success : function(data, event) {
53-
location.reload(true);
56+
$('#project_name').val(data.project_name);
57+
$('#repository_url').val(data.repository_url);
5458
},
5559
error: function(request, status, error) {
5660

@@ -66,18 +70,55 @@ $('#changePassword form').bootstrap3Validate(function(e, data) {
6670
alert(error);
6771
}
6872
});
73+
});
6974

70-
return false
75+
$('#resetPasswordForm').on('show.bs.modal', function (event) {
76+
77+
var button = $(event.relatedTarget);
78+
79+
$(this).find('.modal-dialog form').attr('action', button.data('action'));
80+
});
81+
82+
$('#updateUserForm').on('show.bs.modal', function (event) {
83+
84+
var button = $(event.relatedTarget);
85+
86+
$(this).find('.modal-dialog form').attr('action', button.data('action'));
87+
88+
$.ajax({
89+
method : 'GET',
90+
url : button.data('source'),
91+
data : $(this).serialize(),
92+
dataType : 'json',
93+
success : function(data, event) {
94+
$('#user_name').val(data.user_name);
95+
$('#user_email').val(data.user_email);
96+
$('#is_superuser').attr('checked', data.is_superuser);
97+
},
98+
error: function(request, status, error) {
99+
100+
var data = JSON.parse(request.responseText);
101+
102+
if (data.error !== undefined) {
103+
104+
alert(data.error);
105+
106+
return;
107+
}
108+
109+
alert(error);
110+
}
111+
});
71112
});
72113

73-
$('#addProject form').bootstrap3Validate(function(e, data) {
114+
$('#changePassword form, #projectForm form, #addUserForm form, #updateUserForm form, #resetPasswordForm form').bootstrap3Validate(function(e, data) {
74115

75116
e.preventDefault();
76117

77118
$.ajax({
78119
method : 'POST',
79-
url : '/project/add/',
80-
data : data,
120+
url : $(this).attr('action'),
121+
data : $(this).serialize(),
81122
dataType : 'json',
82123
success : function(data, event) {
83124
location.reload(true);
@@ -99,4 +140,3 @@ $('#addProject form').bootstrap3Validate(function(e, data) {
99140

100141
return false
101142
});
102-

assets/templates_src/index.html

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ <h3 class="box-title">Projects</h3>
3939
</td>
4040
{% if CurrentUser.IsSuperuser %}
4141
<td>
42-
43-
44-
<a href="#" data-toggle="modal" data-target="#editProject" data-action="/project/update/{{ item.ProjectID }}/"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>edit</a>
45-
42+
<a href="#"
43+
data-toggle="modal"
44+
data-target="#projectForm"
45+
data-title="Edit project"
46+
data-action="/project/update/{{ item.ProjectID }}/"
47+
data-source="/project/{{ item.ProjectID }}/get/"
48+
><i class="fa fa-pencil-square-o" aria-hidden="true"></i>edit</a>
4649
<a href="#" data-toggle="modal" data-target="#confirmAction" data-action="/project/delete/{{ item.ProjectID }}/"><i class="fa fa-trash" aria-hidden="true"></i>delete</a>
4750
</td>
4851
{% endif %}
@@ -53,33 +56,41 @@ <h3 class="box-title">Projects</h3>
5356
</div>
5457
{% if CurrentUser.IsSuperuser %}
5558
<div class="box-footer">
56-
<button type="submit" data-toggle="modal" data-target="#addProject" class="btn btn-primary">Add project</button>
59+
<button
60+
type="submit"
61+
data-toggle="modal"
62+
data-target="#projectForm"
63+
data-action="/project/add/"
64+
data-title="Add project"
65+
class="btn btn-primary"
66+
>Add project</button>
5767
</div>
5868
{% endif %}
5969
</div>
6070
{% if CurrentUser.IsSuperuser %}
61-
<div class="modal fade" id="addProject" tabindex="-1" role="dialog">
71+
<div class="modal fade" id="projectForm" tabindex="-1" role="dialog">
6272
<div class="modal-dialog" role="document">
63-
<div class="modal-content">
64-
<form method="post">
73+
<form method="post" action="">
74+
<div class="modal-content">
6575
<div class="modal-header">
6676
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
67-
<h4 class="modal-title">Add project</h4>
77+
<h4 class="modal-title">-</h4>
6878
</div>
6979
<div class="modal-body">
7080
<div class="form-group">
7181
<label for="message-text" class="control-label">name:</label>
72-
<input type="text" name="name" class="form-control" data-title="Please enter a project name" required>
82+
<input type="text" name="name" id="project_name" class="form-control" data-title="Please enter a project name" required>
7383
</div>
74-
<div class="form-group">
84+
<input type="hidden" value="{{ CurrentUser.ID }}" name="owner_id">
85+
<!--div class="form-group">
7586
<label for="message-text" class="control-label">owner:</label>
76-
<select class="form-control" style="width: 100%;" id="select_users" name="owner_id">
77-
<option value="1">first</option>
87+
<select class="form-control" id="select_users" name="owner_id">
88+
<option value="{{ CurrentUser.ID }}">{{ CurrentUser.Name }}</option>
7889
</select>
79-
</div>
90+
</div-->
8091
<div class="form-group">
8192
<label for="message-text" class="control-label">repository url</label>
82-
<input type="text" name="repository_url" class="form-control" data-title="Please enter a repository url" required>
93+
<input type="text" name="url" id="repository_url" class="form-control" data-title="Please enter a repository url" required>
8394
</div>
8495
<!--div class="form-group">
8596
<label for="message-text" class="control-label">github secret</label>
@@ -88,10 +99,10 @@ <h4 class="modal-title">Add project</h4>
8899
</div>
89100
<div class="modal-footer">
90101
<button type="button" class="btn btn-default" data-dismiss="modal">close</button>
91-
<button type="submit" class="btn btn-primary">add project</button>
102+
<button type="submit" class="btn btn-primary">submit</button>
92103
</div>
93-
</form>
94-
</div>
104+
</div>
105+
</form>
95106
</div>
96107
</div>
97108
{% endif %} {% endverbatim %} {% endblock %}

assets/templates_src/internal/layout/header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</header>
2424
<div class="modal fade" id="changePassword" tabindex="-1" role="dialog">
2525
<div class="modal-dialog" role="document">
26-
<form method="post" action="">
26+
<form method="post" action="/password/change/">
2727
<div class="modal-content">
2828
<div class="modal-header">
2929
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>

assets/templates_src/users/index.html

Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,36 @@ <h3 class="box-title">Users</h3>
2828
<th width="210px">created at</th>
2929
<th width="210px">updated at</th>
3030
{% if CurrentUser.IsSuperuser %}
31-
<th width="150px">-</th>
31+
<th width="250px">-</th>
3232
{% endif %}
3333
</tr>
3434
{% for user in users %}
3535
<tr>
3636
<td>{{ user.ID }}</td>
37-
<td>{{ user.Name }}</td>
37+
<td>{{ user.Name }} {% if user.IsSuperuser %}(superuser){% endif %}</td>
3838
<td>{{ user.Login }}</td>
3939
<td>{{ user.Email }}</td>
4040
<td>{{ user.CreatedAt | time:"Mon, 02 Jan 2006 15:04:05 -0700" }}</td>
4141
<td>{{ user.UpdatedAt | time:"Mon, 02 Jan 2006 15:04:05 -0700" }}</td>
4242
{% if CurrentUser.IsSuperuser %}
4343
<td>
44-
<a href="#"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>edit</a>
44+
<a href="#"
45+
data-toggle="modal"
46+
data-target="#updateUserForm"
47+
data-action="/users/update/{{ user.ID }}/"
48+
data-source="/users/get/{{ user.ID }}/"
49+
><i class="fa fa-pencil-square-o" aria-hidden="true"></i>edit</a>
50+
51+
{% if user.ID != CurrentUser.ID %}
52+
<a href="#"
53+
data-toggle="modal"
54+
data-target="#resetPasswordForm"
55+
data-action="/password/reset/{{ user.ID }}/"
56+
><i class="fa fa-refresh" aria-hidden="true"></i>reset password</a>
57+
{% endif %}
58+
{% if !user.IsSuperuser %}
4559
<a href="#" data-toggle="modal" data-target="#confirmAction" data-action="/users/delete/{{ user.ID }}/"><i class="fa fa-trash" aria-hidden="true"></i>delete</a>
60+
{% endif %}
4661
</td>
4762
{% endif %}
4863
</tr>
@@ -52,12 +67,16 @@ <h3 class="box-title">Users</h3>
5267
</div>
5368
<div class="box-footer clearfix">
5469
{% if CurrentUser.IsSuperuser %}
55-
<button type="submit" data-toggle="modal" data-target="#addUser" class="btn btn-primary">Add user</button>
70+
<button type="submit"
71+
data-toggle="modal"
72+
data-target="#addUserForm"
73+
class="btn btn-primary">Add user</button>
5674
{% endif %} {% endverbatim %} {% include "../internal/pagination.html" %}
5775
</div>
5876
{% verbatim %} {% if CurrentUser.IsSuperuser %}
59-
<div class="modal fade" id="addUser" tabindex="-1" role="dialog">
77+
<div class="modal fade" id="addUserForm" tabindex="-1" role="dialog">
6078
<div class="modal-dialog" role="document">
79+
<form method="post" action="/users/add/">
6180
<div class="modal-content">
6281
<div class="modal-header">
6382
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
@@ -66,29 +85,95 @@ <h4 class="modal-title">Add user</h4>
6685
<div class="modal-body">
6786
<div class="form-group">
6887
<label for="message-text" class="control-label">user name:</label>
69-
<input type="text" name="user_name" class="form-control">
88+
<input type="text" name="name" class="form-control" data-title="Enter user name" required>
7089
</div>
7190
<div class="form-group">
7291
<label for="message-text" class="control-label">email:</label>
73-
<input type="email" name="email" class="form-control">
92+
<input type="email" name="email" class="form-control" data-title="Enter email" required>
7493
</div>
7594
<div class="form-group">
7695
<label for="message-text" class="control-label">login:</label>
77-
<input type="text" name="login" class="form-control">
96+
<input type="text" name="login" class="form-control" data-title="Enter login" required>
7897
</div>
7998
<div class="form-group">
8099
<label for="message-text" class="control-label">password:</label>
81-
<input type="password" name="password" class="form-control" id="password">
100+
<input type="password" name="password" class="form-control" id="password" data-title="Enter password" required>
82101
</div>
83102
<div class="form-group">
84103
<label><input type="checkbox" name="is_superuser"> superuser</label>
85104
</div>
86105
</div>
87106
<div class="modal-footer">
88107
<button type="button" class="btn btn-default" data-dismiss="modal">close</button>
89-
<button type="submit" class="btn btn-primary">add</button>
108+
<button type="submit" class="btn btn-primary">submit</button>
90109
</div>
91110
</div>
111+
</form>
112+
</div>
113+
</div>
114+
115+
116+
<div class="modal fade" id="updateUserForm" tabindex="-1" role="dialog">
117+
<div class="modal-dialog" role="document">
118+
<form method="post" action="">
119+
<div class="modal-content">
120+
<div class="modal-header">
121+
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
122+
<h4 class="modal-title">Edit user</h4>
123+
</div>
124+
<div class="modal-body">
125+
<div class="form-group">
126+
<label for="message-text" class="control-label">user name:</label>
127+
<input type="text" name="name" id="user_name" class="form-control" data-title="Enter user name" required>
128+
</div>
129+
<div class="form-group">
130+
<label for="message-text" class="control-label">email:</label>
131+
<input type="email" name="email" id="user_email" class="form-control" data-title="Enter email" required>
132+
</div>
133+
<div class="form-group">
134+
<label><input type="checkbox" id="is_superuser" name="is_superuser"> superuser</label>
135+
</div>
136+
</div>
137+
<div class="modal-footer">
138+
<button type="button" class="btn btn-default" data-dismiss="modal">close</button>
139+
<button type="submit" class="btn btn-primary">submit</button>
140+
</div>
141+
</div>
142+
</form>
143+
</div>
144+
</div>
145+
146+
147+
<div class="modal fade" id="resetPasswordForm" tabindex="-1" role="dialog">
148+
<div class="modal-dialog" role="document">
149+
<form method="post" action="">
150+
<div class="modal-content">
151+
<div class="modal-header">
152+
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
153+
<h4 class="modal-title">Reset password</h4>
154+
</div>
155+
<div class="modal-body">
156+
157+
158+
159+
<div class="form-group">
160+
<label for="message-text" class="control-label">new password:</label>
161+
<input type="password" name="new_password" class="form-control" data-title="Enter password" required>
162+
</div>
163+
164+
165+
166+
<div class="form-group">
167+
<label for="message-text" class="control-label">confirm password:</label>
168+
<input type="password" name="confirm_password" class="form-control" data-title="Enter password" required>
169+
</div>
170+
</div>
171+
<div class="modal-footer">
172+
<button type="button" class="btn btn-default" data-dismiss="modal">close</button>
173+
<button type="submit" class="btn btn-primary">submit</button>
174+
</div>
175+
</div>
176+
</form>
92177
</div>
93178
</div>
94179
{% endif %} {% endverbatim %}

src/app/controllers/project/get.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package project
2+
3+
import (
4+
"github.com/postgres-ci/app-server/src/app/models/project"
5+
"github.com/postgres-ci/app-server/src/common/errors"
6+
"github.com/postgres-ci/app-server/src/tools/params"
7+
"github.com/postgres-ci/app-server/src/tools/render"
8+
"github.com/postgres-ci/http200ok"
9+
10+
"net/http"
11+
)
12+
13+
func getHandler(c *http200ok.Context) {
14+
15+
project, err := project.Get(params.ToInt32(c, "ProjectID"))
16+
17+
if err != nil {
18+
19+
code := http.StatusInternalServerError
20+
21+
if e, ok := err.(*errors.Error); ok {
22+
23+
code = e.Code
24+
}
25+
26+
render.JSONError(c, code, err.Error())
27+
28+
return
29+
}
30+
31+
render.JSON(c, project)
32+
}

0 commit comments

Comments
 (0)