mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Rework all Resource Lists
This commit is contained in:
parent
7b88493e7d
commit
8b18571725
156
app/static/js/ResourceLists/CorpusFileList.js
Normal file
156
app/static/js/ResourceLists/CorpusFileList.js
Normal file
@ -0,0 +1,156 @@
|
||||
class CorpusFileList extends ResourceList {
|
||||
static autoInit() {
|
||||
for (let corpusFileListElement of document.querySelectorAll('.corpus-file-list:not(.no-autoinit)')) {
|
||||
new CorpusFileList(corpusFileListElement);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, options);
|
||||
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
||||
this.isInitialized = false;
|
||||
this.userId = listContainerElement.dataset.userId;
|
||||
this.corpusId = listContainerElement.dataset.corpusId;
|
||||
app.subscribeUser(this.userId).then((response) => {
|
||||
app.socket.on('PATCH', (patch) => {
|
||||
if (this.isInitialized) {this.onPatch(patch);}
|
||||
});
|
||||
});
|
||||
app.getUser(this.userId).then((user) => {
|
||||
this.add(Object.values(user.corpora[this.corpusId].files));
|
||||
this.isInitialized = true;
|
||||
});
|
||||
}
|
||||
|
||||
// #region Mandatory getters and methods to implement
|
||||
get item() {
|
||||
return `
|
||||
<tr class="clickable hoverable">
|
||||
<td><span class="filename"></span></td>
|
||||
<td><span class="author"></span></td>
|
||||
<td><span class="title"></span></td>
|
||||
<td><span class="publishing-year"></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete"><i class="material-icons">delete</i></a>
|
||||
<a class="action-button btn-floating service-color darken waves-effect waves-light" data-action="download" data-service="corpus-analysis"><i class="material-icons">file_download</i></a>
|
||||
<a class="action-button btn-floating service-color darken waves-effect waves-light" data-action="view" data-service="corpus-analysis"><i class="material-icons">send</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim();
|
||||
}
|
||||
|
||||
get valueNames() {
|
||||
return [
|
||||
{data: ['id']},
|
||||
{data: ['creation-date']},
|
||||
'author',
|
||||
'filename',
|
||||
'publishing-year',
|
||||
'title'
|
||||
];
|
||||
}
|
||||
|
||||
initListContainerElement() {
|
||||
if (!this.listContainerElement.hasAttribute('id')) {
|
||||
this.listContainerElement.id = Utils.generateElementId('corpus-file-list-');
|
||||
}
|
||||
let listSearchElementId = Utils.generateElementId(`${this.listContainerElement.id}-search-`);
|
||||
this.listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listSearchElementId}" class="search" type="text"></input>
|
||||
<label for="${listSearchElementId}">Search corpus file</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Filename</th>
|
||||
<th>Author</th>
|
||||
<th>Title</th>
|
||||
<th>Publishing year</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region Optional methods to implement
|
||||
mapResourceToValue(corpusFile) {
|
||||
return {
|
||||
'id': corpusFile.id,
|
||||
'author': corpusFile.author,
|
||||
'creation-date': corpusFile.creation_date,
|
||||
'filename': corpusFile.filename,
|
||||
'publishing-year': corpusFile.publishing_year,
|
||||
'title': corpusFile.title
|
||||
};
|
||||
}
|
||||
|
||||
sort() {
|
||||
this.listjs.sort('creation-date', {order: 'desc'});
|
||||
}
|
||||
// #endregion
|
||||
|
||||
onClick(event) {
|
||||
let corpusFileElement = event.target.closest('tr');
|
||||
if (corpusFileElement === null) {return;}
|
||||
let corpusFileId = corpusFileElement.dataset.id;
|
||||
if (corpusFileId === undefined) {return;}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
||||
switch (action) {
|
||||
case 'delete': {
|
||||
Utils.deleteCorpusFileRequest(this.userId, this.corpusId, corpusFileId);
|
||||
break;
|
||||
}
|
||||
case 'download': {
|
||||
window.location.href = `/corpora/${this.corpusId}/files/${corpusFileId}/download`;
|
||||
break;
|
||||
}
|
||||
case 'view': {
|
||||
window.location.href = `/corpora/${this.corpusId}/files/${corpusFileId}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onPatch(patch) {
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/files/([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}/files/([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}/files/([A-Za-z0-9]*)$`);
|
||||
if (re.test(operation.path)) {
|
||||
let [match, corpusFileId] = operation.path.match(re);
|
||||
this.remove(corpusFileId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'replace': {
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/files/([A-Za-z0-9]*)/(author|filename|publishing_year|title)$`);
|
||||
if (re.test(operation.path)) {
|
||||
let [match, corpusFileId, valueName] = operation.path.match(re);
|
||||
this.replace(corpusFileId, valueName.replace('_', '-'), operation.value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
146
app/static/js/ResourceLists/CorpusList.js
Normal file
146
app/static/js/ResourceLists/CorpusList.js
Normal file
@ -0,0 +1,146 @@
|
||||
class CorpusList extends ResourceList {
|
||||
static autoInit() {
|
||||
for (let corpusListElement of document.querySelectorAll('.corpus-list:not(.no-autoinit)')) {
|
||||
new CorpusList(corpusListElement);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, options);
|
||||
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
||||
this.isInitialized = false;
|
||||
this.userId = listContainerElement.dataset.userId;
|
||||
app.subscribeUser(this.userId).then((response) => {
|
||||
app.socket.on('PATCH', (patch) => {
|
||||
if (this.isInitialized) {this.onPatch(patch);}
|
||||
});
|
||||
});
|
||||
app.getUser(this.userId).then((user) => {
|
||||
this.add(Object.values(user.corpora));
|
||||
this.isInitialized = true;
|
||||
});
|
||||
}
|
||||
|
||||
// #region Mandatory getters and methods to implement
|
||||
get item() {
|
||||
return `
|
||||
<tr class="clickable hoverable">
|
||||
<td><a class="btn-floating disabled"><i class="material-icons service-color darken" data-service="corpus-analysis">book</i></a></td>
|
||||
<td><b class="title"></b><br><i class="description"></i></td>
|
||||
<td><span class="status badge new corpus-status-color corpus-status-text" data-badge-caption=""></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete-request"><i class="material-icons">delete</i></a>
|
||||
<a class="action-button btn-floating service-color darken waves-effect waves-light" data-action="view" data-service="corpus-analysis"><i class="material-icons">send</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim();
|
||||
}
|
||||
|
||||
get valueNames() {
|
||||
return [
|
||||
{data: ['id']},
|
||||
{data: ['creation-date']},
|
||||
{name: 'status', attr: 'data-status'},
|
||||
'description',
|
||||
'title'
|
||||
];
|
||||
}
|
||||
|
||||
initListContainerElement() {
|
||||
if (!this.listContainerElement.hasAttribute('id')) {
|
||||
this.listContainerElement.id = Utils.generateElementId('corpus-list-');
|
||||
}
|
||||
let listSearchElementId = Utils.generateElementId(`${this.listContainerElement.id}-search-`);
|
||||
this.listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listSearchElementId}" class="search" type="text"></input>
|
||||
<label for="${listSearchElementId}">Search corpus</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Title and Description</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region Optional methods to implement
|
||||
mapResourceToValue(corpus) {
|
||||
return {
|
||||
'id': corpus.id,
|
||||
'creation-date': corpus.creation_date,
|
||||
'description': corpus.description,
|
||||
'status': corpus.status,
|
||||
'title': corpus.title
|
||||
};
|
||||
}
|
||||
|
||||
sort() {
|
||||
this.listjs.sort('creation-date', {order: 'desc'});
|
||||
}
|
||||
// #endregion
|
||||
|
||||
onClick(event) {
|
||||
let corpusElement = event.target.closest('tr');
|
||||
if (corpusElement === null) {return;}
|
||||
let corpusId = corpusElement.dataset.id;
|
||||
if (corpusId === undefined) {return;}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
||||
switch (action) {
|
||||
case 'delete-request': {
|
||||
Utils.deleteCorpusRequest(this.userId, corpusId);
|
||||
break;
|
||||
}
|
||||
case 'view': {
|
||||
window.location.href = `/corpora/${corpusId}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onPatch(patch) {
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/([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/([A-Za-z0-9]*)$`);
|
||||
if (re.test(operation.path)) {this.add(operation.value);}
|
||||
break;
|
||||
}
|
||||
case 'remove': {
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/([A-Za-z0-9]*)$`);
|
||||
if (re.test(operation.path)) {
|
||||
let [match, corpusId] = operation.path.match(re);
|
||||
this.remove(corpusId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'replace': {
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/([A-Za-z0-9]*)/(status|description|title)$`);
|
||||
if (re.test(operation.path)) {
|
||||
let [match, corpusId, valueName] = operation.path.match(re);
|
||||
this.replace(corpusId, valueName, operation.value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
101
app/static/js/ResourceLists/JobInputList.js
Normal file
101
app/static/js/ResourceLists/JobInputList.js
Normal file
@ -0,0 +1,101 @@
|
||||
class JobInputList extends ResourceList {
|
||||
static autoInit() {
|
||||
for (let jobInputListElement of document.querySelectorAll('.job-input-list:not(.no-autoinit)')) {
|
||||
new JobInputList(jobInputListElement);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, options);
|
||||
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
||||
this.isInitialized = false;
|
||||
this.userId = listContainerElement.dataset.userId;
|
||||
this.jobId = listContainerElement.dataset.jobId;
|
||||
app.subscribeUser(this.userId).then((response) => {
|
||||
app.socket.on('PATCH', (patch) => {
|
||||
if (this.isInitialized) {this.onPatch(patch);}
|
||||
});
|
||||
});
|
||||
app.getUser(this.userId).then((user) => {
|
||||
this.add(Object.values(user.jobs[this.jobId].inputs));
|
||||
this.isInitialized = true;
|
||||
});
|
||||
}
|
||||
|
||||
// #region Mandatory getters and methods to implement
|
||||
get item() {
|
||||
return `
|
||||
<tr class="clickable hoverable">
|
||||
<td><span class="filename"></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating waves-effect waves-light" data-action="download"><i class="material-icons">file_download</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim();
|
||||
}
|
||||
|
||||
get valueNames() {
|
||||
return [
|
||||
{data: ['id']},
|
||||
{data: ['creation-date']},
|
||||
'filename'
|
||||
];
|
||||
}
|
||||
|
||||
initListContainerElement() {
|
||||
if (!this.listContainerElement.hasAttribute('id')) {
|
||||
this.listContainerElement.id = Utils.generateElementId('job-input-list-');
|
||||
}
|
||||
let listSearchElementId = Utils.generateElementId(`${this.listContainerElement.id}-search-`);
|
||||
this.listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listSearchElementId}" class="search" type="text"></input>
|
||||
<label for="${listSearchElementId}">Search job input</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Filename</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region Optional methods to implement
|
||||
mapResourceToValue(jobInput) {
|
||||
return {
|
||||
'id': jobInput.id,
|
||||
'creation-date': jobInput.creation_date,
|
||||
'filename': jobInput.filename
|
||||
};
|
||||
}
|
||||
|
||||
sort() {
|
||||
this.listjs.sort('filename', {order: 'asc'});
|
||||
}
|
||||
// #endregion
|
||||
|
||||
onClick(event) {
|
||||
let jobInputElement = event.target.closest('tr');
|
||||
if (jobInputElement === null) {return;}
|
||||
let jobInputId = jobInputElement.dataset.id;
|
||||
if (jobInputId === undefined) {return;}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'download' : actionButtonElement.dataset.action;
|
||||
switch (action) {
|
||||
case 'download': {
|
||||
window.location.href = `/jobs/${this.jobId}/inputs/${jobInputId}/download`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
148
app/static/js/ResourceLists/JobList.js
Normal file
148
app/static/js/ResourceLists/JobList.js
Normal file
@ -0,0 +1,148 @@
|
||||
class JobList extends ResourceList {
|
||||
static autoInit() {
|
||||
for (let jobListElement of document.querySelectorAll('.job-list:not(.no-autoinit)')) {
|
||||
new JobList(jobListElement);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, options);
|
||||
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
||||
this.isInitialized = false;
|
||||
this.userId = listContainerElement.dataset.userId;
|
||||
app.subscribeUser(this.userId).then((response) => {
|
||||
app.socket.on('PATCH', (patch) => {
|
||||
if (this.isInitialized) {this.onPatch(patch);}
|
||||
});
|
||||
});
|
||||
app.getUser(this.userId).then((user) => {
|
||||
this.add(Object.values(user.jobs));
|
||||
this.isInitialized = true;
|
||||
});
|
||||
}
|
||||
|
||||
// #region Mandatory getters and methods to implement
|
||||
get item() {
|
||||
return `
|
||||
<tr class="clickable hoverable service-scheme">
|
||||
<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><span class="badge new job-status-color job-status-text status" data-badge-caption=""></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete-request"><i class="material-icons">delete</i></a>
|
||||
<a class="action-button btn-floating darken waves-effect waves-light" data-action="view"><i class="material-icons">send</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim();
|
||||
}
|
||||
|
||||
get valueNames() {
|
||||
return [
|
||||
{data: ['id']},
|
||||
{data: ['creation-date']},
|
||||
{data: ['service']},
|
||||
{name: 'status', attr: 'data-status'},
|
||||
'description',
|
||||
'title'
|
||||
];
|
||||
}
|
||||
|
||||
initListContainerElement() {
|
||||
if (!this.listContainerElement.hasAttribute('id')) {
|
||||
this.listContainerElement.id = Utils.generateElementId('job-list-');
|
||||
}
|
||||
let listSearchElementId = Utils.generateElementId(`${this.listContainerElement.id}-search-`);
|
||||
this.listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listSearchElementId}" class="search" type="text"></input>
|
||||
<label for="${listSearchElementId}">Search job</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Service</th>
|
||||
<th>Title and Description</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region Optional methods to implement
|
||||
mapResourceToValue(job) {
|
||||
return {
|
||||
'id': job.id,
|
||||
'creation-date': job.creation_date,
|
||||
'description': job.description,
|
||||
'service': job.service,
|
||||
'status': job.status,
|
||||
'title': job.title
|
||||
};
|
||||
}
|
||||
|
||||
sort() {
|
||||
this.listjs.sort('creation-date', {order: 'desc'});
|
||||
}
|
||||
// #endregion
|
||||
|
||||
onClick(event) {
|
||||
let jobElement = event.target.closest('tr');
|
||||
if (jobElement === null) {return;}
|
||||
let jobId = jobElement.dataset.id;
|
||||
if (jobId === undefined) {return;}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
||||
switch (action) {
|
||||
case 'delete-request': {
|
||||
Utils.deleteJobRequest(this.userId, jobId);
|
||||
break;
|
||||
}
|
||||
case 'view': {
|
||||
window.location.href = `/jobs/${jobId}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onPatch(patch) {
|
||||
let re = new RegExp(`^/users/${this.userId}/jobs/([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}/jobs/([A-Za-z0-9]*)$`);
|
||||
if (re.test(operation.path)) {this.add(operation.value);}
|
||||
break;
|
||||
}
|
||||
case 'remove': {
|
||||
let re = new RegExp(`^/users/${this.userId}/jobs/([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}/jobs/([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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
122
app/static/js/ResourceLists/JobResultList.js
Normal file
122
app/static/js/ResourceLists/JobResultList.js
Normal file
@ -0,0 +1,122 @@
|
||||
class JobResultList extends ResourceList {
|
||||
static autoInit() {
|
||||
for (let jobResultListElement of document.querySelectorAll('.job-result-list:not(.no-autoinit)')) {
|
||||
new JobResultList(jobResultListElement);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, options);
|
||||
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
||||
this.isInitialized = false;
|
||||
this.userId = listContainerElement.dataset.userId;
|
||||
this.jobId = listContainerElement.dataset.jobId;
|
||||
app.subscribeUser(this.userId).then((response) => {
|
||||
app.socket.on('PATCH', (patch) => {
|
||||
if (this.isInitialized) {this.onPatch(patch);}
|
||||
});
|
||||
});
|
||||
app.getUser(this.userId).then((user) => {
|
||||
this.add(Object.values(user.jobs[this.jobId].results));
|
||||
this.isInitialized = true;
|
||||
});
|
||||
}
|
||||
|
||||
// #region Mandatory getters and methods to implement
|
||||
get item() {
|
||||
return `
|
||||
<tr class="clickable hoverable">
|
||||
<td><span class="description"></span></td>
|
||||
<td><span class="filename"></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating waves-effect waves-light" data-action="download"><i class="material-icons">file_download</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim();
|
||||
}
|
||||
|
||||
get valueNames() {
|
||||
return [
|
||||
{data: ['id']},
|
||||
{data: ['creation-date']},
|
||||
'description',
|
||||
'filename'
|
||||
];
|
||||
}
|
||||
|
||||
initListContainerElement() {
|
||||
if (!this.listContainerElement.hasAttribute('id')) {
|
||||
this.listContainerElement.id = Utils.generateElementId('job-result-list-');
|
||||
}
|
||||
let listSearchElementId = Utils.generateElementId(`${this.listContainerElement.id}-search-`);
|
||||
this.listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listSearchElementId}" class="search" type="text"></input>
|
||||
<label for="${listSearchElementId}">Search job result</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Description</th>
|
||||
<th>Filename</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region Optional methods to implement
|
||||
mapResourceToValue(jobResult) {
|
||||
return {
|
||||
'id': jobResult.id,
|
||||
'creation-date': jobResult.creation_date,
|
||||
'description': jobResult.description,
|
||||
'filename': jobResult.filename
|
||||
};
|
||||
}
|
||||
|
||||
sort() {
|
||||
this.listjs.sort('filename', {order: 'asc'});
|
||||
}
|
||||
// #endregion
|
||||
|
||||
onClick(event) {
|
||||
let jobResultElement = event.target.closest('tr');
|
||||
if (jobResultElement === null) {return;}
|
||||
let jobResultId = jobResultElement.dataset.id;
|
||||
if (jobResultId === undefined) {return;}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'download' : actionButtonElement.dataset.action;
|
||||
switch (action) {
|
||||
case 'download': {
|
||||
window.location.href = `/jobs/${this.jobId}/results/${jobResultId}/download`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onPatch(patch) {
|
||||
let re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}/results/([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}/jobs/${this.jobId}/results/([A-Za-z0-9]*)$`);
|
||||
if (re.test(operation.path)) {this.add(operation.value);}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
107
app/static/js/ResourceLists/PublicUserList.js
Normal file
107
app/static/js/ResourceLists/PublicUserList.js
Normal file
@ -0,0 +1,107 @@
|
||||
class PublicUserList extends ResourceList {
|
||||
static autoInit() {
|
||||
for (let publicUserListElement of document.querySelectorAll('.public-user-list:not(.no-autoinit)')) {
|
||||
new PublicUserList(publicUserListElement);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, options);
|
||||
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
||||
}
|
||||
|
||||
// #region Mandatory getters and methods to implement
|
||||
get item() {
|
||||
return `
|
||||
<tr class="clickable hoverable">
|
||||
<td><img alt="user-image" class="circle responsive-img avatar" style="width:50%"></td>
|
||||
<td><b><span class="username"></span><b></td>
|
||||
<td><span class="full-name"></span></td>
|
||||
<td><span class="location"></span></td>
|
||||
<td><span class="organization"></span></td>
|
||||
<td><span class="corpora-online"></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating waves-effect waves-light" data-action="view"><i class="material-icons">send</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim();
|
||||
}
|
||||
|
||||
get valueNames() {
|
||||
return [
|
||||
{data: ['id']},
|
||||
{data: ['member-since']},
|
||||
{name: 'avatar', attr: 'src'},
|
||||
'username',
|
||||
'full-name',
|
||||
'location',
|
||||
'organization',
|
||||
'corpora-online'
|
||||
];
|
||||
}
|
||||
|
||||
initListContainerElement() {
|
||||
if (!this.listContainerElement.hasAttribute('id')) {
|
||||
this.listContainerElement.id = Utils.generateElementId('public-user-list-');
|
||||
}
|
||||
let listSearchElementId = Utils.generateElementId(`${this.listContainerElement.id}-search-`);
|
||||
this.listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listSearchElementId}" class="search" type="text"></input>
|
||||
<label for="${listSearchElementId}">Search public user</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:15%;"></th>
|
||||
<th>Username</th>
|
||||
<th>Full name</th>
|
||||
<th>Location</th>
|
||||
<th>Organization</th>
|
||||
<th>Corpora online</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region Optional methods to implement
|
||||
mapResourceToValue(user) {
|
||||
return {
|
||||
'id': user.id,
|
||||
'member-since': user.member_since,
|
||||
'avatar': user.avatar ? `/users/${user.id}/avatar` : '/static/images/user_avatar.png',
|
||||
'username': user.username,
|
||||
'full-name': user.full_name ? user.full_name : '',
|
||||
'location': user.location ? user.location : '',
|
||||
'organization': user.organization ? user.organization : '',
|
||||
'corpora-online': '0'
|
||||
};
|
||||
};
|
||||
|
||||
sort() {
|
||||
this.listjs.sort('member-since', {order: 'desc'});
|
||||
}
|
||||
// #endregion
|
||||
|
||||
onClick(event) {
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
||||
let publicUserElement = event.target.closest('tr');
|
||||
let publicUserId = publicUserElement.dataset.id;
|
||||
switch (action) {
|
||||
case 'view': {
|
||||
window.location.href = `/users/${publicUserId}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
70
app/static/js/ResourceLists/ResourceList.js
Normal file
70
app/static/js/ResourceLists/ResourceList.js
Normal file
@ -0,0 +1,70 @@
|
||||
class ResourceList {
|
||||
/* A wrapper class for the list.js list.
|
||||
* This class is not meant to be used directly, instead it should be used as
|
||||
* a base class for concrete resource list implementations.
|
||||
*/
|
||||
|
||||
static autoInit() {
|
||||
CorpusList.autoInit();
|
||||
CorpusFileList.autoInit();
|
||||
JobList.autoInit();
|
||||
JobInputList.autoInit();
|
||||
JobResultList.autoInit();
|
||||
PublicUserList.autoInit();
|
||||
SpaCyNLPPipelineModelList.autoInit();
|
||||
TesseractOCRPipelineModelList.autoInit();
|
||||
UserList.autoInit();
|
||||
}
|
||||
|
||||
static defaultOptions = {
|
||||
page: 5,
|
||||
pagination: {
|
||||
innerWindow: 2,
|
||||
outerWindow: 2
|
||||
}
|
||||
};
|
||||
|
||||
constructor(listContainerElement, options={}) {
|
||||
if ('items' in options) {throw '"items" is not supported as an option, define it as a getter in the list class';}
|
||||
if ('valueNames' in options) {throw '"valueNames" is not supported as an option, define it as a getter in the list class';}
|
||||
let _options = _.merge({item: this.item, valueNames: this.valueNames}, ResourceList.defaultOptions, options);
|
||||
this.listContainerElement = listContainerElement;
|
||||
this.initListContainerElement();
|
||||
this.listjs = new List(listContainerElement, _options);
|
||||
}
|
||||
|
||||
add(resources, callback) {
|
||||
let values = resources.map((resource) => {
|
||||
return this.mapResourceToValue(resource);
|
||||
});
|
||||
this.listjs.add(values, (items) => {
|
||||
this.sort();
|
||||
if (typeof callback === 'function') {
|
||||
callback(items);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
remove(id) {
|
||||
this.listjs.remove('id', id);
|
||||
}
|
||||
|
||||
replace(id, key, value) {
|
||||
let item = this.listjs.get('id', id)[0];
|
||||
item.values({[key]: value});
|
||||
}
|
||||
|
||||
// #region Mandatory getters and methods to implement
|
||||
get item() {throw 'Not implemented';}
|
||||
|
||||
get valueNames() {throw 'Not implemented';}
|
||||
|
||||
initListContainerElement() {throw 'Not implemented';}
|
||||
// #endregion
|
||||
|
||||
// #region Optional methods to implement
|
||||
mapResourceToValue(resource) {return resource;}
|
||||
|
||||
sort() {return;}
|
||||
// #endregion
|
||||
}
|
166
app/static/js/ResourceLists/SpacyNLPPipelineModelList.js
Normal file
166
app/static/js/ResourceLists/SpacyNLPPipelineModelList.js
Normal file
@ -0,0 +1,166 @@
|
||||
class SpaCyNLPPipelineModelList extends ResourceList {
|
||||
static autoInit() {
|
||||
for (let spaCyNLPPipelineModelListElement of document.querySelectorAll('.spacy-nlp-pipeline-model-list:not(.no-autoinit)')) {
|
||||
new SpaCyNLPPipelineModelList(spaCyNLPPipelineModelListElement);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, options);
|
||||
this.listjs.list.addEventListener('change', (event) => {this.onChange(event)});
|
||||
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
||||
this.isInitialized = false;
|
||||
this.userId = listContainerElement.dataset.userId;
|
||||
app.subscribeUser(this.userId).then((response) => {
|
||||
app.socket.on('PATCH', (patch) => {
|
||||
if (this.isInitialized) {this.onPatch(patch);}
|
||||
});
|
||||
});
|
||||
app.getUser(this.userId).then((user) => {
|
||||
this.add(Object.values(user.spacy_nlp_pipeline_models));
|
||||
for (let uncheckedCheckbox of this.listjs.list.querySelectorAll('input[data-checked="True"]')) {
|
||||
uncheckedCheckbox.setAttribute('checked', '');
|
||||
}
|
||||
if (user.role.name !== ('Administrator' || 'Contributor')) {
|
||||
for (let switchElement of this.listjs.list.querySelectorAll('.is_public')) {
|
||||
switchElement.setAttribute('disabled', '');
|
||||
}
|
||||
}
|
||||
this.isInitialized = true;
|
||||
});
|
||||
}
|
||||
|
||||
// #region Mandatory getters and methods to implement
|
||||
get item() {
|
||||
return `
|
||||
<tr class="clickable hoverable">
|
||||
<td><b><span class="title"></span> <span class="version"></span></b><br><i><span class="description"></span></i></td>
|
||||
<td><a class="publisher-url"><span class="publisher"></span></a> (<span class="publishing-year"></span>)<br><a class="publishing-url"><span class="publishing-url-2"></span></a></td>
|
||||
<td>
|
||||
<div class="switch action-switch center-align" data-action="share-request">
|
||||
<span class="share"></span>
|
||||
<label>
|
||||
<input type="checkbox" class="is_public">
|
||||
<span class="lever"></span>
|
||||
public
|
||||
</label>
|
||||
</div>
|
||||
</td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete-request"><i class="material-icons">delete</i></a>
|
||||
<a class="action-button btn-floating service-color darken waves-effect waves-light service-2" data-action="view"><i class="material-icons">send</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim();
|
||||
}
|
||||
|
||||
get valueNames() {
|
||||
return [
|
||||
{data: ['id']},
|
||||
{data: ['creation-date']},
|
||||
{name: 'publisher-url', attr: 'href'},
|
||||
{name: 'publishing-url', attr: 'href'},
|
||||
'description',
|
||||
'publisher',
|
||||
'publishing-url-2',
|
||||
'publishing-year',
|
||||
'title',
|
||||
'title-2',
|
||||
'version',
|
||||
{name: 'is_public', attr: 'data-checked'}
|
||||
];
|
||||
}
|
||||
|
||||
initListContainerElement() {
|
||||
if (!this.listContainerElement.hasAttribute('id')) {
|
||||
this.listContainerElement.id = Utils.generateElementId('spacy-nlp-pipeline-model-list-');
|
||||
}
|
||||
let listSearchElementId = Utils.generateElementId(`${this.listContainerElement.id}-search-`);
|
||||
this.listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listSearchElementId}" class="search" type="text"></input>
|
||||
<label for="${listSearchElementId}">Search SpaCy NLP Pipeline Model</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Title and Description</th>
|
||||
<th>Publisher</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region Optional methods to implement
|
||||
mapResourceToValue(spaCyNLPPipelineModel) {
|
||||
return {
|
||||
'id': spaCyNLPPipelineModel.id,
|
||||
'creation-date': spaCyNLPPipelineModel.creation_date,
|
||||
'description': spaCyNLPPipelineModel.description,
|
||||
'publisher': spaCyNLPPipelineModel.publisher,
|
||||
'publisher-url': spaCyNLPPipelineModel.publisher_url,
|
||||
'publishing-url': spaCyNLPPipelineModel.publishing_url,
|
||||
'publishing-url-2': spaCyNLPPipelineModel.publishing_url,
|
||||
'publishing-year': spaCyNLPPipelineModel.publishing_year,
|
||||
'title': spaCyNLPPipelineModel.title,
|
||||
'title-2': spaCyNLPPipelineModel.title,
|
||||
'version': spaCyNLPPipelineModel.version,
|
||||
'is_public': spaCyNLPPipelineModel.is_public ? 'True' : 'False'
|
||||
};
|
||||
}
|
||||
|
||||
sort() {
|
||||
this.listjs.sort('creation-date', {order: 'desc'});
|
||||
}
|
||||
// #endregion
|
||||
|
||||
onChange(event) {
|
||||
let actionSwitchElement = event.target.closest('.action-switch');
|
||||
let action = actionSwitchElement.dataset.action;
|
||||
let spaCyNLPPipelineModelElement = event.target.closest('tr');
|
||||
let spaCyNLPPipelineModelId = spaCyNLPPipelineModelElement.dataset.id;
|
||||
switch (action) {
|
||||
case 'share-request': {
|
||||
let is_public = actionSwitchElement.querySelector('input').checked;
|
||||
Utils.shareSpaCyNLPPipelineModelRequest(this.userId, spaCyNLPPipelineModelId, is_public);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onClick(event) {
|
||||
if (event.target.closest('.action-switch')) {
|
||||
let userRole = app.data.users[this.userId].role.name;
|
||||
if (userRole !== ('Administrator' || 'Contributor')) {
|
||||
app.flash('You need the "Contributor" or "Administrator" role to perform this action.', 'error');
|
||||
}
|
||||
return;
|
||||
}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
||||
let spaCyNLPPipelineModelElement = event.target.closest('tr');
|
||||
let spaCyNLPPipelineModelId = spaCyNLPPipelineModelElement.dataset.id;
|
||||
switch (action) {
|
||||
case 'delete-request': {
|
||||
Utils.deleteSpaCyNLPPipelineModelRequest(this.userId, spaCyNLPPipelineModelId);
|
||||
break;
|
||||
}
|
||||
case 'view': {
|
||||
window.location.href = `/contributions/spacy-nlp-pipeline-models/${spaCyNLPPipelineModelId}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
166
app/static/js/ResourceLists/TesseractOCRPipelineModelList.js
Normal file
166
app/static/js/ResourceLists/TesseractOCRPipelineModelList.js
Normal file
@ -0,0 +1,166 @@
|
||||
class TesseractOCRPipelineModelList extends ResourceList {
|
||||
static autoInit() {
|
||||
for (let tesseractOCRPipelineModelListElement of document.querySelectorAll('.tesseract-ocr-pipeline-model-list:not(.no-autoinit)')) {
|
||||
new TesseractOCRPipelineModelList(tesseractOCRPipelineModelListElement);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, options);
|
||||
this.listjs.list.addEventListener('change', (event) => {this.onChange(event)});
|
||||
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
||||
this.isInitialized = false;
|
||||
this.userId = listContainerElement.dataset.userId;
|
||||
app.subscribeUser(this.userId).then((response) => {
|
||||
app.socket.on('PATCH', (patch) => {
|
||||
if (this.isInitialized) {this.onPatch(patch);}
|
||||
});
|
||||
});
|
||||
app.getUser(this.userId).then((user) => {
|
||||
this.add(Object.values(user.tesseract_ocr_pipeline_models));
|
||||
for (let uncheckedCheckbox of this.listjs.list.querySelectorAll('input[data-checked="True"]')) {
|
||||
uncheckedCheckbox.setAttribute('checked', '');
|
||||
}
|
||||
if (user.role.name !== ('Administrator' || 'Contributor')) {
|
||||
for (let switchElement of this.listjs.list.querySelectorAll('.is_public')) {
|
||||
switchElement.setAttribute('disabled', '');
|
||||
}
|
||||
}
|
||||
this.isInitialized = true;
|
||||
});
|
||||
}
|
||||
|
||||
// #region Mandatory getters and methods to implement
|
||||
get item() {
|
||||
return `
|
||||
<tr class="clickable hoverable">
|
||||
<td><b><span class="title"></span> <span class="version"></span></b><br><i><span class="description"></span></i></td>
|
||||
<td><a class="publisher-url"><span class="publisher"></span></a> (<span class="publishing-year"></span>)<br><a class="publishing-url"><span class="publishing-url-2"></span></a></td>
|
||||
<td>
|
||||
<div class="switch action-switch center-align" data-action="share-request">
|
||||
<span class="share"></span>
|
||||
<label>
|
||||
<input type="checkbox" class="is_public">
|
||||
<span class="lever"></span>
|
||||
public
|
||||
</label>
|
||||
</div>
|
||||
</td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete-request"><i class="material-icons">delete</i></a>
|
||||
<a class="action-button btn-floating service-color darken waves-effect waves-light service-2" data-action="view"><i class="material-icons">send</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim();
|
||||
}
|
||||
|
||||
get valueNames() {
|
||||
return [
|
||||
{data: ['id']},
|
||||
{data: ['creation-date']},
|
||||
{name: 'publisher-url', attr: 'href'},
|
||||
{name: 'publishing-url', attr: 'href'},
|
||||
'description',
|
||||
'publisher',
|
||||
'publishing-url-2',
|
||||
'publishing-year',
|
||||
'title',
|
||||
'title-2',
|
||||
'version',
|
||||
{name: 'is_public', attr: 'data-checked'}
|
||||
];
|
||||
}
|
||||
|
||||
initListContainerElement() {
|
||||
if (!this.listContainerElement.hasAttribute('id')) {
|
||||
this.listContainerElement.id = Utils.generateElementId('tesseract-ocr-pipeline-model-list-');
|
||||
}
|
||||
let listSearchElementId = Utils.generateElementId(`${this.listContainerElement.id}-search-`);
|
||||
this.listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listSearchElementId}" class="search" type="text"></input>
|
||||
<label for="${listSearchElementId}">Search Tesseract OCR Pipeline Model</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Title and Description</th>
|
||||
<th>Publisher</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region Optional methods to implement
|
||||
mapResourceToValue(tesseractOCRPipelineModel) {
|
||||
return {
|
||||
'id': tesseractOCRPipelineModel.id,
|
||||
'creation-date': tesseractOCRPipelineModel.creation_date,
|
||||
'description': tesseractOCRPipelineModel.description,
|
||||
'publisher': tesseractOCRPipelineModel.publisher,
|
||||
'publisher-url': tesseractOCRPipelineModel.publisher_url,
|
||||
'publishing-url': tesseractOCRPipelineModel.publishing_url,
|
||||
'publishing-url-2': tesseractOCRPipelineModel.publishing_url,
|
||||
'publishing-year': tesseractOCRPipelineModel.publishing_year,
|
||||
'title': tesseractOCRPipelineModel.title,
|
||||
'title-2': tesseractOCRPipelineModel.title,
|
||||
'version': tesseractOCRPipelineModel.version,
|
||||
'is_public': tesseractOCRPipelineModel.is_public ? 'True' : 'False'
|
||||
};
|
||||
}
|
||||
|
||||
sort() {
|
||||
this.listjs.sort('creation-date', {order: 'desc'});
|
||||
}
|
||||
// #endregion
|
||||
|
||||
onChange(event) {
|
||||
let actionSwitchElement = event.target.closest('.action-switch');
|
||||
let action = actionSwitchElement.dataset.action;
|
||||
let tesseractOCRPipelineModelElement = event.target.closest('tr');
|
||||
let tesseractOCRPipelineModelId = tesseractOCRPipelineModelElement.dataset.id;
|
||||
switch (action) {
|
||||
case 'share-request': {
|
||||
let is_public = actionSwitchElement.querySelector('input').checked;
|
||||
Utils.shareTesseractOCRPipelineModelRequest(this.userId, tesseractOCRPipelineModelId, is_public);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onClick(event) {
|
||||
if (event.target.closest('.action-switch')) {
|
||||
let userRole = app.data.users[this.userId].role.name;
|
||||
if (userRole !== ('Administrator' || 'Contributor')) {
|
||||
app.flash('You need the "Contributor" or "Administrator" role to perform this action.', 'error');
|
||||
}
|
||||
return;
|
||||
}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
||||
let tesseractOCRPipelineModelElement = event.target.closest('tr');
|
||||
let tesseractOCRPipelineModelId = tesseractOCRPipelineModelElement.dataset.id;
|
||||
switch (action) {
|
||||
case 'delete-request': {
|
||||
Utils.deleteTesseractOCRPipelineModelRequest(this.userId, tesseractOCRPipelineModelId);
|
||||
break;
|
||||
}
|
||||
case 'view': {
|
||||
window.location.href = `/contributions/tesseract-ocr-pipeline-models/${tesseractOCRPipelineModelId}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
116
app/static/js/ResourceLists/UserList.js
Normal file
116
app/static/js/ResourceLists/UserList.js
Normal file
@ -0,0 +1,116 @@
|
||||
class UserList extends ResourceList {
|
||||
static autoInit() {
|
||||
for (let userListElement of document.querySelectorAll('.user-list:not(.no-autoinit)')) {
|
||||
new UserList(userListElement);
|
||||
}
|
||||
}
|
||||
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, options);
|
||||
this.listjs.list.addEventListener('click', (event) => {this.onClick(event)});
|
||||
}
|
||||
|
||||
// #region Mandatory getters and methods to implement
|
||||
get item() {
|
||||
return `
|
||||
<tr class="clickable hoverable">
|
||||
<td><span class="id-1"></span></td>
|
||||
<td><span class="username"></span></td>
|
||||
<td><span class="email"></span></td>
|
||||
<td><span class="last-seen"></span></td>
|
||||
<td><span class="role"></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete"><i class="material-icons">delete</i></a>
|
||||
<a class="action-button btn-floating waves-effect waves-light" data-action="edit"><i class="material-icons">edit</i></a>
|
||||
<a class="action-button btn-floating waves-effect waves-light" data-action="view"><i class="material-icons">send</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim();
|
||||
}
|
||||
|
||||
get valueNames() {
|
||||
return [
|
||||
{data: ['id']},
|
||||
{data: ['member-since']},
|
||||
'email',
|
||||
'id-1',
|
||||
'last-seen',
|
||||
'role',
|
||||
'username'
|
||||
];
|
||||
}
|
||||
|
||||
initListContainerElement() {
|
||||
if (!this.listContainerElement.hasAttribute('id')) {
|
||||
this.listContainerElement.id = Utils.generateElementId('user-list-');
|
||||
}
|
||||
let listSearchElementId = Utils.generateElementId(`${this.listContainerElement.id}-search-`);
|
||||
this.listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listSearchElementId}" class="search" type="text"></input>
|
||||
<label for="${listSearchElementId}">Search user</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Username</th>
|
||||
<th>Email</th>
|
||||
<th>Last seen</th>
|
||||
<th>Role</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
}
|
||||
// #endregion
|
||||
|
||||
// #region Optional methods to implement
|
||||
mapResourceToValue(user) {
|
||||
return {
|
||||
'id': user.id,
|
||||
'id-1': user.id,
|
||||
'username': user.username,
|
||||
'email': user.email,
|
||||
'last-seen': new Date(user.last_seen).toLocaleString('en-US'),
|
||||
'member-since': user.member_since,
|
||||
'role': user.role.name
|
||||
};
|
||||
}
|
||||
|
||||
sort() {
|
||||
this.listjs.sort('member-since', {order: 'desc'});
|
||||
}
|
||||
// #endregion
|
||||
|
||||
onClick(event) {
|
||||
let userElement = event.target.closest('tr');
|
||||
if (userElement === null) {return;}
|
||||
let userId = userElement.dataset.id;
|
||||
if (userId === undefined) {return;}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
||||
switch (action) {
|
||||
case 'delete': {
|
||||
Utils.deleteUserRequest(userId);
|
||||
if (userId === currentUserId) {window.location.href = '/';}
|
||||
break;
|
||||
}
|
||||
case 'edit': {
|
||||
window.location.href = `/admin/users/${userId}/edit`;
|
||||
break;
|
||||
}
|
||||
case 'view': {
|
||||
window.location.href = `/admin/users/${userId}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,134 +0,0 @@
|
||||
class CorpusFileList extends RessourceList {
|
||||
static autoInit() {
|
||||
for (let corpusFileListElement of document.querySelectorAll('.corpus-file-list:not(.no-autoinit)')) {
|
||||
new CorpusFileList(corpusFileListElement);
|
||||
}
|
||||
}
|
||||
|
||||
static options = {
|
||||
listContainerInnerHTMLGenerator: (listContainerElement) => {
|
||||
listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listContainerElement.id}-search" class="search" type="text"></input>
|
||||
<label for="${listContainerElement.id}-search">Search corpus file</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Filename</th>
|
||||
<th>Author</th>
|
||||
<th>Title</th>
|
||||
<th>Publishing year</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
},
|
||||
ressourceMapper: (corpusFile) => {
|
||||
return {
|
||||
'id': corpusFile.id,
|
||||
'author': corpusFile.author,
|
||||
'creation-date': corpusFile.creation_date,
|
||||
'filename': corpusFile.filename,
|
||||
'publishing-year': corpusFile.publishing_year,
|
||||
'title': corpusFile.title
|
||||
};
|
||||
},
|
||||
sortParams: ['creation-date', {order: 'desc'}],
|
||||
listjs: {
|
||||
item: `
|
||||
<tr class="clickable hoverable">
|
||||
<td><span class="filename"></span></td>
|
||||
<td><span class="author"></span></td>
|
||||
<td><span class="title"></span></td>
|
||||
<td><span class="publishing-year"></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete"><i class="material-icons">delete</i></a>
|
||||
<a class="action-button btn-floating service-color darken waves-effect waves-light" data-action="download" data-service="corpus-analysis"><i class="material-icons">file_download</i></a>
|
||||
<a class="action-button btn-floating service-color darken waves-effect waves-light" data-action="view" data-service="corpus-analysis"><i class="material-icons">send</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim(),
|
||||
valueNames: [
|
||||
{data: ['id']},
|
||||
{data: ['creation-date']},
|
||||
'author',
|
||||
'filename',
|
||||
'publishing-year',
|
||||
'title'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
constructor(listContainerElement, options={}) {
|
||||
super(listContainerElement, _.merge({}, CorpusFileList.options, options));
|
||||
this.corpusId = listContainerElement.dataset.corpusId;
|
||||
}
|
||||
|
||||
init(user) {
|
||||
this._init(user.corpora[this.corpusId].files);
|
||||
}
|
||||
|
||||
onClick(event) {
|
||||
let corpusFileElement = event.target.closest('tr');
|
||||
if (corpusFileElement === null) {return;}
|
||||
let corpusFileId = corpusFileElement.dataset.id;
|
||||
if (corpusFileId === undefined) {return;}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
||||
switch (action) {
|
||||
case 'delete': {
|
||||
Utils.deleteCorpusFileRequest(this.userId, this.corpusId, corpusFileId);
|
||||
break;
|
||||
}
|
||||
case 'download': {
|
||||
window.location.href = `/corpora/${this.corpusId}/files/${corpusFileId}/download`;
|
||||
break;
|
||||
}
|
||||
case 'view': {
|
||||
window.location.href = `/corpora/${this.corpusId}/files/${corpusFileId}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onPatch(patch) {
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/files/([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}/files/([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}/files/([A-Za-z0-9]*)$`);
|
||||
if (re.test(operation.path)) {
|
||||
let [match, corpusFileId] = operation.path.match(re);
|
||||
this.remove(corpusFileId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'replace': {
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/${this.corpusId}/files/([A-Za-z0-9]*)/(author|filename|publishing_year|title)$`);
|
||||
if (re.test(operation.path)) {
|
||||
let [match, corpusFileId, valueName] = operation.path.match(re);
|
||||
this.replace(corpusFileId, valueName.replace('_', '-'), operation.value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
class CorpusList extends RessourceList {
|
||||
static autoInit() {
|
||||
for (let corpusListElement of document.querySelectorAll('.corpus-list:not(.no-autoinit)')) {
|
||||
new CorpusList(corpusListElement);
|
||||
}
|
||||
}
|
||||
|
||||
static options = {
|
||||
listContainerInnerHTMLGenerator: (listContainerElement) => {
|
||||
listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listContainerElement.id}-search" class="search" type="text"></input>
|
||||
<label for="${listContainerElement.id}-search">Search corpus</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Title and Description</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
},
|
||||
ressourceMapper: (corpus) => {
|
||||
return {
|
||||
'id': corpus.id,
|
||||
'creation-date': corpus.creation_date,
|
||||
'description': corpus.description,
|
||||
'status': corpus.status,
|
||||
'title': corpus.title
|
||||
};
|
||||
},
|
||||
sortParams: ['creation-date', {order: 'desc'}],
|
||||
listjs: {
|
||||
item: `
|
||||
<tr class="clickable hoverable">
|
||||
<td><a class="btn-floating disabled"><i class="material-icons service-color darken" data-service="corpus-analysis">book</i></a></td>
|
||||
<td><b class="title"></b><br><i class="description"></i></td>
|
||||
<td><span class="status badge new corpus-status-color corpus-status-text" data-badge-caption=""></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete-request"><i class="material-icons">delete</i></a>
|
||||
<a class="action-button btn-floating service-color darken waves-effect waves-light" data-action="view" data-service="corpus-analysis"><i class="material-icons">send</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim(),
|
||||
valueNames: [
|
||||
{data: ['id']},
|
||||
{data: ['creation-date']},
|
||||
{name: 'status', attr: 'data-status'},
|
||||
'description',
|
||||
'title'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
constructor(listContainerElement, options={}) {
|
||||
super(listContainerElement, _.merge({}, CorpusList.options, options));
|
||||
}
|
||||
|
||||
init(user) {
|
||||
this._init(user.corpora);
|
||||
}
|
||||
|
||||
onClick(event) {
|
||||
let corpusElement = event.target.closest('tr');
|
||||
if (corpusElement === null) {return;}
|
||||
let corpusId = corpusElement.dataset.id;
|
||||
if (corpusId === undefined) {return;}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
||||
switch (action) {
|
||||
case 'delete-request': {
|
||||
Utils.deleteCorpusRequest(this.userId, corpusId);
|
||||
break;
|
||||
}
|
||||
case 'view': {
|
||||
window.location.href = `/corpora/${corpusId}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onPatch(patch) {
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/([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/([A-Za-z0-9]*)$`);
|
||||
if (re.test(operation.path)) {this.add(operation.value);}
|
||||
break;
|
||||
}
|
||||
case 'remove': {
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/([A-Za-z0-9]*)$`);
|
||||
if (re.test(operation.path)) {
|
||||
let [match, corpusId] = operation.path.match(re);
|
||||
this.remove(corpusId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'replace': {
|
||||
let re = new RegExp(`^/users/${this.userId}/corpora/([A-Za-z0-9]*)/(status|description|title)$`);
|
||||
if (re.test(operation.path)) {
|
||||
let [match, corpusId, valueName] = operation.path.match(re);
|
||||
this.replace(corpusId, valueName, operation.value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
class JobInputList extends RessourceList {
|
||||
static autoInit() {
|
||||
for (let jobInputListElement of document.querySelectorAll('.job-input-list:not(.no-autoinit)')) {
|
||||
new JobInputList(jobInputListElement);
|
||||
}
|
||||
}
|
||||
|
||||
static options = {
|
||||
listContainerInnerHTMLGenerator: (listContainerElement) => {
|
||||
listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listContainerElement.id}-search" class="search" type="text"></input>
|
||||
<label for="${listContainerElement.id}-search">Search job input</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Filename</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
},
|
||||
ressourceMapper: (jobInput) => {
|
||||
return {
|
||||
'id': jobInput.id,
|
||||
'creation-date': jobInput.creation_date,
|
||||
'filename': jobInput.filename
|
||||
};
|
||||
},
|
||||
sortParams: ['filename', {order: 'asc'}],
|
||||
listjs: {
|
||||
item: `
|
||||
<tr class="clickable hoverable">
|
||||
<td><span class="filename"></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating waves-effect waves-light" data-action="download"><i class="material-icons">file_download</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim(),
|
||||
valueNames: [
|
||||
{data: ['id']},
|
||||
{data: ['creation-date']},
|
||||
'filename'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
constructor(listContainerElement, options={}) {
|
||||
super(listContainerElement, _.merge({}, JobInputList.options, options));
|
||||
this.jobId = listContainerElement.dataset.jobId;
|
||||
}
|
||||
|
||||
init(user) {
|
||||
this._init(user.jobs[this.jobId].inputs);
|
||||
}
|
||||
|
||||
onClick(event) {
|
||||
let jobInputElement = event.target.closest('tr');
|
||||
if (jobInputElement === null) {return;}
|
||||
let jobInputId = jobInputElement.dataset.id;
|
||||
if (jobInputId === undefined) {return;}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'download' : actionButtonElement.dataset.action;
|
||||
switch (action) {
|
||||
case 'download': {
|
||||
window.location.href = `/jobs/${this.jobId}/inputs/${jobInputId}/download`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onPatch(patch) {return;}
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
class JobList extends RessourceList {
|
||||
static autoInit() {
|
||||
for (let jobListElement of document.querySelectorAll('.job-list:not(.no-autoinit)')) {
|
||||
new JobList(jobListElement);
|
||||
}
|
||||
}
|
||||
|
||||
static options = {
|
||||
listContainerInnerHTMLGenerator: (listContainerElement) => {
|
||||
listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listContainerElement.id}-search" class="search" type="text"></input>
|
||||
<label for="${listContainerElement.id}-search">Search job</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Service</th>
|
||||
<th>Title and Description</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
},
|
||||
ressourceMapper: (job) => {
|
||||
return {
|
||||
'id': job.id,
|
||||
'creation-date': job.creation_date,
|
||||
'description': job.description,
|
||||
'service': job.service,
|
||||
'status': job.status,
|
||||
'title': job.title
|
||||
};
|
||||
},
|
||||
sortParams: ['creation-date', {order: 'desc'}],
|
||||
listjs: {
|
||||
item: `
|
||||
<tr class="clickable hoverable service-scheme">
|
||||
<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><span class="badge new job-status-color job-status-text status" data-badge-caption=""></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete-request"><i class="material-icons">delete</i></a>
|
||||
<a class="action-button btn-floating darken waves-effect waves-light" data-action="view"><i class="material-icons">send</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim(),
|
||||
valueNames: [
|
||||
{data: ['id']},
|
||||
{data: ['creation-date']},
|
||||
{data: ['service']},
|
||||
{name: 'status', attr: 'data-status'},
|
||||
'description',
|
||||
'title'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
constructor(listContainerElement, options={}) {
|
||||
super(listContainerElement, _.merge({}, JobList.options, options));
|
||||
console.log(this);
|
||||
}
|
||||
|
||||
init(user) {
|
||||
this._init(user.jobs);
|
||||
}
|
||||
|
||||
onClick(event) {
|
||||
let jobElement = event.target.closest('tr');
|
||||
if (jobElement === null) {return;}
|
||||
let jobId = jobElement.dataset.id;
|
||||
if (jobId === undefined) {return;}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
||||
switch (action) {
|
||||
case 'delete-request': {
|
||||
Utils.deleteJobRequest(this.userId, jobId);
|
||||
break;
|
||||
}
|
||||
case 'view': {
|
||||
window.location.href = `/jobs/${jobId}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onPatch(patch) {
|
||||
let re = new RegExp(`^/users/${this.userId}/jobs/([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}/jobs/([A-Za-z0-9]*)$`);
|
||||
if (re.test(operation.path)) {this.add(operation.value);}
|
||||
break;
|
||||
}
|
||||
case 'remove': {
|
||||
let re = new RegExp(`^/users/${this.userId}/jobs/([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}/jobs/([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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
class JobResultList extends RessourceList {
|
||||
static autoInit() {
|
||||
for (let jobResultListElement of document.querySelectorAll('.job-result-list:not(.no-autoinit)')) {
|
||||
new JobResultList(jobResultListElement);
|
||||
}
|
||||
}
|
||||
|
||||
static options = {
|
||||
listContainerInnerHTMLGenerator: (listContainerElement) => {
|
||||
listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listContainerElement.id}-search" class="search" type="text"></input>
|
||||
<label for="${listContainerElement.id}-search">Search job result</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Description</th>
|
||||
<th>Filename</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
},
|
||||
ressourceMapper: (jobResult) => {
|
||||
return {
|
||||
'id': jobResult.id,
|
||||
'creation-date': jobResult.creation_date,
|
||||
'description': jobResult.description,
|
||||
'filename': jobResult.filename
|
||||
};
|
||||
},
|
||||
sortParams: ['filename', {order: 'asc'}],
|
||||
listjs: {
|
||||
item: `
|
||||
<tr class="clickable hoverable">
|
||||
<td><span class="description"></span></td>
|
||||
<td><span class="filename"></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating waves-effect waves-light" data-action="download"><i class="material-icons">file_download</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim(),
|
||||
valueNames: [
|
||||
{data: ['id']},
|
||||
{data: ['creation-date']},
|
||||
'description',
|
||||
'filename'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, {...JobResultList.options, ...options});
|
||||
this.jobId = listContainerElement.dataset.jobId;
|
||||
}
|
||||
|
||||
init(user) {
|
||||
super._init(user.jobs[this.jobId].results);
|
||||
}
|
||||
|
||||
onClick(event) {
|
||||
let jobResultElement = event.target.closest('tr');
|
||||
if (jobResultElement === null) {return;}
|
||||
let jobResultId = jobResultElement.dataset.id;
|
||||
if (jobResultId === undefined) {return;}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'download' : actionButtonElement.dataset.action;
|
||||
switch (action) {
|
||||
case 'download': {
|
||||
window.location.href = `/jobs/${this.jobId}/results/${jobResultId}/download`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onPatch(patch) {
|
||||
let re = new RegExp(`^/users/${this.userId}/jobs/${this.jobId}/results/([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}/jobs/${this.jobId}/results/([A-Za-z0-9]*)$`);
|
||||
if (re.test(operation.path)) {this.add(operation.value);}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
class PublicUserList extends RessourceList {
|
||||
static autoInit() {
|
||||
for (let publicUserListElement of document.querySelectorAll('.public-user-list:not(.no-autoinit)')) {
|
||||
new PublicUserList(publicUserListElement);
|
||||
}
|
||||
}
|
||||
|
||||
static options = {
|
||||
listContainerInnerHTMLGenerator: (listContainerElement) => {
|
||||
listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listContainerElement.id}-search" class="search" type="text"></input>
|
||||
<label for="${listContainerElement.id}-search">Search user</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:15%;"></th>
|
||||
<th>Username</th>
|
||||
<th>Full name</th>
|
||||
<th>Location</th>
|
||||
<th>Organization</th>
|
||||
<th>Corpora online</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
},
|
||||
ressourceMapper: (user) => {
|
||||
return {
|
||||
'id': user.id,
|
||||
'member-since': user.member_since,
|
||||
'avatar': user.avatar ? `/users/${user.id}/avatar` : '/static/images/user_avatar.png',
|
||||
'username': user.username,
|
||||
'full-name': user.full_name ? user.full_name : '',
|
||||
'location': user.location ? user.location : '',
|
||||
'organization': user.organization ? user.organization : '',
|
||||
'corpora-online': '0'
|
||||
};
|
||||
},
|
||||
sortParams: ['member-since', {order: 'desc'}],
|
||||
listjs: {
|
||||
item: `
|
||||
<tr class="clickable hoverable">
|
||||
<td><img alt="user-image" class="circle responsive-img avatar" style="width:50%"></td>
|
||||
<td><b><span class="username"></span><b></td>
|
||||
<td><span class="full-name"></span></td>
|
||||
<td><span class="location"></span></td>
|
||||
<td><span class="organization"></span></td>
|
||||
<td><span class="corpora-online"></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating waves-effect waves-light" data-action="view"><i class="material-icons">send</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim(),
|
||||
valueNames: [
|
||||
{data: ['id']},
|
||||
{data: ['member-since']},
|
||||
{name: 'avatar', attr: 'src'},
|
||||
'username',
|
||||
'full-name',
|
||||
'location',
|
||||
'organization',
|
||||
'corpora-online'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, {...PublicUserList.options, ...options});
|
||||
}
|
||||
|
||||
init(users) {
|
||||
super._init(Object.values(users));
|
||||
}
|
||||
|
||||
onClick(event) {
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
||||
let publicUserElement = event.target.closest('tr');
|
||||
let publicUserId = publicUserElement.dataset.id;
|
||||
switch (action) {
|
||||
case 'view': {
|
||||
window.location.href = `/users/${publicUserId}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
class SpaCyNLPPipelineModelList extends RessourceList {
|
||||
static autoInit() {
|
||||
for (let spaCyNLPPipelineModelListElement of document.querySelectorAll('.spacy-nlp-pipeline-model-list:not(.no-autoinit)')) {
|
||||
new SpaCyNLPPipelineModelList(spaCyNLPPipelineModelListElement);
|
||||
}
|
||||
}
|
||||
|
||||
static options = {
|
||||
listContainerInnerHTMLGenerator: (listContainerElement) => {
|
||||
listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listContainerElement.id}-search" class="search" type="text"></input>
|
||||
<label for="${listContainerElement.id}-search">Search SpaCy NLP Pipeline Model</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Title and Description</th>
|
||||
<th>Publisher</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
},
|
||||
ressourceMapper: (spaCyNLPPipelineModel) => {
|
||||
return {
|
||||
'id': spaCyNLPPipelineModel.id,
|
||||
'creation-date': spaCyNLPPipelineModel.creation_date,
|
||||
'description': spaCyNLPPipelineModel.description,
|
||||
'publisher': spaCyNLPPipelineModel.publisher,
|
||||
'publisher-url': spaCyNLPPipelineModel.publisher_url,
|
||||
'publishing-url': spaCyNLPPipelineModel.publishing_url,
|
||||
'publishing-url-2': spaCyNLPPipelineModel.publishing_url,
|
||||
'publishing-year': spaCyNLPPipelineModel.publishing_year,
|
||||
'title': spaCyNLPPipelineModel.title,
|
||||
'title-2': spaCyNLPPipelineModel.title,
|
||||
'version': spaCyNLPPipelineModel.version,
|
||||
'is_public': spaCyNLPPipelineModel.is_public ? 'True' : 'False'
|
||||
};
|
||||
},
|
||||
sortParams: ['creation-date', {order: 'desc'}],
|
||||
listjs: {
|
||||
item: `
|
||||
<tr class="clickable hoverable">
|
||||
<td><b><span class="title"></span> <span class="version"></span></b><br><i><span class="description"></span></i></td>
|
||||
<td><a class="publisher-url"><span class="publisher"></span></a> (<span class="publishing-year"></span>)<br><a class="publishing-url"><span class="publishing-url-2"></span></a></td>
|
||||
<td>
|
||||
<div class="switch action-switch center-align" data-action="share-request">
|
||||
<span class="share"></span>
|
||||
<label>
|
||||
<input type="checkbox" class="is_public">
|
||||
<span class="lever"></span>
|
||||
public
|
||||
</label>
|
||||
</div>
|
||||
</td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete-request"><i class="material-icons">delete</i></a>
|
||||
<a class="action-button btn-floating service-color darken waves-effect waves-light service-2" data-action="view"><i class="material-icons">send</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim(),
|
||||
valueNames: [
|
||||
{data: ['id']},
|
||||
{data: ['creation-date']},
|
||||
{name: 'publisher-url', attr: 'href'},
|
||||
{name: 'publishing-url', attr: 'href'},
|
||||
'description',
|
||||
'publisher',
|
||||
'publishing-url-2',
|
||||
'publishing-year',
|
||||
'title',
|
||||
'title-2',
|
||||
'version',
|
||||
{name: 'is_public', attr: 'data-checked'}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, {...SpaCyNLPPipelineModelList.options, ...options});
|
||||
this.listjs.list.addEventListener('change', (event) => {this.onChange(event)});
|
||||
}
|
||||
|
||||
init(user) {
|
||||
this._init(user.spacy_nlp_pipeline_models);
|
||||
if (user.role.name !== ('Administrator' || 'Contributor')) {
|
||||
for (let switchElement of this.listjs.list.querySelectorAll('.is_public')) {
|
||||
switchElement.setAttribute('disabled', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_init(ressources) {
|
||||
super._init(ressources);
|
||||
for (let uncheckedCheckbox of this.listjs.list.querySelectorAll('input[data-checked="True"]')) {
|
||||
uncheckedCheckbox.setAttribute('checked', '');
|
||||
}
|
||||
}
|
||||
|
||||
onClick(event) {
|
||||
if (event.target.closest('.action-switch')) {
|
||||
let userRole = app.data.users[this.userId].role.name;
|
||||
if (userRole !== ('Administrator' || 'Contributor')) {
|
||||
app.flash('You need the "Contributor" or "Administrator" role to perform this action.', 'error');
|
||||
}
|
||||
return;
|
||||
}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
||||
let spaCyNLPPipelineModelElement = event.target.closest('tr');
|
||||
let spaCyNLPPipelineModelId = spaCyNLPPipelineModelElement.dataset.id;
|
||||
switch (action) {
|
||||
case 'delete-request': {
|
||||
Utils.deleteSpaCyNLPPipelineModelRequest(this.userId, spaCyNLPPipelineModelId);
|
||||
break;
|
||||
}
|
||||
case 'view': {
|
||||
window.location.href = `/contributions/spacy-nlp-pipeline-models/${spaCyNLPPipelineModelId}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onChange(event) {
|
||||
let actionSwitchElement = event.target.closest('.action-switch');
|
||||
let action = actionSwitchElement.dataset.action;
|
||||
let spaCyNLPPipelineModelElement = event.target.closest('tr');
|
||||
let spaCyNLPPipelineModelId = spaCyNLPPipelineModelElement.dataset.id;
|
||||
switch (action) {
|
||||
case 'share-request': {
|
||||
let is_public = actionSwitchElement.querySelector('input').checked;
|
||||
Utils.shareSpaCyNLPPipelineModelRequest(this.userId, spaCyNLPPipelineModelId, is_public);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
class UserList extends RessourceList {
|
||||
static autoInit() {
|
||||
for (let userListElement of document.querySelectorAll('.user-list:not(.no-autoinit)')) {
|
||||
new UserList(userListElement);
|
||||
}
|
||||
}
|
||||
|
||||
static options = {
|
||||
listContainerInnerHTMLGenerator: (listContainerElement) => {
|
||||
listContainerElement.innerHTML = `
|
||||
<div class="input-field">
|
||||
<i class="material-icons prefix">search</i>
|
||||
<input id="${listContainerElement.id}-search" class="search" type="text"></input>
|
||||
<label for="${listContainerElement.id}-search">Search user</label>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Username</th>
|
||||
<th>Email</th>
|
||||
<th>Last seen</th>
|
||||
<th>Role</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="list"></tbody>
|
||||
</table>
|
||||
<ul class="pagination"></ul>
|
||||
`.trim();
|
||||
},
|
||||
ressourceMapper: (user) => {
|
||||
return {
|
||||
'id': user.id,
|
||||
'id-1': user.id,
|
||||
'username': user.username,
|
||||
'email': user.email,
|
||||
'last-seen': new Date(user.last_seen).toLocaleString('en-US'),
|
||||
'member-since': user.member_since,
|
||||
'role': user.role.name
|
||||
};
|
||||
},
|
||||
sortParams: ['member-since', {order: 'desc'}],
|
||||
listjs: {
|
||||
item: `
|
||||
<tr class="clickable hoverable">
|
||||
<td><span class="id-1"></span></td>
|
||||
<td><span class="username"></span></td>
|
||||
<td><span class="email"></span></td>
|
||||
<td><span class="last-seen"></span></td>
|
||||
<td><span class="role"></span></td>
|
||||
<td class="right-align">
|
||||
<a class="action-button btn-floating red waves-effect waves-light" data-action="delete"><i class="material-icons">delete</i></a>
|
||||
<a class="action-button btn-floating waves-effect waves-light" data-action="edit"><i class="material-icons">edit</i></a>
|
||||
<a class="action-button btn-floating waves-effect waves-light" data-action="view"><i class="material-icons">send</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim(),
|
||||
valueNames: [
|
||||
{data: ['id']},
|
||||
{data: ['member-since']},
|
||||
'email',
|
||||
'id-1',
|
||||
'last-seen',
|
||||
'role',
|
||||
'username'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
constructor(listContainerElement, options = {}) {
|
||||
super(listContainerElement, {...UserList.options, ...options});
|
||||
}
|
||||
|
||||
init(users) {
|
||||
super._init(Object.values(users));
|
||||
}
|
||||
|
||||
onClick(event) {
|
||||
let userElement = event.target.closest('tr');
|
||||
if (userElement === null) {return;}
|
||||
let userId = userElement.dataset.id;
|
||||
if (userId === undefined) {return;}
|
||||
let actionButtonElement = event.target.closest('.action-button');
|
||||
let action = actionButtonElement === null ? 'view' : actionButtonElement.dataset.action;
|
||||
switch (action) {
|
||||
case 'delete': {
|
||||
Utils.deleteUserRequest(userId);
|
||||
if (userId === currentUserId) {window.location.href = '/';}
|
||||
break;
|
||||
}
|
||||
case 'edit': {
|
||||
window.location.href = `/admin/users/${userId}/edit`;
|
||||
break;
|
||||
}
|
||||
case 'view': {
|
||||
window.location.href = `/admin/users/${userId}`;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,13 @@ class Utils {
|
||||
return tmpElement.firstChild;
|
||||
}
|
||||
|
||||
static generateElementId(prefix='') {
|
||||
for (let i = 0; true; i++) {
|
||||
if (document.querySelector(`#${prefix}${i}`) !== null) {continue;}
|
||||
return `${prefix}${i}`;
|
||||
}
|
||||
}
|
||||
|
||||
static buildCorpusRequest(userId, corpusId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let corpus = app.data.users[userId].corpora[corpusId];
|
||||
|
@ -19,16 +19,16 @@
|
||||
'js/RessourceDisplays/RessourceDisplay.js',
|
||||
'js/RessourceDisplays/CorpusDisplay.js',
|
||||
'js/RessourceDisplays/JobDisplay.js',
|
||||
'js/RessourceLists/RessourceList.js',
|
||||
'js/RessourceLists/CorpusList.js',
|
||||
'js/RessourceLists/CorpusFileList.js',
|
||||
'js/RessourceLists/JobList.js',
|
||||
'js/RessourceLists/JobInputList.js',
|
||||
'js/RessourceLists/JobResultList.js',
|
||||
'js/RessourceLists/PublicUserList.js',
|
||||
'js/RessourceLists/SpacyNLPPipelineModelList.js',
|
||||
'js/RessourceLists/TesseractOCRPipelineModelList.js',
|
||||
'js/RessourceLists/UserList.js',
|
||||
'js/ResourceLists/ResourceList.js',
|
||||
'js/ResourceLists/CorpusFileList.js',
|
||||
'js/ResourceLists/CorpusList.js',
|
||||
'js/ResourceLists/JobList.js',
|
||||
'js/ResourceLists/JobInputList.js',
|
||||
'js/ResourceLists/JobResultList.js',
|
||||
'js/ResourceLists/UserList.js',
|
||||
'js/ResourceLists/PublicUserList.js',
|
||||
'js/ResourceLists/SpacyNLPPipelineModelList.js',
|
||||
'js/ResourceLists/TesseractOCRPipelineModelList.js',
|
||||
'js/XMLtoObject.js'
|
||||
%}
|
||||
<script src="{{ ASSET_URL }}"></script>
|
||||
@ -62,7 +62,7 @@
|
||||
document.querySelectorAll('#nav-more-dropdown-trigger'),
|
||||
{alignment: 'right', constrainWidth: false, coverTrigger: false}
|
||||
);
|
||||
RessourceList.autoInit();
|
||||
ResourceList.autoInit();
|
||||
Form.autoInit();
|
||||
|
||||
// Display flashed messages
|
||||
|
@ -23,6 +23,6 @@
|
||||
{{ super() }}
|
||||
<script>
|
||||
let userList = new UserList(document.querySelector('.user-list'));
|
||||
userList._init({{ json_users|tojson }});
|
||||
userList.add({{ json_users|tojson }});
|
||||
</script>
|
||||
{% endblock scripts %}
|
||||
|
@ -126,6 +126,6 @@
|
||||
{{ super() }}
|
||||
<script>
|
||||
let publicUserList = new PublicUserList(document.querySelector('.public-user-list'));
|
||||
publicUserList._init({{ users|tojson }});
|
||||
publicUserList.add({{ users|tojson }});
|
||||
</script>
|
||||
{% endblock scripts %}
|
||||
|
Loading…
Reference in New Issue
Block a user