Commit ae2387fb061d7b34c3cf96e158793d4e88bc1e5b
1 parent
96b1e3e06f
Exists in
master
del sqlite, add yml
Showing 17 changed files with 233 additions and 140 deletions Side-by-side Diff
- __pycache__/app.cpython-310.pyc
- __pycache__/routes.cpython-310.pyc
- app.py
- components/__pycache__/__init__.cpython-310.pyc
- components/components.yml
- db/database.db
- k2/__pycache__/__init__.cpython-310.pyc
- k2/__pycache__/k2admmenu.cpython-310.pyc
- k2/__pycache__/k2cfg.cpython-310.pyc
- k2/__pycache__/k2comp.cpython-310.pyc
- k2/__pycache__/k2obj.cpython-310.pyc
- k2/__pycache__/k2rout.cpython-310.pyc
- k2/k2rout.py
- languages/babel_translation_directories.yml
- languages/en/LC_MESSAGES/messages.mo
- languages/pl/LC_MESSAGES/messages.mo
- languages/uk/LC_MESSAGES/messages.mo
__pycache__/app.cpython-310.pyc
No preview for this file type
__pycache__/routes.cpython-310.pyc
No preview for this file type
app.py
components/__pycache__/__init__.cpython-310.pyc
No preview for this file type
components/components.yml
| 1 | +components: [] |
db/database.db
No preview for this file type
k2/__pycache__/__init__.cpython-310.pyc
No preview for this file type
k2/__pycache__/k2admmenu.cpython-310.pyc
No preview for this file type
k2/__pycache__/k2cfg.cpython-310.pyc
No preview for this file type
k2/__pycache__/k2comp.cpython-310.pyc
No preview for this file type
k2/__pycache__/k2obj.cpython-310.pyc
No preview for this file type
k2/__pycache__/k2rout.cpython-310.pyc
No preview for this file type
k2/k2rout.py
| ... | ... | @@ -18,8 +18,10 @@ |
| 18 | 18 | from flask_jwt_extended import get_jwt_identity, jwt_required |
| 19 | 19 | from flask_login import login_user, current_user, logout_user, login_required |
| 20 | 20 | import platform |
| 21 | +import uuid | |
| 21 | 22 | |
| 22 | 23 | |
| 24 | + | |
| 23 | 25 | # initialize db |
| 24 | 26 | # migrate = Migrate(app, db) |
| 25 | 27 | |
| ... | ... | @@ -28,6 +30,9 @@ |
| 28 | 30 | |
| 29 | 31 | db = k2.db |
| 30 | 32 | |
| 33 | +def generate_id(): | |
| 34 | + generated_id = uuid.uuid4().hex[:32] | |
| 35 | + return ''.join([generated_id[i:i + 4] for i in range(0, len(generated_id), 4)]) | |
| 31 | 36 | |
| 32 | 37 | def first_login_required(view_func): |
| 33 | 38 | @wraps(view_func) |
| ... | ... | @@ -81,10 +86,20 @@ |
| 81 | 86 | |
| 82 | 87 | @components_bp.route('/', methods=['GET', 'POST']) |
| 83 | 88 | def home(): |
| 84 | - components = Component.query.all() | |
| 85 | - components_names = [component.name for component in components] | |
| 86 | - if 'k2site' in components_names: | |
| 87 | - return redirect(url_for('k2site.main_page')) #змінити на ендпоінт головної k2site | |
| 89 | + | |
| 90 | + components_folder = 'components' | |
| 91 | + | |
| 92 | + with open(f"{components_folder}/components.yml", 'r') as file: | |
| 93 | + components_data = yaml.safe_load(file) | |
| 94 | + | |
| 95 | + if components_data is None: | |
| 96 | + return redirect('/dashboard') | |
| 97 | + | |
| 98 | + k2site_component = next( | |
| 99 | + (comp for comp in components_data['components'] if comp['name'] == 'k2site' and comp.get('installed', False)), | |
| 100 | + None) | |
| 101 | + if k2site_component: | |
| 102 | + return redirect(url_for('k2site.main_page')) # | |
| 88 | 103 | else: |
| 89 | 104 | return redirect('/dashboard') |
| 90 | 105 | |
| 91 | 106 | |
| ... | ... | @@ -112,11 +127,20 @@ |
| 112 | 127 | |
| 113 | 128 | @components_bp.route('/dashboard') |
| 114 | 129 | def dashboard(): |
| 115 | - components = Component.query.all() | |
| 130 | + #components = Component.query.all() | |
| 131 | + with open(f"components/components.yml", 'r') as file: | |
| 132 | + components_data = yaml.safe_load(file) | |
| 133 | + if components_data is None or 'components' not in components_data: | |
| 134 | + components = [] | |
| 135 | + else: | |
| 136 | + components = components_data['components'] | |
| 116 | 137 | components_names = [] |
| 117 | - components_names = [component.name for component in components] | |
| 118 | - if 'k2site' in components_names: | |
| 119 | - return redirect(url_for('components.home')) | |
| 138 | + components_names = [component['name'] for component in components] | |
| 139 | + k2site_component = next( | |
| 140 | + (comp for comp in components_data['components'] if comp['name'] == 'k2site' and comp.get('installed', False)), | |
| 141 | + None) | |
| 142 | + if k2site_component: | |
| 143 | + return redirect(url_for('components.component_list_dasb')) | |
| 120 | 144 | else: |
| 121 | 145 | # Компоненти доступні для встановлення |
| 122 | 146 | # GET-запит до API |
| ... | ... | @@ -129,8 +153,8 @@ |
| 129 | 153 | component_server = None |
| 130 | 154 | |
| 131 | 155 | # Встановлені компоненти |
| 132 | - components = Component.query.all() | |
| 133 | - components_names = [component.name for component in components] | |
| 156 | + #components = Component.query.all() | |
| 157 | + #components_names = [component.name for component in components] | |
| 134 | 158 | # Отримання значення пошукового запиту з параметрів URL |
| 135 | 159 | search_query = request.args.get('search_query') |
| 136 | 160 | # print(search_query) |
| 137 | 161 | |
| 138 | 162 | |
| 139 | 163 | |
| ... | ... | @@ -291,26 +315,60 @@ |
| 291 | 315 | file.write(code) |
| 292 | 316 | file.write('\n') |
| 293 | 317 | |
| 294 | - # Update database with the installed component | |
| 295 | - component = Component.query.filter_by(name=selected_component['name']).first() | |
| 296 | - if not component: | |
| 297 | - component = Component( | |
| 298 | - name=selected_component['name'], | |
| 299 | - description=selected_component['description'], | |
| 300 | - version=version, | |
| 301 | - git_link=selected_component['git_link'], | |
| 302 | - dependencies=code, | |
| 303 | - installed=True | |
| 304 | - ) | |
| 305 | - db.session.add(component) | |
| 318 | + # Зчитати вміст файлу YAML | |
| 319 | + with open(f"{project_folder}/components.yml", 'r') as file: | |
| 320 | + components_data = yaml.safe_load(file) | |
| 321 | + if components_data == None: | |
| 322 | + components_data = {'components': []} | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + # Перевірити унікальність імен компонентів | |
| 327 | + existing_component = next((c for c in components_data['components'] if c['name'] == selected_component['name']), | |
| 328 | + None) | |
| 329 | + if existing_component: | |
| 330 | + # Оновити існуючий компонент | |
| 331 | + existing_component['id'] = generate_id() | |
| 332 | + existing_component['version'] = version | |
| 333 | + existing_component['git_link'] = selected_component['git_link'] | |
| 334 | + existing_component['dependencies'] = code | |
| 335 | + existing_component['installed'] = True | |
| 306 | 336 | else: |
| 307 | - component.version = version | |
| 308 | - component.git_link = selected_component['git_link'] | |
| 309 | - component.dependencies = code | |
| 310 | - component.installed = True | |
| 337 | + # Додати новий компонент до списку | |
| 338 | + components_data['components'].append({ | |
| 339 | + 'id': generate_id(), | |
| 340 | + 'name': selected_component['name'], | |
| 341 | + 'description': selected_component['description'], | |
| 342 | + 'version': version, | |
| 343 | + 'git_link': selected_component['git_link'], | |
| 344 | + 'dependencies': code, | |
| 345 | + 'installed': True | |
| 346 | + }) | |
| 311 | 347 | |
| 312 | - db.session.commit() | |
| 348 | + # Записати оновлений вміст у файл YAML | |
| 349 | + with open(f"{project_folder}/components.yml", 'a') as file: | |
| 350 | + yaml.dump(components_data, file) | |
| 313 | 351 | |
| 352 | + # Update database with the installed component | |
| 353 | + # component = Component.query.filter_by(name=selected_component['name']).first() | |
| 354 | + # if not component: | |
| 355 | + # component = Component( | |
| 356 | + # name=selected_component['name'], | |
| 357 | + # description=selected_component['description'], | |
| 358 | + # version=version, | |
| 359 | + # git_link=selected_component['git_link'], | |
| 360 | + # dependencies=code, | |
| 361 | + # installed=True | |
| 362 | + # ) | |
| 363 | + # db.session.add(component) | |
| 364 | + # else: | |
| 365 | + # component.version = version | |
| 366 | + # component.git_link = selected_component['git_link'] | |
| 367 | + # component.dependencies = code | |
| 368 | + # component.installed = True | |
| 369 | + # | |
| 370 | + # db.session.commit() | |
| 371 | + | |
| 314 | 372 | # add language folders |
| 315 | 373 | k2.search_babel_translation_directories() |
| 316 | 374 | return f'''Component installed successfully: {selected_component["name"]} v{version} {k2.babel_translation_directories}, |
| 317 | 375 | |
| 318 | 376 | |
| 319 | 377 | |
| 320 | 378 | |
| 321 | 379 | |
| 322 | 380 | |
| 323 | 381 | |
| 324 | 382 | |
| 325 | 383 | |
| 326 | 384 | |
| 327 | 385 | |
| 328 | 386 | |
| 329 | 387 | |
| 330 | 388 | |
| 331 | 389 | |
| 332 | 390 | |
| 333 | 391 | |
| 334 | 392 | |
| 335 | 393 | |
| 336 | 394 | |
| 337 | 395 | |
| 338 | 396 | |
| 339 | 397 | |
| 340 | 398 | |
| 341 | 399 | |
| 342 | 400 | |
| ... | ... | @@ -368,166 +426,186 @@ |
| 368 | 426 | @components_bp.route('/remove_dependencies/<string:component_id>', methods=['GET']) |
| 369 | 427 | def remove_dependencies(component_id): |
| 370 | 428 | # Знаходимо компоненту за її ID |
| 371 | - component = Component.query.get(component_id) | |
| 372 | - if not component: | |
| 373 | - return 'Component not found <meta http-equiv="refresh" content="1;url=/dashboard" />' | |
| 429 | + #component = Component.query.get(component_id) | |
| 430 | + #if not component: | |
| 431 | + # return 'Component not found <meta http-equiv="refresh" content="1;url=/dashboard" />' | |
| 432 | + with open(f"components/components.yml", 'r') as file: | |
| 433 | + components_data = yaml.safe_load(file) | |
| 434 | + if components_data is None: | |
| 435 | + return None | |
| 436 | + # Шукати компонент за id | |
| 437 | + for component in components_data['components']: | |
| 438 | + if component['id'] == component_id: | |
| 439 | + component | |
| 440 | + | |
| 374 | 441 | # remove menu items |
| 375 | - component_name = component.name | |
| 442 | + component_name = component['name'] | |
| 376 | 443 | # file_path = "components/menu.yml" |
| 377 | 444 | # remove_from_yaml_file(file_path, component_name) |
| 378 | - requests.get(f"{k2.domain}api/add-to-menu") | |
| 445 | + #requests.get(f"{k2.domain}api/add-to-menu") | |
| 379 | 446 | # remove routes |
| 380 | 447 | file_path = 'routes.py' |
| 381 | 448 | with open(file_path, 'r') as file: |
| 382 | 449 | lines = file.readlines() |
| 383 | 450 | |
| 384 | - updated_lines = [line for line in lines if line.strip() not in component.dependencies] | |
| 451 | + updated_lines = [line for line in lines if line.strip() not in component['dependencies']] | |
| 385 | 452 | with open(file_path, 'w') as file: |
| 386 | 453 | file.writelines(updated_lines) |
| 454 | + component['installed'] = False | |
| 455 | + with open(f"components/components.yml", 'w') as file: | |
| 456 | + yaml.dump(components_data, file) | |
| 387 | 457 | |
| 388 | - component.installed = False | |
| 389 | - db.session.commit() | |
| 390 | - | |
| 458 | + | |
| 391 | 459 | return 'Component successfully turn off <meta http-equiv="refresh" content="1;url=/dashboard" />' |
| 392 | 460 | |
| 393 | 461 | |
| 394 | 462 | @components_bp.route('/add_dependencies/<string:component_id>', methods=['GET']) |
| 395 | 463 | def add_dependencies(component_id): |
| 396 | - # Знаходимо компоненту за її ID | |
| 397 | - component = Component.query.get(component_id) | |
| 398 | - if not component: | |
| 464 | + # Зчитати вміст файлу YAML | |
| 465 | + with open(f"components/components.yml", 'r') as file: | |
| 466 | + components_data = yaml.safe_load(file) | |
| 467 | + | |
| 468 | + if components_data is None: | |
| 399 | 469 | return 'Component not found <meta http-equiv="refresh" content="1;url=/dashboard" />' |
| 400 | 470 | |
| 471 | + # Знайти компоненту за ID | |
| 472 | + component = None | |
| 473 | + for comp in components_data['components']: | |
| 474 | + if comp['id'] == component_id: | |
| 475 | + component = comp | |
| 476 | + break | |
| 477 | + | |
| 478 | + if component is None: | |
| 479 | + return 'Component not found <meta http-equiv="refresh" content="1;url=/dashboard" />' | |
| 480 | + | |
| 401 | 481 | file_path = 'routes.py' |
| 402 | - code = component.dependencies | |
| 482 | + code = component['dependencies'] | |
| 403 | 483 | # Відкриття файлу у режимі дозапису |
| 404 | 484 | with open(file_path, 'a') as file: |
| 405 | 485 | # Запис нового коду у файл |
| 406 | 486 | file.write(code) |
| 407 | 487 | |
| 408 | 488 | # Оновлюємо статус компоненти |
| 409 | - component.installed = True | |
| 410 | - db.session.commit() | |
| 411 | - | |
| 489 | + component['installed'] = True | |
| 490 | + | |
| 491 | + # Оновлення вмісту файлу YAML | |
| 492 | + with open(f"components/components.yml", 'w') as file: | |
| 493 | + yaml.dump(components_data, file) | |
| 494 | + | |
| 412 | 495 | return 'Dependencies added successfully <meta http-equiv="refresh" content="1;url=/dashboard" />' |
| 413 | 496 | |
| 414 | 497 | |
| 415 | 498 | @components_bp.route('/remove-component/<string:component_id>') |
| 416 | 499 | def remove_component(component_id): |
| 417 | - # Шлях до головної папки проекту | |
| 418 | - project_folder = 'components' | |
| 419 | - component = Component.query.get(component_id) | |
| 420 | - # Назва репозиторія | |
| 421 | - repository_name = component.name | |
| 422 | - # Шлях до папки репозиторія в межах проекту | |
| 423 | - repository_folder = os.path.join(project_folder, repository_name) | |
| 424 | - try: | |
| 425 | - # Перевірка наявності папки репозиторія | |
| 426 | - if os.path.exists(repository_folder): | |
| 427 | - # Видалення папки репозиторія | |
| 428 | - shutil.rmtree(repository_folder) | |
| 429 | - # Видаляємо компоненту з бази | |
| 430 | - if component: | |
| 431 | - db.session.delete(component) | |
| 432 | - db.session.commit() | |
| 500 | + # Шлях до папки з компонентами | |
| 501 | + components_folder = 'components' | |
| 433 | 502 | |
| 434 | - # Повертаємо повідомлення про успішне видалення | |
| 435 | - return 'Component removed successfully <meta http-equiv="refresh" content="1;url=/dashboard" />' | |
| 436 | - except Exception as e: | |
| 437 | - # Повертаємо повідомлення про помилку видалення | |
| 438 | - return 'Error removing component: ' + str(e) | |
| 439 | - | |
| 503 | + # Зчитати вміст файлу YAML | |
| 504 | + with open(f"{components_folder}/components.yml", 'r') as file: | |
| 505 | + components_data = yaml.safe_load(file) | |
| 440 | 506 | |
| 507 | + if components_data is None: | |
| 508 | + return 'Component not found <meta http-equiv="refresh" content="1;url=/dashboard" />' | |
| 441 | 509 | |
| 442 | -# @components_bp.route('/component/add') | |
| 443 | -# def component_add(): | |
| 444 | -# # components for install | |
| 445 | -# try: | |
| 446 | -# # GET-requests to API | |
| 447 | -# response = requests.get(f'{k2.update_domain}api/components') | |
| 448 | -# json_data = response.json() | |
| 449 | -# for item in json_data: | |
| 450 | -# item['button'] = f"{k2.domain}/install_components/{item['id']}" | |
| 451 | -# | |
| 452 | -# except: | |
| 453 | -# json_data = None | |
| 454 | -# return jsonify(json_data) | |
| 455 | -# | |
| 456 | -# | |
| 457 | -# @components_bp.route('/component/list') | |
| 458 | -# def component_list(): | |
| 459 | -# # Встановлені компоненти | |
| 460 | -# component_list = [] | |
| 461 | -# components = Component.query.all() | |
| 462 | -# for component in components: | |
| 463 | -# component_dict = {} | |
| 464 | -# component_dict['name'] = component.name | |
| 465 | -# component_dict['id'] = component.id | |
| 466 | -# component_dict['description'] = component.description | |
| 467 | -# component_dict['version'] = component.version | |
| 468 | -# component_dict['button_off'] =f"{k2.domain}/remove_dependencies/{component.id}" | |
| 469 | -# component_dict['button_on'] = f"{k2.domain}/add_dependencies/{component.id}" | |
| 470 | -# component_dict['button_del'] = f"{k2.domain}/remove-component/{component.id}" | |
| 471 | -# component_list.append(component_dict) | |
| 472 | -# return jsonify(component_list) | |
| 510 | + # Знайти компоненту за ID | |
| 511 | + component = None | |
| 512 | + for comp in components_data['components']: | |
| 513 | + if comp['id'] == component_id: | |
| 514 | + component = comp | |
| 515 | + break | |
| 473 | 516 | |
| 517 | + if component is None: | |
| 518 | + return 'Component not found <meta http-equiv="refresh" content="1;url=/dashboard" />' | |
| 474 | 519 | |
| 520 | + # Видалити папку репозиторія компоненти | |
| 521 | + repository_folder = os.path.join(components_folder, component['name']) | |
| 522 | + if os.path.exists(repository_folder): | |
| 523 | + shutil.rmtree(repository_folder) | |
| 524 | + | |
| 525 | + # Видалити компоненту зі списку | |
| 526 | + components_data['components'] = [comp for comp in components_data['components'] if comp['id'] != component_id] | |
| 527 | + | |
| 528 | + # Записати оновлений вміст у файл YAML | |
| 529 | + with open(f"{components_folder}/components.yml", 'w') as file: | |
| 530 | + yaml.dump(components_data, file) | |
| 531 | + | |
| 532 | + return 'Component removed successfully <meta http-equiv="refresh" content="1;url=/dashboard" />' | |
| 533 | + | |
| 534 | + | |
| 475 | 535 | # menu |
| 476 | 536 | @components_bp.route('/api/add-to-menu', methods=['GET']) |
| 477 | 537 | def add_to_menu(): |
| 538 | + components_folder = 'components' | |
| 478 | 539 | data = [] |
| 479 | 540 | response = requests.get(f"{k2.domain}/menu-admin-items") |
| 480 | 541 | data.append(response.json()[0]) |
| 481 | 542 | prev_menu = response.json()[0]['title'] |
| 482 | 543 | for item in response.json()[0]['children']: |
| 483 | - name_menu = 'k2itm'+ item['to'].replace('/','-') | |
| 544 | + name_menu = 'k2itm' + item['to'].replace('/', '-') | |
| 484 | 545 | caption_menu = item['title'] |
| 485 | 546 | add_menu_with_permissions_db(name_menu, prev_menu, caption_menu) |
| 486 | - components = Component.query.all() | |
| 487 | - components_names = [component.name for component in components] | |
| 488 | - for components_names in components_names: | |
| 489 | - response = requests.get(f"{k2.domain}{components_names}/menu-admin-items") | |
| 490 | - if response.status_code == 200: | |
| 491 | - data.append(response.json()[0]) | |
| 492 | - #prev_menu = | |
| 493 | - prev_menu = response.json()[0]['title'] | |
| 494 | - for item in response.json()[0]['children']: | |
| 495 | - name_menu = 'k2itm'+ item['to'].replace('/','-') | |
| 496 | - caption_menu = item['title'] | |
| 497 | - add_menu_with_permissions_db(name_menu, prev_menu, caption_menu) | |
| 498 | - else: | |
| 499 | - continue | |
| 500 | - # add component_name key for menu items | |
| 501 | - #for item in data: | |
| 502 | - # item['component_name'] = components_names | |
| 503 | - #k2.menu = data | |
| 504 | - return data | |
| 547 | + # Отримати дані з файлу YAML кожного компонента | |
| 548 | + with open(f"{components_folder}/components.yml", 'r') as file: | |
| 549 | + components_data = yaml.safe_load(file) | |
| 505 | 550 | |
| 551 | + if components_data is not None: | |
| 552 | + # Отримати імена всіх компонентів | |
| 553 | + components_names = [comp['name'] for comp in components_data['components']] | |
| 506 | 554 | |
| 555 | + for component_name in components_names: | |
| 556 | + # Виконати запит до відповідного роуту компонента | |
| 557 | + response = requests.get(f"{k2.domain}{component_name}/menu-admin-items") | |
| 507 | 558 | |
| 559 | + if response.status_code == 200: | |
| 560 | + data.append(response.json()[0]) | |
| 561 | + prev_menu = response.json()[0]['title'] | |
| 508 | 562 | |
| 563 | + for item in response.json()[0]['children']: | |
| 564 | + name_menu = 'k2itm' + item['to'].replace('/', '-') | |
| 565 | + caption_menu = item['title'] | |
| 566 | + add_menu_with_permissions_db(name_menu, prev_menu, caption_menu) | |
| 567 | + | |
| 568 | + return jsonify(data) | |
| 569 | + | |
| 570 | + | |
| 509 | 571 | @components_bp.route('/api/main-menu/') |
| 510 | 572 | @login_required |
| 511 | 573 | def get_admin_menu(): |
| 512 | - components = Component.query.all() | |
| 513 | - components_names = [component.name for component in components] | |
| 574 | + | |
| 575 | + components_folder = 'components' | |
| 576 | + # | |
| 577 | + with open(f"{components_folder}/components.yml", 'r') as file: | |
| 578 | + components_data = yaml.safe_load(file) | |
| 579 | + | |
| 580 | + if components_data is None: | |
| 581 | + return jsonify([]) | |
| 582 | + # Отримати список імен компонентів | |
| 583 | + components_names = [comp['name'] for comp in components_data['components']] | |
| 514 | 584 | if 'k2site' in components_names: |
| 515 | 585 | role_id = current_user.get_role_id() |
| 516 | - filter_menu = [] | |
| 517 | - response = requests.get(f"{k2.domain}api/add-to-menu") | |
| 518 | - menu_items_list = K2admin_menus.get_menu_items_by_roles(role_id) | |
| 519 | - for item in response.json(): | |
| 520 | - filtered_children = [] | |
| 521 | - for im in item['children']: | |
| 522 | - if 'k2itm' + im['to'].replace('/','-') in menu_items_list: | |
| 523 | - filtered_children.append(im) | |
| 524 | - if filtered_children: | |
| 525 | - item['children'] = filtered_children | |
| 526 | - filter_menu.append(item) | |
| 527 | - # filter_menu.append({"heading": 'APPS & PAGES'}) | |
| 528 | - return jsonify(filter_menu) | |
| 529 | 586 | |
| 587 | + # Виконати запит до роуту '/api/add-to-menu' | |
| 588 | + response = requests.get(f"{k2.domain}api/add-to-menu") | |
| 589 | + menu_items_list = K2admin_menus.get_menu_items_by_roles(role_id) | |
| 530 | 590 | |
| 591 | + filter_menu = [] | |
| 592 | + | |
| 593 | + for item in response.json(): | |
| 594 | + filtered_children = [] | |
| 595 | + | |
| 596 | + for im in item['children']: | |
| 597 | + if 'k2itm' + im['to'].replace('/', '-') in menu_items_list: | |
| 598 | + filtered_children.append(im) | |
| 599 | + | |
| 600 | + if filtered_children: | |
| 601 | + item['children'] = filtered_children | |
| 602 | + filter_menu.append(item) | |
| 603 | + | |
| 604 | + return jsonify(filter_menu) | |
| 605 | + | |
| 606 | + return jsonify([]) | |
| 607 | + | |
| 608 | + | |
| 531 | 609 | def add_menu_with_permissions_db(name_menu, prev_menu, caption_menu): |
| 532 | 610 | |
| 533 | 611 | # Створення об'єкта k2admin_menus |
| ... | ... | @@ -569,7 +647,6 @@ |
| 569 | 647 | try: |
| 570 | 648 | response = requests.get(f'{k2.update_domain}api/components') |
| 571 | 649 | json_data = response.json() |
| 572 | - # Перетворення JSON-об'єкту на масив | |
| 573 | 650 | component_server = [item for item in json_data] |
| 574 | 651 | except: |
| 575 | 652 | component_server = None |
| 576 | 653 | |
| ... | ... | @@ -585,10 +662,20 @@ |
| 585 | 662 | 'description'] else False)] |
| 586 | 663 | else: |
| 587 | 664 | filtered_components = component_server |
| 588 | - components = Component.query.all() | |
| 589 | - components_names = [component.name for component in components] | |
| 590 | - components_version = [{component.name: component.version} for component in components] | |
| 665 | + project_folder = 'components' | |
| 666 | + with open(f"{project_folder}/components.yml", 'r') as file: | |
| 667 | + components_data = yaml.safe_load(file) | |
| 591 | 668 | |
| 669 | + components_names = [] | |
| 670 | + components_version = [] | |
| 671 | + # Отримати імена та версії компонентів з даних YAML | |
| 672 | + if components_data is not None: | |
| 673 | + for component in components_data['components']: | |
| 674 | + name = component['name'] | |
| 675 | + version = component['version'] | |
| 676 | + components_names.append(name) | |
| 677 | + components_version.append({name: version}) | |
| 678 | + | |
| 592 | 679 | return render_template('dashboard-add.html', |
| 593 | 680 | component_server=filtered_components, search_query=search_query, components_names=components_names, components_version=components_version ) |
| 594 | 681 | |
| ... | ... | @@ -597,7 +684,12 @@ |
| 597 | 684 | @components_bp.route('/component-list') |
| 598 | 685 | @login_required |
| 599 | 686 | def component_list_dasb(): |
| 600 | - components = Component.query.all() | |
| 687 | + with open(f"components/components.yml", 'r') as file: | |
| 688 | + components_data = yaml.safe_load(file) | |
| 689 | + if components_data is None or 'components' not in components_data: | |
| 690 | + components = [] | |
| 691 | + else: | |
| 692 | + components = components_data['components'] | |
| 601 | 693 | |
| 602 | 694 | return render_template('dashboard-list.html', components=components) |
| 603 | 695 |
languages/babel_translation_directories.yml
languages/en/LC_MESSAGES/messages.mo
No preview for this file type
languages/pl/LC_MESSAGES/messages.mo
No preview for this file type
languages/uk/LC_MESSAGES/messages.mo
No preview for this file type