This commit is contained in:
Carlos Jimenez Ruiz 2019-01-24 16:14:10 +01:00
commit d19809c318
10 changed files with 131 additions and 112 deletions

View File

@ -13,9 +13,8 @@ module.exports = function(Self) {
}); });
Self.getUserConfig = async ctx => { Self.getUserConfig = async ctx => {
let token = ctx.req.accessToken; return await Self.app.models.UserConfig.findOne({
let currentUserId = token && token.userId; where: {userFk: ctx.req.accessToken.userId}
});
return await Self.findOne({userFk: currentUserId});
}; };
}; };

View File

@ -24,5 +24,5 @@ module.exports = function(Self) {
params.userFk = currentUserId; params.userFk = currentUserId;
return await Self.app.models.UserConfig.upsertWithWhere({userFk: currentUserId}, params); return await Self.app.models.UserConfig.upsertWithWhere({userFk: currentUserId}, params);
} };
}; };

View File

@ -50,7 +50,5 @@
ng-click="$ctrl.onLogoutClick()"> ng-click="$ctrl.onLogoutClick()">
</vn-icon> </vn-icon>
</div> </div>
<vn-popover vn-id="popover"> <vn-user-configuration-popover vn-id="popover">
<vn-user-configuration-popover>
</vn-user-configuration-popover> </vn-user-configuration-popover>
</vn-popover>

View File

