Skip to content

Commit aa413da

Browse files
authored
Merge branch 'master' into addSchemaClearButton
2 parents 3cd05f0 + 67ddf0d commit aa413da

15 files changed

+662
-28
lines changed

_test/Bureaucracy.test.php

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
namespace dokuwiki\plugin\struct\test;
4+
5+
use dokuwiki\plugin\struct\meta;
6+
use dokuwiki\plugin\struct\meta\AccessTable;
7+
8+
/**
9+
* Tests for the integration with Bureaucracy plugin
10+
*
11+
* @group plugin_struct
12+
* @group plugins
13+
*
14+
*/
15+
class Bureaucracy_struct_test extends StructTest {
16+
17+
/** @var array alway enable the needed plugins */
18+
protected $pluginsEnabled = array('struct', 'sqlite', 'bureaucracy');
19+
20+
/** @var array of lookup data */
21+
protected $lookup = array();
22+
23+
public function setUp() {
24+
parent::setUp();
25+
26+
$this->loadSchemaJSON('bureaucracy_lookup', '', 0, true);
27+
$this->loadSchemaJSON('bureaucracy');
28+
29+
//insert some data to lookup
30+
for($i = 1; $i <= 10; ++$i) {
31+
$data = array(
32+
'lookup_first' => 'value first ' . $i,
33+
'lookup_second' => 'value second ' . $i
34+
);
35+
36+
$lookupData = AccessTable::byTableName('bureaucracy_lookup', 0);
37+
$lookupData->saveData($data);
38+
$this->lookup[] = $lookupData;
39+
}
40+
}
41+
42+
public function test_bureaucracy_lookup_replacement_empty() {
43+
//page created by bureaucracy
44+
$id = 'bureaucracy_lookup_replacement_empty';
45+
//id of template page
46+
$template_id = 'template';
47+
48+
//create template
49+
saveWikiText($template_id, 'Value:@@bureaucracy.lookup_select@@', 'summary');
50+
51+
//build form
52+
$fields = array();
53+
54+
$lookup_field = plugin_load('helper', 'struct_field');
55+
$lookup_field->opt['label'] = 'bureaucracy.lookup_select';
56+
//empty value
57+
$lookup_field->opt['value'] = '';
58+
//left pagename undefined
59+
//$lookup_field->opt['pagename'];
60+
61+
//$args are ommited in struct_field
62+
$lookup_field->initialize(array());
63+
$fields[] = $lookup_field;
64+
65+
//helper_plugin_bureaucracy_actiontemplate
66+
$actiontemplate = plugin_load('helper', 'bureaucracy_actiontemplate');
67+
$actiontemplate->run($fields, '', array($template_id, $id, '_'));
68+
69+
$page_content = io_readWikiPage(wikiFN($id), $id);
70+
71+
$this->assertEquals('Value:', $page_content);
72+
}
73+
74+
public function test_bureaucracy_lookup_replacement() {
75+
//page created by bureaucracy
76+
$id = 'bureaucracy_lookup_replacement';
77+
//id of template page
78+
$template_id = 'template';
79+
//pid of selected value
80+
$lookup_pid = $this->lookup[0]->getPid();
81+
//selected value
82+
$lookup_value = $this->lookup[0]->getData()['lookup_first']->getValue();
83+
84+
//create template
85+
saveWikiText($template_id, 'Value:@@bureaucracy.lookup_select@@', 'summary');
86+
87+
//build form
88+
$fields = array();
89+
90+
$lookup_field = plugin_load('helper', 'struct_field');
91+
$lookup_field->opt['label'] = 'bureaucracy.lookup_select';
92+
$lookup_field->opt['value'] = $lookup_pid;
93+
//left pagename undefined
94+
//$lookup_field->opt['pagename'];
95+
96+
//$args are ommited in struct_field
97+
$lookup_field->initialize(array());
98+
$fields[] = $lookup_field;
99+
100+
//helper_plugin_bureaucracy_actiontemplate
101+
102+
$actiontemplate = plugin_load('helper', 'bureaucracy_actiontemplate');
103+
$actiontemplate->run($fields, '', array($template_id, $id, '_'));
104+
105+
$page_content = io_readWikiPage(wikiFN($id), $id);
106+
107+
$this->assertEquals('Value:' . $lookup_value, $page_content);
108+
}
109+
}

