Skip to content

Commit

Permalink
Clear user guide plugins implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
boyan-tonchev committed Feb 29, 2024
1 parent 98acc84 commit 99c1e4a
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 208 deletions.
4 changes: 3 additions & 1 deletion src/js/angular/guides/guide-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const GuideUtils = (function () {

const clickOnElement = function (elementSelector) {
return () => waitFor(elementSelector)
.then((element) => element.click());
.then((element) => {
element.click();
});
};

const clickOnGuideElement = function (elementSelector, postSelector) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const reloadAndOpenInfoPanel = (services, clasInstanceSelector, resolve, reject) => {
const reloadAndOpenInfoPanel = (services, clasInstanceSelector) => {
services.$location.path('/hierarchy').search({});
return services.GuideUtils.waitFor(clasInstanceSelector, 3)
.then(() => {
Expand Down Expand Up @@ -110,6 +110,7 @@ PluginRegistry.add('guide.step', [
if (!GuideUtils.isVisible(closeButtonSelector)) {
return reloadAndOpenInfoPanel({$location, $route, GuideUtils}, clasInstanceSelector);
}

return Promise.resolve();
}
}, options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ PluginRegistry.add('guide.step', [
class: 'enable-autocomplete-checkbox-guide-dialog',
// Disable default behavior of service when element is clicked.
advanceOn: undefined,
beforeShowPromise: () => GuideUtils.deferredShow(500)(),
show: (guide) => () => {
// Added listener to the element.
$(autocompleteCheckboxSelector)
Expand Down
88 changes: 38 additions & 50 deletions src/js/angular/guides/steps/complex/execute-sparql-query/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,46 +52,37 @@ PluginRegistry.add('guide.step', [
services.toastr.error(services.$translate.instant('guide.unexpected.error.message'));
throw error;
}),
onNextValidate: () => {
return YasguiComponentDirectiveUtil.getOntotextYasguiElementAsync(SPARQL_DIRECTIVE_SELECTOR)
.then((yasgui) => yasgui.getQuery().then((query) => ({yasgui, queryFromEditor: query})))
.then(({yasgui, queryFromEditor}) => {
const editorQuery = GuideUtils.removeWhiteSpaces(queryFromEditor);
const stepQuery = GuideUtils.removeWhiteSpaces(query);
if (editorQuery !== stepQuery) {
if (editorQuery === 'select*where{?s?p?o.}limit100' || overwriteQuery) {
// The query is the default query OR we previously overwrote it => we can overwrite it
yasgui.setQuery(query);
} else {
GuideUtils.noNextErrorToast(toastr, $translate, $interpolate,
'guide.step_plugin.execute-sparql-query.query-not-same.error', options);
return false;
}
onNextValidate: () => YasguiComponentDirectiveUtil.getOntotextYasguiElementAsync(SPARQL_DIRECTIVE_SELECTOR)
.then((yasgui) => yasgui.getQuery().then((query) => ({yasgui, queryFromEditor: query})))
.then(({yasgui, queryFromEditor}) => {
const editorQuery = GuideUtils.removeWhiteSpaces(queryFromEditor);
const stepQuery = GuideUtils.removeWhiteSpaces(query);
if (editorQuery !== stepQuery) {
if (editorQuery === 'select*where{?s?p?o.}limit100' || overwriteQuery) {
// The query is the default query OR we previously overwrote it => we can overwrite it
yasgui.setQuery(query);
} else {
GuideUtils.noNextErrorToast(toastr, $translate, $interpolate,
'guide.step_plugin.execute-sparql-query.query-not-same.error', options);
return false;
}
overwriteQuery = true;
return true;
});
},
initPreviousStep: () => new Promise((resolve, reject) => {
}
overwriteQuery = true;
return true;
}),
initPreviousStep: () => {
if (index === 0) {
YasguiComponentDirectiveUtil.setQuery(SPARQL_DIRECTIVE_SELECTOR, defaultQuery)
.then(() => resolve());
} else {
const haveToReload = '/sparql' !== $location.url();
return YasguiComponentDirectiveUtil.setQuery(SPARQL_DIRECTIVE_SELECTOR, defaultQuery);
}

if (haveToReload) {
$location.path('/sparql').search({});
}
GuideUtils.waitFor(GuideUtils.CSS_SELECTORS.SPARQL_EDITOR_SELECTOR)
.then(() => {
YasguiComponentDirectiveUtil.executeSparqlQuery("#query-editor", query)
.then(() => {
resolve();
})
.catch((error) => reject(error));
});
const haveToReload = '/sparql' !== $location.url();
if (haveToReload) {
$location.path('/sparql').search({});
}
}),

return GuideUtils.waitFor(GuideUtils.CSS_SELECTORS.SPARQL_EDITOR_SELECTOR)
.then(() => YasguiComponentDirectiveUtil.executeSparqlQuery("#query-editor", query));
},
scrollToHandler: GuideUtils.scrollToTop,
extraContent: queryDef.queryExtraContent,
onScope: (scope) => {
Expand All @@ -113,22 +104,19 @@ PluginRegistry.add('guide.step', [
}),
scrollToHandler: GuideUtils.scrollToTop,
canBePaused: false,
initPreviousStep: (services, stepId) => new Promise((resolve, reject) => {
initPreviousStep: (services, stepId) => {
const previousStep = services.ShepherdService.getPreviousStepFromHistory(stepId);
previousStep.options.initPreviousStep(services, previousStep.options.id)
return previousStep.options.initPreviousStep(services, previousStep.options.id)
.then(() => {
const currentStepId = services.ShepherdService.getCurrentStepId();
// Skip expanding of node if last step is "visual-graph-expand"
if (currentStepId === stepId) {
resolve();
} else {
YasguiComponentDirectiveUtil.executeSparqlQuery("#query-editor", query)
.then(() => resolve())
.catch((error) => reject(error));
return Promise.resolve();
}
})
.catch((error) => reject(error));
})

return YasguiComponentDirectiveUtil.executeSparqlQuery("#query-editor", query);
});
}
}, options)
});
steps.push({
Expand All @@ -149,11 +137,11 @@ PluginRegistry.add('guide.step', [
return GuideUtils.waitFor(GuideUtils.CSS_SELECTORS.SPARQL_EDITOR_SELECTOR)
.then(() => GuideUtils.deferredShow(500)())
.then(() => YasguiComponentDirectiveUtil.executeSparqlQuery("#query-editor", query));
} else {
const previousStep = services.ShepherdService.getPreviousStepFromHistory(stepId);
return previousStep.options.initPreviousStep(services, previousStep.options.id)
.then(() => YasguiComponentDirectiveUtil.setQuery(SPARQL_DIRECTIVE_SELECTOR, query));
}

const previousStep = services.ShepherdService.getPreviousStepFromHistory(stepId);
return previousStep.options.initPreviousStep(services, previousStep.options.id)
.then(() => YasguiComponentDirectiveUtil.setQuery(SPARQL_DIRECTIVE_SELECTOR, query));
}
}, options)
});
Expand Down
28 changes: 9 additions & 19 deletions src/js/angular/guides/steps/complex/import-rdf-file/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ PluginRegistry.add('guide.step', [
GuideUtils.noNextErrorToast(toastr, $translate, $interpolate,
'guide.step_plugin.import_rdf_file.file-must-be-uploaded', options);
return Promise.resolve(false);
} else {
return Promise.resolve(true);
}

return Promise.resolve(true);
}
}, options)
},
Expand All @@ -86,19 +86,12 @@ PluginRegistry.add('guide.step', [
GuideUtils.clickOnGuideElement('import-settings-cancel-button')()
.then(() => resolve());
}),
beforeShowPromise: () => new Promise(function (resolve, reject) {
services.GuideUtils.deferredShow(300)()
.then(() => {
services.GuideUtils.waitFor(importSettingsButtonSelector, 3)
.then(() => {
resolve();
})
.catch((error) => {
services.toastr.error(services.$translate.instant('guide.unexpected.error.message'));
reject(error);
});
});
}),
beforeShowPromise: () => services.GuideUtils.deferredShow(300)()
.then(() => services.GuideUtils.waitFor(importSettingsButtonSelector, 3)
.catch((error) => {
services.toastr.error(services.$translate.instant('guide.unexpected.error.message'));
return Promise.reject(error);
})),
onNextClick: () => GuideUtils.clickOnGuideElement('import-settings-import-button')(),
canBePaused: false
}, options)
Expand All @@ -110,10 +103,7 @@ PluginRegistry.add('guide.step', [
url: '/import',
elementSelector: GuideUtils.getGuideElementSelector('import-status-info'),
class: 'import-status-info-guide-dialog',
onPreviousClick: () => new Promise(function (resolve) {
GuideUtils.clickOnGuideElement('import-file-' + options.resourceFile)()
.then(() => resolve());
})
onPreviousClick: () => GuideUtils.clickOnGuideElement('import-file-' + options.resourceFile)()
}, options)
}
]);
Expand Down
24 changes: 10 additions & 14 deletions src/js/angular/guides/steps/complex/main-menu/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,14 @@ PluginRegistry.add('guide.step', [
guide.next();
}
}),
initPreviousStep: (services, stepId) => new Promise((resolve, reject) => {
initPreviousStep: (services, stepId) => {
const previousStep = services.ShepherdService.getPreviousStepFromHistory(stepId);
if (previousStep) {
previousStep.options.initPreviousStep(services, previousStep.options.id)
.then(() => resolve())
.catch((error) => reject(error));
} else {
resolve();
return previousStep.options.initPreviousStep(services, previousStep.options.id);
}
})

return Promise.resolve();
}
}, options)
});

Expand All @@ -146,16 +144,14 @@ PluginRegistry.add('guide.step', [
return true;
},
onNextClick: (guide) => GuideUtils.clickOnGuideElement(submenuSelector, ' a')().then(() => guide.next()),
initPreviousStep: (services, stepId) => new Promise((resolve, reject) => {
initPreviousStep: (services, stepId) => {
const previousStep = services.ShepherdService.getPreviousStepFromHistory(stepId);
if (previousStep) {
previousStep.options.initPreviousStep(services, previousStep.options.id)
.then(() => resolve())
.catch((error) => reject(error));
} else {
resolve();
return previousStep.options.initPreviousStep(services, previousStep.options.id);
}
})

return Promise.resolve();
}
}, options)
});
}
Expand Down
13 changes: 5 additions & 8 deletions src/js/angular/guides/steps/complex/select-repository/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ PluginRegistry.add('guide.step', [
},
class: 'repository-select-button-guide-dialog',
advanceOn: undefined,
beforeShowPromise: () => new Promise(function (resolve, reject) {
services.GuideUtils.waitFor(getRepositoryElementSelector(services, options), 1)
.then(() => resolve())
.catch((error) => {
services.toastr.error(services.$translate.instant('guide.unexpected.error.message'));
reject(error);
});
}),
beforeShowPromise: () => services.GuideUtils.waitFor(getRepositoryElementSelector(services, options), 1)
.catch((error) => {
services.toastr.error(services.$translate.instant('guide.unexpected.error.message'));
throw (error);
}),
show: (guide) => () => {
$('#repositorySelectDropdown').addClass('autoCloseOff');
// Added listener to the element.
Expand Down
Loading

0 comments on commit 99c1e4a

Please sign in to comment.