Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sampletype fix - actually some fixes for storage #93

Merged
merged 26 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cd981c4
Added Delete buttons to the Storage Portal
wiw14 Jul 14, 2021
b568df7
Removed syntax added by Git
wiw14 Jul 15, 2021
869fb15
Added Cancel Buttons to Storage Portal
wiw14 Jul 15, 2021
32dfe33
Added delete-confirmation popup box
wiw14 Jul 15, 2021
670b2ae
Added validation to prevent deleting with assigned samples
wiw14 Jul 16, 2021
f94957f
Started implementation of edit site page
wiw14 Jul 16, 2021
b55a9b2
Added validation for delete buttons
wiw14 Jul 16, 2021
07756fd
Add function to the lock button within the storage portal
wiw14 Jul 19, 2021
889a6ff
Code reformatting
wiw14 Jul 19, 2021
e92eca4
Merge branch 'dev' into af-wiw14
wiw14 Jul 19, 2021
e991703
Update view.html
wiw14 Jul 19, 2021
3f1ab0b
Added validation for locking
wiw14 Jul 20, 2021
3014305
Locking cold storage locks both shelf and rack
wiw14 Jul 20, 2021
9200dc9
Storage Portal Modal Aesthetic Update
wiw14 Jul 20, 2021
92e3ef1
include select.dataTables.min.css in template.html
pipaLU Jul 20, 2021
937eb9b
update datatables.net-select to v1.3.3
pipaLU Jul 20, 2021
afd6a93
Fixed minor bugs related to delete function
wiw14 Jul 21, 2021
5d51174
Fixed issue with deleting rack with no associations
wiw14 Jul 21, 2021
02b2731
func name in rack api
pipaLU Jul 21, 2021
d9e49fb
fix sampletype display for molecular in rack view
pipaLU Jul 21, 2021
272f001
Merge branch 'af-wiw14' of https://github.com/AberystwythSystemsBiolo…
pipaLU Jul 21, 2021
c50322c
Minor changes to storage_transfer_rack_to_shelf
wiw14 Jul 22, 2021
6b72811
fix rack editing with location afer merging af-wiw4
pipaLU Jul 22, 2021
2317a78
Merge branch 'af-wiw14' of https://github.com/AberystwythSystemsBiolo…
pipaLU Jul 22, 2021
fcaa736
fix api for sample/rack-to-shelf (only keep the current location in e…
pipaLU Jul 22, 2021
ed239b2
DOID_PATH in .env.example
pipaLU Jul 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ ONTOLOGY_DIRECTORY=/limbus/ontologies/
DEBUG=True
LC_ALL=C.UTF-8
LANG=C.UTF-8
DOID_PATH=https://users.aber.ac.uk/keo7/doid.xrdf
## DOID_PATH=https://users.aber.ac.uk/keo7/doid.xrdf
DOID_PATH=/limbus/ontologies/doid.xrdf ## https://www.dropbox.com/s/1v3b69iw7o1nibs/doid.xrdf
Empty file added services/web/__init__.py
Empty file.
1 change: 1 addition & 0 deletions services/web/app/admin/routes/sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def sites_new_site():
"street_address_one": form.address_line_one.data,
"street_address_two": form.address_line_two.data,
"city": form.city.data,
"county": form.county.data,
"country": form.country.data,
"post_code": form.post_code.data,
}
Expand Down
6 changes: 2 additions & 4 deletions services/web/app/api/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,18 @@ def generic_lock(
view_schema: masql.SQLAlchemySchema,
tokenuser: UserAccount,
):
existing = Model.query.filter_by(id=id).first()
existing = model.query.filter_by(id=id).first()

if not existing:
return not_found()

existing.is_locked = not existing.is_locked
existing.editor_id = tokenuser.id

db.session.add(existing)
db.session.commit()
db.session.flush()

return success_with_content_response(view_schema.dump(existing))
return success_with_content_response(existing.is_locked)


