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
1b0d84fd
Commit
1b0d84fd
authored
Jun 06, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: better group removal in table
parent
ba57e9ab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
31 deletions
+82
-31
ngramlists.py
gargantext/views/api/ngramlists.py
+17
-0
NGrams_dyna_chart_and_table.js
static/lib/gargantext/NGrams_dyna_chart_and_table.js
+65
-31
No files found.
gargantext/views/api/ngramlists.py
View file @
1b0d84fd
...
@@ -206,6 +206,10 @@ class GroupChange(APIView):
...
@@ -206,6 +206,10 @@ class GroupChange(APIView):
# the others params are links to change
# the others params are links to change
couples
=
self
.
links_to_couples
(
params
)
couples
=
self
.
links_to_couples
(
params
)
# £debug
print
(
"==couples from url =================================++++="
)
print
(
couples
)
# local version of "insert if not exists" -------------------->8--------
# local version of "insert if not exists" -------------------->8--------
# (1) check already existing elements
# (1) check already existing elements
check_query
=
(
session
.
query
(
NodeNgramNgram
)
check_query
=
(
session
.
query
(
NodeNgramNgram
)
...
@@ -220,11 +224,20 @@ class GroupChange(APIView):
...
@@ -220,11 +224,20 @@ class GroupChange(APIView):
for
synonyms
in
check_query
.
all
():
for
synonyms
in
check_query
.
all
():
existing
[(
synonyms
.
ngram1_id
,
synonyms
.
ngram2_id
)]
=
True
existing
[(
synonyms
.
ngram1_id
,
synonyms
.
ngram2_id
)]
=
True
# £debug
print
(
"==existing"
)
print
(
existing
)
# (2) compute difference locally
# (2) compute difference locally
couples_to_add
=
[(
mform
,
sform
)
for
(
mform
,
sform
)
couples_to_add
=
[(
mform
,
sform
)
for
(
mform
,
sform
)
in
couples
in
couples
if
(
mform
,
sform
)
not
in
existing
]
if
(
mform
,
sform
)
not
in
existing
]
# £debug
print
(
"== couples_to_add =================================++++="
)
print
(
couples_to_add
)
# (3) add new groupings
# (3) add new groupings
bulk_insert
(
bulk_insert
(
NodeNgramNgram
,
NodeNgramNgram
,
...
@@ -255,6 +268,10 @@ class GroupChange(APIView):
...
@@ -255,6 +268,10 @@ class GroupChange(APIView):
# the others params are links to change
# the others params are links to change
couples_to_remove
=
self
.
links_to_couples
(
params
)
couples_to_remove
=
self
.
links_to_couples
(
params
)
# £debug
print
(
"==couples_to_remove=================================dd="
)
print
(
couples_to_remove
)
# remove selectively group_couples
# remove selectively group_couples
# using IN is correct in this case: list of ids is short and external
# using IN is correct in this case: list of ids is short and external
# see stackoverflow.com/questions/444475/
# see stackoverflow.com/questions/444475/
...
...
static/lib/gargantext/NGrams_dyna_chart_and_table.js
View file @
1b0d84fd
...
@@ -431,7 +431,9 @@ function saveActiveGroup() {
...
@@ -431,7 +431,9 @@ function saveActiveGroup() {
GroupsBuffer
.
_to_del
[
downgradedNgramId
]
=
CurrentGroups
[
"links"
][
downgradedNgramId
]
GroupsBuffer
.
_to_del
[
downgradedNgramId
]
=
CurrentGroups
[
"links"
][
downgradedNgramId
]
// locally
// locally
deleteInCurrentGroups
(
downgradedNgramId
,
false
)
// "false" <=> no need to change subform states
deleteInCurrentGroups
(
false
,
downgradedNgramId
)
// arg 1 "false" <=> no need to change subform states
// arg 3 no subforms <=> delete entire group
}
}
}
}
...
@@ -671,26 +673,24 @@ function removeSubform(ngramId) {
...
@@ -671,26 +673,24 @@ function removeSubform(ngramId) {
// in another group see comment at the top of script
// in another group see comment at the top of script
// special case: if removed form already was a subform it becomes independant
// special case: if removed form already was a subform it becomes independant
//
//
// (because the old mainform may be remaining in the new group, we set a
// (because the old mainform may be remaining in the new group)
// convention: entire previous group goes "to_delete" at 1st sub remove)
//
//
if
(
CurrentGroups
[
"subs"
][
ngramId
])
{
if
(
CurrentGroups
[
"subs"
][
ngramId
])
{
var
oldMainFormId
=
CurrentGroups
[
"subs"
][
ngramId
]
var
oldMainFormId
=
CurrentGroups
[
"subs"
][
ngramId
]
// it must
break the old group, mark for deletion
// it must
remove the subform from old group
// TODO make temporary
// TODO make temporary
// for DB
// for DB
GroupsBuffer
.
_to_del
[
oldMainFormId
]
=
CurrentGroups
[
"links"
]
[
ngramId
]
GroupsBuffer
.
_to_del
[
oldMainFormId
]
=
[
ngramId
]
// local consequences:
// local consequences:
deleteInCurrentGroups
(
oldMainFormId
,
true
)
var
subformInheritsState
=
true
// => they are all removed from CurrentGroups
deleteInCurrentGroups
(
subformInheritsState
,
oldMainFormId
,
[
ngramId
])
//
=> the removed subform and all others
from the old group
//
arg1 true => the removed subform
from the old group
//
get
a state (map/del/normal)
//
gets
a state (map/del/normal)
}
}
// ==========================================
// ==========================================
...
@@ -723,42 +723,76 @@ function removeSubform(ngramId) {
...
@@ -723,42 +723,76 @@ function removeSubform(ngramId) {
/**
/**
* Effects of deleting a mainform from the current groups
* Effects of deleting a mainform from the current groups
(client-side)
*
*
* => updates the global var CurrentGroups
* => updates the global var CurrentGroups
* => optionally triggers assignment of a state to the ex-subforms
*
*
* @param ngramId of a mainform
* @param inheritState boolean => updates the AjaxRecords[subformId].state
* @param inheritState boolean => updates the AjaxRecords[subformId].state
* @param ngramId of a mainform
* @param (optional) subforms array of subNgramIds (removes individual links)
* if absent: removes the whole group
*/
*/
function
deleteInCurrentGroups
(
ngramId
,
inheritState
)
{
function
deleteInCurrentGroups
(
inheritState
,
mainformId
,
subforms
)
{
var
wholeGroup
=
false
if
(
typeof
subforms
==
"undefined"
)
{
console
.
log
(
"deleteInCurrentGroups: no subforms specified: removing *entire* old group"
)
wholeGroup
=
true
}
if
(
inheritState
)
{
if
(
inheritState
)
{
// ex-subforms can inherit state from their previous mainform
// ex-subforms can inherit state from their previous mainform
var
implicitState
=
AjaxRecords
[
ngra
mId
].
state
var
implicitState
=
AjaxRecords
[
mainfor
mId
].
state
}
}
if
(
CurrentGroups
.
links
[
ngramId
])
{
var
subsToDel
=
[]
var
oldGroup
=
CurrentGroups
.
links
[
ngramId
]
if
(
wholeGroup
)
{
// deleting in reverse index
subsToDel
=
CurrentGroups
.
links
[
mainformId
]
for
(
var
i
in
oldGroup
)
{
}
var
subformId
=
oldGroup
[
i
]
else
{
delete
CurrentGroups
.
subs
[
subformId
]
subsToDel
=
subforms
}
if
(
inheritState
)
{
AjaxRecords
[
subformId
].
state
=
implicitState
// deleting in reverse index
// consequence:
for
(
var
i
in
subsToDel
)
{
// now OriginalNG.records[subformId].state
var
subformId
=
subsToDel
[
i
]
// is != AjaxRecords[subformId].state
// therefore the newly independant forms
// deleting in "subs"
// will be added to their new wordlist
delete
CurrentGroups
.
subs
[
subformId
]
}
if
(
inheritState
)
{
AjaxRecords
[
subformId
].
state
=
implicitState
// consequence:
// now OriginalNG.records[subformId].state
// is != AjaxRecords[subformId].state
// therefore the newly independant forms
// will be added to their new wordlist
}
}
// deleting in "links"
// deleting in "links"
delete
CurrentGroups
.
links
[
ngramId
]
if
(
!
wholeGroup
)
{
// remove 1 from links array (indexOf is ok b/c length always small)
var
i
=
CurrentGroups
[
"links"
][
mainformId
].
indexOf
(
subformId
)
CurrentGroups
[
"links"
][
mainformId
].
splice
(
i
,
1
)
// if it was the last of this group
if
(
CurrentGroups
[
"links"
][
mainformId
].
length
==
0
)
{
delete
CurrentGroups
[
"links"
][
mainformId
]
}
}
}
// deleting in "links" is simpler in this case
if
(
wholeGroup
)
{
delete
CurrentGroups
[
"links"
][
mainformId
]
}
}
}
}
/**
/**
* Adding links to the current groups
* Adding links to the current groups
(client-side)
*
*
* => updates the global var CurrentGroups
* => updates the global var CurrentGroups
*
*
...
...
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