Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DQT] add delete feature #8078

Merged
merged 23 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions modules/dqt/ajax/DeleteDoc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Data Querying Module
*
* PHP Version 5
*
* @category Data_Querying_Module
* @package Loris
* @author Loris Team <[email protected]>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/
require_once __DIR__ . '/../../../vendor/autoload.php';
$client = new NDB_Client();
$client->makeCommandLine();
$client->initialize(__DIR__ . "/../../../project/config.xml");
header("Content-Type: application/json");
$config = \NDB_Config::singleton();
$couchConfig = $config->getSetting('CouchDB');
$cdb = \NDB_Factory::singleton()->couchDB(
$couchConfig['dbName'],
$couchConfig['hostname'],
intval($couchConfig['port']),
$couchConfig['admin'],
$couchConfig['adminpass']
);
$docID = urlencode($_REQUEST['DocID']);

$results = $cdb->deleteDoc(
$docID
);
print json_encode($results);

2 changes: 1 addition & 1 deletion modules/dqt/ajax/saveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
': ' .
$_REQUEST['QueryName'];
}
$fields = json_decode($_REQUEST['Fields']);
$fields = json_decode(strval($_REQUEST['Fields']));
$cond = $_REQUEST['Filters'];
$baseDocument['Conditions'] = $cond;
$baseDocument['Fields'] = $fields;
Expand Down
2 changes: 1 addition & 1 deletion modules/dqt/css/dataquery.css
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ tr.statsReport:nth-child(even) {
}
.tableFieldsCell {
overflow-x: scroll;
max-width: 400px;
max-width: 280px;
min-height: 100px;
}
.tableFiltersCell {
Expand Down
2 changes: 2 additions & 0 deletions modules/dqt/jsx/react.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class DataQueryApp extends Component {
queryIDs: {
user: [],
shared: [],
author: [],
},
savedQueries: {},
queriesLoaded: false,
Expand Down Expand Up @@ -1325,6 +1326,7 @@ class DataQueryApp extends Component {
<SavedQueriesList
userQueries={this.state.queryIDs.user}
globalQueries={this.state.queryIDs.shared}
author={this.state.queryIDs.author}
queryDetails={this.state.savedQueries}
queriesLoaded={this.state.queriesLoaded}
onSelectQuery={this.loadSavedQuery}
Expand Down
55 changes: 52 additions & 3 deletions modules/dqt/jsx/react.savedqueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
import React, {useEffect, useState} from 'react';
import PropTypes from 'prop-types';
import swal from 'sweetalert2';

const ManageSavedQueryFilters = (props) => {
const [content, setContent] = useState(null);
Expand Down Expand Up @@ -70,7 +71,35 @@ const ManageSavedQueryFilters = (props) => {
const ManageSavedQueryRow = (props) => {
const [fieldsVisible, setFields] = useState(null);
const [filtersVisible, setFilters] = useState(null);

/**
* @deleteclick
*/
function publicquerydelete() {
const id = props.Query['_id'];
swal.fire({
title: 'Are you sure?',
text: 'You won\'t be able to revert this!',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
}).then((result) => {
if (result.value) {
let deleteurl = loris.BaseURL +
'/AjaxHelper.php?Module=dqt&script=DeleteDoc.php&DocID='
+ encodeURIComponent(id);
fetch(deleteurl, {
cache: 'no-cache',
credentials: 'same-origin',
}).then((resp) => resp.json())
.then(()=>{
location.reload();
swal.fire('delete Successful!', '', 'success');
});
}
});
};
useEffect(() => {
let fields = [];
let filters = [];
Expand Down Expand Up @@ -157,7 +186,21 @@ const ManageSavedQueryRow = (props) => {
setFilters(filters);
setFields(fields);
}, []);

let docName = props.Query.Meta['name'];
let docAuthor = docName.substring(0, docName.lastIndexOf(':'));
let btn = '';
if (props.author == docAuthor) {
btn = (
<button className='btn btn-danger'
onClick={()=> { // eslint-disable-line
publicquerydelete(); // eslint-disable-line
} // eslint-disable-line
} // eslint-disable-line
>
delete
</button>
);
}
return (
<tr>
<td>
Expand All @@ -175,6 +218,11 @@ const ManageSavedQueryRow = (props) => {
{filtersVisible}
</div>
</td>
<td>
<div className={'tableNameCell'}>
{btn}
</div>
</td>
</tr>
);
};
Expand All @@ -199,7 +247,6 @@ const SavedQueriesList = (props) => {
props.queryDetails[queryName].Conditions
);
};

if (props.queriesLoaded === false) {
return null;
}
Expand All @@ -222,6 +269,7 @@ const SavedQueriesList = (props) => {
<ManageSavedQueryRow key={name}
Name={queryName}
Query={query}
author={props.author}
/>
);
}
Expand All @@ -247,6 +295,7 @@ const SavedQueriesList = (props) => {
<th>Query Name</th>
<th>Fields</th>
<th>Filters</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
Expand Down
44 changes: 44 additions & 0 deletions modules/dqt/jsx/react.tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import React, {Component, useState} from 'react';
import PropTypes from 'prop-types';
import StaticDataTable from '../../../jsx/StaticDataTable';
import swal from 'sweetalert2';

const {jStat} = require('jstat');

/**
Expand Down Expand Up @@ -1116,6 +1118,35 @@ class ManageSavedQueryRow extends Component {
super(props);
this.state = {};
}
/**
* @deleteclick
*/
deleteclick() {
let id = this.props.Query['_id'];
swal.fire({
title: 'Are you sure?',
text: 'You won\'t be able to revert this!',
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
}).then((result) => {
if (result.value) {
let deleteurl = loris.BaseURL +
'/AjaxHelper.php?Module=dqt&script=DeleteDoc.php&DocID='
+ encodeURIComponent(id);
fetch(deleteurl, {
cache: 'no-cache',
credentials: 'same-origin',
}).then((resp) => resp.json())
.then(()=>{
location.reload();
swal.fire('delete Successful!', '', 'success');
});
}
});
}

/**
* Renders the React component.
Expand Down Expand Up @@ -1224,6 +1255,18 @@ class ManageSavedQueryRow extends Component {
{filters}
</div>
</td>
<td>
<div className={'tableNamesCell'}>
<button className='btn btn-danger'
onClick={()=> { // eslint-disable-line
this.deleteclick(); // eslint-disable-line
} // eslint-disable-line
} // eslint-disable-line
>
delete
</button>
</div>
</td>
</tr>
);
}
Expand Down Expand Up @@ -1296,6 +1339,7 @@ let ManageSavedQueriesTabPane = (props) => {
<th>Query Name</th>
<th>Fields</th>
<th>Filters</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
Expand Down
6 changes: 3 additions & 3 deletions modules/dqt/php/dqt_setup.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ class Dqt_Setup extends \NDB_Form implements RequestHandlerInterface
return $row['id'];
};

$usersavedNames = array_map($IDMapCallback, $usersaved);
$globalsavedNames = array_map($IDMapCallback, $globalsaved);

$usersavedNames = array_map($IDMapCallback, $usersaved);
$globalsavedNames = array_map($IDMapCallback, $globalsaved);
$data['savedqueries'] = [
'user' => $usersavedNames,
'shared' => $globalsavedNames,
'author' => $user->getUsername(),
];
$data['visits'] = \Utility::getVisitList();
// Note: StringStream since BinaryStream isn't in 23.0-release.
Expand Down
46 changes: 46 additions & 0 deletions tools/dqt_delete_saved_query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Data Querying Module
*
* PHP Version 7.4
*
* @category Data_Querying_Module
* @package Loris
* @author Loris Team <[email protected]>
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3
* @link https://www.github.com/aces/Loris/
*/
require_once __DIR__ . '/../vendor/autoload.php';
$client = new NDB_Client();
$client->makeCommandLine();
$client->initialize(__DIR__ . "/../project/config.xml");
header("Content-Type: application/json");
$config = \NDB_Config::singleton();
$couchConfig = $config->getSetting('CouchDB');
$cdb = \NDB_Factory::singleton()->couchDB(
$couchConfig['dbName'],
$couchConfig['hostname'],
intval($couchConfig['port']),
$couchConfig['admin'],
$couchConfig['adminpass']
);
echo "Deleting a saved query in DQT.\n";

$user = readline("Please input the author of the saved query:");
$name = readline("Please input the name of the saved query:");
$global = readline("If the saved query is global then input 'y':");
if ($global) {
$docID = urlencode("global:".$user."_".$name);
} else {
$docID = urlencode($user."_".$name);
}
$results = $cdb->deleteDoc(
$docID
);


if (json_encode($results) == "true") {
echo $name." has been deleted in DQT.\n";
} else {
echo "There is no query named ".$name." in DQT.\n";
};