def generic_edit(
Expand Down Expand Up @@ -128,4 +127,3 @@ def generic_delete(

#return success_with_content_response()
return success_without_content_response()

23 changes: 18 additions & 5 deletions services/web/app/api/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,32 @@ def not_found():
{"ContentType": "application/json"},
)

def locked():
return (
{"success": False, "message": "Data locked"},
404,
{"ContentType": "application/json"},
def sample_assigned_delete_response():
return(
{"success": False, "message":"Can't delete assigned samples"},
400,
{"ContentType":"application/json"}
)

def in_use_response(entity):
return(
{"success": False, "message":"Has associated " + entity},
400,
{"ContentType":"application/json"}
)

def no_values_response():
return (
{"success": False, "message": "No input data provided"},
400,
{"ContentType": "application/json"},
)

def locked_response():
return({"success": False, "message": "Entity is locked"},
400,
{"ContentType": "application/json"})


def invalid_query_response():
return (
Expand Down
9 changes: 9 additions & 0 deletions services/web/app/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ def decorated_function(*args, **kwargs):

return decorated_function

def check_if_locked(model):
def inner(f):
def wrapper(*args,**kwargs):
if(model.query.filter_by(id=kwargs["id"]).is_locked):
return abort(401)
return f(*args,**kwargs)
return wrapper
return inner


def requires_access_level(f):
@wraps(f)
Expand Down
1 change: 1 addition & 0 deletions services/web/app/misc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SiteInformation(Base, RefAuthorMixin):
miabis_id = db.Column(db.String(128))
acronym = db.Column(db.String(64))
name = db.Column(db.String(128))
is_locked = db.Column(db.Boolean,default=False)
description = db.Column(db.String(128))
url = db.Column(db.String(128))
address_id = db.Column(db.Integer, db.ForeignKey("address.id"), nullable=False)
Expand Down
28 changes: 28 additions & 0 deletions services/web/app/static/css/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,34 @@ nav img {
color: #000;
}

.btn-cancel {
background-color: #eb4034;
color: #ffffff;
margin-right:0.5em;
}

.btn-cancel:hover {
background-color:#a62b23;
color: #ffffff;
}

.btn-delete{
background-color: #ffffff;
color: #eb4034;
border: 1px #eb4034 solid;
}



.btn-form{
background-color: #007bff;
color:white
}
.btn-form:hover{
background-color: #0062cc;
color: white;
}

#wmd-preview {
background-color: #f5f5f5;
padding:1em;
Expand Down
1 change: 1 addition & 0 deletions services/web/app/static/css/select.dataTables.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 27 additions & 2 deletions services/web/app/static/css/storage/navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
overflow: auto;
top: 30px;
left: 0;
z-index: 998;
z-index: 997;
transition: all 0.3s;
}

Expand All @@ -23,7 +23,7 @@
#sidebar-collapse {
float: right;
margin: 0;
z-index: 999;
z-index: 998;
position: relative;
margin-top: 50%;
right: -1em;
Expand All @@ -36,4 +36,29 @@

#sidebar.active #sidebar-collapse {
right: -3em;
}

/* The Modal (background) */
.modal-delete {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 999; /* Sit on top */
left: 0;
top: 15%;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
/*background-color: #474e5d;*/
padding-top: 50px;
}

/* Modal Content/Box */
.modal-delete-content {
color:black;
background-color: #fefefe;
margin: 5% auto 15% auto; /* 5% from the top, 15% from the bottom and centered */
border: 2px solid #000;
border-radius: 0;
width: 70%; /* Could be more or less, depending on screen size */
height: fit-content;
}
26 changes: 26 additions & 0 deletions services/web/app/static/js/storage/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright (C) 2020 Keiron O'Shea <keo7@aber.ac.uk>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

// Get the modal
var modal = document.getElementById('delete-confirmation');

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target === modal) {
modal.style.display = "none";
}
}
1 change: 1 addition & 0 deletions services/web/app/static/js/storage/navtree.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/


function sap2tree(sap) {
var sites = sap["content"];

Expand Down
2 changes: 1 addition & 1 deletion services/web/app/static/js/storage/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function get_panel_information() {

function render_counts(basic_statistics) {
$("#site_count").html(basic_statistics["site_count"]);
$("#room_count").html(basic_statistics["site_count"]);
$("#room_count").html(basic_statistics["room_count"]);
$("#building_count").html(basic_statistics["building_count"]);
$("#cold_storage_count").html(basic_statistics["cold_storage_count"]);

Expand Down
7 changes: 5 additions & 2 deletions services/web/app/static/js/storage/rack/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,12 @@ function render_sample_table(samples) {
return sample_type_information["fluid_type"];
}
else if (data["sample"]["base_type"] == "Cellular") {
return sample_type_information["cellular_type"] + " > " + sample_type_information["tiss_type"];
return sample_type_information["cellular_type"]; // + " > " + sample_type_information["tissue_type"];
}

else if (data["sample"]["base_type"] == "Molecular") {
return sample_type_information["molecular_type"]; // + " > " + sample_type_information["tissue_type"];
}


}
},
Expand Down
60 changes: 55 additions & 5 deletions services/web/app/storage/api/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from flask import request, current_app, jsonify, send_file
from flask import request, current_app, jsonify, send_file,url_for

from ...api import api
from ...api.responses import *
from ...api.filters import generate_base_query_filters, get_filters_and_joins
from ...decorators import token_required
from ...decorators import token_required,check_if_locked
from ...webarg_parser import use_args, use_kwargs, parser
from ...database import db, Building, UserAccount
from ...database import db, Building, UserAccount,Room
from ..api.room import func_room_delete


import requests
from ...misc import get_internal_api_header



from marshmallow import ValidationError
Expand Down Expand Up @@ -93,11 +99,53 @@ def storage_lock_building(id: int, tokenuser: UserAccount):
building.is_locked = not building.is_locked
building.editor_id = tokenuser.id

db.session.add(building)
db.session.commit()
db.session.flush()

return success_with_content_response(basic_building_schema.dump(building))
return success_with_content_response(building.is_locked)


@api.route("/storage/building/LIMBBUILD-<id>/delete", methods=["PUT"])
@token_required
def storage_building_delete(id, tokenuser: UserAccount):
existing = Building.query.filter_by(id=id).first()

if not existing:
return not_found()

if existing.is_locked:
return locked_response()

existing.editor_id = tokenuser.id

code = delete_buildings_func(existing)

siteID = existing.site_id

if code == "success":
return success_with_content_response(siteID)
elif code == "cold storage":
return in_use_response(code)
elif code == "locked":
return locked_response()
else:
return no_values_response()

def delete_buildings_func(record):
attachedRooms = Room.query.filter(Room.building_id == record.id).all()
for rooms in attachedRooms:
code = func_room_delete(rooms)
if code == "cold storage":
return "cold storage"
elif code == "locked" or record.is_locked:
return "locked"

try:
db.session.delete(record)
db.session.commit()
return "success"
except Exception as err:
return transaction_error_response(err)


@api.route("/storage/building/LIMBBUILD-<id>/edit", methods=["PUT"])
Expand All @@ -108,6 +156,8 @@ def storage_edit_building(id: int, tokenuser: UserAccount):

if not building:
return not_found()
if building.is_locked:
return not_allowed()

values = request.get_json()

Expand Down
Loading