Skip to content

Commit

Permalink
[AJP-2]
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna Grund authored and Anna Grund committed Jul 4, 2023
1 parent 80066fb commit 0134aae
Show file tree
Hide file tree
Showing 10 changed files with 356 additions and 56 deletions.
28 changes: 28 additions & 0 deletions ajapaik/ajapaik/migrations/0026_photomodelsuggestionresult.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.7 on 2023-04-29 15:38

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('ajapaik', '0025_photomodelsuggestionconfirmreject'),
]

operations = [
migrations.CreateModel(
name='PhotoModelSuggestionResult',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateTimeField(auto_now_add=True, db_index=True)),
('viewpoint_elevation', models.PositiveSmallIntegerField(blank=True, choices=[(0, 'Ground'), (1, 'Raised'), (2, 'Aerial')], null=True, verbose_name='Viewpoint elevation')),
('scene', models.PositiveSmallIntegerField(blank=True, choices=[(0, 'Interior'), (1, 'Exterior')], null=True, verbose_name='Scene')),
('photo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ajapaik.photo')),
('proposer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='photo_scene_suggestions_result', to='ajapaik.profile')),
],
options={
'abstract': False,
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.7 on 2023-04-29 16:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('ajapaik', '0026_photomodelsuggestionresult'),
]

operations = [
migrations.RemoveField(
model_name='photomodelsuggestionresult',
name='proposer',
),
]
31 changes: 31 additions & 0 deletions ajapaik/ajapaik/migrations/0028_auto_20230525_1916.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 3.2.7 on 2023-05-25 16:16

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('ajapaik', '0027_remove_photomodelsuggestionresult_proposer'),
]

operations = [
migrations.CreateModel(
name='PhotoModelSuggestionAlternativeCategory',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateTimeField(auto_now_add=True, db_index=True)),
('viewpoint_elevation_alternation', models.PositiveSmallIntegerField(blank=True, choices=[(0, 'Ground'), (1, 'Raised'), (2, 'Aerial')], null=True, verbose_name='Viewpoint elevation')),
('scene_alternation', models.PositiveSmallIntegerField(blank=True, choices=[(0, 'Interior'), (1, 'Exterior')], null=True, verbose_name='Scene')),
('photo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ajapaik.photo')),
('proposer', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='photo_scene_suggestions_alternation', to='ajapaik.profile')),
],
options={
'abstract': False,
},
),
migrations.DeleteModel(
name='PhotoModelSuggestionResult',
),
]
27 changes: 27 additions & 0 deletions ajapaik/ajapaik/migrations/0029_photomodelsuggestionresult.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.2.7 on 2023-05-25 16:21

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('ajapaik', '0028_auto_20230525_1916'),
]

operations = [
migrations.CreateModel(
name='PhotoModelSuggestionResult',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateTimeField(auto_now_add=True, db_index=True)),
('viewpoint_elevation', models.PositiveSmallIntegerField(blank=True, choices=[(0, 'Ground'), (1, 'Raised'), (2, 'Aerial')], null=True, verbose_name='Viewpoint elevation')),
('scene', models.PositiveSmallIntegerField(blank=True, choices=[(0, 'Interior'), (1, 'Exterior')], null=True, verbose_name='Scene')),
('photo', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ajapaik.photo')),
],
options={
'abstract': False,
},
),
]
33 changes: 33 additions & 0 deletions ajapaik/ajapaik/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,7 @@ class PhotoViewpointElevationSuggestion(Suggestion):
on_delete=CASCADE)


# TODO: to be deleted
class PhotoModelSuggestionConfirmReject(Suggestion):
INTERIOR, EXTERIOR = range(2)
GROUND_LEVEL, RAISED, AERIAL = range(3)
Expand All @@ -2095,6 +2096,38 @@ class PhotoModelSuggestionConfirmReject(Suggestion):

proposer = ForeignKey('Profile', blank=True, null=True, related_name='photo_scene_suggestions_confirmation', on_delete=CASCADE)

