Commit 3b6d3d4e authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

WebUI component:

- Link detail: added delete button
parent e669847a
Loading
Loading
Loading
Loading
+24 −2
Original line number Original line Diff line number Diff line
@@ -13,8 +13,8 @@
# limitations under the License.
# limitations under the License.




from flask import render_template, Blueprint, flash, session, redirect, url_for
from flask import current_app, render_template, Blueprint, flash, session, redirect, url_for
from common.proto.context_pb2 import Empty, Link, LinkList
from common.proto.context_pb2 import Empty, Link, LinkId, LinkList
from common.tools.context_queries.EndPoint import get_endpoint_names
from common.tools.context_queries.EndPoint import get_endpoint_names
from common.tools.context_queries.Link import get_link
from common.tools.context_queries.Link import get_link
from common.tools.context_queries.Topology import get_topology
from common.tools.context_queries.Topology import get_topology
@@ -65,3 +65,25 @@ def detail(link_uuid: str):
        device_names, endpoints_data = get_endpoint_names(context_client, link_obj.link_endpoint_ids)
        device_names, endpoints_data = get_endpoint_names(context_client, link_obj.link_endpoint_ids)
    context_client.close()
    context_client.close()
    return render_template('link/detail.html',link=link_obj, device_names=device_names, endpoints_data=endpoints_data)
    return render_template('link/detail.html',link=link_obj, device_names=device_names, endpoints_data=endpoints_data)

@link.get('<path:link_uuid>/delete')
def delete(link_uuid):
    try:

        # first, check if link exists!
        # request: LinkId = LinkId()
        # request.link_uuid.uuid = link_uuid
        # response: Link = client.GetLink(request)
        # TODO: finalize implementation

        request = LinkId()
        request.link_uuid.uuid = link_uuid # pylint: disable=no-member
        context_client.connect()
        context_client.RemoveLink(request)
        context_client.close()

        flash(f'Link "{link_uuid}" deleted successfully!', 'success')
    except Exception as e: # pylint: disable=broad-except
        flash(f'Problem deleting link "{link_uuid}": {e.details()}', 'danger')
        current_app.logger.exception(e)
    return redirect(url_for('link.home'))
+85 −55
Original line number Original line Diff line number Diff line
@@ -13,6 +13,7 @@
    See the License for the specific language governing permissions and
    See the License for the specific language governing permissions and
    limitations under the License.
    limitations under the License.
   -->
   -->

{% extends 'base.html' %}
{% extends 'base.html' %}


{% block content %}
{% block content %}
@@ -24,6 +25,13 @@
            Back to link list
            Back to link list
        </button>
        </button>
    </div>
    </div>
    <div class="col-sm-3">
        <!-- <button type="button" class="btn btn-danger"><i class="bi bi-x-square"></i>Delete link</button> -->
        <button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal">
            <i class="bi bi-x-square"></i>
            Delete link
        </button>
    </div>
</div>
</div>


<br>
<br>
@@ -70,5 +78,27 @@
    </div>
    </div>
</div>
</div>


   {% endblock %}


<!-- Modal -->
<div class="modal fade" id="deleteModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
    aria-labelledby="staticBackdropLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="staticBackdropLabel">Delete link?</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                Are you sure you want to delete the link "{{ link.link_id.link_uuid.uuid }}"?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">No</button>
                <a type="button" class="btn btn-danger"
                    href="{{ url_for('link.delete', link_uuid=link.link_id.link_uuid.uuid) }}"><i
                        class="bi bi-exclamation-diamond"></i>Yes</a>
            </div>
        </div>
    </div>
</div>

{% endblock %}