Skip to content

Commit

Permalink
Working on app
Browse files Browse the repository at this point in the history
  • Loading branch information
BaseMax committed Nov 30, 2024
1 parent 5cbf0a8 commit 0349bfc
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 407 deletions.
34 changes: 24 additions & 10 deletions config/admin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,37 @@ def write_yaml(file_path, data):

@app.route('/')
def index():
return render_template('index.html', files=YAML_FILES)
error = session.pop('error', None)

return render_template('index.html', error=error, files=YAML_FILES)


@app.route('/edit/<path:filepath>', methods=['GET', 'POST'])
@app.route('/edit/<path:filepath>', methods=['POST'])
def edit_file(filepath):
file_path = os.path.join(YAML_DIR, filepath)

if not os.path.exists(file_path):
return f"File {filepath} not found.", 404
return jsonify({'success': False})

if request.method == 'POST':
items = request.json.get('items', [])
data = {'items': items}
write_yaml(file_path, data)

return jsonify({'success': True})
items = request.json.get('items', [])
data = {'items': items}
write_yaml(file_path, data)

return jsonify({'success': True})


@app.route('/edit/<path:filepath>', methods=['GET'])
def edit_file(filepath):
file_path = os.path.join(YAML_DIR, filepath)

if not os.path.exists(file_path):
return f"File {filepath} not found.", 404

data = read_yaml(file_path)
return render_template('edit.html', filename=filepath, items=data['items'])

error = session.pop('error', None)

return render_template('edit.html', error=error, filename=filepath, items=data['items'])


@app.route('/add-file', methods=['POST'])
Expand Down Expand Up @@ -88,6 +100,8 @@ def add_file():
@app.route('/delete-file/<path:filepath>', methods=['POST'])
def delete_file(filepath):
full_path = os.path.join(YAML_DIR, filepath)

print(full_path)

if os.path.exists(full_path) and os.path.abspath(full_path).startswith(os.path.abspath(YAML_DIR)):
try:
Expand Down
2 changes: 1 addition & 1 deletion config/admin/templates/edit.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en-US" dir="ltr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand Down
19 changes: 14 additions & 5 deletions config/admin/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en-US" dir="ltr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Salam Admin Panel</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
<script>
function confirmDelete(event, fileName) {
if (!confirm(`Are you sure you want to delete the file "${fileName}"?`)) {
event.preventDefault();
}
}
</script>
</head>
<body class="container mt-5">
<h1>Salam Admin Panel</h1>

<!-- Display Error Message -->
{% if error %}
<div class="alert alert-danger" role="alert">
{{ error }}
</div>
{% endif %}

<!-- Form to Add New YAML File -->
<form action="{{ url_for('add_file') }}" method="post" class="mb-4">
<div class="input-group">
<input type="text" name="filename" class="form-control" placeholder="Enter new filename (e.g., myfile.yaml)">
<button type="submit" class="btn btn-primary">Add File</button>
</div>
</form>

<!-- List of YAML Files -->
<ul class="list-group">
{% for file in files %}
<li class="list-group-item d-flex justify-content-between align-items-center">
<a href="{{ url_for('edit_file', filepath=file) }}" class="text-decoration-none">{{ file }}</a>
<form action="{{ url_for('delete_file', filepath=file) }}" method="post" class="m-0">
<button type="submit" class="btn btn-danger btn-sm">Delete</button>
<button
type="submit"
class="btn btn-danger btn-sm"
onclick="confirmDelete(event, '{{ file }}')">
Delete
</button>
</form>
</li>
{% endfor %}
Expand Down
10 changes: 0 additions & 10 deletions config/language.yaml

This file was deleted.

Loading

0 comments on commit 0349bfc

Please sign in to comment.