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
7756d26b
Commit
7756d26b
authored
Nov 12, 2015
by
PkSM3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[UPDATE] CRUD map-list OK
parent
c4ed35c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
31 deletions
+64
-31
ngrams.py
rest_v1_0/ngrams.py
+27
-11
NGrams_dyna_chart_and_table.js
static/js/NGrams_dyna_chart_and_table.js
+37
-20
No files found.
rest_v1_0/ngrams.py
View file @
7756d26b
...
...
@@ -497,20 +497,36 @@ class Keep(APIView):
return
JsonHttpResponse
(
results
)
def
put
(
self
,
request
,
list_id
,
ngram_ids
):
def
put
(
self
,
request
,
corpus_id
):
"""
Add ngrams to map list
"""
print
(
"list_id:"
,
list_id
)
print
(
"ngram_ids:"
,
ngram_ids
)
# for ngram_id in ngram_ids.split('+'):
# print('ngram_id', ngram_id)
# ngram_id = int(ngram_id)
# (session.query(NodeNgram)
# .filter(NodeNgram.node_id==list_id)
# .filter(NodeNgram.ngram_id==ngram_id).delete()
# )
# session.commit()
group_rawreq
=
dict
(
request
.
data
)
ngram_2add
=
[
int
(
i
)
for
i
in
list
(
group_rawreq
.
keys
())]
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
corpus_id
)
.
first
()
node_mapList
=
get_or_create_node
(
nodetype
=
'MapList'
,
corpus
=
corpus
)
for
ngram_id
in
ngram_2add
:
map_node
=
Node_Ngram
(
weight
=
1.0
,
ngram_id
=
ngram_id
,
node_id
=
node_mapList
.
id
)
session
.
add
(
map_node
)
session
.
commit
()
return
JsonHttpResponse
(
True
,
201
)
def
delete
(
self
,
request
,
corpus_id
):
"""
Delete ngrams from the map list
"""
group_rawreq
=
dict
(
request
.
data
)
ngram_2del
=
[
int
(
i
)
for
i
in
list
(
group_rawreq
.
keys
())]
corpus
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
corpus_id
)
.
first
()
node_mapList
=
get_or_create_node
(
nodetype
=
'MapList'
,
corpus
=
corpus
)
ngram_2del
=
session
.
query
(
NodeNgram
)
.
filter
(
NodeNgram
.
node_id
==
node_mapList
.
id
,
NodeNgram
.
ngram_id
.
in_
(
ngram_2del
)
)
.
all
()
for
map_node
in
ngram_2del
:
try
:
session
.
delete
(
map_node
)
except
:
pass
session
.
commit
()
return
JsonHttpResponse
(
True
,
201
)
static/js/NGrams_dyna_chart_and_table.js
View file @
7756d26b
...
...
@@ -486,30 +486,43 @@ $("#Save_All").click(function(){
FlagsBuffer
[
"delete"
]
=
{}
FlagsBuffer
[
"keep"
]
=
{}
FlagsBuffer
[
"outmap"
]
=
{}
FlagsBuffer
[
"inmap"
]
=
{}
for
(
var
id
in
AjaxRecords
)
{
if
(
ngrams_map
[
AjaxRecords
[
id
][
"id"
]
]
)
{
if
(
AjaxRecords
[
id
][
"state"
]
==
0
||
AjaxRecords
[
id
][
"state"
]
==
2
)
{
FlagsBuffer
[
"outmap"
][
AjaxRecords
[
id
].
id
]
=
true
}
}
else
{
if
(
AjaxRecords
[
id
][
"state"
]
==
1
)
{
FlagsBuffer
[
"inmap"
][
AjaxRecords
[
id
].
id
]
=
true
}
}
if
(
AjaxRecords
[
id
][
"state"
]
>
0
)
{
FlagsBuffer
[
System
[
0
].
states
[
AjaxRecords
[
id
].
state
]
]
[
AjaxRecords
[
id
].
id
]
=
true
}
}
// [ = = = = For deleting subforms = = = = ]
for
(
var
i
in
FlagsBuffer
[
"group"
])
{
if
(
FlagsBuffer
[
"delete"
][
i
])
{
for
(
var
j
in
FlagsBuffer
[
"group"
][
i
]
)
{
FlagsBuffer
[
"delete"
][
FlagsBuffer
[
"group"
][
i
][
j
]]
=
true
}
}
}
// [ = = = = / For deleting subforms = = = = ]
console
.
log
(
" = = = = = = = = = == "
)
console
.
log
(
"FlagsBuffer:"
)
console
.
log
(
FlagsBuffer
)
// // [ = = = = For deleting subforms = = = = ]
// for(var i in FlagsBuffer["group"]) {
// if(FlagsBuffer["delete"][i]) {
// for(var j in FlagsBuffer["group"][i] ) {
// FlagsBuffer["delete"][FlagsBuffer["group"][i][j]] = true
// }
// }
// }
// // [ = = = = / For deleting subforms = = = = ]
var
nodes_2del
=
Object
.
keys
(
FlagsBuffer
[
"delete"
]).
map
(
Number
)
var
nodes_2keep
=
Object
.
keys
(
FlagsBuffer
[
"keep"
]).
map
(
Number
)
var
nodes_2group
=
$
.
extend
({},
FlagsBuffer
[
"group"
]);
var
nodes_2group
=
$
.
extend
({},
FlagsBuffer
[
"group"
])
var
nodes_2inmap
=
$
.
extend
({},
FlagsBuffer
[
"inmap"
])
var
nodes_2outmap
=
$
.
extend
({},
FlagsBuffer
[
"outmap"
])
var
list_id
=
$
(
"#list_id"
).
val
()
var
corpus_id
=
getIDFromURL
(
"corpus"
)
// not used
...
...
@@ -519,16 +532,19 @@ $("#Save_All").click(function(){
// // window.location.reload()
// });
CRUD
(
list_id
,
""
,
nodes_2del
,
[]
,
"DELETE"
),
$
.
doTimeout
(
1000
,
function
(){
CRUD
(
list_id
,
"/keep"
,
nodes_2keep
,
[]
,
"PUT"
)
$
.
doTimeout
(
1000
,
function
(){
CRUD
(
corpus_id
,
"/group"
,
[]
,
nodes_2group
,
"PUT"
)
$
.
doTimeout
(
1000
,
function
(){
window
.
location
.
reload
()
});
});
});
// CRUD( list_id , "" , nodes_2del , [] , "DELETE" ),
// $.doTimeout( 1000, function(){
// CRUD( corpus_id , "/keep" , [] , nodes_2outmap , "DELETE" )
// $.doTimeout( 1000, function(){
CRUD
(
corpus_id
,
"/keep"
,
[]
,
nodes_2inmap
,
"PUT"
)
// $.doTimeout( 1000, function(){
// CRUD( corpus_id , "/group" , [] , nodes_2group , "PUT" )
// // $.doTimeout( 1000, function(){
// // window.location.reload()
// // });
// });
// });
// });
});
...
...
@@ -537,6 +553,7 @@ function CRUD( parent_id , action , nodes , args , http_method ) {
var
the_url
=
window
.
location
.
origin
+
"/api/node/"
+
parent_id
+
"/ngrams"
+
action
+
"/"
+
nodes
.
join
(
"+"
);
the_url
=
the_url
.
replace
(
/
\/
$/
,
""
);
//remove trailing slash
console
.
log
(
the_url
)
console
.
log
(
args
)
if
(
nodes
.
length
>
0
||
Object
.
keys
(
args
).
length
>
0
)
{
$
.
ajax
({
method
:
http_method
,
...
...
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