Skip to content

Commit 3fd2f1a

Browse files
committed
update docker files
1 parent 3977a9a commit 3fd2f1a

13 files changed

+930
-377
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
*.pyc
22
*~
3+
recastfrontend/*.yaml
34
recastfrontend/*.pyc
45
recastfrontend/*~
56
recastfrontend/templates/*~

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,18 @@ deploying on Heroku
4646
git commit -m 'bla'
4747
git push heroku master
4848

49+
50+
##Docker instructions
51+
52+
docker-compose build
53+
docker-compose up -d
54+
55+
create database
56+
57+
docker-compose run recastfrontend recast-frontend-admin create_db
58+
59+
fill database with dummy data
60+
61+
docker-compose run recastfrontend recast-frontend fill_db
62+
63+

docker-compose.yml

+30-18
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,46 @@ recastfrontend:
22
build: .
33
ports:
44
- "5000:5000"
5+
environment:
6+
- RECAST_DBPATH=postgresql://postgres:postgres@postgres:5432/postgres
57
volumes:
68
- ./recastfrontend:/recast-newfrontend/recastfrontend
79
- ./config.yaml:/recast-newfrontend/recastfrontend/resources/defaultconfig.yaml
810
links:
9-
- db
10-
- cache
11-
- celery
12-
13-
db:
14-
image: postgres
15-
16-
celery:
17-
image: celery
18-
19-
cache:
20-
image: redis
21-
ports:
22-
- "6379:6379"
11+
- postgres
12+
- redis
13+
- api
2314

2415
api:
2516
image: cbora/recastrestapi:0.1
2617
volumes:
2718
- ./config.yaml:/recast-rest-api/recastrestapi/resources/defaultconfig.yaml
2819
ports:
2920
- "6000:5000"
30-
31-
es:
32-
image: elasticsearch
21+
links:
22+
- postgres
23+
24+
data:
25+
image: postgres:latest
26+
volumes:
27+
- /var/lib/postgresql
28+
command: "true"
29+
30+
postgres:
31+
restart: always
32+
image: postgres:latest
33+
volumes_from:
34+
- data
3335
ports:
34-
- "9200:9200"
36+
- "5432:5432"
37+
redis:
38+
restart: always
39+
image: redis:latest
40+
ports:
41+
- "6379:6379"
42+
43+
#es:
44+
# image: elasticsearch
45+
# ports:
46+
# - "9200:9200"
3547

recastfrontend/frontendconfig.py

+10
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@
55
def default_config():
66
return yaml.load(open(pkg_resources.resource_filename('recastfrontend','resources/defaultconfig.yaml')))
77

8+
def update_config(config):
9+
#if we are runnning inside a container
10+
if os.environ.has_key('REDIS_PORT'):
11+
os.environ['RECAST_REDISURL'] = os.environ['REDIS_PORT'].replace('tcp', 'redis')
12+
#update config with ENV variables that have RECAST_*
13+
for k, v in os.environ.iteritems():
14+
if k.startswith('RECAST_'):
15+
config.update({k.replace('RECAST_',''): v})
16+
return config
817

918
def mk_config():
1019
the_config = default_config()
20+
the_config = update_config(the_config)
1121
if os.environ.has_key('RECASTCONTROLCENTER_CONFIG'):
1222
custom_config = yaml.load(open(os.environ['RECASTCONTROLCENTER_CONFIG']))
1323
the_config.update(**custom_config)

recastfrontend/populate_db.py

+387-61
Large diffs are not rendered by default.

recastfrontend/server.py

+51-30
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import asynctasks
77
import synctasks
88

9-
from flask import Flask, redirect, jsonify, session, request, url_for, render_template, flash
9+
from flask import Flask, redirect, jsonify, session
10+
from flask import request, url_for, render_template, flash
1011
from flask.ext import login as login
1112
from frontendconfig import config as frontendconf
1213
from recastdb.database import db
@@ -690,6 +691,9 @@ def rows_to_dict(rows):
690691
def arxiv():
691692
if request.args.has_key('id'):
692693
arxiv_id = request.args.get('id')
694+
else:
695+
#No id found return an error
696+
return
693697
print arxiv_id
694698
fields = "title,author,doi,abstract,corporate_name"
695699
url = "https://inspirehep.net/search?p={}&of=recjson&ot={}".format(arxiv_id,fields)
@@ -698,23 +702,33 @@ def arxiv():
698702

699703
if not response.content or len(response.json()) > 1 or len(response.json()) == 0:
700704
"""No record found"""
701-
return "{}"
705+
return
702706
if len(response.json()) > 1:
703707
"""More than one record found"""
704-
return "{N}"
708+
return
705709

706-
ret = response.json()[0]
707-
ret = json.dumps(ret)
708-
return ret
710+
result = response.json()[0]
711+
712+
data = {}
713+
data['title'] = result['title']['title'] or None
714+
data['collaboration'] = result['corporate_name'][0]['collaboration'] or None
715+
data['doi'] = result['doi'][0] or None
716+
data['description'] = result['abstract'][1]['summary']
717+
return jsonify(data)
709718

710719
@app.route("/add-parameter/<int:request_id>", methods=['GET', 'POST'])
720+
@login.login_required
711721
def add_parameter_point(request_id):
712-
coordinate = request.form['value']
713-
coordinate_name = request.form['name']
714-
zip_file = request.files['file']
715722

716-
request_query = db.session.query(dbmodels.ScanRequest).filter(
717-
dbmodels.ScanRequest.id == request_id).one()
723+
request_query = db.session.query(dbmodels.ScanRequest).filter(dbmodels.ScanRequest.id == request_id).one()
724+
725+
zenodo_deposition_id = request_query.zenodo_deposition_id
726+
727+
point_request_id = synctasks.createPointRequest(app,
728+
request_id,
729+
login.current_user
730+
)
731+
zip_file = request.files['file']
718732

719733
file_uuid = str(uuid.uuid1())
720734
zip_file.save(zip_file.filename)
@@ -726,54 +740,61 @@ def add_parameter_point(request_id):
726740
file_uuid)
727741

728742
deposition_file_id = synctasks.uploadToZenodo(ZENODO_ACCESS_TOKEN,
729-
request_query.zenodo_deposition_id,
743+
zenodo_deposition_id,
730744
file_uuid,
731745
zip_file)
732746

733-
point_request_id = synctasks.createPointRequest(app,
734-
request_id,
735-
login.current_user
736-
)
737-
738-
synctasks.createPointCoordinate(app,
739-
login.current_user,
740-
coordinate_name,
741-
coordinate,
742-
point_request_id
743-
)
744-
745747
synctasks.createRequestArchive(app,
746748
login.current_user,
747749
point_request_id,
748750
file_uuid,
749751
deposition_file_id,
750752
zip_file.filename)
751-
return ""
752-
753753

754+
for k in request.form:
755+
coordinate = json.loads(request.form[k])
756+
if k == 'file':
757+
continue
758+
759+
if coordinate.has_key('value'):
760+
value = coordinate['value']
761+
name = None
762+
if coordinate.has_key('name'):
763+
name = coordinate['name']
764+
765+
synctasks.createPointCoordinate(app,
766+
login.current_user,
767+
name,
768+
float(value),
769+
point_request_id
770+
)
771+
response = {}
772+
response['success'] = True
773+
return jsonify(response)
754774

755775
@app.route("/add-coordinate", methods=['GET', 'POST'])
756776
@app.route("/add-coordinate/<int:point_request_id>", methods=['GET', 'POST'])
757777
def add_coordinate(point_request_id):
778+
758779
if request.method == 'POST':
759780

760781
point_request_query = db.session.query(dbmodels.PointRequest).filter(
761782
dbmodels.PointRequest.id == point_request_id).one()
762783

763-
764784
data = json.loads(request.data.decode())
765785
coordinate = data['value']
766786
coordinate_name = data['name']
767787
point_coordinate_id = synctasks.createPointCoordinate(app,
768788
login.current_user,
769789
coordinate_name,
770790
coordinate,
771-
point_request_query.id)
791+
point_request_query.id
792+
)
772793
#return point_coordinate_id
773-
return ""
774794

775795
return ""
776-
796+
797+
777798
@app.route("/analysis-number")
778799
def analysis_number():
779800
analyses = db.session.query(dbmodels.Analysis).all()

recastfrontend/static/recast.js

+77-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//angular App
44
angular.module('recastApp', [])
55
.controller('HomeCtrl', ['$http', '$interval', function($http, $interval) {
6+
/* home page controller */
67
var self = this;
78
self.analyses = 0;
89
self.requests = 0;
@@ -40,28 +41,48 @@ angular.module('recastApp', [])
4041
}])
4142

