Merge branch 'development' of gitlab.ub.uni-bielefeld.de:sfb1288inf/opaque into development

This commit is contained in:
Patrick Jentsch 2020-04-28 11:20:41 +02:00
commit 86c4b77085
5 changed files with 80 additions and 4 deletions

View File

@ -29,6 +29,26 @@ def init_corpus_analysis(corpus_id):
corpus_id, current_user.id, request.sid) 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.on('corpus_analysis_query')
@socketio_login_required @socketio_login_required
def corpus_analysis_query(query): def corpus_analysis_query(query):

View File

@ -7,12 +7,13 @@ class CorpusAnalysisClient {
// socket on event for corpous analysis initialization // socket on event for corpous analysis initialization
socket.on("corpus_analysis_init", (response) => { socket.on("corpus_analysis_init", (response) => {
var errorText; let errorText;
if (response.code === 200) { if (response.code === 200) {
console.log(`corpus_analysis_init: ${response.code} - ${response.msg}`); console.log(`corpus_analysis_init: ${response.code} - ${response.msg}`);
if (this.callbacks.init != undefined) { if (this.callbacks.init != undefined) {
this.callbacks.init(response.payload); this.callbacks.init(response.payload);
this.callbacks.get_metadata(); // should hold the function getMetaData
} }
if (this.displays.init != undefined) { if (this.displays.init != undefined) {
this.displays.init.setVisibilityByStatus("success"); 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 event for recieveing query results
socket.on("corpus_analysis_query", (response) => { socket.on("corpus_analysis_query", (response) => {
var errorText; let errorText;
if (response.code === 200) { if (response.code === 200) {
console.log(`corpus_analysis_query: ${response.code} - ${response.msg}`); console.log(`corpus_analysis_query: ${response.code} - ${response.msg}`);
@ -80,6 +103,12 @@ class CorpusAnalysisClient {
this.socket.emit("corpus_analysis_init", this.corpusId); 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) { query(queryStr) {
let displayOptionsData; let displayOptionsData;
let resultListOptions; let resultListOptions;

View File

@ -1,13 +1,15 @@
class Results { class Results {
constructor(resultsJSON, resultsList) { constructor(resultsJSON, resultsList , metaDataJSON) {
this.resultsJSON = resultsJSON; this.resultsJSON = resultsJSON;
this.resultsList = resultsList; this.resultsList = resultsList;
this.metaDataJSON = metaDataJSON
} }
clearAll() { clearAll() {
this.resultsList.clear(); this.resultsList.clear();
this.resultsList.update(); this.resultsList.update();
this.resultsJSON.init(); this.resultsJSON.init();
this.metaDataJSON.init();
} }
} }
@ -74,3 +76,13 @@ class ResultsJSON {
this.download(downloadElement, dataStr, resultFilename, "text/json", ".json") 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"] = "";
}
}

View File

@ -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) { function querySetup(payload) {
// This is called when a query was successfull // This is called when a query was successfull
// some hiding and resetting // some hiding and resetting

View File

@ -365,7 +365,8 @@
// Init corpus analysis components // Init corpus analysis components
resultsJSON = new ResultsJSON(); resultsJSON = new ResultsJSON();
resultsList = new ResultsList("result-list", resultsListOptions); resultsList = new ResultsList("result-list", resultsListOptions);
results = new Results(resultsJSON, resultsList); metaDataJSON = new MetaDataJSON();
results = new Results(resultsJSON, resultsList, metaDataJSON);
initDisplay = new CorpusAnalysisDisplay(initDisplayElement); initDisplay = new CorpusAnalysisDisplay(initDisplayElement);
queryDisplay = new CorpusAnalysisDisplay(queryDisplayElement); queryDisplay = new CorpusAnalysisDisplay(queryDisplayElement);
client = new CorpusAnalysisClient({{ corpus_id }}, nopaque.socket); client = new CorpusAnalysisClient({{ corpus_id }}, nopaque.socket);
@ -376,6 +377,12 @@
client.setCallback("init", () => { client.setCallback("init", () => {
initModal.close(); initModal.close();
}); });
client.setCallback('get_metadata', () => {
client.getMetaData();
})
client.setCallback('recv_meta_data', (response) => {
recvMetaData(response);
})
client.setDisplay("query", queryResultsUserFeedbackElement); client.setDisplay("query", queryResultsUserFeedbackElement);
client.setDisplay("query", queryDisplay); client.setDisplay("query", queryDisplay);
client.setCallback("query", (payload) => { client.setCallback("query", (payload) => {