Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
ff788166
Commit
ff788166
authored
4 years ago
by
Stephan Porada
Browse files
Options
Downloads
Patches
Plain Diff
Documentation for Client.js
parent
ccee6071
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
web/app/static/js/modules/corpus_analysis/client/Client.js
+30
-26
30 additions, 26 deletions
web/app/static/js/modules/corpus_analysis/client/Client.js
with
30 additions
and
26 deletions
web/app/static/js/modules/corpus_analysis/client/Client.js
+
30
−
26
View file @
ff788166
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
* It communicates with the server (e.g. connection or query)
* It communicates with the server (e.g. connection or query)
* and recieves data from it, if dynamicMode is true.
* and recieves data from it, if dynamicMode is true.
* If dynamicMode is false, the client can also handle data that is already
* If dynamicMode is false, the client can also handle data that is already
* loaded and is not coming in in chunks.
* loaded and is not coming in
,
in chunks.
*/
*/
class
Client
{
class
Client
{
constructor
({
corpusId
=
null
,
constructor
({
corpusId
=
null
,
...
@@ -19,12 +19,11 @@ class Client {
...
@@ -19,12 +19,11 @@ class Client {
this
.
eventListeners
=
{};
this
.
eventListeners
=
{};
this
.
connected
=
false
;
this
.
connected
=
false
;
/**
/**
* Disable all console logging.
* Disable
s
all console logging.
* This is global. So every other log message in every other Class or
* This is global. So every other log message in every other Class or
* function used in conjunction with the client either logs or does not
* function used in conjunction with the client either logs or does not
* log depending on the logging flag.
* log depending on the logging flag.
It is kind of hacky but not bad.
* Credits to https://gist.github.com/kmonsoor/0244fdb4ad79a4826371e58a1a5fa984
* Credits to https://gist.github.com/kmonsoor/0244fdb4ad79a4826371e58a1a5fa984
*/
*/
if
(
!
logging
)
{
if
(
!
logging
)
{
...
@@ -42,8 +41,11 @@ class Client {
...
@@ -42,8 +41,11 @@ class Client {
}
}
console
.
info
(
"
Client initialized:
"
,
this
);
console
.
info
(
"
Client initialized:
"
,
this
);
}
}
/**
// Registers one or more SocketEventListeners to the Client.
* Registers one or more event listeners to the Client. Either socket or
* custom javascript events. Event listeners are class instances of
* ClientEventListener implemented further below.
*/
setSocketEventListeners
(
eventListeners
)
{
setSocketEventListeners
(
eventListeners
)
{
for
(
let
eventListener
of
eventListeners
)
{
for
(
let
eventListener
of
eventListeners
)
{
this
.
eventListeners
[
eventListener
.
type
]
=
eventListener
;
this
.
eventListeners
[
eventListener
.
type
]
=
eventListener
;
...
@@ -51,8 +53,10 @@ class Client {
...
@@ -51,8 +53,10 @@ class Client {
}
}
/**
/**
* Loads the SocketEventListeners so they will be triggered on their assigned
* Loads the event listeners that have been registered with the function
* type strings because they double as the socket event event names.
* above so that they will be triggered on their assigned
* type strings. Type strings double as the socket event event names or
* javascript custom event names.
*/
*/
loadSocketEventListeners
()
{
loadSocketEventListeners
()
{
for
(
let
[
type
,
listener
]
of
Object
.
entries
(
this
.
eventListeners
))
{
for
(
let
[
type
,
listener
]
of
Object
.
entries
(
this
.
eventListeners
))
{
...
@@ -61,8 +65,10 @@ class Client {
...
@@ -61,8 +65,10 @@ class Client {
}
}
/**
/**
* This functions sends events to the View to trigger specific functions that
* This functions emits the 'notify-view' custom javascript event. This
* are handleing the representation of data stored in the model.
* triggers specific functions in the View depending on the caseIdentifier.
* The detail object can hold any type of data the View needs to know about
* to represent those to the user.
*/
*/
notifyView
(
caseIdentifier
,
detailObject
=
{})
{
notifyView
(
caseIdentifier
,
detailObject
=
{})
{
detailObject
.
caseIdentifier
=
caseIdentifier
;
detailObject
.
caseIdentifier
=
caseIdentifier
;
...
@@ -71,14 +77,9 @@ class Client {
...
@@ -71,14 +77,9 @@ class Client {
document
.
dispatchEvent
(
event
);
document
.
dispatchEvent
(
event
);
}
}
// Registers a CorpusAnalysisDisplay object to the Client.
setDisplay
(
type
,
corpusAnalysisDisplay
)
{
this
.
displays
[
type
]
=
corpusAnalysisDisplay
;
}
/**
/**
* Connects to the corpus analysis session
for the specified corpus via
* Connects to the corpus analysis session
running on the server side for the
* socket.io.
*
specified corpus via
socket.io.
*/
*/
connect
()
{
connect
()
{
console
.
info
(
'
corpus_analysis_init: Client connecting to session via
'
,
console
.
info
(
'
corpus_analysis_init: Client connecting to session via
'
,
...
@@ -86,6 +87,7 @@ class Client {
...
@@ -86,6 +87,7 @@ class Client {
this
.
socket
.
emit
(
'
corpus_analysis_init
'
,
this
.
corpusId
);
this
.
socket
.
emit
(
'
corpus_analysis_init
'
,
this
.
corpusId
);
}
}
// Gets the meta data of the current corpus.
getMetaData
()
{
getMetaData
()
{
console
.
info
(
'
corpus_analysis_meta_data: Client getting meta data via
'
,
console
.
info
(
'
corpus_analysis_meta_data: Client getting meta data via
'
,
'
socket.emit.
'
);
'
socket.emit.
'
);
...
@@ -103,9 +105,9 @@ class Client {
...
@@ -103,9 +105,9 @@ class Client {
}
}
/**
/**
*
Create
results data either f
rom a
ll
results
or from all marked
sub
results
*
Requests
results data either f
or, 'fu
ll
-
results
', '
sub
-
results
' or
*
Triggers emit to get full match context from server for a number of
*
'inspect-results' (resultsType).
*
matches identified by their
data
_i
ndex.
*
Gets full results for evere provided
data
I
ndex
(one match)
.
**/
**/
getResultsData
(
resultsType
,
dataIndexes
,
results
)
{
getResultsData
(
resultsType
,
dataIndexes
,
results
)
{
let
tmp_first_cpos
=
[];
let
tmp_first_cpos
=
[];
...
@@ -125,10 +127,12 @@ class Client {
...
@@ -125,10 +127,12 @@ class Client {
/**
/**
* This class is used to create an SocketEventListener.
* This class is used to create an event listener listening for socket or
* javascript custom events.
* Input are an identifying type string, the listener function and callbacks
* Input are an identifying type string, the listener function and callbacks
* which will be executed as part of the listener function. The identifying
* which will be executed as part of the listener function. The identifying
* type string is also used as the socket event event identifier.
* type string is also used as the socket event or custom javascript event name
* identifier.
*/
*/
class
ClientEventListener
{
class
ClientEventListener
{
constructor
(
type
,
listenerFunction
)
{
constructor
(
type
,
listenerFunction
)
{
...
@@ -137,7 +141,7 @@ class ClientEventListener {
...
@@ -137,7 +141,7 @@ class ClientEventListener {
this
.
type
=
type
;
this
.
type
=
type
;
}
}
// Registers callbacks to this
Socke
tEventListener
// Registers callbacks to this
Clien
tEventListener
.
setCallbacks
(
listenerCallbacks
)
{
setCallbacks
(
listenerCallbacks
)
{
for
(
let
listenerCallback
of
listenerCallbacks
)
{
for
(
let
listenerCallback
of
listenerCallbacks
)
{
this
.
listenerCallbacks
[
listenerCallback
.
type
]
=
listenerCallback
;
this
.
listenerCallbacks
[
listenerCallback
.
type
]
=
listenerCallback
;
...
@@ -159,7 +163,7 @@ class ClientEventListener {
...
@@ -159,7 +163,7 @@ class ClientEventListener {
...
listenerCallback
.
args
);
...
listenerCallback
.
args
);
}
}
}
}
//
use this if you only want to e
xecute a specific registered callback
//
E
xecute
s
a specific registered callback
by provoding a type string.
executeCallback
(
defaultArgs
,
type
)
{
executeCallback
(
defaultArgs
,
type
)
{
let
listenerCallback
=
this
.
listenerCallbacks
[
type
];
let
listenerCallback
=
this
.
listenerCallbacks
[
type
];
listenerCallback
.
callbackFunction
(...
defaultArgs
,
listenerCallback
.
callbackFunction
(...
defaultArgs
,
...
@@ -169,7 +173,7 @@ class ClientEventListener {
...
@@ -169,7 +173,7 @@ class ClientEventListener {
/**
/**
* This class is used to create an ListenerCallback which will be registered
* This class is used to create an ListenerCallback which will be registered
* to an
Socke
tEventListener so the
L
istener can invoke the
ListenerCallback
* to an
Clien
tEventListener so the
l
istener can invoke the
associated
* callback functions.
* callback functions.
*/
*/
class
ListenerCallback
{
class
ListenerCallback
{
...
@@ -180,7 +184,7 @@ class ListenerCallback {
...
@@ -180,7 +184,7 @@ class ListenerCallback {
}
}
}
}
//
e
xport Classes from this module
//
E
xport Classes from this module
.
export
{
export
{
Client
,
Client
,
ClientEventListener
,
ClientEventListener
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment