Skip to content

Commit 965f1e9

Browse files
committed
Going to use tags from graph json only
1 parent 1295505 commit 965f1e9

File tree

7 files changed

+106
-17
lines changed

7 files changed

+106
-17
lines changed

applications/graphs/controllers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,15 @@ def is_user_authorized_to_view_graph(request, username, graph_id):
5959

6060
def is_user_authorized_to_update_graph(request, username, graph_id):
6161
is_authorized = False
62+
user = users.controllers.get_user(request, username)
6263

6364
graph = db.get_graph_by_id(request.db_session, graph_id)
6465

6566
if graph is not None: # Graph exists
6667
if graph.owner_email == username:
6768
is_authorized = True
69+
elif user is not None and user.is_admin == 1:
70+
is_authorized = True
6871

6972
return is_authorized
7073

applications/graphs/dal.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ def find_graphs(db_session, owner_email=None, group_ids=None, graph_ids=None, is
162162
names = [] if names is None else names
163163
tags = [] if tags is None else tags
164164

165-
166165
elements_filter = []
167166
names_filter = []
168167

applications/graphs/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def serialize(cls):
5353
'graph_json': json.loads(cls.graph_json),
5454
'style_json': json.loads(cls.style_json),
5555
'is_public': cls.is_public,
56-
'tags': [tag.serialize() for tag in cls.tags],
56+
'tags': [tag.name for tag in cls.tags],
5757
'default_layout_id': cls.default_layout_id,
5858
'created_at': cls.created_at.isoformat(),
5959
'updated_at': cls.updated_at.isoformat()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""add more network attributes
2+
3+
Revision ID: 755438125e7d
4+
Revises: 97a32c589371
5+
Create Date: 2017-04-12 23:55:47.368030
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
import json
12+
from graphspace_python.graphs.classes.gsgraph import GSGraph
13+
from graphspace_python.graphs.formatter.json_formatter import CyJSFormat
14+
from graphspace_python.api.client import GraphSpace
15+
16+
# revision identifiers, used by Alembic.
17+
revision = '755438125e7d'
18+
down_revision = '97a32c589371'
19+
branch_labels = None
20+
depends_on = None
21+
22+
23+
def upgrade():
24+
graphspace = GraphSpace('adb@vt.edu', 'XXXX')
25+
graphspace.set_api_host('localhost:8000')
26+
response = graphspace.get_public_graphs(limit=70)
27+
for graph in response['graphs']:
28+
graph_json = graph['graph_json']
29+
G = CyJSFormat.create_gsgraph(json.dumps(graph['graph_json']))
30+
tags = list(set(G.get_tags()) | set(graph['tags']))
31+
G.set_tags(tags)
32+
33+
if '2015-bioinformatics-xtalk' in tags:
34+
G.set_data({
35+
'pubmed': '26400040',
36+
'pubmed_title': 'Xtalk: a path-based approach for identifying crosstalk between signaling pathways.',
37+
'pubmed_authors': ['Allison N. Tegge', 'Nicholas Sharp', 'T. M. Murali']
38+
})
39+
elif '2013-jcb-linker' in tags:
40+
G.set_data({
41+
'pubmed': '23641868',
42+
'pubmed_title': 'Top-down network analysis to drive bottom-up modeling of physiological processes.',
43+
'organism': 'Saccharomyces cerevisiae',
44+
'taxon_id': '559292',
45+
'pubmed_authors': ['Christopher L. Poirel', 'Richard R. Rodrigues','Katherine C. Chen','John J. Tyson','T.M. Murali']
46+
})
47+
print(graph['id'])
48+
response = graphspace.update_graph(graph['name'], owner_email=graph['owner_email'], graph=G, is_public=graph['is_public'])
49+
raise
50+
51+
52+
def downgrade():
53+
pass

static/js/graphs_page.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,12 @@ var graphsPage = {
205205
},
206206
tagsFormatter: function (value, row) {
207207
links = "";
208-
for (i in row.tags) {
209-
links += $('<a>').attr('href', '#').html($('<span>').attr('class', 'label label-info tag-btn').attr('onclick', 'graphsPage.graphsTable.searchTag(this);').text(row.tags[i].name)[0])[0].outerHTML + '&nbsp;';
208+
if ('data' in row.graph_json && 'tags' in row.graph_json.data) {
209+
links = _.map(row.graph_json.data.tags, function(tag){
210+
return $('<a>').attr('href', '#').html($('<span>').attr('class', 'label label-info tag-btn').attr('onclick', 'graphsPage.graphsTable.searchTag(this);').text(tag)[0])[0].outerHTML + '&nbsp;';
211+
});
210212
}
211-
return links
213+
return links.join('');
212214
},
213215
ownerEmailFormatter: function (value, row) {
214216
if (_.startsWith(row.owner_email, 'public_user_')) {
@@ -2110,7 +2112,7 @@ var cytoscapeGraph = {
21102112
getStylesheet: function (cy) {
21112113
/*
21122114
* gets stylesheet for the graph.
2113-
*
2115+
*
21142116
* cy: cytoscape graph object
21152117
*/
21162118
var selectedElementStyleAttributes = ['overlay-opacity', 'overlay-color', 'overlay-padding'];
@@ -2133,13 +2135,13 @@ var cytoscapeGraph = {
21332135

21342136
if (format === 'jpg') {
21352137
var b64key = 'base64,';
2136-
var b64 = cy.jpg({'full': true}).substring( cy.jpg({'full': true}).indexOf(b64key) + b64key.length );
2137-
blob = utils.base64ToBlob( b64, 'image/jpeg' );
2138+
var b64 = cy.jpg({'full': true}).substring(cy.jpg({'full': true}).indexOf(b64key) + b64key.length);
2139+
blob = utils.base64ToBlob(b64, 'image/jpeg');
21382140
fileformat = '.jpg';
21392141
} else if (format === 'png') {
21402142
var b64key = 'base64,';
2141-
var b64 = cy.png({'full': true}).substring( cy.png({'full': true}).indexOf(b64key) + b64key.length );
2142-
blob = utils.base64ToBlob( b64, 'image/png' );
2143+
var b64 = cy.png({'full': true}).substring(cy.png({'full': true}).indexOf(b64key) + b64key.length);
2144+
blob = utils.base64ToBlob(b64, 'image/png');
21432145
fileformat = '.png';
21442146
} else if (format === 'cyjs') {
21452147
MIME_TYPE = "application/json";
Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
<div class="margin-top-4">
2-
<table>
3-
{{ description|safe }}
4-
</table>
2+
<style>
3+
img {
4+
max-width: 200px;
5+
}
6+
</style>
7+
<div class="row">
8+
<div class="col-md-6">
9+
<table>
10+
{{ description|safe }}
11+
</table>
12+
</div>
13+
<div class="col-md-6">
14+
<div class="table-responsive">
15+
<table class="table table-bordered">
16+
<tr>
17+
<th>Attribute</th>
18+
<th>Value</th>
19+
</tr>
20+
{% if 'data' in graph.graph_json %}
21+
{% for k,v in graph.graph_json.data.items %}
22+
{% if k != 'description' %}
23+
<tr>
24+
<td>{{ k|safe}}</td>
25+
<td>{{ v|safe }}</td>
26+
</tr>
27+
{% endif %}
28+
{% endfor %}
29+
{% endif %}
30+
31+
32+
</table>
33+
</div>
34+
</div>
35+
</div>
36+
537
</div>

templates/graph/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ <h4 class="zero-margin d-inline-block">
130130
{% endif %}
131131
</small>
132132
</h4>
133-
{% if graph.tags %}
133+
{% if 'data' in graph.graph_json and 'tags' in graph.graph_json.data%}
134134
<div class="tag-cloud d-inline-block" id="Tags" >
135-
{% for tag in graph.tags %}
135+
{% for tag in graph.graph_json.data.tags %}
136136
<a class="tag-anchor"
137-
href="{% url 'graphs' %}?tags={{ tag.name | slugify }}">
138-
<i class="fa fa-hashtag"></i> {{ tag.name }}
137+
href="{% url 'graphs' %}?tags={{ tag | slugify }}">
138+
<i class="fa fa-hashtag"></i> {{ tag }}
139139
</a>
140140
{% endfor %}
141141
</div>

0 commit comments

Comments
 (0)