Merge branch '2127-sample_disable_preview' of verdnatura/salix into dev
gitea/salix/dev This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2020-02-27 06:27:12 +00:00 committed by Gitea
commit c9f37d5fcd
5 changed files with 35 additions and 14 deletions

View File

@ -0,0 +1,6 @@
ALTER TABLE `vn`.`sample`
ADD COLUMN `hasPreview` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' AFTER `hasCompany`,
CHANGE COLUMN `isVisible` `isVisible` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' ,
CHANGE COLUMN `hasCompany` `hasCompany` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' ;
UPDATE `vn`.`sample` SET `hasPreview` = '0' WHERE (`id` = '14');

View File

@ -22,7 +22,10 @@
"type": "Boolean" "type": "Boolean"
}, },
"hasCompany": { "hasCompany": {
"type": "Number" "type": "Boolean"
},
"hasPreview": {
"type": "Boolean"
} }
}, },
"scopes": { "scopes": {

View File

@ -23,7 +23,7 @@
<vn-autocomplete vn-one vn-id="sampleType" <vn-autocomplete vn-one vn-id="sampleType"
ng-model="$ctrl.clientSample.typeFk" ng-model="$ctrl.clientSample.typeFk"
model="ClientSample.typeFk" model="ClientSample.typeFk"
fields="['code','hasCompany']" fields="['code','hasCompany', 'hasPreview']"
url="Samples/visible" url="Samples/visible"
show-field="description" show-field="description"
value-field="id" value-field="id"
@ -31,7 +31,7 @@
</vn-autocomplete> </vn-autocomplete>
<vn-autocomplete vn-one <vn-autocomplete vn-one
ng-model="$ctrl.companyId" ng-model="$ctrl.companyId"
model="ClientSample.companyId" model="ClientSample.companyFk"
data="companiesData" data="companiesData"
show-field="code" show-field="code"
value-field="id" value-field="id"
@ -42,7 +42,10 @@
</vn-card> </vn-card>
<vn-button-bar> <vn-button-bar>
<vn-submit label="Send"></vn-submit> <vn-submit label="Send"></vn-submit>
<vn-button label="Preview" ng-click="$ctrl.showPreview()"></vn-button> <vn-button ng-if="sampleType.selection.hasPreview"
label="Preview"
ng-click="$ctrl.showPreview()">
</vn-button>
<vn-button ui-sref="client.card.sample.index" label="Cancel"></vn-button> <vn-button ui-sref="client.card.sample.index" label="Cancel"></vn-button>
</vn-button-bar> </vn-button-bar>
</form> </form>

View File

@ -26,13 +26,13 @@ class Controller extends Component {
} }
get companyId() { get companyId() {
if (!this.clientSample.companyId) if (!this.clientSample.companyFk)
this.clientSample.companyId = this.vnConfig.companyFk; this.clientSample.companyFk = this.vnConfig.companyFk;
return this.clientSample.companyId; return this.clientSample.companyFk;
} }
set companyId(value) { set companyId(value) {
this.clientSample.companyId = value; this.clientSample.companyFk = value;
} }
onSubmit() { onSubmit() {
@ -74,11 +74,11 @@ class Controller extends Component {
if (!sampleType) if (!sampleType)
return this.vnApp.showError(this.$translate.instant('Choose a sample')); return this.vnApp.showError(this.$translate.instant('Choose a sample'));
if (sampleType.hasCompany && !this.clientSample.companyId) if (sampleType.hasCompany && !this.clientSample.companyFk)
return this.vnApp.showError(this.$translate.instant('Choose a company')); return this.vnApp.showError(this.$translate.instant('Choose a company'));
if (sampleType.hasCompany) if (sampleType.hasCompany)
params.companyId = this.clientSample.companyId; params.companyId = this.clientSample.companyFk;
if (isPreview) params.isPreview = true; if (isPreview) params.isPreview = true;

View File

@ -107,7 +107,7 @@ describe('Client', () => {
expect(controller.$http.get).not.toHaveBeenCalled(); expect(controller.$http.get).not.toHaveBeenCalled();
}); });
it(`should perform an HTTP query without passing companyId param`, () => { it(`should perform an HTTP query without passing companyFk param`, () => {
controller.$.sampleType.selection = { controller.$.sampleType.selection = {
hasCompany: false, hasCompany: false,
code: 'MyReport' code: 'MyReport'
@ -116,25 +116,34 @@ describe('Client', () => {
clientId: 101, clientId: 101,
recipient: 'client@email.com' recipient: 'client@email.com'
}; };
const expectedParams = {
clientId: 101,
recipient: 'client@email.com'
};
const serializedParams = $httpParamSerializer(expectedParams);
const serializedParams = $httpParamSerializer(controller.clientSample);
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`).respond(true); $httpBackend.expect('GET', `email/MyReport?${serializedParams}`).respond(true);
controller.send(false, () => {}); controller.send(false, () => {});
$httpBackend.flush(); $httpBackend.flush();
}); });
it(`should perform an HTTP query passing companyId param`, () => { it(`should perform an HTTP query passing companyFk param`, () => {
controller.$.sampleType.selection = { controller.$.sampleType.selection = {
hasCompany: true, hasCompany: true,
code: 'MyReport' code: 'MyReport'
}; };
controller.clientSample = { controller.clientSample = {
clientId: 101,
recipient: 'client@email.com',
companyFk: 442
};
const expectedParams = {
clientId: 101, clientId: 101,
recipient: 'client@email.com', recipient: 'client@email.com',
companyId: 442 companyId: 442
}; };
const serializedParams = $httpParamSerializer(expectedParams);
const serializedParams = $httpParamSerializer(controller.clientSample);
$httpBackend.expect('GET', `email/MyReport?${serializedParams}`).respond(true); $httpBackend.expect('GET', `email/MyReport?${serializedParams}`).respond(true);
controller.send(false, () => {}); controller.send(false, () => {});
$httpBackend.flush(); $httpBackend.flush();