result['data'] = Util.json_loads_byteified(r.text)
return result
+ def project_edit(self, token, id, project_data):
+
+ result = {'error': True, 'data': ''}
+ headers = {"Content-Type": "application/json", "accept": "application/json",
+ 'Authorization': 'Bearer {}'.format(token['id'])}
+
+ _url = "{0}/admin/v1/projects/{1}".format(self._base_path, id)
+
+ try:
+ r = requests.put(_url, json=project_data, verify=False, headers=headers)
+ except Exception as e:
+ log.exception(e)
+ result['data'] = str(e)
+ return result
+ print r.status_code
+ if r.status_code == requests.codes.no_content:
+ result['error'] = False
+ result['data'] = Util.json_loads_byteified(r.text)
+ return result
+
def project_delete(self, token, id):
result = {'error': True, 'data': ''}
headers = {"Content-Type": "application/yaml", "accept": "application/json",
+++ /dev/null
-<div class="modal" id="modal_new_project" xmlns="http://www.w3.org/1999/html">
- <div class="modal-dialog">
- <div class="modal-content">
- <div class="modal-header">
- <button type="button" class="close" data-dismiss="modal" aria-label="Close">
- <span aria-hidden="true">×</span></button>
- <h4 class="modal-title" id="modal_new_project_title">New Project</h4>
- </div>
- <form id="formNewProject" action='{% url "projects:new_project" %}'class="form-horizontal" method="post" >
- {% csrf_token %}
- <div class="modal-body">
-
- <div id="div_chose_id">
- <label>Project Name: </label>
- <input name="name" id="name" size="40" maxlength="20"/>
- </div>
-
- </div>
-
- <div class="modal-footer">
- <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
- <button class="btn btn-primary"
- data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Creating..."
- id="create_new_project">Create
- </button>
- </div>
- </form>
- </div>
- <!-- /.modal-content -->
- </div>
- <!-- /.modal-dialog -->
-</div>
\ No newline at end of file
--- /dev/null
+<div class="modal" id="modal_edit_project" xmlns="http://www.w3.org/1999/html">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+ <span aria-hidden="true">×</span></button>
+ <h4 class="modal-title" id="modal_edit_project_title">Edit Project</h4>
+ </div>
+ <form id="formEditProject" class="form-horizontal" method="post" >
+ {% csrf_token %}
+ <div class="modal-body">
+
+ <div id="div_chose_id">
+ <label>Project Name: </label>
+ <input name="name" id="name" size="40" maxlength="20"/>
+ </div>
+
+ </div>
+
+ <div class="modal-footer">
+ <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
+ <button class="btn btn-primary"
+ data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Editing..."
+ id="create_edit_project">Apply
+ </button>
+ </div>
+ </form>
+ </div>
+ <!-- /.modal-content -->
+ </div>
+ <!-- /.modal-dialog -->
+</div>
\ No newline at end of file
--- /dev/null
+<div class="modal" id="modal_new_project" xmlns="http://www.w3.org/1999/html">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+ <span aria-hidden="true">×</span></button>
+ <h4 class="modal-title" id="modal_new_project_title">New Project</h4>
+ </div>
+ <form id="formNewProject" action='{% url "projects:new_project" %}'class="form-horizontal" method="post" >
+ {% csrf_token %}
+ <div class="modal-body">
+
+ <div id="div_chose_id">
+ <label>Project Name: </label>
+ <input name="name" id="name" size="40" maxlength="20"/>
+ </div>
+
+ </div>
+
+ <div class="modal-footer">
+ <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
+ <button class="btn btn-primary"
+ data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Creating..."
+ id="create_new_project">Create
+ </button>
+ </div>
+ </form>
+ </div>
+ <!-- /.modal-content -->
+ </div>
+ <!-- /.modal-dialog -->
+</div>
\ No newline at end of file
<th>Modification Date</th>
<th>Creation Date</th>
-
-
- <th><i class="far fa-trash-alt"></i></th>
+ <th>Actions</th>
</tr>
</thead>
<tbody>
<td>{{ p|get_sub:"_admin,modified"|get_date}}</td>
<td>{{ p|get_sub:"_admin,created"|get_date}}</td>
- <td><a href="javascript:deleteProject('{% url 'projects:delete_project' %}')"> Delete</a></td>
-
+ <td>
+ <div class="btn-group">
+ <button type="button" class="btn btn-default dropdown-toggle"
+ data-toggle="dropdown" aria-expanded="false">Actions
+ <span class="fa fa-caret-down"></span></button>
+ <ul class="dropdown-menu">
+ <li><a href="#"
+ onclick="javascript:editProject('{% url 'projects:edit_project' project_id=p.name %}')">
+ <i class="fa fa-edit"></i> Rename</a></li>
+ <li>
+ <a href="#" onclick="javascript:deleteProject('{% url 'projects:delete_project' project_id=p.name%}')" style="color:red">
+ <i class="fa fa-trash" ></i> Delete</a>
+ </li>
+ </ul>
+ </div>
+ </td>
</tr>
{% endfor %}
</tbody>
</div>
</div>
-{% include "modal/new_project.html" %}
+{% include "modal/project_new.html" %}
+{% include "modal/project_edit.html" %}
{% endblock %}
{% block resource_block %}
$('#modal_new_project').modal('show');
}
+ function editProject(url){
+ $("#formEditProject").attr("action", url);
+ $('#modal_edit_project').modal('show');
+ }
+
function deleteProject(url) {
bootbox.confirm("Are you sure want to delete?", function (result) {
if (result) {
url(r'^$', views.open_project, name='open_project'),
url(r'^list/', views.user_projects, name='projects_list'),
url(r'^new/', views.create_new_project, name='new_project'),
- url(r'^delete$', views.delete_project, name='delete_project'),
- url(r'^switch/(?P<project_id>\w+)', views.switch_project, name='switch_project'),
+ url(r'^(?P<project_id>\w+)/delete$', views.delete_project, name='delete_project'),
+ url(r'^(?P<project_id>\w+)/switch', views.switch_project, name='switch_project'),
+ url(r'^(?P<project_id>\w+)/edit', views.edit_project, name='edit_project'),
url(r'^descriptors/(?P<descriptor_type>\w+)/list$', views.show_descriptors, name='list_descriptors'),
url(r'^descriptors/(?P<descriptor_type>\w+)/(?P<descriptor_id>[-\w]+)(/$)',
views.edit_descriptor, name='edit_descriptor'),
@login_required
-def delete_project(request):
+def delete_project(request, project_id):
user = osmutils.get_user(request)
- project_id = user.project_id
+
client = Client()
result = client.project_delete(user.get_token(), project_id)
if isinstance(result, dict) and 'error' in result and result['error']:
return redirect('projects:open_project')
+@login_required
+def edit_project(request, project_id):
+ if request.method == 'POST':
+ user = osmutils.get_user(request)
+ client = Client()
+ project_dict = request.POST.dict()
+ keys = ["name"]
+ project_data = dict(filter(lambda i: i[0] in keys and len(i[1]) > 0, project_dict.items()))
+ result = client.project_edit(user.get_token(), project_id, project_data)
+ if isinstance(result, dict) and 'error' in result and result['error']:
+ print result
+ return __response_handler(request, result['data'], url=None,
+ status=result['data']['status'] if 'status' in result['data'] else 500)
+ else:
+ return __response_handler(request, {}, url=None, status=200)
+
+
@login_required
def show_descriptors(request, descriptor_type=None):
user = osmutils.get_user(request)
--- /dev/null
+<div class="modal" id="modal_edit_user" xmlns="http://www.w3.org/1999/html">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+ <span aria-hidden="true">×</span></button>
+ <h4 class="modal-title">New User</h4>
+ </div>
+ <form id="formCreateNS" action='{% url "users:update" %}'
+ class="form-horizontal"
+ method="post" enctype="multipart/form-data">
+ {% csrf_token %}
+ <div class="modal-body" id="modal_edit_user_body">
+ <div class="form-group">
+ <label for="username" class="col-sm-3 control-label">Username *</label>
+ <div class="col-sm-6">
+ <input class="form-control" id="username" name="username"
+ placeholder="Username" required>
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label for="password" class="col-sm-3 control-label">Password *</label>
+ <div class="col-sm-6">
+ <input class="form-control" id="password" name="password" type="password"
+ placeholder="Password" required>
+ </div>
+ </div>
+ <div class="form-group">
+ <label for=projects" class="col-sm-3 control-label">Projects *</label>
+ <div class="col-sm-6">
+ <select required id="projects" class="js-example-basic-multiple form-control" name="projects"
+ multiple="multiple">
+ </select>
+ </div>
+ </div>
+
+
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-default pull-left" data-dismiss="modal">Cancel</button>
+ <button class="btn btn-primary"
+ data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Editing..."
+ id="create_edit_user">Apply
+ </button>
+
+ </div>
+ </form>
+ </div>
+ <!-- /.modal-content -->
+ </div>
+ <!-- /.modal-dialog -->
+</div>
<td>{{ s|get_sub:"_admin,created"|get_date}}</td>
<td>
- <div class="btn-group">
- <button type="button" class="btn btn-default"
- onclick="javascript:deleteUser('{% url "users:delete" user_id=s|get:"_id" %}')" data-toggle="tooltip" data-placement="top" data-container="body" title="Delete"><i
- class="far fa-trash-alt" ></i></button>
- </div>
+ <div class="btn-group">
+ <button type="button" class="btn btn-default dropdown-toggle"
+ data-toggle="dropdown" aria-expanded="false">Actions
+ <span class="fa fa-caret-down"></span></button>
+ <ul class="dropdown-menu">
+
+ <li>
+ <a href="#" onclick="javascript:deleteUser('{% url "users:delete" user_id=s|get:"_id" %}')" style="color:red">
+ <i class="fa fa-trash" ></i> Delete</a>
+
+ </li>
+ </ul>
+ </div>
</td>
</tr>