4243

43-
.controller('parameterCtrl', ['$http', 'IDService', function($http, ris) {
44+
.controller('parameterCtrl', ['$http', 'IDService', 'ItemService', function($http, ris, coordinates) {
45+
/* Controller to add parameter */
4446
var self = this;
47+
48+
self.items = function() {
49+
return coordinates.items();
50+
};
51+
52+
self.addCoordinate = function() {
53+
coordinates.push();
54+
};
55+
4556
self.addParameter = function(rid) {
57+
console.log("add parameter");
4658
ris.setID(rid);
59+
coordinates.clear();
60+
coordinates.push();
4761
$('#zip-file-request-page').val('');
4862
$('#modal-add-parameter').modal('show');
4963
};
64+
5065
self.submit = function() {
5166
self.hideModal();
5267
NProgress.start();
5368
NProgress.inc(0.4);
5469
var form_data = new FormData();
5570
form_data.append('file', self.zipFile);
56-
for (var k in self.parameter){
57-
form_data.append(k, self.parameter[k]);
71+
72+
for (var k in self.items()){
73+
parameter = {};
74+
parameter.name = self.items()[k].name;
75+
parameter.value = self.items()[k].value;
76+
par = angular.toJson(parameter);
77+
form_data.append(k, par);
5878
}
79+
5980
$http({
6081
method: 'POST',
6182
url:'/add-parameter/'+ris.getID(),
6283
data: form_data,
6384
headers: {'Content-Type': undefined},
64-
trnasformRequest: angular.identity
85+
transformRequest: angular.identity
6586
})
6687
.success(function(response){
6788
NProgress.inc(0.5);
@@ -79,6 +100,7 @@ angular.module('recastApp', [])
79100
}])
80101

81102
.controller('coordinateCtrl', ['$http', 'IDService', function($http, prs) {
103+
/* Controller to add coordinate on request page */
82104
var self = this;
83105
self.addCoordinate = function(pid) {
84106
prs.setID(pid);
@@ -97,11 +119,61 @@ angular.module('recastApp', [])
97119
});
98120
};
99121
self.hideModal = function() {
100-
console.log('hide modal');
101122
$('#modal-add-coordinate').modal('hide');
102123
};
103124
}])
104125

126+
.controller('arxivImportCtrl', ['$http', 'IDService', function($http, id_service) {
127+
128+
var self = this;
129+
self.arxiv_id;
130+
self.example = "this";
131+
self.here = "hello";
132+
self.title = "";
133+
self.collaboration = "";
134+
self.doi = "";
135+
self.abstract = "";
136+
137+
self.import = function() {
138+
console.log("clicked");
139+
console.log(self.arxiv_id);
140+
$('#modal-arxiv-data').modal('show');
141+
$http.post('/arxiv?id='+self.arxiv_id)
142+
.then(function(response) {
143+
console.log(response);
144+
self.title = response.data['title'];
145+
self.collaboration = response.data['collaboration'];
146+
self.doi = response.data['doi'];
147+
self.abstract = response.data['description'];
148+
console.log(self.title);
149+
console.log(self.collaboration);
150+
console.log(self.doi);
151+
console.log(self.abstract);
152+
});
153+
};
154+
}])
155+
156+
.factory('ItemService', [function() {
157+
items = [];
158+
159+
return {
160+
push: function() {
161+
items.push({
162+
name: "",
163+
value: "",
164+
namePlaceholder: "Name",
165+
valuePlaceholder: "Value",
166+
});
167+
},
168+
clear: function() {
169+
items = [];
170+
},
171+
items: function() {
172+
return items;
173+
}
174+
}
175+
}])
176+
105177
.factory('IDService', [function() {
106178
/* Service to store ID's */
107179
variable_id = 0;

0 commit comments

Comments
 (0)