Directiva focus, InputAttrsNormalizer

This commit is contained in:
Juan Ferrer Toribio 2016-12-14 08:43:10 +01:00
parent ab0b9aee33
commit dba859c5a2
23 changed files with 159 additions and 82 deletions

View File

@ -28,13 +28,13 @@ html [margin-small-bottom], .margin-small-bottom {
margin-bottom: $margin-small; margin-bottom: $margin-small;
} }
html [margin-small-v], .margin-small-v { html [margin-small-v], .margin-small-v {
margin-left: $margin-small;
margin-right: $margin-small;
}
html [margin-small-h], .margin-small-h {
margin-top: $margin-small; margin-top: $margin-small;
margin-bottom: $margin-small; margin-bottom: $margin-small;
} }
html [margin-small-h], .margin-small-h {
margin-left: $margin-small;
margin-right: $margin-small;
}
/* Medium */ /* Medium */
@ -54,13 +54,13 @@ html [margin-medium-bottom], .margin-medium-bottom {
margin-bottom: $margin-medium; margin-bottom: $margin-medium;
} }
html [margin-medium-v], .margin-medium-v { html [margin-medium-v], .margin-medium-v {
margin-left: $margin-medium;
margin-right: $margin-medium;
}
html [margin-medium-h], .margin-medium-h {
margin-top: $margin-medium; margin-top: $margin-medium;
margin-bottom: $margin-medium; margin-bottom: $margin-medium;
} }
html [margin-medium-h], .margin-medium-h {
margin-left: $margin-medium;
margin-right: $margin-medium;
}
/* Large */ /* Large */
@ -80,10 +80,10 @@ html [margin-large-bottom], .margin-large-bottom {
margin-bottom: $margin-large; margin-bottom: $margin-large;
} }
html [margin-large-v], .margin-large-v { html [margin-large-v], .margin-large-v {
margin-left: $margin-large;
margin-right: $margin-large;
}
html [margin-large-h], .margin-large-h {
margin-top: $margin-large; margin-top: $margin-large;
margin-bottom: $margin-large; margin-bottom: $margin-large;
} }
html [margin-large-h], .margin-large-h {
margin-left: $margin-large;
margin-right: $margin-large;
}

View File

@ -28,13 +28,13 @@ html [pad-small-bottom], .pad-small-bottom {
padding-bottom: $pad-small; padding-bottom: $pad-small;
} }
html [pad-small-v], .pad-small-v { html [pad-small-v], .pad-small-v {
padding-left: $pad-small;
padding-right: $pad-small;
}
html [pad-small-h], .pad-small-h {
padding-top: $pad-small; padding-top: $pad-small;
padding-bottom: $pad-small; padding-bottom: $pad-small;
} }
html [pad-small-h], .pad-small-h {
padding-left: $pad-small;
padding-right: $pad-small;
}
/* Medium */ /* Medium */
@ -54,13 +54,13 @@ html [pad-medium-bottom], .pad-medium-bottom {
padding-bottom: $pad-medium; padding-bottom: $pad-medium;
} }
html [pad-medium-v], .pad-medium-v { html [pad-medium-v], .pad-medium-v {
padding-left: $pad-medium;
padding-right: $pad-medium;
}
html [pad-medium-h], .pad-medium-h {
padding-top: $pad-medium; padding-top: $pad-medium;
padding-bottom: $pad-medium; padding-bottom: $pad-medium;
} }
html [pad-medium-h], .pad-medium-h {
padding-left: $pad-medium;
padding-right: $pad-medium;
}
/* Large */ /* Large */
@ -80,10 +80,10 @@ html [pad-large-bottom], .pad-large-bottom {
padding-bottom: $pad-large; padding-bottom: $pad-large;
} }
html [pad-large-v], .pad-large-v { html [pad-large-v], .pad-large-v {
padding-left: $pad-large;
padding-right: $pad-large;
}
html [pad-large-h], .pad-large-h {
padding-top: $pad-large; padding-top: $pad-large;
padding-bottom: $pad-large; padding-bottom: $pad-large;
} }
html [pad-large-h], .pad-large-h {
padding-left: $pad-large;
padding-right: $pad-large;
}

View File

@ -1,16 +1,18 @@
import {module as _module} from '../module'; import {module as _module} from '../module';
import * as resolveFactory from '../resolveDefaultComponents'; import * as resolveFactory from '../resolveDefaultComponents';
import * as normalizerFactory from '../inputAttrsNormalizer';
import * as util from '../util'; import * as util from '../util';
const _NAME = 'check'; const _NAME = 'check';
export const NAME = util.getName(_NAME); export const NAME = util.getName(_NAME);
directive.$inject =[resolveFactory.NAME]; directive.$inject =[resolveFactory.NAME, normalizerFactory.NAME];
export function directive (resolve){ export function directive (resolve, normalizer){
return{ return{
require:'E', require:'E',
template: function(_,attr){ template: function(_,attrs){
return resolve.getTemplate(_NAME, attr); normalizer.normalize (attrs);
return resolve.getTemplate(_NAME, attrs);
} }
} }
} }

View File

@ -1,4 +1,4 @@
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect"> <label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect">
<input type="checkbox" name="*[name]*" class="*[className]*" ng-model="*[model]*.*[name]*" *[enabled]*> <input type="checkbox" name="*[name]*" class="*[className]*" name="*[name]*" ng-model="*[model]*" rule="*[rule]*" *[enabled]* *[focus]*>
<span class="mdl-checkbox__label">*[label]*</span> <span class="mdl-checkbox__label">*[label]*</span>
</label> </label>

View File

@ -1,17 +1,19 @@
import {module} from '../module'; import {module} from '../module';
import * as resolveFactory from '../resolveDefaultComponents'; import * as resolveFactory from '../resolveDefaultComponents';
import * as normalizerFactory from '../inputAttrsNormalizer';
import * as util from '../util'; import * as util from '../util';
const _NAME = 'combo'; const _NAME = 'combo';
export const NAME = util.getName(_NAME); export const NAME = util.getName(_NAME);
directive.$inject = [resolveFactory.NAME]; directive.$inject = [resolveFactory.NAME, normalizerFactory.NAME];
export function directive(resolve) { export function directive(resolve, normalizer) {
return { return {
require: 'E', require: 'E',
transclude: true, transclude: true,
template: function(_, attr) { template: function(_, attrs) {
return resolve.getTemplate(_NAME, attr); normalizer.normalize (attrs);
return resolve.getTemplate(_NAME, attrs);
} }
}; };
} }

View File

@ -1,5 +1,5 @@
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<select class="mdl-textfield__input" class="*[className]*" name="*[name]*" ng-model="*[model]*.*[name]*" *[enabled]* ng-transclude> <select class="mdl-textfield__input" class="*[className]*" name="*[name]*" ng-model="*[model]*" rule="*[rule]*" *[enabled]* ng-transclude>
</select> </select>
<label class="mdl-textfield__label">*[label]*</label> <label class="mdl-textfield__label">*[label]*</label>
</div> </div>

View File

@ -8,6 +8,9 @@ export {NAME as RESOLVEDEFAULTCOMPONENT, ResolveDefaultComponent} from './resolv
export {NAME as INTERPOLATE, Interpolate} from './interpolate' export {NAME as INTERPOLATE, Interpolate} from './interpolate'
export {NAME as ROUTES_LOADER, RoutesLoader} from './routesLoader' export {NAME as ROUTES_LOADER, RoutesLoader} from './routesLoader'
export {NAME as FOCUS, directive as Focus} from './focus'
export {NAME as RULE, directive as Rule} from './rule'
export {NAME as BUTTON, directive as ButtonDirective} from './button/button' export {NAME as BUTTON, directive as ButtonDirective} from './button/button'
export {NAME as BUTTON_MDL, factory as buttonMdl} from './button/button.mdl' export {NAME as BUTTON_MDL, factory as buttonMdl} from './button/button.mdl'
export {NAME as BUTTON_BT, factory as buttonBt} from './button/button.bt' export {NAME as BUTTON_BT, factory as buttonBt} from './button/button.bt'
@ -39,7 +42,4 @@ export {NAME as DATE_PICKER, directive as DatePickerDirective} from './date-pick
export {NAME as DATE_PICKER_MDL, factory as datePickerMdl} from './date-picker/date-picker.mdl' export {NAME as DATE_PICKER_MDL, factory as datePickerMdl} from './date-picker/date-picker.mdl'
export {NAME as TITLE, COMPONENT as TITLE_COMPONENT} from './title/title' export {NAME as TITLE, COMPONENT as TITLE_COMPONENT} from './title/title'
export {NAME as SUBTITLE, COMPONENT as SUBTITLE_COMPONENT} from './subtitle/subtitle'

View File

@ -1,16 +1,18 @@
import {module} from '../module'; import {module} from '../module';
import * as resolveFactory from '../resolveDefaultComponents'; import * as resolveFactory from '../resolveDefaultComponents';
import * as normalizerFactory from '../inputAttrsNormalizer';
import * as util from '../util'; import * as util from '../util';
const _NAME = 'datePicker'; const _NAME = 'datePicker';
export const NAME = util.getName(_NAME); export const NAME = util.getName(_NAME);
directive.$inject = [resolveFactory.NAME]; directive.$inject = [resolveFactory.NAME, normalizerFactory.NAME];
export function directive(resolve) { export function directive(resolve, normalizer) {
return { return {
require: 'E', require: 'E',
template: function(_, attr) { template: function(_, attrs) {
return resolve.getTemplate(_NAME, attr); normalizer.normalize (attrs);
return resolve.getTemplate(_NAME, attrs);
} }
}; };
} }

View File

@ -1,4 +1,4 @@
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input *[className]*" type="text" name="*[name]*" ng-model="*[model]*.*[name]*" *[enabled]*> <input class="mdl-textfield__input *[className]*" type="text" name="*[name]*" ng-model="*[model]*" rule="*[rule]*" *[enabled]*>
<label class="mdl-textfield__label">*[label]*</label> <label class="mdl-textfield__label">*[label]*</label>
</div> </div>

16
@salix/core/src/focus.js Normal file
View File

@ -0,0 +1,16 @@
import {module} from './module';
export const NAME = 'vnFocus';
export function directive() {
return {
restrict: 'A',
link: function (scope, elements, attrs){
let element = elements[0];
element.focus();
let len = element.value ? element.value.length : 0;
element.setSelectionRange(0, len);
//element.select();
}
};
}
module.directive(NAME, directive);

View File

@ -0,0 +1,30 @@
import {module} from './module';
export const NAME = 'vnInputAttrsNormalizer';
export class InputAttrsNormalizer {
constructor () {}
$get(){
return {
normalize: function(attrs) {
if (!attrs.entity)
throw new Error(`Attribute 'entity' not defined on input`);
if (!attrs.field)
throw new Error(`Attribute 'field' not defined on input`);
if (attrs.model === undefined)
attrs.model = `${attrs.entity}.model.${attrs.field}`;
if (attrs.rule === undefined)
attrs.rule = `${attrs.entity}.${attrs.field}`;
if (attrs.label === undefined)
attrs.label = `${attrs.entity}.${attrs.field}`;
if (attrs.name === undefined)
attrs.name = attrs.field;
if (attrs.focus !== undefined)
attrs.focus = 'vn-focus';
}
};
}
}
module.provider (NAME, () => new InputAttrsNormalizer ())

View File

@ -1,16 +1,18 @@
import {module} from '../module'; import {module} from '../module';
import * as resolveFactory from '../resolveDefaultComponents'; import * as resolveFactory from '../resolveDefaultComponents';
import * as normalizerFactory from '../inputAttrsNormalizer';
import * as util from '../util'; import * as util from '../util';
const _NAME = 'password'; const _NAME = 'password';
export const NAME = util.getName(_NAME); export const NAME = util.getName(_NAME);
directive.$inject =[resolveFactory.NAME]; directive.$inject =[resolveFactory.NAME, normalizerFactory.NAME];
export function directive (resolve){ export function directive (resolve, normalizer){
return{ return{
require:'E', require:'E',
template: function(_,attr){ template: function(_, attrs){
return resolve.getTemplate(_NAME, attr); normalizer.normalize (attrs);
return resolve.getTemplate(_NAME, attrs);
} }
} }
} }

View File

@ -1,4 +1,4 @@
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="*[className]*" type="password" name="*[name]*" ng-model="*[model]*.*[name]*" *[enabled]*> <input class="*[className]*" type="password" name="*[name]*" ng-model="*[model]*" rule="*[rule]*" *[enabled]* *[focus]*>
<label class="mdl-textfield__label">*[label]*</label> <label class="mdl-textfield__label">*[label]*</label>
</div> </div>

View File

