Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/1.3.17 forward ports #1886

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
23 changes: 13 additions & 10 deletions api/main/rest/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def _create_media(project, params, user, use_rq=False):
gid = params.get("gid", None)
uid = params.get("uid", None)
new_attributes = params.get("attributes", None)
url = params.get("url")
url = params.get("url", None)
elemental_id = params.get("elemental_id", uuid4())
if gid is not None:
gid = str(gid)
Expand Down Expand Up @@ -317,15 +317,18 @@ def _create_media(project, params, user, use_rq=False):
# Set up S3 client.
tator_store = get_tator_store(project_obj.bucket)

reference_only = params.get("reference_only", 0) == 1
if use_rq:
push_job(
"image_jobs",
main._import_image._import_image,
args=(name, url, thumbnail_url, media_obj.id, reference_only),
)
else:
main._import_image._import_image(name, url, thumbnail_url, media_obj.id, reference_only)
if url:
reference_only = params.get("reference_only", 0) == 1
if use_rq:
push_job(
"image_jobs",
main._import_image._import_image,
args=(name, url, thumbnail_url, media_obj.id, reference_only),
)
else:
main._import_image._import_image(
name, url, thumbnail_url, media_obj.id, reference_only
)

else:
# Create the media object.
Expand Down
10 changes: 10 additions & 0 deletions api/main/rest/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,9 +678,19 @@ def delete_qs(self, params, qs):
f"Pedantic mode is enabled. Can not edit prior object {state.pk}, must only edit latest mark on version."
f"Object is mark {state.mark} of {state.latest_mark} for {state.version.name}/{state.elemental_id}"
)
old_media = state.media.all()
old_localizations = state.localizations.all()
state.pk = None
state.variant_deleted = True
origin_datetime = state.created_datetime
state.save()
found_it = State.objects.get(pk=state.pk)
# Keep original creation time
found_it.created_datetime = origin_datetime
found_it.save()
found_it.media.set(old_media)
found_it.localizations.set(old_localizations)
found_it.save()
obj_id = state.pk
log_changes(state, state.model_dict, state.project, self.request.user)
qs = Localization.objects.filter(pk__in=delete_localizations)
Expand Down
2 changes: 1 addition & 1 deletion api/main/schema/components/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
"type": "string",
},
"reference_only": {
"description": "Do not import the media resources into Tator. This causes the image to be accessed at the supplied URL upon access in the UI. Valid for images only.",
"description": "Do not import the media resources into Tator. This causes the image to be accessed at the supplied URL upon access in the UI. Attempts loading the image from the URL, but fall back to other records if the URL is not accessible.",
"type": "integer",
"default": 0,
"maximum": 1,
Expand Down
18 changes: 18 additions & 0 deletions api/main/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2997,6 +2997,24 @@ def setUp(self):
self.patch_json = {"name": "image1"}
memberships_to_rowp(self.project.pk, force=False, verbose=False)

def test_empty_image(self):
unique_string_attr_val = str(uuid4())
body = [
{
"type": self.entity_type.pk,
"section": "asdf",
"name": "asdf",
"md5": "asdf",
"attributes": {"String Test": unique_string_attr_val},
}
]
response = self.client.post(f"/rest/Medias/{self.project.pk}", body, format="json")
media_id1 = response.data["id"][0]

response = self.client.get(f"/rest/Media/{media_id1}")
assert response.data["attributes"]["String Test"] == unique_string_attr_val
assert response.data["media_files"] in [None, {}]


class LocalizationBoxTestCase(
TatorTransactionTest,
Expand Down
2 changes: 1 addition & 1 deletion scripts/packages/tator-py
5 changes: 5 additions & 0 deletions ui/src/js/annotation/annotation-multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,11 @@ export class AnnotationMulti extends TatorElement {

this._videoTimeline.init(0, this._timeStore.getLastGlobalFrame());
this._entityTimeline.init(0, this._timeStore.getLastGlobalFrame());
this._displayTimelineLabels = true;
this._entityTimeline.showFocus(
this._displayTimelineLabels,
this._videos[this._primaryVideoIndex].currentFrame()
);

this._slider.setAttribute("min", 0);
this._slider.setAttribute("max", this._timeStore.getLastGlobalFrame());
Expand Down
5 changes: 5 additions & 0 deletions ui/src/js/annotation/annotation-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,11 @@ export class AnnotationPlayer extends TatorElement {

this._videoTimeline.init(0, this._timeStore.getLastGlobalFrame());
this._entityTimeline.init(0, this._timeStore.getLastGlobalFrame());
this._displayTimelineLabels = true;
this._entityTimeline.showFocus(
this._displayTimelineLabels,
this._video.currentFrame()
);

this._slider.setAttribute("min", 0);
this._slider.setAttribute("max", this._timeStore.getLastGlobalFrame());
Expand Down
15 changes: 1 addition & 14 deletions ui/src/js/annotation/entity-timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1581,20 +1581,7 @@ export class EntityTimeline extends BaseTimeline {
showFocus(display, currentFrame) {
if (display) {
if (currentFrame != null) {
var timelineSpan = this._maxFrame - this._minFrame;
var window = Math.floor(timelineSpan * 0.1);
if (window < 25) {
window = 25;
}
var minFrame = currentFrame - window;
if (minFrame < this._minFrame) {
minFrame = this._minFrame;
}
var maxFrame = currentFrame + window;
if (maxFrame > this._maxFrame) {
maxFrame = this._maxFrame;
}
this._mainBrushWindow = [minFrame, maxFrame];
this._mainBrushWindow = [this._minFrame, this._maxFrame];
}

this._focusTimelineDiv.style.display = "block";
Expand Down
25 changes: 23 additions & 2 deletions ui/src/js/project-detail/project-text.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import { TatorElement } from "../components/tator-element.js";

function sanitizeHTML(input) {
// Create a DOM parser
const parser = new DOMParser();
// Parse the input as HTML
const doc = parser.parseFromString(input, "text/html");
// Check if the input was parsed as HTML (not just plain text)
const isHTML = doc.body.children.length > 0;
if (isHTML) {
// Remove all <script> tags
const scripts = doc.querySelectorAll("script");
scripts.forEach((script) => script.remove());
// Return the sanitized HTML
return doc.body.innerHTML;
} else {
// If not HTML, return the input as-is
return input;
}
}

export class ProjectText extends TatorElement {
constructor() {
super();
Expand Down Expand Up @@ -32,7 +51,8 @@ export class ProjectText extends TatorElement {
}

const text1 = lines.slice(0, 2).join("\n");
const summaryText = document.createTextNode(text1);
const summaryText = document.createElement("div");
summaryText.innerHTML = sanitizeHTML(text1);

if (lines.length > 2) {
const details = document.createElement("details");
Expand All @@ -48,7 +68,8 @@ export class ProjectText extends TatorElement {
summary.appendChild(summaryText);

const text2 = lines.slice(2).join("\n");
const detailText = document.createTextNode(text2);
const detailText = document.createElement("div");
detailText.innerHTML = sanitizeHTML(text2);
details.appendChild(detailText);
} else {
const div = document.createElement("div");
Expand Down
Loading