123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- #coding: utf8
- from datetime import datetime
-
- from tracim_backend.models.contents import CONTENT_TYPES
- from tracim_backend.models.data import VirtualEvent
- from tracim_backend.models import data
-
- # FIXME: fix temporaire ...
- style = """
- .title {
- background:#F5F5F5;
- padding-right:15px;
- padding-left:15px;
- padding-top:10px;
- border-bottom:1px solid #CCCCCC;
- overflow:auto;
- } .title h1 { margin-top:0; }
-
- .content {
- padding: 15px;
- }
-
- #left{ padding:0; }
-
- #right {
- background:#F5F5F5;
- border-left:1px solid #CCCCCC;
- border-bottom: 1px solid #CCCCCC;
- padding-top:15px;
- }
- @media (max-width: 1200px) {
- #right {
- border-top:1px solid #CCCCCC;
- border-left: none;
- border-bottom: none;
- }
- }
-
- body { overflow:auto; }
-
- .btn {
- text-align: left;
- }
-
- .table tbody tr .my-align {
- vertical-align:middle;
- }
-
- .title-icon {
- font-size:2.5em;
- float:left;
- margin-right:10px;
- }
- .title.page, .title-icon.page { color:#00CC00; }
- .title.thread, .title-icon.thread { color:#428BCA; }
-
- /* ****************************** */
- .description-icon {
- color:#999;
- font-size:3em;
- }
-
- .description {
- border-left: 5px solid #999;
- padding-left: 10px;
- margin-left: 10px;
- margin-bottom:10px;
- }
-
- .description-text {
- display:block;
- overflow:hidden;
- color:#999;
- }
-
- .comment-row:nth-child(2n) {
- background-color:#F5F5F5;
- }
-
- .comment-row:nth-child(2n+1) {
- background-color:#FFF;
- }
-
- .comment-icon {
- color:#CCC;
- font-size:3em;
- display:inline-block;
- margin-right: 10px;
- float:left;
- }
-
- .comment-content {
- display:block;
- overflow:hidden;
- }
-
- .comment, .comment-revision {
- padding:10px;
- border-top: 1px solid #999;
- }
-
- .comment-revision-icon {
- color:#777;
- margin-right: 10px;
- }
-
- .title-text {
- display: inline-block;
- }
- """
-
- _LABELS = {
- 'archiving': 'Item archived',
- 'content-comment': 'Item commented',
- 'creation': 'Item created',
- 'deletion': 'Item deleted',
- 'edition': 'item modified',
- 'revision': 'New revision',
- 'status-update': 'New status',
- 'unarchiving': 'Item unarchived',
- 'undeletion': 'Item undeleted',
- 'move': 'Item moved',
- 'comment': 'Comment',
- 'copy' : 'Item copied',
- }
-
-
- def create_readable_date(created, delta_from_datetime: datetime = None):
- if not delta_from_datetime:
- delta_from_datetime = datetime.now()
-
- delta = delta_from_datetime - created
-
- if delta.days > 0:
- if delta.days >= 365:
- aff = '%d year%s ago' % (delta.days / 365, 's' if delta.days / 365 >= 2 else '')
- elif delta.days >= 30:
- aff = '%d month%s ago' % (delta.days / 30, 's' if delta.days / 30 >= 2 else '')
- else:
- aff = '%d day%s ago' % (delta.days, 's' if delta.days >= 2 else '')
- else:
- if delta.seconds < 60:
- aff = '%d second%s ago' % (delta.seconds, 's' if delta.seconds > 1 else '')
- elif delta.seconds / 60 < 60:
- aff = '%d minute%s ago' % (delta.seconds / 60, 's' if delta.seconds / 60 >= 2 else '')
- else:
- aff = '%d hour%s ago' % (delta.seconds / 3600, 's' if delta.seconds / 3600 >= 2 else '')
-
- return aff
-
- def designPage(content: data.Content, content_revision: data.ContentRevisionRO) -> str:
- hist = content.get_history(drop_empty_revision=False)
- histHTML = '<table class="table table-striped table-hover">'
- for event in hist:
- if isinstance(event, VirtualEvent):
- date = event.create_readable_date()
- label = _LABELS[event.type.id]
-
- histHTML += '''
- <tr class="%s">
- <td class="my-align"><span class="label label-default"><i class="fa %s"></i> %s</span></td>
- <td>%s</td>
- <td>%s</td>
- <td>%s</td>
- </tr>
- ''' % ('warning' if event.id == content_revision.revision_id else '',
- event.type.fa_icon,
- label,
- date,
- event.owner.display_name,
- # NOTE: (WABDAV_HIST_DEL_DISABLED) Disabled for beta 1.0
- '<i class="fa fa-caret-left"></i> shown' if event.id == content_revision.revision_id else '' # '''<span><a class="revision-link" href="/.history/%s/(%s - %s) %s.html">(View revision)</a></span>''' % (
- # content.label, event.id, event.type.id, event.ref_object.label) if event.type.id in ['revision', 'creation', 'edition'] else '')
- )
- histHTML += '</table>'
-
- page = '''
- <html>
- <head>
- <meta charset="utf-8" />
- <title>%s</title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
- <style>%s</style>
- <script type="text/javascript" src="/home/arnaud/Documents/css/script.js"></script>
- <script
- src="https://code.jquery.com/jquery-3.1.0.min.js"
- integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s="
- crossorigin="anonymous"></script>
- </head>
- <body>
- <div id="left" class="col-lg-8 col-md-12 col-sm-12 col-xs-12">
- <div class="title page">
- <div class="title-text">
- <i class="fa fa-file-text-o title-icon page"></i>
- <h1>%s</h1>
- <h6>page created on <b>%s</b> by <b>%s</b></h6>
- </div>
- <div class="pull-right">
- <div class="btn-group btn-group-vertical">
- <!-- NOTE: Not omplemented yet, don't display not working link
- <a class="btn btn-default">
- <i class="fa fa-external-link"></i> View in tracim</a>
- </a>-->
- </div>
- </div>
- </div>
- <div class="content col-xs-12 col-sm-12 col-md-12 col-lg-12">
- %s
- </div>
- </div>
- <div id="right" class="col-lg-4 col-md-12 col-sm-12 col-xs-12">
- <h4>History</h4>
- %s
- </div>
- <script type="text/javascript">
- window.onload = function() {
- file_location = window.location.href
- file_location = file_location.replace(/\/[^/]*$/, '')
- file_location = file_location.replace(/\/.history\/[^/]*$/, '')
-
- // NOTE: (WABDAV_HIST_DEL_DISABLED) Disabled for beta 1.0
- // $('.revision-link').each(function() {
- // $(this).attr('href', file_location + $(this).attr('href'))
- // });
- }
- </script>
- </body>
- </html>
- ''' % (content_revision.label,
- style,
- content_revision.label,
- content.created.strftime("%B %d, %Y at %H:%m"),
- content.owner.display_name,
- content_revision.description,
- histHTML)
-
- return page
-
-
- def designThread(content: data.Content, content_revision: data.ContentRevisionRO, comments) -> str:
- hist = content.get_history(drop_empty_revision=False)
-
- allT = []
- allT += comments
- allT += hist
- allT.sort(key=lambda x: x.created, reverse=True)
-
- disc = ''
- participants = {}
- for t in allT:
- if t.type == CONTENT_TYPES.Comment.slug:
- disc += '''
- <div class="row comment comment-row">
- <i class="fa fa-comment-o comment-icon"></i>
- <div class="comment-content">
- <h5>
- <span class="comment-author"><b>%s</b> wrote :</span>
- <div class="pull-right text-right">%s</div>
- </h5>
- %s
- </div>
- </div>
- ''' % (t.owner.display_name, create_readable_date(t.created), t.description)
-
- if t.owner.display_name not in participants:
- participants[t.owner.display_name] = [1, t.created]
- else:
- participants[t.owner.display_name][0] += 1
- else:
- if isinstance(t, VirtualEvent) and t.type.id != 'comment':
- label = _LABELS[t.type.id]
-
- disc += '''
- <div class="%s row comment comment-row to-hide">
- <i class="fa %s comment-icon"></i>
- <div class="comment-content">
- <h5>
- <span class="comment-author"><b>%s</b></span>
- <div class="pull-right text-right">%s</div>
- </h5>
- %s %s
- </div>
- </div>
- ''' % ('warning' if t.id == content_revision.revision_id else '',
- t.type.fa_icon,
- t.owner.display_name,
- t.create_readable_date(),
- label,
- # NOTE: (WABDAV_HIST_DEL_DISABLED) Disabled for beta 1.0
- '<i class="fa fa-caret-left"></i> shown' if t.id == content_revision.revision_id else '' # else '''<span><a class="revision-link" href="/.history/%s/%s-%s">(View revision)</a></span>''' % (
- # content.label,
- # t.id,
- # t.ref_object.label) if t.type.id in ['revision', 'creation', 'edition'] else '')
- )
-
- thread = '''
- <html>
- <head>
- <meta charset="utf-8" />
- <title>%s</title>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
- <style>%s</style>
- <script type="text/javascript" src="/home/arnaud/Documents/css/script.js"></script>
- </head>
- <body>
- <div id="left" class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
- <div class="title thread">
- <div class="title-text">
- <i class="fa fa-comments-o title-icon thread"></i>
- <h1>%s</h1>
- <h6>thread created on <b>%s</b> by <b>%s</b></h6>
- </div>
- <div class="pull-right">
- <div class="btn-group btn-group-vertical">
- <!-- NOTE: Not omplemented yet, don't display not working link
- <a class="btn btn-default" onclick="hide_elements()">
- <i id="hideshow" class="fa fa-eye-slash"></i> <span id="hideshowtxt" >Hide history</span></a>
- </a>-->
- <a class="btn btn-default">
- <i class="fa fa-external-link"></i> View in tracim</a>
- </a>
- </div>
- </div>
- </div>
- <div class="content col-xs-12 col-sm-12 col-md-12 col-lg-12">
- <div class="description">
- <span class="description-text">%s</span>
- </div>
- %s
- </div>
- </div>
- <script type="text/javascript">
- window.onload = function() {
- file_location = window.location.href
- file_location = file_location.replace(/\/[^/]*$/, '')
- file_location = file_location.replace(/\/.history\/[^/]*$/, '')
-
- // NOTE: (WABDAV_HIST_DEL_DISABLED) Disabled for beta 1.0
- // $('.revision-link').each(function() {
- // $(this).attr('href', file_location + $(this).attr('href'))
- // });
- }
-
- function hide_elements() {
- elems = document.getElementsByClassName('to-hide');
- if (elems.length > 0) {
- for(var i = 0; i < elems.length; i++) {
- $(elems[i]).addClass('to-show')
- $(elems[i]).hide();
- }
- while (elems.length>0) {
- $(elems[0]).removeClass('comment-row');
- $(elems[0]).removeClass('to-hide');
- }
- $('#hideshow').addClass('fa-eye').removeClass('fa-eye-slash');
- $('#hideshowtxt').html('Show history');
- }
- else {
- elems = document.getElementsByClassName('to-show');
- for(var i = 0; i<elems.length; i++) {
- $(elems[0]).addClass('comment-row');
- $(elems[i]).addClass('to-hide');
- $(elems[i]).show();
- }
- while (elems.length>0) {
- $(elems[0]).removeClass('to-show');
- }
- $('#hideshow').removeClass('fa-eye').addClass('fa-eye-slash');
- $('#hideshowtxt').html('Hide history');
- }
- }
- </script>
- </body>
- </html>
- ''' % (content_revision.label,
- style,
- content_revision.label,
- content.created.strftime("%B %d, %Y at %H:%m"),
- content.owner.display_name,
- content_revision.description,
- disc)
-
- return thread
|