2020-04-23 03:25:00 +00:00
<?php
2020-04-25 20:33:35 +00:00
2020-04-23 03:25:00 +00:00
use Utopia\View;
2020-04-25 20:33:35 +00:00
use Appwrite\Database\Validator\Authorization;
2020-04-23 03:25:00 +00:00
$collection = $this->getParam('collection', null);
2020-04-25 20:33:35 +00:00
$db = $this->getParam('db', null);
2020-04-24 11:24:04 +00:00
$rules = $collection->getAttribute('rules', []);
2020-04-25 20:33:35 +00:00
$namespace = 'project-document';
2020-04-27 18:36:21 +00:00
$collections = [];
2020-04-23 03:25:00 +00:00
?>
2020-04-27 18:36:21 +00:00
<?php foreach ( $rules as $rule ) :
$key = (isset($rule['key'])) ? $rule['key'] : '';
$label = (isset($rule['label'])) ? $rule['label'] : '';
$type = (isset($rule['type'])) ? $rule['type'] : '';
$list = (isset($rule['list'])) ? $rule['list'] : false;
$array = (isset($rule['array'])) ? $rule['array'] : false;
if($type !== 'document') {
continue;
}
?>
<?php foreach ( $list as $item ) :
if($item === $collection->getId()) {
continue; // Do not allow rec recrusion
}
Authorization::disable(); //TODO Try and avoid calling the DB from the template
$childCollection = $db->getDocument($item, false);
Authorization::reset();
if(!$childCollection->getId()) {
continue;
}
$collections[$childCollection->getId()] = $childCollection->getAttribute('name');
?>
< form class = "margin-bottom-no"
data-analytics-event="submit"
data-analytics-category="console"
data-analytics-label="Added Child Document"
data-service="container.path"
data-event="collection-child-<?php echo $this -> escape ( $namespace . '.' . $key ); ?> -<?php echo $this -> escape ( $childCollection -> getId ()); ?> "
data-scope="window.ls"
data-success="reset">
< input type = "hidden" name = "path" value = " <?php echo $this -> escape ( $namespace . '.' . $key ); ?> " />
< input type = "hidden" name = "type" value = "append" / >
< fieldset name = "value" data-cast-to = "object" >
< input name = "$id" type = "hidden" value = "" / >
< input name = "$collection" type = "hidden" value = " <?php echo $this -> escape ( $childCollection -> getId ()); ?> " />
< / fieldset >
< / form >
< script type = "text/html" id = "collection- <?php echo ( $array ) ? 'array-' : '' ; ?><?php echo $this -> escape ( $childCollection -> getId ()); ?> " >
<?php
$comp = new View(__DIR__.'/form.phtml');
$comp
->setParam('collection', $childCollection)
->setParam('namespace', ($array) ? 'node' : $namespace.'.'.$key)
->setParam('key', $key)
->setParam('array', $array)
->setParam('parent', 0)
;
echo $comp->render();
?>
< / script >
<?php endforeach ; ?>
<?php endforeach ; ?>
<?php foreach ( $rules as $rule ) :
$key = (isset($rule['key'])) ? $rule['key'] : '';
$label = (isset($rule['label'])) ? $rule['label'] : '';
$type = (isset($rule['type'])) ? $rule['type'] : '';
$list = (isset($rule['list'])) ? $rule['list'] : false;
$array = (isset($rule['array'])) ? $rule['array'] : false;
if(!$array) {
continue;
}
?>
< ul data-ls-loop = " <?php echo $this -> escape ( $namespace . '.' . $key ); ?> " data-ls-as = "xxx" >
< li >
< form
data-service="container.path"
data-event="splice-<?php echo $this -> escape ( $namespace . '.' . $key ); ?> -{{$index}}"
data-scope="window.ls"
data-success="reset">
< input type = "hidden" name = "path" value = " <?php echo $this -> escape ( $namespace . '.' . $key ); ?> " />
< input type = "hidden" name = "type" value = "splice" / >
< input type = "hidden" name = "value" data-ls-bind = "{{$index}}" / >
< / form >
< / li >
< / ul >
<?php endforeach ; ?>
2020-03-16 18:41:56 +00:00
< div
data-service="database.getCollection"
data-param-collection-id="{{router.params.collection}}"
data-scope="sdk"
data-event="load,database.updateCollection"
data-name="project-collection">
2020-03-29 19:38:15 +00:00
< div
data-service="database.getDocument"
data-param-collection-id="{{router.params.collection}}"
data-param-document-id="{{router.params.id}}"
data-scope="sdk"
2020-04-25 20:33:35 +00:00
data-event="load,database.updateDocument"
2020-03-29 19:38:15 +00:00
data-name="project-document"
data-success="default">
2020-03-16 18:41:56 +00:00
2020-03-29 19:38:15 +00:00
< div class = "cover" >
< h1 class = "zone xl margin-bottom-large" >
2020-04-23 03:25:00 +00:00
< a data-ls-attrs = "href=/console/database/collection?id={{router.params.collection}}&project={{router.params.project}}" class = "back text-size-small" > < i class = "icon-left-open" > < / i > < span data-ls-bind = "{{project-collection.name}}" > Collection< / span > < / a >
2020-03-16 18:41:56 +00:00
2020-03-29 19:38:15 +00:00
< br / >
2020-03-16 18:41:56 +00:00
2020-04-17 03:15:13 +00:00
< span data-ls-if = "({{project-document.$id}})" data-ls-bind = "Update Document" > < / span >
< span data-ls-if = "(!{{project-document.$id}})" data-ls-bind = "New Document" > < / span >
2020-03-29 19:38:15 +00:00
< / h1 >
< / div >
2020-03-16 18:41:56 +00:00
2020-04-20 18:47:26 +00:00
< div data-ui-modal class = "modal width-large box close" data-button-hide = "on" data-open-event = "open-json" >
< button type = "button" class = "close pull-end" data-ui-modal-close = "" > < i class = "icon-cancel" > < / i > < / button >
2020-04-21 08:29:09 +00:00
< h2 > JSON View< / h2 >
2020-04-20 18:47:26 +00:00
< div class = "margin-bottom" >
< input type = "hidden" data-ls-bind = "{{project-document}}" data-forms-code / >
< / div >
< button data-ui-modal-close = "" type = "button" class = "reverse" > Cancel< / button >
< / div >
2020-04-27 18:36:21 +00:00
< div class = "zone xl margin-bottom-no" >
2020-03-29 19:38:15 +00:00
< ul class = "phases clear" data-ui-phases data-selected = "{{router.params.tab}}" >
< li data-state = "/console/database/document?id={{router.params.id}}&collection={{router.params.collection}}&project={{router.params.project}}" >
< h2 > Update< / h2 >
< div class = "row responsive margin-top-negative" >
< div class = "col span-8 margin-bottom" >
< form
data-analytics-event="submit"
data-analytics-category="console"
data-analytics-label="Update Database Document"
2020-04-01 21:41:29 +00:00
data-service="{{|documentAction}}"
2020-04-17 22:19:02 +00:00
data-name="project-document"
2020-03-29 19:38:15 +00:00
data-scope="sdk"
data-event="submit"
2020-04-25 20:33:35 +00:00
data-success="alert,trigger{{|documentSuccess}}"
2020-03-29 19:38:15 +00:00
data-success-param-alert-text="Updated document successfully"
2020-04-25 20:33:35 +00:00
data-success-param-trigger-events="database.updateDocument"
data-success-param-redirect-url="/console/database/document?id={{serviceData.$id}}& collection={{router.params.collection}}& project={{router.params.project}}"
2020-03-29 19:38:15 +00:00
data-failure="alert"
data-failure-param-alert-text="Failed to update document"
data-failure-param-alert-classname="error">
< label > < / label >
< div class = "box" >
2020-04-24 11:24:04 +00:00
<?php if ( empty ( $rules )) : ?>
< div class = "margin-bottom-xl margin-top-xl margin-end margin-start text-align-center" >
2020-04-25 20:33:35 +00:00
< h4 class = "text-fade text-size-small" > No attribute rules added yet.< br / > < br / > < a data-ls-attrs = "href=/console/database/collection/settings?id={{router.params.collection}}&project={{router.params.project}}" > Update Collection< / a > < / h4 >
2020-04-24 11:24:04 +00:00
< / div >
<?php else : ?>
<?php
$comp = new View(__DIR__.'/form.phtml');
$comp
->setParam('collection', $collection)
2020-04-27 18:36:21 +00:00
->setParam('collections', $collections)
2020-04-25 20:33:35 +00:00
->setParam('namespace', $namespace)
2020-04-24 11:24:04 +00:00
->setParam('key', 'data')
->setParam('parent', 1)
;
echo $comp->render();
?>
< div class = "toggle margin-bottom" data-ls-ui-open >
< i class = "icon-plus pull-end margin-top-tiny" > < / i >
< i class = "icon-minus pull-end margin-top-tiny" > < / i >
< h3 class = "margin-bottom-large" > Permissions< / h3 >
< label for = "collection-read" > Read Access < span class = "text-size-small" > (< a data-ls-attrs = "href={{env.HOME}}/docs/permissions" target = "_blank" > Learn more< / a > )< / span > < / label >
< input type = "hidden" id = "collection-read" name = "read" data-forms-tags data-cast-to = "json" data-ls-bind = "{{project-document.$permissions.read}}" placeholder = "User ID, Team ID or Role" / >
< label for = "collection-write" > Write Access < span class = "text-size-small" > (< a data-ls-attrs = "href={{env.HOME}}/docs/permissions" target = "_blank" > Learn more< / a > )< / label >
< input type = "hidden" id = "collection-write" name = "write" data-forms-tags data-cast-to = "json" data-ls-bind = "{{project-collection.$permissions.write}}" placeholder = "User ID, Team ID or Role" / >
< / div >
< button data-ls-if = "({{project-document.$id}})" > Update< / button >
< button data-ls-if = "(!{{project-document.$id}})" > Create< / button >
<?php endif ; ?>
2020-03-16 18:41:56 +00:00
< / div >
2020-03-29 19:38:15 +00:00
< / form >
< / div >
< div class = "col span-4 sticky-top" >
2020-04-18 13:57:28 +00:00
< div data-ls-if = "({{project-document.$id}})" >
2020-03-29 19:38:15 +00:00
< label > Document ID< / label >
< div class = "input-copy margin-bottom" >
< input type = "text" autocomplete = "off" placeholder = "" data-ls-bind = "{{project-document.$id}}" disabled data-forms-copy class = "margin-bottom-no" / >
< / div >
2020-03-16 18:41:56 +00:00
< / div >
2020-03-29 19:38:15 +00:00
< label > Collection ID< / label >
2020-03-16 18:41:56 +00:00
< div class = "input-copy margin-bottom" >
2020-03-29 19:38:15 +00:00
< input type = "text" autocomplete = "off" placeholder = "" data-ls-bind = "{{project-collection.$id}}" disabled data-forms-copy class = "margin-bottom-no" / >
2020-03-16 18:41:56 +00:00
< / div >
2020-04-20 18:47:26 +00:00
< ul class = "margin-bottom-large text-fade text-size-small" >
2020-04-27 18:36:21 +00:00
< li class = "margin-bottom-small" > < i class = "icon-angle-circled-right margin-start-tiny margin-end-tiny" > < / i > < button data-ls-ui-trigger = "open-json" class = "link text-size-small" > View as JSON< / button > < / li >
2020-04-20 18:47:26 +00:00
< / ul >
2020-04-18 13:57:28 +00:00
< div data-ls-if = "({{project-document.$id}})" >
2020-04-01 21:41:29 +00:00
< form name = "database.deleteDocument" class = "margin-bottom"
data-analytics-event="submit"
data-analytics-category="console"
data-analytics-label="Delete Collection Document"
data-service="database.deleteDocument"
data-event="submit"
data-param-collection-id="{{router.params.collection}}"
2020-04-18 13:57:28 +00:00
data-param-document-id="{{project-document.$id}}"
2020-04-01 21:41:29 +00:00
data-confirm="Are you sure you want to delete this document?"
data-success="alert,trigger,redirect"
data-success-param-alert-text="Document deleted successfully"
data-success-param-trigger-events="database.deleteDocument"
data-success-param-redirect-url="/console/database/collection?id={{router.params.collection}}& project={{router.params.project}}"
data-failure="alert"
data-failure-param-alert-text="Failed to delete collection"
data-failure-param-alert-classname="error">
< button type = "submit" class = "danger fill" > Delete Document< / button >
< / form >
< / div >
2020-03-16 18:41:56 +00:00
< / div >
< / div >
2020-03-29 19:38:15 +00:00
< / li >
2020-04-18 13:57:28 +00:00
< li data-ls-if = "{{project-document.$id}}" data-state = "/console/database/document/activity?id={{router.params.id}}&collection={{router.params.collection}}&project={{router.params.project}}" >
< h2 > Activity< / h2 >
2020-03-29 19:38:15 +00:00
< / li >
< / ul >
< / div >
2020-03-16 18:41:56 +00:00
< / div >
2020-04-28 08:35:51 +00:00
< / div >
< div data-ui-modal class = "modal width-large box close" data-button-hide = "on" data-open-event = "open-file-serach" data-close-event = "none" >
< button type = "button" class = "close pull-end" data-ui-modal-close = "" > < i class = "icon-cancel" > < / i > < / button >
< h2 > File Search< / h2 >
< form class = "search margin-bottom-large"
data-service="storage.listFiles"
data-event="submit"
data-param-search="{{router.params.search}}"
data-param-limit="<?php echo APP_PAGING_LIMIT ; ?> "
data-param-offset=""
data-param-order-type="DESC"
data-scope="sdk"
data-name="project-files"
data-success="state"
data-success-param-state-keys="search,offset">
< input name = "search" id = "searchFiles" type = "search" autocomplete = "off" placeholder = "Search" class = "margin-bottom-no" data-ls-bind = "{{router.params.search}}" >
< / form >
< div
data-service="storage.listFiles"
data-event="load,storage.createFile,storage.updateFile,storage.deleteFile"
data-param-search="{{router.params.search}}"
data-param-limit="<?php echo APP_PAGING_LIMIT ; ?> "
data-param-offset="{{router.params.offset}}"
data-param-order-type="DESC"
data-scope="sdk"
data-name="project-files">
< div data-ls-if = "0 == {{project-files.sum}}" class = "margin-bottom" >
< h3 class = "margin-bottom-small text-bold" > No Files Found< / h3 >
< p class = "margin-bottom-no" > Try a different search term.< / p >
< / div >
< div data-ls-if = "0 != {{project-files.sum}}" >
< div >
< table class = "vertical margin-bottom" >
< thead >
< tr >
< th width = "40" > < / th >
< th > Filename< / th >
< th width = "160" > Type< / th >
< th width = "100" > Size< / th >
< th width = "100" > Created< / th >
< / tr >
< / thead >
< tbody data-ls-loop = "project-files.files" data-ls-as = "file" >
< tr >
< td class = "hide" >
< img src = "" data-ls-attrs = "src=//{{env.DOMAIN}}/v1/storage/files/{{file.$id}}/preview?width=65&height=65&project={{router.params.project}}&mode=admin" class = "pull-start avatar" width = "30" height = "30" loading = "lazy" / >
< / td >
< td data-title = "Name: " class = "text-one-liner" >
< span data-ls-bind = "{{file.name}}" class = "text-fade text-size-small" > < / span >
< / td >
< td data-title = "Type: " >
< span data-ls-bind = "{{file.mimeType}}" class = "text-fade text-size-small" > < / span >
< / td >
< td data-title = "Size: " >
< span class = "text-fade text-size-small" data-ls-bind = "{{file.sizeOriginal|humanFileSize}}" > < / span >
< / td >
< td data-title = "Created: " >
< span class = "text-fade text-size-small" data-ls-bind = "{{file.dateCreated|date-text}}" > < / span >
< / td >
< / tr >
< / tbody >
< / table >
< / div >
< / div >
< / div >
< div class = "clear text-align-center paging" >
< form
data-service="storage.listFiles"
data-event="submit"
data-param-search="{{router.params.search}}"
data-param-limit="<?php echo APP_PAGING_LIMIT ; ?> "
data-param-order-type="DESC"
data-scope="sdk"
data-name="project-files"
data-success="state"
data-success-param-state-keys="search,offset">
< button name = "offset" data-paging-back data-offset = "{{router.params.offset}}" data-sum = "{{project-files.sum}}" class = "margin-end round small" aria-label = "Back" > < i class = "icon-left-open" > < / i > < / button >
< / form >
< span data-ls-bind = "{{router.params.offset|pageCurrent}} / {{project-files.sum|pageTotal}}" > < / span >
< form
data-service="storage.listFiles"
data-event="submit"
data-param-search="{{router.params.search}}"
data-param-limit="<?php echo APP_PAGING_LIMIT ; ?> "
data-param-order-type="DESC"
data-scope="sdk"
data-name="project-files"
data-success="state"
data-success-param-state-keys="search,offset">
< button name = "offset" data-paging-next data-offset = "{{router.params.offset}}" data-sum = "{{project-files.sum}}" class = "margin-start round small" aria-label = "Next" > < i class = "icon-right-open" > < / i > < / button >
< / form >
< / div >
2020-04-27 18:36:21 +00:00
< / div >