class PhotoModelSuggestionResult(Suggestion):
INTERIOR, EXTERIOR = range(2)
GROUND_LEVEL, RAISED, AERIAL = range(3)
SCENE_CHOICES = (
(INTERIOR, _('Interior')),
(EXTERIOR, _('Exterior'))
)
VIEWPOINT_ELEVATION_CHOICES = (
(GROUND_LEVEL, _('Ground')),
(RAISED, _('Raised')),
(AERIAL, _('Aerial'))
)
viewpoint_elevation = PositiveSmallIntegerField(_('Viewpoint elevation'), choices=VIEWPOINT_ELEVATION_CHOICES, blank=True, null=True)
scene = PositiveSmallIntegerField(_('Scene'), choices=SCENE_CHOICES, blank=True, null=True)

class PhotoModelSuggestionAlternativeCategory(Suggestion):
INTERIOR, EXTERIOR = range(2)
GROUND_LEVEL, RAISED, AERIAL = range(3)
SCENE_CHOICES = (
(INTERIOR, _('Interior')),
(EXTERIOR, _('Exterior'))
)
VIEWPOINT_ELEVATION_CHOICES = (
(GROUND_LEVEL, _('Ground')),
(RAISED, _('Raised')),
(AERIAL, _('Aerial'))
)
viewpoint_elevation_alternation = PositiveSmallIntegerField(_('Viewpoint elevation'), choices=VIEWPOINT_ELEVATION_CHOICES, blank=True, null=True)
scene_alternation = PositiveSmallIntegerField(_('Scene'), choices=SCENE_CHOICES, blank=True, null=True)

proposer = ForeignKey('Profile', blank=True, null=True, related_name='photo_scene_suggestions_alternation', on_delete=CASCADE)


class PhotoFlipSuggestion(Suggestion):
proposer = ForeignKey('Profile', blank=True, null=True, related_name='photo_flip_suggestions', on_delete=CASCADE)
Expand Down
38 changes: 37 additions & 1 deletion ajapaik/ajapaik/static/js/ajp-picture-category-retrival.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,42 @@ function getPictureCategoryCategories(photoId, callback) {
);
}

function sendCategoryFeedback(photoId, category, categoryValue) {
console.log("Persisting category alternation to db")
let payload = {
"photo_id": photoId
};

if (category === "scene") {
if (categoryValue === "interior") {
payload["scene_to_alternate"] = 0
} else if (categoryValue === "exterior") {
payload["scene_to_alternate"] = 1
}
} else if (category === "view-point") {
if (categoryValue === "ground") {
payload["viewpoint_elevation_to_alternate"] = 0
} else if (categoryValue === "raised") {
payload["viewpoint_elevation_to_alternate"] = 1
} else {
payload["viewpoint_elevation_to_alternate"] = 2
}
}

var onSuccess = function () {
console.log("It was a success!")
};

postRequest(
'/object-categorization/confirm-latest-category',
payload,
constants.translations.queries.POST_CATEGORY_CONFIRMATION_SUCCESS,
constants.translations.queries.POST_CATEGORY_CONFIRMATION_FAILED,
onSuccess
);
}

