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
cbe804cd
Commit
cbe804cd
authored
Feb 23, 2016
by
delanoe
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'refactoring' into refactoring-alex
parents
0c4ca9a6
c7bed046
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
34 deletions
+72
-34
ngrams.py
gargantext/models/ngrams.py
+2
-2
nodes.py
gargantext/models/nodes.py
+3
-2
nodes.py
gargantext/views/api/nodes.py
+35
-3
urls.py
gargantext/views/api/urls.py
+2
-1
Docs_dyna_chart_and_table.js
static/js/gargantext/Docs_dyna_chart_and_table.js
+30
-26
No files found.
gargantext/models/ngrams.py
View file @
cbe804cd
...
...
@@ -17,6 +17,6 @@ class Ngram(Base):
class
NodeNgram
(
Base
):
__tablename__
=
'nodes_ngrams'
id
=
Column
(
Integer
)
node_id
=
Column
(
Integer
,
ForeignKey
(
Node
.
id
),
primary_key
=
True
)
ngram_id
=
Column
(
Integer
,
ForeignKey
(
Ngram
.
id
),
primary_key
=
True
)
node_id
=
Column
(
Integer
,
ForeignKey
(
Node
.
id
,
ondelete
=
'CASCADE'
),
primary_key
=
True
)
ngram_id
=
Column
(
Integer
,
ForeignKey
(
Ngram
.
id
,
ondelete
=
'CASCADE'
),
primary_key
=
True
)
weight
=
Column
(
Float
)
gargantext/models/nodes.py
View file @
cbe804cd
...
...
@@ -25,8 +25,9 @@ class Node(Base):
__tablename__
=
'nodes'
id
=
Column
(
Integer
,
primary_key
=
True
)
typename
=
Column
(
NodeType
,
index
=
True
)
user_id
=
Column
(
Integer
,
ForeignKey
(
User
.
id
))
parent_id
=
Column
(
Integer
,
ForeignKey
(
'nodes.id'
))
# foreign keys
user_id
=
Column
(
Integer
,
ForeignKey
(
User
.
id
,
ondelete
=
'CASCADE'
))
parent_id
=
Column
(
Integer
,
ForeignKey
(
'nodes.id'
,
ondelete
=
'CASCADE'
))
# main data
name
=
Column
(
String
(
255
))
date
=
Column
(
DateTime
(),
default
=
datetime
.
now
)
...
...
gargantext/views/api/nodes.py
View file @
cbe804cd
from
gargantext.util.http
import
*
from
gargantext.util.db
import
*
from
gargantext.util.db_cache
import
*
from
gargantext.models
import
*
from
gargantext.constants
import
*
from
gargantext.util.validation
import
validate
class
Node
sList
(
APIView
):
class
Node
ListResource
(
APIView
):
_fields
=
[
'id'
,
'parent_id'
,
'name'
,
'typename'
,
'hyperdata'
]
_types
=
NODETYPES
...
...
@@ -37,8 +38,11 @@ class NodesList(APIView):
# filter by parent
if
'parent_id'
in
parameters
:
query
=
query
.
filter
(
Node
.
parent_id
==
parameters
[
'parent_id'
])
#
paginate the query
#
count
count
=
query
.
count
()
# order
query
=
query
.
order_by
(
Node
.
hyperdata
[
'publication_date'
],
Node
.
id
)
# paginate the query
if
parameters
[
'pagination_limit'
]
==
-
1
:
query
=
query
[
parameters
[
'pagination_offset'
]:]
else
:
...
...
@@ -49,7 +53,6 @@ class NodesList(APIView):
# return the result!
return
parameters
,
query
,
count
def
get
(
self
,
request
):
"""Displays the list of nodes corresponding to the query.
"""
...
...
@@ -72,3 +75,32 @@ class NodesList(APIView):
'parameters'
:
parameters
,
'count'
:
count
,
},
200
)
class
NodeResource
(
APIView
):
def
_query
(
self
,
request
,
node_id
):
user
=
cache
.
User
[
request
.
user
.
username
]
node
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
node_id
)
.
first
()
if
node
is
None
:
raise
Http404
()
if
not
user
.
owns
(
node
):
raise
HttpResponseForbidden
()
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
,
'parent_id'
:
node
.
parent_id
,
'name'
:
node
.
name
,
'hyperdata'
:
node
.
hyperdata
,
})
def
delete
(
self
,
request
,
node_id
):
user
,
node
=
self
.
_query
(
request
,
node_id
)
result
=
session
.
execute
(
delete
(
Node
)
.
where
(
Node
.
id
==
node_id
)
)
session
.
commit
()
return
JsonHttpResponse
({
'deleted'
:
result
.
rowcount
})
gargantext/views/api/urls.py
View file @
cbe804cd
...
...
@@ -4,5 +4,6 @@ from . import nodes
urlpatterns
=
[
url
(
r'^nodes$'
,
nodes
.
NodesList
.
as_view
()),
url
(
r'^nodes$'
,
nodes
.
NodeListResource
.
as_view
()),
url
(
r'^nodes/(\d+)$'
,
nodes
.
NodeResource
.
as_view
()),
]
static/js/gargantext/Docs_dyna_chart_and_table.js
View file @
cbe804cd
function
get_node_date
(
node
)
{
var
hyperdata
=
node
.
hyperdata
;
return
new
Date
(
Number
(
hyperdata
.
publication_year
),
Number
(
hyperdata
.
publication_month
)
-
1
,
Number
(
hyperdata
.
publication_day
)
);
};
function
pr
(
msg
)
{
console
.
log
(
msg
)
}
...
...
@@ -89,19 +98,21 @@ function Final_UpdateTable( action ) {
var
TimeRange
=
AjaxRecords
;
var
dataini
=
TheBuffer
[
0
]
.
toISOString
().
split
(
"T"
)[
0
]
var
datafin
=
TheBuffer
[
1
]
.
toISOString
().
split
(
"T"
)[
0
]
var
dataini
=
TheBuffer
[
0
]
;
var
datafin
=
TheBuffer
[
1
]
;
pr
(
"show me the pubs of the selected period"
)
console
.
log
(
TheBuffer
)
pr
(
"
\
tfrom ["
+
dataini
+
"] to ["
+
datafin
+
"]"
)
TimeRange
=
[]
for
(
var
i
in
AjaxRecords
)
{
if
(
AjaxRecords
[
i
].
date
>=
dataini
&&
AjaxRecords
[
i
].
date
<=
datafin
){
console
.
log
(
dataini
,
datafin
)
$
.
each
(
AjaxRecords
,
function
(
i
,
node
)
{
if
(
node
.
date
>=
dataini
&&
node
.
date
>=
dataini
)
{
// pr( AjaxRecords[i].date+" : "+AjaxRecords[i].id )
TimeRange
.
push
(
AjaxRecords
[
i
])
TimeRange
.
push
(
node
);
}
}
});
console
.
log
(
TimeRange
)
MyTable
=
$
(
'#my-ajax-table'
).
dynatable
({
dataset
:
{
...
...
@@ -292,16 +303,10 @@ function Main_test( Data , SearchFilter ) {
// console.log(Data[i]["date"]+" : originalRecords["+arr_id+"] <- "+orig_id+" | "+Data[i]["name"])
}
var
get_date
=
function
(
node
)
{
var
hyperdata
=
node
.
hyperdata
;
return
new
Date
(
Number
(
hyperdata
.
publication_year
),
Number
(
hyperdata
.
publication_month
)
-
1
,
Number
(
hyperdata
.
publication_day
)
);
};
var
t0
=
get_date
(
AjaxRecords
[
0
]);
var
t1
=
get_date
(
AjaxRecords
.
slice
(
-
1
)[
0
]);
var
t0
=
get_node_date
(
AjaxRecords
[
0
]);
var
t1
=
get_node_date
(
AjaxRecords
.
slice
(
-
1
)[
0
]);
oldest
=
t0
;
latest
=
t1
;
console
.
log
(
t0
,
t1
)
TheBuffer
=
[
t0
,
t1
];
...
...
@@ -310,15 +315,13 @@ function Main_test( Data , SearchFilter ) {
var
arrayd3
=
[]
$
.
each
(
Data
,
function
(
i
,
node
)
{
var
date
=
node
.
hyperdata
.
publication_date
;
if
(
justdates
[
date
]
!=
false
)
{
var
info
=
{};
info
.
date
=
date
;
info
.
dd
=
get_date
(
node
);
info
.
month
=
d3
.
time
.
month
(
info
.
dd
);
info
.
volume
=
justdates
[
date
];
arrayd3
.
push
(
info
);
justdates
[
date
]
=
false
;
if
(
node
.
date
)
{
arrayd3
.
push
({
date
:
get_node_date
(
node
),
dd
:
node
.
date
,
month
:
d3
.
time
.
month
(
node
.
date
),
volume
:
justdates
[
date
],
});
}
});
...
...
@@ -529,7 +532,7 @@ $("#corpusdisplayer").hide()
// FIRST portion of code to be EXECUTED:
// (3) Get records and hyperdata for paginator
$
.
ajax
({
url
:
'/api/nodes?type[]=DOCUMENT&parent_id='
+
corpus_id
,
url
:
'/api/nodes?type[]=DOCUMENT&pa
gination_limit=-1&pa
rent_id='
+
corpus_id
,
success
:
function
(
data
){
$
(
"#content_loader"
).
remove
();
$
.
each
(
data
.
records
,
function
(
i
,
record
){
...
...
@@ -538,6 +541,7 @@ $.ajax({
RecDict
[
orig_id
]
=
arr_id
;
record
.
title
=
record
.
name
;
record
.
name
=
'<a target="_blank" href="/projects/'
+
project_id
+
'/corpora/'
+
corpus_id
+
'/documents/'
+
record
.
id
+
'">'
+
record
.
name
+
'</a>'
;
record
.
date
=
get_node_date
(
record
);
record
.
del
=
false
;
});
for
(
var
i
in
data
.
records
)
{
...
...
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