feature(python): forgotten files page

This commit is contained in:
Serik Ibragimov
2024-04-16 13:02:55 +05:00
parent 4263175871
commit d1a1127b63
5 changed files with 323 additions and 1 deletions

View File

@ -9,7 +9,7 @@ from django.core.management.commands.runserver import Command as RunServer
from django.conf.urls.static import static
from django.urls import path
from src.common import string
from src.views import actions, index
from src.views import actions, index, forgotten
def debug():
@ -65,6 +65,8 @@ def configuration():
def routers():
main = [
path('', index.default),
path('forgotten', forgotten.default),
path('deleteforgotten', forgotten.delete),
path('convert', actions.convert),
path('create', actions.createNew),
path('csv', actions.csv),

View File

@ -0,0 +1,70 @@
"""
(c) Copyright Ascensio System SIA 2024
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from django.shortcuts import render
from src.configuration import ConfigurationManager
from src.utils import trackManager, fileUtils
from django.http import HttpResponse
import json
config_manager = ConfigurationManager()
def default(request): # default parameters that will be passed to the template
context = {
'files': getForgottenFiles(), # information about stored files
'serverVersion': config_manager.getVersion()
}
# execute the "index.html" template with context data and return http response in json format
return render(request, 'forgotten.html', context)
def getForgottenFiles():
files = []
try:
forgottenList = trackManager.commandRequest('getForgottenList', '').json()
for key in forgottenList["keys"]:
file = trackManager.commandRequest('getForgotten', key).json()
file["type"] = fileUtils.getFileType(file["url"])
files.append(file)
except (Exception, ValueError):
pass # TODO: write to logger
return files
# delete a forgotten file from the document server
def delete(request):
response = {}
status = 204
try:
filename = request.GET.get('filename', '')
if filename:
trackManager.commandRequest('deleteForgotten', filename)
except Exception as e:
response.setdefault('error', str(e.args[0]))
status = 500
return HttpResponse(
json.dumps(response),
content_type='application/json',
status=status)

View File

@ -0,0 +1,114 @@
.center {
width: auto;
}
.left-panel {
width: 256px;
}
.main-panel {
width: 832px;
padding: 0;
margin: 48px 0 48px 32px;
left: 0;
}
.tableRow {
display: flex;
width: 100%;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid #E2E2E2;
}
.tableRow td:first-child {
width: 70%;
flex-grow: 0;
max-width: none;
}
.tableHeader td:first-child {
text-align: left;
}
.tableHeader td:last-child, .tableRow td:last-child {
width: 10%;
text-align: center;
padding: 0 !important;
}
.tableHeader {
width: 100%;
}
.stored-edit {
display: block;
padding-top: 0;
max-width: none;
}
menu.links {
width: 100%;
}
.scroll-table-body table {
table-layout: fixed;
}
.stored-edit span {
font-size: 12px;
line-height: normal;
position: static;
}
@media (max-width: 1279px) and (min-width: 1024px) {
.left-panel {
width: 208px;
}
.main-panel {
width: 688px;
}
}
@media (max-width: 1023px) and (min-width: 593px) {
.center {
max-width: 768px;
width: calc(100% - 80px);
}
.table-main {
width: 100%;
}
.left-panel {
width: 208px;
}
.main-panel {
width: calc(100% - 32px);
}
.tableHeader td:last-child, .tableRow td:last-child {
width: 20%;
}
}
@media (max-width: 592px) and (min-width: 320px) {
.center, .table-main {
width: 100%;
}
.left-panel {
display: none;
}
.main-panel {
width: calc(100% - 32px);
margin: 16px;
}
.tableHeader td:last-child, .tableRow td:last-child {
width: 25%;
}
}

View File

@ -0,0 +1,19 @@
function deleteFile(event) {
let filename = event.currentTarget.getAttribute("data");
filename = encodeURIComponent(filename);
let url = `deleteforgotten?filename=${filename}`;
fetch(url, {
headers: {
"Content-Type": "application/json",
}
}).then(result => {
if(result.status == 204) {
document.location.reload(true);
}
});
}
document.querySelectorAll('.delete-file').forEach(el => {
el.addEventListener('click', deleteFile);
});

View File

@ -0,0 +1,117 @@
<!--*
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*-->
{% load static %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width" />
<meta name="server-version" content="{{serverVersion}}">
<title>ONLYOFFICE Document Editors</title>
<link href="{% static "images/favicon.ico" %}" rel="shortcut icon" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Open+Sans:900,800,700,600,500,400,300&subset=latin,cyrillic-ext,cyrillic,latin-ext" />
<link rel="stylesheet" type="text/css" href="{% static "css/stylesheet.css" %}" />
<link rel="stylesheet" type="text/css" href="{% static "css/jquery-ui.css" %}" />
<link rel="stylesheet" type="text/css" href="{% static "css/media.css" %}" />
<link rel="stylesheet" type="text/css" href="{% static "css/forgotten.css" %}" />
</head>
<body>
<header>
<div class="center">
<a href="">
<img src="{% static "images/logo.svg" %}" alt="ONLYOFFICE" />
</a>
</div>
</header>
<div class="center main">
<table class="table-main">
<tbody>
<tr>
<td class="left-panel section"></td>
<td class="section">
<div class="main-panel">
<div class="stored-list">
<div class="storedHeader">
<div class="storedHeaderText">
<span class="header-list">Forgotten files</span>
</div>
</div>
<table class="tableHeader" cellspacing="0" cellpadding="0" width="100%">
<thead>
<tr>
<td class="tableHeaderCell">Filename</td>
<td class="tableHeaderCell">Action</td>
</tr>
</thead>
</table>
<div class="scroll-table-body">
<table cellspacing="0" cellpadding="0" width="100%">
<tbody>
{% for file in files %}
<tr class="tableRow" title="{{ file.key }}">
<td>
<a class="stored-edit {{ file.type }} action-link" href="{{ file.url }}" target="_blank">
<span>{{ file.key }}</span>
</a>
</td>
<td>
<a href="{{ file.url }}">
<img class="icon-download" src="{% static "images/download.svg" %}" alt="Download" title="Download" /></a>
<a class="delete-file" data="{{ file.key }}">
<img class="icon-action" src="{% static "images/delete.svg" %}" alt="Delete" title="Delete" /></a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<footer>
<div class="center">
<table>
<tbody>
<tr>
<td>
<a href="http://api.onlyoffice.com/editors/howitworks" target="_blank">API Documentation</a>
</td>
<td>
<a href="mailto:sales@onlyoffice.com">Submit your request</a>
</td>
<td class="copy">
&copy; Ascensio Systems SIA 2024. All rights reserved.
</td>
</tr>
</tbody>
</table>
</div>
</footer>
<script type="text/javascript" src="{% static "js/forgotten.js" %}"></script>
</body>
</html>