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
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
d699fd09
Commit
d699fd09
authored
2 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Add live data updates for corpus follower lists
parent
ff238cd8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models.py
+37
-8
37 additions, 8 deletions
app/models.py
app/static/js/ResourceLists/CorpusFollowerList.js
+32
-1
32 additions, 1 deletion
app/static/js/ResourceLists/CorpusFollowerList.js
with
69 additions
and
9 deletions
app/models.py
+
37
−
8
View file @
d699fd09
...
@@ -653,7 +653,7 @@ class User(HashidMixin, UserMixin, db.Model):
...
@@ -653,7 +653,7 @@ class User(HashidMixin, UserMixin, db.Model):
self
.
role
.
to_json_serializeable
(
backrefs
=
True
)
self
.
role
.
to_json_serializeable
(
backrefs
=
True
)
if
relationships
:
if
relationships
:
json_serializeable
[
'
corpus_follower_associations
'
]
=
{
json_serializeable
[
'
corpus_follower_associations
'
]
=
{
x
.
hashid
:
x
.
to_json_serializeable
()
x
.
hashid
:
x
.
to_json_serializeable
(
relationships
=
True
)
for
x
in
self
.
corpus_follower_associations
for
x
in
self
.
corpus_follower_associations
}
}
json_serializeable
[
'
corpora
'
]
=
{
json_serializeable
[
'
corpora
'
]
=
{
...
@@ -672,10 +672,6 @@ class User(HashidMixin, UserMixin, db.Model):
...
@@ -672,10 +672,6 @@ class User(HashidMixin, UserMixin, db.Model):
x
.
hashid
:
x
.
to_json_serializeable
(
relationships
=
True
)
x
.
hashid
:
x
.
to_json_serializeable
(
relationships
=
True
)
for
x
in
self
.
spacy_nlp_pipeline_models
for
x
in
self
.
spacy_nlp_pipeline_models
}
}
json_serializeable
[
'
followed_corpora
'
]
=
{
x
.
hashid
:
x
.
to_json_serializeable
(
relationships
=
True
)
for
x
in
self
.
followed_corpora
}
if
filter_by_privacy_settings
:
if
filter_by_privacy_settings
:
if
not
self
.
has_profile_privacy_setting
(
ProfilePrivacySettings
.
SHOW_EMAIL
):
if
not
self
.
has_profile_privacy_setting
(
ProfilePrivacySettings
.
SHOW_EMAIL
):
...
@@ -1430,7 +1426,7 @@ class Corpus(HashidMixin, db.Model):
...
@@ -1430,7 +1426,7 @@ class Corpus(HashidMixin, db.Model):
self
.
user
.
to_json_serializeable
(
backrefs
=
True
)
self
.
user
.
to_json_serializeable
(
backrefs
=
True
)
if
relationships
:
if
relationships
:
json_serializeable
[
'
corpus_follower_associations
'
]
=
{
json_serializeable
[
'
corpus_follower_associations
'
]
=
{
x
.
hashid
:
x
.
to_json_serializeable
()
x
.
hashid
:
x
.
to_json_serializeable
(
relationships
=
True
)
for
x
in
self
.
corpus_follower_associations
for
x
in
self
.
corpus_follower_associations
}
}
json_serializeable
[
'
files
'
]
=
{
json_serializeable
[
'
files
'
]
=
{
...
@@ -1454,12 +1450,27 @@ class Corpus(HashidMixin, db.Model):
...
@@ -1454,12 +1450,27 @@ class Corpus(HashidMixin, db.Model):
@db.event.listens_for
(
TesseractOCRPipelineModel
,
'
after_delete
'
)
@db.event.listens_for
(
TesseractOCRPipelineModel
,
'
after_delete
'
)
def
ressource_after_delete
(
mapper
,
connection
,
ressource
):
def
ressource_after_delete
(
mapper
,
connection
,
ressource
):
jsonpatch
=
[{
'
op
'
:
'
remove
'
,
'
path
'
:
ressource
.
jsonpatch_path
}]
jsonpatch
=
[{
'
op
'
:
'
remove
'
,
'
path
'
:
ressource
.
jsonpatch_path
}]
room
=
f
'
users.
{
ressource
.
user_hashid
}
'
socketio
.
emit
(
'
users.patch
'
,
jsonpatch
,
room
=
room
)
room
=
f
'
/users/
{
ressource
.
user_hashid
}
'
room
=
f
'
/users/
{
ressource
.
user_hashid
}
'
socketio
.
emit
(
'
PATCH
'
,
jsonpatch
,
room
=
room
)
socketio
.
emit
(
'
PATCH
'
,
jsonpatch
,
room
=
room
)
@db.event.listens_for
(
CorpusFollowerAssociation
,
'
after_delete
'
)
def
corpus_follower_association_after_delete_handler
(
mapper
,
connection
,
ressource
):
corpus_owner_hashid
=
ressource
.
corpus
.
user
.
hashid
corpus_hashid
=
hashids
.
encode
(
ressource
.
corpus_id
)
follower_hashid
=
hashids
.
encode
(
ressource
.
follower_id
)
# Send a PATCH to the corpus owner
jsonpatch_path
=
f
'
/users/
{
corpus_owner_hashid
}
/corpora/
{
corpus_hashid
}
/corpus_follower_associations/
{
ressource
.
hashid
}
'
jsonpatch
=
[{
'
op
'
:
'
remove
'
,
'
path
'
:
jsonpatch_path
}]
room
=
f
'
/users/
{
corpus_owner_hashid
}
'
socketio
.
emit
(
'
PATCH
'
,
jsonpatch
,
room
=
room
)
# Send a PATCH to the follower
jsonpatch_path
=
f
'
/users/
{
follower_hashid
}
/corpus_follower_associations/
{
ressource
.
hashid
}
'
jsonpatch
=
[{
'
op
'
:
'
remove
'
,
'
path
'
:
jsonpatch_path
}]
room
=
f
'
/users/
{
follower_hashid
}
'
socketio
.
emit
(
'
PATCH
'
,
jsonpatch
,
room
=
room
)
@db.event.listens_for
(
Corpus
,
'
after_insert
'
)
@db.event.listens_for
(
Corpus
,
'
after_insert
'
)
@db.event.listens_for
(
CorpusFile
,
'
after_insert
'
)
@db.event.listens_for
(
CorpusFile
,
'
after_insert
'
)
@db.event.listens_for
(
Job
,
'
after_insert
'
)
@db.event.listens_for
(
Job
,
'
after_insert
'
)
...
@@ -1478,6 +1489,24 @@ def ressource_after_insert_handler(mapper, connection, ressource):
...
@@ -1478,6 +1489,24 @@ def ressource_after_insert_handler(mapper, connection, ressource):
socketio
.
emit
(
'
PATCH
'
,
jsonpatch
,
room
=
room
)
socketio
.
emit
(
'
PATCH
'
,
jsonpatch
,
room
=
room
)
# @db.event.listens_for(CorpusFollowerAssociation, 'after_insert')
# def corpus_follower_association_after_insert_handler(mapper, connection, ressource):
# corpus_owner_hashid = ressource.corpus.user.hashid
# corpus_hashid = hashids.encode(ressource.corpus_id)
# follower_hashid = hashids.encode(ressource.follower_id)
# value = ressource.to_json_serializeable()
# # Send a PATCH to the corpus owner
# jsonpatch_path = f'/users/{corpus_owner_hashid}/corpora/{corpus_hashid}/corpus_follower_associations/{ressource.hashid}'
# jsonpatch = [{'op': 'add', 'path': jsonpatch_path, 'value': value}]
# room = f'/users/{corpus_owner_hashid}'
# socketio.emit('PATCH', jsonpatch, room=room)
# # Send a PATCH to the follower
# jsonpatch_path = f'/users/{follower_hashid}/corpus_follower_associations/{ressource.hashid}'
# jsonpatch = [{'op': 'add', 'path': jsonpatch_path, 'value': value}]
# room = f'/users/{follower_hashid}'
# socketio.emit('PATCH', jsonpatch, room=room)
@db.event.listens_for
(
Corpus
,
'
after_update
'
)
@db.event.listens_for
(
Corpus
,
'
after_update
'
)
@db.event.listens_for
(
CorpusFile
,
'
after_update
'
)
@db.event.listens_for
(
CorpusFile
,
'
after_update
'
)
@db.event.listens_for
(
Job
,
'
after_update
'
)
@db.event.listens_for
(
Job
,
'
after_update
'
)
...
...
This diff is collapsed.
Click to expand it.
app/static/js/ResourceLists/CorpusFollowerList.js
+
32
−
1
View file @
d699fd09
...
@@ -169,5 +169,36 @@ class CorpusFollowerList extends ResourceList {
...
@@ -169,5 +169,36 @@ class CorpusFollowerList extends ResourceList {
}
}
}
}
onPatch
(
patch
)
{}
onPatch
(
patch
)
{
let
re
=
new
RegExp
(
`^/users/
${
this
.
userId
}
/corpora/
${
this
.
corpusId
}
/corpus_follower_associations/([A-Za-z0-9]*)`
);
let
filteredPatch
=
patch
.
filter
(
operation
=>
re
.
test
(
operation
.
path
));
for
(
let
operation
of
filteredPatch
)
{
switch
(
operation
.
op
)
{
case
'
add
'
:
{
// let re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/corpus_follower_associations/([A-Za-z0-9]*)$`);
// if (re.test(operation.path)) {this.add(operation.value);}
break
;
}
case
'
remove
'
:
{
let
re
=
new
RegExp
(
`^/users/
${
this
.
userId
}
/corpora/
${
this
.
corpusId
}
/corpus_follower_associations/([A-Za-z0-9]*)$`
);
if
(
re
.
test
(
operation
.
path
))
{
let
[
match
,
jobId
]
=
operation
.
path
.
match
(
re
);
this
.
remove
(
jobId
);
}
break
;
}
case
'
replace
'
:
{
// let re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/corpus_follower_associations/([A-Za-z0-9]*)/(service|status|description|title)$`);
// if (re.test(operation.path)) {
// let [match, jobId, valueName] = operation.path.match(re);
// this.replace(jobId, valueName, operation.value);
// }
break
;
}
default
:
{
break
;
}
}
}
}
}
}
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