mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-01-17 13:30:34 +00:00
Compare commits
No commits in common. "c2a6b9d7465981ce815366375dfe7e34077953f3" and "2f3ddc6b817755549ccc42ef4c1fc226fd1f3108" have entirely different histories.
c2a6b9d746
...
2f3ddc6b81
@ -11,66 +11,65 @@ from app.models import (
|
|||||||
from ..decorators import corpus_follower_permission_required
|
from ..decorators import corpus_follower_permission_required
|
||||||
from . import bp
|
from . import bp
|
||||||
|
|
||||||
|
@bp.route('/<hashid:corpus_id>/followers', methods=['POST'])
|
||||||
# @bp.route('/<hashid:corpus_id>/followers', methods=['POST'])
|
@corpus_follower_permission_required('MANAGE_FOLLOWERS')
|
||||||
# @corpus_follower_permission_required('MANAGE_FOLLOWERS')
|
@content_negotiation(consumes='application/json', produces='application/json')
|
||||||
# @content_negotiation(consumes='application/json', produces='application/json')
|
def create_corpus_followers(corpus_id):
|
||||||
# def create_corpus_followers(corpus_id):
|
usernames = request.json
|
||||||
# usernames = request.json
|
if not (isinstance(usernames, list) or all(isinstance(u, str) for u in usernames)):
|
||||||
# if not (isinstance(usernames, list) or all(isinstance(u, str) for u in usernames)):
|
abort(400)
|
||||||
# abort(400)
|
corpus = Corpus.query.get_or_404(corpus_id)
|
||||||
# corpus = Corpus.query.get_or_404(corpus_id)
|
for username in usernames:
|
||||||
# for username in usernames:
|
user = User.query.filter_by(username=username, is_public=True).first_or_404()
|
||||||
# user = User.query.filter_by(username=username, is_public=True).first_or_404()
|
user.follow_corpus(corpus)
|
||||||
# user.follow_corpus(corpus)
|
db.session.commit()
|
||||||
# db.session.commit()
|
response_data = {
|
||||||
# response_data = {
|
'message': f'Users are now following "{corpus.title}"',
|
||||||
# 'message': f'Users are now following "{corpus.title}"',
|
'category': 'corpus'
|
||||||
# 'category': 'corpus'
|
}
|
||||||
# }
|
return response_data, 200
|
||||||
# return response_data, 200
|
|
||||||
|
|
||||||
|
|
||||||
# @bp.route('/<hashid:corpus_id>/followers/<hashid:follower_id>/role', methods=['PUT'])
|
@bp.route('/<hashid:corpus_id>/followers/<hashid:follower_id>/role', methods=['PUT'])
|
||||||
# @corpus_follower_permission_required('MANAGE_FOLLOWERS')
|
@corpus_follower_permission_required('MANAGE_FOLLOWERS')
|
||||||
# @content_negotiation(consumes='application/json', produces='application/json')
|
@content_negotiation(consumes='application/json', produces='application/json')
|
||||||
# def update_corpus_follower_role(corpus_id, follower_id):
|
def update_corpus_follower_role(corpus_id, follower_id):
|
||||||
# role_name = request.json
|
role_name = request.json
|
||||||
# if not isinstance(role_name, str):
|
if not isinstance(role_name, str):
|
||||||
# abort(400)
|
abort(400)
|
||||||
# cfr = CorpusFollowerRole.query.filter_by(name=role_name).first()
|
cfr = CorpusFollowerRole.query.filter_by(name=role_name).first()
|
||||||
# if cfr is None:
|
if cfr is None:
|
||||||
# abort(400)
|
abort(400)
|
||||||
# cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404()
|
cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404()
|
||||||
# cfa.role = cfr
|
cfa.role = cfr
|
||||||
# db.session.commit()
|
db.session.commit()
|
||||||
# response_data = {
|
response_data = {
|
||||||
# 'message': f'User "{cfa.follower.username}" is now {cfa.role.name}',
|
'message': f'User "{cfa.follower.username}" is now {cfa.role.name}',
|
||||||
# 'category': 'corpus'
|
'category': 'corpus'
|
||||||
# }
|
}
|
||||||
# return response_data, 200
|
return response_data, 200
|
||||||
|
|
||||||
|
|
||||||
# @bp.route('/<hashid:corpus_id>/followers/<hashid:follower_id>', methods=['DELETE'])
|
@bp.route('/<hashid:corpus_id>/followers/<hashid:follower_id>', methods=['DELETE'])
|
||||||
# def delete_corpus_follower(corpus_id, follower_id):
|
def delete_corpus_follower(corpus_id, follower_id):
|
||||||
# cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404()
|
cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=follower_id).first_or_404()
|
||||||
# if not (
|
if not (
|
||||||
# current_user.id == follower_id
|
current_user.id == follower_id
|
||||||
# or current_user == cfa.corpus.user
|
or current_user == cfa.corpus.user
|
||||||
# or CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=current_user.id).first().role.has_permission('MANAGE_FOLLOWERS')
|
or CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=current_user.id).first().role.has_permission('MANAGE_FOLLOWERS')
|
||||||
# or current_user.is_administrator()):
|
or current_user.is_administrator()):
|
||||||
# abort(403)
|
abort(403)
|
||||||
# if current_user.id == follower_id:
|
if current_user.id == follower_id:
|
||||||
# flash(f'You are no longer following "{cfa.corpus.title}"', 'corpus')
|
flash(f'You are no longer following "{cfa.corpus.title}"', 'corpus')
|
||||||
# response = make_response()
|
response = make_response()
|
||||||
# response.status_code = 204
|
response.status_code = 204
|
||||||
# else:
|
else:
|
||||||
# response_data = {
|
response_data = {
|
||||||
# 'message': f'"{cfa.follower.username}" is not following "{cfa.corpus.title}" anymore',
|
'message': f'"{cfa.follower.username}" is not following "{cfa.corpus.title}" anymore',
|
||||||
# 'category': 'corpus'
|
'category': 'corpus'
|
||||||
# }
|
}
|
||||||
# response = jsonify(response_data)
|
response = jsonify(response_data)
|
||||||
# response.status_code = 200
|
response.status_code = 200
|
||||||
# cfa.follower.unfollow_corpus(cfa.corpus)
|
cfa.follower.unfollow_corpus(cfa.corpus)
|
||||||
# db.session.commit()
|
db.session.commit()
|
||||||
# return response
|
return response
|
||||||
|
@ -71,7 +71,6 @@ def corpus(corpus_id):
|
|||||||
users = users
|
users = users
|
||||||
)
|
)
|
||||||
if (current_user.is_following_corpus(corpus) or corpus.is_public):
|
if (current_user.is_following_corpus(corpus) or corpus.is_public):
|
||||||
abort(403)
|
|
||||||
cfas = CorpusFollowerAssociation.query.filter(Corpus.id == corpus_id, CorpusFollowerAssociation.follower_id != corpus.user.id).all()
|
cfas = CorpusFollowerAssociation.query.filter(Corpus.id == corpus_id, CorpusFollowerAssociation.follower_id != corpus.user.id).all()
|
||||||
print(cfas)
|
print(cfas)
|
||||||
return render_template(
|
return render_template(
|
||||||
@ -99,14 +98,14 @@ def analysis(corpus_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# @bp.route('/<hashid:corpus_id>/follow/<token>')
|
@bp.route('/<hashid:corpus_id>/follow/<token>')
|
||||||
# def follow_corpus(corpus_id, token):
|
def follow_corpus(corpus_id, token):
|
||||||
# corpus = Corpus.query.get_or_404(corpus_id)
|
corpus = Corpus.query.get_or_404(corpus_id)
|
||||||
# if current_user.follow_corpus_by_token(token):
|
if current_user.follow_corpus_by_token(token):
|
||||||
# db.session.commit()
|
db.session.commit()
|
||||||
# flash(f'You are following "{corpus.title}" now', category='corpus')
|
flash(f'You are following "{corpus.title}" now', category='corpus')
|
||||||
# return redirect(url_for('corpora.corpus', corpus_id=corpus_id))
|
return redirect(url_for('corpora.corpus', corpus_id=corpus_id))
|
||||||
# abort(403)
|
abort(403)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/import', methods=['GET', 'POST'])
|
@bp.route('/import', methods=['GET', 'POST'])
|
||||||
|
@ -81,7 +81,7 @@ class CorpusFileList extends ResourceList {
|
|||||||
<th>
|
<th>
|
||||||
<label class="selection-action-trigger ${this.listContainerElement.dataset?.hasPermissionView == 'true' ? '' : 'hide'}" data-selection-action="select-all">
|
<label class="selection-action-trigger ${this.listContainerElement.dataset?.hasPermissionView == 'true' ? '' : 'hide'}" data-selection-action="select-all">
|
||||||
<input class="select-all-checkbox" type="checkbox">
|
<input class="select-all-checkbox" type="checkbox">
|
||||||
<span class="disable-on-click"></span>
|
<span></span>
|
||||||
</label>
|
</label>
|
||||||
</th>
|
</th>
|
||||||
<th>Filename</th>
|
<th>Filename</th>
|
||||||
@ -89,8 +89,8 @@ class CorpusFileList extends ResourceList {
|
|||||||
<th>Title</th>
|
<th>Title</th>
|
||||||
<th>Publishing year</th>
|
<th>Publishing year</th>
|
||||||
<th class="right-align">
|
<th class="right-align">
|
||||||
<a class="selection-action-trigger btn-floating red waves-effect waves-light hide" data-selection-action="delete"><i class="material-icons">delete</i></a>
|
<a class="selection-action-trigger btn-floating red waves-effect waves-light hide" data-selection-action="delete"><i class="material-icons">delete</i></a>
|
||||||
<a class="selection-action-trigger btn-floating service-color darken waves-effect waves-light hide" data-selection-action="download" data-service="corpus-analysis"><i class="material-icons">file_download</i></a>
|
<a class="selection-action-trigger btn-floating service-color darken waves-effect waves-light hide" data-selection-action="download" data-service="corpus-analysis"><i class="material-icons">file_download</i></a>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -173,13 +173,13 @@ class CorpusFileList extends ResourceList {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'select': {
|
case 'select': {
|
||||||
|
|
||||||
if (event.target.checked) {
|
if (event.target.checked) {
|
||||||
this.selectedItemIds.add(itemId);
|
this.selectedItemIds.add(itemId);
|
||||||
} else {
|
} else {
|
||||||
this.selectedItemIds.delete(itemId);
|
this.selectedItemIds.delete(itemId);
|
||||||
}
|
}
|
||||||
this.renderingItemSelection();
|
this.renderingItemSelection();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
break;
|
break;
|
||||||
@ -199,16 +199,15 @@ class CorpusFileList extends ResourceList {
|
|||||||
case 'select-all': {
|
case 'select-all': {
|
||||||
let selectedIds = new Set(Array.from(items)
|
let selectedIds = new Set(Array.from(items)
|
||||||
.map(item => item.values().id))
|
.map(item => item.values().id))
|
||||||
if (event.target.checked !== undefined) {
|
if (event.target.checked) {
|
||||||
if (event.target.checked) {
|
selectableItems.forEach(selectableItem => selectableItem.checked = true);
|
||||||
selectableItems.forEach(selectableItem => selectableItem.checked = true);
|
this.selectedItemIds = selectedIds;
|
||||||
this.selectedItemIds = selectedIds;
|
} else {
|
||||||
} else {
|
selectableItems.forEach(checkbox => checkbox.checked = false);
|
||||||
selectableItems.forEach(checkbox => checkbox.checked = false);
|
this.selectedItemIds = new Set([...this.selectedItemIds].filter(id => !selectedIds.has(id)));
|
||||||
this.selectedItemIds = new Set([...this.selectedItemIds].filter(id => !selectedIds.has(id)));
|
|
||||||
}
|
|
||||||
this.renderingItemSelection();
|
|
||||||
}
|
}
|
||||||
|
this.renderingItemSelection();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'delete': {
|
case 'delete': {
|
||||||
@ -327,14 +326,6 @@ class CorpusFileList extends ResourceList {
|
|||||||
actionButton.classList.remove('hide');
|
actionButton.classList.remove('hide');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check select all checkbox if all items are selected
|
|
||||||
let selectAllCheckbox = document.querySelector('.select-all-checkbox[type="checkbox"]');
|
|
||||||
if (selectableItems.length === this.selectedItemIds.size && selectAllCheckbox.checked === false) {
|
|
||||||
selectAllCheckbox.checked = true;
|
|
||||||
} else if (selectableItems.length !== this.selectedItemIds.size && selectAllCheckbox.checked === true) {
|
|
||||||
selectAllCheckbox.checked = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onPatch(patch) {
|
onPatch(patch) {
|
||||||
|
@ -43,7 +43,7 @@ class CorpusFollowerList extends ResourceList {
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="input-field disable-on-click list-action-trigger" data-list-action="update-role">
|
<div class="input-field disable-on-click list-action-trigger" data-list-action="update-role">
|
||||||
<select ${values['follower-id'] === currentUserId ? 'disabled' : ''}>
|
<select ${values['user_id'] === currentUserId ? 'disabled' : ''}>
|
||||||
<option value="Viewer" ${values['role-name'] === 'Viewer' ? 'selected' : ''}>Viewer</option>
|
<option value="Viewer" ${values['role-name'] === 'Viewer' ? 'selected' : ''}>Viewer</option>
|
||||||
<option value="Contributor" ${values['role-name'] === 'Contributor' ? 'selected' : ''}>Contributor</option>
|
<option value="Contributor" ${values['role-name'] === 'Contributor' ? 'selected' : ''}>Contributor</option>
|
||||||
<option value="Administrator" ${values['role-name'] === 'Administrator' ? 'selected' : ''}>Administrator</option>
|
<option value="Administrator" ${values['role-name'] === 'Administrator' ? 'selected' : ''}>Administrator</option>
|
||||||
|
@ -8,11 +8,7 @@ class CorpusList extends ResourceList {
|
|||||||
constructor(listContainerElement, options = {}) {
|
constructor(listContainerElement, options = {}) {
|
||||||
super(listContainerElement, options);
|
super(listContainerElement, options);
|
||||||
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
||||||
document.querySelectorAll('.corpus-list-selection-action-trigger[data-selection-action]').forEach((element) => {
|
|
||||||
element.addEventListener('click', (event) => {this.onSelectionAction(event)});
|
|
||||||
});
|
|
||||||
this.isInitialized = false
|
this.isInitialized = false
|
||||||
this.selectedItemIds = new Set();
|
|
||||||
this.userId = listContainerElement.dataset.userId;
|
this.userId = listContainerElement.dataset.userId;
|
||||||
if (this.userId === undefined) {return;}
|
if (this.userId === undefined) {return;}
|
||||||
app.subscribeUser(this.userId).then((response) => {
|
app.subscribeUser(this.userId).then((response) => {
|
||||||
@ -26,18 +22,13 @@ class CorpusList extends ResourceList {
|
|||||||
get item() {
|
get item() {
|
||||||
return (values) => {
|
return (values) => {
|
||||||
return `
|
return `
|
||||||
<tr class="${values['is-owner'] ? '' : 'deep-purple lighten-5'} list-item">
|
<tr class="${values['is-owner'] ? '' : 'deep-purple lighten-5'} list-item clickable hoverable">
|
||||||
<td>
|
<td><a class="btn-floating disabled"><i class="material-icons service-color darken" data-service="corpus-analysis">book</i></a></td>
|
||||||
<label class="list-action-trigger ${values['is-owner'] ? '' : 'hide'}" data-list-action="select">
|
|
||||||
<input class="select-checkbox" type="checkbox">
|
|
||||||
<span class="disable-on-click"></span>
|
|
||||||
</label>
|
|
||||||
</td>
|
|
||||||
<td><b class="title"></b><br><i class="description"></i></td>
|
<td><b class="title"></b><br><i class="description"></i></td>
|
||||||
<td><span class="owner"></span></td>
|
<td><span class="owner"></span></td>
|
||||||
<td><span class="status badge new corpus-status-color corpus-status-text" data-badge-caption=""></span></td>
|
<td><span class="status badge new corpus-status-color corpus-status-text" data-badge-caption=""></span></td>
|
||||||
<td class="right-align">
|
<td class="right-align">
|
||||||
<a class="list-action-trigger btn-floating red waves-effect waves-light ${values['is-owner'] ? '' : 'hide'}" data-list-action="delete-request"><i class="material-icons">delete</i></a>
|
<a class="list-action-trigger btn-floating red waves-effect waves-light" data-list-action="delete-request"><i class="material-icons">delete</i></a>
|
||||||
<a class="list-action-trigger btn-floating service-color darken waves-effect waves-light" data-list-action="view" data-service="corpus-analysis"><i class="material-icons">send</i></a>
|
<a class="list-action-trigger btn-floating service-color darken waves-effect waves-light" data-list-action="view" data-service="corpus-analysis"><i class="material-icons">send</i></a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -70,18 +61,11 @@ class CorpusList extends ResourceList {
|
|||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>
|
<th></th>
|
||||||
<label class="corpus-list-selection-action-trigger" data-selection-action="select-all">
|
|
||||||
<input class="corpus-list-select-all-checkbox" type="checkbox">
|
|
||||||
<span></span>
|
|
||||||
</label>
|
|
||||||
</th>
|
|
||||||
<th>Title and Description</th>
|
<th>Title and Description</th>
|
||||||
<th>Owner</th>
|
<th>Owner</th>
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
<th class="right-align">
|
<th></th>
|
||||||
<a class="corpus-list-selection-action-trigger btn-floating red waves-effect waves-light hide" data-selection-action="delete"><i class="material-icons">delete</i></a>
|
|
||||||
</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="list"></tbody>
|
<tbody class="list"></tbody>
|
||||||
@ -111,7 +95,7 @@ class CorpusList extends ResourceList {
|
|||||||
if (listItemElement === null) {return;}
|
if (listItemElement === null) {return;}
|
||||||
let itemId = listItemElement.dataset.id;
|
let itemId = listItemElement.dataset.id;
|
||||||
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
|
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
|
||||||
let listAction = listActionElement === null ? '' : listActionElement.dataset.listAction;
|
let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction;
|
||||||
switch (listAction) {
|
switch (listAction) {
|
||||||
case 'delete-request': {
|
case 'delete-request': {
|
||||||
let values = this.listjs.get('id', itemId)[0].values();
|
let values = this.listjs.get('id', itemId)[0].values();
|
||||||
@ -151,149 +135,12 @@ class CorpusList extends ResourceList {
|
|||||||
window.location.href = `/corpora/${itemId}`;
|
window.location.href = `/corpora/${itemId}`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'select': {
|
|
||||||
|
|
||||||
if (event.target.checked) {
|
|
||||||
this.selectedItemIds.add(itemId);
|
|
||||||
} else {
|
|
||||||
this.selectedItemIds.delete(itemId);
|
|
||||||
}
|
|
||||||
this.renderingItemSelection();
|
|
||||||
}
|
|
||||||
default: {
|
default: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelectionAction(event) {
|
|
||||||
let selectionActionElement = event.target.closest('.corpus-list-selection-action-trigger[data-selection-action]');
|
|
||||||
let selectionAction = selectionActionElement.dataset.selectionAction;
|
|
||||||
let items = Array.from(this.listjs.items).filter(item => item._values["is-owner"] === true);
|
|
||||||
let selectableItems = Array.from(items)
|
|
||||||
.filter(item => item.elm)
|
|
||||||
.map(item => item.elm.querySelector('.select-checkbox[type="checkbox"]'));
|
|
||||||
|
|
||||||
switch (selectionAction) {
|
|
||||||
case 'select-all': {
|
|
||||||
let selectedIds = new Set(Array.from(items)
|
|
||||||
.map(item => item.values().id))
|
|
||||||
if (event.target.checked !== undefined) {
|
|
||||||
if (event.target.checked) {
|
|
||||||
selectableItems.forEach(selectableItem => selectableItem.checked = true);
|
|
||||||
this.selectedItemIds = selectedIds;
|
|
||||||
} else {
|
|
||||||
selectableItems.forEach(checkbox => checkbox.checked = false);
|
|
||||||
this.selectedItemIds = new Set([...this.selectedItemIds].filter(id => !selectedIds.has(id)));
|
|
||||||
}
|
|
||||||
this.renderingItemSelection();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'delete': {
|
|
||||||
let modalElement = Utils.HTMLToElement(
|
|
||||||
`
|
|
||||||
<div class="modal">
|
|
||||||
<div class="modal-content">
|
|
||||||
<h4>Confirm Corpus File deletion</h4>
|
|
||||||
<p>Do you really want to delete this Corpora?</p>
|
|
||||||
<ul id="selected-items-list"></ul>
|
|
||||||
<p>All corpora will be permanently deleted!</p>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<a class="btn modal-close waves-effect waves-light">Cancel</a>
|
|
||||||
<a class="action-button btn modal-close red waves-effect waves-light" data-action="confirm">Delete</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`
|
|
||||||
);
|
|
||||||
document.querySelector('#modals').appendChild(modalElement);
|
|
||||||
let itemList = document.querySelector('#selected-items-list');
|
|
||||||
this.selectedItemIds.forEach(selectedItemId => {
|
|
||||||
let listItem = this.listjs.get('id', selectedItemId)[0].elm;
|
|
||||||
let values = this.listjs.get('id', listItem.dataset.id)[0].values();
|
|
||||||
let itemElement = Utils.HTMLToElement(`<li> - ${values.title}</li>`);
|
|
||||||
itemList.appendChild(itemElement);
|
|
||||||
});
|
|
||||||
let modal = M.Modal.init(
|
|
||||||
modalElement,
|
|
||||||
{
|
|
||||||
dismissible: false,
|
|
||||||
onCloseEnd: () => {
|
|
||||||
modal.destroy();
|
|
||||||
modalElement.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
let confirmElement = modalElement.querySelector('.action-button[data-action="confirm"]');
|
|
||||||
confirmElement.addEventListener('click', (event) => {
|
|
||||||
this.selectedItemIds.forEach(selectedItemId => {
|
|
||||||
Requests.corpora.entity.delete(selectedItemId);
|
|
||||||
});
|
|
||||||
this.selectedItemIds.clear();
|
|
||||||
this.renderingItemSelection();
|
|
||||||
});
|
|
||||||
modal.open();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
renderingItemSelection() {
|
|
||||||
let selectionActionButtons = document.querySelectorAll('.corpus-list-selection-action-trigger:not([data-selection-action="select-all"])');
|
|
||||||
let selectableItems = this.listjs.items;
|
|
||||||
let actionButtons = [];
|
|
||||||
|
|
||||||
Object.values(selectableItems).forEach(selectableItem => {
|
|
||||||
if (selectableItem._values["is-owner"] === false && this.selectedItemIds.size > 0) {
|
|
||||||
selectableItem.elm.classList.add('hide');
|
|
||||||
} else if (selectableItem._values["is-owner"] === false && this.selectedItemIds.size === 0) {
|
|
||||||
selectableItem.elm.classList.remove('hide');
|
|
||||||
} else {
|
|
||||||
if (selectableItem.elm) {
|
|
||||||
let checkbox = selectableItem.elm.querySelector('.select-checkbox[type="checkbox"]');
|
|
||||||
if (checkbox.checked) {
|
|
||||||
selectableItem.elm.classList.add('grey', 'lighten-3');
|
|
||||||
} else {
|
|
||||||
selectableItem.elm.classList.remove('grey', 'lighten-3');
|
|
||||||
}
|
|
||||||
let itemActionButtons = selectableItem.elm.querySelectorAll('.list-action-trigger:not([data-list-action="select"])');
|
|
||||||
itemActionButtons.forEach(itemActionButton => {
|
|
||||||
actionButtons.push(itemActionButton);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Hide item action buttons if > 0 item is selected and show selection action buttons
|
|
||||||
if (this.selectedItemIds.size > 0) {
|
|
||||||
selectionActionButtons.forEach(selectionActionButton => {
|
|
||||||
selectionActionButton.classList.remove('hide');
|
|
||||||
});
|
|
||||||
actionButtons.forEach(actionButton => {
|
|
||||||
actionButton.classList.add('hide');
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
selectionActionButtons.forEach(selectionActionButton => {
|
|
||||||
selectionActionButton.classList.add('hide');
|
|
||||||
});
|
|
||||||
actionButtons.forEach(actionButton => {
|
|
||||||
actionButton.classList.remove('hide');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check select all checkbox if all items are selected
|
|
||||||
let filteredItems = Object.values(selectableItems).filter(item => item._values["is-owner"] === true)
|
|
||||||
let selectAllCheckbox = document.querySelector('.corpus-list-select-all-checkbox[type="checkbox"]');
|
|
||||||
if (filteredItems.length === this.selectedItemIds.size && selectAllCheckbox.checked === false) {
|
|
||||||
selectAllCheckbox.checked = true;
|
|
||||||
} else if (filteredItems.length !== this.selectedItemIds.size && selectAllCheckbox.checked === true) {
|
|
||||||
selectAllCheckbox.checked = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onPatch(patch) {
|
onPatch(patch) {
|
||||||
let re = new RegExp(`^/users/${this.userId}/corpora/([A-Za-z0-9]*)`);
|
let re = new RegExp(`^/users/${this.userId}/corpora/([A-Za-z0-9]*)`);
|
||||||
let filteredPatch = patch.filter(operation => re.test(operation.path));
|
let filteredPatch = patch.filter(operation => re.test(operation.path));
|
||||||
|
@ -7,13 +7,8 @@ class JobList extends ResourceList {
|
|||||||
|
|
||||||
constructor(listContainerElement, options = {}) {
|
constructor(listContainerElement, options = {}) {
|
||||||
super(listContainerElement, options);
|
super(listContainerElement, options);
|
||||||
this.documentJobArea = document.querySelector('#jobs');
|
|
||||||
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
||||||
document.querySelectorAll('.job-list-selection-action-trigger[data-selection-action]').forEach((element) => {
|
|
||||||
element.addEventListener('click', (event) => {this.onSelectionAction(event)});
|
|
||||||
});
|
|
||||||
this.isInitialized = false;
|
this.isInitialized = false;
|
||||||
this.selectedItemIds = new Set();
|
|
||||||
this.userId = listContainerElement.dataset.userId;
|
this.userId = listContainerElement.dataset.userId;
|
||||||
if (this.userId === undefined) {return;}
|
if (this.userId === undefined) {return;}
|
||||||
app.subscribeUser(this.userId).then((response) => {
|
app.subscribeUser(this.userId).then((response) => {
|
||||||
@ -29,13 +24,7 @@ class JobList extends ResourceList {
|
|||||||
|
|
||||||
get item() {
|
get item() {
|
||||||
return `
|
return `
|
||||||
<tr class="list-item service-scheme">
|
<tr class="list-item clickable hoverable service-scheme">
|
||||||
<td>
|
|
||||||
<label class="list-action-trigger" data-list-action="select">
|
|
||||||
<input class="select-checkbox" type="checkbox">
|
|
||||||
<span class="disable-on-click"></span>
|
|
||||||
</label>
|
|
||||||
</td>
|
|
||||||
<td><a class="btn-floating"><i class="nopaque-icons service-icons" data-service="inherit"></i></a></td>
|
<td><a class="btn-floating"><i class="nopaque-icons service-icons" data-service="inherit"></i></a></td>
|
||||||
<td><b class="title"></b><br><i class="description"></i></td>
|
<td><b class="title"></b><br><i class="description"></i></td>
|
||||||
<td><span class="badge new job-status-color job-status-text status" data-badge-caption=""></span></td>
|
<td><span class="badge new job-status-color job-status-text status" data-badge-caption=""></span></td>
|
||||||
@ -72,18 +61,10 @@ class JobList extends ResourceList {
|
|||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>
|
|
||||||
<label class="job-list-selection-action-trigger" data-selection-action="select-all">
|
|
||||||
<input class="job-list-select-all-checkbox" type="checkbox">
|
|
||||||
<span class="disable-on-click"></span>
|
|
||||||
</label>
|
|
||||||
</th>
|
|
||||||
<th>Service</th>
|
<th>Service</th>
|
||||||
<th>Title and Description</th>
|
<th>Title and Description</th>
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
<th class="right-align">
|
<th></th>
|
||||||
<a class="job-list-selection-action-trigger btn-floating red waves-effect waves-light hide" data-selection-action="delete"><i class="material-icons">delete</i></a>
|
|
||||||
</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="list"></tbody>
|
<tbody class="list"></tbody>
|
||||||
@ -112,7 +93,7 @@ class JobList extends ResourceList {
|
|||||||
if (listItemElement === null) {return;}
|
if (listItemElement === null) {return;}
|
||||||
let itemId = listItemElement.dataset.id;
|
let itemId = listItemElement.dataset.id;
|
||||||
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
|
let listActionElement = event.target.closest('.list-action-trigger[data-list-action]');
|
||||||
let listAction = listActionElement === null ? '' : listActionElement.dataset.listAction;
|
let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction;
|
||||||
switch (listAction) {
|
switch (listAction) {
|
||||||
case 'delete-request': {
|
case 'delete-request': {
|
||||||
let values = this.listjs.get('id', itemId)[0].values();
|
let values = this.listjs.get('id', itemId)[0].values();
|
||||||
@ -152,145 +133,12 @@ class JobList extends ResourceList {
|
|||||||
window.location.href = `/jobs/${itemId}`;
|
window.location.href = `/jobs/${itemId}`;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'select': {
|
|
||||||
if (event.target.checked) {
|
|
||||||
this.selectedItemIds.add(itemId);
|
|
||||||
} else {
|
|
||||||
this.selectedItemIds.delete(itemId);
|
|
||||||
}
|
|
||||||
this.renderingItemSelection();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
default: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelectionAction(event) {
|
|
||||||
let selectionActionElement = event.target.closest('.job-list-selection-action-trigger[data-selection-action]');
|
|
||||||
let selectionAction = selectionActionElement.dataset.selectionAction;
|
|
||||||
let items = this.listjs.items;
|
|
||||||
let selectableItems = Array.from(items)
|
|
||||||
.filter(item => item.elm)
|
|
||||||
.map(item => item.elm.querySelector('.select-checkbox[type="checkbox"]'));
|
|
||||||
switch (selectionAction) {
|
|
||||||
case 'select-all': {
|
|
||||||
let selectedIds = new Set(Array.from(items)
|
|
||||||
.map(item => item.values().id))
|
|
||||||
if (event.target.checked !== undefined) {
|
|
||||||
if (event.target.checked) {
|
|
||||||
selectableItems.forEach(selectableItem => selectableItem.checked = true);
|
|
||||||
this.selectedItemIds = selectedIds;
|
|
||||||
} else {
|
|
||||||
selectableItems.forEach(checkbox => checkbox.checked = false);
|
|
||||||
this.selectedItemIds = new Set([...this.selectedItemIds].filter(id => !selectedIds.has(id)));
|
|
||||||
}
|
|
||||||
this.renderingItemSelection();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'delete': {
|
|
||||||
let modalElement = Utils.HTMLToElement(
|
|
||||||
`
|
|
||||||
<div class="modal">
|
|
||||||
<div class="modal-content">
|
|
||||||
<h4>Confirm Corpus File deletion</h4>
|
|
||||||
<p>Do you really want to delete the Jobs?</p>
|
|
||||||
<ul id="selected-items-list"></ul>
|
|
||||||
<p>All files will be permanently deleted!</p>
|
|
||||||
</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<a class="btn modal-close waves-effect waves-light">Cancel</a>
|
|
||||||
<a class="action-button btn modal-close red waves-effect waves-light" data-action="confirm">Delete</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`
|
|
||||||
);
|
|
||||||
document.querySelector('#modals').appendChild(modalElement);
|
|
||||||
let itemList = document.querySelector('#selected-items-list');
|
|
||||||
this.selectedItemIds.forEach(selectedItemId => {
|
|
||||||
let listItem = this.listjs.get('id', selectedItemId)[0].elm;
|
|
||||||
let values = this.listjs.get('id', listItem.dataset.id)[0].values();
|
|
||||||
let itemElement = Utils.HTMLToElement(`<li> - ${values.title}</li>`);
|
|
||||||
itemList.appendChild(itemElement);
|
|
||||||
});
|
|
||||||
let modal = M.Modal.init(
|
|
||||||
modalElement,
|
|
||||||
{
|
|
||||||
dismissible: false,
|
|
||||||
onCloseEnd: () => {
|
|
||||||
modal.destroy();
|
|
||||||
modalElement.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
let confirmElement = modalElement.querySelector('.action-button[data-action="confirm"]');
|
|
||||||
confirmElement.addEventListener('click', (event) => {
|
|
||||||
this.selectedItemIds.forEach(selectedItemId => {
|
|
||||||
Requests.jobs.entity.delete(selectedItemId);
|
|
||||||
});
|
|
||||||
this.selectedItemIds.clear();
|
|
||||||
this.renderingItemSelection();
|
|
||||||
});
|
|
||||||
modal.open();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
renderingItemSelection() {
|
|
||||||
let selectionActionButtons = document.querySelectorAll('.job-list-selection-action-trigger:not([data-selection-action="select-all"])');
|
|
||||||
let selectableItems = this.listjs.items;
|
|
||||||
let actionButtons = [];
|
|
||||||
|
|
||||||
Object.values(selectableItems).forEach(selectableItem => {
|
|
||||||
if (selectableItem.elm) {
|
|
||||||
let checkbox = selectableItem.elm.querySelector('.select-checkbox[type="checkbox"]');
|
|
||||||
if (checkbox.checked) {
|
|
||||||
selectableItem.elm.classList.add('grey', 'lighten-3');
|
|
||||||
} else {
|
|
||||||
selectableItem.elm.classList.remove('grey', 'lighten-3');
|
|
||||||
}
|
|
||||||
let itemActionButtons = selectableItem.elm.querySelectorAll('.list-action-trigger:not([data-list-action="select"])');
|
|
||||||
itemActionButtons.forEach(itemActionButton => {
|
|
||||||
actionButtons.push(itemActionButton);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Hide item action buttons if > 0 item is selected and show selection action buttons
|
|
||||||
if (this.selectedItemIds.size > 0) {
|
|
||||||
selectionActionButtons.forEach(selectionActionButton => {
|
|
||||||
selectionActionButton.classList.remove('hide');
|
|
||||||
});
|
|
||||||
actionButtons.forEach(actionButton => {
|
|
||||||
actionButton.classList.add('hide');
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
selectionActionButtons.forEach(selectionActionButton => {
|
|
||||||
selectionActionButton.classList.add('hide');
|
|
||||||
});
|
|
||||||
actionButtons.forEach(actionButton => {
|
|
||||||
actionButton.classList.remove('hide');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check select all checkbox if all items are selected
|
|
||||||
let selectAllCheckbox = document.querySelector('.job-list-select-all-checkbox[type="checkbox"]');
|
|
||||||
if (selectableItems.length === this.selectedItemIds.size && selectAllCheckbox.checked === false) {
|
|
||||||
selectAllCheckbox.checked = true;
|
|
||||||
} else if (selectableItems.length !== this.selectedItemIds.size && selectAllCheckbox.checked === true) {
|
|
||||||
selectAllCheckbox.checked = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
onPatch(patch) {
|
onPatch(patch) {
|
||||||
let re = new RegExp(`^/users/${this.userId}/jobs/([A-Za-z0-9]*)`);
|
let re = new RegExp(`^/users/${this.userId}/jobs/([A-Za-z0-9]*)`);
|
||||||
let filteredPatch = patch.filter(operation => re.test(operation.path));
|
let filteredPatch = patch.filter(operation => re.test(operation.path));
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col s12">
|
<div class="col s12">
|
||||||
<h1>{{ corpus.title }}</h1>
|
<h1>{{ corpus.title }}</h1>
|
||||||
|
{% for cfa in cfas %}
|
||||||
|
{{ cfa.follower.username|tojson }},
|
||||||
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col s12 l7">
|
<div class="col s12 l7">
|
||||||
<div class="card service-color-border border-darken" data-service="corpus-analysis" style="border-top: 10px solid">
|
<div class="card service-color-border border-darken" data-service="corpus-analysis" style="border-top: 10px solid">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user