Commit e3b1c2ee471f00bef87802306ca794a62f062f01
Exists in
master
marge master
Showing 14 changed files Side-by-side Diff
- __pycache__/__init__.cpython-310.pyc
- __pycache__/main.cpython-310.pyc
- __pycache__/routes.cpython-310.pyc
- components/adm/__pycache__/__init__.cpython-310.pyc
- components/adm/__pycache__/__init__.cpython-311.pyc
- components/k2test/k2test/views.py
- components/menu.yml
- k2/__pycache__/__init__.cpython-310.pyc
- k2/__pycache__/k2cfg.cpython-310.pyc
- k2/__pycache__/k2inst.cpython-310.pyc
- k2/__pycache__/k2obj.cpython-310.pyc
- k2/k2cfg.py
- k2/k2inst.py
- k2/k2obj.py
__pycache__/__init__.cpython-310.pyc
No preview for this file type
__pycache__/main.cpython-310.pyc
No preview for this file type
__pycache__/routes.cpython-310.pyc
No preview for this file type
components/adm/__pycache__/__init__.cpython-310.pyc
No preview for this file type
components/adm/__pycache__/__init__.cpython-311.pyc
No preview for this file type
components/k2test/k2test/views.py
| ... | ... | @@ -38,23 +38,16 @@ |
| 38 | 38 | def menu_items(): |
| 39 | 39 | data = [ |
| 40 | 40 | { |
| 41 | - 'url': {'name': 'new2'}, | |
| 42 | - 'icon': 'mdi-chart-timeline-variant', | |
| 43 | - 'title': 'Тест 2', | |
| 44 | - 'category': 'Тестова компонента', | |
| 45 | - }, | |
| 46 | - { | |
| 47 | - 'url': {'name': 'new3'}, | |
| 48 | - 'icon': 'mdi-chart-timeline-variant', | |
| 49 | - 'title': 'Тест 3', | |
| 50 | - 'category': 'Тестова компонента', | |
| 51 | - }, | |
| 52 | - { | |
| 53 | - 'url': {'name': 'new4'}, | |
| 54 | - 'icon': 'mdi-chart-timeline-variant', | |
| 55 | - 'title': 'Тест 4', | |
| 56 | - 'category': 'Тестова компонента', | |
| 57 | - }, | |
| 41 | + | |
| 42 | + 'title': 'Тестова компонента', | |
| 43 | + 'category': 'Тест', | |
| 44 | + 'icon': {'icon': 'mdi-chart-timeline-variant'}, | |
| 45 | + 'children': [ | |
| 46 | + {'title': 'Тест 3', 'to': 'k2test-new3'}, | |
| 47 | + {'title': 'Тест 3', 'to': 'k2test-new4'}, | |
| 48 | + ], | |
| 49 | + } | |
| 50 | + | |
| 58 | 51 | ] |
| 59 | 52 | return data |
components/menu.yml
| 1 | -- category: dashboards | |
| 2 | - icon: mdi-chart-timeline-variant | |
| 3 | - id: 1 | |
| 4 | - title: Analytics Dashboard | |
| 5 | - url: | |
| 6 | - name: dashboards-analytics | |
| 7 | -- category: dashboards | |
| 8 | - icon: mdi-cart-outline | |
| 1 | +- category: "\u0422\u0435\u0441\u0442" | |
| 2 | + children: | |
| 3 | + - title: "\u0422\u0435\u0441\u0442 3" | |
| 4 | + to: k2test-new3 | |
| 5 | + - title: "\u0422\u0435\u0441\u0442 3" | |
| 6 | + to: k2test-new4 | |
| 7 | + component_name: k2test | |
| 8 | + icon: | |
| 9 | + icon: mdi-chart-timeline-variant | |
| 9 | 10 | id: 2 |
| 10 | - title: CRM Dashboard | |
| 11 | - url: | |
| 12 | - name: dashboards-crm | |
| 13 | -- category: "\u0422\u0435\u0441\u0442\u043E\u0432\u0430 \u043A\u043E\u043C\u043F\u043E\ | |
| 11 | + title: "\u0422\u0435\u0441\u0442\u043E\u0432\u0430 \u043A\u043E\u043C\u043F\u043E\ | |
| 14 | 12 | \u043D\u0435\u043D\u0442\u0430" |
| 15 | - icon: mdi-chart-timeline-variant | |
| 16 | - id: 3 | |
| 17 | - title: "\u0422\u0435\u0441\u0442 2" | |
| 18 | - url: | |
| 19 | - name: new2 | |
| 20 | -- category: "\u0422\u0435\u0441\u0442\u043E\u0432\u0430 \u043A\u043E\u043C\u043F\u043E\ | |
| 21 | - \u043D\u0435\u043D\u0442\u0430" | |
| 22 | - icon: mdi-chart-timeline-variant | |
| 23 | - id: 4 | |
| 24 | - title: "\u0422\u0435\u0441\u0442 3" | |
| 25 | - url: | |
| 26 | - name: new3 | |
| 27 | -- category: "\u0422\u0435\u0441\u0442\u043E\u0432\u0430 \u043A\u043E\u043C\u043F\u043E\ | |
| 28 | - \u043D\u0435\u043D\u0442\u0430" | |
| 29 | - icon: mdi-chart-timeline-variant | |
| 30 | - id: 5 | |
| 31 | - title: "\u0422\u0435\u0441\u0442 4" | |
| 32 | - url: | |
| 33 | - name: new4 |
k2/__pycache__/__init__.cpython-310.pyc
No preview for this file type
k2/__pycache__/k2cfg.cpython-310.pyc
No preview for this file type
k2/__pycache__/k2inst.cpython-310.pyc
No preview for this file type
k2/__pycache__/k2obj.cpython-310.pyc
No preview for this file type
k2/k2cfg.py
| ... | ... | @@ -10,7 +10,6 @@ |
| 10 | 10 | from flask import session |
| 11 | 11 | |
| 12 | 12 | class k2(k2obj): |
| 13 | - | |
| 14 | 13 | version = '2.5.1.27' |
| 15 | 14 | db = SQLAlchemy() |
| 16 | 15 | domain = 'http://127.0.0.1:5000/' |
| ... | ... | @@ -58,8 +57,6 @@ |
| 58 | 57 | with open('components/menu.yml', 'r') as f: |
| 59 | 58 | yaml_data = yaml.load(f, Loader=yaml.FullLoader) |
| 60 | 59 | cls.menu = yaml_data |
| 61 | - | |
| 62 | - | |
| 63 | 60 | |
| 64 | 61 | |
| 65 | 62 | # load database settings from yml file |
k2/k2inst.py
| ... | ... | @@ -12,9 +12,14 @@ |
| 12 | 12 | from flask import current_app |
| 13 | 13 | import yaml |
| 14 | 14 | from functools import wraps |
| 15 | +import os | |
| 16 | +import sys | |
| 15 | 17 | |
| 18 | + | |
| 19 | +# initialize db | |
| 16 | 20 | db = k2.db |
| 17 | 21 | #migrate = Migrate(app, db) |
| 22 | + | |
| 18 | 23 | def generate_id(): |
| 19 | 24 | generated_id = uuid.uuid4().hex[:32] |
| 20 | 25 | return ''.join([generated_id[i:i + 4] for i in range(0, len(generated_id), 4)]) |
| ... | ... | @@ -44,6 +49,10 @@ |
| 44 | 49 | def get_repository_by_id(self,rep_id): |
| 45 | 50 | component = db.session.query(Component).filter(Component.id == rep_id).first() |
| 46 | 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 | |
| 47 | 56 | components_bp = Blueprint('components', __name__, template_folder='templates') |
| 48 | 57 | config = yaml.safe_load(open("db/first-login.yml")) |
| 49 | 58 | |
| ... | ... | @@ -71,6 +80,16 @@ |
| 71 | 80 | with open(file_path, 'w') as f: |
| 72 | 81 | yaml.dump(existing_data, f, default_flow_style=False) |
| 73 | 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 | + | |
| 74 | 93 | @components_bp.route('/api/languages', methods=['GET']) |
| 75 | 94 | def find_language(): |
| 76 | 95 | components = Component.query.all() |
| ... | ... | @@ -120,7 +139,7 @@ |
| 120 | 139 | # Компоненти доступні для встановлення |
| 121 | 140 | try: |
| 122 | 141 | # GET-запит до API |
| 123 | - response = requests.get('http://127.0.0.1:8001/api/components') | |
| 142 | + response = requests.get(f'{k2.update_domain}api/components') | |
| 124 | 143 | json_data = response.json() |
| 125 | 144 | # Перетворення JSON-об'єкту на масив |
| 126 | 145 | component_server = [item for item in json_data] |
| ... | ... | @@ -149,7 +168,7 @@ |
| 149 | 168 | |
| 150 | 169 | @components_bp.route('/show_components/<string:component_id>') |
| 151 | 170 | def show_components(component_id): |
| 152 | - response = requests.get('http://127.0.0.1:8001/api/components') | |
| 171 | + response = requests.get(f'{k2.update_domain}api/components') | |
| 153 | 172 | json_data = response.json() |
| 154 | 173 | selected_component = next((component for component in json_data if component['id'] == component_id), None) |
| 155 | 174 | return render_template('component-info.html', selected_component=selected_component) |
| ... | ... | @@ -159,7 +178,7 @@ |
| 159 | 178 | # Шлях до головної папки проекту |
| 160 | 179 | project_folder = 'components' |
| 161 | 180 | #component = Component.get_repository_by_id(component_id) |
| 162 | - response = requests.get('http://127.0.0.1:8001/api/components') | |
| 181 | + response = requests.get(f'{k2.update_domain}api/components') | |
| 163 | 182 | json_data = response.json() |
| 164 | 183 | selected_component = next((component for component in json_data if component['id'] == component_id), None) |
| 165 | 184 | # Назва репозиторія |
| ... | ... | @@ -224,7 +243,7 @@ |
| 224 | 243 | # Шлях до головної папки проекту |
| 225 | 244 | project_folder = 'components' |
| 226 | 245 | # Отримати відповідну компоненту зі списку компонент |
| 227 | - response = requests.get('http://127.0.0.1:8001/api/components') | |
| 246 | + response = requests.get(f'{k2.update_domain}api/components') | |
| 228 | 247 | json_data = response.json() |
| 229 | 248 | selected_component = next((component for component in json_data if component['id'] == component_id), None) |
| 230 | 249 | if selected_component is None: |
| 231 | 250 | |
| 232 | 251 | |
| ... | ... | @@ -286,25 +305,25 @@ |
| 286 | 305 | component.installed = True |
| 287 | 306 | |
| 288 | 307 | db.session.commit() |
| 289 | - # add menu items | |
| 290 | - file_path_input = f"components/{selected_component['name']}/menu_items.yml" | |
| 291 | - if os.path.exists(file_path_input): | |
| 292 | - with open(file_path_input, 'r', encoding='utf-8') as file: | |
| 293 | - data = yaml.safe_load(file) | |
| 294 | - else: | |
| 295 | - data = { | |
| 296 | - 'url': {'name': 'error'}, | |
| 297 | - 'icon': 'error', | |
| 298 | - 'title': f"{selected_component['name']}--error", | |
| 299 | - 'category': 'error', | |
| 300 | - } | |
| 308 | + # add menu items yml | |
| 309 | + #file_path_input = f"components/{selected_component['name']}/menu_items.yml" | |
| 310 | + #if os.path.exists(file_path_input): | |
| 311 | + # with open(file_path_input, 'r', encoding='utf-8') as file: | |
| 312 | + # data = yaml.safe_load(file) | |
| 313 | + #else: | |
| 314 | + # data = { | |
| 315 | + # 'url': {'name': 'error'}, | |
| 316 | + # 'icon': 'error', | |
| 317 | + # 'title': f"{selected_component['name']}--error", | |
| 318 | + # 'category': 'error', | |
| 319 | + # } | |
| 301 | 320 | |
| 302 | - file_path = 'components/menu.yml' | |
| 303 | - append_to_yaml_file(file_path, data) | |
| 321 | + #file_path = 'components/menu.yml' | |
| 322 | + #append_to_yaml_file(file_path, data) | |
| 304 | 323 | |
| 305 | 324 | #add language folders |
| 306 | 325 | k2.search_babel_translation_directories() |
| 307 | - | |
| 326 | + print(k2.domain) | |
| 308 | 327 | return f'''Component installed successfully: {selected_component["name"]} v{version} {k2.babel_translation_directories}, |
| 309 | 328 | \n \n please wait installing requirments... |
| 310 | 329 | <meta http-equiv="refresh" content="0;url=/install-requirments/{selected_component["name"]}" />''' |
| ... | ... | @@ -314,6 +333,26 @@ |
| 314 | 333 | |
| 315 | 334 | @components_bp.route('/install-requirments/<string:selected_component_name>', methods=['GET']) |
| 316 | 335 | def install_requirments(selected_component_name): |
| 336 | + #menu items api | |
| 337 | + response = requests.get(f"{k2.domain}{selected_component_name}/menu-items") | |
| 338 | + if response.status_code == 200: | |
| 339 | + data = response.json() | |
| 340 | + print(data) | |
| 341 | + else: | |
| 342 | + data = [{ | |
| 343 | + 'url': {'name': 'error'}, | |
| 344 | + 'icon': 'error', | |
| 345 | + 'title': f"{selected_component_name}--error", | |
| 346 | + 'category': 'error', | |
| 347 | + }] | |
| 348 | + # add component_name key for menu items | |
| 349 | + for item in data: | |
| 350 | + item['component_name'] = selected_component_name | |
| 351 | + file_path = 'components/menu.yml' | |
| 352 | + append_to_yaml_file(file_path, data) | |
| 353 | + k2.get_menu_elenents() | |
| 354 | + | |
| 355 | + #install requirements | |
| 317 | 356 | requirements_file = os.path.join('components', selected_component_name, "requirements.txt") |
| 318 | 357 | if os.path.isfile(requirements_file): |
| 319 | 358 | pip_command = f"{k2.venv_bin_path}/python -m pip install -r {requirements_file}" |
| ... | ... | @@ -322,7 +361,6 @@ |
| 322 | 361 | \n \n please wait installing requirments components... |
| 323 | 362 | <meta http-equiv="refresh" content="1;url=/install-requirments-components" />''' |
| 324 | 363 | |
| 325 | - | |
| 326 | 364 | @components_bp.route('/install-requirments-components') |
| 327 | 365 | def install_requirements_components(): |
| 328 | 366 | # Откриття файлу requirements_components.txt |
| 329 | 367 | |
| 330 | 368 | |
| 331 | 369 | |
| 332 | 370 | |
| 333 | 371 | |
| ... | ... | @@ -348,22 +386,20 @@ |
| 348 | 386 | component = Component.query.get(component_id) |
| 349 | 387 | if not component: |
| 350 | 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) | |
| 351 | 393 | |
| 352 | - # Шлях до файлу, з якого потрібно видалити залежності | |
| 394 | + # remove routes | |
| 353 | 395 | file_path = 'routes.py' |
| 354 | - | |
| 355 | - # Зчитуємо вміст файлу | |
| 356 | 396 | with open(file_path, 'r') as file: |
| 357 | 397 | lines = file.readlines() |
| 358 | 398 | |
| 359 | - # Видаляємо рядки, що містять залежності компоненти | |
| 360 | 399 | updated_lines = [line for line in lines if line.strip() not in component.dependencies] |
| 361 | - | |
| 362 | - # Записуємо оновлений вміст у файл | |
| 363 | 400 | with open(file_path, 'w') as file: |
| 364 | 401 | file.writelines(updated_lines) |
| 365 | 402 | |
| 366 | - # Оновлюємо статус компоненти | |
| 367 | 403 | component.installed = False |
| 368 | 404 | db.session.commit() |
| 369 | 405 | |
| ... | ... | @@ -414,4 +450,8 @@ |
| 414 | 450 | except Exception as e: |
| 415 | 451 | # Повертаємо повідомлення про помилку видалення |
| 416 | 452 | return 'Error removing component: ' + str(e) |
| 453 | + | |
| 454 | +@components_bp.route('/api/main-menu/') | |
| 455 | +def project_menu(): | |
| 456 | + return k2.menu |
k2/k2obj.py