mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-25 10:54:18 +00:00
Merge branch 'development' of gitlab.ub.uni-bielefeld.de:sfb1288inf/opaque into development
This commit is contained in:
commit
86c4b77085
@ -29,6 +29,26 @@ def init_corpus_analysis(corpus_id):
|
||||
corpus_id, current_user.id, request.sid)
|
||||
|
||||
|
||||
@socketio.on('corpus_analysis_get_meta_data')
|
||||
@socketio_login_required
|
||||
def corpus_analysis_get_meta_data(corpus_id):
|
||||
# get meta data from db
|
||||
db_corpus = Corpus.query.get(corpus_id)
|
||||
# TODO: Check if current user is actually the creator of the corpus?
|
||||
metadata = {}
|
||||
metadata["corpus_name"] = db_corpus.title
|
||||
metadata["corpus_description"] = db_corpus.description
|
||||
metadata["corpus_creation_date"] = db_corpus.creation_date.isoformat()
|
||||
# get meta data from corpus in cqp server
|
||||
client = corpus_analysis_clients.get(request.sid)
|
||||
client_corpus = client.corpora.get('CORPUS')
|
||||
metadata["corpus_properties"] = client_corpus.attrs['properties']
|
||||
# metadata["corpus_properties"] = client.api.corpus_properties('CORPUS')
|
||||
payload = metadata
|
||||
response = {'code': 200, 'desc': 'Corpus meta data', 'msg': 'OK', 'payload': payload}
|
||||
socketio.emit('corpus_analysis_send_meta_data', response, room=request.sid)
|
||||
|
||||
|
||||
@socketio.on('corpus_analysis_query')
|
||||
@socketio_login_required
|
||||
def corpus_analysis_query(query):
|
||||
|
@ -7,12 +7,13 @@ class CorpusAnalysisClient {
|
||||
|
||||
// socket on event for corpous analysis initialization
|
||||
socket.on("corpus_analysis_init", (response) => {
|
||||
var errorText;
|
||||
let errorText;
|
||||
|
||||
if (response.code === 200) {
|
||||
console.log(`corpus_analysis_init: ${response.code} - ${response.msg}`);
|
||||
if (this.callbacks.init != undefined) {
|
||||
this.callbacks.init(response.payload);
|
||||
this.callbacks.get_metadata(); // should hold the function getMetaData
|
||||
}
|
||||
if (this.displays.init != undefined) {
|
||||
this.displays.init.setVisibilityByStatus("success");
|
||||
@ -30,9 +31,31 @@ class CorpusAnalysisClient {
|
||||
}
|
||||
});
|
||||
|
||||
// socket on event for recieving meta
|
||||
socket.on('corpus_analysis_send_meta_data', (response) => {
|
||||
let errorText;
|
||||
|
||||
if (response.code === 200) {
|
||||
console.log(`corpus_analysis_send_meta_data: ${response.code} - ${response.msg} - ${response.desc}`);
|
||||
if (this.callbacks.recv_meta_data != undefined) {
|
||||
this.callbacks.recv_meta_data(response.payload);
|
||||
}
|
||||
} else {
|
||||
errorText = `Error ${response.code} - ${response.msg}`;
|
||||
if (this.displays.init.errorContainer != undefined) {
|
||||
this.displays.init.errorContainer.innerHTML = `<p class="red-text">` +
|
||||
`<i class="material-icons tiny">error</i> ${errorText}</p>`;
|
||||
}
|
||||
if (this.displays.init != undefined) {
|
||||
this.displays.init.setVisibilityByStatus("error");
|
||||
}
|
||||
console.error(`corpus_analysis_send_meta_data: ${errorText}`);
|
||||
}
|
||||
});
|
||||
|
||||
// socket on event for recieveing query results
|
||||
socket.on("corpus_analysis_query", (response) => {
|
||||
var errorText;
|
||||
let errorText;
|
||||
|
||||
if (response.code === 200) {
|
||||
console.log(`corpus_analysis_query: ${response.code} - ${response.msg}`);
|
||||
@ -80,6 +103,12 @@ class CorpusAnalysisClient {
|
||||
this.socket.emit("corpus_analysis_init", this.corpusId);
|
||||
}
|
||||
|
||||
getMetaData() {
|
||||
// just emits thos to tell the server to gather all meta dat infos and send
|
||||
// those back
|
||||
this.socket.emit("corpus_analysis_get_meta_data", this.corpusId);
|
||||
}
|
||||
|
||||
query(queryStr) {
|
||||
let displayOptionsData;
|
||||
let resultListOptions;
|
||||
|
@ -1,13 +1,15 @@
|
||||
class Results {
|
||||
constructor(resultsJSON, resultsList) {
|
||||
constructor(resultsJSON, resultsList , metaDataJSON) {
|
||||
this.resultsJSON = resultsJSON;
|
||||
this.resultsList = resultsList;
|
||||
this.metaDataJSON = metaDataJSON
|
||||
}
|
||||
|
||||
clearAll() {
|
||||
this.resultsList.clear();
|
||||
this.resultsList.update();
|
||||
this.resultsJSON.init();
|
||||
this.metaDataJSON.init();
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,4 +75,14 @@ class ResultsJSON {
|
||||
// start actual download
|
||||
this.download(downloadElement, dataStr, resultFilename, "text/json", ".json")
|
||||
}
|
||||
}
|
||||
|
||||
class MetaDataJSON {
|
||||
// Sets empty object structure. Also usefull to delete old results.
|
||||
init() {
|
||||
this["corpus_name"] = "";
|
||||
this["corpus_description"] = "";
|
||||
this["corpus_creation_date"] = "";
|
||||
this["corpus_properties"] = "";
|
||||
}
|
||||
}
|
@ -1,3 +1,11 @@
|
||||
function recvMetaData(payload) {
|
||||
results.metaDataJSON.corpus_name = payload.corpus_name;
|
||||
results.metaDataJSON.corpus_description = payload.corpus_description;
|
||||
results.metaDataJSON.corpus_creation_date = payload.corpus_creation_date;
|
||||
results.metaDataJSON.corpus_properties = payload.corpus_properties;
|
||||
console.log(results.metaDataJSON);
|
||||
}
|
||||
|
||||
function querySetup(payload) {
|
||||
// This is called when a query was successfull
|
||||
// some hiding and resetting
|
||||
|
@ -365,7 +365,8 @@
|
||||
// Init corpus analysis components
|
||||
resultsJSON = new ResultsJSON();
|
||||
resultsList = new ResultsList("result-list", resultsListOptions);
|
||||
results = new Results(resultsJSON, resultsList);
|
||||
metaDataJSON = new MetaDataJSON();
|
||||
results = new Results(resultsJSON, resultsList, metaDataJSON);
|
||||
initDisplay = new CorpusAnalysisDisplay(initDisplayElement);
|
||||
queryDisplay = new CorpusAnalysisDisplay(queryDisplayElement);
|
||||
client = new CorpusAnalysisClient({{ corpus_id }}, nopaque.socket);
|
||||
@ -376,6 +377,12 @@
|
||||
client.setCallback("init", () => {
|
||||
initModal.close();
|
||||
});
|
||||
client.setCallback('get_metadata', () => {
|
||||
client.getMetaData();
|
||||
})
|
||||
client.setCallback('recv_meta_data', (response) => {
|
||||
recvMetaData(response);
|
||||
})
|
||||
client.setDisplay("query", queryResultsUserFeedbackElement);
|
||||
client.setDisplay("query", queryDisplay);
|
||||
client.setCallback("query", (payload) => {
|
||||
|
Loading…
Reference in New Issue
Block a user