Commit 7285fe209e8a9db38cd2eecac6a709b0e4990cda
1 parent
db940340d9
Exists in
master
add remove menu items function
Showing 10 changed files with 34 additions and 18 deletions Side-by-side Diff
- __pycache__/main.cpython-310.pyc
- __pycache__/routes.cpython-310.pyc
- components/k2test/__pycache__/__init__.cpython-310.pyc
- components/k2test/k2test/__pycache__/__init__.cpython-310.pyc
- components/k2test/k2test/__pycache__/views.cpython-310.pyc
- components/menu.yml
- db/database.db
- k2/__pycache__/k2inst.cpython-310.pyc
- k2/k2inst.py
- main.py
__pycache__/main.cpython-310.pyc
No preview for this file type
__pycache__/routes.cpython-310.pyc
No preview for this file type
components/k2test/__pycache__/__init__.cpython-310.pyc
No preview for this file type
components/k2test/k2test/__pycache__/__init__.cpython-310.pyc
No preview for this file type
components/k2test/k2test/__pycache__/views.cpython-310.pyc
No preview for this file type
components/menu.yml
| 1 | 1 | - category: dashboards |
| 2 | + component_name: main | |
| 2 | 3 | icon: mdi-chart-timeline-variant |
| 3 | 4 | id: 1 |
| 4 | 5 | title: Analytics Dashboard |
| 5 | 6 | url: |
| 6 | - name: dashboards-analytics | |
| 7 | + name: dashboards- | |
| 7 | 8 | - category: dashboards |
| 9 | + component_name: main | |
| 8 | 10 | icon: mdi-cart-outline |
| 9 | 11 | id: 2 |
| 10 | 12 | title: CRM Dashboard |
| 11 | 13 | url: |
| 12 | 14 | name: dashboards-crm |
| 13 | 15 | - category: error |
| 16 | + component_name: k2test | |
| 14 | 17 | icon: error |
| 15 | 18 | id: 3 |
| 16 | 19 | title: k2test--error |
| 17 | 20 | url: |
| 18 | 21 | name: error |
| 19 | -- category: error | |
| 20 | - icon: error | |
| 21 | - id: 4 | |
| 22 | - title: k2test--error | |
| 23 | - url: | |
| 24 | - name: error | |
| 25 | 22 | - category: "\u0422\u0435\u0441\u0442\u043E\u0432\u0430 \u043A\u043E\u043C\u043F\u043E\ |
| 26 | 23 | \u043D\u0435\u043D\u0442\u0430" |
| 24 | + component_name: k2test | |
| 27 | 25 | icon: mdi-chart-timeline-variant |
| 28 | - id: 5 | |
| 26 | + id: 4 | |
| 29 | 27 | title: "\u0422\u0435\u0441\u0442 2" |
| 30 | 28 | url: |
| 31 | 29 | name: new2 |
| 32 | 30 | - category: "\u0422\u0435\u0441\u0442\u043E\u0432\u0430 \u043A\u043E\u043C\u043F\u043E\ |
| 33 | 31 | \u043D\u0435\u043D\u0442\u0430" |
| 32 | + component_name: k2test | |
| 34 | 33 | icon: mdi-chart-timeline-variant |
| 35 | - id: 6 | |
| 34 | + id: 5 | |
| 36 | 35 | title: "\u0422\u0435\u0441\u0442 3" |
| 37 | 36 | url: |
| 38 | 37 | name: new3 |
| 39 | 38 | - category: "\u0422\u0435\u0441\u0442\u043E\u0432\u0430 \u043A\u043E\u043C\u043F\u043E\ |
| 40 | 39 | \u043D\u0435\u043D\u0442\u0430" |
| 40 | + component_name: k2test | |
| 41 | 41 | icon: mdi-chart-timeline-variant |
| 42 | - id: 7 | |
| 42 | + id: 6 | |
| 43 | 43 | title: "\u0422\u0435\u0441\u0442 4" |
| 44 | 44 | url: |
| 45 | 45 | name: new4 |
db/database.db
No preview for this file type
k2/__pycache__/k2inst.cpython-310.pyc
No preview for this file type
k2/k2inst.py
| ... | ... | @@ -49,6 +49,10 @@ |
| 49 | 49 | def get_repository_by_id(self,rep_id): |
| 50 | 50 | component = db.session.query(Component).filter(Component.id == rep_id).first() |
| 51 | 51 | return component |
| 52 | + @classmethod | |
| 53 | + def get_repository_by_id(self,rep_id): | |
| 54 | + component = db.session.query(Component).filter(Component.id == rep_id).first() | |
| 55 | + return component | |
| 52 | 56 | components_bp = Blueprint('components', __name__, template_folder='templates') |
| 53 | 57 | config = yaml.safe_load(open("db/first-login.yml")) |
| 54 | 58 | |
| ... | ... | @@ -76,6 +80,16 @@ |
| 76 | 80 | with open(file_path, 'w') as f: |
| 77 | 81 | yaml.dump(existing_data, f, default_flow_style=False) |
| 78 | 82 | |
| 83 | + | |
| 84 | +def remove_from_yaml_file(file_path, component_name): | |
| 85 | + with open(file_path, 'r') as f: | |
| 86 | + existing_data = yaml.safe_load(f) or [] | |
| 87 | + | |
| 88 | + updated_data = [item for item in existing_data if item.get('component_name') != component_name] | |
| 89 | + | |
| 90 | + with open(file_path, 'w') as f: | |
| 91 | + yaml.dump(updated_data, f, default_flow_style=False) | |
| 92 | + | |
| 79 | 93 | @components_bp.route('/api/languages', methods=['GET']) |
| 80 | 94 | def find_language(): |
| 81 | 95 | components = Component.query.all() |
| ... | ... | @@ -331,7 +345,9 @@ |
| 331 | 345 | 'title': f"{selected_component_name}--error", |
| 332 | 346 | 'category': 'error', |
| 333 | 347 | }] |
| 334 | - | |
| 348 | + # add component_name key for menu items | |
| 349 | + for item in data: | |
| 350 | + item['component_name'] = selected_component_name | |
| 335 | 351 | file_path = 'components/menu.yml' |
| 336 | 352 | append_to_yaml_file(file_path, data) |
| 337 | 353 | k2.get_menu_elenents() |
| 338 | 354 | |
| 339 | 355 | |
| 340 | 356 | |
| 341 | 357 | |
| 342 | 358 | |
| ... | ... | @@ -370,22 +386,20 @@ |
| 370 | 386 | component = Component.query.get(component_id) |
| 371 | 387 | if not component: |
| 372 | 388 | return 'Component not found <meta http-equiv="refresh" content="1;url=/dashboard" />' |
| 389 | + #remove menu items | |
| 390 | + component_name = component.name | |
| 391 | + file_path = "components/menu.yml" | |
| 392 | + remove_from_yaml_file(file_path, component_name) | |
| 373 | 393 | |
| 374 | - # Шлях до файлу, з якого потрібно видалити залежності | |
| 394 | + # remove routes | |
| 375 | 395 | file_path = 'routes.py' |
| 376 | - | |
| 377 | - # Зчитуємо вміст файлу | |
| 378 | 396 | with open(file_path, 'r') as file: |
| 379 | 397 | lines = file.readlines() |
| 380 | 398 | |
| 381 | - # Видаляємо рядки, що містять залежності компоненти | |
| 382 | 399 | updated_lines = [line for line in lines if line.strip() not in component.dependencies] |
| 383 | - | |
| 384 | - # Записуємо оновлений вміст у файл | |
| 385 | 400 | with open(file_path, 'w') as file: |
| 386 | 401 | file.writelines(updated_lines) |
| 387 | 402 | |
| 388 | - # Оновлюємо статус компоненти | |
| 389 | 403 | component.installed = False |
| 390 | 404 | db.session.commit() |
| 391 | 405 |