Fixes for use dashboard in modules

This commit is contained in:
Antonio de la Rosa 2024-02-09 19:43:34 +01:00
parent 8a0354b85b
commit ff81d2aa8d
3 changed files with 69 additions and 8 deletions

View file

@ -6,7 +6,7 @@ from paramecio2.modules.admin import admin_app, t as admin_t
from paramecio2.libraries.db.coreforms import SelectForm, SelectModelForm, HiddenForm
from paramecio2.libraries.mtemplates import PTemplate, env_theme
from paramecio2.libraries import datetime
from paramecio2.libraries.urls import make_media_url
from paramecio2.libraries.urls import make_media_url, make_url
#from modules.monit.models.monit import Server, ServerData, Alerts
from modules.pastafari2.libraries.scandir import scandir
from paramecio2.libraries.db.webmodel import WebModel
@ -26,6 +26,7 @@ from collections import OrderedDict
from importlib import import_module, reload
from modules.pastafari2.libraries.progress import load_progress
from modules.pastafari2.libraries.load_task import load_db_in_task
from importlib import import_module
try:
import ujson as json
@ -55,17 +56,59 @@ if hasattr(config, 'pastafari_paths'):
@admin_app.route('/pastafari2/dashboard/')
def pastafari2_dashboard():
db=g.connection
config_parser=configparser.ConfigParser()
select_task=scandir(base_path, config_parser, OrderedDict(), 'tasks')
(select_task, select_hash)=scandir(base_path, config_parser, OrderedDict(), {}, 'tasks')
for module in pastafari_paths:
select_task=scandir(module, config_parser, select_task, 'tasks')
(select_task, select_hash)=scandir(module, config_parser, select_task, select_hash, 'tasks')
title_task=''
description_task=''
links=''
path_module='admin_app.pastafari2_dashboard'
task_path=request.args.get('task_path', '')
return t.load_template('dash_pastafari.phtml', title=I18n.lang('pastafari2', 'servers_dashboard', 'Servers Dashboard'), path_module='admin_app.pastafari2_dashboard', select_task=select_task, task_path=task_path)
module=os.getcwd()+'/'+task_path
details_task=[]
#import the module for load links in general dashboard
if os.path.isfile(module) and task_path in select_hash:
final_path=task_path.replace('.py', '').replace('/','.')
#print(final_path)
ptask=import_module(final_path)
if config.reloader:
reload(ptask)
task_first=ptask.ServerTask('', db, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data=dict(request.args))
links=task_first.links
path_module=task_first.path_module
title_task=' - '+task_first.name_task
description_task=task_first.description_task
details_task=select_hash[task_path]
else:
task_path=''
#print(task_first.links)
#print(module)
return t.load_template('dash_pastafari.phtml', title=I18n.lang('pastafari2', 'servers_dashboard', 'Servers Dashboard')+title_task, path_module=path_module, select_task=select_task, task_path=task_path, links=links, description_task=description_task, details_task=details_task)
@admin_app.route('/pastafari2/settings/')
def pastafari2_settings():

View file

@ -3,7 +3,7 @@
import os
from collections import OrderedDict
def scandir(mydir, config_parser, arr_dir=OrderedDict(), father=''):
def scandir(mydir, config_parser, arr_dir=OrderedDict(), arr_hash={}, father=''):
search_dir=os.listdir(mydir)
@ -35,11 +35,12 @@ def scandir(mydir, config_parser, arr_dir=OrderedDict(), father=''):
form=config_parser['form'][k]
arr_dir[father][os.path.basename(mydir)].append([config_parser['modules'][k], mydir+'/'+k+'.py', 1, form])
arr_hash[mydir+'/'+k+'.py']=[config_parser['modules'][k], mydir+'/'+k+'.py', 1, form]
elif os.path.isdir(mydir+'/'+one_path):
arr_dir=scandir(mydir+'/'+one_path, config_parser, arr_dir, os.path.basename(mydir))
(arr_dir, arr_hash)=scandir(mydir+'/'+one_path, config_parser, arr_dir, arr_hash, os.path.basename(mydir))
return arr_dir
return (arr_dir, arr_hash)

View file

@ -1,7 +1,12 @@
<%inherit file="dashboard.phtml"/>
<%block name="content">
<div id="principal_container">
% if task_path=='':
<p><a href="${url_for('.pastafari2_add_server')}">${lang('pastafari2', 'add_server', 'Add server')}</a>
% else:
<p><strong>${description_task}</strong></p>
<p>${links|n}</p>
% endif
<p>${lang('pastafari2', 'choose_group', 'Choose group')}:
<select name="group_id" id="group_id">
@ -52,23 +57,35 @@ form_set=[]
<!--</ul>-->
</%def>
<p>
% if task_path=='':
<select name="task" id="task">
<option value="">Select a task...</option>
${show_tasks('tasks', '')}
</select>
% else:
<input type="hidden" name="task" id="task" value="${task_path}" />
<input type="hidden" name="${details_task[1]}" id="${details_task[1].replace('/', '_')}_form" value="${str(details_task[3])}">
% endif
${"\n".join(form_set)|n}
</p>
<input type="button" name="select_all" class="select_all" value="${lang('pastafari2', 'select_all_servers', 'Select all servers')}" />
<input type="button" name="deselect_all" class="deselect_all" value="${lang('pastafari2', 'deselect_all_servers', 'Deselect all servers')}" />
% if task_path=='':
<input type="button" name="update_selected_servers" class="send_task_server update_selected_servers button_blue" value="${lang('pastafari2', 'update_selected_servers', 'Update selected servers')}" />
% endif
<input type="button" name="make_task_selected_servers" class="send_task_server make_task_selected_servers button_blue" value="${lang('pastafari2', 'make_task_selected_servers', 'Make task in selected servers')}" />
<div id="table_servers">
</div>
<input type="button" name="select_all" class="select_all" value="${lang('pastafari2', 'select_all_servers', 'Select all servers')}" />
<input type="button" name="deselect_all" class="deselect_all" value="${lang('pastafari2', 'deselect_all_servers', 'Deselect all servers')}" />
% if task_path=='':
<input type="button" name="update_selected_servers" class="send_task_server update_selected_servers button_blue" value="${lang('pastafari2', 'update_selected_servers', 'Update selected servers')}" />
% endif
<input type="button" name="make_task_selected_servers" class="send_task_server make_task_selected_servers button_blue" value="${lang('pastafari2', 'make_task_selected_servers', 'Make task in selected servers')}" />
</div>
% if task_path!='':
<p>${links|n}</p>
% endif
</%block>
<%block name="jscript_block">
<script language="Javascript" src="${make_media_url('js/jsutils/posting2.js', 'pastafari2')}"></script>