Skip to content

Commit bedc3bd

Browse files
FiretawnyowlFiretawnyowl
and
Firetawnyowl
authored
Added tuples deleting by key + cs fix (#73)
implemented #50 index search truncate context --------- Co-authored-by: Firetawnyowl <selderelium@gmail.com>
1 parent bf9f47f commit bedc3bd

File tree

6 files changed

+102
-21
lines changed

6 files changed

+102
-21
lines changed

php/Job/Admin/Configuration.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ protected function getLatest()
5656
$tag = @json_decode(file_get_contents($url, false, $context))->tag_name;
5757
$timestamp = time();
5858

59-
file_put_contents($filename,
60-
'<' . '?php return ' . var_export(compact('tag', 'timestamp'), true) . ';'
61-
);
59+
$contents = '<' . '?php return ' . var_export(compact('tag', 'timestamp'), true) . ';';
60+
file_put_contents($filename, $contents);
6261

6362
return $tag;
6463
}

php/Job/Space/Job.php

+17-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,22 @@ public function getSpace(): Space
1717
return $this->spaceInstance;
1818
}
1919

20-
return $this->spaceInstance = $this->space
21-
? $this->getMapper()->getSchema()->getSpace($this->space)
22-
: throw new Exception('Space name is not defined');
20+
if (!$this->space) {
21+
throw new Exception('space name is not defined');
22+
}
23+
24+
return $this->spaceInstance = $this->getMapper()->getSchema()->getSpace($this->space);
25+
}
26+
27+
public function trimTail($arr): array
28+
{
29+
$trimArr = [];
30+
foreach ($arr as $value) {
31+
if ($value === null) {
32+
break;
33+
}
34+
$trimArr[] = $value;
35+
}
36+
return $trimArr;
2337
}
2438
}

php/Job/Space/Select.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@ class Select extends Job
1818

1919
public function run(): array
2020
{
21-
$key = [];
22-
foreach ($this->key as $value) {
23-
if ($value === null) {
24-
break;
25-
}
26-
$key[] = $value;
27-
}
21+
$key = $this->trimTail($this->key);
2822

2923
$data = null;
3024
$total = null;

php/Job/Space/Truncate.php

+25-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,37 @@
66

77
class Truncate extends Job
88
{
9+
public array $key = [];
10+
public ?int $index = null;
11+
912
public function run(): void
1013
{
1114
$space = $this->getSpace();
15+
1216
if ($space->getId() < 512) {
1317
throw new Exception('Disabled for system spaces');
1418
}
1519

16-
$this->getClient()->call('box.space.' . $space->getName() . ':truncate');
20+
if (count($this->key) == 0 || $this->index == null) {
21+
$this->getClient()->call('box.space.' . $space->getName() . ':truncate');
22+
} else {
23+
$this->getClient()->evaluate(
24+
'local space, index, key, iterator = ...
25+
box.begin()
26+
box.space[space].index[index]:pairs(key, {iterator=iterator})
27+
:each(function(tuple)
28+
local pk = {}
29+
for _, part in pairs(box.space[space].index[0].parts) do
30+
table.insert(pk, tuple[part.fieldno])
31+
end
32+
box.space[space]:delete(pk)
33+
end)
34+
box.commit()',
35+
$space->getName(),
36+
$this->index,
37+
$this->trimTail($this->key),
38+
$this->iterator
39+
);
40+
}
1741
}
1842
}

public/admin/js/Database/Spaces.js

+43-3
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,55 @@ Ext.define('Admin.Database.Spaces', {
7777
}
7878
},
7979

80-
truncateSpace(space) {
80+
keyEmptyCheck(key) {
81+
return !key || key.every(v => v == null);
82+
},
83+
84+
keyValidCheck(key) {
85+
var isValid = true;
86+
87+
if (this.keyEmptyCheck(key)) {
88+
isValid = false;
89+
}
90+
else {
91+
for (let i=0; i<key.length-1; i++) {
92+
if (key[i] == undefined && key[i+1] != undefined) {
93+
isValid = false;
94+
break;
95+
}
96+
}
97+
}
98+
99+
return isValid;
100+
},
101+
102+
truncateSpace(space, searchdata = undefined) {
103+
var params = this.spaceParams(space);
104+
105+
var message =
106+
'Are you sure to truncate space ' + space + '?<br/>' +
107+
'This operation can not be undone';
108+
109+
if (searchdata && searchdata.index >= 0) {
110+
if (!this.keyValidCheck(searchdata.key)) {
111+
Ext.Msg.alert('Warning!', 'Not valid key. Please, fill in all fields starting from the first.');
112+
return;
113+
}
114+
115+
Ext.apply(params, searchdata);
116+
message = 'Are you sure to delete tuples by index ' + searchdata.indexObj.name +
117+
' and key ' + searchdata.key + ' from space ' + space + '?<br/>' +
118+
'This operation can not be undone';
119+
}
120+
81121
Ext.MessageBox.confirm({
82122
title: 'Danger!',
83123
icon: Ext.MessageBox.WARNING,
84-
message: 'Are you sure to truncate space ' + space + '?<br/>This operation can not be undone',
124+
message: message,
85125
buttons: Ext.MessageBox.YESNO,
86126
callback: (answer) => {
87127
if (answer == 'yes') {
88-
dispatch('space.truncate', this.spaceParams(space))
128+
dispatch('space.truncate', params)
89129
.then(() => {
90130
this.refreshSpaces();
91131
this.up('database-tab').items.each(item => {

public/admin/js/Space/toolbar/Collection.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,29 @@ Ext.define('Admin.Space.toolbar.Collection', {
176176
disabled: true,
177177
menu: [],
178178
}, {
179-
text: 'Truncate',
179+
text: this.params.truncateButtonText || 'Truncate',
180180
iconCls: 'fa fa-trash',
181181
handler() {
182-
var space = this.up('grid').store.proxy.params.space;
182+
var params = this.up('grid').store.proxy.params;
183+
var space = params.space;
183184

184185
// > database tabs
185186
// > collection
186187
// > space tabs
187188
// > {collection}
188189

190+
var index = this.up('grid').indexes[params.index];
191+
var searchdata = {
192+
key: params.key,
193+
index: params.index,
194+
indexObj: index,
195+
iterator: params.iterator };
196+
189197
this.up('tabpanel').up('tabpanel')
190198
.down('[name=spaces]')
191-
.truncateSpace(space);
199+
.truncateSpace(space, searchdata);
200+
201+
this.up('toolbar-collection').refreshStore();
192202
},
193203
}, {
194204
iconCls: 'fa fa-download',
@@ -353,7 +363,7 @@ Ext.define('Admin.Space.toolbar.Collection', {
353363
return {
354364
text: index.name,
355365
handler: () => {
356-
var params = Ext.apply({ index: index.id }, this.up('space-tab').params);
366+
var params = Ext.apply({ index: index.id, truncateButtonText: 'Truncate rows' }, this.up('space-tab').params);
357367
var view = Ext.create('Admin.Space.Collection', {
358368
params: params,
359369
autoLoad: false,

0 commit comments

Comments
 (0)