Commit db940340d9c10c5a36fc46957d694fc99c0ef1b3

Authored by Василь Свідрик
1 parent e002d7855c
Exists in master

add get menu-items api ver.

Showing 10 changed files with 57 additions and 25 deletions Side-by-side Diff

__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
... ... @@ -10,24 +10,36 @@
10 10 title: CRM Dashboard
11 11 url:
12 12 name: dashboards-crm
  13 +- category: error
  14 + icon: error
  15 + id: 3
  16 + title: k2test--error
  17 + url:
  18 + name: error
  19 +- category: error
  20 + icon: error
  21 + id: 4
  22 + title: k2test--error
  23 + url:
  24 + name: error
13 25 - category: "\u0422\u0435\u0441\u0442\u043E\u0432\u0430 \u043A\u043E\u043C\u043F\u043E\
14 26 \u043D\u0435\u043D\u0442\u0430"
15 27 icon: mdi-chart-timeline-variant
16   - id: 3
  28 + id: 5
17 29 title: "\u0422\u0435\u0441\u0442 2"
18 30 url:
19 31 name: new2
20 32 - category: "\u0422\u0435\u0441\u0442\u043E\u0432\u0430 \u043A\u043E\u043C\u043F\u043E\
21 33 \u043D\u0435\u043D\u0442\u0430"
22 34 icon: mdi-chart-timeline-variant
23   - id: 4
  35 + id: 6
24 36 title: "\u0422\u0435\u0441\u0442 3"
25 37 url:
26 38 name: new3
27 39 - category: "\u0422\u0435\u0441\u0442\u043E\u0432\u0430 \u043A\u043E\u043C\u043F\u043E\
28 40 \u043D\u0435\u043D\u0442\u0430"
29 41 icon: mdi-chart-timeline-variant
30   - id: 5
  42 + id: 7
31 43 title: "\u0422\u0435\u0441\u0442 4"
32 44 url:
33 45 name: new4
No preview for this file type
k2/__pycache__/k2inst.cpython-310.pyc
No preview for this file type
... ... @@ -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)])
... ... @@ -120,7 +125,7 @@
120 125 # Компоненти доступні для встановлення
121 126 try:
122 127 # GET-запит до API
123   - response = requests.get('http://127.0.0.1:8001/api/components')
  128 + response = requests.get(f'{k2.update_domain}api/components')
124 129 json_data = response.json()
125 130 # Перетворення JSON-об'єкту на масив
126 131 component_server = [item for item in json_data]
... ... @@ -149,7 +154,7 @@
149 154  
150 155 @components_bp.route('/show_components/<string:component_id>')
151 156 def show_components(component_id):
152   - response = requests.get('http://127.0.0.1:8001/api/components')
  157 + response = requests.get(f'{k2.update_domain}api/components')
153 158 json_data = response.json()
154 159 selected_component = next((component for component in json_data if component['id'] == component_id), None)
155 160 return render_template('component-info.html', selected_component=selected_component)
... ... @@ -159,7 +164,7 @@
159 164 # Шлях до головної папки проекту
160 165 project_folder = 'components'
161 166 #component = Component.get_repository_by_id(component_id)
162   - response = requests.get('http://127.0.0.1:8001/api/components')
  167 + response = requests.get(f'{k2.update_domain}api/components')
163 168 json_data = response.json()
164 169 selected_component = next((component for component in json_data if component['id'] == component_id), None)
165 170 # Назва репозиторія
... ... @@ -224,7 +229,7 @@
224 229 # Шлях до головної папки проекту
225 230 project_folder = 'components'
226 231 # Отримати відповідну компоненту зі списку компонент
227   - response = requests.get('http://127.0.0.1:8001/api/components')
  232 + response = requests.get(f'{k2.update_domain}api/components')
228 233 json_data = response.json()
229 234 selected_component = next((component for component in json_data if component['id'] == component_id), None)
230 235 if selected_component is None:
231 236  
... ... @@ -286,21 +291,21 @@
286 291 component.installed = True
287 292  
288 293 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   - }
  294 + # add menu items yml
  295 + #file_path_input = f"components/{selected_component['name']}/menu_items.yml"
  296 + #if os.path.exists(file_path_input):
  297 + # with open(file_path_input, 'r', encoding='utf-8') as file:
  298 + # data = yaml.safe_load(file)
  299 + #else:
  300 + # data = {
  301 + # 'url': {'name': 'error'},
  302 + # 'icon': 'error',
  303 + # 'title': f"{selected_component['name']}--error",
  304 + # 'category': 'error',
  305 + # }
301 306  
302   - file_path = 'components/menu.yml'
303   - append_to_yaml_file(file_path, data)
  307 + #file_path = 'components/menu.yml'
  308 + #append_to_yaml_file(file_path, data)
304 309  
305 310 #add language folders
306 311 k2.search_babel_translation_directories()
... ... @@ -314,6 +319,24 @@
314 319  
315 320 @components_bp.route('/install-requirments/<string:selected_component_name>', methods=['GET'])
316 321 def install_requirments(selected_component_name):
  322 + #menu items api
  323 + response = requests.get(f"{k2.domain}{selected_component_name}/menu-items")
  324 + if response.status_code == 200:
  325 + data = response.json()
  326 + print(data)
  327 + else:
  328 + data = [{
  329 + 'url': {'name': 'error'},
  330 + 'icon': 'error',
  331 + 'title': f"{selected_component_name}--error",
  332 + 'category': 'error',
  333 + }]
  334 +
  335 + file_path = 'components/menu.yml'
  336 + append_to_yaml_file(file_path, data)
  337 + k2.get_menu_elenents()
  338 +
  339 + #install requirements
317 340 requirements_file = os.path.join('components', selected_component_name, "requirements.txt")
318 341 if os.path.isfile(requirements_file):
319 342 pip_command = f"{k2.venv_bin_path}/python -m pip install -r {requirements_file}"
... ... @@ -321,7 +344,6 @@
321 344 return f'''Requirements installed successfully
322 345 \n \n please wait installing requirments components...
323 346 <meta http-equiv="refresh" content="1;url=/install-requirments-components" />'''
324   -
325 347  
326 348 @components_bp.route('/install-requirments-components')
327 349 def install_requirements_components():
... ... @@ -19,8 +19,6 @@
19 19 babel = Babel(app)
20 20 babel.init_app(app, locale_selector=k2.get_locale)
21 21  
22   -#menu
23   -k2.get_menu_elenents()
24 22  
25 23 # flask routing
26 24 from routes import *