Skip to content

Commit

Permalink
Merge pull request #93 from Ontotext-AD/gdb-3906
Browse files Browse the repository at this point in the history
GDB-3906: Add "force drop" to the connector manager in the workbench
  • Loading branch information
desislava-hristova-ontotext authored Sep 24, 2019
2 parents d9a2681 + 2b57785 commit 33feba9
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 10 deletions.
51 changes: 42 additions & 9 deletions src/js/angular/externalsync/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ define(['lib/stringify/stringify'],
return query;
}

function deleteConnectorQuery(name, prefix) {
function deleteConnectorQuery(name, prefix, force) {
var namePrefix = prefix.substring(0, prefix.length - 1) + "/instance#";
var query = 'PREFIX prefix:<' + prefix + '>\n' +
'INSERT DATA {\n' +
'\t<' + namePrefix + name + '> prefix:dropConnector ""\n' +
'\t<' + namePrefix + name + '> prefix:dropConnector "' + (force ? "force" : "") + '"\n' +
'}';
return query;
}
Expand Down Expand Up @@ -221,6 +221,7 @@ define(['lib/stringify/stringify'],
angular
.module('graphdb.framework.externalsync.controllers', [])
.controller('ConnectorsCtrl', ConnectorsCtrl)
.controller('DeleteConnectorCtrl', DeleteConnectorCtrl)
.controller('ExtendNewConnectorCtrl', ExtendNewConnectorCtrl)
.controller('CreateConnectorCtrl', CreateConnectorCtrl)
.controller('CreateProgressCtrl', CreateProgressCtrl)
Expand Down Expand Up @@ -505,22 +506,38 @@ define(['lib/stringify/stringify'],
};

$scope.delete = function (inst, type) {
ModalService.openSimpleModal({
title: 'Confirm delete',
message: 'Are you sure you want to delete this connector?',
warning: true
var isExternal = type.key.indexOf("Elastic") >= 0 || type.key.indexOf("Solr") >= 0;

$modal.open({
templateUrl: 'js/angular/externalsync/templates/deleteConnector.html',
controller: 'DeleteConnectorCtrl',
resolve: {
type: function () {
return type.key;
},
isExternal: function () {
return isExternal;
}
}
}).result
.then(function () {
.then(function(force) {
$scope.setLoader(true, 'Deleting connector ' + inst.name, 'This is usually a fast operation but it might take a while.');

var query = deleteConnectorQuery(inst.name, type.value);
var query = deleteConnectorQuery(inst.name, type.value, force);
$http.post('repositories/' + $repositories.getActiveRepository() + '/statements', jsonToFormData({update: query}), {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}).then(function (res) {
$http.get('rest/connectors').then(function (res) {
$http.get('rest/connectors/existing?prefix=' + encodeURIComponent(type.value)).then(function (res) {
$scope.existing[type.key] = res.data;
});
});
toastr.success("Deleted connector " + inst.name);
if (force) {
toastr.success("Deleted (with force) connector " + inst.name);
if (isExternal) {
toastr.warning("You may have to remove the index manually from " + type.key);
}
} else {
toastr.success("Deleted connector " + inst.name);
}
}, function (err) {
toastr.error(getError(err));
}).finally(function() {
Expand All @@ -546,6 +563,22 @@ define(['lib/stringify/stringify'],

}

DeleteConnectorCtrl.$inject = ['$scope', '$modalInstance', 'type', 'isExternal'];
function DeleteConnectorCtrl($scope, $modalInstance, type, isExternal) {
$scope.force = false;
$scope.type = type;
$scope.isExternal = isExternal;

$scope.ok = function () {
$modalInstance.close($scope.force);
};

$scope.cancel = function () {
$modalInstance.dismiss();
};
}


ExtendNewConnectorCtrl.$inject = ['$scope', '$modalInstance', 'connector', '$modal', 'toastr'];
function ExtendNewConnectorCtrl($scope, $modalInstance, connector, $modal, toastr) {

Expand Down
16 changes: 16 additions & 0 deletions src/js/angular/externalsync/templates/deleteConnector.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="modal-header">
<button type="button" class="close" ng-click="cancel()"></button>
<h3 class="modal-title">Confirm delete</h3>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this connector?</p>
<span popover="Force delete will remove the connector even if part of the operation fails. Use it if normal delete does not work.{{ isExternal ? (' Note that you may have to drop the index manually from ' + type + '.') : '' }}"
popover-trigger="mouseenter"
popover-placement="bottom">
<input id="force-delete" type="checkbox" ng-model="force"><label for="force-delete">&nbsp;Force delete</label>
</span>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" ng-click="cancel()">Cancel</button>
<button type="submit" class="btn btn-primary delete-connector-btn" ng-click="ok()">Delete</button>
</div>
</div>
2 changes: 1 addition & 1 deletion test-cypress/integration/setup/connectors-lucene.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('Setup / Connectors - Lucene', () => {
}

function getConfirmConnectorDeletebutton() {
return cy.get('.confirm-btn');
return cy.get('.delete-connector-btn');
}

});
4 changes: 4 additions & 0 deletions webpack.config.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ module.exports = {
from: 'src/js/angular/explore/templates',
to: 'js/angular/explore/templates'
},
{
from: 'src/js/angular/externalsync/templates',
to: 'js/angular/externalsync/templates'
},
{
from: 'src/js/angular/graphexplore/templates',
to: 'js/angular/graphexplore/templates'
Expand Down

0 comments on commit 33feba9

Please sign in to comment.