Skip to content

Commit 13ff934

Browse files
committed
Feature:
replace or add collection data
1 parent 0731722 commit 13ff934

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

app.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,17 @@ def postCollectionData(coll_index):
115115
'''Upload new collection data. Recent data will be deleted.'''
116116
if coll_index > 0:
117117
if file := request.files.get('file'):
118-
# Copy data to file, then call importer services receive and add
119-
# logger.info(f'name = {file.filename} index = {index}')
118+
add_mode = request.form.get('add_mode', 'false')
119+
# Copy data to file, then call importer services receive and add/load
120+
# logger.info(f'name = {file.filename} add-mode = {add_mode}')
120121
buffer_name = f'collection_{coll_index}{Path(file.filename).suffix}'
121122
file.save(f'./data/{buffer_name}')
122123

123124
service_url = f'{IMPORTER_HOST}/collection/{coll_index}'
124125
res = requests.post(f'{service_url}/receive?from={buffer_name}')
125126
if res.ok:
126-
res = requests.post(f'{service_url}/load')
127-
# TODO res = requests.post(f'{service}/add') #Not supporte
127+
cmd_str = 'add' if add_mode == 'true' else 'load'
128+
res = requests.post(f'{service_url}/{cmd_str}')
128129
Path(f'./data/{buffer_name}').unlink(missing_ok=False)
129130
return res.text, res.status_code
130131
return jsonify(message='No data or collection index provided')

static/collections.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ function showProgess(on = false) {
5050
}
5151

5252
/// Import TTL data into the KG
53-
function postCollectionData(index,file) {
53+
function postCollectionData(index,file,add_mode=false) {
5454
showProgess(true);
5555
var data = new FormData();
5656
data.append('file', file, file.filename);
5757
data.append('index', index);
58+
data.append('add_mode', add_mode);
5859

5960
var req = { method: 'POST', body: data, };
6061
fetch('/postCollectionData/'+index, req)
@@ -79,6 +80,7 @@ function makeAppData() {
7980
displayCollection: null,
8081
collectionInfo: 'No info.',
8182
rdfFiles: [],
83+
add_mode: false,
8284
}
8385
},
8486
delimiters: ["${", "}$"], // for global
@@ -173,7 +175,7 @@ function makeAppData() {
173175
}
174176
else {
175177
const file0 = this.rdfFiles[0]
176-
postCollectionData(this.displayCollection.id, file0);
178+
postCollectionData(this.displayCollection.id, file0, this.add_mode);
177179
this.rdfFiles = [];
178180
}
179181
},

templates/collections.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ <h5 class="modal-title" id="uploadRDFLabel">Uploading RDF files</h5>
3434
<form novalidate @submit.prevent="uploadRDF">
3535
<div class="input-group mb-3">
3636
<input type="file" class="form-control" @change="saveRDFUrl" accept=".ttl,.nt,.xml,.n3,.zip" />&nbsp;
37-
<input type="submit" class="btn btn-primary" data-bs-dismiss="modal" value="Open" />
37+
<input type="submit" class="btn btn-primary" data-bs-dismiss="modal" value="Load" />
3838
</div>
3939
</form>
40+
<div class="form-check">
41+
<input class="form-check-input" type="checkbox" value="" id="id_add_mode" v-model="add_mode">
42+
<label class="form-check-label" for="id_add_mode">add data</label>
43+
</div>
4044
</div>
4145
<div class="modal-footer">
4246
<button type="button" class="btn btn-primary btn-sm" data-bs-dismiss="modal">Close</button>

0 commit comments

Comments
 (0)