_test/SearchConfigParameter.test.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,54 @@ public function test_sort() {
203203
$this->assertArrayNotHasKey('sort', $conf);
204204
$this->assertArrayNotHasKey(meta\SearchConfigParameters::$PARAM_SORT, $param);
205205
}
206+
207+
public function test_pagination() {
208+
global $INPUT;
209+
210+
$data = array(
211+
'schemas' => array(
212+
array('schema2', 'alias2'),
213+
),
214+
'cols' => array(
215+
'afirst'
216+
),
217+
'rownumbers' => '1',
218+
'limit' => '5',
219+
);
220+
221+
$R = new \Doku_Renderer_xhtml();
222+
// init with offset
223+
$INPUT->set(meta\SearchConfigParameters::$PARAM_OFFSET, 5);
224+
//$params[meta\SearchConfigParameters::$PARAM_OFFSET] = 25;
225+
$searchConfig = new meta\SearchConfig($data);
226+
$aggregationTable = new meta\AggregationTable('test_pagination', 'xhtml', $R, $searchConfig);
227+
$aggregationTable->render();
228+
$expect = '<div class="structaggregation"><div class="table"><table class="inline">
229+
<thead>
230+
<tr class="row0">
231+
<th class="col0">#</th><th data-field="schema2.afirst"><a href="/./doku.php?id=test_pagination&amp;ofs=5&amp;srt=schema2.afirst" class="" title="Sort by this column">afirst</a></th>
232+
</tr>
233+
</thead>
234+
<tbody>
235+
<tr class="row1" data-pid="page14"><td class="col0">6</td><td class="col1">page14 first data</td>
236+
</tr>
237+
<tr class="row2" data-pid="page15"><td class="col0">7</td><td class="col1">page15 first data</td>
238+
</tr>
239+
<tr class="row3" data-pid="page16"><td class="col0">8</td><td class="col1">page16 first data</td>
240+
</tr>
241+
<tr class="row4" data-pid="page17"><td class="col0">9</td><td class="col1">page17 first data</td>
242+
</tr>
243+
<tr class="row5" data-pid="page18"><td class="col0">10</td><td class="col1">page18 first data</td>
244+
</tr>
245+
</tbody>
246+
<tfoot>
247+
<tr class="row6">
248+
<th class="col0" colspan="2"><a href="/./doku.php?id=test_pagination" class="prev">Previous page</a><a href="/./doku.php?id=test_pagination&amp;ofs=10" class="next">Next page</a></th>
249+
</tr>
250+
</tfoot>
251+
</table></div>
252+
</div>';
253+
254+
$this->assertEquals($expect, $R->doc);
255+
}
206256
}

_test/json/bureaucracy.struct.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"structversion": "2017-07-11",
3+
"schema": "bureaucracy",
4+
"id": "2",
5+
"user": "",
6+
"config": {
7+
"allowed editors": "",
8+
"label": {
9+
"en": ""
10+
}
11+
},
12+
"columns": [
13+
{
14+
"colref": 1,
15+
"ismulti": false,
16+
"isenabled": true,
17+
"sort": 10,
18+
"label": "lookup_select",
19+
"class": "Lookup",
20+
"config": {
21+
"visibility": {
22+
"inpage": true,
23+
"ineditor": true
24+
},
25+
"schema": "bureaucracy_lookup",
26+
"field": "lookup_first",
27+
"label": {
28+
"en": ""
29+
},
30+
"hint": {
31+
"en": ""
32+
}
33+
}
34+
}
35+
]
36+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"structversion": "2017-07-11",
3+
"schema": "bureaucracy_lookup",
4+
"id": "1",
5+
"user": "",
6+
"config": {
7+
"allowed editors": "",
8+
"label": {
9+
"en": ""
10+
}
11+
},
12+
"columns": [
13+
{
14+
"colref": 1,
15+
"ismulti": false,
16+
"isenabled": true,
17+
"sort": 10,
18+
"label": "lookup_first",
19+
"class": "Text",
20+
"config": {
21+
"visibility": {
22+
"inpage": true,
23+
"ineditor": true
24+
},
25+
"prefix": "",
26+
"postfix": "",
27+
"label": {
28+
"en": ""
29+
},
30+
"hint": {
31+
"en": ""
32+
}
33+
}
34+
},
35+
{
36+
"colref": 2,
37+
"ismulti": false,
38+
"isenabled": true,
39+
"sort": 20,
40+
"label": "lookup_second",
41+
"class": "Text",
42+
"config": {
43+
"visibility": {
44+
"inpage": true,
45+
"ineditor": true
46+
},
47+
"prefix": "",
48+
"postfix": "",
49+
"label": {
50+
"en": ""
51+
},
52+
"hint": {
53+
"en": ""
54+
}
55+
}
56+
}
57+
]
58+
}

action/bureaucracy.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use dokuwiki\plugin\struct\meta\AccessTable;
1313
use dokuwiki\plugin\struct\meta\Assignments;
1414
use dokuwiki\plugin\struct\meta\Schema;
15+
use dokuwiki\plugin\struct\meta\Search;
1516

1617
/**
1718
* Handles bureaucracy additions
@@ -32,6 +33,7 @@ class action_plugin_struct_bureaucracy extends DokuWiki_Action_Plugin {
3233
* @return void
3334
*/
3435
public function register(Doku_Event_Handler $controller) {
36+
$controller->register_hook('PLUGIN_BUREAUCRACY_TEMPLATE_SAVE', 'BEFORE', $this, 'handle_lookup_fields');
3537
$controller->register_hook('PLUGIN_BUREAUCRACY_TEMPLATE_SAVE', 'AFTER', $this, 'handle_save');
3638
$controller->register_hook('PLUGIN_BUREAUCRACY_FIELD_UNKNOWN', 'BEFORE', $this, 'handle_schema');
3739
}
@@ -72,6 +74,47 @@ public function handle_schema(Doku_Event $event, $param) {
7274
return true;
7375
}
7476

