Tarea #614 nueva sección cuenta
This commit is contained in:
parent
fda683f59e
commit
0481cac14e
|
@ -4,3 +4,4 @@ import './main-menu/main-menu';
|
||||||
import './left-menu/left-menu';
|
import './left-menu/left-menu';
|
||||||
import './left-menu/menu-item';
|
import './left-menu/menu-item';
|
||||||
import './topbar/topbar';
|
import './topbar/topbar';
|
||||||
|
import './user-configuration-popover'
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
<div style="position: fixed; top: 0; right: 0; padding: .8em 1.5em; z-index: 10;">
|
<div style="position: fixed; top: 0; right: 0; padding: .8em 1.5em; z-index: 10;">
|
||||||
<div
|
<div
|
||||||
id="user">
|
ng-click="$ctrl.openUserConfiguration($event)"
|
||||||
|
id="user"
|
||||||
|
class="unselectable">
|
||||||
<h6>{{currentUserName}}</h6>
|
<h6>{{currentUserName}}</h6>
|
||||||
</div>
|
</div>
|
||||||
<a href="/salix/version-notes.html"
|
<a href="/salix/version-notes.html"
|
||||||
|
@ -47,6 +49,7 @@
|
||||||
translate-attr="{title: 'Logout'}"
|
translate-attr="{title: 'Logout'}"
|
||||||
ng-click="$ctrl.onLogoutClick()">
|
ng-click="$ctrl.onLogoutClick()">
|
||||||
</vn-icon>
|
</vn-icon>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
TODO: Keep it commented until they are functional
|
TODO: Keep it commented until they are functional
|
||||||
|
|
||||||
|
@ -54,3 +57,8 @@
|
||||||
<vn-icon icon="account_circle" translate-attr="{title: 'Profile'}"></vn-icon>
|
<vn-icon icon="account_circle" translate-attr="{title: 'Profile'}"></vn-icon>
|
||||||
-->
|
-->
|
||||||
</div>
|
</div>
|
||||||
|
<vn-popover vn-id="popover">
|
||||||
|
<vn-user-configuration-popover>
|
||||||
|
|
||||||
|
</vn-user-configuration-popover>
|
||||||
|
</vn-popover>
|
|
@ -34,6 +34,11 @@ export default class MainMenu {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
openUserConfiguration(event) {
|
||||||
|
this.$.popover.parent = event.target;
|
||||||
|
this.$.popover.show();
|
||||||
|
}
|
||||||
|
|
||||||
onLogoutClick() {
|
onLogoutClick() {
|
||||||
this.$window.location = '/logout';
|
this.$window.location = '/logout';
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
<vn-crud-model
|
||||||
|
url="/api/Banks"
|
||||||
|
data="banks"
|
||||||
|
order="bank">
|
||||||
|
</vn-crud-model>
|
||||||
|
<vn-crud-model
|
||||||
|
url="/api/Warehouses"
|
||||||
|
data="warehouses"
|
||||||
|
order="name">
|
||||||
|
</vn-crud-model>
|
||||||
|
<vn-crud-model
|
||||||
|
url="/api/Companies"
|
||||||
|
data="companies"
|
||||||
|
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.localWarehouse"
|
||||||
|
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.localBank"
|
||||||
|
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.localCompany"
|
||||||
|
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>
|
|
@ -0,0 +1,90 @@
|
||||||
|
import ngModule from '../../module';
|
||||||
|
import './style.scss'
|
||||||
|
|
||||||
|
class Controller {
|
||||||
|
constructor($scope, $http, $state, vnApp, $translate) {
|
||||||
|
this.$scope = $scope;
|
||||||
|
this.$http = $http;
|
||||||
|
this.$state = $state;
|
||||||
|
this.vnApp = vnApp;
|
||||||
|
this.$translate = $translate;
|
||||||
|
this.getUserConfig()
|
||||||
|
}
|
||||||
|
|
||||||
|
set localBank(value) {
|
||||||
|
window.localStorage.localBank = value;
|
||||||
|
this.showOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
get localBank() {
|
||||||
|
return parseInt(window.localStorage.localBank);
|
||||||
|
}
|
||||||
|
|
||||||
|
set localWarehouse(value) {
|
||||||
|
window.localStorage.localWarehouse = value;
|
||||||
|
this.showOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
get localWarehouse() {
|
||||||
|
return parseInt(window.localStorage.localWarehouse);
|
||||||
|
}
|
||||||
|
|
||||||
|
set localCompany(value) {
|
||||||
|
window.localStorage.localCompany = value;
|
||||||
|
this.showOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
get localCompany() {
|
||||||
|
return parseInt(window.localStorage.localCompany);
|
||||||
|
}
|
||||||
|
|
||||||
|
set warehouseFk(value) {
|
||||||
|
this.warehouse = value;
|
||||||
|
this.setUserConfig('warehouseFk');
|
||||||
|
}
|
||||||
|
|
||||||
|
get warehouseFk () {
|
||||||
|
return this.warehouse;
|
||||||
|
}
|
||||||
|
|
||||||
|
set companyFk(value) {
|
||||||
|
this.company = value;
|
||||||
|
this.setUserConfig('companyFk');
|
||||||
|
}
|
||||||
|
|
||||||
|
get companyFk () {
|
||||||
|
return this.company;
|
||||||
|
}
|
||||||
|
|
||||||
|
showOk() {
|
||||||
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||||
|
}
|
||||||
|
|
||||||
|
getUserConfig() {
|
||||||
|
this.$http.get('/api/UserConfigs/getUserConfig')
|
||||||
|
.then(res => {
|
||||||
|
if (res.data.response.warehouseFk)
|
||||||
|
this.warehouse = res.data.response.warehouseFk;
|
||||||
|
|
||||||
|
if (res.data.response.companyFk)
|
||||||
|
this.company = res.data.response.companyFk;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setUserConfig(property) {
|
||||||
|
let params = {};
|
||||||
|
params[property] = this[property];
|
||||||
|
|
||||||
|
this.$http.post('/api/UserConfigs/setUserConfig', params)
|
||||||
|
.then(() => {
|
||||||
|
this.showOk();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Controller.$inject = ['$scope', '$http', '$state', 'vnApp', '$translate'];
|
||||||
|
|
||||||
|
ngModule.component('vnUserConfigurationPopover', {
|
||||||
|
template: require('./index.html'),
|
||||||
|
controller: Controller
|
||||||
|
});
|
|
@ -0,0 +1,97 @@
|
||||||
|
import './index.js';
|
||||||
|
|
||||||
|
describe('Salix', () => {
|
||||||
|
describe('Component vnUserConfigurationPopover', () => {
|
||||||
|
let $componentController;
|
||||||
|
let controller;
|
||||||
|
let $httpBackend;
|
||||||
|
let $scope;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
angular.mock.module('salix');
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_, $rootScope) => {
|
||||||
|
$componentController = _$componentController_;
|
||||||
|
$httpBackend = _$httpBackend_;
|
||||||
|
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||||||
|
$scope = $rootScope.$new();
|
||||||
|
controller = $componentController('vnUserConfigurationPopover', {$scope: $scope, $translate: null});
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('localBank() setter', () => {
|
||||||
|
it('should set window.localStorage.localBank and call showOk', () => {
|
||||||
|
spyOn(controller, 'showOk')
|
||||||
|
controller.localBank = 4;
|
||||||
|
|
||||||
|
expect(window.localStorage.localBank).toBe('4');
|
||||||
|
expect(controller.showOk).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('localWarehouse() setter', () => {
|
||||||
|
it('should set window.localStorage.localWarehouse and call showOk', () => {
|
||||||
|
spyOn(controller, 'showOk')
|
||||||
|
controller.localWarehouse = 4;
|
||||||
|
|
||||||
|
expect(window.localStorage.localWarehouse).toBe('4');
|
||||||
|
expect(controller.showOk).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('localCompany() setter', () => {
|
||||||
|
it('should set window.localStorage.localCompany and call showOk', () => {
|
||||||
|
spyOn(controller, 'showOk')
|
||||||
|
controller.localCompany = 4;
|
||||||
|
|
||||||
|
expect(window.localStorage.localCompany).toBe('4');
|
||||||
|
expect(controller.showOk).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('warehouseFk() setter', () => {
|
||||||
|
it('should set warehouse and call setUserConfig', () => {
|
||||||
|
spyOn(controller, 'setUserConfig')
|
||||||
|
controller.warehouseFk = 4;
|
||||||
|
|
||||||
|
expect(controller.warehouse).toBe(4);
|
||||||
|
expect(controller.setUserConfig).toHaveBeenCalledWith('warehouseFk');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('companyFk() setter', () => {
|
||||||
|
it('should set company and call setUserConfig', () => {
|
||||||
|
spyOn(controller, 'setUserConfig')
|
||||||
|
controller.companyFk = 4;
|
||||||
|
|
||||||
|
expect(controller.company).toBe(4);
|
||||||
|
expect(controller.setUserConfig).toHaveBeenCalledWith('companyFk');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getUserConfig()', () => {
|
||||||
|
it('should make a query, set company and not set warehouse if its not in the response', () => {
|
||||||
|
$httpBackend.when('GET', `/api/UserConfigs/getUserConfig`).respond({response: {companyFk: 2}});
|
||||||
|
$httpBackend.expect('GET', `/api/UserConfigs/getUserConfig`);
|
||||||
|
controller.getUserConfig();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.warehouse).toBeUndefined();
|
||||||
|
expect(controller.company).toEqual(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('setUserConfig()', () => {
|
||||||
|
it('should make a query with the property given and call showOk', () => {
|
||||||
|
spyOn(controller, 'showOk');
|
||||||
|
controller.company = 1;
|
||||||
|
$httpBackend.when('POST', `/api/UserConfigs/setUserConfig`, {companyFk: 1}).respond(200);
|
||||||
|
$httpBackend.expect('POST', `/api/UserConfigs/setUserConfig`, {companyFk: 1});
|
||||||
|
controller.setUserConfig('companyFk');
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.showOk).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,12 @@
|
||||||
|
@import 'colors';
|
||||||
|
|
||||||
|
vn-user-configuration-popover {
|
||||||
|
color: $main-font-color;
|
||||||
|
& > vn-vertical {
|
||||||
|
min-width: 250px;
|
||||||
|
}
|
||||||
|
.body {
|
||||||
|
padding: 16px 16px 6px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
module.exports = function(Self) {
|
||||||
|
Self.remoteMethodCtx('getUserConfig', {
|
||||||
|
description: 'returns the information from UserConfig model for the active user',
|
||||||
|
accepts: [],
|
||||||
|
returns: {
|
||||||
|
arg: 'response',
|
||||||
|
type: 'object'
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/getUserConfig`,
|
||||||
|
verb: 'get'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.getUserConfig = async(ctx) => {
|
||||||
|
let token = ctx.req.accessToken;
|
||||||
|
let currentUserId = token && token.userId;
|
||||||
|
|
||||||
|
return await Self.app.models.UserConfig.findOne({userFk: currentUserId});
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,28 @@
|
||||||
|
module.exports = function(Self) {
|
||||||
|
Self.remoteMethodCtx('setUserConfig', {
|
||||||
|
description: 'Change worker of tickets state',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'params',
|
||||||
|
type: 'object',
|
||||||
|
required: true,
|
||||||
|
description: 'warehouseFk, companyFk',
|
||||||
|
http: {source: 'body'}
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
arg: 'response',
|
||||||
|
type: 'object'
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/setUserConfig`,
|
||||||
|
verb: 'post'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.setUserConfig = async(ctx, params) => {
|
||||||
|
let token = ctx.req.accessToken;
|
||||||
|
let currentUserId = token && token.userId;
|
||||||
|
params.userFk = currentUserId;
|
||||||
|
|
||||||
|
return await Self.app.models.UserConfig.upsertWithWhere({userFk: currentUserId}, params);
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,4 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
require('../methods/userConfig/setUserConfig')(Self);
|
||||||
|
require('../methods/userConfig/getUserConfig')(Self);
|
||||||
|
};
|
|
@ -0,0 +1,46 @@
|
||||||
|
{
|
||||||
|
"name": "UserConfig",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "userConfig",
|
||||||
|
"database": "vn"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"userFk": {
|
||||||
|
"id": true,
|
||||||
|
"type": "Number",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
"warehouseFk": {
|
||||||
|
"type": "Number"
|
||||||
|
},
|
||||||
|
"companyFk": {
|
||||||
|
"type": "Number"
|
||||||
|
},
|
||||||
|
"created": {
|
||||||
|
"type": "Date"
|
||||||
|
},
|
||||||
|
"updated": {
|
||||||
|
"type": "Date"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"relations": {
|
||||||
|
"warehouse": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Warehouse",
|
||||||
|
"foreignKey": "warehouseFk"
|
||||||
|
},
|
||||||
|
"company": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Company",
|
||||||
|
"foreignKey": "companyFk"
|
||||||
|
},
|
||||||
|
"account": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Account",
|
||||||
|
"foreignKey": "userFk"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,6 +42,9 @@
|
||||||
"AgencyMode": {
|
"AgencyMode": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"Bank": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"Client": {
|
"Client": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
@ -125,5 +128,8 @@
|
||||||
},
|
},
|
||||||
"DeliveryMethod": {
|
"DeliveryMethod": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
|
"UserConfig": {
|
||||||
|
"dataSource": "vn"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue