Merge branch 'master' of ssh://git.verdnatura.es:/var/lib/git/salix

This commit is contained in:
Juan Ferrer Toribio 2017-01-18 18:07:26 +01:00
commit 9fcf18594a
22 changed files with 196 additions and 71 deletions

View File

@ -10,6 +10,7 @@ export const COMPONENT = {
var self = this; var self = this;
this.clientId = $state.params.id; this.clientId = $state.params.id;
this.address = {}; this.address = {};
$http.get('/client/api/Agencies').then( $http.get('/client/api/Agencies').then(
json => this.agencies = json.data json => this.agencies = json.data
); );

View File

@ -5,23 +5,43 @@ export const NAME = 'vnClientAddressesDataEdit';
export const COMPONENT = { export const COMPONENT = {
template: template, template: template,
controllerAs: 'addressData', controllerAs: 'addressData',
controller: function($http, $stateParams) { controller: function($http, $stateParams, copyObject, equalsObject) {
this.address = {}; this.address = {};
$http.get(`/client/api/Addresses/${$stateParams.addressId}`).then( $http.get(`/client/api/Addresses/${$stateParams.addressId}`).then(
json => this.address = json.data json => {
this.address = json.data;
this.copyAddress();
}
); );
$http.get('/client/api/Agencies').then( $http.get('/client/api/Agencies').then(
json => this.agencies = json.data json => {
this.agencies = json.data;
}
); );
$http.get('/client/api/Provinces').then( $http.get('/client/api/Provinces').then(
json => this.provinces = json.data json => {
this.provinces = json.data;
}
); );
this.submit = function() { this.submit = function() {
$http.put('/client/api/Addresses', this.address); if (!equalsObject(this.address, this.addressOld)) {
$http.put('/client/api/Addresses', this.address).then(
json => {
this.address = json.data;
this.copyAddress();
}
);
}
};
this.copyAddress = () => {
this.addressOld = {};
copyObject(this.address, this.addressOld);
}; };
} }
}; };
COMPONENT.controller.$inject = ['$http', '$stateParams']; COMPONENT.controller.$inject = ['$http', '$stateParams', 'copyObject', 'equalsObject'];
module.component(NAME, COMPONENT); module.component(NAME, COMPONENT);

View File

@ -26,5 +26,7 @@ export {NAME as CLIENT_ADDRESSES_DATA_EDIT_INDEX,
COMPONENT as CLIENT_ADDRESSES_DATA_EDIT_INDEX_COMPONENT} from './addresses-data-edit/index'; COMPONENT as CLIENT_ADDRESSES_DATA_EDIT_INDEX_COMPONENT} from './addresses-data-edit/index';
export {NAME as CLIENT_CONFIRM_INDEX, export {NAME as CLIENT_CONFIRM_INDEX,
COMPONENT as CLIENT_CONFIRM_INDEX_COMPONENT} from './confirm/index'; COMPONENT as CLIENT_CONFIRM_INDEX_COMPONENT} from './confirm/index';
export {NAME as NEW_NOTE_INDEX,
COMPONENT as NEW_NOTE_INDEX_COMPONENT} from './new-note/index';
import {default as changePassword} from './change-password/index'; import {default as changePassword} from './change-password/index';

View File

@ -0,0 +1,12 @@
<form name="form" ng-submit="form.$valid && newNote.submit()" pad-medium>
<vn-card>
<vn-vertical pad-large>
<vn-title>Nueva nota</vn-title>
<vn-textarea label="Nueva nota" model="newNote.note.text" focus padd-medium-top></vn-textarea>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit label="Guardar"></vn-submit>
</vn-button-bar>
</form>
<vn-dialog-confirm object="newNote.note" object-old="newNote.noteOld" state="newNote.state"></vn-dialog-confirm>

View File

