Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
93957939
Commit
93957939
authored
Feb 24, 2016
by
Mathieu Rodic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[BUG] corpora are now deletable from `/projects/(\d+)`
[FEAT] implemented a kind of simple front-end REST library
parent
d6b0b08b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
134 additions
and
7 deletions
+134
-7
nodes.py
gargantext/views/api/nodes.py
+5
-1
garganrest.js
static/js/gargantext/garganrest.js
+119
-0
project.html
templates/pages/projects/project.html
+10
-6
No files found.
gargantext/views/api/nodes.py
View file @
93957939
...
...
@@ -63,6 +63,9 @@ class NodeListResource(APIView):
'records'
:
[
dict
(
zip
(
parameters
[
'fields'
],
node
))
for
node
in
query
]
})
def
post
(
self
,
request
):
pass
def
delete
(
self
,
request
):
"""Removes the list of nodes corresponding to the query.
WARNING! THIS IS TOTALLY UNTESTED!!!!!
...
...
@@ -76,6 +79,7 @@ class NodeListResource(APIView):
'count'
:
count
,
},
200
)
class
NodeResource
(
APIView
):
def
_query
(
self
,
request
,
node_id
):
...
...
@@ -88,7 +92,6 @@ class NodeResource(APIView):
return
user
,
node
def
get
(
self
,
request
,
node_id
):
from
sqlalchemy
import
delete
user
,
node
=
self
.
_query
(
request
,
node_id
)
return
JsonHttpResponse
({
'id'
:
node
.
id
,
...
...
@@ -98,6 +101,7 @@ class NodeResource(APIView):
})
def
delete
(
self
,
request
,
node_id
):
from
sqlalchemy
import
delete
user
,
node
=
self
.
_query
(
request
,
node_id
)
result
=
session
.
execute
(
delete
(
Node
)
.
where
(
Node
.
id
==
node_id
)
...
...
static/js/gargantext/garganrest.js
0 → 100644
View file @
93957939
// check if an object is an array
if
(
typeof
Array
.
isArray
!=
'function'
)
{
Array
.
isArray
=
function
(
stuff
)
{
return
Object
.
prototype
.
toString
.
call
(
stuff
)
==
'[object Array]'
;
};
}
// CSRF token management for Django
var
getCookie
=
function
(
name
)
{
var
cookieValue
=
null
;
if
(
document
.
cookie
&&
document
.
cookie
!=
''
)
{
var
cookies
=
document
.
cookie
.
split
(
';'
);
for
(
var
i
=
0
;
i
<
cookies
.
length
;
i
++
)
{
var
cookie
=
jQuery
.
trim
(
cookies
[
i
]);
// Does this cookie string begin with the name we want?
if
(
cookie
.
substring
(
0
,
name
.
length
+
1
)
==
(
name
+
'='
))
{
cookieValue
=
decodeURIComponent
(
cookie
.
substring
(
name
.
length
+
1
));
break
;
}
}
}
return
cookieValue
;
}
var
csrftoken
=
getCookie
(
'csrftoken'
);
$
.
ajaxSetup
({
beforeSend
:
function
(
xhr
,
settings
)
{
xhr
.
setRequestHeader
(
"X-CSRFToken"
,
csrftoken
);
}
});
// Resource class
var
Resource
=
function
(
url_path
)
{
// retrieve one or many items
this
.
get
=
function
(
criteria
,
callback
)
{
var
url
=
url_path
;
switch
(
typeof
criteria
)
{
// get the list, according to the criteria passed as parameters
case
'object'
:
var
url_parameters
=
''
;
$
.
each
(
criteria
,
function
(
key
,
value
)
{
if
(
Array
.
isArray
(
value
))
{
$
.
each
(
value
,
function
(
i
,
item
)
{
url_parameters
+=
url_parameters
.
length
?
'&'
:
'?'
;
url_parameters
+=
encodeURIComponent
(
key
)
+
'[]='
+
encodeURIComponent
(
item
);
});
}
else
{
url_parameters
+=
url_parameters
.
length
?
'&'
:
'?'
;
url_parameters
+=
encodeURIComponent
(
key
)
+
'='
+
encodeURIComponent
(
value
);
}
});
url
+=
url_parameters
;
break
;
// get the list, without paramters
case
'function'
:
callback
=
criteria
;
break
;
case
'number'
:
case
'string'
:
url
+=
'/'
+
criteria
;
break
;
}
$
.
ajax
({
url
:
url
,
type
:
'GET'
,
success
:
callback
});
};
// change an item
this
.
change
=
this
.
update
=
function
(
item
,
callback
)
{
$
.
ajax
({
url
:
url_path
+
'/'
+
item
.
id
,
type
:
'PATCH'
,
success
:
callback
});
};
// remove an item
this
.
delete
=
this
.
remove
=
function
(
id
,
callback
)
{
if
(
id
.
id
!=
undefined
)
{
id
=
id
.
id
;
}
$
.
ajax
({
url
:
url_path
+
'/'
+
id
,
type
:
'DELETE'
,
success
:
callback
});
};
// add an item
this
.
add
=
this
.
append
=
function
(
value
,
callback
)
{
$
.
ajax
({
url
:
url_path
+
'/'
+
id
,
type
:
'POST'
,
success
:
callback
});
};
};
var
GarganRest
=
function
(
base_path
,
path_list
)
{
var
that
=
this
;
$
.
each
(
path_list
,
function
(
p
,
path
){
that
[
path
]
=
new
Resource
(
base_path
+
path
);
});
};
garganrest
=
new
GarganRest
(
'/api/'
,
[
'nodes'
]);
// var log = function(result){console.log(result);};
// garganrest.nodes.get(log);
// garganrest.nodes.get(167, log);
// garganrest.nodes.delete(167, log);
// garganrest.nodes.get({
// pagination_offset: 0,
// pagination_limit: 10,
// type: ['DOCUMENT'],
// parent_id: 2,
// }, log);
templates/pages/projects/project.html
View file @
93957939
...
...
@@ -4,6 +4,7 @@
{% load staticfiles %}
<link
rel=
"stylesheet"
href=
"{% static "
css
/
bootstrap
.
css
"
%}"
>
<script
type=
"text/javascript"
src=
"{% static "
js
/
jquery
/
jquery
.
min
.
js
"
%}"
></script>
<script
type=
"text/javascript"
src=
"{% static "
js
/
gargantext
/
garganrest
.
js
"
%}"
></script>
<link
rel=
"stylesheet"
href=
"http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css"
>
<script
type=
"text/javascript"
src=
"{% static "
js
/
morris
.
min
.
js
"
%}"
></script>
...
...
@@ -75,7 +76,7 @@
{{ key }}
<ul>
{% for corpus in corpora %}
<li>
<li
id=
"corpus_{{corpus.id}}"
>
{% ifequal corpus.processing 1 %}
{{corpus.name}}:
<img
width=
"20px"
src=
"{% static "
js
/
libs
/
img2
/
loading-bar
.
gif
"
%}"
>
...
...
@@ -84,13 +85,16 @@
<a
href=
"/projects/{{project.id}}/corpora/{{corpus.id}}"
>
{{corpus.name}} , {{ corpus.count }} documents
</a>
{% endifequal %}
<button
type=
"button"
class=
"btn btn-xs btn-default"
data-container=
"body"
data-toggle=
"popover"
data-placement=
"bottom"
data-content=
'
data-content=
"
<ul>
<li> Rename </li>
<li> Add new documents </li>
<li><a href="/delete/{{corpus.id}}">Delete</a></li>
<li>Rename</li>
<li>Add new documents</li>
<li onclick="
garganrest.nodes.delete({{corpus.id}}, function(){$('#corpus_'+{{corpus.id}}).remove()});
$(this).parent().parent().parent().remove();
"><a href="#">Delete</a></li>
</ul>
'
>
Manage
</button>
"
>
Manage
</button>
</li>
{% endfor %}
</ul>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment