From 664fd444cc33420756e0f2d729bf09f9fc9da67b Mon Sep 17 00:00:00 2001 From: joan Date: Thu, 22 Sep 2022 15:44:35 +0200 Subject: [PATCH] Sample refactor --- db/changes/10490-august/00-sample.sql | 17 +++ modules/client/back/models/sample.json | 6 + modules/client/front/sample/create/index.html | 3 +- modules/client/front/sample/create/index.js | 105 +++++++++++------- 4 files changed, 92 insertions(+), 39 deletions(-) create mode 100644 db/changes/10490-august/00-sample.sql diff --git a/db/changes/10490-august/00-sample.sql b/db/changes/10490-august/00-sample.sql new file mode 100644 index 000000000..e70d1fd13 --- /dev/null +++ b/db/changes/10490-august/00-sample.sql @@ -0,0 +1,17 @@ +alter table `vn`.`sample` + add model VARCHAR(25) null comment 'Model name in plural'; + +alter table `vn`.`sample` + add property VARCHAR(25) null comment 'Remote method property name'; + + +UPDATE vn.sample t + SET t.model = 'Clients', + t.property = 'printerSetup' + WHERE t.id = 13; + +UPDATE vn.sample t +SET t.model = 'Clients', + t.property = 'clientWelcome' +WHERE t.id = 12; + diff --git a/modules/client/back/models/sample.json b/modules/client/back/models/sample.json index cfb127ab2..fcb33a593 100644 --- a/modules/client/back/models/sample.json +++ b/modules/client/back/models/sample.json @@ -29,6 +29,12 @@ }, "datepickerEnabled": { "type": "boolean" + }, + "model": { + "type": "string" + }, + "property": { + "type": "string" } }, "scopes": { diff --git a/modules/client/front/sample/create/index.html b/modules/client/front/sample/create/index.html index 2d0f3d29c..ac6cc312e 100644 --- a/modules/client/front/sample/create/index.html +++ b/modules/client/front/sample/create/index.html @@ -31,6 +31,7 @@ ng-model="$ctrl.clientSample.typeFk" model="ClientSample.typeFk" data="samplesVisible" + fields="['id', 'description', 'model']" show-field="description" label="Sample" required="true"> @@ -77,7 +78,7 @@ + ng-click="$ctrl.preview()"> { - this.$.showPreview.show(); - const dialog = document.body.querySelector('div.vn-dialog'); - const body = dialog.querySelector('tpl-body'); - const scroll = dialog.querySelector('div:first-child'); + // showPreview() { + // this.send(true, res => { + // this.$.showPreview.show(); + // const dialog = document.body.querySelector('div.vn-dialog'); + // const body = dialog.querySelector('tpl-body'); + // const scroll = dialog.querySelector('div:first-child'); - body.innerHTML = res.data; - scroll.scrollTop = 0; - }); - } + // body.innerHTML = res.data; + // scroll.scrollTop = 0; + // }); + // } - sendSample() { - this.send(false, () => { - this.vnApp.showSuccess(this.$t('Notification sent!')); - this.$state.go('client.card.sample.index'); - }); - } + // sendSample() { + // this.send(false, () => { + // this.vnApp.showSuccess(this.$t('Notification sent!')); + // this.$state.go('client.card.sample.index'); + // }); + // } - send(isPreview, cb) { + // send(isPreview, cb) { + // const sampleType = this.$.sampleType.selection; + // const params = { + // recipientId: this.$params.id, + // recipient: this.clientSample.recipient, + // replyTo: this.clientSample.replyTo + // }; + + // if (!params.recipient) + // return this.vnApp.showError(this.$t('Email cannot be blank')); + + // if (!sampleType) + // return this.vnApp.showError(this.$t('Choose a sample')); + + // if (sampleType.hasCompany && !this.clientSample.companyFk) + // return this.vnApp.showError(this.$t('Choose a company')); + + // if (sampleType.hasCompany) + // params.companyId = this.clientSample.companyFk; + + // if (sampleType.datepickerEnabled && !this.clientSample.from) + // return this.vnApp.showError(this.$t('Choose a date')); + + // if (sampleType.datepickerEnabled) + // params.from = this.clientSample.from; + + // let query = `email/${sampleType.code}`; + // if (isPreview) + // query = `email/${sampleType.code}/preview`; + + // this.$http.get(query, {params}).then(cb); + // } + + preview() { const sampleType = this.$.sampleType.selection; + const params = { recipientId: this.$params.id, recipient: this.clientSample.recipient, replyTo: this.clientSample.replyTo }; - if (!params.recipient) - return this.vnApp.showError(this.$t('Email cannot be blank')); + const path = `${sampleType.model}/${this.$params.id}/${sampleType.property}Html`; + this.$http.get(path, {params}) + .then(response => { + this.$.showPreview.show(); + const dialog = document.body.querySelector('div.vn-dialog'); + const body = dialog.querySelector('tpl-body'); + const scroll = dialog.querySelector('div:first-child'); - if (!sampleType) - return this.vnApp.showError(this.$t('Choose a sample')); + body.innerHTML = response.data; + scroll.scrollTop = 0; + }); + } - if (sampleType.hasCompany && !this.clientSample.companyFk) - return this.vnApp.showError(this.$t('Choose a company')); - - if (sampleType.hasCompany) - params.companyId = this.clientSample.companyFk; - - if (sampleType.datepickerEnabled && !this.clientSample.from) - return this.vnApp.showError(this.$t('Choose a date')); - - if (sampleType.datepickerEnabled) - params.from = this.clientSample.from; - - let query = `email/${sampleType.code}`; - if (isPreview) - query = `email/${sampleType.code}/preview`; - - this.$http.get(query, {params}).then(cb); + send() { + this.vnEmail.send(`tickets/${this.id}/credit-request-email`, { + recipientId: this.ticket.client.id, + recipient: $data.email + }); } getWorkerEmail() {