@ -0,0 +1,54 @@
import template from './index.html';
import {module} from '../../module';
export const NAME = 'vnNewNote';
export const COMPONENT = {
template: template,
controllerAs: 'newNote',
controller: function($http, $state, copyObject, equalsObject, $transitions, $element) {
this.client = $state.params.id;
this.note = {text: null};
var self = this;
var deregister = $transitions.onStart({ }, callback);
this.submit = function() {
if (this.note) {
let observation = this.createNote();
$http.post('/client/api/ClientObservations', observation).then(
json => {
this.note = json.data;
this.copyNote();
$state.go('clientCard.notes');
}
);
}
};
this.$onDestroy = function() {
deregister();
};
this.createNote = () => {
let observation = {client: this.client, text: this.note.text, salesPerson: 'user', modify: 'ClientObservation'};
return observation;
};
function callback(transition) {
if (!equalsObject(self.note, self.noteOld)) {
self.state = transition.to().name;
var dialog = $element[0].querySelector('dialog');
dialog.showModal();
return false;
}
}
this.copyNote = () => {
this.noteOld = {}
copyObject(this.note, this.noteOld);
}
}
};
COMPONENT.controller.$inject = ['$http', '$state', 'copyObject', 'equalsObject', '$transitions', '$element'];
module.component(NAME, COMPONENT);

View File

@ -1,19 +1,14 @@
<form name="form" ng-submit="form.$valid && observation.submit()" pad-medium> <vn-card ng-show="observation.observations.length" pad-medium>
<vn-card>
<vn-vertical pad-large> <vn-vertical pad-large>
<vn-title>Notas</vn-title> <vn-title>Notas</vn-title>
<vn-textarea label="Notas" model="observation.newNote" focus padd-medium-top></vn-textarea>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit label="Guardar"></vn-submit>
</vn-button-bar>
<vn-card ng-show="observation.observations.length" margin-small-top>
<vn-vertical pad-large style="max-height: 300px; overflow: auto;">
<div ng-repeat="n in observation.observations"> <div ng-repeat="n in observation.observations">
<p><b>{{n.creationDate | date:'medium'}} {{n.salesPerson}}</b></p> <div class="notes-date">{{n.creationDate | date:'medium'}} {{n.salesPerson}}</div>
<p>{{n.text}}</p> {{n.text}}
</div> </div>
</vn-vertical> </vn-vertical>
</vn-card> </vn-card>
</form> <vn-float-button
fixed-bottom-right
ng-click="observation.newObservation()"
icon="add">
</vn-float-button>

View File

@ -1,3 +1,4 @@
import './style.css';
import template from './index.html'; import template from './index.html';
import {module} from '../../module'; import {module} from '../../module';
@ -8,48 +9,13 @@ export const COMPONENT = {
bindings: { bindings: {
client: '<' client: '<'
}, },
controller: function($http, copyObject, equalsObject, $transitions, $element) { controller: function($http, $state) {
var self = this;
var deregister = $transitions.onStart({ }, callback);
this.submit = function() {
if (this.newNote) {
this.client.modify = "ClientObservation";
let observation = {
client: this.client.id,
text: this.newNote,
creationDate: new Date(),
salesPerson: 'user'
};
$http.put('/client/api/ClientObservations', observation).then(
() => {
this.newNote = "";
this.observations.unshift(observation);
}
);
}
};
this.$onChanges = function(changes) { this.$onChanges = function(changes) {
if (this.client) { if (this.client) {
this.getObservation(this.client.id); this.getObservation(this.client.id);
} }
}; };
this.$onDestroy = function() {
deregister();
};
function callback(transition) {
if (!equalsObject(self.observation, self.observationOld)) {
self.state = transition.to().name;
var dialog = $element[0].querySelector('dialog');
dialog.showModal();
return false;
}
}
this.observations = [];
this.getObservation = function(clientId) { this.getObservation = function(clientId) {
let json = JSON.stringify({where: {client: this.client.id}, order: 'creationDate DESC'}); let json = JSON.stringify({where: {client: this.client.id}, order: 'creationDate DESC'});
$http.get(`/client/api/clientObservations?filter=${json}`).then( $http.get(`/client/api/clientObservations?filter=${json}`).then(
@ -58,7 +24,11 @@ export const COMPONENT = {
} }
); );
}; };
this.newObservation = () => {
$state.go("clientCard.newNote", {id: this.client.id});
};
} }
}; };
COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions', '$element']; COMPONENT.controller.$inject = ['$http', '$state'];
module.component(NAME, COMPONENT); module.component(NAME, COMPONENT);