//TODO: to remove
function sendCategoryConfirmation(photoId, category, categoryValue, confirm) {


Expand Down Expand Up @@ -67,7 +103,7 @@ function determinePictureCategory(responseData) {
for (let i = 0; i < responseData.length; i++) {
var data = responseData[i]
var model = data["model"];
if (model === "ajapaik.photoscenesuggestion") {
if (model === "ajapaik.photomodelsuggestionresult") {
category = data["fields"]["scene"]
if (category === 0) {
responseDict["scene"] = "interior";
Expand Down
66 changes: 63 additions & 3 deletions ajapaik/ajapaik/templates/photo/_photo_comments_and_labels.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
<span>Scene category:</span>
<span id="ajp-latest-category-scene"></span>
<div class='btn-group w-10' role='group'>
<button type='submit' id='ajp-confirm-scene-category' class='btn btn-success w-5' onclick="sendCategoryConfirmation('{{ photo.id }}', 'scene', $('#ajp-latest-category-scene').text(), 1)"><span class='material-icons notranslate'>check</span></button>
<button type='button' id='ajp-reject-scene-category' class='btn btn-danger w-5' onclick="sendCategoryConfirmation('{{ photo.id }}', 'scene', $('#ajp-latest-category-scene').text(), 0)"><span class='material-icons notranslate'>close</span></button>
<button type='submit' id='ajp-confirm-scene-category' class='btn btn-success w-5' onclick="sendCategoryFeedback('{{ photo.id }}', 'scene', $('#ajp-latest-category-scene').text())"><span class='material-icons notranslate'>check</span></button>
<!-- <button type='button' id='ajp-reject-scene-category' class='btn btn-danger w-5' onclick="sendCategoryConfirmation('{{ photo.id }}', 'scene', $('#ajp-latest-category-scene').text(), 0)"><span class='material-icons notranslate'>close</span></button>-->
<button type="button" id="ajp-reject-scene-category" class="btn btn-danger w-5">
<span class="material-icons notranslate">close</span>
</button>

</div>
</div>
</div>
Expand Down Expand Up @@ -85,11 +89,47 @@
</div>

<script src="{% static "js/ajp-picture-category-retrival.js" %}"></script>

{% block specific_js %}
<script>
$(document).ready(function () {

let feedbackView = `
<div style='width: 150px'>
<button type='button' class='btn btn-light btn-sm c mr-2' id='interior-alternative' onclick="enableInterior()">
<span class='material-icons notranslate ajp-icon-36'>hotel</span><br>Interior
</button>
<button type='button' class='btn btn-light btn-sm' id='exterior-alternative' onclick="enableExterior()">
<span class='material-icons notranslate ajp-icon-36'>home</span><br>Exterior
</button>
<button id='send-suggestion-button' class='btn btn-success mt-3 w-100' disabled onclick="sendAlternativeCategoryConfirmation({{ photo.id }})">Confirm</button>
</div>`;

$('#ajp-reject-scene-category').popover({
html: true,
sanitize: false,
trigger: 'manual',
content: feedbackView,
title: 'Suggest different',
});

$('#ajp-reject-scene-category').on('click', function() {
$(this).popover('toggle');
});

$('#send-suggestion-button').on('click', function() {
$('#ajp-reject-scene-category').popover('hide');
});

$(document).on('click', function (event) {
const target = $(event.target);
if (!target.is('#ajp-reject-scene-category') && !target.closest('.popover').length) {
$('#ajp-reject-scene-category').popover('hide');
}
});

getPictureCategoryCategories('{{ photo.id }}', function(categoryMap) {
console.log("===")
console.log(categoryMap)
if (categoryMap.hasOwnProperty('scene')) {
$("#ajp-latest-category-scene").html(categoryMap["scene"]);
$("#ajp-latest-category-scene-div").show();
Expand Down Expand Up @@ -150,5 +190,25 @@
});
});
})
function enableInterior() {
$('#interior-alternative').addClass('active');
$('#exterior-alternative').removeClass('active');
$('#send-suggestion-button').prop('disabled', false);
}

function enableExterior() {
$('#exterior-alternative').addClass('active');
$('#interior-alternative').removeClass('active');
$('#send-suggestion-button').prop('disabled', false);
}

function sendAlternativeCategoryConfirmation(photoId) {
if ($('#interior-alternative').hasClass('active')) {
sendCategoryFeedback(photoId, "scene", "interior")
} else if ($('#exterior-alternative').hasClass('active')) {
sendCategoryFeedback(photoId, "scene", "exterior")
}
$('#ajp-reject-scene-category').popover('hide');
}
</script>
{% endblock %}
Loading

0 comments on commit 0134aae

Please sign in to comment.