From 25fc7ade6fdb22c849bb69ae1b6d70fce777283b Mon Sep 17 00:00:00 2001 From: Tobias Nteireho Date: Fri, 13 Dec 2024 13:58:16 -0600 Subject: [PATCH] prelim working hide preview for unpreviewable templates --- demo/viewer/viewer.html | 4 +- index.dev.html | 2 +- index.html | 2 +- package-lock.json | 4 +- package.json | 2 +- src/footer/footerVersion.js | 4 +- src/mobile/pages/fields/field/field.js | 2 - src/mobile/pages/pages.js | 6 +-- src/mobile/pages/pages.stache | 6 ++- src/models/page.js | 9 ++++ start-app.js | 62 ++++++++++++++++++++++++++ 11 files changed, 88 insertions(+), 15 deletions(-) diff --git a/demo/viewer/viewer.html b/demo/viewer/viewer.html index 82cf0a361..92736975b 100644 --- a/demo/viewer/viewer.html +++ b/demo/viewer/viewer.html @@ -53,9 +53,9 @@ diff --git a/index.dev.html b/index.dev.html index ce8ce4cd0..7fc82a117 100644 --- a/index.dev.html +++ b/index.dev.html @@ -59,6 +59,6 @@ errRepURL: '' })); - + \ No newline at end of file diff --git a/index.html b/index.html index 762e9ffb9..b42dba179 100644 --- a/index.html +++ b/index.html @@ -59,6 +59,6 @@ errRepURL: '' })); - + \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 444199c1d..4ebbc710f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@caliorg/a2jviewer", - "version": "8.4.0", + "version": "8.5.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@caliorg/a2jviewer", - "version": "8.4.0", + "version": "8.5.0", "license": "GNU AGPL v3.0", "dependencies": { "@caliorg/a2jdeps": "^7.1.7", diff --git a/package.json b/package.json index 4c7fd33ce..cb220e32a 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/footer/footerVersion.js b/src/footer/footerVersion.js index de7d3ed1d..03e0babb4 100644 --- a/src/footer/footerVersion.js +++ b/src/footer/footerVersion.js @@ -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 diff --git a/src/mobile/pages/fields/field/field.js b/src/mobile/pages/fields/field/field.js index 9a6906763..06a4ecf77 100644 --- a/src/mobile/pages/fields/field/field.js +++ b/src/mobile/pages/fields/field/field.js @@ -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 diff --git a/src/mobile/pages/pages.js b/src/mobile/pages/pages.js index 3ef361632..017d2bd42 100644 --- a/src/mobile/pages/pages.js +++ b/src/mobile/pages/pages.js @@ -46,7 +46,8 @@ export default Component.extend({ }, trim (str) { return (str || '').trim() - } + }, + }, events: { @@ -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 = { @@ -173,7 +174,6 @@ export default Component.extend({ dataType: 'json' }) .then((response) => response.json()) - .then((json) => console.log(json)) } } } diff --git a/src/mobile/pages/pages.stache b/src/mobile/pages/pages.stache index 2c18e2e93..9e610a6f5 100644 --- a/src/mobile/pages/pages.stache +++ b/src/mobile/pages/pages.stache @@ -97,13 +97,17 @@ {{/for}} {{#if(currentPage.canPreview)}} + {{#if(currentPage.needsPreview)}} +

You have documents that can be previewed.

+
+ {{/if}} {{/if}} {{/if}} {{/if}} diff --git a/src/models/page.js b/src/models/page.js index 1fb9542a1..49fac1380 100644 --- a/src/models/page.js +++ b/src/models/page.js @@ -16,6 +16,14 @@ 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 @@ -23,6 +31,7 @@ const Page = DefineMap.extend('Page Model', { serialize: false, get () { + const buttons = this.buttons return buttons && buttons.length > 0 ? buttons.some(button => { diff --git a/start-app.js b/start-app.js index cc4ea072f..adbfe8318 100644 --- a/start-app.js +++ b/start-app.js @@ -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() @@ -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 }))