Skip to content

Commit

Permalink
Implement and close #62
Browse files Browse the repository at this point in the history
  • Loading branch information
ylvion committed Apr 7, 2022
1 parent d8798a5 commit 3da9798
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,22 @@ public void finalizeAnalysis(DaveVis analysis) {

/**
* Delete an Analysis description.
* This can only be done, if it's not in use in a {@link DaveDashboard}
* This can only be done, if it's not in use in a {@link DaveDashboard}.
* The corresponding {@link DaveQuery} and {@link DaveGraphDescription} will also be deleted, if they are not used by another Analysis
*
* @param analysis Entity to delete
* @throws de.tudresden.inf.verdatas.xapitools.dave.analysis.AnalysisExceptions.SideEffectsError when the Analysis is still used in a {@link DaveDashboard}
*/
// TODO Delete option for query and graph description
@Transactional
public void deleteAnalysis(DaveVis analysis) {
Set<String> used = this.checkUsageOfAnalysis(analysis);
if (used.isEmpty()) {
if (this.getAnalysesWithSameQuery(analysis, analysis.getQuery()).isEmpty()) {
this.queryRepository.delete(analysis.getQuery());
}
if (this.getAnalysesWithSameGraphDescription(analysis, analysis.getDescription()).isEmpty()) {
this.graphDescriptionRepository.delete(analysis.getDescription());
}
this.visRepository.delete(analysis);
} else {
throw new AnalysisExceptions.SideEffectsError("Deletion of "
Expand All @@ -290,7 +296,34 @@ public Set<String> checkUsageOfAnalysis(DaveVis analysis) {
}

/**
* Get the Titles of all Analyses, which use the same Query
* Get all Analyses, which use the same Query
*
* @param analysis Entity as reference value
* @param query {@link DaveQuery} which usage should be checked
*/
public Set<DaveVis> getAnalysesWithSameQuery(DaveVis analysis, DaveQuery query) {
return this.getAllAnalysis(false)
.filter(daveVis -> daveVis.getQuery().getQuery().equals(query.getQuery()))
.filter(vis -> !(vis.getId().equals(analysis.getId())))
.collect(Collectors.toSet());
}

/**
* Get all Analyses, which use the same Graph Description
*
* @param analysis Entity as reference value
* @param graphDescription {@link DaveGraphDescription} which usage should be checked
*/
public Set<DaveVis> getAnalysesWithSameGraphDescription(DaveVis analysis, DaveGraphDescription graphDescription) {
return this.getAllAnalysis(false)
.filter(daveVis -> daveVis.getDescription().getDescription().equals(graphDescription.getDescription()))
.filter(vis -> !(vis.getId().equals(analysis.getId())))
.collect(Collectors.toSet());
}

/**
* Get the Titles of all Analyses, which use the same Query.
* This is used to check if the modification of this description would lead to errors
*
* @param analysis Entity as reference value
* @param queryName Title of the {@link DaveQuery}, which usage should be checked
Expand All @@ -305,7 +338,8 @@ public Set<String> checkUsageOfQuery(DaveVis analysis, String queryName, String
}

/**
* Get the Titles of all Analyses, which use the same Graph Description
* Get the Titles of all Analyses, which use the same Graph Description.
* This is used to check if the modification of this description would lead to errors
*
* @param analysis Entity as reference value
* @param graphName Title of the {@link DaveGraphDescription}, which usage should be checked
Expand Down
34 changes: 30 additions & 4 deletions src/main/resources/static/js/toolkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,29 @@ function triggerGraphSelect(element) {
});
}

function adaptDataset(element) {
var openButton = element.querySelector('#openModal')
openButton.dataset.bsVisName = element.dataset.vname;
openButton.dataset.bsVisId = element.dataset.vid;
}

function adaptModal(element) {
// Adapted from https://getbootstrap.com/docs/5.0/components/modal/
element.addEventListener('show.bs.modal', function (event) {
// Button that triggered the modal
var button = event.relatedTarget
// Extract info from data-bs-* attributes
var analysisName = button.getAttribute('data-bs-vis-name')
var analysisId = button.getAttribute('data-bs-vis-id')
// Update the modal's content.
var modalText = element.querySelector('#visName')
var modalFlowInput = element.querySelector('#flow')

modalText.textContent = analysisName
modalFlowInput.value = analysisId
})
}

function triggerGraphShow(element) {
if ($('#graphIdInput')[0].value === '') return;
$('.xapi-graph-content').each(function () {
Expand All @@ -157,10 +180,6 @@ function replaceSvgVis(element) {
.then(() => element.firstElementChild.setAttribute('height', 1.2 * element.firstElementChild.getAttribute('height')));
}

function showLoadingModal(element) {
$('#openModal').click();
}

// Inspired by https://thecoderain.blogspot.com/2020/11/generate-valid-random-email-js-jquery.html
const emailChars = '1234567890';

Expand Down Expand Up @@ -232,6 +251,13 @@ $(document).ready(function () {
$('#graphIdInput').each(function () {
triggerGraphShow(this);
});
// Analyses deletion modal
$('.xapi-vis').each(function () {
adaptDataset(this)
});
$('.xapi-vis-modal').each(function () {
adaptModal(this)
});
// Dashboard presenter
$('.xapi-dashboard-vis').each(function () {
replaceSvgVis(this);
Expand Down
37 changes: 30 additions & 7 deletions src/main/resources/templates/bootstrap/dave/analysis/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h5 class="card-title mb-3">Select files</h5>
</div>
<!-- Content Cards -->
<div class="col d-flex align-items-stretch" th:each="vis: ${analysis}">
<div class="card flex-fill">
<div class="card flex-fill xapi-vis" th:data-vname="${vis.getName()}" th:data-vid="${vis.getId()}">
<div class="card-header flex-fill">
<h3>
<span th:text="${vis.getName()}"></span>
Expand All @@ -77,11 +77,35 @@ <h3>
<button type="submit" class="btn btn-primary flex-fill">Copy</button>
</form>
</div>
<div class="col">
<form method="POST" th:action="@{/ui/dave/manage/analysis/delete}" class="flex-fill d-flex">
<input type="hidden" name="flow" th:value="${vis.getId()}">
<button type="submit" class="btn btn-danger flex-fill">Delete</button>
</form>
<div class="col d-flex">
<!-- Button trigger modal -->
<button type="button" class="btn btn-danger flex-fill" id="openModal" data-bs-toggle="modal" data-bs-target="#deleteModal" >
Delete
</button>

<!-- Modal -->
<div class="modal fade xapi-vis-modal" id="deleteModal" tabindex="-1" aria-labelledby="deleteModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModalLabel">Confirm deletion of analysis</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Please confirm the deletion of the analysis named: <br> &nbsp;<span id="visName"></span>&nbsp;. <br>
The corresponding Query and Graph description will also be deleted, if they are not used by another analysis. <br>
This action can <span style="font-weight:bold">not</span> be undone.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Go Back</button>
<form method="POST" th:action="@{/ui/dave/manage/analysis/delete}">
<input type="hidden" id="flow" name="flow" value="">
<button type="submit" class="btn btn-danger button-spinner">Delete</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
Expand All @@ -96,7 +120,6 @@ <h3>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

0 comments on commit 3da9798

Please sign in to comment.