This repository has been archived by the owner on Feb 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add components for the basic fields (text, textarea, integer and float)
- Loading branch information
Jonas Metzener
committed
Oct 25, 2018
1 parent
3a681cb
commit 6a968a4
Showing
41 changed files
with
2,356 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Component from "@ember/component"; | ||
import { computed } from "@ember/object"; | ||
import { inject as service } from "@ember/service"; | ||
import layout from "../templates/components/cf-field"; | ||
|
||
/** | ||
* @class CfFieldComponent | ||
*/ | ||
export default Component.extend({ | ||
layout, | ||
classNames: ["uk-margin"], | ||
|
||
fieldStore: service(), | ||
|
||
/** | ||
* @argument {Object} question | ||
*/ | ||
question: null, | ||
|
||
/** | ||
* @argument {Object} document | ||
*/ | ||
document: null, | ||
|
||
/** | ||
* @property {Field} field | ||
* @accessor | ||
*/ | ||
field: computed("question.slug", "document.id", function() { | ||
return this.fieldStore.find(this.question, this.document); | ||
}).readOnly() | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Component from "@ember/component"; | ||
import { computed, get } from "@ember/object"; | ||
import layout from "../../templates/components/cf-field/input"; | ||
|
||
/** | ||
* Component for wrapping the input components | ||
* | ||
* @class CfFieldInputComponent | ||
*/ | ||
export default Component.extend({ | ||
layout, | ||
classNames: ["uk-form-controls"], | ||
|
||
/** | ||
* The input component type | ||
* | ||
* @property {String} type | ||
* @accessor | ||
*/ | ||
type: computed("field.question.__typename", function() { | ||
const typename = get(this, "field.question.__typename"); | ||
|
||
return typename && typename.replace(/Question$/, "").toLowerCase(); | ||
}).readOnly() | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Component from "@ember/component"; | ||
|
||
/** | ||
* Input component for the float question type | ||
* | ||
* @class CfFieldInputFloatComponent | ||
*/ | ||
export default Component.extend({ | ||
tagName: "input", | ||
classNames: ["uk-input"], | ||
attributeBindings: [ | ||
"type", | ||
"step", | ||
"field.id:name", | ||
"field.answer.floatValue:value", | ||
"field.question.floatMinValue:min", | ||
"field.question.floatMaxValue:max" | ||
], | ||
type: "number", | ||
step: 0.001 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Component from "@ember/component"; | ||
|
||
/** | ||
* Input component for the integer question type | ||
* | ||
* @class CfFieldInputIntegerComponent | ||
*/ | ||
export default Component.extend({ | ||
tagName: "input", | ||
classNames: ["uk-input"], | ||
attributeBindings: [ | ||
"type", | ||
"step", | ||
"field.id:name", | ||
"field.answer.integerValue:value", | ||
"field.question.integerMinValue:min", | ||
"field.question.integerMaxValue:max" | ||
], | ||
type: "number", | ||
step: 1 | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Component from "@ember/component"; | ||
|
||
/** | ||
* Input component for the text question type | ||
* | ||
* @class CfFieldInputTextComponent | ||
*/ | ||
export default Component.extend({ | ||
tagName: "input", | ||
classNames: ["uk-input"], | ||
attributeBindings: [ | ||
"type", | ||
"field.id:name", | ||
"field.answer.stringValue:value", | ||
"field.question.textMaxLength:maxlength" | ||
], | ||
type: "text" | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Component from "@ember/component"; | ||
|
||
/** | ||
* Input component for the textarea question type | ||
* | ||
* @class CfFieldInputTextareaComponent | ||
*/ | ||
export default Component.extend({ | ||
tagName: "textarea", | ||
classNames: ["uk-textarea"], | ||
attributeBindings: [ | ||
"field.id:name", | ||
"field.answer.stringValue:value", | ||
"field.question.textareaMaxLength:maxlength" | ||
] | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Component from "@ember/component"; | ||
import layout from "../../templates/components/cf-field/label"; | ||
|
||
export default Component.extend({ | ||
layout, | ||
tagName: "label", | ||
classNames: ["uk-form-label"] | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Component from "@ember/component"; | ||
import { inject as service } from "@ember/service"; | ||
import { ComponentQueryManager } from "ember-apollo-client"; | ||
import { task } from "ember-concurrency"; | ||
import layout from "../templates/components/cf-form"; | ||
|
||
import getDocumentQuery from "ember-caluma-form/gql/queries/get-document"; | ||
|
||
export default Component.extend(ComponentQueryManager, { | ||
layout, | ||
tagName: "form", | ||
apollo: service(), | ||
|
||
willInsertElement() { | ||
this.data.perform(); | ||
}, | ||
|
||
data: task(function*() { | ||
return yield this.apollo.watchQuery( | ||
{ | ||
query: getDocumentQuery, | ||
variables: { id: this.documentId }, | ||
fetchPolicy: "network-only" | ||
}, | ||
"allDocuments.edges" | ||
); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
fragment FieldAnswer on Answer { | ||
id | ||
question { | ||
slug | ||
} | ||
... on StringAnswer { | ||
stringValue: value | ||
} | ||
... on IntegerAnswer { | ||
integerValue: value | ||
} | ||
... on FloatAnswer { | ||
floatValue: value | ||
} | ||
... on ListAnswer { | ||
listValue: value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
fragment FieldQuestion on Question { | ||
slug | ||
label | ||
isRequired | ||
... on TextQuestion { | ||
textMaxLength: maxLength | ||
} | ||
... on TextareaQuestion { | ||
textareaMaxLength: maxLength | ||
} | ||
... on IntegerQuestion { | ||
integerMinValue: minValue | ||
integerMaxValue: maxValue | ||
} | ||
... on FloatQuestion { | ||
floatMinValue: minValue | ||
floatMaxValue: maxValue | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#import 'ember-caluma-form/gql/fragments/field-answer' | ||
#import 'ember-caluma-form/gql/fragments/field-question' | ||
|
||
fragment FormDocument on Document { | ||
id | ||
answers { | ||
edges { | ||
node { | ||
...FieldAnswer | ||
} | ||
} | ||
} | ||
form { | ||
slug | ||
questions { | ||
edges { | ||
node { | ||
...FieldQuestion | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#import 'ember-caluma-form/gql/fragments/form-document' | ||
|
||
query($id: ID!) { | ||
allDocuments(id: $id) { | ||
edges { | ||
node { | ||
...FormDocument | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{{cf-field/label field=field}} | ||
{{cf-field/input field=field}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{#if type}} | ||
{{component (concat "cf-field/input/" type) field=field}} | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{field.question.label}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{#let data.lastSuccessful.value.firstObject.node as |document|}} | ||
{{#each document.form.questions.edges as |questionEdge|}} | ||
{{#let questionEdge.node as |question|}} | ||
{{cf-field question=question document=document}} | ||
{{/let}} | ||
{{/each}} | ||
{{/let}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "ember-caluma-form/components/cf-field"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "ember-caluma-form/components/cf-field/input"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "ember-caluma-form/components/cf-field/input/float"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "ember-caluma-form/components/cf-field/input/integer"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "ember-caluma-form/components/cf-field/input/text"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "ember-caluma-form/components/cf-field/input/textarea"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "ember-caluma-form/components/cf-field/label"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "ember-caluma-form/components/cf-form"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Route from "@ember/routing/route"; | ||
import { inject as service } from "@ember/service"; | ||
import { get } from "@ember/object"; | ||
import { RouteQueryManager } from "ember-apollo-client"; | ||
import gql from "graphql-tag"; | ||
|
||
export default Route.extend(RouteQueryManager, { | ||
apollo: service(), | ||
|
||
async model() { | ||
const res = await this.apollo.watchQuery( | ||
{ | ||
query: gql` | ||
query { | ||
allDocuments { | ||
edges { | ||
node { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
` | ||
}, | ||
"allDocuments.edges" | ||
); | ||
|
||
return get(res, "firstObject.node"); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import ApolloService from "ember-apollo-client/services/apollo"; | ||
import CalumaApolloServiceMixin from "ember-caluma-utils/mixins/caluma-apollo-service-mixin"; | ||
|
||
export default ApolloService.extend(CalumaApolloServiceMixin, {}); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import "ember-uikit"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import config from "../config/environment"; | ||
import graphqlHandler from "ember-caluma-utils/mirage-graphql"; | ||
|
||
export default function() { | ||
this.urlPrefix = ""; // make this `http://localhost:8080`, for example, if your API is on a different server | ||
this.namespace = ""; // make this `/api`, for example, if your API is namespaced | ||
this.timing = 400; // delay for each request, automatically set to 0 during testing | ||
|
||
this.post(config.apollo.apiURL, graphqlHandler(this), 200); | ||
|
||
if (config.environment !== "production") { | ||
this.get("/versions.json", {}, 200); | ||
} | ||
|
||
this.passthrough(); | ||
} |
Oops, something went wrong.