mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-28 17:00:34 +00:00
Rework all Resource Lists
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user