Skip to content

Commit

Permalink
Merge pull request #43 from brianwalborn/feature/40
Browse files Browse the repository at this point in the history
Implement breadcrumb navigation
  • Loading branch information
brianwalborn authored Mar 13, 2022
2 parents f7c34d8 + d075f18 commit 74cbb30
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 15 deletions.
1 change: 1 addition & 0 deletions cloud_browser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ def create_app(test_config = None):
database.init_app(app)

return app

7 changes: 4 additions & 3 deletions cloud_browser/blueprints/autoscaling.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from cloud_browser.blueprints.utils.breadcrumb import Breadcrumb
from cloud_browser.tasks.get_auto_scaling_groups import GetAutoScalingGroups
from flask import Blueprint, flash, render_template
from flask import Blueprint, flash, render_template, request

bp = Blueprint('autoscaling', __name__)

Expand All @@ -14,7 +15,7 @@ def get_life_cycle_hooks():
except Exception as e:
flash(e, 'error')

return render_template('autoscaling/life_cycle_hooks.html', auto_scaling_groups = auto_scaling_groups, service = 'get_life_cycle_hooks')
return render_template('autoscaling/life_cycle_hooks.html', auto_scaling_groups = auto_scaling_groups, breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), service = 'get_life_cycle_hooks')

@bp.route('/autoscaling/get_suspended_processes')
def get_suspended_processes():
Expand All @@ -27,4 +28,4 @@ def get_suspended_processes():
except Exception as e:
flash(e, 'error')

return render_template('autoscaling/suspended_processes.html', auto_scaling_groups = auto_scaling_groups, service = 'get_suspended_processes')
return render_template('autoscaling/suspended_processes.html', auto_scaling_groups = auto_scaling_groups, breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), service = 'get_suspended_processes')
5 changes: 3 additions & 2 deletions cloud_browser/blueprints/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json
import os
from cloud_browser.blueprints.utils.breadcrumb import Breadcrumb
from flask import current_app as app
from flask import Blueprint, render_template
from flask import Blueprint, render_template, request

bp = Blueprint('base', __name__)

Expand All @@ -21,4 +22,4 @@ def load_tasks(service):
for aws_service in services:
if aws_service['name'] == service: tasks = aws_service['tasks']

