Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
4a580446
Commit
4a580446
authored
5 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Add admin functions to api. Add to_jsonifyable method to Job and Corpus and use it in API.
parent
2832dd8b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models.py
+21
-0
21 additions, 0 deletions
app/models.py
app/templates/main/dashboard.html.j2
+99
-30
99 additions, 30 deletions
app/templates/main/dashboard.html.j2
with
120 additions
and
30 deletions
app/models.py
+
21
−
0
View file @
4a580446
...
@@ -247,6 +247,21 @@ class Job(db.Model):
...
@@ -247,6 +247,21 @@ class Job(db.Model):
"""
"""
return
'
<Job %r>
'
%
self
.
title
return
'
<Job %r>
'
%
self
.
title
def
to_jsonifyable
(
self
):
return
{
'
id
'
:
self
.
id
,
'
creation_date
'
:
self
.
creation_date
.
timestamp
(),
'
description
'
:
self
.
description
,
'
end_date
'
:
(
self
.
end_date
.
timestamp
()
if
self
.
end_date
else
None
),
'
mem_mb
'
:
self
.
mem_mb
,
'
n_cores
'
:
self
.
n_cores
,
'
service
'
:
self
.
service
,
'
service_args
'
:
self
.
service_args
,
'
service_version
'
:
self
.
service_version
,
'
status
'
:
self
.
status
,
'
title
'
:
self
.
title
,
'
user_id
'
:
self
.
user_id
}
class
Corpus
(
db
.
Model
):
class
Corpus
(
db
.
Model
):
"""
"""
...
@@ -269,6 +284,12 @@ class Corpus(db.Model):
...
@@ -269,6 +284,12 @@ class Corpus(db.Model):
"""
"""
return
'
<Corpus %r>
'
%
self
.
title
return
'
<Corpus %r>
'
%
self
.
title
def
to_jsonifyable
(
self
):
return
{
'
id
'
:
self
.
id
,
'
creation_date
'
:
self
.
creation_date
,
'
description
'
:
self
.
description
,
'
title
'
:
self
.
title
,
'
user_id
'
:
self
.
user_id
}
'''
'''
'
Flask-Login is told to use the application’s custom anonymous user by setting
'
Flask-Login is told to use the application’s custom anonymous user by setting
...
...
This diff is collapsed.
Click to expand it.
app/templates/main/dashboard.html.j2
+
99
−
30
View file @
4a580446
...
@@ -76,45 +76,114 @@
...
@@ -76,45 +76,114 @@
</div>
</div>
</div>
</div>
</div>
</div>
<div class="collection list">
<div class="collection list"></div>
{% for job in current_user.jobs.all() %}
{% if job.service == 'nlp' %}
{% set service_color = 'blue' %}
{% set service_icon = 'format_textdirection_l_to_r' %}
{% elif job.service =='ocr' %}
{% set service_color = 'green' %}
{% set service_icon = 'find_in_page' %}
{% else %}
{% set service_color = 'red' %}
{% set service_icon = 'help' %}
{% endif %}
{% if job.status == 'pending' %}
{% set badge_color = 'amber' %}
{% elif job.status =='running' %}
{% set badge_color = 'indigo' %}
{% elif job.status =='complete' %}
{% set badge_color = 'teal' %}
{% else %}
{% set badge_color = 'red' %}
{% endif %}
<a href="{{ url_for('main.job', job_id=job.id) }}" class="collection-item avatar">
<i class="material-icons circle {{ service_color }}">{{ service_icon }}</i>
<span class="new badge {{ badge_color }}" data-badge-caption="">{{ job.status }}</span>
<span class="title">{{ job.title }}</span>
<p>{{ job.description }}</p>
</a>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
<script>
<script>
var jobList = new List("job-list", {valueNames: ["title"],
var jobList = new List("job-list", {valueNames: ["title"],
page: 4,
page: 4,
pagination:
tru
e});
pagination:
fals
e});
jobList.on("filterComplete", updatePagination);
jobList.on("filterComplete", updatePagination);
jobList.on("searchComplete", updatePagination);
jobList.on("searchComplete", updatePagination);
</script>
</script>
<script>
const SERVICE_COLORS = {"nlp": "blue",
"ocr": "green"}
const SERVICE_ICONS = {"nlp": "format_textdirection_l_to_r",
"ocr": "find_in_page"}
const STATUS_COLORS = {"pending": "amber",
"running": "indigo",
"complete": "teal"}
var getJobsCallbackFunctions = [];
function getJobs() {
fetch("/api/v1.0/jobs")
.then(function(response) {
if (response.status >= 200 && response.status < 300) {
return Promise.resolve(response)
} else {
return Promise.reject(new Error(response.statusText))
}
})
.then(function(response) {
return response.json()
})
.then(function(jobs) {
for (callbackFunction of getJobsCallbackFunctions) {
callbackFunction(jobs);
}
})
.catch(function(error) {
console.log('Request failed', error);
});
}
setInterval(getJobs, 1000);
function createJobElement(job) {
jobElement = document.createElement("a");
jobElement.classList.add("avatar", "collection-item");
jobElement.dataset.key = "id";
jobElement.dataset.value = job.id;
jobElement.href = `/jobs/${job.id}`;
jobDescriptionElement = document.createElement("p");
jobDescriptionElement.dataset.key = "description";
jobDescriptionElement.innerText = job.description;
jobServiceElement = document.createElement("i");
jobServiceElement.classList.add("circle", "material-icons", SERVICE_COLORS[job.service]);
jobServiceElement.dataset.key = "service";
jobServiceElement.innerText = SERVICE_ICONS[job.service];
jobStatusElement = document.createElement("span");
jobStatusElement.classList.add("badge", "new", "status", STATUS_COLORS[job.status]);
jobStatusElement.dataset.badgeCaption = "";
jobStatusElement.dataset.key = "status";
jobStatusElement.innerText = job.status;
jobTitleElement = document.createElement("span");
jobTitleElement.classList.add("title");
jobTitleElement.dataset.key = "title";
jobTitleElement.innerText = job.title;
jobElement.appendChild(jobServiceElement);
jobElement.appendChild(jobStatusElement);
jobElement.appendChild(jobTitleElement);
jobElement.appendChild(jobDescriptionElement);
return jobElement;
}
function updateJobElement(job, jobElement) {
/*
if (jobElement.dataset.value != job.id) {
jobElement.dataset.value = job.id;
jobElement.href = `/jobs/${job.id}`;
}
*/
}
function processJobs(jobs) {
for (job of jobs) {
jobElement = jobList.list.querySelectorAll('[data-key="id"]')
.querySelector(`[data-value="${job.id}"]`);
console.log(jobElement);
if (jobElement) {
statusElement = jobElement.querySelector(".status");
currentStatus = statusElement.text
continue;
}
jobList.list.appendChild(createJobElement(job));
}
jobList.reIndex();
jobList.update();
}
getJobsCallbackFunctions.push(processJobs)
</script>
<div id="new-corpus-modal" class="modal">
<div id="new-corpus-modal" class="modal">
<div class="modal-content">
<div class="modal-content">
<h4>New corpus</h4>
<h4>New corpus</h4>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment