#139 Add the code/logic to remove a widget from a hub
Merged 7 years ago by pingou. Opened 8 years ago by pingou.
pingou/fedora-hubs delete_widget  into  develop

file modified
+16 -2
@@ -156,8 +156,6 @@ 

  @app.route('/<hub>/<idx>/edit', methods=['GET'])

  def widget_edit_get(hub, idx):

      widget = get_widget(session, hub, idx)

-     if not widget.module.data.widget_arguments:

-         flask.abort(404, 'Nothing to configure for this hub.')

      return flask.render_template(

          'edit.html',

          hub=hub,
@@ -201,6 +199,22 @@ 

      return flask.redirect(flask.url_for('hub', name=hub))

  

  

+ @app.route('/<hub>/<idx>/delete/', methods=['POST'])

+ @app.route('/<hub>/<idx>/delete', methods=['POST'])

+ def widget_edit_delete(hub, idx):

+     ''' Remove a widget from a hub. '''

+     widget = get_widget(session, hub, idx)

+     session.delete(widget)

+     try:

+         session.commit()

+     except Exception as err:

+         flask.flash(

+             'Could not delete this widget from this hub in the database '\

+             'if the error persists, please warn an admin',

+             'error')

+     return flask.redirect(flask.url_for('hub', name=hub))

+ 

+ 

  @app.route('/source/<name>/')

  @app.route('/source/<name>')

  def widget_source(name):

@@ -385,3 +385,12 @@ 

      color: #a07cbc;

  }

  

+ .modal-footer button {

+   float: right;

+   margin-left: 1em;

+ }

+ 

+ .p-abs {

+   position: absolute;

+   bottom: 0;

+ }

file modified
+20 -7
@@ -1,13 +1,14 @@ 

  

  <div class="modal-dialog" id="edit_form">

-   <form method="post" action="{{ url_to }}">

+   <div class="modal-content">

+     <form method="post" action="{{ url_to }}">

      <!-- Modal content-->

-     <div class="modal-content">

        <div class="modal-header">

          <button type="button" class="close" data-dismiss="modal">&times;</button>

          <h4 class="modal-title">Configure {{ name }}</h4>

        </div>

        <div class="modal-body">

+       {% if widget.module.data.widget_arguments %}

          {% for arg in widget.module.data.widget_arguments %}

            <fieldset class="form-group ">

              <strong>{{ arg.name | capitalize }}</strong>
@@ -21,15 +22,27 @@ 

              </div>

            {% endif %}

          {% endfor %}

+       {% else %}

+         <p>Nothing to configure</p>

+       {% endif %}

        </div>

        <div class="modal-footer">

-         <button type="submit" class="btn btn-default">

-           Save

-         </button>

          <button type="button" class="btn btn-default" data-dismiss="modal">

            Close

          </button>

+         {% if widget.module.data.widget_arguments %}

+         <button type="submit" class="btn btn-default">

+           Save

+         </button>

+         {% endif %}

        </div>

-     </div>

-   </form>

+     </form>

+     <form method="POST" action="{{ url_for(

+         'widget_edit_delete', hub=widget.hub.name, idx=widget.idx) }}"

+         class="modal-footer p-abs" >

+         <button type="submit" class="btn btn-danger" id="delete_widget">

+           Remove this widget

+         </button>

+     <form>

+   </div>

  </div>

file modified
+12 -8
@@ -1,11 +1,12 @@ 

- <html>

+ <!DOCTYPE html>

+ <html lang='en'>

  <head>

    <title>{{ hub.name }}</title>

    <link href="{{ url_for('static', filename='bootstrap/css/bootstrap.css') }}" rel="stylesheet" />

    <link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet" />

    <link href="{{ url_for('static', filename='css/pace-theme-minimal.css') }}" rel="stylesheet" />

+   <script type="text/javascript"  src="{{ url_for('static', filename='js/pace.min.js') }}"></script>

  </head>

- <script src="{{ url_for('static', filename='js/pace.min.js') }}"></script>

  <body>

  <div class="super-header">

    <div class="row">
@@ -37,7 +38,7 @@ 

      <div class="col-sm-4 col-sm-pull-4 col-xs-12">

        <!-- NOT HOOKED UP TO ANYTHING XOXO -->

        <div class="input-group">

-         <input type="search" placeholder="Search across all hubs ..."></input>

+         <input type="search" placeholder="Search across all hubs ..." />

          <span class="input-group-addon">

            <span class="glyphicon glyphicon-search"></span>

          </span>
@@ -207,9 +208,12 @@ 

    </div>

  </div>

  

- <script src="{{ url_for('static', filename='js/jquery-1.10.2.min.js') }}"></script>

- <script src="{{ url_for('static', filename='bootstrap/js/bootstrap.min.js') }}"></script>

- <script src="{{ url_for('static', filename='js/utils.js') }}"></script>

+ <script type="text/javascript" src="{{

+   url_for('static', filename='js/jquery-1.10.2.min.js') }}"></script>

+ <script type="text/javascript" src="{{

+   url_for('static', filename='bootstrap/js/bootstrap.min.js') }}"></script>

+ <script type="text/javascript" src="{{

+   url_for('static', filename='js/utils.js') }}"></script>

  <script type="text/javascript">

  function setup_edit_btns() {

    $(".edit_widget").unbind();
@@ -260,6 +264,6 @@ 

    setup_edit_btns();

  });

  

- 

  </script>

- </body></html>

+ </body>

+ </html>

file modified
+1 -1
@@ -50,7 +50,7 @@ 

                  'widget_render', hub=widget.hub.name, idx=widget.idx)

              result['edit_url'] = flask.url_for(

                  'widget_edit_get', hub=widget.hub.name, idx=widget.idx)

-             result['widget_idx'] = widget.idx

+             result['widget'] = widget

              return result

  

          return inner

@@ -5,10 +5,9 @@ 

      <a href="{{ source_url }}"><span class="glyphicon glyphicon-eye-open"></span></a>

      <a href="{{ widget_url }}"><span class="glyphicon glyphicon-new-window"></span></a>

      <a data-target="#edit_modal" data-toggle="modal" type="button"

-         class="edit_widget" data-idx="{{ widget_idx }}">

+         class="edit_widget" data-idx="{{ widget.idx }}">

        <span class="glyphicon glyphicon-edit"></span>

      </a>

-     </a>

    </div>

    <div class="panel-body">

      {{ content }}

no initial comment

Pull-Request has been updated

8 years ago

We can have a float-left and a float-right class and reuse it.

No I had to have it below for the delete button to appear on the same row

hm I've been trying to use these two classes but it didn't appear as I want them to be :-(

Pull-Request has been rebased

7 years ago

Pull-Request has been updated

7 years ago

Pull-Request has been merged by pingou

7 years ago