View File

@ -0,0 +1,3 @@
.notes-date{
font-family: raleway-bold;
}

View File

@ -54,6 +54,12 @@
}, },
description: "Notas", description: "Notas",
icon: "insert_drive_file" icon: "insert_drive_file"
}, {
url: "/new-note",
state: "clientCard.newNote",
component: "vn-new-note",
description: "Nueva nota",
icon: "insert_drive_file"
},{ },{
url: "/create", url: "/create",
state: "create", state: "create",

View File

@ -2,13 +2,13 @@
<vn-card> <vn-card>
<vn-vertical pad-large> <vn-vertical pad-large>
<vn-title>Web access</vn-title> <vn-title>Web access</vn-title>
<vn-check label="Web access enabled" field="web.account.active"></vn-check> <vn-check label="Acceso Web" field="web.account.active"></vn-check>
<vn-textfield label="User" class="margin-medium-top" field="web.account.user" focus></vn-textfield> <vn-textfield label="Usuario" class="margin-medium-top" field="web.account.name" focus></vn-textfield>
</vn-vertical> </vn-vertical>
</vn-card> </vn-card>
<vn-button-bar> <vn-button-bar>
<vn-submit label="Save"></vn-submit> <vn-submit label="Guardar"></vn-submit>
<vn-button label="Change password" vn-dialog="vn-client-change-password"></vn-button> <vn-button label="Cambiar password" vn-dialog="vn-client-change-password"></vn-button>
</vn-button-bar> </vn-button-bar>
</form> </form>
<vn-dialog-confirm object="web.account" object-old="web.accountOld" state="web.state"></vn-dialog-confirm> <vn-dialog-confirm object="web.account" object-old="web.accountOld" state="web.state"></vn-dialog-confirm>

View File

@ -15,7 +15,7 @@ export const COMPONENT = {
this.submit = function() { this.submit = function() {
if (!equalsObject(this.account, this.accountOld)) { if (!equalsObject(this.account, this.accountOld)) {
this.client.modify = "WebAccess"; this.client.modify = "WebAccess";
$http.put(`/client/api/Accounts/${this.account.id}`, this.account).then( $http.put('/client/api/Accounts', this.account).then(
json => { json => {
this.account = json.data; this.account = json.data;
self.copyAccount(); self.copyAccount();

View File

@ -9,7 +9,7 @@
"Country": 3, "Country": 3,
"Province": 3, "Province": 3,
"Agency": 4, "Agency": 4,
"Account": 15, "Account": 20,
"ClientObservation": 1265 "ClientObservation": 1265
}, },
"models": { "models": {
@ -53,9 +53,9 @@
"3": "{\"name\":\"DHL\",\"id\":3}" "3": "{\"name\":\"DHL\",\"id\":3}"
}, },
"Account": { "Account": {
"1": "{\"id\":1,\"password\":\"12\"}", "1": "{\"id\":1,\"password\":\"joselito\",\"name\":\"asdf\"}",
"12": "{\"id\":12,\"name\":\"prueba12\",\"active\":true,\"user\":\"juanete\"}", "14": "{\"id\":14,\"active\":true,\"name\":\"f\"}",
"13": "{\"id\":13,\"name\":\"manu\",\"active\":false,\"user\":\"joselito\"}" "15": "{\"id\":15,\"name\":\"asdf\"}"
}, },
"ClientObservation": { "ClientObservation": {
"1258": "{\"text\":\"Nota de prueba 1\",\"creationDate\":\"2017-01-17T15:24:23.320Z\",\"client\":12,\"salesPerson\":\"user\",\"id\":1258}", "1258": "{\"text\":\"Nota de prueba 1\",\"creationDate\":\"2017-01-17T15:24:23.320Z\",\"client\":12,\"salesPerson\":\"user\",\"id\":1258}",

View File

@ -0,0 +1,34 @@
module.exports = function(Address) {
Address.validate('default',isEnabled,{message: 'No se puede poner predeterminado un consignatario desactivado'});
function isEnabled(err) {
if (!this.enabled && this.default) err();
}
Address.observe('before save', function (ctx, next) {
var data = getData(ctx);
if (isEnabled(data) && isDefault(data)) {
updateData(ctx);
}
next();
});
function getData(ctx){
if(ctx.data)
return ctx.data;
else
return ctx.instance;
}
function isEnabled(data){
return data.isEnabled;
}
function isDefault(data){
return data.default;
}
function updateData(ctx){
ctx.Model.update({client: ctx.data.client}, {default: false});
}
};

View File

@ -1,6 +1,7 @@
{ {
"name": "Address", "name": "Address",
"base": "PersistedModel", "base": "PersistedModel",
"validateUpsert": true,
"properties": { "properties": {
"id": { "id": {
"type": "Number", "type": "Number",

View File

@ -1,6 +1,7 @@
{ {
"name": "Agency", "name": "Agency",
"base": "PersistedModel", "base": "PersistedModel",
"validateUpsert": true,
"properties": { "properties": {
"id": { "id": {
"type": "Number", "type": "Number",

View File

@ -0,0 +1,21 @@
module.exports = function(ClientObservation) {
ClientObservation.validate('text',isEnabled,{message: 'Se debe rellenar el campo de texto'});
function isEnabled(err) {
if (!this.text) err();
}
ClientObservation.observe('before save', function (ctx, next) {
ctx.instance.creationDate = Date();
next();
});
ClientObservation.on('attached', function() {
var override = ClientObservation.find;
ClientObservation.find = function(filter, callback) {
var elements = override.apply(this, arguments);
//return elements;
elements = null;
}
});
};

View File

@ -11,11 +11,11 @@
}, },
"text": { "text": {
"type": "string", "type": "string",
"description": "Fiscal indetifier" "description": "Text"
}, },
"creationDate": { "creationDate": {
"type": "date", "type": "date",
"description": "Fiscal indetifier" "description": "Creation Date"
}, },
"relations": { "relations": {
"salesPerson": { "salesPerson": {

View File

@ -1,6 +1,7 @@
{ {
"name": "Country", "name": "Country",
"base": "PersistedModel", "base": "PersistedModel",
"validateUpsert": true,
"properties": { "properties": {
"id": { "id": {
"type": "Number", "type": "Number",

View File

@ -1,6 +1,7 @@
{ {
"name": "PaymentMethod", "name": "PaymentMethod",
"base": "PersistedModel", "base": "PersistedModel",
"validateUpsert": true,
"properties": { "properties": {
"id": { "id": {
"type": "Number", "type": "Number",

View File

@ -1,6 +1,7 @@
{ {
"name": "Province", "name": "Province",
"base": "PersistedModel", "base": "PersistedModel",
"validateUpsert": true,
"properties": { "properties": {
"id": { "id": {
"type": "Number", "type": "Number",

View File

@ -1,6 +1,7 @@
{ {
"name": "SalesPerson", "name": "SalesPerson",
"base": "PersistedModel", "base": "PersistedModel",
"validateUpsert": true,
"properties": { "properties": {
"id": { "id": {
"type": "Number", "type": "Number",

View File

@ -1,6 +1,7 @@
{ {
"name": "Account", "name": "Account",
"base": "PersistedModel", "base": "PersistedModel",
"validateUpsert": true,
"properties": { "properties": {
"id": { "id": {
"type": "Number", "type": "Number",