Skip to content

Commit

Permalink
2.2.3 node 12 update and small DAT fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasnteireho committed Feb 17, 2020
1 parent ffc1282 commit e40bad5
Show file tree
Hide file tree
Showing 68 changed files with 557 additions and 29,098 deletions.
8 changes: 3 additions & 5 deletions DAT/js/author/models/a2j-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,17 @@ A2JTemplate.List = A2JTemplate.List.extend({
sortBy (key, direction = 'asc') {
switch (key) {
case 'buildOrder':
this.attr('comparator', comparator.number(key, direction))
sort(this, comparator.number(key, direction))
break

case 'title':
this.attr('comparator', comparator.string(key, direction))
sort(this, comparator.string(key, direction))
break

case 'updatedAt':
this.attr('comparator', comparator.moment(key, direction))
sort(this, comparator.moment(key, direction))
break
}

sort(this, this.attr('comparator'))
},

search (token) {
Expand Down
4 changes: 2 additions & 2 deletions DAT/js/author/models/app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ export default CanMap.extend('AuthorAppState', {
},

/**
* @property {String} viewerInterview
* @property {String} previewInterview
*
* The Interview instance used by the viewer app in preview mode.
* this is set by viewer-preview-layout.stache bindings
*/
viewerInterview: {
previewInterview: {
serialize: false
},

Expand Down
77 changes: 34 additions & 43 deletions DAT/js/author/models/fixtures/a2j-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,67 @@ import template2112 from './templates/guide1261-template2112'
import template2113 from './templates/guide1261-template2113'
import template2114 from './templates/guide20-template2114'

// emulates a Guide's local templates.json file which has a map like {"guideId":20,"templateIds":[2114]}
// and the api call that returns the template based on guideId/templateId comboId like {20-2114}
let fixtureTemplates = {
2111: template2111,
2112: template2112,
2113: template2113,
2114: template2114
1261: { 2111: template2111, 2112: template2112, 2113: template2113 },
20: { 2114: template2114 },
5150: {} // used for 'throw away' tests that don't need templates map to persist
}

let a2jTemplates = JSON.parse(localStorage.getItem('a2jTemplates'))
let a2jTemplateSequence = Number(localStorage.getItem('a2jTemplateSequence'))
let a2jTemplates
let a2jTemplateSequence

let persistTemplates = () => {
window.localStorage.setItem('a2jTemplates', JSON.stringify(a2jTemplates))
window.localStorage.setItem('a2jTemplateSequence', a2jTemplateSequence)
}

if (!a2jTemplates) {
export const resetFixtureTemplates = function () {
a2jTemplates = fixtureTemplates
a2jTemplateSequence = 3000
}

persistTemplates()
if (!a2jTemplates) {
resetFixtureTemplates()
}

export default function (request, response) {
let requestData = request.data || {}
let guideId = requestData.guideId || '1261' // TODO: remove 'default' guideId of '1261'
let templateId = requestData.templateId

switch (request.type) {
case 'put':
a2jTemplates[requestData.templateId] = requestData
persistTemplates()

response(a2jTemplates[requestData.templateId])
case 'put': // update
a2jTemplates[guideId][templateId] = requestData
response(a2jTemplates[guideId][templateId])
break

case 'post':
a2jTemplateSequence += 1
requestData.templateId = a2jTemplateSequence
requestData.guideId = requestData.guideId || '1261'

a2jTemplates[requestData.templateId] = requestData
persistTemplates()

response(a2jTemplates[requestData.templateId])
case 'post': // create
templateId = a2jTemplateSequence += 1
// assign new templateId
requestData.templateId = templateId
// store in "DB"
a2jTemplates[guideId][templateId] = requestData
response(a2jTemplates[guideId][templateId])
break

case 'delete':
if (a2jTemplates[requestData.templateId] == null) {
case 'delete': // destroy
if (a2jTemplates[guideId] == null) {
response(404)
} else {
delete a2jTemplates[requestData.templateId]
persistTemplates()
delete a2jTemplates[guideId][templateId]
response(200)
}

break

default:
if (requestData.templateId) {
const templateId = requestData.templateId
response(a2jTemplates[templateId])
// findOne template for templateId
if (templateId) {
response(a2jTemplates[guideId][templateId])
} else {
const guideId = requestData.guideId
const list = []
Object.keys(a2jTemplates).forEach(k => {
const template = a2jTemplates[k]
// only return templates that match the guideId
if (a2jTemplates[k].guideId === guideId) {
list.push(template)
}
// findAll templates for guideId
const templatesList = []
Object.keys(a2jTemplates[guideId]).forEach((templateId) => {
templatesList.push(a2jTemplates[guideId][templateId])
})
response(list)
response(templatesList)
}
}
}
51 changes: 2 additions & 49 deletions DAT/js/author/models/tests/a2j-template-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,11 @@ import '../fixtures/templates'
import 'steal-mocha'

describe('A2JTemplate Model', function () {
beforeEach(function () {
window.localStorage.clear()
})

afterEach(function () {
window.localStorage.clear()
})

it('findOne', function () {
let promise = A2JTemplate.findOne({ guideId: 1261, templateId: 2112 })

return promise.then(function (a2jTemplate) {
assert.equal(a2jTemplate.attr('templateId'), '2112', 'should grab correct template')
assert.ok(a2jTemplate.attr('rootNode') instanceof A2JNode)
assert.ok(a2jTemplate.attr('rootNode.children.0') instanceof A2JNode)
assert.ok(a2jTemplate.attr('rootNode.children.1') instanceof A2JNode)
Expand All @@ -29,6 +22,7 @@ describe('A2JTemplate Model', function () {
let promise = A2JTemplate.findAll({ guideId: 1261 })

return promise.then(function (a2jTemplates) {
assert.equal(a2jTemplates.length, 3, 'should have 3 total templates')
a2jTemplates.forEach(function (a2jTemplate) {
assert.ok(a2jTemplate.attr('rootNode') instanceof A2JNode)

Expand All @@ -47,47 +41,6 @@ describe('A2JTemplate Model', function () {
})
})

it('create', function () {
let a2jTemplate = new A2JTemplate({ title: 'Best Template' })

return a2jTemplate.save().then(function (bestTemplate) {
assert.equal(bestTemplate.attr('title'), 'Best Template')
})
})

it('update', function (done) {
let a2jTemplate = new A2JTemplate({ title: 'Best Template' })

a2jTemplate.save().then(function (bestTemplate) {
assert.equal(bestTemplate.attr('title'), 'Best Template')

let templateId = bestTemplate.attr('templateId')

bestTemplate.attr('title', 'Bestest Template')

bestTemplate.save().then(function (bestestTemplate) {
assert.equal(bestestTemplate.attr('title'), 'Bestest Template')
assert.equal(bestestTemplate.attr('templateId'), templateId)
done()
})
})
})

it('destroy', function (done) {
let promise = A2JTemplate.findAll({ guideId: 1261 })

promise.then(function (a2jTemplates) {
const destroyPromises = a2jTemplates.map(function (a2jTemplate) {
if (a2jTemplate.attr('templateId') >= 3000) {
return a2jTemplate.destroy()
}
})

Promise.all(destroyPromises)
.then(done())
})
})

it('addNode', function () {
let promise = A2JTemplate.findOne({ guideId: 1261, templateId: 2112 })

Expand Down
2 changes: 2 additions & 0 deletions DAT/js/author/pdf/addendum-options/addendum-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import CanMap from 'can-map'
import Component from 'can-component'
import template from './addendum-options.stache'

import 'can-map-define'

function toNumber (value, defaultValue) {
if (typeof value !== 'number') {
value = parseFloat(value)
Expand Down
16 changes: 16 additions & 0 deletions DAT/js/author/pdf/assemble-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html>

<title>Author Assemble Tests</title>

<div id="mocha"></div>
<div id="test-area"></div>

<script type="text/javascript">
window.less = {async: true, fileSync: true};
</script>

<script src="../../node_modules/steal/steal.js"
mocha="bdd"
main="caja/author/pdf/assemble-test">
</script>
37 changes: 37 additions & 0 deletions DAT/js/author/pdf/assemble-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,43 @@ describe('pdf/assemble', () => {
text: defaultTextOptions
}])
})

it('should return a multi-line patch if single-line needs addendum', () => {
const variableOptions = {
overflowStyle: 'overflow-to-addendum',
addendumLabel: 'someLabel'
}

const boxes = [{
page: 1,
area: { top: 0, left: 0, width: 0, height: 0 }
}]
const variable = {}
const answerValue = 'Hello'
const patches = getTextPatches({
boxes,
getBoxArea,
variable,
variableOptions,
answerValue,
defaultTextOptions
})

assert.deepEqual(patches, [{
type: 'multiline-text',
content: 'Hello',
overflow: {
style: variableOptions.overflowStyle,
addendumLabel: variableOptions.addendumLabel
},
addendumText: defaultTextOptions,
lines: [{
page: 1,
area: 'GetBoxArea',
text: defaultTextOptions
}]
}])
})
})
})

Expand Down
3 changes: 2 additions & 1 deletion DAT/js/author/pdf/assemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@
return [tablePatch]
}

var isSingleLine = boxes.length === 1
// mutli-line patch required for addendum overflow on single-text
var isSingleLine = boxes.length === 1 && (!style || style === 'clip-overflow')
if (isSingleLine) {
var box = boxes[0]
var textPatch = {
Expand Down
17 changes: 10 additions & 7 deletions DAT/js/author/pdf/assignment-form/assignment-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import CanMap from 'can-map'
import Component from 'can-component'
import template from './assignment-form.stache'

import 'can-map-define'

/*
Assignment = {
deleteVariable: Maybe String,
Expand Down Expand Up @@ -84,7 +86,9 @@ function makeVariableBuffer (variable, options, boxes) {
isGroup,
isCheck,
isInverted: boxes.reduce((i, box) => i || box.isInverted, false),
choices: boxes.map(box => box.variableValue)
// variableValue of `undefined` causes a bug in rendering the MC value input
// will be fixed with can-list & can-define/list bug fix
choices: boxes.map(box => box.variableValue === undefined ? '' : box.variableValue)
}
}

Expand Down Expand Up @@ -231,6 +235,10 @@ export const AssignmentFormVm = CanMap.extend('AssignmentFormVm', {
}
},

connectedCallback () {
this.didInsertElement()
},

didInsertElement () {
this.updateBufferWithBoxes()
},
Expand Down Expand Up @@ -370,10 +378,5 @@ export default Component.extend({
tag: 'assignment-form',
view: template,
leakScope: false,
ViewModel: AssignmentFormVm,
events: {
inserted () {
this.viewModel.didInsertElement()
}
}
ViewModel: AssignmentFormVm
})
Loading

0 comments on commit e40bad5

Please sign in to comment.