refs #5941 feat: sendToSuppor component and fix CSS and JSON format
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2023-07-14 14:30:08 +02:00
parent 7881385f4b
commit 9097a1dc28
12 changed files with 91 additions and 77 deletions

View File

@ -6,12 +6,6 @@ module.exports = Self => {
description: 'Send mail to support',
accessType: 'WRITE',
accepts: [
{
arg: 'subject',
type: 'string',
required: true,
description: 'The subject'
},
{
arg: 'reason',
type: 'string',
@ -34,29 +28,35 @@ module.exports = Self => {
}
});
Self.sendToSupport = async(ctx, subject, reason, additionalData) => {
Self.sendToSupport = async(ctx, reason, additionalData) => {
const emailUser =
await Self.app.models.EmailUser.findById(ctx.req.accessToken.userId, {fields: ['email']});
let html = `<strong>Motivo</strong>:<br/>${reason}<br/>`;
for (const data in additionalData) {
tryJson(additionalData[data]);
html += `<strong>${data}</strong>:<br/>${tryJson(additionalData[data])}<br/>`;
}
console.log(subject, reason, additionalData);
console.log(html);
for (const data in additionalData)
html += `<strong>${data}</strong>:<br/>${tryParse(additionalData[data])}<br/>`;
const subjectReason = JSON.parse(additionalData?.httpRequest)?.data?.error;
smtp.send({
to: config.app.reportEmail,
replyTo: emailUser.email,
subject: '[Support-Salix] ' + subject,
subject:
'[Support-Salix] ' +
additionalData?.frontPath + ' ' +
subjectReason?.name + ':' +
subjectReason?.message,
html
});
};
function tryJson(value) {
function tryParse(value) {
try {
return JSON.parse(value);
} catch (e) {
try {
value = JSON.parse(value);
} catch {}
return JSON.stringify(value, null, '&nbsp;').split('\n').join('<br>');
} catch {
return value;
}
}

View File

@ -55,3 +55,4 @@ import './datalist';
import './contextmenu';
import './rating';
import './smart-table';
import './support-dialog';

View File

@ -1,35 +1,5 @@
<div id="shapes"></div>
<vn-dialog
vn-id="supportDialog"
on-accept="$ctrl.sendToSupport()">
<tpl-body>
<section>
<h5 class="vn-py-sm" translate>Open CAU</h5>
<vn-horizontal>
<vn-textfield
vn-one
label="Subject"
ng-model="supportDialog.subject"
required="true">
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textarea vn-one
label="Reason"
ng-model="supportDialog.reason"
rows="2"
required="true">
</vn-textarea>
</vn-horizontal>
<vn-horizontal>
<span>
{{'Este cau contiene más información relevante para el equipo de informática' | translate}}:
</span>
</vn-horizontal>
</section>
</tpl-body>
<tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
<button response="accept" translate>Send</button>
</tpl-buttons>
</vn-dialog>
<vn-support-dialog
vn-id="support-dialog"
additional-data="$ctrl.additionalData">
</vn-support-dialog>

View File

@ -28,15 +28,15 @@ export default class Controller extends Component {
shape.element = element;
if (data.additionalData) {
this.additionalData = data.additionalData;
let supportButton = document.createElement('i');
supportButton.setAttribute('class', 'material-icons');
supportButton.addEventListener('click', () => this.onButtonClick(this.$.supportDialog.show()));
supportButton.setAttribute('class', 'material-icons clickable');
supportButton.addEventListener('click', () => this.$.supportDialog.show());
element.appendChild(supportButton);
let buttonIcon = 'support_agent';
buttonIcon = document.createTextNode(buttonIcon);
supportButton.appendChild(buttonIcon);
this.$.supportDialog.additionalData = data.additionalData;
}
if (shape.type)
@ -154,23 +154,6 @@ export default class Controller extends Component {
else
this.hide(shape);
}
sendToSupport() {
const supportDialog = this.$.supportDialog;
console.log(this.$.supportDialog.subject);
console.log(this.$.supportDialog.reason);
console.log(this.$.supportDialog.additionalData);
console.log({
subject: supportDialog.subject,
reason: supportDialog.reason,
additionalData: supportDialog.additionalData
});
this.$http.post('Ostickets/send-to-support', {
subject: supportDialog.subject,
reason: supportDialog.reason,
additionalData: supportDialog.additionalData
});
}
}
ngModule.vnComponent('vnSnackbar', {

View File

@ -20,6 +20,10 @@ vn-snackbar .shape {
margin-bottom: 15px;
color: white;
padding: 12px 25px 12px 12px;
display: flex ;
flex-direction: row;
justify-content: center;
align-items: center;
& > .text {
text-align: center;
@ -64,4 +68,12 @@ vn-snackbar .shape {
top: 0;
right: 0
}
.clickable{
background-color: $color-main;
padding: 6px;
border-radius: 50%;
cursor: pointer;
margin-right: 7px;
}
}

View File

@ -0,0 +1,22 @@
<tpl-body>
<section>
<h5 class="vn-py-sm" translate>Send cau</h5>
<vn-horizontal>
<vn-textarea vn-one
label="Reason"
ng-model="$ctrl.reason"
rows="2"
required="true">
</vn-textarea>
</vn-horizontal>
<vn-horizontal>
<span>
{{'This email contains more relevant information for the IT team' | translate}}
</span>
</vn-horizontal>
</section>
</tpl-body>
<tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
<button response="accept" translate>Send</button>
</tpl-buttons>

View File

@ -0,0 +1,27 @@
import ngModule from '../../module';
import Dialog from '../dialog';
export default class Controller extends Dialog {
constructor($element, $, $transclude) {
super($element, $, $transclude);
}
responseHandler(response) {
this.$http.post('Ostickets/send-to-support', {
reason: this.reason,
additionalData: this.additionalData
})
.then(() => super.responseHandler(response))
.then(() => this.vnApp.showSuccess(this.$t('Email sended!')));
}
}
Controller.$inject = ['$element', '$scope', '$transclude'];
ngModule.vnComponent('vnSupportDialog', {
slotTemplate: require('./index.html'),
controller: Controller,
bindings: {
additionalData: '<?'
}
});

View File

@ -64,3 +64,5 @@ No results found: Sin resultados
No data: Sin datos
Undo changes: Deshacer cambios
Load more results: Cargar más resultados
Send cau: Enviar cau
This email contains more relevant information for the IT team: Este correo contiene más información relevante para el equipo de informática

View File

@ -149,10 +149,11 @@ function $exceptionHandler(vnApp, $window, $state, $injector) {
if (messageT)
message = $translate.instant(messageT);
cause = cause.replace('Possibly unhandled rejection: ', '');
const additonalData = {
frontPath: $state.current.name,
httpRequest: cause.replace('Possibly unhandled rejection: ', ''),
backError: JSON.stringify(exception)
backError: exception
};
vnApp.showError(message, additonalData);
};

View File

@ -2,7 +2,6 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const buildFilter = require('vn-loopback/util/filter').buildFilter;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('filter', {
@ -89,7 +88,6 @@ module.exports = Self => {
const conn = Self.dataSource.connector;
const models = Self.app.models;
const myOptions = {};
throw new UserError(`You don't have enough privileges`);
if (typeof options == 'object')
Object.assign(myOptions, options);

View File

@ -46,8 +46,6 @@ class Controller extends Section {
}
deleteRoadmaps() {
console.log(this.checked);
for (const roadmap of this.checked) {
this.$http.delete(`Roadmaps/${roadmap.id}`)
.then(() => this.$.model.refresh())

View File

@ -24,7 +24,7 @@
ng-style="::{backgroundColor: weekday.event.color}">
</vn-avatar>
<div>
{{::weekday.event.name}}
{{::weekday.event}}
</div>
</vn-chip>
</vn-td>