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