ui fix 69/6369/1
authorlombardofr <lombardo@everyup.it>
Wed, 18 Jul 2018 15:02:16 +0000 (17:02 +0200)
committerlombardofr <lombardo@everyup.it>
Thu, 19 Jul 2018 12:40:12 +0000 (14:40 +0200)
Change-Id: I73d09df0e5851c08dc5eb2a588446d4c3eac8573
Signed-off-by: lombardofr <lombardo@everyup.it>
lib/osm/osmclient/clientv2.py
projecthandler/template/project/modal/new_project.html [deleted file]
projecthandler/template/project/modal/project_edit.html [new file with mode: 0644]
projecthandler/template/project/modal/project_new.html [new file with mode: 0644]
projecthandler/template/project/projectlist.html
projecthandler/urls/project.py
projecthandler/views.py
userhandler/templates/modal/user_edit.html [new file with mode: 0644]
userhandler/templates/user_list.html

index 5e4f390..47c8e67 100644 (file)
@@ -180,6 +180,26 @@ class Client(object):
         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",
diff --git a/projecthandler/template/project/modal/new_project.html b/projecthandler/template/project/modal/new_project.html
deleted file mode 100644 (file)
index c346ec8..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-<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
diff --git a/projecthandler/template/project/modal/project_edit.html b/projecthandler/template/project/modal/project_edit.html
new file mode 100644 (file)
index 0000000..27a9ee6
--- /dev/null
@@ -0,0 +1,32 @@
+<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
diff --git a/projecthandler/template/project/modal/project_new.html b/projecthandler/template/project/modal/project_new.html
new file mode 100644 (file)
index 0000000..c346ec8
--- /dev/null
@@ -0,0 +1,32 @@
+<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
index 85abb59..ed8b583 100644 (file)
@@ -47,9 +47,7 @@
 
                                                <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>
@@ -74,7 +86,8 @@
 </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) {
index e0395c8..9d653b6 100644 (file)
@@ -21,8 +21,9 @@ urlpatterns = [
     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'),
index 0f0cf6c..0f4248a 100644 (file)
@@ -281,9 +281,9 @@ def open_project(request):
 
 
 @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']:
@@ -301,6 +301,23 @@ def switch_project(request, project_id):
     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)
diff --git a/userhandler/templates/modal/user_edit.html b/userhandler/templates/modal/user_edit.html
new file mode 100644 (file)
index 0000000..b278e22
--- /dev/null
@@ -0,0 +1,53 @@
+<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>
index 03ae70f..f8fa6ac 100644 (file)
                                 <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>