| @@ -186,5 +186,5 @@ def create_resource(): | |||
| db.session.add(new_reference) | |||
| db.session.commit() | |||
| practice_dropdown = Resource.query.filter_by(type='practice') | |||
| return render_template('create.html', practice_dropdown=practice_dropdown) | |||
| resource_dropdown = Resource.query | |||
| return render_template('create.html', resource_dropdown=resource_dropdown) | |||
| @@ -6,7 +6,6 @@ | |||
| # @author: Simon Bowie <ad7588@coventry.ac.uk> | |||
| # @purpose: JavaScript functions for various functions | |||
| # @acknowledgements: | |||
| # https://stackoverflow.com/questions/67942546/bootstrap-5-select-dropdown-with-the-multiple-attribute-collapsed | |||
| */ | |||
| // Dynamic HTML forms based on dropdown menu | |||
| @@ -9,6 +9,8 @@ | |||
| # https://www.digitalocean.com/community/tutorials/how-to-make-a-web-application-using-flask-in-python-3 | |||
| # Bootstrap 5.1.3: https://getbootstrap.com/ | |||
| # Flask-Moment: https://flask-moment.readthedocs.io/en/latest/ | |||
| # Boostrap select: https://stackoverflow.com/questions/67942546/bootstrap-5-select-dropdown-with-the-multiple-attribute-collapsed | |||
| --> | |||
| <!DOCTYPE html> | |||
| @@ -71,13 +71,14 @@ | |||
| <div class="mb-3 mt-3"> | |||
| <label for="linked_practice_id">Linked resources</label> | |||
| <!--<select class="form-select" aria-label="Linked practices" name="linked_practice_id" multiple="multiple" id="linked_practice_id">--> | |||
| </div> | |||
| <div class="mb-3 mt-3"> | |||
| <select name="linked_resources" id="linked_resources" aria-label="Linked resources" class="selectpicker" data-live-search="true" multiple> | |||
| <optgroup label="Practices"> | |||
| {% for practice_dropdown in practice_dropdown %} | |||
| <option value="{{ practice_dropdown['id'] }}">{{ practice_dropdown['name'] }}</option> | |||
| {% for resource_dropdown in resource_dropdown %} | |||
| {% if resource_dropdown['type'] != 'tool' %} | |||
| <option value="{{ resource_dropdown['id'] }}">{{ resource_dropdown['name'] }}</option> | |||
| {% endif %} | |||
| {% endfor %} | |||
| </optgroup> | |||
| </select> | |||
| </div> | |||
| </div> | |||
| @@ -75,6 +75,19 @@ | |||
| value="{{ request.form['status'] or resource['status'] }}"> | |||
| </input> | |||
| </div> | |||
| <div class="mb-3 mt-3"> | |||
| <label for="linked_practice_id">Linked resources</label> | |||
| </div> | |||
| <div class="mb-3 mt-3"> | |||
| {{ links }} | |||
| <select name="linked_resources" id="linked_resources" aria-label="Linked resources" class="selectpicker" data-live-search="true" multiple> | |||
| {% for resource_dropdown in resource_dropdown %} | |||
| {% if resource_dropdown['type'] != 'tool' %} | |||
| <option value="{{ resource_dropdown['id'] }}">{{ resource_dropdown['name'] }}</option> | |||
| {% endif %} | |||
| {% endfor %} | |||
| </select> | |||
| </div> | |||
| {% endif %} | |||
| <div class="mb-3 mt-3"> | |||
| @@ -33,6 +33,8 @@ def show_tool(tool_id): | |||
| @login_required | |||
| def edit_tool(tool_id): | |||
| tool = get_resource(tool_id) | |||
| resource_dropdown = Resource.query | |||
| links = get_linked_resources(tool_id) | |||
| if request.method == 'POST': | |||
| name = request.form['name'] | |||
| @@ -45,6 +47,7 @@ def edit_tool(tool_id): | |||
| ingestFormats = request.form['ingestFormats'] | |||
| outputFormats = request.form['outputFormats'] | |||
| status = request.form['status'] | |||
| linked_resource = request.form.getlist('linked_resources') | |||
| if not name: | |||
| flash('Name is required!') | |||
| @@ -61,9 +64,18 @@ def edit_tool(tool_id): | |||
| tool.outputFormats = outputFormats | |||
| tool.status = status | |||
| db.session.commit() | |||
| if linked_resource: | |||
| for linked_resource in request.form.getlist('linked_resources'): | |||
| first_resource_id = tool_id | |||
| second_resource_id = linked_resource | |||
| new_relationship = Relationship(first_resource_id=first_resource_id, second_resource_id=second_resource_id) | |||
| # add the new relationship to the database | |||
| db.session.add(new_relationship) | |||
| db.session.commit() | |||
| return redirect(url_for('tool.get_tools')) | |||
| return render_template('edit.html', resource=tool) | |||
| return render_template('edit.html', resource=tool, resource_dropdown=resource_dropdown, links=links) | |||
| # route for function to delete a single tool from the edit page | |||
| @tool.route('/tools/<int:tool_id>/delete', methods=('POST',)) | |||