Merge pull request #338 from nextcloud/fix/maxStringLengths
Provide DBs max string lengths as InitialState
This commit is contained in:
commit
78b53cbb8e
|
@ -64,6 +64,18 @@ class PageController extends Controller {
|
||||||
/** @var FormsService */
|
/** @var FormsService */
|
||||||
private $formService;
|
private $formService;
|
||||||
|
|
||||||
|
/** @var Array
|
||||||
|
*
|
||||||
|
* Maximum String lengths, the database is set to store.
|
||||||
|
*/
|
||||||
|
private $maxStringLengths = [
|
||||||
|
'formTitle' => 256,
|
||||||
|
'formDescription' => 2048,
|
||||||
|
'questionText' => 2048,
|
||||||
|
'optionText' => 1024,
|
||||||
|
'answerText' => 2048,
|
||||||
|
];
|
||||||
|
|
||||||
public function __construct(string $appName,
|
public function __construct(string $appName,
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
IGroupManager $groupManager,
|
IGroupManager $groupManager,
|
||||||
|
@ -96,6 +108,7 @@ class PageController extends Controller {
|
||||||
public function index(): TemplateResponse {
|
public function index(): TemplateResponse {
|
||||||
Util::addScript($this->appName, 'forms');
|
Util::addScript($this->appName, 'forms');
|
||||||
Util::addStyle($this->appName, 'forms');
|
Util::addStyle($this->appName, 'forms');
|
||||||
|
$this->initialStateService->provideInitialState($this->appName, 'maxStringLengths', $this->maxStringLengths);
|
||||||
return new TemplateResponse($this->appName, 'main');
|
return new TemplateResponse($this->appName, 'main');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +121,7 @@ class PageController extends Controller {
|
||||||
public function createForm(): TemplateResponse {
|
public function createForm(): TemplateResponse {
|
||||||
Util::addScript($this->appName, 'forms');
|
Util::addScript($this->appName, 'forms');
|
||||||
Util::addStyle($this->appName, 'forms');
|
Util::addStyle($this->appName, 'forms');
|
||||||
|
$this->initialStateService->provideInitialState($this->appName, 'maxStringLengths', $this->maxStringLengths);
|
||||||
return new TemplateResponse($this->appName, 'main');
|
return new TemplateResponse($this->appName, 'main');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +136,7 @@ class PageController extends Controller {
|
||||||
public function cloneForm(): TemplateResponse {
|
public function cloneForm(): TemplateResponse {
|
||||||
Util::addScript($this->appName, 'forms');
|
Util::addScript($this->appName, 'forms');
|
||||||
Util::addStyle($this->appName, 'forms');
|
Util::addStyle($this->appName, 'forms');
|
||||||
|
$this->initialStateService->provideInitialState($this->appName, 'maxStringLengths', $this->maxStringLengths);
|
||||||
return new TemplateResponse($this->appName, 'main');
|
return new TemplateResponse($this->appName, 'main');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +149,7 @@ class PageController extends Controller {
|
||||||
public function editForm(): TemplateResponse {
|
public function editForm(): TemplateResponse {
|
||||||
Util::addScript($this->appName, 'forms');
|
Util::addScript($this->appName, 'forms');
|
||||||
Util::addStyle($this->appName, 'forms');
|
Util::addStyle($this->appName, 'forms');
|
||||||
|
$this->initialStateService->provideInitialState($this->appName, 'maxStringLengths', $this->maxStringLengths);
|
||||||
return new TemplateResponse($this->appName, 'main');
|
return new TemplateResponse($this->appName, 'main');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,6 +198,7 @@ class PageController extends Controller {
|
||||||
|
|
||||||
Util::addScript($this->appName, 'submit');
|
Util::addScript($this->appName, 'submit');
|
||||||
$this->initialStateService->provideInitialState($this->appName, 'form', $this->formsService->getForm($form->getId()));
|
$this->initialStateService->provideInitialState($this->appName, 'form', $this->formsService->getForm($form->getId()));
|
||||||
|
$this->initialStateService->provideInitialState($this->appName, 'maxStringLengths', $this->maxStringLengths);
|
||||||
return new TemplateResponse($this->appName, 'main', [], $renderAs);
|
return new TemplateResponse($this->appName, 'main', [], $renderAs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
:placeholder="t('forms', 'Answer number {index}', { index: index + 1 })"
|
:placeholder="t('forms', 'Answer number {index}', { index: index + 1 })"
|
||||||
:value="answer.text"
|
:value="answer.text"
|
||||||
class="question__input"
|
class="question__input"
|
||||||
maxlength="256"
|
:maxlength="maxOptionLength"
|
||||||
minlength="1"
|
minlength="1"
|
||||||
type="text"
|
type="text"
|
||||||
@input="onInput"
|
@input="onInput"
|
||||||
|
@ -50,6 +50,10 @@ export default {
|
||||||
type: Number,
|
type: Number,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
maxOptionLength: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
class="question__header-title"
|
class="question__header-title"
|
||||||
type="text"
|
type="text"
|
||||||
minlength="1"
|
minlength="1"
|
||||||
maxlength="256"
|
:maxlength="maxQuestionLength"
|
||||||
required
|
required
|
||||||
@input="onInput"
|
@input="onInput"
|
||||||
@keyup="onTitleChange">
|
@keyup="onTitleChange">
|
||||||
|
@ -101,6 +101,10 @@ export default {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
maxQuestionLength: {
|
||||||
|
type: Number,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
v-bind.sync="$attrs"
|
v-bind.sync="$attrs"
|
||||||
:text="text"
|
:text="text"
|
||||||
:edit.sync="edit"
|
:edit.sync="edit"
|
||||||
|
:max-question-length="maxStringLengths.questionText"
|
||||||
@delete="onDelete"
|
@delete="onDelete"
|
||||||
@update:text="onTitleChange">
|
@update:text="onTitleChange">
|
||||||
<div class="question__content">
|
<div class="question__content">
|
||||||
|
@ -35,7 +36,7 @@
|
||||||
:required="true /* TODO: implement required option */"
|
:required="true /* TODO: implement required option */"
|
||||||
:value="values[0]"
|
:value="values[0]"
|
||||||
class="question__text"
|
class="question__text"
|
||||||
maxlength="1024"
|
:maxlength="maxStringLengths.answerText"
|
||||||
minlength="1"
|
minlength="1"
|
||||||
@input="onInput"
|
@input="onInput"
|
||||||
@keydown="autoSizeText" />
|
@keydown="autoSizeText" />
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
v-bind.sync="$attrs"
|
v-bind.sync="$attrs"
|
||||||
:text="text"
|
:text="text"
|
||||||
:edit.sync="edit"
|
:edit.sync="edit"
|
||||||
|
:max-question-length="maxStringLengths.questionText"
|
||||||
@delete="onDelete"
|
@delete="onDelete"
|
||||||
@update:text="onTitleChange">
|
@update:text="onTitleChange">
|
||||||
<ul class="question__content">
|
<ul class="question__content">
|
||||||
|
@ -57,6 +58,7 @@
|
||||||
ref="input"
|
ref="input"
|
||||||
:answer="answer"
|
:answer="answer"
|
||||||
:index="index"
|
:index="index"
|
||||||
|
:max-option-length="maxStringLengths.optionText"
|
||||||
@add="addNewEntry"
|
@add="addNewEntry"
|
||||||
@delete="deleteAnswer"
|
@delete="deleteAnswer"
|
||||||
@update:answer="updateAnswer"
|
@update:answer="updateAnswer"
|
||||||
|
@ -64,12 +66,11 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<li v-if="(edit && !isLastEmpty) || hasNoAnswer" class="question__item">
|
<li v-if="(edit && !isLastEmpty) || hasNoAnswer" class="question__item">
|
||||||
<!-- TODO: properly choose max length -->
|
|
||||||
<input
|
<input
|
||||||
:aria-label="t('forms', 'Add a new answer')"
|
:aria-label="t('forms', 'Add a new answer')"
|
||||||
:placeholder="t('forms', 'Add a new answer')"
|
:placeholder="t('forms', 'Add a new answer')"
|
||||||
class="question__input"
|
class="question__input"
|
||||||
maxlength="256"
|
:maxlength="maxStringLengths.optionText"
|
||||||
minlength="1"
|
minlength="1"
|
||||||
type="text"
|
type="text"
|
||||||
@click="addNewEntry">
|
@click="addNewEntry">
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
v-bind.sync="$attrs"
|
v-bind.sync="$attrs"
|
||||||
:text="text"
|
:text="text"
|
||||||
:edit.sync="edit"
|
:edit.sync="edit"
|
||||||
|
:max-question-length="maxStringLengths.questionText"
|
||||||
@delete="onDelete"
|
@delete="onDelete"
|
||||||
@update:text="onTitleChange">
|
@update:text="onTitleChange">
|
||||||
<div class="question__content">
|
<div class="question__content">
|
||||||
|
@ -35,7 +36,7 @@
|
||||||
:required="true /* TODO: implement required option */"
|
:required="true /* TODO: implement required option */"
|
||||||
:value="values[0]"
|
:value="values[0]"
|
||||||
class="question__input"
|
class="question__input"
|
||||||
maxlength="256"
|
:maxlength="maxStringLengths.answerText"
|
||||||
minlength="1"
|
minlength="1"
|
||||||
type="text"
|
type="text"
|
||||||
@input="onInput">
|
@input="onInput">
|
||||||
|
|
|
@ -57,6 +57,14 @@ export default {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Database-Restrictions
|
||||||
|
*/
|
||||||
|
maxStringLengths: {
|
||||||
|
type: Object,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
id="form-title"
|
id="form-title"
|
||||||
v-model="form.title"
|
v-model="form.title"
|
||||||
:minlength="0"
|
:minlength="0"
|
||||||
|
:maxlength="maxStringLengths.formTitle"
|
||||||
:placeholder="t('forms', 'Form title')"
|
:placeholder="t('forms', 'Form title')"
|
||||||
:required="true"
|
:required="true"
|
||||||
autofocus
|
autofocus
|
||||||
|
@ -61,6 +62,7 @@
|
||||||
id="form-desc"
|
id="form-desc"
|
||||||
ref="description"
|
ref="description"
|
||||||
v-model="form.description"
|
v-model="form.description"
|
||||||
|
:maxlength="maxStringLengths.formDescription"
|
||||||
:placeholder="t('forms', 'Description')"
|
:placeholder="t('forms', 'Description')"
|
||||||
@change="autoSizeDescription"
|
@change="autoSizeDescription"
|
||||||
@keydown="autoSizeDescription"
|
@keydown="autoSizeDescription"
|
||||||
|
@ -83,6 +85,7 @@
|
||||||
:key="question.id"
|
:key="question.id"
|
||||||
:model="answerTypes[question.type]"
|
:model="answerTypes[question.type]"
|
||||||
:index="index + 1"
|
:index="index + 1"
|
||||||
|
:max-string-lengths="maxStringLengths"
|
||||||
v-bind.sync="question"
|
v-bind.sync="question"
|
||||||
@delete="deleteQuestion(question)" />
|
@delete="deleteQuestion(question)" />
|
||||||
</Draggable>
|
</Draggable>
|
||||||
|
@ -112,6 +115,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { emit } from '@nextcloud/event-bus'
|
import { emit } from '@nextcloud/event-bus'
|
||||||
import { generateUrl } from '@nextcloud/router'
|
import { generateUrl } from '@nextcloud/router'
|
||||||
|
import { loadState } from '@nextcloud/initial-state'
|
||||||
import { showError } from '@nextcloud/dialogs'
|
import { showError } from '@nextcloud/dialogs'
|
||||||
import axios from '@nextcloud/axios'
|
import axios from '@nextcloud/axios'
|
||||||
import debounce from 'debounce'
|
import debounce from 'debounce'
|
||||||
|
@ -151,6 +155,8 @@ export default {
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
maxStringLengths: loadState('forms', 'maxStringLengths'),
|
||||||
|
|
||||||
questionMenuOpened: false,
|
questionMenuOpened: false,
|
||||||
answerTypes,
|
answerTypes,
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@
|
||||||
:read-only="true"
|
:read-only="true"
|
||||||
:model="answerTypes[question.type]"
|
:model="answerTypes[question.type]"
|
||||||
:index="index + 1"
|
:index="index + 1"
|
||||||
|
:max-string-lengths="maxStringLengths"
|
||||||
v-bind="question"
|
v-bind="question"
|
||||||
:values.sync="answers[question.id]" />
|
:values.sync="answers[question.id]" />
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -97,6 +98,7 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
form: loadState('forms', 'form'),
|
form: loadState('forms', 'form'),
|
||||||
|
maxStringLengths: loadState('forms', 'maxStringLengths'),
|
||||||
answerTypes,
|
answerTypes,
|
||||||
answers: {},
|
answers: {},
|
||||||
loading: false,
|
loading: false,
|
||||||
|
|
Loading…
Reference in a new issue