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 => {
let token = ctx.req.accessToken;
let currentUserId = token && token.userId;
return await Self.findOne({userFk: currentUserId});
return await Self.app.models.UserConfig.findOne({
where: {userFk: ctx.req.accessToken.userId}
});
};
};

View File

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

View File

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

View File

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

View File

@ -1,79 +1,85 @@
<vn-crud-model
url="/api/Banks"
data="banks"
vn-id="banks"
data="banksData"
order="bank">
</vn-crud-model>
<vn-crud-model
url="/api/Warehouses"
data="warehouses"
vn-id="warehouses"
data="warehousesData"
order="name">
</vn-crud-model>
<vn-crud-model
url="/api/Companies"
data="companies"
vn-id="companies"
data="companiesData"
order="code">
</vn-crud-model>
<vn-vertical class="body">
<form name="form" ng-submit="$ctrl.onSubmit()">
<vn-horizontal>
<vn-autocomplete
vn-one
label="Local warehouse"
id="localWarehouse"
field="$ctrl.localWarehouseFk"
data="warehouses"
select-fields="['id','name']"
show-field="name"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="Local bank"
id="localBank"
field="$ctrl.localBankFk"
data="banks"
select-fields="['id','bank']"
show-field="bank"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="Local company"
id="localCompany"
field="$ctrl.localCompanyFk"
data="companies"
select-fields="['id','code']"
show-field="code"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="User warehouse"
id="userWarehouse"
field="$ctrl.warehouseFk"
data="warehouses"
select-fields="['id', 'name']"
show-field="name"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="User company"
id="userCompany"
field="$ctrl.companyFk"
data="companies"
select-fields="['id', 'code']"
show-field="code"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
</form>
</vn-vertical>
<vn-popover vn-id="popover">
<vn-vertical class="body">
<form name="form" ng-submit="$ctrl.onSubmit()">
<vn-horizontal>
<vn-autocomplete
vn-one
label="Local warehouse"
id="localWarehouse"
field="$ctrl.localWarehouseFk"
data="warehousesData"
select-fields="['id','name']"
show-field="name"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="Local bank"
id="localBank"
field="$ctrl.localBankFk"
data="banksData"
select-fields="['id','bank']"
show-field="bank"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="Local company"
id="localCompany"
field="$ctrl.localCompanyFk"
data="companiesData"
select-fields="['id','code']"
show-field="code"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="User warehouse"
id="userWarehouse"
field="$ctrl.warehouseFk"
data="warehousesData"
select-fields="['id', 'name']"
show-field="name"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="User company"
id="userCompany"
field="$ctrl.companyFk"
data="companiesData"
select-fields="['id', 'code']"
show-field="code"
value-field="id">
</vn-autocomplete>
</vn-horizontal>
</form>
</vn-vertical>
</vn-popover>

View File

@ -43,7 +43,7 @@ class Controller {
set warehouseFk(value) {
this.warehouse = value;
this.setUserConfig('warehouseFk');
this.setUserConfig('warehouseFk', value);
}
get warehouseFk() {
@ -52,7 +52,7 @@ class Controller {
set companyFk(value) {
this.company = value;
this.setUserConfig('companyFk');
this.setUserConfig('companyFk', value);
}
get companyFk() {
@ -63,31 +63,39 @@ class Controller {
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
}
getUserConfig() {
this.$http.get('/api/UserConfigs/getUserConfig')
.then(res => {
if (res.data && res.data.warehouseFk) {
this.warehouse = res.data.warehouseFk;
if (!localStorage.getItem('localWarehouseFk'))
localStorage.setItem('defaultWarehouseFk', res.data.warehouseFk);
}
if (res.data && res.data.companyFk) {
this.company = res.data.companyFk;
if (!localStorage.getItem('localCompanyFk'))
localStorage.setItem('defaultCompanyFk', res.data.companyFk);
}
});
show(event) {
this.$scope.banks.refresh();
this.$scope.warehouses.refresh();
this.$scope.companies.refresh();
this.$scope.popover.parent = event.target;
this.$scope.popover.show();
}
setUserConfig(property) {
getUserConfig() {
this.$http.get('/api/UserConfigs/getUserConfig')
.then(res => {
if (res.data && res.data.warehouseFk) {
this.warehouse = res.data.warehouseFk;
if (!localStorage.getItem('localWarehouseFk'))
localStorage.setItem('defaultWarehouseFk', res.data.warehouseFk);
}
if (res.data && res.data.companyFk) {
this.company = res.data.companyFk;
if (!localStorage.getItem('localCompanyFk'))
localStorage.setItem('defaultCompanyFk', res.data.companyFk);
}
});
}
setUserConfig(property, value) {
let params = {};
params[property] = this[property];
params[property] = value;
this.$http.post('/api/UserConfigs/setUserConfig', params)
.then(() => {
this.showOk();
});
.then(() => {
this.showOk();
});
}
$onInit() {

View File

@ -50,7 +50,7 @@ describe('Salix', () => {
controller.warehouseFk = 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;
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.expect('GET', `/api/UserConfigs/getUserConfig`);
$httpBackend.when('POST', `/api/UserConfigs/setUserConfig`, {companyFk: 1}).respond(200);
$httpBackend.expect('POST', `/api/UserConfigs/setUserConfig`, {companyFk: 1});
controller.setUserConfig('companyFk');
$httpBackend.expect('POST', `/api/UserConfigs/setUserConfig`);
controller.setUserConfig('companyFk', 1);
$httpBackend.flush();
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';
vn-user-configuration-popover {
color: $main-font-color;
& > vn-vertical {
min-width: 250px;
vn-popover {
color: $main-font-color;
vn-vertical {
min-width: 250px;
}
.body {
padding: 16px 16px 6px 16px;
}
}
.body {
padding: 16px 16px 6px 16px;
}
}

View File

@ -1050,7 +1050,10 @@ INSERT INTO `vn`.`orderTicket`(`orderFk`, `ticketFk`)
(21, 21);
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`)
VALUES