From d0fa7064f87eabd69c2c4faa4ea7599b98e21052 Mon Sep 17 00:00:00 2001 From: Clint Tseng Date: Tue, 5 Mar 2019 16:01:19 -0800 Subject: [PATCH 1/2] new: support new media appearance types. --- lib/convert.js | 24 ++++++++++++++++++++++-- spec/src/convert-question-spec.ls | 28 ++++++++++++++++++++++++++++ src/convert.ls | 22 +++++++++++++++++++++- 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/lib/convert.js b/lib/convert.js index e433325..d6e5207 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -1,6 +1,6 @@ // Generated by LiveScript 1.5.0 (function(){ - var ref$, isType, map, filter, foldl, join, flatten, keys, empty, deepcopy, writeFile, build, isNonsense, exprValue, surveyFields, choicesFields, multilingualFields, pruneFalse, fieldnameConversion, typeConversion, choiceTypeConversion, dateTypeConversion, dateKindConversion, locationTypeConversion, metadataTypeConversion, appearanceNoops, appearanceConversion, rangeAppearanceConversion, newContext, genRange, convertQuestion, withColumn, genSettings, convertForm, serializeForm, writeForm; + var ref$, isType, map, filter, foldl, join, flatten, keys, empty, deepcopy, writeFile, build, isNonsense, exprValue, surveyFields, choicesFields, multilingualFields, pruneFalse, fieldnameConversion, typeConversion, choiceTypeConversion, dateTypeConversion, dateKindConversion, locationTypeConversion, metadataTypeConversion, appearanceNoops, appearanceConversion, rangeAppearanceConversion, mediaTypeConversion, mediaAppearanceConversion, newContext, genRange, convertQuestion, withColumn, genSettings, convertForm, serializeForm, writeForm; ref$ = require('prelude-ls'), isType = ref$.isType, map = ref$.map, filter = ref$.filter, foldl = ref$.foldl, join = ref$.join, flatten = ref$.flatten; ref$ = require('prelude-ls').Obj, keys = ref$.keys, empty = ref$.empty; deepcopy = require('deepcopy'); @@ -73,6 +73,23 @@ 'Vertical Slider': 'vertical', 'Picker': 'picker' }; + mediaTypeConversion = { + 'Image': 'image', + 'Selfie': 'image', + 'Annotate': 'image', + 'Draw': 'image', + 'Signature': 'image', + 'Audio': 'audio', + 'Video': 'video', + 'Selfie Video': 'video' + }; + mediaAppearanceConversion = { + 'Signature': 'signature', + 'Annotate': 'annotate', + 'Draw': 'draw', + 'Selfie': 'new-front', + 'Selfie Video': 'new-front' + }; newContext = function(){ return { seenFields: {}, @@ -170,13 +187,16 @@ question.appearance = dateKindConversion[question.kind]; } } + if (question.type === 'inputMedia' && mediaAppearanceConversion[question.kind] != null) { + question.appearance = mediaAppearanceConversion[question.kind]; + } if ((ref$ = question.fieldList, delete question.fieldList, ref$) === true) { question.appearance = 'field-list'; } question.type = question.type === 'inputNumeric' ? question.appearance == null || question.appearance === 'Textbox' ? (delete question.appearance, ((ref$ = (ref1$ = question.kind, delete question.kind, ref1$)) != null ? ref$ : 'integer').toLowerCase()) : 'range' : question.type === 'inputMedia' - ? ((ref$ = (ref1$ = question.kind, delete question.kind, ref1$)) != null ? ref$ : 'image').toLowerCase() + ? mediaTypeConversion[(ref$ = (ref1$ = question.kind, delete question.kind, ref1$)) != null ? ref$ : 'Image'] : question.type === 'inputDate' ? dateTypeConversion[(ref$ = (ref1$ = question.kind, delete question.kind, ref1$)) != null ? ref$ : 'Full Date'] : question.type === 'inputLocation' diff --git a/spec/src/convert-question-spec.ls b/spec/src/convert-question-spec.ls index c3a8505..04ddc2c 100644 --- a/spec/src/convert-question-spec.ls +++ b/spec/src/convert-question-spec.ls @@ -78,17 +78,45 @@ describe \type -> test 'media: image' -> explicit = { type: \inputMedia, kind: \Image } |> convert-simple expect(explicit.type).toBe(\image) + expect(explicit.appearance).toBeUndefined() implicit = { type: \inputMedia } |> convert-simple expect(implicit.type).toBe(\image) + test 'media: image/selfie' -> + explicit = { type: \inputMedia, kind: \Selfie } |> convert-simple + expect(explicit.type).toBe(\image) + expect(explicit.appearance).toBe(\new-front) + + test 'media: image/annotate' -> + explicit = { type: \inputMedia, kind: \Annotate } |> convert-simple + expect(explicit.type).toBe(\image) + expect(explicit.appearance).toBe(\annotate) + + test 'media: image/draw' -> + explicit = { type: \inputMedia, kind: \Draw } |> convert-simple + expect(explicit.type).toBe(\image) + expect(explicit.appearance).toBe(\draw) + + test 'media: image/signature' -> + explicit = { type: \inputMedia, kind: \Signature } |> convert-simple + expect(explicit.type).toBe(\image) + expect(explicit.appearance).toBe(\signature) + test 'media: audio' -> result = { type: \inputMedia, kind: \Audio } |> convert-simple expect(result.type).toBe(\audio) + expect(result.appearance).toBeUndefined() test 'media: video' -> result = { type: \inputMedia, kind: \Video } |> convert-simple expect(result.type).toBe(\video) + expect(result.appearance).toBeUndefined() + + test 'media: video/selfie' -> + result = { type: \inputMedia, kind: 'Selfie Video' } |> convert-simple + expect(result.type).toBe(\video) + expect(result.appearance).toBe(\new-front) test \barcode -> result = { type: \inputBarcode } |> convert-simple diff --git a/src/convert.ls b/src/convert.ls index 52df457..2cb207d 100644 --- a/src/convert.ls +++ b/src/convert.ls @@ -69,6 +69,22 @@ range-appearance-conversion = 'Vertical Slider': \vertical 'Picker': \picker +media-type-conversion = + 'Image': \image + 'Selfie': \image + 'Annotate': \image + 'Draw': \image + 'Signature': \image + 'Audio': \audio + 'Video': \video + 'Selfie Video': \video +media-appearance-conversion = + 'Signature': \signature + 'Annotate': \annotate + 'Draw': \draw + 'Selfie': \new-front + 'Selfie Video': \new-front + # make unit testing easier. new-context = -> { seen-fields: {}, choices: {}, warnings: [] } @@ -139,6 +155,10 @@ convert-question = (question, context, prefix = []) -> if question.type is \inputDate question.appearance = date-kind-conversion[question.kind] if date-type-conversion[question.kind]? + # if media, we may need to apply an appearance. + if question.type is \inputMedia and media-appearance-conversion[question.kind]? + question.appearance = media-appearance-conversion[question.kind] + # field-list appearance. if (delete question.fieldList) is true question.appearance = \field-list @@ -152,7 +172,7 @@ convert-question = (question, context, prefix = []) -> else \range else if question.type is \inputMedia - ((delete question.kind) ? \image).toLowerCase() + media-type-conversion[(delete question.kind) ? 'Image'] else if question.type is \inputDate date-type-conversion[(delete question.kind) ? 'Full Date'] else if question.type is \inputLocation From f5bf22633de631b9a10aca131461b12501cd3f7b Mon Sep 17 00:00:00 2001 From: Clint Tseng Date: Wed, 6 Mar 2019 14:21:16 -0800 Subject: [PATCH 2/2] new: add "new" appearance type for media type controls. --- lib/convert.js | 2 ++ spec/src/convert-question-spec.ls | 5 +++++ src/convert.ls | 2 ++ 3 files changed, 9 insertions(+) diff --git a/lib/convert.js b/lib/convert.js index d6e5207..30abf32 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -75,6 +75,7 @@ }; mediaTypeConversion = { 'Image': 'image', + 'New Image': 'image', 'Selfie': 'image', 'Annotate': 'image', 'Draw': 'image', @@ -84,6 +85,7 @@ 'Selfie Video': 'video' }; mediaAppearanceConversion = { + 'New Image': 'new', 'Signature': 'signature', 'Annotate': 'annotate', 'Draw': 'draw', diff --git a/spec/src/convert-question-spec.ls b/spec/src/convert-question-spec.ls index 04ddc2c..118d710 100644 --- a/spec/src/convert-question-spec.ls +++ b/spec/src/convert-question-spec.ls @@ -83,6 +83,11 @@ describe \type -> implicit = { type: \inputMedia } |> convert-simple expect(implicit.type).toBe(\image) + test 'media: image/new' -> + explicit = { type: \inputMedia, kind: 'New Image' } |> convert-simple + expect(explicit.type).toBe(\image) + expect(explicit.appearance).toBe(\new) + test 'media: image/selfie' -> explicit = { type: \inputMedia, kind: \Selfie } |> convert-simple expect(explicit.type).toBe(\image) diff --git a/src/convert.ls b/src/convert.ls index 2cb207d..49311e4 100644 --- a/src/convert.ls +++ b/src/convert.ls @@ -71,6 +71,7 @@ range-appearance-conversion = media-type-conversion = 'Image': \image + 'New Image': \image 'Selfie': \image 'Annotate': \image 'Draw': \image @@ -79,6 +80,7 @@ media-type-conversion = 'Video': \video 'Selfie Video': \video media-appearance-conversion = + 'New Image': \new 'Signature': \signature 'Annotate': \annotate 'Draw': \draw