diff --git a/app/_config.py b/app/_config.py index 3eafcd2..5dda034 100644 --- a/app/_config.py +++ b/app/_config.py @@ -5,12 +5,12 @@ import random, string ## Flask Server (For DEV) app_ip = '127.0.0.1' -app_port = 80 +app_port = 5000 app_debug = True app_maintenance = False app_name = 'takeus-ipam' -app_version = 'V1.6' +app_version = 'V2026.1' app_release_date = '11/2025' app_url = "http://0.0.0.0" diff --git a/app/models.py b/app/models.py index 0c67813..5ecec68 100644 --- a/app/models.py +++ b/app/models.py @@ -8,6 +8,7 @@ class User(UserMixin, db.Model): is_admin = db.Column(db.Boolean(),default=False) is_reado = db.Column(db.Boolean(),default=False) ui_theme = db.Column(db.String(16)) + ui_lmode = db.Column(db.Boolean(),default=False) dat_last = db.Column(db.DateTime()) class Network(db.Model): diff --git a/app/routes/r_networks.py b/app/routes/r_networks.py index 0dc0ae7..e472c0c 100644 --- a/app/routes/r_networks.py +++ b/app/routes/r_networks.py @@ -46,26 +46,55 @@ def networks(): @network.route('//allocations',methods=['GET','POST']) @login_required def allocations(net_id): - - active_page = request.args.get('page', type=int) - if active_page == None: - active_page = 1 - - next_page = active_page+1 - prev_page = active_page-1 - - if request.args.get('items', type=int) != None: - session['items'] = request.args.get('items', type=int) + # CHANGE VIEW + if request.args.get('view') == "change": + db_user = User.query.filter_by(id=current_user.id).first() + if current_user.ui_lmode == False: + db_user.ui_lmode = True + else: + db_user.ui_lmode = False + db.session.commit() + return redirect(url_for('network.allocations',net_id=net_id)) + # HIDE DHCP try: - if session['items'] == None: - session['items'] = 15 + session['hide_dhcp'] except: - session['items'] = 15 - - db_network = Network.query.filter_by(id=net_id).first() - db_allocations = db.paginate(db.select(Allocation).filter_by(net_id=net_id), per_page=session['items'] ) - - return render_template('panel/allocations.html', title="Allocations", is_networks=True, app_version=app_version, allocations=db_allocations, network=db_network, Inventory=Inventory, active_page=active_page, next_page=next_page, prev_page=prev_page, navcolor='dark') + session['hide_dhcp'] = False + if request.args.get('view') == "hide_dhcp": + if session['hide_dhcp'] == False: + session['hide_dhcp'] = True + else: + session['hide_dhcp'] = False + return redirect(url_for('network.allocations',net_id=net_id)) + print(session['hide_dhcp']) + # PAGINATION MODE + if current_user.ui_lmode == False: + active_page = request.args.get('page', type=int) + if active_page == None: + active_page = 1 + + next_page = active_page+1 + prev_page = active_page-1 + + if request.args.get('items', type=int) != None: + session['items'] = request.args.get('items', type=int) + try: + if session['items'] == None: + session['items'] = 15 + except: + session['items'] = 15 + + db_network = Network.query.filter_by(id=net_id).first() + db_allocations = db.paginate(db.select(Allocation).filter_by(net_id=net_id), per_page=session['items'] ) + + return render_template('panel/allocations.html', title="Allocations", is_networks=True, app_version=app_version, allocations=db_allocations, network=db_network, Inventory=Inventory, active_page=active_page, next_page=next_page, prev_page=prev_page, navcolor='dark') + + # LIST MODE + else: + db_network = Network.query.filter_by(id=net_id).first() + db_allocations = Allocation.query.filter_by(net_id=net_id).all() + + return render_template('panel/allocations.html', title="Allocations", is_networks=True, app_version=app_version, allocations=db_allocations, network=db_network, Inventory=Inventory, navcolor='dark') ## MODAL ROUTES @@ -94,7 +123,7 @@ def allocation_del_modal(net_id,ipv4): 'action_text': 'Remove', 'action_url': url_for('network.allocation_delete',net_id=net_id,ipv4=ipv4) } - return render_template('panel/_modal.html', modal=modal, net_id=net_id, ipv4=ipv4, old_page=request.args.get('page', type=int), pagination_active=True) + return render_template('panel/_modal.html', modal=modal, net_id=net_id, ipv4=ipv4, old_page=str(request.args.get('page', type=int))+f"#{ipv4}", pagination_active=True) @network.route('//allocations//edit_modal', methods=['GET','POST']) @@ -128,7 +157,7 @@ def allocation_edit_modal(net_id, ipv4): db.session.commit() flash("Allocation Updated", 'success') - return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int))) + return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int),_anchor=request.args.get('item', type=str))) modal = { 'title': 'Update Allocation', @@ -151,7 +180,7 @@ def allocation_edit_modal(net_id, ipv4): form.is_special.default = 2 form.process() - return render_template('panel/_modal.html', modal=modal, form=form, old_page=old_page, pagination_active=True) + return render_template('panel/_modal.html', modal=modal, form=form, old_page=str(old_page)+f"#{ipv4}", pagination_active=True) ## MODIFICATION ROUTES @network.get('//allocations//unallocate') @@ -169,7 +198,7 @@ def allocation_delete(net_id,ipv4): db_alloc.is_decom = False db.session.commit() flash("Allocation Removed", 'warning') - return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int))) + return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int),_anchor=request.args.get('item', type=str))) @network.get('//allocations//decom/') @login_required @@ -183,7 +212,7 @@ def allocation_decom(net_id,ipv4,action): else: db_alloc.is_decom = False db.session.commit() - return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int))) + return redirect(url_for('network.allocations',net_id=net_id,page=request.args.get('page', type=int),_anchor=request.args.get('item', type=str))) @network.get('//delete') @login_required diff --git a/app/static/css/custom.css b/app/static/css/custom.css index 7f9c31d..77ecfb0 100644 --- a/app/static/css/custom.css +++ b/app/static/css/custom.css @@ -6,4 +6,8 @@ pre { margin: 0; padding: 0; +} + +html { + scroll-behavior: auto !important; } \ No newline at end of file diff --git a/app/static/js/custom.js b/app/static/js/custom.js new file mode 100644 index 0000000..8fa6825 --- /dev/null +++ b/app/static/js/custom.js @@ -0,0 +1,27 @@ +if (history.scrollRestoration) { + history.scrollRestoration = 'manual'; +} + +function instantCenter() { + const hash = window.location.hash; + if (!hash) return; + + const targetId = hash.substring(1); + const element = document.getElementById(targetId); + + if (element) { + setTimeout(() => { + const elementRect = element.getBoundingClientRect(); + const absoluteElementTop = elementRect.top + window.scrollY; + + const middle = absoluteElementTop - (window.innerHeight / 2) + (elementRect.height / 2); + + window.scrollTo({ + top: middle, + behavior: 'auto' + }); + }, 0); + } +} + +window.addEventListener('load', instantCenter); \ No newline at end of file diff --git a/app/templates/panel/_footer.html b/app/templates/panel/_footer.html index 5904deb..dd1a63e 100644 --- a/app/templates/panel/_footer.html +++ b/app/templates/panel/_footer.html @@ -1 +1 @@ -
Flask IPAM - 2025 - {{app_version}}
\ No newline at end of file +
Flask IPAM - {{app_version}}
\ No newline at end of file diff --git a/app/templates/panel/_table-alloc.html b/app/templates/panel/_table-alloc.html index 02b1966..8642c9e 100644 --- a/app/templates/panel/_table-alloc.html +++ b/app/templates/panel/_table-alloc.html @@ -1,6 +1,8 @@ {% for allocation in allocations %} +{% if session['hide_dhcp'] and allocation.is_dhcp %} +{% else %} - {{allocation.ipv4}} + {{allocation.ipv4}} {{allocation.hostname}} {{allocation.description}} @@ -26,7 +28,7 @@ {% if allocation.is_used %} {% if allocation.is_decom %} - Undecom + Undecom {% else %} - Decom + Decom {% endif %}