@ -14,7 +14,7 @@ export class ResolveDefaultComponent {
} }
$get($injector,vnInterpolate) { $get($injector,vnInterpolate) {
return { return {
getTemplate:function(name ,attr) { getTemplate:function(name, attrs) {
this._frameworkName = 'Mdl'; this._frameworkName = 'Mdl';
let _name = util.getFactoryName( name + this._frameworkName); let _name = util.getFactoryName( name + this._frameworkName);
let defaultfactory = $injector.has(_name) ? $injector.get(_name) : undefined; let defaultfactory = $injector.has(_name) ? $injector.get(_name) : undefined;
@ -25,7 +25,7 @@ export class ResolveDefaultComponent {
let defaultValues = defaultfactory.default; let defaultValues = defaultfactory.default;
let template = defaultfactory.template; let template = defaultfactory.template;
let scope = Object.assign(defaultValues || {},attr||{}); let scope = Object.assign({}, defaultValues || {}, attrs || {});
return template && vnInterpolate(template)(scope); return template && vnInterpolate(template)(scope);
} }
}; };

11
@salix/core/src/rule.js Normal file
View File

@ -0,0 +1,11 @@
import {module} from './module';
export const NAME = 'vnRule';
export function directive() {
return {
restrict: 'A',
link: function (attrs, element){
}
};
}
module.directive(NAME, directive);

View File

@ -0,0 +1,2 @@
<h5 style="margin-top: 0;" class="border-dashed-top pad-medium-v" level="*[level]*" ng-transclude>
</h5>

View File

@ -0,0 +1,9 @@
import template from './subtitle.html';
import {module} from '../module';
export const NAME = "vnSubtitle";
export const COMPONENT = {
template: template,
transclude: true
};
module.component(NAME, COMPONENT);

View File

@ -1,16 +1,18 @@
import {module as _module} from '../module'; import {module as _module} from '../module';
import * as resolveFactory from '../resolveDefaultComponents'; import * as resolveFactory from '../resolveDefaultComponents';
import * as normalizerFactory from '../inputAttrsNormalizer';
import * as util from '../util'; import * as util from '../util';
const _NAME = 'textfield'; const _NAME = 'textfield';
export const NAME = util.getName(_NAME); export const NAME = util.getName(_NAME);
directive.$inject =[resolveFactory.NAME]; directive.$inject =[resolveFactory.NAME, normalizerFactory.NAME];
export function directive (resolve){ export function directive (resolve, normalizer){
return{ return{
require:'E', require:'E',
template: function(_,attr){ template: function(_, attrs){
return resolve.getTemplate(_NAME, attr); normalizer.normalize (attrs);
return resolve.getTemplate(_NAME, attrs);
} }
} }
} }

View File

@ -1,4 +1,4 @@
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="*[className]*" type="*[type]*" name="*[name]*" ng-model="*[model]*.*[name]*" *[enabled]* *[focus]*> <input class="*[className]*" type="*[type]*" name="*[name]*" ng-model="*[model]*" rule="*[rule]*" *[enabled]* *[focus]*>
<label class="mdl-textfield__label">*[label]*</label> <label class="mdl-textfield__label">*[label]*</label>
</div> </div>

View File

@ -16,10 +16,8 @@ export function factory() {
default: { default: {
label: DEFAULT_LABEL, label: DEFAULT_LABEL,
name: 'textfield', name: 'textfield',
enabled: 'enabled',
className: DEFAULT_CLASS, className: DEFAULT_CLASS,
type: DEFAULT_TYPE, type: DEFAULT_TYPE
model: '$ctrl.model'
} }
} }
} }

View File

@ -11,7 +11,8 @@ export const COMPONENT = {
json => console.error(json.data.error.message) json => console.error(json.data.error.message)
); );
}; };
} },
controllerAs: 'client'
}; };
COMPONENT.controller.$inject = ['$http']; COMPONENT.controller.$inject = ['$http'];
module.component(NAME, COMPONENT); module.component(NAME, COMPONENT);

View File

@ -3,9 +3,9 @@
<div class="box"> <div class="box">
<img src="./logo.svg"/> <img src="./logo.svg"/>
<form name="form" ng-submit="login.submit()"> <form name="form" ng-submit="login.submit()">
<vn-textfield label="User" name="email" model="login.model"></vn-textfield> <vn-textfield label="User" entity="login" field="email"></vn-textfield>
<vn-password label="Password" name="password" model="login.model"></vn-password> <vn-password label="Password" entity="login" field="password"></vn-password>
<vn-check label="Do not close session" name="remember" model="login.model"></vn-check> <vn-check label="Do not close session" entity="login" field="remember"></vn-check>
<div class="footer"> <div class="footer">
<vn-submit label="Enter"></vn-submit> <vn-submit label="Enter"></vn-submit>
<vn-spinner id="spinner"></vn-spinner> <vn-spinner id="spinner"></vn-spinner>

View File

@ -1,22 +1,22 @@
version: '2' version: '2'
services: services:
salix:
build:
context: ./services/salix
ports:
- "3001:3001"
account: account:
build: build:
context: ./@salix-services/account context: ./services/account
ports: ports:
- "3000:3000" - "3000:3000"
client:
build:
context: ./@salix-services/client
ports:
- "3002:3002"
nginx: nginx:
build: build:
context: ./@salix context: ./@salix
ports: ports:
- "8080:8080" - "8080:8080"
salix: client:
build: build:
context: ./@salix-services/salix context: ./services/client
ports: ports:
- "3001:3001" - "3002:3002"