Skip to content

Commit

Permalink
Merge branch '121-debug-with-definemap' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mitch committed Mar 15, 2021
2 parents e52cac0 + b564c39 commit 0bc8003
Show file tree
Hide file tree
Showing 47 changed files with 1,203 additions and 65 deletions.
42 changes: 30 additions & 12 deletions app.stache
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<can-import from="~/src/mobile/" />
<can-import from="~/src/debug-alerts/"/>
<can-import from="~/src/debug-menu/"/>
<can-import from="~/src/debug-panel/" />
<can-import from="~/src/desktop/" />
<can-import from="~/src/modal/" />

Expand All @@ -13,18 +16,33 @@
traceMessage:to="traceMessage"
class="bootstrap-styles" />
{{else}}
{{ let remainingSteps = null, maxDisplayedSteps = null }}
<a2j-desktop-viewer
remainingSteps:to="remainingSteps"
maxDisplayedSteps:to="maxDisplayedSteps"
showDebugPanel:from="appState.showDebugPanel"
lang:from="lang"
logic:from="logic"
appState:from="appState"
pState:from="pState"
mState:from="mState"
interview:from="interview"
class="bootstrap-styles steps-left-{{remainingSteps}} steps-{{maxDisplayedSteps}}" />
{{#if(showDebugPanel)}}
<div class="debug-panel">
<debug-panel
interview:from="interview"
traceMessage:from="appState.traceMessage" />
</div>
{{/if}}
<div id="viewer-app" {{#if(appState.showDebugPanel)}}class="with-debug-panel"{{/if}}>
{{ let remainingSteps = null, maxDisplayedSteps = null }}
<a2j-desktop-viewer
remainingSteps:to="remainingSteps"
maxDisplayedSteps:to="maxDisplayedSteps"
showDebugPanel:from="showDebugPanel"
lang:from="lang"
logic:from="logic"
appState:from="appState"
pState:from="pState"
mState:from="mState"
interview:from="interview"
class="bootstrap-styles steps-left-{{remainingSteps}} steps-{{maxDisplayedSteps}}" />


<debug-menu appState:from="appState" />
{{#if(appState.viewerAlertMessages.length)}}
<author-debug-alerts alertMessages:from="appState.viewerAlertMessages" />
{{/if}}
</div>
{{/if}}

<a2j-modal
Expand Down
4 changes: 2 additions & 2 deletions demo/build.viewer.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const buildViewerHtml = function () {
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="viewer-app"></div>
<body class="with-lawn">
<div id="viewer-app-container"></div>
<script>window.pushState = function () { debugger } </script>
<script>global = window;</script>
<script>window.less = { async: true };</script>
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
<div id="viewer-app"></div>
<body class="with-lawn">
<div id="viewer-app-container"></div>

<script> window.less = { async: true, useFileCache: true };</script>
<script>
Expand Down
6 changes: 3 additions & 3 deletions index.production.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
<div id="viewer-app"></div>
<body class="with-lawn">
<div id="viewer-app-container"></div>

<script> window.less = { async: true, useFileCache: true };</script>
<script>
Expand Down Expand Up @@ -59,6 +59,6 @@
errRepURL: ''
}));
</script>
<script src="node_modules/steal/steal.production.js?v=1590768714184" cache-key="v" cache-version="1590768714184" main="@caliorg/a2jviewer/app"></script>
<script src="node_modules/steal/steal.production.js?v=1614113856433" cache-key="v" cache-version="1614113856433" main="@caliorg/a2jviewer/app"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}
},
"dependencies": {
"@caliorg/a2jdeps": "^7.0.15",
"@caliorg/a2jdeps": "^7.0.16",
"bit-tabs": "^2.0.0",
"blueimp-file-upload": "^9.10.1",
"bootstrap": "^3.4.1",
Expand Down Expand Up @@ -132,6 +132,7 @@
"archiver": "^3.1.1",
"can-debug": "^2.0.1",
"can-fixture": "^2.1.0",
"can-view-model": "^4.0.3",
"chai": "^4.1.2",
"date-fns": "^2.16.1",
"funcunit": "^3.0.0",
Expand Down
70 changes: 70 additions & 0 deletions src/debug-alerts/debug-alerts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import DefineMap from 'can-define/map/map'
import DefineList from 'can-define/list/list'
import Component from 'can-component'
import template from './debug-alerts.stache'

/**
* @module {Module} author/debug-alerts <author-debug-alerts>
* @parent api-components
*
* List of warnings/errors regarding the interview (e.g variable names that
* are too long for HotDocs) shown to the author in preview mode.
*
* ## Use
*
* @codestart
* <author-debug-alerts {(alert-messages)}="alertMessages" />
* @codeend
*/

/**
* @property {can.Map} debugAlerts.viewModel
* @parent author/debug-alerts
*
* `<author-debug-alerts>`'s viewModel.
*/
const DebugAlerts = DefineMap.extend('DebugAlerts', {
/**
* @property {can.List} debugAlerts.viewModel.prototype.define.alertMessages alertMessages
* @parent debugAlerts.viewModel
*
* List of error/warning messages related to an interview.
*/
alertMessages: {
Default: DefineList
},

/**
* @property {Number} debugAlerts.viewModel.prototype.define.messagesCount messagesCount
* @parent debugAlerts.viewModel
*
* Number of messages currently visible to the user (when the user dismisses
* a message this number gets updated).
*/
messagesCount: {
get () {
let messages = this.alertMessages

return messages
.filter(m => m.open)
.length
}
}
})

export default Component.extend({
view: template,
ViewModel: DebugAlerts,
tag: 'author-debug-alerts',

events: {
'.btn-dismiss click': function () {
let $el = $(this.element)
let vm = this.viewModel

$el.slideUp('slow', function () {
vm.alertMessages.update([])
})
}
}
})
30 changes: 30 additions & 0 deletions src/debug-alerts/debug-alerts.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
author-debug-alerts {
left: 50px;
right: 50px;
bottom: 50px;
overflow: auto;
display: block;
max-height: 250px;
z-index: 99999999;
position: absolute;

app-alert .alert {
margin-bottom: 0;
}

.btn-dismiss .badge {
top: -1px;
line-height: 1;
font-size: 12px;
min-width: 10px;
padding: 3px 7px;
font-weight: 700;
margin-left: 3px;
text-align: center;
position: relative;
white-space: nowrap;
border-radius: 10px;
display: inline-block;
vertical-align: middle;
}
}
14 changes: 14 additions & 0 deletions src/debug-alerts/debug-alerts.stache
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<can-import from="@caliorg/a2jdeps/alert/"/>
<can-import from="~/src/debug-alerts/debug-alerts.less"/>

<div class="debug-alerts-wrapper">
<button type="button" class="btn btn-default btn-block btn-dismiss">
Dismiss All <span class="badge">{{messagesCount}}</span>
</button>

{{#for(item of alertMessages)}}
<app-alert open:raw="true" alert-type:raw="danger" dismissible:raw="true">
{{{item.message}}}
</app-alert>
{{/for}}
</div>
13 changes: 13 additions & 0 deletions src/debug-menu/debug-menu-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>Debug Menu Tests</title>
<div id="test-area"></div>
</head>

<body>
<script src="../../node_modules/steal/steal.js"
data-mocha="bdd"
data-main="~/src/debug-menu/debug-menu-test"></script>
</body>
</html>
49 changes: 49 additions & 0 deletions src/debug-menu/debug-menu-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import AppState from '~/src/models/app-state'
import FieldModel from '~/src/models/field'
import AnswerVM from '~/src/models/answervm'
import stache from 'can-stache'
import canViewModel from 'can-view-model'
import { assert } from 'chai'

import 'steal-mocha'
import './debug-menu'
import '~/src/mobile/pages/fields/'

describe('<debug-panel>', () => {
describe('Component', () => {
afterEach(() => {
$('#test-area').empty()
})

const render = (data) => {
const tpl = stache('<debug-menu appState:from="appState" />')
document.querySelector('#test-area').appendChild(tpl(data))
return canViewModel('debug-menu')
}

it('fillPageSample', (done) => {
const appState = new AppState()
const vm = render({ appState })

// validation is tested in ~/src/mobile/pages/fields/field/field-test.js
const oldValidateSampleFill = vm.validateSampleFill
vm.constructor.prototype.validateSampleFill = () => {}

const fieldModel = new FieldModel({ name: 'someName', type: 'text', sample: 'foo' })
fieldModel._answerVm = new AnswerVM({ field: fieldModel, answer: fieldModel.emptyAnswer })

const fields = [ fieldModel ]
const fieldsTpl = stache('<a2j-fields appState:from="appState" fields:from="fields" />')
document.querySelector('#test-area').appendChild(fieldsTpl({ appState, fields }))

const fieldEl = document.querySelector('a2j-field')

setTimeout(() => {
vm.fillPageSample()
assert.equal(fieldEl.value, 'foo', 'should fill in field with sample value')
vm.constructor.prototype.validateSampleFill = oldValidateSampleFill
done()
})
})
})
})
73 changes: 73 additions & 0 deletions src/debug-menu/debug-menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import DefineMap from 'can-define/map/map'
import Component from 'can-component'
import template from './debug-menu.stache'
import constants from '~/src/models/constants'
import _includes from 'lodash/includes'

/**
* @module {Module} author/debug-menu <debug-menu>
* @parent api-components
*
* This component renders some buttons that allow the user (author) to debug
* the interview in the "preview" tab. Among these options there is the button
* that toggles the variables panel and the button that takes the user straight
* to the page edit modal.
*
* ## Use
*
* @codestart
* <debug-menu {(app-state)}="appState" />
* @codeend
*/

// List of field types that can be filled with the `sample` property.
const canUseSampleValues = [
constants.ftText, constants.ftTextLong,
constants.ftTextPick, constants.ftNumber,
constants.ftNumberDollar, constants.ftNumberSSN,
constants.ftNumberPhone, constants.ftNumberZIP,
constants.ftNumberPick, constants.ftDateMDY
]

let DebugMenuVM = DefineMap.extend('DebugMenuVM', {
// passed in via stache
appState: {},

currentPageName: {
get () {
return this.appState.page
}
},

validateSampleFill (fieldVM, context, fieldEl) {
return fieldVM.validateField(context, fieldEl)
},

fillPageSample () {
// fieldElements NodeList used to access individual FieldVMs & validate
const fieldElements = document.querySelectorAll('a2j-field')
// do nothing if `a2j-field` components not in the DOM.
if (!fieldElements.length) return

let fieldVM
let fieldModel

for (const fieldEl of fieldElements) {
fieldVM = fieldEl.viewModel
fieldModel = fieldVM.field
if (_includes(canUseSampleValues, fieldModel.type)) {
// this emulates user input and onBlur validation
fieldEl.value = fieldModel.sample
this.validateSampleFill(fieldVM, null, fieldEl)
}
}
}
})

export default Component.extend({
view: template,
ViewModel: DebugMenuVM,
tag: 'debug-menu',

leakScope: true
})
10 changes: 10 additions & 0 deletions src/debug-menu/debug-menu.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
debug-menu {
display: block;

.debugmenu {
left: 5px;
bottom: 20px;
position: absolute;
z-index: 2000;
}
}
Loading

0 comments on commit 0bc8003

Please sign in to comment.