77+
/**
78+
* Replace lookup fields placeholder's values
79+
*
80+
* @param Doku_Event $event event object by reference
81+
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this
82+
* handler was registered]
83+
* @return bool
84+
*/
85+
public function handle_lookup_fields(Doku_Event $event, $param) {
86+
foreach($event->data['fields'] as $field) {
87+
if(!is_a($field, 'helper_plugin_struct_field')) continue;
88+
if($field->column->getType()->getClass() != 'Lookup') continue;
89+
90+
$pid = $field->getParam('value');
91+
$config = $field->column->getType()->getConfig();
92+
93+
// find proper value
94+
// current Search implementation doesn't allow doing it using SQL
95+
$search = new Search();
96+
$search->addSchema($config['schema']);
97+
$search->addColumn($config['field']);
98+
$result = $search->execute();
99+
$pids = $search->getPids();
100+
$len = count($result);
101+
102+
$value = '';
103+
for($i = 0; $i < $len; $i++) {
104+
if ($pids[$i] == $pid) {
105+
$value = $result[$i][0]->getDisplayValue();
106+
break;
107+
}
108+
}
109+
110+
//replace previous value
111+
if ($value) {
112+
$event->data['values'][$field->column->getFullQualifiedLabel()] = $value;
113+
}
114+
}
115+
return true;
116+
}
117+
75118
/**
76119
* Save the struct data
77120
*
@@ -112,7 +155,8 @@ public function handle_save(Doku_Event $event, $param) {
112155
);
113156

114157
// trigger meta data rendering to set page title
115-
p_get_metadata($id);
158+
// expire the cache in order to correctly render the struct header on the first page visit
159+
p_get_metadata($id, array('cache' => 'expire'));
116160
}
117161
}
118162

admin/schemas.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
use dokuwiki\Form\Form;
1010
use dokuwiki\plugin\struct\meta\CSVExporter;
11-
use dokuwiki\plugin\struct\meta\CSVImporter;
11+
use dokuwiki\plugin\struct\meta\CSVLookupImporter;
12+
use dokuwiki\plugin\struct\meta\CSVPageImporter;
1213
use dokuwiki\plugin\struct\meta\Schema;
1314
use dokuwiki\plugin\struct\meta\SchemaBuilder;
1415
use dokuwiki\plugin\struct\meta\SchemaEditor;
@@ -80,7 +81,13 @@ public function handle() {
8081
if($table && $INPUT->bool('importcsv')) {
8182
if(isset($_FILES['csvfile']['tmp_name'])) {
8283
try {
83-
new CSVImporter($table, $_FILES['csvfile']['tmp_name']);
84+
if ($INPUT->bool('lookup')) {
85+
$csvImporter = new CSVLookupImporter($table, $_FILES['csvfile']['tmp_name']);
86+
} else {
87+
$csvImporter = new CSVPageImporter($table, $_FILES['csvfile']['tmp_name']);
88+
}
89+
$csvImporter->import();
90+
8491
msg($this->getLang('admin_csvdone'), 1);
8592
} catch(StructException $e) {
8693
msg(hsc($e->getMessage()), -1);
@@ -198,13 +205,11 @@ protected function html_json(Schema $schema) {
198205
$form->addButton('exportcsv', $this->getLang('btn_export'));
199206
$form->addFieldsetClose();
200207

201-
if($schema->isLookup()) {
202-
$form->addFieldsetOpen($this->getLang('admin_csvimport'));
203-
$form->addElement(new \dokuwiki\Form\InputElement('file', 'csvfile'));
204-
$form->addButton('importcsv', $this->getLang('btn_import'));
205-
$form->addHTML('<p><a href="https://www.dokuwiki.org/plugin:struct:csvimport">' . $this->getLang('admin_csvhelp') . '</a></p>');
206-
$form->addFieldsetClose();
207-
}
208+
$form->addFieldsetOpen($this->getLang('admin_csvimport'));
209+
$form->addElement(new \dokuwiki\Form\InputElement('file', 'csvfile'));
210+
$form->addButton('importcsv', $this->getLang('btn_import'));
211+
$form->addHTML('<p><a href="https://www.dokuwiki.org/plugin:struct:csvimport">' . $this->getLang('admin_csvhelp') . '</a></p>');
212+
$form->addFieldsetClose();
208213

209214
return $form->toHTML();
210215
}

all.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@media only screen and (max-width: @ini_tablet_width) {
1+
@media only screen and (max-width: 800px) {
22
#plugin__struct_output {
33
margin-right: 0;
44
}

0 commit comments

Comments
 (0)