Added support for default values in the DB
This commit is contained in:
parent
c41dc2cd1b
commit
392801f07a
|
@ -232,6 +232,7 @@ $utopia->get('/v1/database/collections/:collectionId/logs')
|
|||
$response->json($output);
|
||||
}
|
||||
);
|
||||
|
||||
$utopia->put('/v1/database/collections/:collectionId')
|
||||
->desc('Update Collection')
|
||||
->label('scope', 'collections.write')
|
||||
|
@ -416,6 +417,18 @@ $utopia->post('/v1/database/collections/:collectionId/documents')
|
|||
$data = $parentDocument->getArrayCopy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default collection values
|
||||
*/
|
||||
foreach ($collection->getAttribute('rules') as $key => $rule) {
|
||||
$key = (isset($rule['key'])) ? $rule['key'] : '';
|
||||
$default = (isset($rule['default'])) ? $rule['default'] : null;
|
||||
|
||||
if(!isset($data[$key])) {
|
||||
$data[$key] = $default;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$data = $projectDB->createDocument($data);
|
||||
} catch (AuthorizationException $exception) {
|
||||
|
|
|
@ -68,16 +68,20 @@
|
|||
<div class="margin-bottom-small margin-end-small text-align-end text-size-small"><span data-ls-bind="{{project-documents.sum}}"></span> documents found</div>
|
||||
|
||||
<div class="box margin-bottom y-scroll">
|
||||
<table class="vertical full">
|
||||
<table class="vertical">
|
||||
<thead>
|
||||
<tr data-ls-loop="project-collection.rules" data-ls-as="rule">
|
||||
<th data-ls-bind="{{rule.label}}"></th>
|
||||
<th width="160" data-ls-bind="{{rule.label}}"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody data-ls-loop="project-documents.documents" data-ls-as="node">
|
||||
<tr data-ls-loop="project-collection.rules" data-ls-as="rule">
|
||||
<td data-ls-attrs="data-title={{rule.label}}:">
|
||||
<a data-ls-attrs="href=/console/database/document?id={{node.$id}}&collection={{project-collection.$id}}&project={{router.params.project}}" data-ls-bind="{{node|documentLabel}}"></a>
|
||||
<a data-ls-attrs="href=/console/database/document?id={{node.$id}}&collection={{project-collection.$id}}&project={{router.params.project}}">
|
||||
<span data-ls-if="{{rule.type}} !== 'document'" data-ls-bind="{{node|documentLabel}}"></span>
|
||||
<span data-ls-if="{{rule.type}} == 'document' && {{rule.array}} && {{node|documentLabel}}">Linked Documents</span>
|
||||
<span data-ls-if="{{rule.type}} == 'document' && !{{rule.array}} && {{node|documentLabel}}" class="tag">Linked Document</span>
|
||||
</a>
|
||||
</th>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -388,7 +392,7 @@
|
|||
<script type="text/html" id="template-validation-text">
|
||||
<div class="margin-bottom">
|
||||
<label data-ls-attrs="for=rule-default-{{rule.$id}}">Default Value</label>
|
||||
<input name="default" type="text" data-ls-bind="{{rule.default}}" />
|
||||
<input name="default" type="text" data-ls-bind="{{rule.default}}" data-forms-text-direction />
|
||||
</div>
|
||||
</script>
|
||||
|
||||
|
@ -409,7 +413,7 @@
|
|||
<script type="text/html" id="template-validation-text">
|
||||
<div class="margin-bottom">
|
||||
<label data-ls-attrs="for=rule-default-{{rule.$id}}">Default Value</label>
|
||||
<input name="default" type="text" data-ls-bind="{{rule.default}}" />
|
||||
<input name="default" type="text" data-ls-bind="{{rule.default}}" data-forms-text-direction />
|
||||
</div>
|
||||
</script>
|
||||
|
||||
|
|
|
@ -57,8 +57,8 @@
|
|||
</form>
|
||||
</div>
|
||||
<div class="col span-4 sticky-top">
|
||||
|
||||
<div data-ls-if="({{router.params.id}})">
|
||||
|
||||
<div data-ls-if="({{project-document.$id}})">
|
||||
<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" />
|
||||
|
@ -70,7 +70,7 @@
|
|||
<input type="text" autocomplete="off" placeholder="" data-ls-bind="{{project-collection.$id}}" disabled data-forms-copy class="margin-bottom-no" />
|
||||
</div>
|
||||
|
||||
<div data-ls-if="({{router.params.id}})">
|
||||
<div data-ls-if="({{project-document.$id}})">
|
||||
<form name="database.deleteDocument" class="margin-bottom"
|
||||
data-analytics-event="submit"
|
||||
data-analytics-category="console"
|
||||
|
@ -78,7 +78,7 @@
|
|||
data-service="database.deleteDocument"
|
||||
data-event="submit"
|
||||
data-param-collection-id="{{router.params.collection}}"
|
||||
data-param-document-id="{{router.params.id}}"
|
||||
data-param-document-id="{{project-document.$id}}"
|
||||
data-confirm="Are you sure you want to delete this document?"
|
||||
data-success="alert,trigger,redirect"
|
||||
data-success-param-alert-text="Document deleted successfully"
|
||||
|
@ -94,22 +94,8 @@
|
|||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li data-state="/console/database/document/api?id={{router.params.id}}&collection={{router.params.collection}}&project={{router.params.project}}">
|
||||
<h2>API</h2>
|
||||
|
||||
<div class="row responsive">
|
||||
<div class="col span-3">
|
||||
<ul>
|
||||
<li>
|
||||
<a data-ls-attrs="href=/console/database/document/api?id={{router.params.id}}&collection={{router.params.collection}}&project={{router.params.project}}#api-response"><i class="icon-angle-circled-right margin-start-negative-tiny margin-end-tiny"></i> Response</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col span-9">
|
||||
<h3 id="api-response">Response</h3>
|
||||
<input type="hidden" data-ls-bind="{{project-document}}" data-forms-code />
|
||||
</div>
|
||||
</div>
|
||||
<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>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -200,7 +186,7 @@ $list = [
|
|||
</script>
|
||||
|
||||
<script type="text/html" id="template-url-form<?php echo $mode['key']; ?>">
|
||||
<input data-ls-attrs="name={{rule.key}},{{rule.required|documentRequired}}" type="url" data-ls-bind="<?php echo $mode['bind']; ?>" />
|
||||
<input data-ls-attrs="name={{rule.key}},{{rule.required|documentRequired}}" type="url" data-ls-bind="<?php echo $mode['bind']; ?>" placeholder="https://example.com" />
|
||||
|
||||
<div class="preview" data-ls-if="(<?php echo $mode['bind']; ?>.toString() !== '')">
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
data-scope="sdk"
|
||||
data-success="alert,reset,redirect,trigger"
|
||||
data-success-param-alert-text="Collection created successfully"
|
||||
data-success-param-redirect-url="/console/database/collection/settings?id={{serviceData.$id}}&project={{router.params.project}}"
|
||||
data-success-param-redirect-url="/console/database/collection/update?id={{serviceData.$id}}&project={{router.params.project}}"
|
||||
data-success-param-trigger-events="database.createCollection"
|
||||
data-failure="alert"
|
||||
data-failure-param-alert-text="Failed to create collection"
|
||||
|
|
2
public/dist/styles/default-ltr.css
vendored
2
public/dist/styles/default-ltr.css
vendored
File diff suppressed because one or more lines are too long
2
public/dist/styles/default-rtl.css
vendored
2
public/dist/styles/default-rtl.css
vendored
File diff suppressed because one or more lines are too long
|
@ -96,6 +96,7 @@ table {
|
|||
td, th {
|
||||
//text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue