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
a4b628e1
Commit
a4b628e1
authored
Jul 25, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
annotations: generalize/rationalize use of the new common function 'makeChainedCalls'
parent
3bf4f9c8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
123 additions
and
157 deletions
+123
-157
app.js
annotations/static/annotations/app.js
+16
-2
highlight.js
annotations/static/annotations/highlight.js
+27
-33
ngramlist.js
annotations/static/annotations/ngramlist.js
+80
-122
No files found.
annotations/static/annotations/app.js
View file @
a4b628e1
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
* Main function
* Main function
* GET the document node and all its ngrams
* GET the document node and all its ngrams
*/
*/
window
.
annotationsApp
.
run
(
function
(
$rootScope
)
{
window
.
annotationsApp
.
run
(
function
(
$rootScope
,
NgramListHttpService
)
{
// ex: projects/1/corpora/2/documents/9/
// ex: projects/1/corpora/2/documents/9/
// ex: projects/1/corpora/2/documents/9/focus=2677 (to highlight ngram 2677 more)
// ex: projects/1/corpora/2/documents/9/focus=2677 (to highlight ngram 2677 more)
var
path
=
window
.
location
.
pathname
.
match
(
/
\/
projects
\/(
.*
)\/
corpora
\/(
.*
)\/
documents
\/(
.*
)\/(?:
focus=
([
0-9,
]
+
))?
/
);
var
path
=
window
.
location
.
pathname
.
match
(
/
\/
projects
\/(
.*
)\/
corpora
\/(
.*
)\/
documents
\/(
.*
)\/(?:
focus=
([
0-9,
]
+
))?
/
);
...
@@ -40,8 +40,22 @@
...
@@ -40,8 +40,22 @@
$rootScope
.
focusNgrams
=
[]
$rootScope
.
focusNgrams
=
[]
// -------------------------------
// -------------------------------
// shared toolbox (functions useful for several modules) -------------------
// shared toolbox (functions useful for several modules) -------------------
$rootScope
.
mafonction
=
function
(
bidule
)
{
console
.
warn
(
bidule
)}
$rootScope
.
refresh
=
function
()
{
// Refresh the annotations
NgramListHttpService
.
get
(
{
'corpusId'
:
$rootScope
.
corpusId
,
'docId'
:
$rootScope
.
docId
},
function
(
data
)
{
$rootScope
.
annotations
=
data
[
$rootScope
.
corpusId
.
toString
()][
$rootScope
.
docId
.
toString
()];
$rootScope
.
refreshDisplay
();
},
function
(
data
)
{
console
.
error
(
"unable to refresh the list of ngrams"
);
}
);
}
// chained recursion to do several AJAX actions and then a callback (eg refresh)
// chained recursion to do several AJAX actions and then a callback (eg refresh)
$rootScope
.
makeChainedCalls
=
$rootScope
.
makeChainedCalls
=
...
...
annotations/static/annotations/highlight.js
View file @
a4b628e1
...
@@ -88,6 +88,8 @@
...
@@ -88,6 +88,8 @@
function
toggleMenu
(
context
,
annotation
)
{
function
toggleMenu
(
context
,
annotation
)
{
$timeout
(
function
()
{
$timeout
(
function
()
{
$scope
.
$apply
(
function
()
{
$scope
.
$apply
(
function
()
{
$scope
.
menuItems
=
[];
// init empty menu
var
mainlist_id
=
$rootScope
.
listIds
.
MAINLIST
;
var
mainlist_id
=
$rootScope
.
listIds
.
MAINLIST
;
var
stoplist_id
=
$rootScope
.
listIds
.
STOPLIST
;
var
stoplist_id
=
$rootScope
.
listIds
.
STOPLIST
;
var
maplist_id
=
$rootScope
.
listIds
.
MAPLIST
;
var
maplist_id
=
$rootScope
.
listIds
.
MAPLIST
;
...
@@ -128,9 +130,11 @@
...
@@ -128,9 +130,11 @@
// NB: remember that shown mainlist items are actually main 'without map'
// NB: remember that shown mainlist items are actually main 'without map'
// otherwise the menu for mainlist items can hide the menu for map items
// otherwise the menu for mainlist items can hide the menu for map items
if
(
$rootScope
.
lists
[
annotation
.
list_id
]
==
"MAPLIST"
)
{
var
sourceList
=
$rootScope
.
lists
[
annotation
.
list_id
]
$scope
.
menuItems
.
push
({
if
(
sourceList
==
"MAPLIST"
)
{
$scope
.
menuItems
=
[
{
// "tgtListName" is just used to render the GUI explanation
// "tgtListName" is just used to render the GUI explanation
'tgtListName'
:
'STOPLIST'
,
'tgtListName'
:
'STOPLIST'
,
// crudCalls is an array of rest/DB actions
// crudCalls is an array of rest/DB actions
...
@@ -143,18 +147,20 @@
...
@@ -143,18 +147,20 @@
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
stoplist_id
,
'ngramIdList'
:
targetId
}
}
'params'
:
{
'listId'
:
stoplist_id
,
'ngramIdList'
:
targetId
}
}
]
]
}
);
}
,
$scope
.
menuItems
.
push
(
{
{
'tgtListName'
:
'MAINLIST'
,
'tgtListName'
:
'MAINLIST'
,
'crudCalls'
:[
'crudCalls'
:[
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
'params'
:
{
'listId'
:
maplist_id
,
'ngramIdList'
:
targetId
}
}
'params'
:
{
'listId'
:
maplist_id
,
'ngramIdList'
:
targetId
}
}
]
]
});
}
];
}
}
else
if
(
$rootScope
.
lists
[
annotation
.
list_id
]
==
"MAINLIST"
)
{
else
if
(
sourceList
==
"MAINLIST"
)
{
$scope
.
menuItems
.
push
({
$scope
.
menuItems
=
[
{
'tgtListName'
:
"STOPLIST"
,
'tgtListName'
:
"STOPLIST"
,
'crudCalls'
:[
'crudCalls'
:[
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
...
@@ -162,18 +168,20 @@
...
@@ -162,18 +168,20 @@
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
stoplist_id
,
'ngramIdList'
:
targetId
}
}
'params'
:
{
'listId'
:
stoplist_id
,
'ngramIdList'
:
targetId
}
}
]
]
}
);
}
,
$scope
.
menuItems
.
push
(
{
{
'tgtListName'
:
"MAPLIST"
,
'tgtListName'
:
"MAPLIST"
,
'crudCalls'
:[
'crudCalls'
:[
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
maplist_id
,
'ngramIdList'
:
targetId
}
}
'params'
:
{
'listId'
:
maplist_id
,
'ngramIdList'
:
targetId
}
}
]
]
});
}
];
}
}
else
if
(
$rootScope
.
lists
[
annotation
.
list_id
]
==
"STOPLIST"
)
{
else
if
(
sourceList
==
"STOPLIST"
)
{
$scope
.
menuItems
.
push
({
$scope
.
menuItems
=
[
{
'tgtListName'
:
"MAINLIST"
,
'tgtListName'
:
"MAINLIST"
,
'crudCalls'
:[
'crudCalls'
:[
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
...
@@ -181,8 +189,8 @@
...
@@ -181,8 +189,8 @@
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
mainlist_id
,
'ngramIdList'
:
targetId
}
}
'params'
:
{
'listId'
:
mainlist_id
,
'ngramIdList'
:
targetId
}
}
]
]
});
},
$scope
.
menuItems
.
push
(
{
{
'tgtListName'
:
"MAPLIST"
,
'tgtListName'
:
"MAPLIST"
,
'crudCalls'
:[
'crudCalls'
:[
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
...
@@ -192,7 +200,8 @@
...
@@ -192,7 +200,8 @@
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
maplist_id
,
'ngramIdList'
:
targetId
}
}
'params'
:
{
'listId'
:
maplist_id
,
'ngramIdList'
:
targetId
}
}
]
]
});
}
];
}
}
// show the menu
// show the menu
...
@@ -305,28 +314,13 @@
...
@@ -305,28 +314,13 @@
* (1 intention => list of actions => MainApiChangeNgramHttpService CRUDs)
* (1 intention => list of actions => MainApiChangeNgramHttpService CRUDs)
* post/delete
* post/delete
*/
*/
$scope
.
onMenuClick
=
function
(
$event
,
c
rudCalls
)
{
$scope
.
onMenuClick
=
function
(
$event
,
todoC
rudCalls
)
{
// console.warn('in onMenuClick')
// console.warn('in onMenuClick')
// console.warn('item.crudCalls', crudCalls)
// console.warn('item.crudCalls', crudCalls)
var
lastCallback
=
function
()
{
// Refresh the annotationss
NgramListHttpService
.
get
(
{
'corpusId'
:
$rootScope
.
corpusId
,
'docId'
:
$rootScope
.
docId
},
function
(
data
)
{
$rootScope
.
annotations
=
data
[
$rootScope
.
corpusId
.
toString
()][
$rootScope
.
docId
.
toString
()];
$rootScope
.
refreshDisplay
();
},
function
(
data
)
{
console
.
error
(
"unable to refresh the list of ngrams"
);
}
);
}
// run the loop by calling the initial recursion step
// run the loop by calling the initial recursion step
$rootScope
.
makeChainedCalls
(
0
,
crudCalls
,
lastCallback
)
$rootScope
.
makeChainedCalls
(
0
,
todoCrudCalls
,
$rootScope
.
refresh
)
// syntax: (step_to_run
, list_of_steps,
lastCallback)
// syntax: (step_to_run
_first, list_of_steps,
lastCallback)
// hide the highlighted text and the menu element
// hide the highlighted text and the menu element
$
(
".text-panel"
).
removeClass
(
"selection"
);
$
(
".text-panel"
).
removeClass
(
"selection"
);
...
...
annotations/static/annotations/ngramlist.js
View file @
a4b628e1
...
@@ -21,89 +21,37 @@
...
@@ -21,89 +21,37 @@
if
(
listName
==
'MAPLIST'
)
{
if
(
listName
==
'MAPLIST'
)
{
crudActions
=
[
crudActions
=
[
[
"delete"
,
thisListId
]
// only 'remove' is needed here
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
'params'
:
{
'listId'
:
thisListId
,
'ngramIdList'
:
thisNgramId
}
}
]
]
}
}
else
if
(
listName
==
'MAINLIST'
)
{
else
if
(
listName
==
'MAINLIST'
)
{
crudActions
=
[
crudActions
=
[
[
"delete"
,
thisListId
],
// remove
[
"put"
,
$rootScope
.
listIds
.
STOPLIST
],
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
'params'
:
{
'listId'
:
thisListId
,
'ngramIdList'
:
thisNgramId
}
},
// consequence: add to opposite list
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
$rootScope
.
listIds
.
STOPLIST
,
'ngramIdList'
:
thisNgramId
}
}
]
]
}
}
else
if
(
listName
==
'STOPLIST'
)
{
else
if
(
listName
==
'STOPLIST'
)
{
crudActions
=
[
crudActions
=
[
[
"delete"
,
thisListId
],
// remove
[
"put"
,
$rootScope
.
listIds
.
MAINLIST
],
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
]
'params'
:
{
'listId'
:
thisListId
,
'ngramIdList'
:
thisNgramId
}
},
// consequence: add to opposite list
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
$rootScope
.
listIds
.
MAINLIST
,
'ngramIdList'
:
thisNgramId
}
}
]
}
}
// console.log(crudActions)
// console.log(crudActions)
// using recursion to make chained calls,
// using recursion to make chained calls,
// todo factorize with highlight.js
var
lastCallback
=
function
()
{
// Refresh the annotationss
NgramListHttpService
.
get
(
{
'corpusId'
:
$rootScope
.
corpusId
,
'docId'
:
$rootScope
.
docId
},
function
(
data
)
{
// $rootScope.annotations
// ----------------------
// is the union of all lists, one being later "active"
// (then used for left-side flatlist AND inline annots)
$rootScope
.
annotations
=
data
[
$rootScope
.
corpusId
.
toString
()][
$rootScope
.
docId
.
toString
()];
// TODO £NEW : lookup obj[list_id][term_text] = {terminfo}
// $rootScope.lookup =
$rootScope
.
refreshDisplay
();
},
function
(
data
)
{
console
.
error
(
"unable to refresh the list of ngrams"
);
}
);
}
// chained recursion to do several actions then callback (eg refresh)
function
makeChainedCalls
(
i
,
listOfActions
,
finalCallback
)
{
// each action couple has 2 elts
var
action
=
listOfActions
[
i
][
0
]
var
listId
=
listOfActions
[
i
][
1
]
MainApiChangeNgramHttpService
[
action
](
{
'listId'
:
listId
,
'ngramIdList'
:
thisNgramId
},
// on success
function
(
data
)
{
// case NEXT
// ----
// when chained actions
if
(
listOfActions
.
length
>
i
+
1
)
{
// console.log("calling next action ("+(i+1)+")")
// ==============================================
makeChainedCalls
(
i
+
1
,
listOfActions
,
finalCallback
)
// ==============================================
}
// case LAST
// ------
// when last action
else
{
finalCallback
()
}
},
// on error
function
(
data
)
{
console
.
error
(
"unable to edit the Ngram
\"
"
+
ngramText
+
"
\"
"
+
"(ngramId "
+
ngramId
+
")"
+
"at crud no "
+
i
+
" ("
+
action
+
" on list "
+
listId
+
")"
);
}
);
}
// run the loop by calling the initial recursion step
// run the loop by calling the initial recursion step
makeChainedCalls
(
0
,
crudActions
,
lastCallback
)
$rootScope
.
makeChainedCalls
(
0
,
crudActions
,
$rootScope
.
refresh
)
};
};
}]);
}]);
...
@@ -184,64 +132,74 @@
...
@@ -184,64 +132,74 @@
if
(
already_in_list
)
{
return
;
}
if
(
already_in_list
)
{
return
;
}
// ---------------------------------------------------------------
// ---------------------------------------------------------------
var
listName
=
$rootScope
.
lists
[
listId
]
alert
(
"listId: "
+
listId
+
"
\n
listName: "
+
listName
)
console
.
log
(
"dir $rootScope :"
)
console
.
dir
(
$rootScope
)
// run the loop by calling the initial recursion step
// $rootScope.makeChainedCalls(0, crudCalls, lastCallback)
// AddNgram
// AddNgram
// --------
// --------
// creation will return an ngramId
// creation will return an ngramId
// (checks if there's a preexisting ngramId for this value
// (checks if there's a preexisting ngramId for this value
// otherwise creates a new one and indexes the ngram in corpus)
// otherwise creates a new one and indexes the ngram in corpus)
MainApiAddNgramHttpService
.
put
(
//
MainApiAddNgramHttpService.put(
{
//
{
// text <=> str to create the new ngram
//
// text <=> str to create the new ngram
'text'
:
value
,
//
'text': value,
'corpusId'
:
$rootScope
.
corpusId
//
'corpusId': $rootScope.corpusId
},
//
},
// on AddNgram success
//
// on AddNgram success
function
(
data
)
{
//
function(data) {
var
newNgramId
=
data
.
id
//
var newNgramId = data.id
console
.
log
(
"OK created new ngram for '"
+
value
+
"' with id: "
+
newNgramId
)
//
console.log("OK created new ngram for '"+value+"' with id: "+newNgramId)
//
// ChangeNgram
//
// ChangeNgram
// -----------
//
// -----------
// add to listId after creation
//
// add to listId after creation
// TODO: if maplist => also add to miam
//
// TODO: if maplist => also add to miam
MainApiChangeNgramHttpService
[
"put"
](
//
MainApiChangeNgramHttpService["put"](
{
//
{
'listId'
:
listId
,
//
'listId': listId,
'ngramIdList'
:
newNgramId
//
'ngramIdList': newNgramId
},
//
},
// on ChangeNgram success
//
// on ChangeNgram success
function
(
data
)
{
//
function(data) {
// Refresh the annotations (was broken: TODO FIX)
//
// Refresh the annotations (was broken: TODO FIX)
console
.
warn
(
"refresh attempt"
);
//
console.warn("refresh attempt");
angular
.
element
(
inputEltId
).
val
(
""
);
// what for ???
//
angular.element(inputEltId).val(""); // what for ???
NgramListHttpService
.
get
(
//
NgramListHttpService.get(
{
//
{
'corpusId'
:
$rootScope
.
corpusId
,
//
'corpusId': $rootScope.corpusId,
'docId'
:
$rootScope
.
docId
//
'docId': $rootScope.docId
},
//
},
// on refresh success
//
// on refresh success
function
(
data
)
{
//
function(data) {
$rootScope
.
annotations
=
data
[
$rootScope
.
corpusId
.
toString
()][
$rootScope
.
docId
.
toString
()];
//
$rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
$rootScope
.
refreshDisplay
();
//
$rootScope.refreshDisplay();
},
//
},
// on refresh error
//
// on refresh error
function
(
data
)
{
//
function(data) {
console
.
error
(
"unable to get the list of ngrams"
);
//
console.error("unable to get the list of ngrams");
}
//
}
);
//
);
},
//
},
// on ChangeNgram error
//
// on ChangeNgram error
function
(
data
)
{
//
function(data) {
console
.
error
(
"unable to edit the Ngram"
+
ngramId
+
") on list "
+
listId
+
")"
);
//
console.error("unable to edit the Ngram"+ngramId+") on list "+listId+")");
}
//
}
);
//
);
},
//
},
// on AddNgram error
//
// on AddNgram error
function
(
data
)
{
//
function(data) {
angular
.
element
(
inputEltId
).
parent
().
addClass
(
"has-error"
);
//
angular.element(inputEltId).parent().addClass("has-error");
console
.
error
(
"error adding Ngram "
+
value
);
//
console.error("error adding Ngram "+ value);
}
//
}
);
//
);
};
// onListSubmit
};
// onListSubmit
}]);
}]);
...
...
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