@ -37,8 +37,7 @@ export default class MainMenu {
} }
openUserConfiguration(event) { openUserConfiguration(event) {
this.$.popover.parent = event.target; this.$.popover.show(event);
this.$.popover.show();
} }
onLogoutClick() { onLogoutClick() {

View File

@ -1,18 +1,23 @@
<vn-crud-model <vn-crud-model
url="/api/Banks" url="/api/Banks"
data="banks" vn-id="banks"
data="banksData"
order="bank"> order="bank">
</vn-crud-model> </vn-crud-model>
<vn-crud-model <vn-crud-model
url="/api/Warehouses" url="/api/Warehouses"
data="warehouses" vn-id="warehouses"
data="warehousesData"
order="name"> order="name">
</vn-crud-model> </vn-crud-model>
<vn-crud-model <vn-crud-model
url="/api/Companies" url="/api/Companies"
data="companies" vn-id="companies"
data="companiesData"
order="code"> order="code">
</vn-crud-model> </vn-crud-model>
<vn-popover vn-id="popover">
<vn-vertical class="body"> <vn-vertical class="body">
<form name="form" ng-submit="$ctrl.onSubmit()"> <form name="form" ng-submit="$ctrl.onSubmit()">
<vn-horizontal> <vn-horizontal>
@ -21,7 +26,7 @@
label="Local warehouse" label="Local warehouse"
id="localWarehouse" id="localWarehouse"
field="$ctrl.localWarehouseFk" field="$ctrl.localWarehouseFk"
data="warehouses" data="warehousesData"
select-fields="['id','name']" select-fields="['id','name']"
show-field="name" show-field="name"
value-field="id"> value-field="id">
@ -33,7 +38,7 @@
label="Local bank" label="Local bank"
id="localBank" id="localBank"
field="$ctrl.localBankFk" field="$ctrl.localBankFk"
data="banks" data="banksData"
select-fields="['id','bank']" select-fields="['id','bank']"
show-field="bank" show-field="bank"
value-field="id"> value-field="id">
@ -45,7 +50,7 @@
label="Local company" label="Local company"
id="localCompany" id="localCompany"
field="$ctrl.localCompanyFk" field="$ctrl.localCompanyFk"
data="companies" data="companiesData"
select-fields="['id','code']" select-fields="['id','code']"
show-field="code" show-field="code"
value-field="id"> value-field="id">
@ -57,7 +62,7 @@
label="User warehouse" label="User warehouse"
id="userWarehouse" id="userWarehouse"
field="$ctrl.warehouseFk" field="$ctrl.warehouseFk"
data="warehouses" data="warehousesData"
select-fields="['id', 'name']" select-fields="['id', 'name']"
show-field="name" show-field="name"
value-field="id"> value-field="id">
@ -69,7 +74,7 @@
label="User company" label="User company"
id="userCompany" id="userCompany"
field="$ctrl.companyFk" field="$ctrl.companyFk"
data="companies" data="companiesData"
select-fields="['id', 'code']" select-fields="['id', 'code']"
show-field="code" show-field="code"
value-field="id"> value-field="id">
@ -77,3 +82,4 @@
</vn-horizontal> </vn-horizontal>
</form> </form>
</vn-vertical> </vn-vertical>
</vn-popover>

View File

@ -43,7 +43,7 @@ class Controller {
set warehouseFk(value) { set warehouseFk(value) {
this.warehouse = value; this.warehouse = value;
this.setUserConfig('warehouseFk'); this.setUserConfig('warehouseFk', value);
} }
get warehouseFk() { get warehouseFk() {
@ -52,7 +52,7 @@ class Controller {
set companyFk(value) { set companyFk(value) {
this.company = value; this.company = value;
this.setUserConfig('companyFk'); this.setUserConfig('companyFk', value);
} }
get companyFk() { get companyFk() {
@ -63,6 +63,14 @@ class Controller {
this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
} }
show(event) {
this.$scope.banks.refresh();
this.$scope.warehouses.refresh();
this.$scope.companies.refresh();
this.$scope.popover.parent = event.target;
this.$scope.popover.show();
}
getUserConfig() { getUserConfig() {
this.$http.get('/api/UserConfigs/getUserConfig') this.$http.get('/api/UserConfigs/getUserConfig')
.then(res => { .then(res => {
@ -80,9 +88,9 @@ class Controller {
}); });
} }
setUserConfig(property) { setUserConfig(property, value) {
let params = {}; let params = {};
params[property] = this[property]; params[property] = value;
this.$http.post('/api/UserConfigs/setUserConfig', params) this.$http.post('/api/UserConfigs/setUserConfig', params)
.then(() => { .then(() => {

View File

@ -50,7 +50,7 @@ describe('Salix', () => {
controller.warehouseFk = 4; controller.warehouseFk = 4;
expect(controller.warehouse).toBe(4); expect(controller.warehouse).toBe(4);
expect(controller.setUserConfig).toHaveBeenCalledWith('warehouseFk'); expect(controller.setUserConfig).toHaveBeenCalledWith('warehouseFk', 4);
}); });
}); });
@ -60,7 +60,7 @@ describe('Salix', () => {
controller.companyFk = 4; controller.companyFk = 4;
expect(controller.company).toBe(4); expect(controller.company).toBe(4);
expect(controller.setUserConfig).toHaveBeenCalledWith('companyFk'); expect(controller.setUserConfig).toHaveBeenCalledWith('companyFk', 4);
}); });
}); });
@ -83,8 +83,8 @@ describe('Salix', () => {
$httpBackend.when('GET', `/api/UserConfigs/getUserConfig`).respond({companyFk: 2}); $httpBackend.when('GET', `/api/UserConfigs/getUserConfig`).respond({companyFk: 2});
$httpBackend.expect('GET', `/api/UserConfigs/getUserConfig`); $httpBackend.expect('GET', `/api/UserConfigs/getUserConfig`);
$httpBackend.when('POST', `/api/UserConfigs/setUserConfig`, {companyFk: 1}).respond(200); $httpBackend.when('POST', `/api/UserConfigs/setUserConfig`, {companyFk: 1}).respond(200);
$httpBackend.expect('POST', `/api/UserConfigs/setUserConfig`, {companyFk: 1}); $httpBackend.expect('POST', `/api/UserConfigs/setUserConfig`);
controller.setUserConfig('companyFk'); controller.setUserConfig('companyFk', 1);
$httpBackend.flush(); $httpBackend.flush();
expect(controller.showOk).toHaveBeenCalledWith(); expect(controller.showOk).toHaveBeenCalledWith();

View File

@ -0,0 +1,5 @@
Local warehouse: Almacén local
Local bank: Banco local
Local company: Compañia local
User warehouse: Almacén del usuario
User company: Compañia del usuario

View File

@ -1,12 +1,13 @@
@import 'colors'; @import 'colors';
vn-user-configuration-popover { vn-user-configuration-popover {
vn-popover {
color: $main-font-color; color: $main-font-color;
& > vn-vertical { vn-vertical {
min-width: 250px; min-width: 250px;
} }
.body { .body {
padding: 16px 16px 6px 16px; padding: 16px 16px 6px 16px;
} }
}
} }

View File

@ -1050,7 +1050,10 @@ INSERT INTO `vn`.`orderTicket`(`orderFk`, `ticketFk`)
(21, 21); (21, 21);
INSERT INTO `vn`.`userConfig` (`userFk`, `warehouseFk`, `companyFk`) INSERT INTO `vn`.`userConfig` (`userFk`, `warehouseFk`, `companyFk`)
VALUES (9, 1, 442); VALUES
(1, 2, 69),
(9, 1, 442),
(18, 3, 791);
INSERT INTO `vn`.`receipt`(`id`, `invoiceFk`, `amountPaid`, `amountUnpaid`, `payed`, `workerFk`, `bankFk`, `clientFk`, `created`, `companyFk`, `isConciliate`) INSERT INTO `vn`.`receipt`(`id`, `invoiceFk`, `amountPaid`, `amountUnpaid`, `payed`, `workerFk`, `bankFk`, `clientFk`, `created`, `companyFk`, `isConciliate`)
VALUES VALUES