return render_template('tasks.html', service = service, tasks = tasks)
return render_template('tasks.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), service = service, tasks = tasks)
5 changes: 3 additions & 2 deletions cloud_browser/blueprints/ec2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from cloud_browser.blueprints.utils.breadcrumb import Breadcrumb
from cloud_browser.tasks.generate_conf_cons import GenerateConfCons
from flask import Blueprint, flash, render_template
from flask import Blueprint, flash, render_template, request

bp = Blueprint('ec2', __name__)

Expand All @@ -12,4 +13,4 @@ def generate_conf_cons():
except Exception as e:
flash(e, 'error')

return render_template('ec2/generate_conf_cons.html', service = 'generate_conf_cons', xml = xml)
return render_template('ec2/generate_conf_cons.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), service = 'generate_conf_cons', xml = xml)
5 changes: 3 additions & 2 deletions cloud_browser/blueprints/elb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from cloud_browser.blueprints.utils.breadcrumb import Breadcrumb
from cloud_browser.tasks.load_balancer_health import LoadBalancerHealth
from flask import Blueprint, flash, render_template
from flask import Blueprint, flash, render_template, request

bp = Blueprint('elb', __name__)

Expand All @@ -14,4 +15,4 @@ def get_load_balancer_health():
except Exception as e:
flash(e, 'error')

return render_template('elb/load_balancer_health.html', load_balancers = load_balancers, service = 'get_load_balancer_health')
return render_template('elb/load_balancer_health.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), load_balancers = load_balancers, service = 'get_load_balancer_health')
5 changes: 3 additions & 2 deletions cloud_browser/blueprints/elbv2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from cloud_browser.blueprints.utils.breadcrumb import Breadcrumb
from cloud_browser.tasks.target_group_health import TargetGroupHealth
from flask import Blueprint, flash, render_template
from flask import Blueprint, flash, render_template, request

bp = Blueprint('elbv2', __name__)

Expand All @@ -12,4 +13,4 @@ def get_target_group_health():
except Exception as e:
flash(e, 'error')

return render_template('elbv2/target_group_health.html', target_groups = results, service = 'get_target_group_health')
return render_template('elbv2/target_group_health.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), target_groups = results, service = 'get_target_group_health')
3 changes: 2 additions & 1 deletion cloud_browser/blueprints/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from cloud_browser.blueprints.utils.breadcrumb import Breadcrumb
from cloud_browser.blueprints.utils.validator import Validator
from cloud_browser.database.database import get_database
from flask import Blueprint, flash, render_template, request
Expand Down Expand Up @@ -40,4 +41,4 @@ def index():
tags = database.execute('SELECT * FROM settings_query_tags').fetchall()
tags_to_exclude = database.execute('SELECT * FROM settings_exclude_tags').fetchall()

return render_template('settings.html', invalid_fields = validator.invalid_fields, putty_sessions = putty_sessions, regions = regions, service = 'settings', tags = tags, tags_to_exclude = tags_to_exclude)
return render_template('settings.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), invalid_fields = validator.invalid_fields, putty_sessions = putty_sessions, regions = regions, service = 'settings', tags = tags, tags_to_exclude = tags_to_exclude)
7 changes: 4 additions & 3 deletions cloud_browser/blueprints/ssm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import flask
from cloud_browser.blueprints.utils.breadcrumb import Breadcrumb
from cloud_browser.blueprints.utils.validator import Validator
from cloud_browser.models.aws.ec2.instance import Instance
from cloud_browser.tasks.send_ssm_command import SendSsmCommand
Expand Down Expand Up @@ -44,7 +45,7 @@ def command_input():
except Exception as e:
flash(e, 'error')

return render_template('ssm/send_ssm_command/command_input.html', instances = context.selected_instances, invalid_fields = validator.invalid_fields, operating_systems = operating_systems, service = 'send_ssm_command')
return render_template('ssm/send_ssm_command/command_input.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), instances = context.selected_instances, invalid_fields = validator.invalid_fields, operating_systems = operating_systems, service = 'send_ssm_command')

@bp.route('/ssm/send_ssm_command/command_results')
def command_results():
Expand All @@ -63,7 +64,7 @@ def command_results():

context.clear()

return render_template('ssm/send_ssm_command/command_results.html', results = results, service = 'send_ssm_command')
return render_template('ssm/send_ssm_command/command_results.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), results = results, service = 'send_ssm_command')

@bp.route('/ssm/send_ssm_command')
def redirect():
Expand All @@ -88,4 +89,4 @@ def select_instances():
except Exception as e:
flash(e, 'error')

return render_template('ssm/send_ssm_command/select_instances.html', instances = context.all_instances, service = 'send_ssm_command')
return render_template('ssm/send_ssm_command/select_instances.html', breadcrumbs = Breadcrumb.get_breadcrumbs(request.path), instances = context.all_instances, service = 'send_ssm_command')
19 changes: 19 additions & 0 deletions cloud_browser/blueprints/utils/breadcrumb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Breadcrumb:
def get_breadcrumbs(path: str) -> list[str]:
breadcrumbs: list[Crumb] = []
crumbs: list[str] = path.split('/')

for crumb in crumbs:
if not breadcrumbs:
breadcrumbs.append(Crumb('home', True, '/'))
continue

breadcrumbs.append(Crumb(crumb, crumbs.index(crumb) < len(crumbs) - 1, f'{path.split(crumb)[0]}/{crumb}'.replace('//', '/')))

return breadcrumbs

class Crumb:
def __init__(self, display, enabled, path):
self.display: str = display
self.enabled: bool = enabled
self.path: str = path
7 changes: 7 additions & 0 deletions cloud_browser/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
</div>
{% endfor %}


<ul class="uk-breadcrumb uk-margin-left">
{% for breadcrumb in breadcrumbs %}
<li><a {% if not breadcrumb.enabled %} class="uk-disabled" {% endif %} href="{{ breadcrumb.path }}" onclick="loading()">{{ breadcrumb.display }}</a></li>
{% endfor %}
</ul>

<div id="loader" class="uk-overlay-default uk-position-cover">
<div class="uk-position-center">
<span uk-spinner="ratio: 2"></span>
Expand Down

0 comments on commit 74cbb30

Please sign in to comment.