Skip to content

Commit

Permalink
prelim working hide preview for unpreviewable templates
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasnteireho committed Dec 13, 2024
1 parent ebe6b55 commit 25fc7ad
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 15 deletions.
4 changes: 2 additions & 2 deletions demo/viewer/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
<script main="@empty"
env="production"
config="../package.json!npm"
src="../dist/bundles/app.js?v=1733890832481"
src="../dist/bundles/app.js?v=1734119820307"
cache-key="v"
cache-version="1733890832481"
cache-version="1734119820307"
base-url="../">
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion index.dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@
errRepURL: ''
}));
</script>
<script src="node_modules/steal/steal.production.js?v=1733872401300" cache-key="v" cache-version="1733872401300" main="@caliorg/a2jviewer/app"></script>
<script src="node_modules/steal/steal.production.js?v=1734118793893" cache-key="v" cache-version="1734118793893" main="@caliorg/a2jviewer/app"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@
errRepURL: ''
}));
</script>
<script src="node_modules/steal/steal.production.js?v=1733928463964" cache-key="v" cache-version="1733928463964" main="@caliorg/a2jviewer/app"></script>
<script src="node_modules/steal/steal.production.js?v=1734119803464" cache-key="v" cache-version="1734119803464" main="@caliorg/a2jviewer/app"></script>
</body>
</html>
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@caliorg/a2jviewer",
"version": "8.4.0",
"version": "8.5.0",
"description": "A2J Viewer standalone and preview app.",
"main": "a2jviewer/app",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/footer/footerVersion.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

const version = {
number: '8.4.0',
date: '2024-12-11'
number: '8.5.0',
date: '2024-12-13'
}

export default version
2 changes: 0 additions & 2 deletions src/mobile/pages/fields/field/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,6 @@ export const FieldVM = DefineMap.extend('FieldVM', {

_answerVm.values = value

console.log('answer value: ' + _answerVm.values)

let errors = _answerVm.errors
field.hasError = errors
// update group validation for radio buttons
Expand Down
6 changes: 3 additions & 3 deletions src/mobile/pages/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export default Component.extend({
},
trim (str) {
return (str || '').trim()
}
},

},

events: {
Expand Down Expand Up @@ -151,7 +152,7 @@ export default Component.extend({
const vm = this.viewModel

/***
* !!! Change this in pproduction to prod server!!!
* !!! Change this in production to prod server!!!
*/
if (!vm.appState.previewActive) {
let postBody = {
Expand All @@ -173,7 +174,6 @@ export default Component.extend({
dataType: 'json'
})
.then((response) => response.json())
.then((json) => console.log(json))
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/mobile/pages/pages.stache
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,17 @@
{{/for}}

{{#if(currentPage.canPreview)}}
{{#if(currentPage.needsPreview)}}
<div id="canPreview">
<p>You have documents that can be previewed.</p>
<button
class="btn btn-default btn-navigate open-preview"
type="button"
>
Open document preview
Open document preview
</button>
</div>
{{/if}}
{{/if}}
{{/if}}
{{/if}}
9 changes: 9 additions & 0 deletions src/models/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ const Page = DefineMap.extend('Page Model', {
default: () => []
},

needsPreview: {
serialize: false,

get() {
return sessionStorage.getItem("needsPreviewBtn")
}
},

// Whether the UI should show the preview button for the page.
// The button should show if there are Assemble or Assemble & Save buttons.
// In the future, this button will only be shown when particular requirements are met: https://github.com/CCALI/a2jviewer/issues/176
canPreview: {
serialize: false,

get () {

const buttons = this.buttons

return buttons && buttons.length > 0 ? buttons.some(button => {
Expand Down
62 changes: 62 additions & 0 deletions start-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,59 @@ import route from 'can-route'

import '~/src/util/object-assign-polyfill'

const hasPDFTemplates = (mState) => {


let needsPreviewBtn = false
$("#canPreview").hide()

const templates = $.ajax({
url: mState.fileDataURL + '/templates.json',
type: 'GET',
dataType: 'json'
})
templates.then(templates => {
let t = []
for(let i =0;
i < templates.templateIds.length && !needsPreviewBtn;
i++){
const template = $.ajax({
url: mState.fileDataURL + '/template' + templates.templateIds[i] + '.json',
type: 'GET',
dataType: 'json'
})
t.push(template.then(template => {
//if (template.rootNode.tag === "a2j-pdf"){
if (template.rootNode.tag === "a2j-template"){
needsPreviewBtn = true
sessionStorage.setItem("needsPreviewBtn", "true");
$("#canPreview").show()
//$("#canPreview").attr("hidden", "")
//$("#canPreview").removeAttr("hidden")
}

}))


}
console.log(t)
Promise.allSettled(t).then(() => {
if (sessionStorage.getItem("needsPreviewBtn")){
//$("#canPreview").attr("hidden", "")
$("#canPreview").removeAttr("hidden")
$("#canPreview").show()

}
})
})

Promise.allSettled([templates])

return Boolean(sessionStorage.getItem("needsPreviewBtn"))

}


export default function ({ interview, pState, mState, appState }) {
route.start()

Expand Down Expand Up @@ -57,6 +110,15 @@ export default function ({ interview, pState, mState, appState }) {
const authorId = interview.authorId || 0
analytics.initialize(authorId)


mState.needsPreviewBtn = hasPDFTemplates(mState)
if (sessionStorage.getItem("needsPreviewBtn")){
$("#canPreview").removeAttr("hidden")
$("#canPreview").show()
}

console.log(mState)

$('#viewer-app-container').append(template({
appState, pState, mState, interview, logic, lang, isMobile
}))
Expand Down

0 comments on commit 25fc7ad

Please sign in to comment.