Skip to content

Commit

Permalink
feat!: add multi file upload
Browse files Browse the repository at this point in the history
This replaces the single file upload and will enable the user to upload
multiple files at once.

BREAKING CHANGE: This requires the caluma backend version v8.0.0-beta.12
or later.
  • Loading branch information
derrabauke committed Aug 4, 2022
1 parent 807c280 commit 48db5ac
Show file tree
Hide file tree
Showing 34 changed files with 399 additions and 328 deletions.
8 changes: 4 additions & 4 deletions packages/core/addon/-private/possible-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
"DateQuestion",
"TableQuestion",
"FormQuestion",
"FileQuestion",
"FilesQuestion",
"StaticQuestion",
"CalculatedFloatQuestion",
"ActionButtonQuestion",
Expand All @@ -35,15 +35,15 @@ export default {
"DateQuestion",
"TableQuestion",
"FormQuestion",
"FileQuestion",
"FilesQuestion",
"StaticQuestion",
"StringAnswer",
"ListAnswer",
"IntegerAnswer",
"FloatAnswer",
"DateAnswer",
"TableAnswer",
"FileAnswer",
"FilesAnswer",
"File",
"CalculatedFloatQuestion",
"ActionButtonQuestion",
Expand All @@ -62,7 +62,7 @@ export default {
"FloatAnswer",
"DateAnswer",
"TableAnswer",
"FileAnswer",
"FilesAnswer",
],
Task: ["SimpleTask", "CompleteWorkflowFormTask", "CompleteTaskFormTask"],
DynamicQuestion: ["DynamicChoiceQuestion", "DynamicMultipleChoiceQuestion"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import saveDefaultStringAnswerMutation from "@projectcaluma/ember-form-builder/g
import saveDefaultTableAnswerMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-default-table-answer.graphql";
import saveDynamicChoiceQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-dynamic-choice-question.graphql";
import saveDynamicMultipleChoiceQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-dynamic-multiple-choice-question.graphql";
import saveFileQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-file-question.graphql";
import saveFilesQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-files-question.graphql";
import saveFloatQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-float-question.graphql";
import saveFormQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-form-question.graphql";
import saveIntegerQuestionMutation from "@projectcaluma/ember-form-builder/gql/mutations/save-integer-question.graphql";
Expand All @@ -53,7 +53,7 @@ export const TYPES = {
DynamicChoiceQuestion: saveDynamicChoiceQuestionMutation,
TableQuestion: saveTableQuestionMutation,
FormQuestion: saveFormQuestionMutation,
FileQuestion: saveFileQuestionMutation,
FilesQuestion: saveFilesQuestionMutation,
StaticQuestion: saveStaticQuestionMutation,
DateQuestion: saveDateQuestionMutation,
CalculatedFloatQuestion: saveCalculatedFloatQuestionMutation,
Expand Down Expand Up @@ -335,7 +335,7 @@ export default class CfbFormEditorQuestion extends Component {
};
}

_getFileQuestionInput(changeset) {
_getFilesQuestionInput(changeset) {
return {
hintText: changeset.get("hintText"),
};
Expand Down
6 changes: 3 additions & 3 deletions packages/form-builder/addon/gql/fragments/field.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fragment SimpleQuestion on Question {
calcExpression
hintText
}
... on FileQuestion {
... on FilesQuestion {
hintText
}
... on ActionButtonQuestion {
Expand Down Expand Up @@ -216,8 +216,8 @@ fragment SimpleAnswer on Answer {
... on ListAnswer {
listValue: value
}
... on FileAnswer {
fileValue: value {
... on FilesAnswer {
filesValue: value {
id
uploadUrl
downloadUrl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#import QuestionInfo from '../fragments/question-info.graphql'

mutation SaveFileQuestion($input: SaveFileQuestionInput!) {
saveFileQuestion(input: $input) {
mutation SaveFilesQuestion($input: SaveFilesQuestionInput!) {
saveFilesQuestion(input: $input) {
question {
id
...QuestionInfo
... on FileQuestion {
... on FilesQuestion {
hintText
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ query FormEditorQuestion($slug: String!) {
calcExpression
hintText
}
... on FileQuestion {
... on FilesQuestion {
hintText
}
... on ActionButtonQuestion {
Expand Down
2 changes: 1 addition & 1 deletion packages/form-builder/addon/validations/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default {
hintText: or(
validateType("FormQuestion", true),
validateType("StaticQuestion", true),
validateType("FileQuestion", true),
validateType("FilesQuestion", true),
validateLength({ max: 1024, allowBlank: true })
),
integerMinValue: or(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ module("Integration | Component | cfb-form-editor/question", function (hooks) {
this.server.create("form", { slug: "test-form" });

this.set("afterSubmit", (question) => {
assert.strictEqual(question.__typename, "FileQuestion");
assert.strictEqual(question.__typename, "FilesQuestion");
assert.strictEqual(question.label, "Label");
assert.strictEqual(question.slug, "slug");

Expand All @@ -526,7 +526,7 @@ module("Integration | Component | cfb-form-editor/question", function (hooks) {
hbs`<CfbFormEditor::Question @form='test-form' @onAfterSubmit={{this.afterSubmit}}/>`
);

await fillIn("[name=__typename]", "FileQuestion");
await fillIn("[name=__typename]", "FilesQuestion");
await fillIn("[name=label]", "Label");
await fillIn("[name=slug]", "slug");

Expand Down
2 changes: 1 addition & 1 deletion packages/form-builder/translations/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ caluma:
TextareaQuestion: "Text (mehrzeilig)"
TableQuestion: "Tabelle"
FormQuestion: "Formular"
FileQuestion: "Datei"
FilesQuestion: "Dateien"
StaticQuestion: "Nichtinteraktiver Inhalt"
DateQuestion: "Datum"
DynamicMultipleChoiceQuestion: "Dynamische Mehrfachauswahl"
Expand Down
2 changes: 1 addition & 1 deletion packages/form-builder/translations/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ caluma:
TextareaQuestion: "Textarea"
TableQuestion: "Table"
FormQuestion: "Form"
FileQuestion: "File"
FilesQuestion: "Files"
StaticQuestion: "Non-interactive content"
DateQuestion: "Date"
DynamicMultipleChoiceQuestion: "Dynamic choices"
Expand Down
2 changes: 1 addition & 1 deletion packages/form-builder/translations/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ caluma:
TextareaQuestion: "Texte (plusieurs lignes)"
TableQuestion: "Tableau"
FormQuestion: "Formulaire"
FileQuestion: "Fichier"
FilesQuestion: "Fichiers"
StaticQuestion: "Contenu non interactif"
DateQuestion: "Date"
DynamicMultipleChoiceQuestion: "Sélection multiple dynamique"
Expand Down
10 changes: 5 additions & 5 deletions packages/form/addon/components/cf-field-value.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
month="2-digit"
year="numeric"
}}
{{else if (has-question-type @field.question "file")}}
{{#if @field.answer.value}}
{{else if (has-question-type @field.question "files")}}
{{#each @field.answer.value as |file|}}
<UkButton
@color="link"
@label={{@field.answer.value.name}}
@onClick={{fn this.download @field.answer.raw.id}}
@label={{file.name}}
@onClick={{fn this.download file.id}}
/>
{{/if}}
{{/each}}
{{else}}
{{@field.answer.value}}
{{/if}}
11 changes: 6 additions & 5 deletions packages/form/addon/components/cf-field-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ import { action } from "@ember/object";
import Component from "@glimmer/component";
import { queryManager } from "ember-apollo-client";

import getFileAnswerInfoQuery from "@projectcaluma/ember-form/gql/queries/fileanswer-info.graphql";
import getFilesAnswerInfoQuery from "@projectcaluma/ember-form/gql/queries/filesanswer-info.graphql";

export default class CfFieldValueComponent extends Component {
@queryManager apollo;

@action
async download(id) {
const { downloadUrl } = await this.apollo.query(
const files = await this.apollo.query(
{
query: getFileAnswerInfoQuery,
variables: { id },
query: getFilesAnswerInfoQuery,
variables: { id: this.args.field.answer.raw.id },
fetchPolicy: "network-only",
},
"node.fileValue"
"node.value"
);

const { downloadUrl } = files?.find((file) => file.id === id);
if (downloadUrl) {
window.open(downloadUrl, "_blank");
}
Expand Down
4 changes: 2 additions & 2 deletions packages/form/addon/components/cf-field/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Component from "@glimmer/component";
import ActionButtonComponent from "@projectcaluma/ember-form/components/cf-field/input/action-button";
import CheckboxComponent from "@projectcaluma/ember-form/components/cf-field/input/checkbox";
import DateComponent from "@projectcaluma/ember-form/components/cf-field/input/date";
import FileComponent from "@projectcaluma/ember-form/components/cf-field/input/file";
import FilesComponent from "@projectcaluma/ember-form/components/cf-field/input/files";
import FloatComponent from "@projectcaluma/ember-form/components/cf-field/input/float";
import IntegerComponent from "@projectcaluma/ember-form/components/cf-field/input/integer";
import RadioComponent from "@projectcaluma/ember-form/components/cf-field/input/radio";
Expand All @@ -20,7 +20,7 @@ const COMPONENT_MAPPING = {
DateQuestion: DateComponent,
DynamicChoiceQuestion: RadioComponent,
DynamicMultipleChoiceQuestion: CheckboxComponent,
FileQuestion: FileComponent,
FilesQuestion: FilesComponent,
FloatQuestion: FloatComponent,
IntegerQuestion: IntegerComponent,
MultipleChoiceQuestion: CheckboxComponent,
Expand Down
32 changes: 0 additions & 32 deletions packages/form/addon/components/cf-field/input/file.hbs

This file was deleted.

89 changes: 0 additions & 89 deletions packages/form/addon/components/cf-field/input/file.js

This file was deleted.

35 changes: 35 additions & 0 deletions packages/form/addon/components/cf-field/input/files.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div class="uk-flex-middle uk-grid-divider uk-grid-column-small" uk-grid>
<div uk-form-custom="target: true">

<input
type="file"
name={{@field.pk}}
id={{@field.pk}}
disabled={{@disabled}}
multiple
{{on "change" this.save}}
/>
<UkButton disabled={{@disabled}}>
{{t "caluma.form.selectFile"}}
</UkButton>
</div>
<ul class="uk-list uk-list-collapse" data-test-file-list={{@field.pk}}>
{{#each this.files as |file|}}
<li class="uk-text-justify uk-text-middle">
<UkButton
data-test-download-link={{file.id}}
@color="link"
@onClick={{fn this.download file.id}}
>
{{file.name}}
</UkButton>
<UkIcon
class="uk-icon-button uk-margin-small-left"
role="button"
@icon="trash"
{{on "click" (fn this.delete file.id)}}
/>
</li>
{{/each}}
</ul>
</div>
Loading

0 comments on commit 48db5ac

Please sign in to comment.