From 90807c35d6899410d41f7796fcb1a4af6ddd2024 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 20 Apr 2020 21:47:26 +0300 Subject: [PATCH] Moved form to server side --- app/controllers/web/console.php | 41 +++- app/init.php | 2 +- app/views/console/database/document.phtml | 217 +++--------------- app/views/console/database/form.phtml | 75 ++++++ app/views/console/database/rules/array.phtml | 37 +++ .../console/database/rules/boolean.phtml | 7 + .../console/database/rules/document.phtml | 24 ++ app/views/console/database/rules/email.phtml | 6 + app/views/console/database/rules/ip.phtml | 6 + .../console/database/rules/numeric.phtml | 7 + app/views/console/database/rules/text.phtml | 6 + app/views/console/database/rules/url.phtml | 6 + .../console/database/rules/wildcard.phtml | 6 + app/views/console/storage/index.phtml | 2 +- app/views/layouts/strip.phtml | 1 + public/dist/scripts/app-all.js | 8 +- public/dist/scripts/app.js | 8 +- public/dist/styles/default-ltr.css | 2 +- public/dist/styles/default-rtl.css | 2 +- public/scripts/dependencies/litespeed.js | 2 +- public/scripts/routes.js | 5 + public/scripts/views/ui/modal.js | 3 +- public/styles/comps/modal.less | 6 + public/styles/forms.less | 1 + 24 files changed, 280 insertions(+), 200 deletions(-) create mode 100644 app/views/console/database/form.phtml create mode 100644 app/views/console/database/rules/array.phtml create mode 100644 app/views/console/database/rules/boolean.phtml create mode 100644 app/views/console/database/rules/document.phtml create mode 100644 app/views/console/database/rules/email.phtml create mode 100644 app/views/console/database/rules/ip.phtml create mode 100644 app/views/console/database/rules/numeric.phtml create mode 100644 app/views/console/database/rules/text.phtml create mode 100644 app/views/console/database/rules/url.phtml create mode 100644 app/views/console/database/rules/wildcard.phtml create mode 100644 app/views/layouts/strip.phtml diff --git a/app/controllers/web/console.php b/app/controllers/web/console.php index 5b959e6ed..86102a8a6 100644 --- a/app/controllers/web/console.php +++ b/app/controllers/web/console.php @@ -8,8 +8,12 @@ use Utopia\View; use Utopia\Config\Config; use Utopia\Domains\Domain; use Appwrite\Database\Database; +use Appwrite\Database\Validator\Authorization; use Appwrite\Database\Validator\UID; use Appwrite\Storage\Storage; +use Utopia\Validator\Numeric; +use Utopia\Validator\Range; +use Utopia\Validator\Text; $utopia->init(function () use ($layout, $utopia) { $layout @@ -79,6 +83,7 @@ $utopia->get('/console/account') ; $layout + ->setPath(__DIR__.'/../../views/layouts/strip.phtml') ->setParam('title', 'Account - '.APP_NAME) ->setParam('body', $page); }); @@ -178,7 +183,7 @@ $utopia->get('/console/database') }); $utopia->get('/console/database/collection') - ->desc('Platform console project settings') + ->desc('Platform console project database collection') ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($layout, $projectDB) { @@ -190,7 +195,7 @@ $utopia->get('/console/database/collection') }); $utopia->get('/console/database/document') - ->desc('Platform console project settings') + ->desc('Platform console project database document') ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($layout, $projectDB) { @@ -201,6 +206,38 @@ $utopia->get('/console/database/document') ->setParam('body', $page); }); +$utopia->get('/console/database/form') + ->desc('Platform console project database form') + ->label('permission', 'public') + ->label('scope', 'console') + ->param('collectionId', '', function () { return new UID(); }, 'Collection unique ID.') + ->param('namespace', 'project-document', function () { return new Text(256); }, 'Namespace for vars.', true) + ->param('key', 'data', function () { return new Text(256); }, 'Object main key.', true) + ->param('parent', 1, function () { return new Range(0, 1); }, 'Is parent?.', true) + ->action(function ($collectionId, $namespace, $key, $parent) use ($layout, $projectDB) { + + Authorization::disable(); + $collection = $projectDB->getDocument($collectionId, false); + Authorization::reset(); + + if (empty($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) { + throw new Exception('Collection not found', 404); + } + + $page = new View(__DIR__.'/../../views/console/database/form.phtml'); + + $page + ->setParam('collection', $collection) + ->setParam('namespace', $namespace) + ->setParam('key', $key) + ->setParam('parent', $parent) + ; + + $layout + ->setParam('title', APP_NAME.' - Database Form') + ->setParam('body', $page); + }); + $utopia->get('/console/storage') ->desc('Platform console project settings') ->label('permission', 'public') diff --git a/app/init.php b/app/init.php index 7bf97d9d9..9d3fdbdd9 100644 --- a/app/init.php +++ b/app/init.php @@ -32,7 +32,7 @@ const APP_EMAIL_SECURITY = 'security@localhost.test'; // Default security email const APP_USERAGENT = APP_NAME.'-Server v%s. Please report abuse at %s'; const APP_MODE_ADMIN = 'admin'; const APP_PAGING_LIMIT = 15; -const APP_CACHE_BUSTER = 87; +const APP_CACHE_BUSTER = 88; const APP_VERSION_STABLE = '0.5.3'; const APP_STORAGE_UPLOADS = '/storage/uploads'; const APP_STORAGE_CACHE = '/storage/cache'; diff --git a/app/views/console/database/document.phtml b/app/views/console/database/document.phtml index 1186bd0d5..65d209076 100644 --- a/app/views/console/database/document.phtml +++ b/app/views/console/database/document.phtml @@ -1,4 +1,3 @@ -
+ +
+ +
- - - '', - 'bind' => '{{project-document|documentLabel}}', - ], - [ - 'key' => '-array', - 'bind' => '{{node}}', - ], - [ - 'key' => '-child', - 'bind' => '{{project-document|documentLabel}}.{{rule.key}}{{childRule.key}}', - ], -]; -?> - - - - - - - - - - - - - - - - - - - - - -
\ No newline at end of file diff --git a/app/views/console/database/form.phtml b/app/views/console/database/form.phtml new file mode 100644 index 000000000..85929127e --- /dev/null +++ b/app/views/console/database/form.phtml @@ -0,0 +1,75 @@ +getParam('collection', null); +$rules = $collection->getAttribute('rules', []); +$key = $this->getParam('key', 'data'); +$parent = $this->getParam('parent', true); +$namespace = $this->getParam('namespace', 'project-document'); +?> + + + + + + +
+ + + + + + +
\ No newline at end of file diff --git a/app/views/console/database/rules/array.phtml b/app/views/console/database/rules/array.phtml new file mode 100644 index 000000000..59ebc39fe --- /dev/null +++ b/app/views/console/database/rules/array.phtml @@ -0,0 +1,37 @@ +getParam('key', ''); +$required = $this->getParam('required', ''); +$comp = $this->getParam('comp', ''); +$namespace = $this->getParam('namespace', ''); + +$comp->setParam('namespace', 'node.'); +?> + + required data-cast-to="array-empty"> + + \ No newline at end of file diff --git a/app/views/console/database/rules/boolean.phtml b/app/views/console/database/rules/boolean.phtml new file mode 100644 index 000000000..2e809d85a --- /dev/null +++ b/app/views/console/database/rules/boolean.phtml @@ -0,0 +1,7 @@ +getParam('key', ''); +$required = $this->getParam('required', ''); +$namespace = $this->getParam('namespace', ''); +?> + + required class="margin-bottom-no" /> \ No newline at end of file diff --git a/app/views/console/database/rules/document.phtml b/app/views/console/database/rules/document.phtml new file mode 100644 index 000000000..8cdb076e9 --- /dev/null +++ b/app/views/console/database/rules/document.phtml @@ -0,0 +1,24 @@ +getParam('key', ''); +$array = $this->getParam('array', false); +$required = $this->getParam('required', ''); +$namespace = $this->getParam('namespace', ''); +?> + +
+ +
+ +
+
+
\ No newline at end of file diff --git a/app/views/console/database/rules/email.phtml b/app/views/console/database/rules/email.phtml new file mode 100644 index 000000000..94a8915f9 --- /dev/null +++ b/app/views/console/database/rules/email.phtml @@ -0,0 +1,6 @@ +getParam('key', ''); +$required = $this->getParam('required', ''); +$namespace = $this->getParam('namespace', ''); +?> + required class="margin-bottom-no"> \ No newline at end of file diff --git a/app/views/console/database/rules/ip.phtml b/app/views/console/database/rules/ip.phtml new file mode 100644 index 000000000..eab629015 --- /dev/null +++ b/app/views/console/database/rules/ip.phtml @@ -0,0 +1,6 @@ +getParam('key', ''); +$required = $this->getParam('required', ''); +$namespace = $this->getParam('namespace', ''); +?> + required class="margin-bottom-no"> \ No newline at end of file diff --git a/app/views/console/database/rules/numeric.phtml b/app/views/console/database/rules/numeric.phtml new file mode 100644 index 000000000..2f74331cf --- /dev/null +++ b/app/views/console/database/rules/numeric.phtml @@ -0,0 +1,7 @@ +getParam('key', ''); +$required = $this->getParam('required', ''); +$namespace = $this->getParam('namespace', ''); +?> + + required class="margin-bottom-no" /> \ No newline at end of file diff --git a/app/views/console/database/rules/text.phtml b/app/views/console/database/rules/text.phtml new file mode 100644 index 000000000..e3723a812 --- /dev/null +++ b/app/views/console/database/rules/text.phtml @@ -0,0 +1,6 @@ +getParam('key', ''); +$required = $this->getParam('required', ''); +$namespace = $this->getParam('namespace', ''); +?> + required /> \ No newline at end of file diff --git a/app/views/console/database/rules/url.phtml b/app/views/console/database/rules/url.phtml new file mode 100644 index 000000000..0696fb891 --- /dev/null +++ b/app/views/console/database/rules/url.phtml @@ -0,0 +1,6 @@ +getParam('key', ''); +$required = $this->getParam('required', ''); +$namespace = $this->getParam('namespace', ''); +?> + required class="margin-bottom-no"> \ No newline at end of file diff --git a/app/views/console/database/rules/wildcard.phtml b/app/views/console/database/rules/wildcard.phtml new file mode 100644 index 000000000..ad38997db --- /dev/null +++ b/app/views/console/database/rules/wildcard.phtml @@ -0,0 +1,6 @@ +getParam('key', ''); +$required = $this->getParam('required', ''); +$namespace = $this->getParam('namespace', ''); +?> + \ No newline at end of file diff --git a/app/views/console/storage/index.phtml b/app/views/console/storage/index.phtml index 8ba7f544a..970d87f4d 100644 --- a/app/views/console/storage/index.phtml +++ b/app/views/console/storage/index.phtml @@ -111,7 +111,7 @@ $fileLimitHuman = $this->getParam('fileLimitHuman', 0); -