Skip to content

Commit

Permalink
Fixed #142
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Kraft committed Jan 16, 2024
1 parent 222036c commit 785f560
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
11 changes: 11 additions & 0 deletions odmf/static/templates/download.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ <h5 class="card-title">
</a>
</span>
<span>

<button py:if="f.basename in import_history" class="btn btn-success" aria-expanded="false" aria-controls="import-history-${f.basename}"
data-toggle="popover" title="Already imported" data-content="${markdown(import_history[f.basename])}" data-html="true"
>
<i class="fas fa-check"/>
</button>
<button class="btn btn-secondary copy-button" data-name="${f.basename}" py:if="modes[curdir]>=Mode.write"
title="copy file" data-toggle="tooltip">
<i class="fas fa-copy" />
Expand Down Expand Up @@ -325,6 +331,11 @@ <h5 class="">
<i class="fas fa-${handler[curdir].icon} fa-lg mr-2"/><span py:for="bc in curdir.breadcrumbs()">/<a href="${bc.href}" py:content="bc.basename" /></span>
</h5>
<div class="ml-auto">
<button py:if="curdir.basename in import_history" class="btn btn-success"
data-toggle="popover" title="Already imported" data-content="${markdown(import_history[curdir.basename])}" data-html="true"
>
<i class="fas fa-check"/>
</button>
${literal(handler[curdir].get_action_buttons(curdir))}
<a class="btn btn-primary" href="./?serve=True"><i class="fas fa-file-download mr-4"/>download</a>
<a class="btn btn-outline-primary" href="${curdir.parent().href}"><i class="fas fa-folder-open mr-4"/>..</a>
Expand Down
30 changes: 22 additions & 8 deletions odmf/webpage/filemanager/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,27 @@ def render_file(self, path, error=None):
error += '\n```\n' + traceback() + '\n```\n'
return content, error

def get_import_history(self, path: Path):
"""
Returns a dictionary with the import history for each file in the given path that is mentioned in the
`.import.hist` file
:param path:
"""
if path.isfile():
path = path.parent()

imphist = path / '.import.hist'

if imphist.exists():
with imphist.to_pythonpath().open() as f:
data = [l.split(',', 3) for l in f]
return {
l[0]: f'imported by user:{l[1]} at {l[2]} into {l[3]}'
for l in data
}
else:
return {}


@expose_for(Level.logger)
@web.method.get
Expand Down Expand Up @@ -141,7 +162,7 @@ def index(self, uri='.', error='', msg='', serve=False, _=None):
files=sorted(files),
directories=sorted(directories),
handler=self.filehandler,
curdir=path,
curdir=path, import_history=self.get_import_history(path),
max_size=conf.upload_max_size
).render()

Expand Down Expand Up @@ -206,13 +227,6 @@ def getindex(self, dir):
text = open(index.absolute).read()
io.write(text)

imphist = Path(dir, '.import.hist')

if imphist.exists():
io.write('\n')
for l in open(imphist.absolute):
fn, user, date, ds = l.split(',', 3)
io.write(f' * file:{dir}/{fn} imported by user:{user} at {date} into {ds}\n')
return web.markdown(io.getvalue())

@expose_for(Level.logger)
Expand Down

0 comments on commit 785f560

Please sign in to comment.