Skip to content

Commit a241014

Browse files
committed
Revert "Remove vue2 scope builder"
1 parent 45a086f commit a241014

32 files changed

+13114
-12
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Atk4\Ui\Demos;
6+
7+
use Atk4\Ui\Form;
8+
use Atk4\Ui\Grid;
9+
10+
/** @var \Atk4\Ui\App $app */
11+
require_once __DIR__ . '/../init-app.php';
12+
13+
$q = [
14+
'logicalOperator' => 'AND',
15+
'children' => [
16+
[
17+
'type' => 'query-builder-rule',
18+
'query' => [
19+
'rule' => Product::hinting()->fieldName()->product_category_id,
20+
'operator' => 'equals',
21+
'operand' => 'Product Category Id',
22+
'value' => '3',
23+
],
24+
],
25+
[
26+
'type' => 'query-builder-rule',
27+
'query' => [
28+
'rule' => Product::hinting()->fieldName()->product_sub_category_id,
29+
'operator' => 'equals',
30+
'operand' => 'Product Sub Category Id',
31+
'value' => '6',
32+
],
33+
],
34+
],
35+
];
36+
$scope = Form\Control\ScopeBuilder::queryToScope($q);
37+
38+
$product = new Product($app->db);
39+
40+
$g = Grid::addTo($app);
41+
$g->setModel($product->addCondition($scope));

demos/_unit-test/scope-builder.php

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Atk4\Ui\Demos;
6+
7+
use Atk4\Data\Model\Scope;
8+
use Atk4\Data\Model\Scope\Condition;
9+
use Atk4\Ui\Form;
10+
use Atk4\Ui\Header;
11+
use Atk4\Ui\View;
12+
13+
/** @var \Atk4\Ui\App $app */
14+
require_once __DIR__ . '/../init-app.php';
15+
16+
$model = new Stat($app->db, ['caption' => 'Demo Stat']);
17+
18+
$project = new Condition($model->fieldName()->project_name, Condition::OPERATOR_REGEXP, '[a-zA-Z]');
19+
$brazil = new Condition($model->fieldName()->client_country_iso, '=', 'BR');
20+
$start = new Condition($model->fieldName()->start_date, '=', '2020-10-22');
21+
$finish = new Condition($model->fieldName()->finish_time, '!=', '22:22');
22+
$isCommercial = new Condition($model->fieldName()->is_commercial, '0');
23+
$budget = new Condition($model->fieldName()->project_budget, '>=', '1000');
24+
$currency = new Condition($model->fieldName()->currency, 'USD');
25+
26+
$scope = Scope::createAnd($project, $brazil, $start);
27+
$orScope = Scope::createOr($finish, $isCommercial, $currency);
28+
29+
$model->addCondition($budget);
30+
$model->scope()->add($scope);
31+
$model->scope()->add($orScope);
32+
33+
$form = Form::addTo($app);
34+
35+
$form->addControl('qb', [Form\Control\ScopeBuilder::class, 'model' => $model], ['type' => 'object']);
36+
37+
$form->onSubmit(function (Form $form) use ($model) {
38+
$message = $form->model->get('qb')->toWords($model);
39+
$view = (new View(['name' => false]))->addClass('atk-scope-builder-response');
40+
$view->invokeInit();
41+
42+
$view->set($message);
43+
44+
return $view;
45+
});
46+
47+
$expectedWord = <<<'EOF'
48+
Project Budget is greater or equal to '1000'
49+
and (Project Name is regular expression '[a-zA-Z]'
50+
and Client Country Iso is equal to 'BR' ('Brazil') and Start Date is equal to '2020-10-22')
51+
and (Finish Time is not equal to '22:22' or Is Commercial is equal to '0' or Currency is equal to 'USD')
52+
EOF;
53+
54+
$statModelForHinting = new Stat($app->db);
55+
$expectedInput = json_encode(json_decode(<<<"EOF"
56+
{
57+
"logicalOperator": "AND",
58+
"children": [
59+
{
60+
"type": "query-builder-rule",
61+
"query": {
62+
"rule": "{$statModelForHinting->fieldName()->project_budget}",
63+
"operator": ">=",
64+
"value": "1000",
65+
"option": null
66+
}
67+
},
68+
{
69+
"type": "query-builder-group",
70+
"query": {
71+
"logicalOperator": "AND",
72+
"children": [
73+
{
74+
"type": "query-builder-rule",
75+
"query": {
76+
"rule": "{$statModelForHinting->fieldName()->project_name}",
77+
"operator": "matches regular expression",
78+
"value": "[a-zA-Z]",
79+
"option": null
80+
}
81+
},
82+
{
83+
"type": "query-builder-rule",
84+
"query": {
85+
"rule": "{$statModelForHinting->fieldName()->client_country_iso}",
86+
"operator": "equals",
87+
"value": "BR",
88+
"option": {
89+
"key": "BR",
90+
"text": "Brazil",
91+
"value": "BR"
92+
}
93+
}
94+
},
95+
{
96+
"type": "query-builder-rule",
97+
"query": {
98+
"rule": "{$statModelForHinting->fieldName()->start_date}",
99+
"operator": "is on",
100+
"value": "2020-10-22",
101+
"option": null
102+
}
103+
}
104+
]
105+
}
106+
},
107+
{
108+
"type": "query-builder-group",
109+
"query": {
110+
"logicalOperator": "OR",
111+
"children": [
112+
{
113+
"type": "query-builder-rule",
114+
"query": {
115+
"rule": "{$statModelForHinting->fieldName()->finish_time}",
116+
"operator": "is not on",
117+
"value": "22:22",
118+
"option": null
119+
}
120+
},
121+
{
122+
"type": "query-builder-rule",
123+
"query": {
124+
"rule": "{$statModelForHinting->fieldName()->is_commercial}",
125+
"operator": "equals",
126+
"value": "0",
127+
"option": null
128+
}
129+
},
130+
{
131+
"type": "query-builder-rule",
132+
"query": {
133+
"rule": "{$statModelForHinting->fieldName()->currency}",
134+
"operator": "equals",
135+
"value": "USD",
136+
"option": null
137+
}
138+
}
139+
]
140+
}
141+
}
142+
]
143+
}
144+
EOF, true));
145+
146+
Header::addTo($app, ['Word:']);
147+
View::addTo($app, ['element' => 'p', 'content' => $expectedWord])->addClass('atk-expected-word-result');
148+
149+
Header::addTo($app, ['Input:']);
150+
View::addTo($app, ['element' => 'p', 'content' => $expectedInput])->addClass('atk-expected-input-result');

