Merged PR 6: Add mouse suggestion selection functionality

This commit is contained in:
Sebastin Santy 2020-01-13 11:03:21 +00:00
Родитель 2c632efd38
Коммит 3b10ef5499
5 изменённых файлов: 140 добавлений и 5 удалений

Просмотреть файл

@ -151,8 +151,8 @@ if PRODUCTION:
AZURE_CUSTOM_DOMAIN = f'{AZURE_ACCOUNT_NAME}.blob.core.windows.net' AZURE_CUSTOM_DOMAIN = f'{AZURE_ACCOUNT_NAME}.blob.core.windows.net'
STATIC_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{STATIC_LOCATION}/' STATIC_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{STATIC_LOCATION}/'
MEDIA_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{MEDIA_LOCATION}/' MEDIA_URL = f'https://{AZURE_CUSTOM_DOMAIN}/{MEDIA_LOCATION}/'
else:
STATIC_URL = '/static/' STATIC_URL = '/static/'
# LOGGING = { # LOGGING = {
# 'version': 1, # 'version': 1,
@ -180,6 +180,8 @@ STATIC_URL = '/static/'
if SOCKETS: if SOCKETS:
ASGI_APPLICATION = 'InteractiveTranslation.routing.application' ASGI_APPLICATION = 'InteractiveTranslation.routing.application'
DATA_UPLOAD_MAX_NUMBER_FIELDS = 5000
# CHANNEL_LAYERS = { # CHANNEL_LAYERS = {
# "default": { # "default": {
# "BACKEND": "channels_redis.core.RedisChannelLayer", # "BACKEND": "channels_redis.core.RedisChannelLayer",

Просмотреть файл

@ -17,6 +17,7 @@ from django.contrib import admin
from django.urls import include, path from django.urls import include, path
from django.conf import settings from django.conf import settings
from django.conf.urls.static import static from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = [ urlpatterns = [
path('', include('mt.urls')), path('', include('mt.urls')),
@ -25,4 +26,4 @@ urlpatterns = [
# path('gpt/', include('gpt.urls')), # path('gpt/', include('gpt.urls')),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('accounts/', include('django.contrib.auth.urls')), path('accounts/', include('django.contrib.auth.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + staticfiles_urlpatterns()

Просмотреть файл

@ -1,6 +1,34 @@
from django.contrib import admin from django.contrib import admin
from .models import * from .models import *
from django.apps import apps from django.apps import apps
from django.http import HttpResponse
import csv
class ExportCsvMixin:
def export_as_csv(self, request, queryset):
meta = self.model._meta
field_names = [field.name for field in meta.fields]
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename={}.csv'.format(meta)
writer = csv.writer(response)
writer.writerow(field_names)
for obj in queryset:
row = writer.writerow([getattr(obj, field) for field in field_names])
return response
export_as_csv.short_description = "Export Selected"
# @admin.register(dockeystroke)
class CSVAdmin(admin.ModelAdmin, ExportCsvMixin):
list_per_page = 2000
actions = ["export_as_csv"]
# @admin.register(translatedSentence)
# class TranslAdmin(admin.ModelAdmin, ExportCsvMixin):
# actions = ["export_as_csv"]
for model in apps.get_app_config('mt').models.values(): for model in apps.get_app_config('mt').models.values():
admin.site.register(model) admin.site.register(model, CSVAdmin)

Просмотреть файл

@ -755,6 +755,110 @@ $(document).ready(function() {
} }
}); });
document.addEventListener('mouseover', function(e) {
var target = e.target
var partial = $(target).closest('.partial')
// console.log("Hello")
if(target.className.includes("spanres")){
// console.log(parseInt(target.id.substring(3,4)));
selecte = parseInt(target.id.substring(3,4))
resetcolors('.res', $('.spanres').length)
$('.res' + selecte).css({"background-color": "#ddd"})
$(target).closest('.bmo').find('.suggest').text(result[selecte])
$(partial).data("mouseover", parseInt($(this).data("mouseover")) + 1)
// selecte = selecte - 1;
// resetcolors('.res', $('.spanres').length)
// $('.res' + selecte).css({"background-color": "#ddd"})
// $(this).closest('.bmo').find('.suggest').text(result[selecte])
// $(this).data("up", parseInt($(this).data("up")) + 1)
}
}, false);
// document.addEventListener('mouseout', function(e) {
// e.preventDefault();
// var target = e.target
// if(target.className.includes("spanres")){
// selecte = 0
// resetcolors('.res', $('.spanres').length)
// $(target).closest('.bmo').find('.suggest').text(result[selecte])
// }
// }, false);
// document.addEventListener('click', function(e){
// // e.preventDefault();
// var target = e.target;
// console.log(target.className)
// if(target.className.includes("partial transtext")){
// console.log(result[selecte])
// }
// })
// document.addEventListener('mousedown', function(e) {
// console.log("Hellllsajkfhksjaf")
// }, false);
$('.dropdown').on('mousedown', function(e) {
var target = e.target
var sugtext = $(target).closest('.bmo').find('.suggest').text()
var partial = $(target).closest('.bmo').find('.partial')
$(partial).text(sugtext).trigger('click');
placeCaretAtEnd($(partial).get(0))
setTimeout(function() {
$(partial).focus();
}, 0);
// console.log(sugtext)
// var partial = $(this).parent().children().children('.partial');
// // $(this).css('visibility', 'hidden');
// var dropdown = $(this);
// var firsttext = $(partial).text()
// var textlist = firsttext.split(" ")
// var part2text = textlist.pop()
// var part1text = textlist.join(" ")
// $(partial).html(part1text + '<div id="dummy"></div>' + part2text)
// if (firsttext) {
// dropdown.css('left', $('#dummy')[0].offsetLeft + 2).css('top', $('#dummy')[0].offsetTop+7);
// } else {
// dropdown.css('left', $('#dummy')[0].offsetLeft).css('top', $('#dummy')[0].offsetTop+24);
// }
// $(partial).html(firsttext)
// placeCaretAtEnd($(partial).get(0))
// clearTimeout(debounceTimeout);
// debounceTimeout = setTimeout(searchEvents($(this)), 50);
})
// document.addEventListener('click', function(e) {
// var target = e.target
// var partial = $(target).closest('.partial')
// console.log(partial)
// if(target.className.includes("dropcontainer")){
// // console.log(target.className)
// $(partial).html(result[selecte])
// $(partial).closest('.bmo').find('.suggest').text(result[selecte])
// placeCaretAtEnd($(partial).get(0))
// $(partial).closest('.bmo').find('.dropdown').css('visibility', 'hidden')
// $(partial).data("selectsug", parseInt($(partial).data("selectsug")) + 1)
// // var dropdown = $(partial).parent().parent().children('.dropdown');
// // var firsttext = $(partial).text()
// // var textlist = firsttext.split(" ")
// // var part2text = textlist.pop()
// // var part1text = textlist.join(" ")
// // $(partial).html(part1text + '<div id="dummy"></div>' + part2text)
// // if (firsttext) {
// // dropdown.css('left', $('#dummy')[0].offsetLeft + 2).css('top', $('#dummy')[0].offsetTop+7);
// // } else {
// // dropdown.css('left', $('#dummy')[0].offsetLeft).css('top', $('#dummy')[0].offsetTop+24);
// // }
// // $(partial).html(firsttext)
// // placeCaretAtEnd($(partial).get(0))
// // clearTimeout(debounceTimeout);
// // debounceTimeout = setTimeout(searchEvents($(partial)), 50);
// }
// }, false);
$('.partial').one('focus', function() { $('.partial').one('focus', function() {
if (system_type == 'PE') { if (system_type == 'PE') {
searchEvents($(this)); searchEvents($(this));

Просмотреть файл

@ -194,7 +194,7 @@
padding-left: 1px; padding-left: 1px;
border: 1px solid rgba(0, 0, 255, 0.25); border: 1px solid rgba(0, 0, 255, 0.25);
display: block; display: block;
cursor: pointer;
} }
.perinstr { .perinstr {