Skip to content

Commit

Permalink
added progress indication for reindexing
Browse files Browse the repository at this point in the history
  • Loading branch information
ssuvorov-fls committed Nov 30, 2022
1 parent 53b4cf2 commit cf830a6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 9 deletions.
5 changes: 3 additions & 2 deletions js/pages/configuration/configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@
</a>
</div>
<div class="configuration__padded" data-bind="if: $component.searchAvailable()">
<button class="btn btn-sm btn-primary" data-bind="click: reindexConceptSets">
<span data-bind="text:ko.i18n('configuration.buttons.reindexCS', 'Concept Sets Reindex')"></span>
<button data-bind="css: $component.getReindexButtonStyles().buttonClass, click: function(){$component.reindexConceptSets();}" class="connection-check-button btn btn-sm">
<i data-bind="css : $component.getReindexButtonStyles().iconClass" class="fa"></i>
<span data-bind="text: $component.getReindexButtonTitle()"></span>
</button>
</div>
</div>
Expand Down
65 changes: 59 additions & 6 deletions js/pages/configuration/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ define([
this.jobListing = sharedState.jobListing;
this.sourceJobs = new Map();
this.sources = sharedState.sources;
this.reindexJob = ko.observable();

this.priorityOptions = [
{id: 'session', name: ko.i18n('configuration.priorityOptions.session', 'Current Session')},
Expand Down Expand Up @@ -81,7 +82,10 @@ define([
});

this.intervalId = PollService.add({
callback: () => this.checkJobs(),
callback: () => {
this.checkJobs();
this.checkReindexJob();
},
interval: 5000
});

Expand All @@ -100,20 +104,24 @@ define([
} finally {
this.loading(false);
}
};
}

async reindexConceptSets () {
async reindexConceptSets() {
const confirmAction = confirm(ko.unwrap(ko.i18n('configuration.confirms.reindexSource', 'Reindexing may take a long time. It depends on amount and complexity of concept sets')));
if (!confirmAction) {
return;
}
try {
const data = await conceptSetService.reindexConceptSets();

const data =await conceptSetService.reindexConceptSets();
if (data.status === 'RUNNING') {
alert(ko.unwrap(ko.i18n('configuration.alerts.reindexRunning', 'Reindexing of concept sets is currently in progress')));
} else {
this.reindexJob(data);
}
} catch(e) {
throw new Error(e);
}
};
}

dispose() {
PollService.stop(this.intervalId);
Expand Down Expand Up @@ -141,6 +149,21 @@ define([
});
}

async checkReindexJob() {
try {
let data;
if (this.reindexJob()) {
data = await conceptSetService.statusReindexConceptSets(this.reindexJob().executionId);
} else {
data = await conceptSetService.statusReindexConceptSets();
}
this.reindexJob(data);
} catch(e) {
this.reindexJob(null);
throw new Error(e);
}
}

async onPageCreated() {
this.loading(true);
await sourceApi.initSourcesConfig();
Expand Down Expand Up @@ -271,6 +294,36 @@ define([
return this.getButtonStyles(source.connectionCheck());
}

getReindexButtonStyles() {
let iconClass = 'fa-caret-right';
let buttonClass = 'btn-primary';
let state = sourceApi.buttonCheckState.unknown;
if (this.reindexJob()) {
switch(this.reindexJob().status) {
case 'COMPLETED':
state = sourceApi.buttonCheckState.success;
break;
case 'FAILED':
state = sourceApi.buttonCheckState.failed;
break;
case 'CREATED':
case 'RUNNING':
state = sourceApi.buttonCheckState.checking;
break;
}
}
return this.getButtonStyles(state);
}

getReindexButtonTitle() {
if (this.reindexJob() && this.reindexJob().status !== 'UNAVAILABLE') {
return ko.unwrap(ko.i18nformat('configuration.buttons.reindexCSStatus', 'Concept Sets Reindex (<%=doneCount%> of <%=maxCount%>)',
{doneCount: this.reindexJob().doneCount, maxCount: this.reindexJob().maxCount})());
} else {
return ko.unwrap(ko.i18n('configuration.buttons.reindexCS', 'Concept Sets Reindex'));
}
}

getButtonStyles(sourceState) {
let iconClass = 'fa-caret-right';
let buttonClass = 'btn-primary';
Expand Down
8 changes: 7 additions & 1 deletion js/services/ConceptSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ define(function (require) {
return httpService.doGet(`${config.api.url}conceptset/${sourceKey}/index`).then(({ data }) => data);
}

function statusReindexConceptSets(jobExecutionId) {
const sourceKey = sharedState.sourceKeyOfVocabUrl();
return httpService.doGet(`${config.api.url}conceptset/${sourceKey}/index/${jobExecutionId || -1}/status`).then(({ data }) => data);
}

function lookupIdentifiers(identifiers) {
return httpService.doPost(sharedState.vocabularyUrl() + 'lookup/identifiers', identifiers);
}
Expand Down Expand Up @@ -156,7 +161,8 @@ define(function (require) {
copyVersion,
searchConceptSets,
checkSearchAvailable,
reindexConceptSets
reindexConceptSets,
statusReindexConceptSets
};

return api;
Expand Down

0 comments on commit cf830a6

Please sign in to comment.