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

Added support for pasting images into description and comments fields as base64. #23

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Open
79 changes: 76 additions & 3 deletions trac/ticket/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
to_utimestamp, utc, utcmax)
from trac.util.text import empty, stripws
from trac.util.translation import _, N_, gettext
import time

__all__ = ['Ticket', 'Type', 'Status', 'Resolution', 'Priority', 'Severity',
'Component', 'Milestone', 'Version']
Expand Down Expand Up @@ -226,6 +227,7 @@ def _fetch_ticket(self, tkt_id):
default = self._custom_field_default(field)
if default:
self[name] = default
self.load_revisions()

def __getitem__(self, name):
return self.values.get(name)
Expand Down Expand Up @@ -736,9 +738,80 @@ def _find_change(self, cnum):
""" % db.prefix_match(),
(self.id, ts, db.prefix_match_value('_'))):
break
return ts, author, comment


return ts, author, comments

#--------------------------------------------------
# Personalizzazione omega
# Carico le revisioni legate all' item per poi mostrarle.
std_revisions = []
nonstd_revisions = []

revisions_loaded = False

def load_revisions(self):
if self.revisions_loaded:
return

self.std_revisions.clear()
self.nonstd_revisions.clear()
self.revisions_loaded = True

with self.env.db_query as db:
for row in db("""
SELECT time, author, message, rev, (case (coalesce(repository.value,'')) when '' then 'Xsolving' else repository.value end) as repname FROM revision
INNER JOIN repository on repository.id = revision.repos and repository.name='name'
WHERE itemid = %s
""", (str(self.id),)):
revis = Revision(row[0],row[1],row[2],row[3],row[4])
if revis.get_repname() == 'Xsolving':
self.std_revisions.append(revis)
else:
self.nonstd_revisions.append(revis)


class Revision(object):
def __init__(self, time, author, message, rev, repname):
self._time = from_utimestamp(time).strftime("%d/%m/%Y, %H:%M:%S")
self._author = author
self._message = message
self._repname = repname
self._rev = "r" + str(int(rev))
if repname != 'Xsolving':
self._rev = self._rev + '/' + self._repname


def get_time(self):
return self._time

def set_time(self, value):
self._time= value

def get_author(self):
return self._author

def set_author(self, value):
self._author= value

def get_message(self):
return self._message

def set_message(self, value):
self._message= value

def get_rev(self):
return self._rev

def set_rev(rev, value):
self._rev= value

def get_repname(self):
return self._repname

def set_repname(rev, value):
self._repname= value

#--------------------------------------------------
# Fine personalizzazione omega
class AbstractEnum(object):
type = None
ticket_col = None
Expand Down
123 changes: 110 additions & 13 deletions trac/ticket/templates/ticket.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#}

# extends 'layout.html'
# import 'macros.html' as jmacros with context

<!DOCTYPE html>
<html>
Expand All @@ -34,6 +35,31 @@
# endif
<script>
jQuery(function($) {
function setSmartAttachmentsHandler(elementId) {
$("#"+elementId).bind('paste',function(e){

const dt = e.originalEvent.clipboardData || window.clipboardData;
if(dt.files.length > 0){

var imgFile = dt.files[0];
var extension = imgFile.name.split('.').pop();
if(extension=="png"){
var fileReader = new FileReader();
fileReader.onloadend = function() {
$("#"+elementId).val(function(i,text){ return text + " [[Image('"+fileReader.result+"')]]"});
}
fileReader.readAsDataURL(imgFile);
}else{
console.log("extension '"+extension+"' not supported.");
}
}
});
}

setSmartAttachmentsHandler("field-description");
setSmartAttachmentsHandler("comment");


$("div.description").find("h1,h2,h3,h4,h5,h6")
.addAnchor(_("Link to this section"));
$(".foldable").enableFolding(false, true);
Expand Down Expand Up @@ -241,6 +267,88 @@ <h3 class="foldable">
</div>
# endif
## end of the section we don't show for initial new tickets

## -----------------------------------------------------------------
## Personalizzazione omega per mostrare le revisioni
# if ticket.exists:
<div id="trac-get-revisioni" class="field">
<h3 class="foldable">${_("Revisioni std")}<span class="trac-count">(${len(ticket.std_revisions)})</span></h3>
<div>
#if (not ticket.revisions_loaded):
<p>Revisioni non caricate.</p>
#else:
# if ticket.std_revisions:
<table class="trac-properties" style="border: 1px solid black;">
<tr>
<th span="1" style="width: 10%;border: 1px solid black;">Revisione</th>
<th span="1" style="width: 20%;border: 1px solid black;">Data</th>
<th span="1" style="width: 10%;border: 1px solid black;">Autore</th>
<th span="1" style="width: 10%;border: 1px solid black;">Repository</th>
<th span="1" style="width: 60%;border: 1px solid black;">Messaggio</th>
</tr>
# for revision in ticket.std_revisions:
<tr>
<td class="wikitext" style="border: 1px solid black;">
${wiki_to_html(context, revision.get_rev(), escape_newlines=preserve_newlines)}
</td>
<td style="border: 1px solid black;">${revision.get_time()}</td>
<td style="border: 1px solid black;">${revision.get_author()}</td>
<td style="border: 1px solid black;">${revision.get_repname()}</td>
<td style="border: 1px solid black;">${revision.get_message()}</td>
</tr>
# endfor
</table>
# else:
<p>
${"Nessuna revisione standard trovata per l'item"}
</p>
# endif

#endif
</div>
</div>
#endif

# if ticket.exists:
<div id="trac-get-revisioni" class="field">
<h3 class="foldable">${_("Revisioni non std")}<span class="trac-count">(${len(ticket.nonstd_revisions)})</span></h3>
<div>
#if (not ticket.revisions_loaded):
<p>Revisioni non caricate.</p>
#else:
# if ticket.nonstd_revisions:
<table class="trac-properties" style="border: 1px solid black;">
<tr>
<th span="1" style="width: 10%;border: 1px solid black;">Revisione</th>
<th span="1" style="width: 20%;border: 1px solid black;">Data</th>
<th span="1" style="width: 10%;border: 1px solid black;">Autore</th>
<th span="1" style="width: 10%;border: 1px solid black;">Repository</th>
<th span="1" style="width: 60%;border: 1px solid black;">Messaggio</th>
</tr>
# for revision in ticket.nonstd_revisions:
<tr>
<td class="wikitext" style="border: 1px solid black;">
${wiki_to_html(context, revision.get_rev(), escape_newlines=preserve_newlines)}
</td>
<td style="border: 1px solid black;">${revision.get_time()}</td>
<td style="border: 1px solid black;">${revision.get_author()}</td>
<td style="border: 1px solid black;">${revision.get_repname()}</td>
<td style="border: 1px solid black;">${revision.get_message()}</td>
</tr>
# endfor
</table>
# else:
<p>
${"Nessuna revisione non standard trovata per l'item"}
</p>
# endif

#endif
</div>
</div>
#endif
## Fine personalizzazione omega
## -----------------------------------------------------------------

# if has_property_editor:
<form method="post" id="propertyform"
Expand All @@ -249,6 +357,7 @@ <h3 class="foldable">
${jmacros.form_token_input()}

<div>

# if ticket.exists:
<h3 class="foldable">${_("Modify Ticket")}</h3>
# endif
Expand Down Expand Up @@ -330,7 +439,7 @@ <h3 class="foldable">${_("Modify Ticket")}</h3>
# trans wikiformatting = jmacros.wikiformatting_link()

You may use ${wikiformatting} here.

# endtrans
</label>
</td>
Expand Down Expand Up @@ -564,18 +673,6 @@ <h3 class="foldable" id="edit">${_("Add Comment")}</h3>
</p>
# endif

# if ticket.exists:
<div class="trac-nav">
# if attachments.attachments or attachments.can_create:
<a href="#attachments" id="trac-up-attachments"
title="${_('Go to the list of attachments')}">${
_("Attachments")}</a> &uarr;
# endif
<a href="#content" id="trac-up-view"
title="${_('View the ticket description')}">${
_("Description")}</a> &uarr;
</div>
# endif
<div class="buttons">
# if ticket.exists:
<input type="hidden" name="start_time"
Expand Down