Skip to content

Commit 3e60c1c

Browse files
committed
New importer api
1 parent bbdc78e commit 3e60c1c

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

app.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
sparql_url = 'http://fuseki:3030/n4o'
1414
def lido2rdf_url(): return f'http://converter:5000/convert'
15-
def importer_url(coll): return f'http://importer:5020/collection/import/{coll}'
15+
def importer_url(coll): return f'http://importer:5020/collection/{coll}/load'
1616

1717

1818
app = Flask(__name__, template_folder='templates', static_folder='static', static_url_path='/assets')
@@ -83,7 +83,7 @@ def home():
8383
collection = 'default'
8484
if user := find_user(username):
8585
collection = user['collection'] or 'default'
86-
data_dir = './data/'
86+
data_dir = './admin_data/'
8787
with open(data_dir+user['samplefile'], 'r') as f:
8888
user['profile_data'] = f.read()
8989
return render_template('index.html', collection=collection, user=jsonify(user).json)
@@ -127,9 +127,10 @@ def import_ttl():
127127
''''Import TTL data into the RDF store'''
128128
if coll := request.json.get('coll_index'):
129129
if data := request.json['data']:
130-
with open(f'./stage/inbox/{coll}/out.ttl', 'w') as f:
131-
f.write(data)
132-
return requests.post(importer_url(coll)).text
130+
fn = f'import_{coll}.ttl'
131+
with open(f'./data/{fn}', 'w') as f: f.write(data)
132+
res =requests.post(f'http://importer:5020/collection/{coll}/receive?from={fn}')
133+
return requests.post(f'http://importer:5020/collection/{coll}/load').text, res.status_code
133134
return jsonify(message='No data or collection index provided')
134135

135136

templates/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ <h4>RDF Output (ttl)</h4>
6262
<button type="button" class="btn btn-danger btn-sm" onclick="import_ttl()" id="ITB">Import</button>
6363
<button type="button" class="btn btn-primary btn-sm" onclick="rdfEditor.setValue('')" id="ITB">Clear</button>
6464
<button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#uploadFile">Upload file</button>
65+
<div class="spinner-border text-primary" role="status" id="SP2"></div>
6566
</p>
6667
<div id="rdfEditor" style="height:600px"></div>
6768
</div>
@@ -71,6 +72,7 @@ <h4>RDF Output (ttl)</h4>
7172
</body>
7273
<script>
7374
document.getElementById("SP1").style.display = "none";
75+
document.getElementById("SP2").style.display = "none";
7476

7577
function makeEditor(label, style = "ace/theme/monokai", fmt = "ace/mode/xml") {
7678
// Returns an ace editor object
@@ -115,6 +117,7 @@ <h4>RDF Output (ttl)</h4>
115117
}
116118

117119
function import_ttl(collection = "n4o") {
120+
document.getElementById("SP2").style.display = "inline-block";
118121
var req = {
119122
method: 'POST',
120123
headers: {
@@ -127,6 +130,9 @@ <h4>RDF Output (ttl)</h4>
127130
.then(response => response.json())
128131
.then(json => console.log(json))
129132
.catch(err => console.error(err))
133+
.finally(() => {
134+
document.getElementById("SP2").style.display = "none";
135+
});
130136
}
131137

132138
function uploadTurtle(form) {

0 commit comments

Comments
 (0)