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
bb6fc256
Commit
bb6fc256
authored
Jul 22, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FIX] reconnect the context menu 'add ngram' in annotations view
parent
b4f866ce
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
304 additions
and
280 deletions
+304
-280
app.css
annotations/static/annotations/app.css
+0
-2
app.js
annotations/static/annotations/app.js
+97
-0
highlight.js
annotations/static/annotations/highlight.js
+111
-143
http.js
annotations/static/annotations/http.js
+22
-39
ngramlist.js
annotations/static/annotations/ngramlist.js
+68
-45
main.html
annotations/templates/annotations/main.html
+4
-1
urls.py
annotations/urls.py
+1
-1
views.py
annotations/views.py
+1
-49
No files found.
annotations/static/annotations/app.css
View file @
bb6fc256
...
@@ -133,8 +133,6 @@
...
@@ -133,8 +133,6 @@
background
:
white
;
background
:
white
;
font-size
:
0.8em
;
font-size
:
0.8em
;
font-weight
:
600
;
font-weight
:
600
;
-webkit-box-shadow
:
1px
1px
2px
rgba
(
0
,
0
,
0
,
0.5
);
-moz-box-shadow
:
1px
1px
2px
rgba
(
0
,
0
,
0
,
0.5
);
box-shadow
:
1px
1px
2px
rgba
(
0
,
0
,
0
,
0.5
);
box-shadow
:
1px
1px
2px
rgba
(
0
,
0
,
0
,
0.5
);
}
}
...
...
annotations/static/annotations/app.js
View file @
bb6fc256
...
@@ -26,10 +26,107 @@
...
@@ -26,10 +26,107 @@
// 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,
]
+
))?
/
);
// shared vars -------------------
$rootScope
.
projectId
=
path
[
1
];
$rootScope
.
projectId
=
path
[
1
];
$rootScope
.
corpusId
=
path
[
2
];
$rootScope
.
corpusId
=
path
[
2
];
$rootScope
.
docId
=
path
[
3
];
$rootScope
.
docId
=
path
[
3
];
$rootScope
.
focusNgram
=
path
[
4
];
$rootScope
.
focusNgram
=
path
[
4
];
// -------------------------------
// shared toolbox (functions useful for several modules) -------------------
$rootScope
.
mafonction
=
function
(
bidule
)
{
console
.
warn
(
bidule
)}
// chained recursion to do several AJAX actions and then a callback (eg refresh)
$rootScope
.
makeChainedCalls
=
function
(
i
,
listOfCalls
,
finalCallback
,
lastCache
)
{
var
callDetails
=
listOfCalls
[
i
]
console
.
log
(
">> calling ajax call ("
+
(
i
+
1
)
+
"/"
+
listOfCalls
.
length
+
")"
)
// each callDetails object describes the Ajax call
// and passes the required functions and arguments
// via 3 properties: service, action, params
// ex: callDetails = {
// 'service' : MainApiChangeNgramHttpService,
// 'action' : 'delete'
// 'params' : { 'listId': ..., 'ngramIdList':...}
// there is an optional 4th slot: the dataPropertiesToCache directive
//
// 'dataPropertiesToCache' : ['id'] <== means that on call success
// we will store data.id into
// cache.id for next calls
// }
var
service
=
callDetails
[
'service'
]
var
params
=
callDetails
[
'params'
]
var
action
=
callDetails
[
'action'
]
// cache if we need to store properties of data response for next calls
var
cache
=
{}
if
(
lastCache
)
cache
=
lastCache
// and interpolation of params with this current cache
for
(
var
key
in
params
)
{
var
val
=
params
[
key
]
if
(
typeof
val
==
"object"
&&
val
[
"fromCache"
])
{
var
propToRead
=
val
[
"fromCache"
]
// console.log("reading from cache: response data property "
// +propToRead+" ("+cache[propToRead]+")")
params
[
key
]
=
cache
[
propToRead
]
}
}
// Now we run the call
// ex:
// service action
// vvvvv vvvv
// MainApiChangeNgramHttpService["delete"](
// params >>> {'listId': listId, 'ngramIdList': ngramId},
// onsuccess(), onfailure() )
service
[
action
](
params
,
// on success
function
(
data
)
{
// console.log("SUCCESS:" + action)
// console.log("listOfCalls.length:" + listOfCalls.length)
// console.log("i+1:" + i+1)
// case NEXT
// ----
// when chained actions
if
(
listOfCalls
.
length
>
i
+
1
)
{
// if we need to store anything it's the right moment
for
(
var
k
in
callDetails
[
'dataPropertiesToCache'
])
{
var
prop
=
callDetails
[
'dataPropertiesToCache'
][
k
]
// console.log("storing in cache: response data property "
// +prop+" ("+data[prop]+")")
cache
[
prop
]
=
data
[
prop
]
}
// ======= recursive call for next action in list ================
$rootScope
.
makeChainedCalls
(
i
+
1
,
listOfCalls
,
finalCallback
,
cache
)
// ================================================================
}
// case LAST
// ------
// when last action
else
{
console
.
log
(
">> calling refresh"
)
finalCallback
()
}
},
// on error
function
(
data
)
{
console
.
error
(
"unable to call ajax no "
+
i
+
" with service "
+
service
.
name
+
" (http "
+
action
+
" with args "
+
JSON
.
stringify
(
params
)
+
")"
);
}
);
}
// -------------------------------------------------------------------------
// debug
// debug
// console.log("==> $rootScope <==")
// console.log("==> $rootScope <==")
...
...
annotations/static/annotations/highlight.js
View file @
bb6fc256
...
@@ -31,9 +31,10 @@
...
@@ -31,9 +31,10 @@
$scope
.
keyword
=
keyword
;
$scope
.
keyword
=
keyword
;
}
}
// this onClick only works for existing annotations
$scope
.
onClick
=
function
(
e
)
{
$scope
.
onClick
=
function
(
e
)
{
$rootScope
.
$emit
(
"positionAnnotationMenu"
,
e
.
pageX
,
e
.
pageY
);
$rootScope
.
$emit
(
"toggleAnnotationMenu"
,
$scope
.
keyword
);
$rootScope
.
$emit
(
"toggleAnnotationMenu"
,
$scope
.
keyword
);
$rootScope
.
$emit
(
"positionAnnotationMenu"
,
e
.
pageX
,
e
.
pageY
);
// $rootScope.$emit("toggleAnnotationMenu", {'uuid':42,'list_id':1,'text':'gotcha'});
// $rootScope.$emit("toggleAnnotationMenu", {'uuid':42,'list_id':1,'text':'gotcha'});
// console.log("EMIT toggleAnnotationMenu with \$scope.keyword: '" + $scope.keyword.text +"'")
// console.log("EMIT toggleAnnotationMenu with \$scope.keyword: '" + $scope.keyword.text +"'")
e
.
stopPropagation
();
e
.
stopPropagation
();
...
@@ -44,8 +45,9 @@
...
@@ -44,8 +45,9 @@
* Controls the menu over the current mouse selection
* Controls the menu over the current mouse selection
*/
*/
annotationsAppHighlight
.
controller
(
'TextSelectionMenuController'
,
annotationsAppHighlight
.
controller
(
'TextSelectionMenuController'
,
[
'$scope'
,
'$rootScope'
,
'$element'
,
'$timeout'
,
'MainApiChangeNgramHttpService'
,
'NgramListHttpService'
,
[
'$scope'
,
'$rootScope'
,
'$element'
,
'$timeout'
,
'MainApiChangeNgramHttpService'
,
'MainApiAddNgramHttpService'
,
'NgramListHttpService'
,
function
(
$scope
,
$rootScope
,
$element
,
$timeout
,
MainApiChangeNgramHttpService
,
NgramListHttpService
)
{
function
(
$scope
,
$rootScope
,
$element
,
$timeout
,
MainApiChangeNgramHttpService
,
MainApiAddNgramHttpService
,
NgramListHttpService
)
{
/*
/*
* Universal text selection
* Universal text selection
*/
*/
...
@@ -106,7 +108,12 @@
...
@@ -106,7 +108,12 @@
// console.log("toggleMenu with \$scope.selection_text: '" + JSON.stringify($scope.selection_text) +"'") ;
// console.log("toggleMenu with \$scope.selection_text: '" + JSON.stringify($scope.selection_text) +"'") ;
if
(
angular
.
isObject
(
annotation
)
&&
!
$element
.
hasClass
(
'menu-is-opened'
))
{
if
(
angular
.
isObject
(
annotation
)
&&
!
$element
.
hasClass
(
'menu-is-opened'
))
{
// existing ngram
// existing ngram
var
ngramId
=
annotation
.
uuid
var
mainformId
=
annotation
.
group
var
targetId
=
mainformId
?
mainformId
:
ngramId
// Context menu proposes 2 things for each item of list A
// Context menu proposes 2 things for each item of list A
// - adding/moving to other lists B or C
// - adding/moving to other lists B or C
...
@@ -122,22 +129,26 @@
...
@@ -122,22 +129,26 @@
// 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"
)
{
if
(
$rootScope
.
lists
[
annotation
.
list_id
]
==
"MAPLIST"
)
{
console
.
log
(
$scope
)
$scope
.
menuItems
.
push
({
$scope
.
menuItems
.
push
({
// "tgtListName" is just used to render the GUI explanation
// "tgtListName" is just used to render the GUI explanation
'tgtListName'
:
'STOPLIST'
,
'tgtListName'
:
'STOPLIST'
,
// crud
Action
s is an array of rest/DB actions
// crud
Call
s is an array of rest/DB actions
// (consequences of the intention)
// (consequences of the intention)
'crudActions'
:[
'crudCalls'
:[
[
"delete"
,
maplist_id
],
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
[
"delete"
,
mainlist_id
],
'params'
:
{
'listId'
:
maplist_id
,
'ngramIdList'
:
targetId
}
},
[
"put"
,
stoplist_id
]
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
'params'
:
{
'listId'
:
mainlist_id
,
'ngramIdList'
:
targetId
}
},
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
stoplist_id
,
'ngramIdList'
:
targetId
}
}
]
]
});
});
$scope
.
menuItems
.
push
({
$scope
.
menuItems
.
push
({
'tgtListName'
:
'MAINLIST'
,
'tgtListName'
:
'MAINLIST'
,
'crudActions'
:[
'crudCalls'
:[
[
"delete"
,
maplist_id
]
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
'params'
:
{
'listId'
:
maplist_id
,
'ngramIdList'
:
targetId
}
}
]
]
});
});
}
}
...
@@ -145,15 +156,18 @@
...
@@ -145,15 +156,18 @@
else
if
(
$rootScope
.
lists
[
annotation
.
list_id
]
==
"MAINLIST"
)
{
else
if
(
$rootScope
.
lists
[
annotation
.
list_id
]
==
"MAINLIST"
)
{
$scope
.
menuItems
.
push
({
$scope
.
menuItems
.
push
({
'tgtListName'
:
"STOPLIST"
,
'tgtListName'
:
"STOPLIST"
,
'crudActions'
:[
'crudCalls'
:[
[
"delete"
,
mainlist_id
],
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
[
"put"
,
stoplist_id
]
'params'
:
{
'listId'
:
mainlist_id
,
'ngramIdList'
:
targetId
}
},
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
stoplist_id
,
'ngramIdList'
:
targetId
}
}
]
]
});
});
$scope
.
menuItems
.
push
({
$scope
.
menuItems
.
push
({
'tgtListName'
:
"MAPLIST"
,
'tgtListName'
:
"MAPLIST"
,
'crudActions'
:[
'crudCalls'
:[
[
"put"
,
maplist_id
]
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
maplist_id
,
'ngramIdList'
:
targetId
}
}
]
]
});
});
}
}
...
@@ -161,46 +175,79 @@
...
@@ -161,46 +175,79 @@
else
if
(
$rootScope
.
lists
[
annotation
.
list_id
]
==
"STOPLIST"
)
{
else
if
(
$rootScope
.
lists
[
annotation
.
list_id
]
==
"STOPLIST"
)
{
$scope
.
menuItems
.
push
({
$scope
.
menuItems
.
push
({
'tgtListName'
:
"MAINLIST"
,
'tgtListName'
:
"MAINLIST"
,
'crudActions'
:[
'crudCalls'
:[
[
"delete"
,
stoplist_id
],
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
[
"put"
,
mainlist_id
]
'params'
:
{
'listId'
:
stoplist_id
,
'ngramIdList'
:
targetId
}
},
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
mainlist_id
,
'ngramIdList'
:
targetId
}
}
]
]
});
});
$scope
.
menuItems
.
push
({
$scope
.
menuItems
.
push
({
'tgtListName'
:
"MAPLIST"
,
'tgtListName'
:
"MAPLIST"
,
'crudActions'
:[
'crudCalls'
:[
[
"delete"
,
stoplist_id
],
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'delete'
,
[
"put"
,
mainlist_id
],
'params'
:
{
'listId'
:
stoplist_id
,
'ngramIdList'
:
targetId
}
},
[
"put"
,
maplist_id
]
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
mainlist_id
,
'ngramIdList'
:
targetId
}
},
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
maplist_id
,
'ngramIdList'
:
targetId
}
}
]
]
});
});
}
}
// show the menu
// show the menu
$element
.
fadeIn
(
10
0
);
$element
.
fadeIn
(
5
0
);
$element
.
addClass
(
'menu-is-opened'
);
$element
.
addClass
(
'menu-is-opened'
);
}
}
// -------8<------ "add" actions for non-existing ngram ------
// "add" actions for non-existing ngram
// else if (annotation.trim() !== "" && !$element.hasClass('menu-is-opened')) {
else
if
(
annotation
.
trim
()
!==
""
&&
!
$element
.
hasClass
(
'menu-is-opened'
))
{
// // new ngram
var
newNgramText
=
annotation
.
trim
()
// $scope.menuItems = [
// new ngram (first call creates then like previous case for list)
// {
$scope
.
menuItems
.
push
({
// 'action': 'post',
'comment'
:
"Create and add to STOPLIST"
,
// 'listId': miamlist_id,
'tgtListName'
:
"STOPLIST"
,
// 'verb': 'Add to',
'crudCalls'
:[
// 'listName': $rootScope.lists[miamlist_id]
{
'service'
:
MainApiAddNgramHttpService
,
'action'
:
'put'
,
// }
'params'
:
{
'ngramStr'
:
newNgramText
,
corpusId
:
$rootScope
.
corpusId
},
// ];
'dataPropertiesToCache'
:
[
'id'
]
},
// // show the menu
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
// $element.fadeIn(100);
'params'
:
{
'listId'
:
stoplist_id
,
'ngramIdList'
:
{
'fromCache'
:
'id'
}
}
}
// $element.addClass('menu-is-opened');
]
// }
})
;
// -------8<--------------------------------------------------
$scope
.
menuItems
.
push
({
'comment'
:
"Create and add to MAINLIST"
,
'tgtListName'
:
"MAINLIST"
,
'crudCalls'
:[
{
'service'
:
MainApiAddNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'ngramStr'
:
newNgramText
,
corpusId
:
$rootScope
.
corpusId
},
'dataPropertiesToCache'
:
[
'id'
]
},
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
mainlist_id
,
'ngramIdList'
:
{
'fromCache'
:
'id'
}
}
}
]
})
;
$scope
.
menuItems
.
push
({
'comment'
:
"Create and add to MAPLIST"
,
'tgtListName'
:
"MAPLIST"
,
'crudCalls'
:[
{
'service'
:
MainApiAddNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'ngramStr'
:
newNgramText
,
corpusId
:
$rootScope
.
corpusId
},
'dataPropertiesToCache'
:
[
'id'
]
},
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
mainlist_id
,
'ngramIdList'
:
{
'fromCache'
:
'id'
}
}
},
{
'service'
:
MainApiChangeNgramHttpService
,
'action'
:
'put'
,
'params'
:
{
'listId'
:
maplist_id
,
'ngramIdList'
:
{
'fromCache'
:
'id'
}
}
}
]
})
;
// show the menu
$element
.
fadeIn
(
50
);
$element
.
addClass
(
'menu-is-opened'
);
}
else
{
else
{
$scope
.
menuItems
=
[];
// close the menu
// close the menu
$element
.
fadeOut
(
100
);
$scope
.
menuItems
=
[];
$element
.
fadeOut
(
50
);
$element
.
removeClass
(
'menu-is-opened'
);
$element
.
removeClass
(
'menu-is-opened'
);
}
}
});
});
...
@@ -229,8 +276,9 @@
...
@@ -229,8 +276,9 @@
/*
/*
* Finish positioning the menu then display the menu
* Finish positioning the menu then display the menu
*/
*/
$
(
".text-container"
).
mouseup
(
function
(){
$
(
".text-container"
).
mouseup
(
function
(
e
){
$
(
".text-container"
).
unbind
(
"mousemove"
,
positionMenu
);
$
(
".text-container"
).
unbind
(
"mousemove"
,
positionMenu
);
$rootScope
.
$emit
(
"positionAnnotationMenu"
,
e
.
pageX
,
e
.
pageY
);
toggleSelectionHighlight
(
selection
.
toString
().
trim
());
toggleSelectionHighlight
(
selection
.
toString
().
trim
());
toggleMenu
(
null
,
selection
.
toString
().
trim
());
toggleMenu
(
null
,
selection
.
toString
().
trim
());
});
});
...
@@ -257,16 +305,9 @@
...
@@ -257,16 +305,9 @@
* (1 intention => list of actions => MainApiChangeNgramHttpService CRUDs)
* (1 intention => list of actions => MainApiChangeNgramHttpService CRUDs)
* post/delete
* post/delete
*/
*/
$scope
.
onMenuClick
=
function
(
$event
,
crud
Action
s
)
{
$scope
.
onMenuClick
=
function
(
$event
,
crud
Call
s
)
{
// console.warn('in onMenuClick')
// console.warn('in onMenuClick')
// console.warn('item.crudActions')
// console.warn('item.crudCalls', crudCalls)
// console.warn(crudActions)
if
(
angular
.
isObject
(
$scope
.
selection_text
))
{
var
ngramId
=
$scope
.
selection_text
.
uuid
var
mainformId
=
$scope
.
selection_text
.
group
var
ngramText
=
$scope
.
selection_text
.
text
var
lastCallback
=
function
()
{
var
lastCallback
=
function
()
{
// Refresh the annotationss
// Refresh the annotationss
...
@@ -278,87 +319,14 @@
...
@@ -278,87 +319,14 @@
$rootScope
.
refreshDisplay
();
$rootScope
.
refreshDisplay
();
},
},
function
(
data
)
{
function
(
data
)
{
console
.
error
(
"unable to get the list of ngrams"
);
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
]
console
.
log
(
"===>"
+
action
+
"<==="
)
MainApiChangeNgramHttpService
[
action
](
{
'listId'
:
listId
,
'ngramIdList'
:
mainformId
?
mainformId
:
ngramId
},
// 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
,
crudCalls
,
lastCallback
)
}
// syntax: (step_to_run, list_of_steps, lastCallback)
// TODO: first action creates then like previous case
// else if ($scope.selection_text.trim() !== "") {
// // new annotation from selection
// NgramHttpService.post(
// {
// 'listId': listId,
// 'ngramId': 'create'
// },
// {
// 'text': $scope.selection_text.trim()
// }, function(data) {
// // 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 get the list of ngrams");
// }
// );
// }, function(data) {
// console.error("unable to edit the Ngram " + $scope.selection_text);
// }
// );
// }
// 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/http.js
View file @
bb6fc256
...
@@ -86,48 +86,31 @@
...
@@ -86,48 +86,31 @@
);
);
});
});
/*
/*
* NgramHttpService: Create, modify or delete 1 Ngram
* MainApiAddNgramHttpService: Create and index a new ngram
* =================
* ===========================
*
* route: PUT api/ngrams?text=mynewngramstring&corpus=corpus_id
* TODO add a create case separately and then remove service
* ------
*
* NB : replaced by external api: (MainApiChangeNgramHttpService)
* api/ngramlists/change?list=LISTID&ngrams=ID1,ID2..
*
* old logic:
* ----------
* if new ngram
* -> ngram_id will be "create"
* -> route: annotations/lists/@node_id/ngrams/create
* -> will land on views.NgramCreate
*
* else:
* -> ngram_id is a real ngram id
* -> route: annotations/lists/@node_id/ngrams/@ngram_id
* -> will land on views.NgramEdit
*
*
*/
*/
// http.factory('NgramHttpService', function ($resource) {
http
.
factory
(
'MainApiAddNgramHttpService'
,
function
(
$resource
)
{
// return $resource(
return
$resource
(
// window.ANNOTATION_API_URL + 'lists/:listId/ngrams/:ngramId',
// adding explicit "http://" b/c this a cross origin request
// {
'http://'
+
window
.
GARG_ROOT_URL
// listId: '@listId',
+
"/api/ngrams?text=:ngramStr&corpus=:corpusId"
,
// ngramId: '@id'
{
// },
ngramStr
:
'@ngramStr'
,
// {
corpusId
:
'@corpusId'
// post: {
},
// method: 'POST',
{
// params: {'listId': '@listId', 'ngramId': '@ngramId'}
put
:
{
// },
method
:
'PUT'
,
// delete: {
params
:
{
listId
:
'@listId'
,
ngramIdList
:
'@ngramIdList'
}
// method: 'DELETE',
}
// params: {'listId': '@listId', 'ngramId': '@ngramId'}
}
// }
);
// }
});
// );
// });
/*
/*
* MainApiChangeNgramHttpService: Add/remove ngrams from lists
* MainApiChangeNgramHttpService: Add/remove ngrams from lists
...
...
annotations/static/annotations/ngramlist.js
View file @
bb6fc256
...
@@ -142,12 +142,16 @@
...
@@ -142,12 +142,16 @@
}
}
};
};
});
});
/*
/*
* new NGram from the user input
* new NGram from the user input
*/
*/
annotationsAppNgramList
.
controller
(
'NgramInputController'
,
annotationsAppNgramList
.
controller
(
'NgramInputController'
,
[
'$scope'
,
'$rootScope'
,
'$element'
,
'NgramListHttpService'
,
[
'$scope'
,
'$rootScope'
,
'$element'
,
'NgramListHttpService'
,
function
(
$scope
,
$rootScope
,
$element
,
NgramListHttpService
)
{
'MainApiChangeNgramHttpService'
,
'MainApiAddNgramHttpService'
,
function
(
$scope
,
$rootScope
,
$element
,
NgramListHttpService
,
MainApiChangeNgramHttpService
,
MainApiAddNgramHttpService
)
{
/*
/*
* Add a new NGram from the user input in the extra-text list
* Add a new NGram from the user input in the extra-text list
*/
*/
...
@@ -158,11 +162,14 @@
...
@@ -158,11 +162,14 @@
var
value
=
angular
.
element
(
inputEltId
).
val
().
trim
();
var
value
=
angular
.
element
(
inputEltId
).
val
().
trim
();
if
(
value
===
""
)
return
;
if
(
value
===
""
)
return
;
//
£TEST locally check if already in annotations NodeNgrams
------
//
locally check if already in annotations NodeNgrams ------
------
// $rootScope.annotations = array of ngram objects like:
// $rootScope.annotations = array of ngram objects like:
// {"list_id":805,"occs":2,"uuid":9386,"text":"petit échantillon"}
// {"list_id":805,"occs":2,"uuid":9386,"text":"petit échantillon"}
// TODO £NEW : lookup obj[list_id][term_text] = {terminfo}
// // $rootScope.lookup =
console
.
log
(
'looking for "'
+
value
+
'" in list:'
+
listId
)
console
.
log
(
'looking for "'
+
value
+
'" in list:'
+
listId
)
var
already_in_list
=
false
;
var
already_in_list
=
false
;
angular
.
forEach
(
$rootScope
.
annotations
,
function
(
annot
,
i
)
{
angular
.
forEach
(
$rootScope
.
annotations
,
function
(
annot
,
i
)
{
...
@@ -177,49 +184,65 @@
...
@@ -177,49 +184,65 @@
if
(
already_in_list
)
{
return
;
}
if
(
already_in_list
)
{
return
;
}
// ---------------------------------------------------------------
// ---------------------------------------------------------------
// will check if there's a preexisting ngramId for this value
// AddNgram
// TODO: reconnect separately from list addition
// --------
// creation will return an ngramId
// (checks if there's a preexisting ngramId for this value
// otherwise creates a new one and indexes the ngram in corpus)
MainApiAddNgramHttpService
.
put
(
{
// text <=> str to create the new ngram
'text'
:
value
,
'corpusId'
:
$rootScope
.
corpusId
},
// on AddNgram success
function
(
data
)
{
var
newNgramId
=
data
.
id
console
.
log
(
"OK created new ngram for '"
+
value
+
"' with id: "
+
newNgramId
)
// ChangeNgram
// -----------
// add to listId after creation
// TODO: if maplist => also add to miam
// TODO: if maplist => also add to miam
// NgramHttpService.post(
MainApiChangeNgramHttpService
[
"put"
](
// {
{
// 'listId': listId,
'listId'
:
listId
,
// 'ngramId': 'create'
'ngramIdList'
:
newNgramId
// },
},
// {
// on ChangeNgram success
// 'text': value
function
(
data
)
{
// },
// Refresh the annotations (was broken: TODO FIX)
// function(data) {
console
.
warn
(
"refresh attempt"
);
// console.warn("refresh attempt");
angular
.
element
(
inputEltId
).
val
(
""
);
// what for ???
// // on success
NgramListHttpService
.
get
(
// if (data) {
{
// angular.element(inputEltId).val("");
'corpusId'
:
$rootScope
.
corpusId
,
// // Refresh the annotationss
'docId'
:
$rootScope
.
docId
// NgramListHttpService.get(
},
// {
// on refresh success
// 'corpusId': $rootScope.corpusId,
function
(
data
)
{
// 'docId': $rootScope.docId
$rootScope
.
annotations
=
data
[
$rootScope
.
corpusId
.
toString
()][
$rootScope
.
docId
.
toString
()];
// },
$rootScope
.
refreshDisplay
();
// function(data) {
},
// $rootScope.annotations = data[$rootScope.corpusId.toString()][$rootScope.docId.toString()];
// on refresh error
//
function
(
data
)
{
// // TODO £NEW : lookup obj[list_id][term_text] = {terminfo}
console
.
error
(
"unable to get the list of ngrams"
);
// // $rootScope.lookup =
}
//
);
//
},
// $rootScope.refreshDisplay();
// on ChangeNgram error
// },
function
(
data
)
{
// function(data) {
console
.
error
(
"unable to edit the Ngram"
+
ngramId
+
") on list "
+
listId
+
")"
);
// console.error("unable to get the list of ngrams");
}
// }
);
// );
},
// }
// on AddNgram error
// }, function(data) {
function
(
data
)
{
// // on error
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
};
}]);
}]);
})(
window
);
})(
window
);
annotations/templates/annotations/main.html
View file @
bb6fc256
...
@@ -121,7 +121,10 @@
...
@@ -121,7 +121,10 @@
<!-- this menu is over the text on mouse selection -->
<!-- this menu is over the text on mouse selection -->
<div
ng-controller=
"TextSelectionMenuController"
id=
"selection"
class=
"selection-menu"
>
<div
ng-controller=
"TextSelectionMenuController"
id=
"selection"
class=
"selection-menu"
>
<ul
class=
"noselection"
>
<ul
class=
"noselection"
>
<li
ng-repeat=
"item in menuItems"
class=
"{[{item.tgtListName}]}"
ng-click=
"onMenuClick($event, item.crudActions)"
>
Move to {[{item.tgtListName}]}
</li>
<li
ng-repeat=
"item in menuItems"
class=
"{[{item.tgtListName}]}"
ng-click=
"onMenuClick($event, item.crudCalls)"
>
{[{item.comment ? item.comment : 'Move to ' + item.tgtListName}]}
</li>
</ul>
</ul>
</div>
</div>
</div>
</div>
...
...
annotations/urls.py
View file @
bb6fc256
...
@@ -18,5 +18,5 @@ urlpatterns = [
...
@@ -18,5 +18,5 @@ urlpatterns = [
# 2016-03-24: refactoring, deactivated NgramEdit and NgramCreate
# 2016-03-24: refactoring, deactivated NgramEdit and NgramCreate
# 2016-05-27: removed NgramEdit: replaced the local httpservice by api/ngramlists
# 2016-05-27: removed NgramEdit: replaced the local httpservice by api/ngramlists
#
url(r'^lists/(?P<list_id>[0-9]+)/ngrams/create$', views.NgramCreate.as_view()), #
#
2016-07-21: removed NgramCreate: replaced the local httpservice by api/ngrams (put)
]
]
annotations/views.py
View file @
bb6fc256
...
@@ -162,55 +162,7 @@ class NgramList(APIView):
...
@@ -162,55 +162,7 @@ class NgramList(APIView):
# 2016-03-24: refactoring, deactivated NgramEdit and NgramCreate
# 2016-03-24: refactoring, deactivated NgramEdit and NgramCreate
# 2016-05-27: removed NgramEdit: replaced the local httpservice by api/ngramlists
# 2016-05-27: removed NgramEdit: replaced the local httpservice by api/ngramlists
# ------------------------------------
# 2016-07-21: removed NgramCreate: replaced the local httpservice by api/ngrams (put)
#
# class NgramCreate(APIView):
# """
# Create a new Ngram in one list
# """
# renderer_classes = (JSONRenderer,)
# authentication_classes = (SessionAuthentication, BasicAuthentication)
#
# def post(self, request, list_id):
# """
# create NGram in a given list
#
# example: request.data = {'text': 'phylogeny'}
# """
# # implicit global session
# list_id = int(list_id)
# # format the ngram's text
# ngram_text = request.data.get('text', None)
# if ngram_text is None:
# raise APIException("Could not create a new Ngram without one \
# text key in the json body")
#
# ngram_text = ngram_text.strip().lower()
# ngram_text = ' '.join(ngram_text.split())
# # check if the ngram exists with the same terms
# ngram = session.query(Ngram).filter(Ngram.terms == ngram_text).first()
# if ngram is None:
# ngram = Ngram(n=len(ngram_text.split()), terms=ngram_text)
# else:
# # make sure the n value is correct
# ngram.n = len(ngram_text.split())
#
# session.add(ngram)
# session.commit()
# ngram_id = ngram.id
# # create the new node_ngram relation
# # TODO check existing Node_Ngram ?
# # £TODO ici indexation
# node_ngram = NodeNgram(node_id=list_id, ngram_id=ngram_id, weight=1.0)
# session.add(node_ngram)
# session.commit()
#
# # return the response
# return Response({
# 'uuid': ngram_id,
# 'text': ngram_text,
# 'list_id': list_id,
# })
class
Document
(
APIView
):
class
Document
(
APIView
):
"""
"""
...
...
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