Skip to content

Commit

Permalink
fix(PdhHandler): softer error message for not admins
Browse files Browse the repository at this point in the history
  • Loading branch information
J9rem committed Dec 15, 2022
1 parent 4d905e9 commit ce5d112
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 13 deletions.
6 changes: 4 additions & 2 deletions javascripts/components/Step.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SpinnerLoader from './SpinnerLoader.js'

export default {
props: ['name','value','text'],
props: ['name','value','text','isAdmin'],
components: {SpinnerLoader},
computed: {
isChecked: function(){
Expand All @@ -21,8 +21,10 @@ export default {
<span v-html="text"></span>
</label>
&nbsp;
<span v-if="value === 1">&#9203;</span>
<SpinnerLoader :size="1" :height="25" v-if="value === 1"/>
<span v-if="value === 3">&#10060;</span>
<span v-else-if="value === 3 && isAdmin">&#10060;</span>
<span v-else-if="value === 3 && !isAdmin">&#9889;</span>
</div>
`
}
31 changes: 27 additions & 4 deletions javascripts/handler-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let appParams = {
components: { Translations, Step, SpinnerLoader },
data: function() {
return {
abortController : null,
browserLoaded: 0,
buttonAction: null,
buttonType: 'primary',
Expand Down Expand Up @@ -73,14 +74,19 @@ let appParams = {
return urls;
},
contactServer: async function(url){
return fetch(url,{referrer:wiki.url(this.pageTag)})
this.stopFetch();
this.abortController = new AbortController();
return fetch(url,{referrer:wiki.url(this.pageTag),signal:this.abortController.signal})
.then((response)=>{
if (!response.ok && [401,403,404].includes(response.status)){
return Promise.reject(`${response.status} => ${response.statusText}`);
}
return response;
})
.catch((error)=>{
if (typeof error == 'DOMException' && error.name == 'AbortError'){
return Promise.reject(new Error('===Do Nothing==='));
}
let errorMessage = this.t('errorforexternaleurlcheck',{
extUrl: url,
helpLink: this.renderHelpUrlButton(),
Expand Down Expand Up @@ -185,7 +191,9 @@ let appParams = {
})
.catch((error)=>{
this.clearTimer();
this.message = '';
if (typeof error != "object" || error.message !== '===Do Nothing==='){
this.message = '';
}
if (this.pdfServiceContacted < 2){
this.pdfServiceContacted = 3;
}
Expand Down Expand Up @@ -312,7 +320,7 @@ let appParams = {
if (error.message === '===Do Nothing==='){
return;
}
this.messageType = 'danger';
this.messageType = this.isAdmin ? 'danger' : 'info';
if (this.isAdmin){
this.message = this.t('errorforadmin',{error:error.toString()})
if (error.lineNumber != undefined && error.fileName != undefined){
Expand All @@ -339,6 +347,16 @@ let appParams = {
renderErrorJsonFormat: function ({url,response,contentType}){
return Promise.reject(`Bad format of response to url '${url}' : status '${response.status}' => '${response.statusText}', but json waited with error = true, obtained : ${contentType}`);
},
returnToPage: function(){
this.stopFetch();
window.location = wiki.url(wiki.pageTag);
},
stopFetch: function(){
if (this.abortController !== null){
this.abortController.abort();
}
this.abortController = null;
},
t: function(text, replacements = null){
if (replacements === null || typeof replacements != "object"){
replacements = {};
Expand Down Expand Up @@ -379,7 +397,12 @@ let appParams = {
},
updateStatus: async function(url){
try {
let jsonResponse = await fetch(url)
let aController = this.abortController
if (aController === null){
this.abortController = new AbortController();
aController = this.abortController;
}
let jsonResponse = await fetch(url,{signal:this.abortController.signal})
.then((response)=>{
return (response.ok)
? response.json()
Expand Down
1 change: 1 addition & 0 deletions lang/publication_en.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,6 @@
'PUBLICATION_OPEN_DEFAULT_LINK' => 'Open external page for print',
'PUBLICATION_PDF_CREATION' => 'Create pdf of %{pageTag}\s page',
'PUBLICATION_PRINT_VIA_PREVIEW' => 'Print via browser',
'PUBLICATION_RETURN_TO_PAGE' => 'Back to page',
'PUBLICATION_SAVE_FILE' => 'Save pdf',
];
1 change: 1 addition & 0 deletions lang/publication_fr.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,6 @@
'PUBLICATION_OPEN_DEFAULT_LINK' => 'Ouvrir la page externe d\'impresssion',
'PUBLICATION_PDF_CREATION' => 'Création du pdf de la page %{pageTag}',
'PUBLICATION_PRINT_VIA_PREVIEW' => 'Imprimer par le navigateur',
'PUBLICATION_RETURN_TO_PAGE' => 'Retour à la page',
'PUBLICATION_SAVE_FILE' => 'Enregistrer le pdf',
];
1 change: 1 addition & 0 deletions lang/publication_pt.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,6 @@
// 'PUBLICATION_OPEN_DEFAULT_LINK' => 'Ouvrir la page externe d\'impresssion',
// 'PUBLICATION_PDF_CREATION' => 'Création du pdf de la page %{pageTag}',
// 'PUBLICATION_PRINT_VIA_PREVIEW' => 'Imprimer par le navigateur',
// 'PUBLICATION_RETURN_TO_PAGE' => 'Retour à la page',
// 'PUBLICATION_SAVE_FILE' => 'Enregistrer le pdf',
];
15 changes: 8 additions & 7 deletions templates/handler-pdf.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
<h2>{{ _t('PUBLICATION_PDF_CREATION',{pageTag:pageTag}) }}</h2>
<div>
{% if isAdmin == true %}
<step :name="'getPdfServiceUrl'" :value="urlOfPdfServiceGet" :text="{{ _t('PUBLICATION_GET_PDF_SERVICE_URL')|json_encode }}"></step>
<step :name="'checkUrls'" :value="urlsChecked" :text="{{ _t('PUBLICATION_CHECK_URLS')|json_encode }}"></step>
<step :name="'getPdfServiceUrl'" :value="urlOfPdfServiceGet" :text="{{ _t('PUBLICATION_GET_PDF_SERVICE_URL')|json_encode }}" :is-admin="{{ isAdmin|json_encode }}"></step>
<step :name="'checkUrls'" :value="urlsChecked" :text="{{ _t('PUBLICATION_CHECK_URLS')|json_encode }}" :is-admin="{{ isAdmin|json_encode }}"></step>
{% endif %}
<step :name="'contactService'" :value="pdfServiceContacted" :text="{{ _t('PUBLICATION_CONTACT_SERVICE')|json_encode }}"></step>
<step :name="'contactService'" :value="pdfServiceContacted" :text="{{ _t('PUBLICATION_CONTACT_SERVICE')|json_encode }}" :is-admin="{{ isAdmin|json_encode }}"></step>
{% if isAdmin == true %}
<step :name="'browserLoaded'" :value="browserLoaded" :text="{{ _t('PUBLICATION_LOADING_BROWSER')|json_encode }}"></step>
<step :name="'pageLoadedByBrowser'" :value="pageLoadedByBrowser" :text="{{ _t('PUBLICATION_LOADING_PAGE')|json_encode }}"></step>
<step :name="'creatingPdf'" :value="creatingPdf" :text="{{ _t('PUBLICATION_CREATING_PDF')|json_encode }}"></step>
<step :name="'browserLoaded'" :value="browserLoaded" :text="{{ _t('PUBLICATION_LOADING_BROWSER')|json_encode }}" :is-admin="{{ isAdmin|json_encode }}"></step>
<step :name="'pageLoadedByBrowser'" :value="pageLoadedByBrowser" :text="{{ _t('PUBLICATION_LOADING_PAGE')|json_encode }}" :is-admin="{{ isAdmin|json_encode }}"></step>
<step :name="'creatingPdf'" :value="creatingPdf" :text="{{ _t('PUBLICATION_CREATING_PDF')|json_encode }}" :is-admin="{{ isAdmin|json_encode }}"></step>
{% endif %}
<step :name="'getPdf'" :value="pdfDownloaded" :text="{{ _t('PUBLICATION_DOWNLOAD_PDF')|json_encode }}"></step>
<step :name="'getPdf'" :value="pdfDownloaded" :text="{{ _t('PUBLICATION_DOWNLOAD_PDF')|json_encode }}" :is-admin="{{ isAdmin|json_encode }}"></step>
</div>
<div v-if="message.length > 0" :class="{alert:true,[`alert-${messageType}`]:true}" v-html="message">
</div>
Expand All @@ -53,4 +53,5 @@
>
{{ _t('PUBLICATION_SAVE_FILE') }}
</a>
<button class="btn btn-default" @click.prevent.stop="returnToPage">{{ _t('PUBLICATION_RETURN_TO_PAGE') }}</button>
</div>

0 comments on commit ce5d112

Please sign in to comment.