demos/form-control/scope-builder.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Atk4\Ui\Demos;
6+
7+
use Atk4\Ui\Form;
8+
9+
/** @var \Atk4\Ui\App $app */
10+
require_once __DIR__ . '/../init-app.php';
11+
12+
$model = new Stat($app->db, ['caption' => 'Demo Stat']);
13+
$model->addCondition($model->fieldName()->finish_time, '=', '22:12:00');
14+
$model->addCondition($model->fieldName()->start_date, '=', '2020-10-22');
15+
16+
$form = Form::addTo($app);
17+
18+
$form->addControl('qb', [Form\Control\ScopeBuilder::class, 'model' => $model, 'options' => ['debug' => true]]);
19+
20+
$form->onSubmit(function (Form $form) use ($model) {
21+
return "Scope selected:\n\n" . $form->model->get('qb')->toWords($model);
22+
});

demos/init-app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public static function get_class(\Closure $createAnonymousClassFx): string
126126
$layout->addMenuItem(['File Upload'], [$path . 'upload'], $menu);
127127
$layout->addMenuItem(['Multi Line'], [$path . 'multiline'], $menu);
128128
$layout->addMenuItem(['Tree Selector'], [$path . 'tree-item-selector'], $menu);
129+
$layout->addMenuItem(['Scope Builder'], [$path . 'scope-builder'], $menu);
129130

130131
$path = $demosUrl . 'collection/';
131132
$menu = $layout->addMenuGroup(['Data Collection', 'icon' => 'table']);

js/package-lock.json

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"mitt": "^3.0.0",
3030
"vue": "^3.2.41",
3131
"vue-flatpickr-component": "^10.0.0",
32-
"vue-fomantic-ui": "^0.13.0"
32+
"vue-fomantic-ui": "^0.13.0",
33+
"vue-query-builder": "github:TheAustinG/vue-query-builder#2f5c4408e3"
3334
},
3435
"devDependencies": {
3536
"@babel/cli": "^7.19.3",

js/src/services/vue.service.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class VueService {
8181
app.component('AtkItemSearch', asyncComponentFactory('AtkItemSearch', () => import(/* webpackChunkName: 'atk-vue-item-search' */'../vue-components/item-search.component')));
8282
app.component('AtkMultiline', asyncComponentFactory('AtkMultiline', () => import(/* webpackChunkName: 'atk-vue-multiline' */'../vue-components/multiline/multiline.component')));
8383
app.component('AtkTreeItemSelector', asyncComponentFactory('AtkTreeItemSelector', () => import(/* webpackChunkName: 'atk-vue-tree-item-selector' */'../vue-components/tree-item-selector/tree-item-selector.component')));
84+
app.component('AtkQueryBuilder', asyncComponentFactory('AtkQueryBuilder', () => import(/* webpackChunkName: 'atk-vue-query-builder' */'../vue-components/query-builder/query-builder.component.vue')));
8485
}
8586

8687
/**

0 commit comments

Comments
 (0)